-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderware.h
427 lines (355 loc) · 9.31 KB
/
renderware.h
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#ifndef _RENDERWARE_H_
#define _RENDERWARE_H_
#ifdef _WIN32
#include <windows.h>
#endif
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
namespace rw {
typedef char int8;
typedef short int16;
typedef long int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned long uint32;
typedef float float32;
extern char *filename;
extern uint32 version;
#ifdef DEBUG
#define READ_HEADER(x)\
header.read(dff);\
if (header.type != (x)) {\
cerr << filename;\
ChunkNotFound((x), dff.tellg());\
}
#else
#define READ_HEADER(x)\
header.read(dff);
#endif
enum PLATFORM_ID
{
PLATFORM_PS2 = 4,
PLATFORM_XBOX = 5,
PLATFORM_D3D8 = 8,
PLATFORM_D3D9 = 9
};
typedef enum PLATFORM_ID PLATFORM_ID;
enum CHUNK_TYPE {
CHUNK_NAOBJECT = 0x0,
CHUNK_STRUCT = 0x1,
CHUNK_STRING = 0x2,
CHUNK_EXTENSION = 0x3,
CHUNK_CAMERA = 0x5,
CHUNK_TEXTURE = 0x6,
CHUNK_MATERIAL = 0x7,
CHUNK_MATLIST = 0x8,
CHUNK_ATOMICSECT = 0x9,
CHUNK_PLANESECT = 0xA,
CHUNK_WORLD = 0xB,
CHUNK_SPLINE = 0xC,
CHUNK_MATRIX = 0xD,
CHUNK_FRAMELIST = 0xE,
CHUNK_GEOMETRY = 0xF,
CHUNK_CLUMP = 0x10,
CHUNK_LIGHT = 0x12,
CHUNK_UNICODESTRING = 0x13,
CHUNK_ATOMIC = 0x14,
CHUNK_TEXTURENATIVE = 0x15,
CHUNK_TEXDICTIONARY = 0x16,
CHUNK_ANIMDATABASE = 0x17,
CHUNK_IMAGE = 0x18,
CHUNK_SKINANIMATION = 0x19,
CHUNK_GEOMETRYLIST = 0x1A,
CHUNK_ANIMANIMATION = 0x1B,
CHUNK_HANIMANIMATION = 0x1B,
CHUNK_TEAM = 0x1C,
CHUNK_CROWD = 0x1D,
CHUNK_RIGHTTORENDER = 0x1F,
CHUNK_MTEFFECTNATIVE = 0x20,
CHUNK_MTEFFECTDICT = 0x21,
CHUNK_TEAMDICTIONARY = 0x22,
CHUNK_PITEXDICTIONARY = 0x23,
CHUNK_TOC = 0x24,
CHUNK_PRTSTDGLOBALDATA = 0x25,
CHUNK_ALTPIPE = 0x26,
CHUNK_PIPEDS = 0x27,
CHUNK_PATCHMESH = 0x28,
CHUNK_CHUNKGROUPSTART = 0x29,
CHUNK_CHUNKGROUPEND = 0x2A,
CHUNK_UVANIMDICT = 0x2B,
CHUNK_COLLTREE = 0x2C,
CHUNK_ENVIRONMENT = 0x2D,
CHUNK_COREPLUGINIDMAX = 0x2E,
CHUNK_MORPH = 0x105,
CHUNK_SKYMIPMAP = 0x110,
CHUNK_SKIN = 0x116,
CHUNK_PARTICLES = 0x118,
CHUNK_HANIM = 0x11E,
CHUNK_MATERIALEFFECTS = 0x120,
CHUNK_ADCPLG = 0x134,
CHUNK_BINMESH = 0x50E,
CHUNK_NATIVEDATA = 0x510,
CHUNK_PIPELINESET = 0x253F2F3,
CHUNK_SPECULARMAT = 0x253F2F6,
CHUNK_2DFX = 0x253F2F8,
CHUNK_NIGHTVERTEXCOLOR = 0x253F2F9,
CHUNK_COLLISIONMODEL = 0x253F2FA,
CHUNK_REFLECTIONMAT = 0x253F2FC,
CHUNK_MESHEXTENSION = 0x253F2FD,
CHUNK_FRAME = 0x253F2FE
};
typedef enum CHUNK_TYPE CHUNK_TYPE;
#define NORMALSCALE (float32) 1/128
#define VERTSCALE1 (float32) 1/128 /* normally used */
#define VERTSCALE2 (float32) 1/1024 /* used by cars and peds */
#define UVSCALE (float32) 1/4096
enum {
FLAGS_TRISTRIP = 0x01,
FLAGS_POSITIONS = 0x02,
FLAGS_TEXTURED = 0x04,
FLAGS_PRELIT = 0x08,
FLAGS_NORMALS = 0x10,
FLAGS_LIGHT = 0x20,
FLAGS_MODULATEMATERIALCOLOR = 0x40,
FLAGS_TEXTURED2 = 0x80
};
#define MATFX_BUMPMAP 0x1
#define MATFX_ENVMAP 0x2
#define MATFX_BUMPENVMAP
#define MATFX_DUAL 0x4
#define MATFX_UVTRANSFORM 0x5
#define MATFX_DUALUVTRANSFORM 0x6
#define FACETYPE_STRIP 0x1
#define FACETYPE_LIST 0x0
/* gta3 ps2: 302, 304, 310
* gta3 pc: 304, 310, 401ffff, 800ffff, c02ffff
* gtavc ps2: c02ffff
* gtavc pc: c02ffff, 800ffff, 1003ffff
* gtasa: 1803ffff */
enum {
GTA3_1 = 0x00000302,
GTA3_2 = 0x00000304,
GTA3_3 = 0x00000310,
GTA3_4 = 0x0800FFFF,
VCPS2 = 0x0C02FFFF,
VCPC = 0x1003FFFF,
SA = 0x1803FFFF
};
struct Frame
{
float32 rotationMatrix[9];
float32 position[3];
int32 parent;
/* Extensions */
/* node name */
std::string name;
/* hanim */
bool hasHAnim;
uint32 hAnimUnknown1;
int32 hAnimBoneId;
uint32 hAnimBoneCount;
uint32 hAnimUnknown2;
uint32 hAnimUnknown3;
std::vector<int32> hAnimBoneIds;
std::vector<uint32> hAnimBoneNumbers;
std::vector<uint32> hAnimBoneTypes;
/* functions */
void readStruct(std::ifstream &dff);
void readExtension(std::ifstream &dff);
uint32 writeStruct(std::ofstream &dff);
uint32 writeExtension(std::ofstream &dff);
Frame(void);
~Frame(void);
};
struct Atomic
{
uint32 frameIndex;
uint32 geometryIndex;
/* Extensions */
/* right to render */
bool hasRightToRender;
uint32 rightToRenderVal1;
uint32 rightToRenderVal2;
/* particles */
bool hasParticles;
uint32 particlesVal;
/* pipelineset */
bool hasPipelineSet;
uint32 pipelineSetVal;
/* material fx */
bool hasMaterialFx;
uint32 materialFxVal;
/* functions */
void read(std::ifstream &dff);
uint32 write(std::ofstream &dff);
void readExtension(std::ifstream &dff);
Atomic(void);
~Atomic(void);
};
struct Texture
{
uint32 filterFlags;
std::string name;
std::string maskName;
/* Extensions */
/* sky mipmap */
bool hasSkyMipmap;
/* functions */
void read(std::ifstream &dff);
uint32 write(std::ofstream &dff);
void readExtension(std::ifstream &dff);
Texture(void);
~Texture(void);
};
struct Material
{
uint32 flags;
uint8 color[4];
uint32 unknown;
bool hasTex;
float32 surfaceProps[3]; /* ambient, specular, diffuse */
Texture texture;
/* Extensions */
/* right to render */
bool hasRightToRender;
uint32 rightToRenderVal1;
uint32 rightToRenderVal2;
/* matfx */
// todo
Texture reflection;
/* reflection mat */
bool hasReflectionMat;
float32 reflectionChannelAmount[4];
float32 reflectionIntensity;
/* specular mat */
bool hasSpecularMat;
float32 specularLevel;
std::string specularName;
/* uv anim */
// to do
/* functions */
void read(std::ifstream &dff);
void readExtension(std::ifstream &dff);
uint32 write(std::ofstream &dff);
Material(void);
~Material(void);
};
struct MeshExtension
{
uint32 unknown;
std::vector<float32> vertices;
std::vector<float32> texCoords;
std::vector<uint8> vertexColors;
std::vector<uint16> faces;
std::vector<uint16> assignment;
std::vector<std::string> textureName;
std::vector<std::string> maskName;
std::vector<float32> unknowns;
};
struct Split
{
uint32 matIndex;
std::vector<uint32> indices;
};
struct Geometry
{
uint32 flags;
uint32 numUVs;
bool hasNativeGeometry;
uint32 vertexCount;
std::vector<float32> vertices;
std::vector<float32> normals;
std::vector<uint16> faces;
std::vector<uint8> vertexColors;
std::vector<float32> texCoords1;
std::vector<float32> texCoords2;
float32 boundingSphere[4];
uint32 bsPos;
uint32 bsNor;
std::vector<Material> materialList;
/* Extensions */
/* bin mesh */
uint32 faceType;
uint32 numIndices;
std::vector<Split> splits;
/* skin */
bool hasSkin;
uint32 boneCount;
uint32 specialIndexCount;
uint32 unknown1;
uint32 unknown2;
std::vector<uint8> specialIndices;
std::vector<uint32> vertexBoneIndices;
std::vector<float32> vertexBoneWeights;
std::vector<float32> inverseMatrices;
/* mesh extension */
bool hasMeshExtension;
MeshExtension *meshExtension;
/* night vertex colors */
bool hasNightColors;
uint32 nightColorsUnknown;
std::vector<uint8> nightColors;
/* 2dfx */
// to do
/* morph (only flag) */
bool hasMorph;
/* functions */
void read(std::ifstream &dff);
uint32 write(std::ofstream &dff);
void readExtension(std::ifstream &dff);
void readMeshExtension(std::ifstream &dff);
uint32 writeMeshExtension(std::ofstream &dff);
void readXboxNativeData(std::ifstream &dff);
void readPs2NativeData(std::ifstream &dff);
void deleteOverlapping(std::vector<uint32> &typesRead, uint32 split);
void readData(uint32 vertexCount, uint32 type,
uint32 split, std::ifstream &dff);
bool isDegenerateFace(uint32 i, uint32 j, uint32 k);
void generateFaces(void);
Geometry(void);
~Geometry(void);
void writeMsh(std::ofstream &msh);
};
struct Clump
{
std::vector<Atomic> atomicList;
std::vector<Frame> frameList;
std::vector<Geometry> geometryList;
/* Extensions */
/* collision file */
// to do
/* functions */
bool read(std::ifstream &dff);
void readExtension(std::ifstream &dff);
void write(std::ofstream &dff);
Clump(void);
~Clump(void);
void writeMsh(std::ofstream &msh);
};
struct HeaderInfo
{
uint32 type;
uint32 length;
uint32 version;
void read(std::ifstream &rw);
uint32 write(std::ofstream &rw);
};
void ChunkNotFound(CHUNK_TYPE chunk, uint32 address);
uint32 writeInt8(int8 tmp, std::ofstream &rw);
uint32 writeUInt8(uint8 tmp, std::ofstream &rw);
uint32 writeInt16(int16 tmp, std::ofstream &rw);
uint32 writeUInt16(uint16 tmp, std::ofstream &rw);
uint32 writeInt32(int32 tmp, std::ofstream &rw);
uint32 writeUInt32(uint32 tmp, std::ofstream &rw);
uint32 writeFloat32(float32 tmp, std::ofstream &rw);
int8 readInt8(std::ifstream &rw);
uint8 readUInt8(std::ifstream &rw);
int16 readInt16(std::ifstream &rw);
uint16 readUInt16(std::ifstream &rw);
int32 readInt32(std::ifstream &rw);
uint32 readUInt32(std::ifstream &rw);
float32 readFloat32(std::ifstream &rw);
}
#endif