-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoad.cpp
More file actions
328 lines (283 loc) · 11.2 KB
/
Load.cpp
File metadata and controls
328 lines (283 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#include "Load.h"
#include "CSEAPI.h"
extern std::vector<string>* FunctionDocMap = NULL;
CSEIntelliSenseInterface* g_CSEISIntfc = NULL;
CSEConsoleInterface* g_CSEConsoleIntfc = NULL;
void ConScribeMessageHandler(OBSEMessagingInterface::Message* Msg)
{
if (Msg->type == 'CSEI') {
CSEInterface* Interface = (CSEInterface*)Msg->data; // CSEInterface is the API class
g_CSEConsoleIntfc = (CSEConsoleInterface*)Interface->InitializeInterface(CSEInterface::kCSEInterface_Console);
g_CSEISIntfc = (CSEIntelliSenseInterface*)Interface->InitializeInterface(CSEInterface::kCSEInterface_IntelliSense);
_MESSAGE("Received interface from CSE");
g_CSEConsoleIntfc->PrintToConsole("NifSE", ("Registering " + UIntToString(FunctionDocMap->size()) + " command URLs ...").c_str());
for ( std::vector<string>::iterator i = FunctionDocMap->begin(); i != FunctionDocMap->end(); ++i )
g_CSEISIntfc->RegisterCommandURL(i->c_str(), (url + *i).c_str());
delete FunctionDocMap;
}
}
void MessageHandler(OBSEMessagingInterface::Message* msg) {
switch (msg->type) {
case OBSEMessagingInterface::kMessage_PostLoad:
_MESSAGE("Game loaded: Creating ni\\ directory.\n");
CreateDirectory((GetOblivionDirectory()+"Data\\"+s_nifSEFullPath).c_str(), NULL);
break;
case OBSEMessagingInterface::kMessage_ExitGame:
case OBSEMessagingInterface::kMessage_ExitGame_Console:
_MESSAGE("Game quit: Deleting ni\\ directory.");
RemoveDirectory((GetOblivionDirectory()+"Data\\"+s_nifSEFullPath).c_str());
break;
}
}
void EditorMessageHandler(OBSEMessagingInterface::Message* msg) {
switch (msg->type) {
case OBSEMessagingInterface::kMessage_PostLoad:
msgInterface->RegisterListener(g_pluginHandle, "CSE", ConScribeMessageHandler);
_MESSAGE("Registered to receive messages from CSE");
break;
case OBSEMessagingInterface::kMessage_PostPostLoad:
_MESSAGE("Requesting an interface from CSE");
msgInterface->Dispatch(g_pluginHandle, 'CSEI', NULL, 0, "CSE");
break;
}
}
string ReadString(UInt32 length) {
char* tempStr = new char[length+1];
serInterface->ReadRecordData(tempStr, length);
tempStr[length] = '\0';
string changes = string(tempStr);
delete[] tempStr;
return changes;
}
void LoadChangelog(string &changes, UInt32 &chNode, UInt32 &chType, UInt32 &chAct, string &chVal) {
string::size_type posS;
string::size_type posF;
posS = 0;
posF = changes.find(logNode,posS);
chNode = StringToUInt(changes.substr(posS,posF-posS));
dPrintAndLog("LoadChangelog","Change node: \""+changes.substr(posS,posF-posS)+"\".");
posS = posF+1;
posF = changes.find(logType,posS);
chType = StringToUInt(changes.substr(posS,posF-posS));
dPrintAndLog("LoadChangelog","Change type: \""+changes.substr(posS,posF-posS)+"\".");
posS = posF+1;
posF = changes.find(logAction,posS);
chAct = StringToUInt(changes.substr(posS,posF-posS));
dPrintAndLog("LoadChangelog","Change action: \""+changes.substr(posS,posF-posS)+"\".");
posS = posF+1;
posF = changes.find(logValue,posS);
chVal = changes.substr(posS,posF-posS);
dPrintAndLog("LoadChangelog","Change value: \""+chVal+"\".");
changes.erase(0,posF+1);
}
// constructs list of BSA files
std::list<string> GetBSAfiles() {
std::list<string> BSAfiles;
WIN32_FIND_DATA bsaSearch;
HANDLE h;
// build a list of BSA files
// code adapted from that by Hammer on CProgramming.com
// http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1046380353&id=1044780608
h = FindFirstFile((GetOblivionDirectory()+"Data\\*.bsa").c_str(), &bsaSearch);
if (h != INVALID_HANDLE_VALUE)
{
do {
if ( !strncmp(bsaSearch.cFileName, "Oblivion", 8) ) {
if ( !strcmp(bsaSearch.cFileName, "Oblivion - Meshes.bsa") )
BSAfiles.push_back((GetOblivionDirectory()+"Data\\"+bsaSearch.cFileName));
}
else if ( !strncmp(bsaSearch.cFileName, "DLCShiveringIsles", 17) ) {
if ( !strcmp(bsaSearch.cFileName, "DLCShiveringIsles - Meshes.bsa") )
BSAfiles.push_back((GetOblivionDirectory()+"Data\\"+bsaSearch.cFileName));
}
else if ( strncmp(bsaSearch.cFileName, "ArchiveInvalidationInvalidated!.bsa", 34) )
BSAfiles.push_back((GetOblivionDirectory()+"Data\\"+bsaSearch.cFileName));
} while (FindNextFile(h, &bsaSearch));
if (GetLastError() != ERROR_NO_MORE_FILES)
PrintAndLog("GetBSAfiles","Unknown error during BSA search - some Nif files inside archives may be inaccessible.");
}
else
{
PrintAndLog("GetBSAfiles","No BSA files found!");
}
FindClose(h);
return BSAfiles;
}
void NifSE_PreloadCallback(void * reserved) {
dPrintAndLog("NifLoad","Loading NifSE data.");
UInt32 type, version, length;
UInt32 modID;
bool modLoaded;
UInt32 nifSEv = VERSION(1,0,0,3);
UInt32 nifID;
string nifPath;
string changes;
UInt32 chNode;
UInt32 chType;
UInt32 chAct;
string chVal;
NifFile* nifPtr = NULL;
dPrintAndLog("NifLoad","Clearing previous RegList.");
NifFile::RegList.clear();
NifFile::RegListByFilename.clear();
NifFile::delta.clear();
while( serInterface->GetNextRecordInfo(&type, &version, &length) ) {
dPrintAndLog("NifLoad",string("Type '")+((char*)&type)[3]+((char*)&type)[2]+((char*)&type)[1]+((char*)&type)[0]+"'\tVersion "+UIntToString(version)+"\tLength "+UIntToString(length));
switch (type) {
case 'MOD ':
dPrintAndLog("NifLoad","'MOD ' record - new mod's NifFiles.");
serInterface->ReadRecordData(&modID, sizeof(UInt8));
dPrintAndLog("NifLoad","Saved modID: "+UIntToString(modID)+".");
if ( !(serInterface->ResolveRefID(modID << 24, &modID)) ) {
modLoaded = false;
dPrintAndLog("NifLoad","Mod no longer loaded.");
}
else {
modLoaded = true;
modID = modID >> 24;
dPrintAndLog("NifLoad","modID resolved: "+UIntToString(modID)+".");
}
break;
case 'niID':
dPrintAndLog("NifLoad","'niID' record - new NifFile.");
if ( modLoaded )
serInterface->ReadRecordData(&nifID, sizeof(UInt32));
nifPath = "";
nifSEv = VERSION(1, 0, 0, 3); // defaults to v1.0 a"1.3", as this was the last version to not include version information
dPrintAndLog("NifLoad","New NifFile #"+UIntToString(modID)+"-"+UIntToString(nifID)+".");
break;
case 'nSEV':
dPrintAndLog("NifLoad","'nSEV' record - NifFile version.");
serInterface->ReadRecordData(&nifSEv, sizeof(UInt32));
dPrintAndLog("NifLoad","NifFile version #"+UIntToString(nifSEv)+".");
break;
case 'niRo': // deprecated "oriPath"
dPrintAndLog("NifLoad","'niRo' record - new oriPath.");
if ( modLoaded ) {
if ( nifPath == "" ) {
nifPath = ReadString(length);
dPrintAndLog("NifLoad","oriPath is \""+nifPath+"\".");
}
else {
nifPtr = new NifFile(ReadString(length), nifPath);
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Open);
dPrintAndLog("NifLoad","New deprecated nif created.");
}
}
break;
case 'niRa': // deprecated "altPath"
dPrintAndLog("NifLoad","'niRa' record - new altPath.");
if ( modLoaded ) {
if ( nifPath == "" ) {
nifPath = ReadString(length);
dPrintAndLog("NifLoad","altPath is \""+nifPath+"\".");
}
else {
nifPtr = new NifFile(nifPath, ReadString(length));
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Open);
dPrintAndLog("NifLoad","New deprecated nif created.");
}
}
break;
case 'niRe':
dPrintAndLog("NifLoad","'niRe' record - new NifFile, editable.");
if ( modLoaded ) {
nifPath = ReadString(length);
if ( !NifFile::getRegNif(modID, nifID, nifPtr) ) {
nifPtr = new NifFile(nifPath, modID, nifID, true, nifSEv);
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Open);
}
dPrintAndLog("NifLoad","Filename is \""+nifPath+"\".");
}
break;
case 'niRc':
dPrintAndLog("NifLoad","'niRc' record - new filename, const.");
if ( modLoaded ) {
nifPath = ReadString(length);
if ( !NifFile::getRegNif(modID, nifID, nifPtr) ) {
nifPtr = new NifFile(nifPath, modID, nifID, false, nifSEv);
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Open);
}
dPrintAndLog("NifLoad","Filename is \""+nifPath+"\".");
}
break;
case 'niCh':
dPrintAndLog("NifLoad","'niCh' record - new changes.");
if ( modLoaded ) {
changes = ReadString(length);
dPrintAndLog("NifLoad","Changes loaded.");
while ( changes.length() != 0 ) {
LoadChangelog(changes, chNode, chType, chAct, chVal);
nifPtr->logChange(chNode, chType, chAct, chVal);
dPrintAndLog("NifLoad","Changes loaded; parsing.");
switch (chType) {
case kNiflibType_NifFile:
nifPtr->loadChNifFile(chAct);
break;
case kNiflibType_NiExtraData:
case kNiflibType_BSBound:
case kNiflibType_BSDecalPlacementVectorExtraData:
case kNiflibType_BSWArray:
case kNiflibType_NiArkAnimationExtraData:
case kNiflibType_NiArkImporterExtraData:
case kNiflibType_NiArkShaderExtraData:
case kNiflibType_NiArkTextureExtraData:
case kNiflibType_NiArkViewportInfoExtraData:
case kNiflibType_NiBinaryExtraData:
case kNiflibType_NiBinaryVoxelExtraData:
case kNiflibType_NiBooleanExtraData:
case kNiflibType_NiColorExtraData:
case kNiflibType_NiFloatExtraData:
case kNiflibType_NiFloatsExtraData:
case kNiflibType_NiIntegerExtraData:
case kNiflibType_BSXFlags:
case kNiflibType_NiIntegersExtraData:
case kNiflibType_NiStringExtraData:
case kNiflibType_NiStringsExtraData:
case kNiflibType_NiTextKeyExtraData:
case kNiflibType_NiVectorExtraData:
case kNiflibType_NiVertWeightsExtraData:
nifPtr->loadChNiExtraData(chNode, chAct, chType, chVal);
break;
case kNiflibType_BSFurnitureMarker:
nifPtr->loadChBSFurnMkr(chNode, chAct, chVal);
case kNiflibType_NiObjectNET:
nifPtr->loadChNiObjectNET(chNode, chAct, chVal);
break;
case kNiflibType_NiAVObject:
nifPtr->loadChNiAVObject(chNode, chAct, chVal);
break;
case kNiflibType_NiNode:
nifPtr->loadChNiNode(chNode, chAct, chVal);
break;
case kNiflibType_NiAlphaProperty:
nifPtr->loadChNiAlphaProperty(chNode, chAct, chVal);
break;
case kNiflibType_NiMaterialProperty:
nifPtr->loadChNiMatProperty(chNode, chAct, chVal);
break;
case kNiflibType_NiStencilProperty:
nifPtr->loadChNiStenProperty(chNode, chAct, chVal);
break;
case kNiflibType_NiTexturingProperty:
nifPtr->loadChNiTexturingProperty(chNode, chAct, chVal);
break;
case kNiflibType_NiVertexColorProperty:
nifPtr->loadChNiVertColorProperty(chNode, chAct, chVal);
break;
case kNiflibType_NiSourceTexture:
nifPtr->loadChNiSourceTexture(chNode, chAct, chVal);
break;
default:
dPrintAndLog("NifLoad","\n\n\t\tBlock type is unsupported! Loaded nif will be incorrect!\n");
break;
}
}
}
break;
default:
dPrintAndLog("NifLoad","Unknown record type.");
}
}
dPrintAndLog("NifLoad","Load complete.\n");
}