-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelSwap.cpp
266 lines (217 loc) · 5.24 KB
/
ModelSwap.cpp
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
#include <stdio.h>
#include <string.h>
#define DESCRIPTION "Replaces a model filename with another one of the same or less length in an ADT."
#define ARGUMENTS "<map filename> <old filename> <new filename>"
#define USAGE( minimumArguments, argc, argv ) \
if( argc < minimumArguments + 1 ) \
{ \
printf( " %s\n", argv[0] ); \
printf( " " DESCRIPTION "\n\n" ); \
printf( " Usage: \"%s " ARGUMENTS "\"\n", argv[0] ); \
printf( " Built at: " __DATE__ "\n" ); \
return -1; \
}
FILE *Input;
struct MCIN{
unsigned int Offset;
unsigned int Size;
unsigned int Temp1;
unsigned int Temp2;
};
/*
MCNK
0x14 MCVT Offset
0x18 MCNR Offset
0x1C MCLY Offset
0x20 MCRF Offset
0x24 MCAL Offset
0x2C MCSH Offset
0x52 MCSE Offset
0x60 MCLQ Offset
0x68 Z' Base Coordinate
0x6C X' Base Coordinate
0x70 Y Base Coordinate
*/
struct MCNK{
float Z;
float X;
float Y;
};
struct Pos
{
float x;
float y;
float z;
};
struct MCLQ
{
int Enabled;
float First;
float Vertex[81];
int Flags[81];
float Last;
};
MCIN Positions[256];
MCNK ADTOffsets[256];
MCLQ WaterLevels[256];
unsigned int MCNK_Positions[256];
unsigned int MTEX_Offset;
unsigned int MMDX_Offset;
unsigned int MMID_Offset;
unsigned int MWMO_Offset;
unsigned int MWID_Offset;
unsigned int MDDF_Offset;
unsigned int MODF_Offset;
int NumDoodads;
Pos *Doodads;
unsigned char *File;
unsigned int FileSize;
struct DDF
{
unsigned int ID;
unsigned int UniqueID;
float Pos[3];
float Rot[3];
unsigned int Scale;
};
struct WMO
{
unsigned int ID;
unsigned int UniqueID;
float Pos[3];
float Rot[3];
float Pos2[3];
float Pos3[3];
short Unknown1;
short DoodadIndex;
unsigned int Unknown2;
};
int NumWMOs;
WMO *WMOs;
char *Textures;
char *MDXFiles;
int diffMDXs;
int *MDXOffsets;
char *WMOFiles;
int diffWMOs;
int *WMOOffsets;
int NumDDFs;
DDF *DDFs;
char *ReplacingMe;
char *TheReplacement;
void FindMDDFandMODF()
{
fseek(Input,0x1c,SEEK_SET);
fread(&MTEX_Offset,sizeof(unsigned int),1,Input);
fread(&MMDX_Offset,sizeof(unsigned int),1,Input);
fread(&MMID_Offset,sizeof(unsigned int),1,Input);
fread(&MWMO_Offset,sizeof(unsigned int),1,Input);
fread(&MWID_Offset,sizeof(unsigned int),1,Input);
fread(&MDDF_Offset,sizeof(unsigned int),1,Input);
fread(&MODF_Offset,sizeof(unsigned int),1,Input);
}
short Map[256];
void LoadMTEX()
{
unsigned int TexSize;
fseek(Input,0x14+0x04+MTEX_Offset,SEEK_SET);
fread(&TexSize,sizeof(int),1,Input);
Textures=new char[TexSize];
fread(Textures,sizeof(char),TexSize,Input);
for(int i=0;i<TexSize-1;i++)
if (Textures[i]==0)
Textures[i]='\n';
}
void LoadMDXs()
{
unsigned int temp,temp2;
temp2=0x14+0x04+MMDX_Offset;
fseek(Input,0x14+0x04+MMDX_Offset,SEEK_SET);
fread(&temp,sizeof(int),1,Input);
printf("Position %d Size %d\n",temp2,temp);
MDXFiles=new char[temp];
fread(MDXFiles,sizeof(char),temp,Input);
fseek(Input,0x14+0x04+MMID_Offset,SEEK_SET);
fread(&temp,sizeof(int),1,Input);
diffMDXs=temp/4;
MDXOffsets=new int[diffMDXs];
fread(MDXOffsets,sizeof(int),diffMDXs,Input);
for (int i=0;i<diffMDXs ;i++ )
{
if(strcmp(ReplacingMe,MDXFiles+MDXOffsets[i])==0)
{
printf("Replacing %i (%s) with %s length %d\n",i,MDXFiles+MDXOffsets[i],TheReplacement,strlen(ReplacingMe));
memcpy(MDXFiles+MDXOffsets[i],TheReplacement,strlen(TheReplacement)+1);
}
}
fseek(Input,temp2,SEEK_SET);
fread(&temp,sizeof(int),1,Input);
fseek(Input,0,SEEK_CUR);
fwrite(MDXFiles,1,temp,Input);
}
void LoadWMOs()
{
unsigned int temp;
fseek(Input,0x14+0x04+MWMO_Offset,SEEK_SET);
fread(&temp,sizeof(int),1,Input);
WMOFiles=new char[temp];
fread(WMOFiles,sizeof(char),temp,Input);
fseek(Input,0x14+0x04+MWID_Offset,SEEK_SET);
fread(&temp,sizeof(int),1,Input);
diffWMOs=temp/4;
WMOOffsets=new int[diffWMOs];
fread(WMOOffsets,sizeof(int),diffWMOs,Input);
fseek(Input,0x14+0x04+MODF_Offset,SEEK_SET);
fread(&NumWMOs,sizeof(unsigned int),1,Input);
NumWMOs=NumWMOs/64;
WMOs=new WMO[NumWMOs];
fread(WMOs,sizeof(WMO),NumWMOs,Input);
}
void LoadMCLQ()
{
float WaterLevel;
unsigned int *Test;
char Temp[8];
Test=(unsigned int *)&WaterLevel;
for (int i=0;i<256;i++)
{
fseek(Input,MCNK_Positions[i],SEEK_SET);
fread(Temp,1,8,Input);
fread(Test,sizeof(float),1,Input);
if((*Test)==0x4d435345)
{
WaterLevels[i].Enabled=0;
continue;
}
WaterLevels[i].Enabled=1;
WaterLevels[i].First=WaterLevel;
for(int j=0;j<81;j++)
{
fread(&(WaterLevels[i].Vertex[j]),sizeof(float),1,Input);
fread(&(WaterLevels[i].Flags[j]),sizeof(float),1,Input);
}
fread(&(WaterLevels[i].Last),sizeof(float),1,Input);
}
}
int main(int argc, char **argv)
{
USAGE( 3, argc, argv );
int i;
char *replace;
printf("Replacing in File %s\n",argv[1]);
ReplacingMe=argv[2];
TheReplacement=argv[3];
if(strlen(TheReplacement)<=strlen(ReplacingMe))
printf("Replacing %s with %s\n",ReplacingMe,TheReplacement);
else
{
printf("The replacement string is too long\n");
return 0;
}
Input=fopen(argv[1],"rb+");
FindMDDFandMODF();
// LoadMTEX();
LoadMDXs();
// LoadWMOs();
fclose(Input);
}