-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommands_NiSourceTexture.cpp
More file actions
193 lines (176 loc) · 7.03 KB
/
Commands_NiSourceTexture.cpp
File metadata and controls
193 lines (176 loc) · 7.03 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
#include "Commands_NiSourceTexture.h"
#include "obj/NiSourceTexture.h"
#include <boost/algorithm/string/find.hpp>
static bool Cmd_NiSourceTextureIsExternal_Execute(COMMAND_ARGS) {
*result = -1;
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiSourceTextureIsExternal","Getting whether an external texture is used by the NiSourceTexture (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::NiSourceTextureRef srcTex = Niflib::DynamicCast<Niflib::NiSourceTexture>(nifPtr->nifList[blockID]);
if ( srcTex ) {
try {
*result = (srcTex->IsTextureExternal()?1:0);
dPrintAndLog("NiSourceTextureIsExternal","Returning "+string(srcTex->IsTextureExternal()?"TRUE":"FALSE")+".\n");
}
catch (std::exception e) {
*result = -1;
dPrintAndLog("NiSourceTextureIsExternal","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiSourceTextureIsExternal","Not NiSourceTexture.\n");
}
else
dPrintAndLog("NiSourceTextureIsExternal","Block index out of range.\n");
}
else
dPrintAndLog("NiSourceTextureIsExternal","Nif root bad.\n");
}
else
dPrintAndLog("NiSourceTextureIsExternal","Could not find Nif.\n");
}
else
dPrintAndLog("NiSourceTextureIsExternal","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiSourceTextureIsExternal,
NiSrcTexIsExt,
"Gets whether the source texture is an external file.",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiSourceTextureGetFile_Execute(COMMAND_ARGS) {
*result = 0;
string file = " ";
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiSourceTextureGetFile","Getting the filename of the texture used by the NiSourceTexture (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::NiSourceTextureRef srcTex = Niflib::DynamicCast<Niflib::NiSourceTexture>(nifPtr->nifList[blockID]);
if ( srcTex ) {
try {
file = srcTex->GetTextureFileName();
string fileSub = "";
boost::iterator_range<string::iterator> fileRng (boost::ifind_first(file, "textures\\").end(), file.end());
for ( string::iterator i = fileRng.begin(); i != fileRng.end(); ++i )
fileSub += *i;
file = fileSub;
dPrintAndLog("NiSourceTextureGetFile","Returning \""+file+"\".\n");
}
catch (std::exception e) {
file = "";
dPrintAndLog("NiSourceTextureGetFile","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiSourceTextureGetFile","Block #"+UIntToString(blockID)+" is not NiSourceTexture.\n");
}
else
dPrintAndLog("NiSourceTextureGetFile","Block #"+UIntToString(blockID)+" is out of range.\n");
}
else
dPrintAndLog("NiSourceTextureGetFile","Nif root is bad.\n");
}
else
dPrintAndLog("NiSourceTextureGetFile","Nif not found.\n");
}
else
dPrintAndLog("Error extracting arguments.\n");
strInterface->Assign(PASS_COMMAND_ARGS, file.c_str());
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiSourceTextureGetFile,
NiSrcTexGetFile,
"Gets the source texture's filename.",
0,
kParams_OneInt_OneOptionalInt
);
static bool Cmd_NiSourceTextureSetExternalTexture_Execute(COMMAND_ARGS) {
*result = 0;
char newFile[kMaxMessageLength];
int nifID = -1;
UInt32 blockID = 0;
if (ExtractArgs(PASS_EXTRACT_ARGS, &newFile, &nifID, &blockID)) {
UInt8 modID = scriptObj->GetModIndex();
dPrintAndLog("NiSourceTextureSetExternalTexture","Setting the filename of the texture used by the NiSourceTexture (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::NiSourceTextureRef srcTex = Niflib::DynamicCast<Niflib::NiSourceTexture>(nifPtr->nifList[blockID]);
if ( srcTex ) {
try {
*result = 1;
srcTex->SetExternalTexture(string("textures\\")+newFile);
nifPtr->logChange(blockID,kNiflibType_NiSourceTexture,kNiSrcTexAct_SetExtTex,newFile,true);
dPrintAndLog("NiSourceTextureSetExternalTexture","Setting file name to \""+string(newFile)+"\".\n");
}
catch (std::exception e) {
*result = 0;
dPrintAndLog("NiSourceTextureSetExternalTexture","Exception \""+string(e.what())+"\" thrown.\n");
}
}
else
dPrintAndLog("NiSourceTextureSetExternalTexture","Block #"+UIntToString(blockID)+" is not NiSourceTexture.\n");
}
else
dPrintAndLog("NiSourceTextureSetExternalTexture","Block #"+UIntToString(blockID)+" is out of range.\n");
}
else
dPrintAndLog("NiSourceTextureSetExternalTexture","Nif is not editable.\n");
}
else
dPrintAndLog("NiSourceTextureSetExternalTexture","Nif root is bad.\n");
}
else
dPrintAndLog("NiSourceTextureSetExternalTexture","Nif not found.\n");
}
else
dPrintAndLog("NiSourceTextureSetExternalTexture","Error extracting arguments.\n");
return true;
}
DEFINE_CMD_PLUGIN_ALT(
NiSourceTextureSetExternalTexture,
NiSrcTexSetExtTex,
"Gets the source texture's filename.",
0,
kParams_OneString_OneInt_OneOptionalInt
);
void NifFile::loadChNiSourceTexture(UInt32 block, UInt32 act, std::string &val) {
if ( block < nifList.size() ) {
Niflib::NiSourceTextureRef srcTex = Niflib::DynamicCast<Niflib::NiSourceTexture>(nifList[block]);
if ( srcTex ) {
switch (act) {
case kNiSrcTexAct_SetExtTex:
srcTex->SetExternalTexture(string("textures\\")+val);
dPrintAndLog("NifLoad - NiSourceTexture","External texture change loaded.");
break;
case kNiSrcTexAct_SetIntTex:
case kNiSrcTexAct_SetPixLayout:
case kNiSrcTexAct_SetMipMapFormat:
case kNiSrcTexAct_SetAlphaFormat:
dPrintAndLog("NifLoad - NiSourceTexture","\n\n\t\tThis version of NifSE does not support these changes! Loaded nif will be incorrect!\n");
default:
dPrintAndLog("NifLoad - NiSourceTexture","\n\n\t\tUnknown change type! Loaded nif will be incorrect!\n");
}
}
else
dPrintAndLog("NifLoad - NiSourceTexture","\n\n\t\tIndicated block is not a NiSourceTexture! Change cannot be loaded; loaded nif will be incorrect!\n");
}
else
dPrintAndLog("NifLoad - NiSourceTexture","\n\n\t\tIndicated block index is out of range! Change cannot be loaded; loaded nif will be incorrect!\n");
}