-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_Basic.cpp
More file actions
231 lines (203 loc) · 6.8 KB
/
Commands_Basic.cpp
File metadata and controls
231 lines (203 loc) · 6.8 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
#include "Commands_Basic.h"
// creates a NifFile from given file in folders or archives.
// returns nifID of the NifFile.
static bool Cmd_NifOpen_Execute(COMMAND_ARGS) {
*result = -1;
char oriPath[kMaxMessageLength] = " ";
int forEdit = 0;
if (!ExtractArgs(PASS_EXTRACT_ARGS, &oriPath, &forEdit)) {
dPrintAndLog("NifOpen","Error extracting arguments.\n");
return true;
}
dPrintAndLog("NifOpen", "\""+string(oriPath)+"\" opened"+(forEdit!=0?(" for editing."):(" for reading.")));
try {
NifFile* nifPtr = new NifFile(string(oriPath), scriptObj->GetModIndex(), (forEdit!=0));
if ( nifPtr ) {
if ( nifPtr->nifID >= 0 ) {
*result = nifPtr->nifID;
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Open);
dPrintAndLog("NifOpen", "\""+string(oriPath)+"\" registered as #"+UIntToString(nifPtr->modID)+"-"+UIntToString(*result)+".\n");
}
else
dPrintAndLog("NifOpen", "\""+string(oriPath)+"\" failed to register!\n");
}
else
dPrintAndLog("NifOpen", "\""+string(oriPath)+"\" failed to register!\n");
}
catch (exception& except) {
dPrintAndLog("NifOpen","Failed to create NifFile; exception \""+string(except.what())+"\" thrown.\n");
}
return true;
}
DEFINE_COMMAND_PLUGIN(
NifOpen,
"Registers a nif for a mod to read or modify. Optional second argument is a boolean for editing - default is const.",
0,
2,
kParams_OneString_OneOptionalBool
);
// deregisters and deletes NifFile of given nifID
static bool Cmd_NifClose_Execute(COMMAND_ARGS) {
*result = 0;
UInt32 nifID = 0;
if (!ExtractArgs(PASS_EXTRACT_ARGS, &nifID)) {
dPrintAndLog("NifClose","Error extracting arguments.\n");
return true;
}
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NifClose","Closing nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( !nifPtr->delChange() )
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Close);
delete nifPtr;
dPrintAndLog("NifClose","NifFile successfully closed.\n");
}
else
dPrintAndLog("NifClose","Nif not found.\n");
return true;
}
DEFINE_COMMAND_PLUGIN(
NifClose,
"Deletes the given NifFile, and if an editable file, deletes the file itself as well",
0,
1,
kParams_OneInt
);
// returns the path where NifFile associated with the given nifID can be found
// for editable nifs, does not actually exist until called for by Oblivion
// but Oblivion needs to be calling the correct filename.
static bool Cmd_NifGetPath_Execute(COMMAND_ARGS) {
*result = 0;
string pathStr = " ";
int nifID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NifGetPath","Getting the path to nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
pathStr = nifPtr->filePath;
dPrintAndLog("NifGetPath","Returning \""+pathStr+"\".\n");
}
else
dPrintAndLog("NifGetPath","Root bad.\n");
}
else
dPrintAndLog("NifGetPath","Nif not found.\n");
}
else
dPrintAndLog("NifGetPath","Error extracting arguments.\n");
strInterface->Assign(PASS_COMMAND_ARGS, pathStr.c_str());
return true;
}
DEFINE_COMMAND_PLUGIN(
NifGetPath,
"Returns the path of a given registered Nif",
0,
1,
kParams_OneInt
);
// returns the path where the path to the originally opened nif file
// can be found. For uneditable nif's, this is the same as the path.
static bool Cmd_NifGetOriginalPath_Execute(COMMAND_ARGS) {
*result = 0;
string pathStr = " ";
int nifID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NifGetOriginalPath","Getting the original path to nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
pathStr = nifPtr->basePath;
dPrintAndLog("NifGetOriginalPath","Returning \""+pathStr+"\".\n");
}
else
dPrintAndLog("NifGetOriginalPath","Root bad.\n");
}
else
dPrintAndLog("NifGetOriginalPath","Nif not found.\n");
}
else
dPrintAndLog("NifGetOriginalPath","Error extracting arguments.\n");
strInterface->Assign(PASS_COMMAND_ARGS, pathStr.c_str());
return true;
}
DEFINE_COMMAND_PLUGIN(
NifGetOriginalPath,
"Returns the original path of a given registered Nif",
0,
1,
kParams_OneInt
);
// returns the total number of blocks in a nif.
static bool Cmd_NifGetNumBlocks_Execute(COMMAND_ARGS) {
*result = 0;
int nifID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NifGetNumBlocks","Getting the number of blocks in nif #"+UIntToString(modID)+"-"+UIntToString(nifID));
NifFile* nifPtr = NULL;
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( nifPtr->root ) {
*result = nifPtr->nifList.size();
dPrintAndLog("NifGetNumBlocks","Returning "+UIntToString(nifPtr->nifList.size())+".\n");
}
else
dPrintAndLog("NifGetNumBlocks","Root bad.\n");
}
else
dPrintAndLog("NifGetNumBlocks","Nif not found.\n");
}
else
dPrintAndLog("NifGetNumBlocks","Error extracting arguments.\n");
return true;
}
DEFINE_COMMAND_PLUGIN(
NifGetNumBlocks,
"Returns the number of blocks in a given registered Nif",
0,
1,
kParams_OneInt
);
static bool Cmd_GetNifTypeIndex_Execute(COMMAND_ARGS) {
*result = -1;
char typeName[kMaxMessageLength];
if (ExtractArgs(PASS_EXTRACT_ARGS, &typeName)) {
dPrintAndLog("GetNifTypeIndex","Getting the code for Nif block type \""+string(typeName)+"\".");
*result = getNiflibTypeIndex(typeName);
dPrintAndLog("GetNifTypeIndex","Returning "+UIntToString(*result)+".\n");
}
else
dPrintAndLog("GetNifTypeIndex","Error extracting arguments.\n");
return true;
}
DEFINE_COMMAND_PLUGIN(
GetNifTypeIndex,
"Returns code for the passed type name",
0,
1,
kParams_OneString
);
void NifFile::loadChNifFile(UInt32 act) {
NifFile* nifPtr = NULL;
switch (act) {
case kBasicAct_Open:
if ( !NifFile::getRegNif(modID, nifID, nifPtr) )
dPrintAndLog("NifLoad - NifFiles","\n\n\t\tCalled for opening unknown nif! Behavior indeterminate.\n");
break;
case kBasicAct_Close:
if ( NifFile::getRegNif(modID, nifID, nifPtr) ) {
if ( !nifPtr->delChange() )
nifPtr->logChange(0, kNiflibType_NifFile, kBasicAct_Close, "");
delete nifPtr;
dPrintAndLog("NifLoad - NifFiles","NifFile successfully closed.\n");
}
else
dPrintAndLog("NifLoad - NifFiles","\n\n\t\tCalled for closing unknown nif! Behavior indeterminate.\n");
break;
default:
dPrintAndLog("NifLoad - NifFiles","\n\n\t\tUnknown change type! Loaded nif will be incorrect!\n");
}
}