-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_NiObject.cpp
More file actions
177 lines (156 loc) · 5.89 KB
/
Commands_NiObject.cpp
File metadata and controls
177 lines (156 loc) · 5.89 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
#include "Commands_NiObject.h"
#include "obj/NiObject.h"
static bool Cmd_NiObjectGetType_Execute(COMMAND_ARGS) {
*result = 0;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectGetType","Getting the type of object #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectRef obj = nifPtr->nifList[blockID];
if ( obj ) {
try {
*result = getNiflibTypeIndex(obj->GetType());
dPrintAndLog("NiObjectGetType","Returning "+UIntToString(*result)+".\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiObjectGetType","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectGetType","Bad object.\n");
}
else
dPrintAndLog("NiObjectGetType","Object index out of range.\n");
}
else
dPrintAndLog("NiObjectGetType","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectGetType","Nif not found.\n");
}
else
dPrintAndLog("NiObjectGetType","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectGetType,
NiObjGetType,
"Returns the type of the Nth block of the given Nif",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiObjectGetTypeName_Execute(COMMAND_ARGS) {
*result = 0;
string typeStr = " ";
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectGetTypeName","Getting the type name of object #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectRef obj = nifPtr->nifList[blockID];
if ( obj ) {
try {
typeStr = obj->GetType().GetTypeName();
dPrintAndLog("NiObjectGetTypeName","Returning \""+typeStr+"\".\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiObjectGetTypeName","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectGetTypeName","Bad object.\n");
}
else
dPrintAndLog("NiObjectGetTypeName","Object index out of range.\n");
}
else
dPrintAndLog("NiObjectGetTypeName","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectGetTypeName","Nif not found.\n");
}
else
dPrintAndLog("NiObjectGetTypeName","Error extracting arguments.\n");
strInterface->Assign(PASS_COMMAND_ARGS, typeStr.c_str());
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectGetTypeName,
NiObjGetTypeName,
"Returns the name of the type of the Nth block of the given Nif",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiObjectTypeDerivesFrom_Execute(COMMAND_ARGS) {
*result = 0;
int nifType = -1;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifType, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiObjectTypeDerivesFrom","Getting whether the type of object #"+UIntToString(blockID)+" of nif #"+UIntToString(modID)+"-"+UIntToString(nifID)+" is derived from type #"+UIntToString(nifType)+".");
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
if ( blockID < nifPtr->nifList.size() ) {
Niflib::NiObjectRef obj = nifPtr->nifList[blockID];
if ( obj ) {
try {
const Niflib::Type* ancestor = getNiflibType(nifType);
dPrintAndLog("NiObjectTypeDerivesFrom","Testing whether \""+obj->GetType().GetTypeName()+"\" derives from \""+ancestor->GetTypeName()+"\".");
bool isDeriv = obj->GetType().IsDerivedType(*ancestor);
*result = (isDeriv?1:0);
dPrintAndLog("NiObjectTypeDerivesFrom","Returning "+string(isDeriv?"TRUE":"FALSE")+".\n");
}
catch (std::exception e) {
dPrintAndLog("NiObjectTypeDerivesFrom","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiObjectTypeDerivesFrom","Bad object.\n");
}
else
dPrintAndLog("NiObjectTypeDerivesFrom","Object index out of range.\n");
}
else
dPrintAndLog("NiObjectTypeDerivesFrom","Nif root bad.\n");
}
else
dPrintAndLog("NiObjectTypeDerivesFrom","Nif not found.\n");
}
else
dPrintAndLog("NiObjectTypeDerivesFrom","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiObjectTypeDerivesFrom,
NiObjIsDeriv,
"Returns the type of the Nth block of the given Nif",
0,
kParams_TwoInts_OneOptionalInt
);
vector<Niflib::NiObjectRef> Util_CopyBranch(Niflib::NiObjectRef branchRoot, Niflib::NifInfo* headerInfoPtr) {
return Util_CopyBranch(branchRoot, headerInfoPtr, branchRoot);
}
vector<Niflib::NiObjectRef> Util_CopyBranch(Niflib::NiObjectRef branchRoot, Niflib::NifInfo* headerInfoPtr, Niflib::NiObjectRef destRoot) {
std::stringstream nifStream = std::stringstream(std::ios::binary | std::ios::in | std::ios::out);
list<Niflib::NiObject*> missing_link_ptrs = list<Niflib::NiObject*>();
Niflib::WriteNifTree(nifStream, branchRoot, missing_link_ptrs, *headerInfoPtr);
dPrintAndLog("Util_CopyBranch", "WriteNifTree complete.");
list<Niflib::NiObjectRef> missing_link_refs = Niflib::CopyAndResolveMissingLinkStack(destRoot, missing_link_ptrs);
vector<Niflib::NiObjectRef> copiedBranch = Niflib::ReadNifList(nifStream, missing_link_refs, headerInfoPtr);
dPrintAndLog("Util_CopyBranch", "ReadNifTree complete.");
if (copiedBranch.empty()) throw std::exception("Copied branch is empty.");
return copiedBranch;
}