-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_NiObjectNET.cpp
More file actions
471 lines (434 loc) · 16.9 KB
/
Commands_NiObjectNET.cpp
File metadata and controls
471 lines (434 loc) · 16.9 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#include "Commands_NiObjectNET.h"
#include "obj/NiObject.h"
#include "obj/NiObjectNET.h"
#include "NiExtraData.h"
// returns the name of the specified ObjectNET of the NifFile
// associated with given nifID.
static bool Cmd_NiObjectNETGetName_Execute(COMMAND_ARGS) {
*result = 0;
string nameStr = " ";
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectNETGetName","Getting the name of nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
try {
nameStr = objNET->GetName();
dPrintAndLog("NiObjectNETGetName","Returning \""+nameStr+"\".\n");
}
catch (std::exception e) {
nameStr = "";
dPrintAndLog("NiObjectNETGetName","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETGetName","Block is not ObjectNET.\n");
}
else
dPrintAndLog("NiObjectNETGetName","Block index out of range.\n");
}
else
dPrintAndLog("NiObjectNETGetName","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectNETGetName","Could not find Nif.\n");
}
else
dPrintAndLog("NiObjectNETGetName","Error extracting arguments.\n");
strInterface->Assign(PASS_COMMAND_ARGS, nameStr.c_str());
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETGetName,
NiObjNETGetName,
"Returns the name of the NiObjectNET on the given Nif",
0,
kParams_TwoInts
);
// sets the name of the specified ExtraData in the
// NifFile associated with the given nifID.
static bool Cmd_NiObjectNETSetName_Execute(COMMAND_ARGS) {
*result = 0;
char nuName[kMaxMessageLength] = " ";
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nuName, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectNETSetName","Setting the name of nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+" to \""+string(nuName)+"\".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
try {
*result = 1;
objNET->SetName(nuName);
dPrintAndLog("NiObjectNETSetName","ObjectNET name set successfully.\n");
nifPtr->logChange(blockID, kNiflibType_NiObjectNET, kNiObjNETAct_SetName, nuName, true);
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiObjectNETSetName","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETSetName","Block is not ObjectNET.\n");
}
else
dPrintAndLog("NiObjectNETSetName","Block index out of range.\n");
}
else
dPrintAndLog("NiObjectNETSetName","Nif not editable.\n");
}
else
dPrintAndLog("NiObjectNETSetName","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectNETSetName","Could not find Nif.\n");
}
else
dPrintAndLog("NiObjectNETSetName","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETSetName,
NiObjNETSetName,
"Sets the name of the NiObjectNET to the passed string.",
0,
kParams_OneString_OneInt_OneOptionalInt
);
// returns the number of ExtraData in the NifFile associated
// with given nifID.
static bool Cmd_NiObjectNETGetNumExtraData_Execute(COMMAND_ARGS) {
*result = -1;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NifGetNumExtraData","Getting the number of ExtraData nodes in nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
try {
*result = objNET->GetExtraData().size();
dPrintAndLog("NiObjectNETGetNumExtraData","Returning "+UIntToString(*result)+".\n");
}
catch (std::exception e) {
*result = -1;
dPrintAndLog("NiObjectNETGetNumExtraData","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETGetNumExtraData","Block is not ObjectNET.\n");
}
else
dPrintAndLog("NiObjectNETGetNumExtraData","Block index out of range.\n");
}
else
dPrintAndLog("NiObjectNETGetNumExtraData","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectNETGetNumExtraData","Could not find Nif.\n");
}
else
dPrintAndLog("NiObjectNETGetNumExtraData","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETGetNumExtraData,
NiObjNETGetNumED,
"Returns the number of ExtraData nodes in the given Nif",
0,
kParams_OneInt_OneOptionalInt
);
// returns an array of ExtraData in the NifFile associated
// with given nifID.
static bool Cmd_NiObjectNETGetExtraData_Execute(COMMAND_ARGS) {
*result = 0;
OBSEArray* arr = NULL;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectNETGetExtraData","Getting ExtraData nodes in nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
try {
vector<OBSEElement> edvec = vector<OBSEElement>();
list<Niflib::NiExtraDataRef> eds = objNET->GetExtraData();
for ( list<Niflib::NiExtraDataRef>::iterator i = eds.begin(); i != eds.end(); ++i )
edvec.push_back((*i)->internal_block_number);
arr = ArrayFromStdVector(edvec, scriptObj);
}
catch (std::exception e) {
arr = NULL;
dPrintAndLog("NiObjectNETGetName","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETGetExtraData","Block is not ObjectNET.");
}
else
dPrintAndLog("NiObjectNETGetExtraData","Block index out of range.");
}
else
dPrintAndLog("NiObjectNETGetExtraData","Nif root bad.");
}
else
dPrintAndLog("NiObjectNETGetExtraData","Could not find Nif.");
}
else
dPrintAndLog("NiObjectNETGetExtraData","Error extracting arguments.");
if ( arrInterface->AssignCommandResult(arr, result) )
dPrintAndLog("NiObjectNETGetExtraData","Returning node's extra data.\n");
else
dPrintAndLog("NiObjectNETGetExtraData","Failed to create and return array.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETGetExtraData,
NiObjNETGetED,
"Returns an array of ExtraData nodes to the given node",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiObjectNETGetExtraDataByName_Execute(COMMAND_ARGS) {
*result = -1;
char edName[kMaxMessageLength];
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &edName, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectNETGetExtraDataByName","Getting the index of ExtraData \""+string(edName)+"\" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
try {
list<Niflib::NiExtraDataRef> eds = objNET->GetExtraData();
for ( list<Niflib::NiExtraDataRef>::iterator i = eds.begin(); i != eds.end(); ++i )
if ( (*i)->GetName().compare(edName) == 0 )
*result = (*i)->internal_block_number;
if ( *result == -1 )
dPrintAndLog("NiObjectNETGetExtraDataByName","ExtraData not found.\n");
else
dPrintAndLog("NiObjectNETGetExtraDataByName","ExtraData found.\n");
}
catch (std::exception e) {
*result = -1;
dPrintAndLog("NiObjectNETGetExtraDataByName","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETGetExtraDataByName","Block is not ObjectNET.\n");
}
else
dPrintAndLog("NiObjectNETGetExtraDataByName","Block index out of range.\n");
}
else
dPrintAndLog("NiObjectNETGetExtraDataByName","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectNETGetExtraDataByName","Could not find Nif.\n");
}
else
dPrintAndLog("NiObjectNETGetExtraDataByName","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETGetExtraDataByName,
NiObjNETGetEDByName,
"Returns the index of the named ExtraData of the specified Nif.",
0,
kParams_OneString_OneInt_OneOptionalInt
);
static bool Cmd_NiObjectNETAddExtraData_Execute(COMMAND_ARGS) {
*result = 0;
char name[kMaxMessageLength];
UInt32 typeID = 0;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &name, &typeID, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectNETAddExtraData","Adding ExtraData \""+string(name)+"\" of type #"+UIntToString(typeID)+" to nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
try {
*result = Util_NiObjectNETAddExtraData(nifPtr, objNET, typeID, name);
nifPtr->logChange(objNET->internal_block_number, kNiflibType_NiObjectNET, kNiObjNETAct_AddED, UIntToString(typeID)+logValType+name);
dPrintAndLog("NiObjectNETAddExtraData","Addition successful.\n");
}
catch (std::exception e) {
*result = -1;
dPrintAndLog("NiObjectNETAddExtraData","Addition failed; exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETAddExtraData","Block is not ObjectNET.\n");
}
else
dPrintAndLog("NiObjectNETAddExtraData","Block index out of bounds.\n");
}
else
dPrintAndLog("NiObjectNETAddExtraData","Nif not editable.\n");
}
else
dPrintAndLog("NiObjectNETAddExtraData","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectNETAddExtraData","Nif not found.\n");
}
else
dPrintAndLog("NiObjectNETAddExtraData","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETAddExtraData,
NiObjNETAddED,
"Adds an ExtraData node of the given type to the given Nif",
0,
kParams_OneString_TwoInts_OneOptionalInt
);
static bool Cmd_NiObjectNETDeleteExtraData_Execute(COMMAND_ARGS) {
*result = 0;
int edID = -1;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &edID, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectNETDeleteExtraData","Deleting ExtraData with Block #"+UIntToString(edID)+" from ObjectNET (nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" block #"+UIntToString(blockID)+").");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( nifPtr->editable ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifPtr->nifList[blockID]);
if ( objNET ) {
if ( edID < nifPtr->nifList.size() ) {
Niflib::NiExtraDataRef ed = Niflib::DynamicCast<Niflib::NiExtraData>(nifPtr->nifList[edID]);
if ( ed ) {
try {
objNET->RemoveExtraData(ed);
*result = 1;
dPrintAndLog("NiObjectNETDeleteExtraData","ExtraData deleted.\n");
nifPtr->logChange(blockID, kNiflibType_NiObjectNET, kNiObjNETAct_DelED, UIntToString(edID));
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiObjectNETDeleteExtraData","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectNETDeleteExtraData","Block not NiExtraData; not deleted. Block type: \""+nifPtr->nifList[edID]->GetType().GetTypeName()+"\".\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Block indicated for ExtraData is out of range; block not deleted.\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Block not NiObjectNET; ExtraData not deleted. Block type: \""+nifPtr->nifList[blockID]->GetType().GetTypeName()+"\".\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Block indicated for ObjectNET is out of range; ExtraData not deleted.\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Nif is not editable.\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Nif root is bad.\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Nif not found.\n");
}
else
dPrintAndLog("NiObjectNetDeleteExtraData","Could not extract arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectNETDeleteExtraData,
NiObjNETDelED,
"Deletes the Nth block of the given Nif if it is an ExtraData",
0,
kParams_TwoInts_OneOptionalInt
);
UInt32 Util_NiObjectNETAddExtraData(NifFile* nifPtr, Niflib::NiObjectNETRef objNET, UInt32 typeID, const string& name) {
Niflib::NiExtraDataRef nuED = Niflib::DynamicCast<Niflib::NiExtraData>(getNiflibType(typeID)->Create());
if ( nuED ) {
nuED->SetName(name);
nuED->internal_block_number = nifPtr->nifList.size();
objNET->AddExtraData(nuED, nifPtr->nifVersion);
nifPtr->nifList.push_back(Niflib::StaticCast<Niflib::NiObject>(nuED));
return nuED->internal_block_number;
}
else
throw std::exception("Passed type is not derived from NiExtraData.");
}
void NifFile::loadChNiObjectNET(UInt32 block, UInt32 act, string& val) {
if ( block < nifList.size() ) {
Niflib::NiObjectNETRef objNET = Niflib::DynamicCast<Niflib::NiObjectNET>(nifList[block]);
if ( objNET ) {
switch (act) {
case kNiObjNETAct_SetName:
objNET->SetName(val);
dPrintAndLog("NifLoad - NiObjectNET","NiObjectNET name change loaded; name set to \""+val+"\".");
break;
case kNiObjNETAct_AddED:
try {
string::size_type i = val.find(logValType);
UInt32 edType = StringToUInt(val.substr(0, i));
string edName = val.substr(i+1);
UInt32 blockID = Util_NiObjectNETAddExtraData(this, objNET, edType, edName);
dPrintAndLog("NifLoad - NiObjectNET","NiExtraData \""+edName+"\" added to nif as block #"+UIntToString(blockID)+".");
}
catch (std::exception e) {
dPrintAndLog("NifLoad - NiObjectNET","\n\n\t\tNiExtraData node not added! Exception \""+string(e.what())+"\" thrown. Loaded nif will be incorrect!\n");
}
break;
case kNiObjNETAct_DelED:
{
UInt32 edID = StringToUInt(val);
if ( edID < nifList.size() ) {
list<Niflib::NiExtraDataRef> eds = objNET->GetExtraData();
for ( list<Niflib::NiExtraDataRef>::iterator i = eds.begin(); i != eds.end(); ++i )
if ( *i == Niflib::DynamicCast<Niflib::NiExtraData>(nifList[edID]) )
objNET->RemoveExtraData(*i);
dPrintAndLog("NifLoad - NiObjectNET","ExtraData (block #"+val+") deleted.");
}
else
dPrintAndLog("NifLoad - NiObjectNET","\n\n\t\tBlock #"+val+" out of range! Loaded nif will be incorrect!\n");
}
break;
case kNiObjNETAct_AddCtlr:
case kNiObjNETAct_DelCtlr:
dPrintAndLog("NifLoad - NiObjectNET","\n\n\t\tThis version of NifSE does not support these changes! Loaded nif will be incorrect!\n");
default:
dPrintAndLog("NifLoad - NiObjectNET","\n\n\t\tUnknown change type! Loaded nif will be incorrect!\n");
}
}
else
dPrintAndLog("NifLoad - NiObjectNET","\n\n\t\tIndicated block is not a NiObjectNET! Change cannot be loaded; loaded nif will be incorrect!\n");
}
else
dPrintAndLog("NifLoad - NiObjectNET","\n\n\t\tIndicated block index is out of range! Change cannot be loaded; loaded nif will be incorrect!\n");
}