-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddDetailDoodads.cpp
More file actions
159 lines (127 loc) · 3.03 KB
/
AddDetailDoodads.cpp
File metadata and controls
159 lines (127 loc) · 3.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
#define DESCRIPTION "Adds detail doodads per texture filename."
#define ARGUMENTS "<map 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; \
}
struct MCIN{
unsigned int Offset;
unsigned int void1;
unsigned int void2;
unsigned int void3;
};
struct MCLY
{
unsigned int textureId;
unsigned int void1;
unsigned int void2;
unsigned int effectId;
};
FILE *Input;
char *File;
char *MTEX;
unsigned int FileSize;
char *NewFile;
unsigned int NewFileSize;
unsigned int Change;
MCIN *Positions;
MCLY Layer;
int DoodadForTexture[100];
unsigned int MCLQ_Positions[256];
unsigned int MCSE_Positions[256];
void FindMCNKs()
{
Positions=(MCIN *)(File+92);
for(int i =0;i<100;i++)
{
DoodadForTexture[i] = -1;
}
}
void FindTextures()
{
int nTex=0;
fseek(Input,0x1060,SEEK_SET);
fread(&nTex,sizeof(unsigned int),1,Input);
char text[nTex];
fseek(Input,0x1064,SEEK_SET);
fread(text,sizeof(char),nTex,Input);
int i = 0;
int j = 0;
while(i<nTex)
{
printf("please assign doodads to: \n\t");
while(text[i]!='\0')
{
printf("%c",text[i]);
i++;
}
printf("\n (-1: no change to existing doodads)\n");
int newd;
cin >> newd;
DoodadForTexture[j] = newd;
j++;
i++;
}
}
void addDoodads()
{
unsigned int *TFloat;
unsigned int *TInt=0;
unsigned int T=0;
unsigned int nlayers;
for (int i=0;i<256;i++)
{
fseek(Input,Positions[i].Offset+0x8+0x1C,SEEK_SET);
fread(&T,sizeof(unsigned int),1,Input);
T=T+Positions[i].Offset;
fseek(Input,Positions[i].Offset+0x8+0x0C,SEEK_SET);
fread(&nlayers,sizeof(unsigned int),1,Input);
printf("found chunk %d with %d layers (@0x%x)\n",i,nlayers,T);
// Layers=(MCLY *)(TInt+8);
for (int j = 0;j < nlayers;j++)
{
fseek(Input,T+8+(sizeof(struct MCLY))*j,SEEK_SET);
fread(&Layer,sizeof(struct MCLY),1,Input);
// printf("%d> texture %d, doodads %d\n",j,Layer.textureId,Layer.effectId);
if (DoodadForTexture[Layer.textureId]!=-1)
{
Layer.effectId = DoodadForTexture[Layer.textureId];
}
fseek(Input,T+8+(sizeof(struct MCLY))*j,SEEK_SET);
fwrite(&Layer,0x10,1,Input);
}
// if(i%10==0)
// system("pause");
}
}
int main(int argc, char **argv)
{
USAGE( 1, argc, argv );
char *replace;
int i,len;
printf("Adding doodads to layers in file %s\n\n",argv[1]);
Input=fopen(argv[1],"rb+");
fseek(Input,0,SEEK_END);
FileSize=ftell(Input);
NewFileSize=FileSize;
File=new char[FileSize];
fseek(Input,0,SEEK_SET);
fread(File,1,FileSize,Input);
Change=0;
FindMCNKs();
FindTextures();
addDoodads();
fclose(Input);
delete File;
}