-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathDme.bt
524 lines (430 loc) · 12.2 KB
/
Dme.bt
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
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
// 010 Editor Template for Forgelight DME files
// from Planetside 2
// July, 2018
typedef struct
{
ubyte x;
ubyte y;
ubyte z;
ubyte w;
} ubyte4n_t;
typedef struct
{
ubyte a;
ubyte r;
ubyte g;
ubyte b;
} d3dcolor_t;
typedef struct
{
float m00;
float m01;
float m02;
} xfrm_row_0_t;
typedef struct
{
float m10;
float m11;
float m12;
} xfrm_row_1_t;
typedef struct
{
float m20;
float m21;
float m22;
} xfrm_row_2_t;
typedef struct
{
float m30;
float m31;
float m32;
} xfrm_row_3_t;
////////////////////////
// USAGE TYPES
////////////////////////
typedef struct
{
float x<name="X">;
float y<name="Y">;
float z<name="Z">;
} position_t<read=fn_Read_position_t>;
typedef struct
{
hfloat u<name="U">;
hfloat v<name="V">;
} texcoord_t;
typedef struct
{
ubyte a;
ubyte r;
ubyte g;
ubyte b;
} color_t;
typedef struct
{
ubyte x;
ubyte y;
ubyte z;
ubyte w;
} tangent_t;
typedef struct
{
ubyte x;
ubyte y;
ubyte z;
ubyte w;
} binormal_t;
typedef struct
{
ubyte4n_t blendweight<name="BlendWeight", read=fn_Read_BlendWeight>;
} blendweight_t;
typedef struct
{
d3dcolor_t blendindices<name="BlendIndices", read=fn_Read_BlendIndices>;
} blendindices_t;
typedef struct
{
position_t min<name="min">;
position_t max<name="max">;
} aabb_t<read=fn_Read_AABB>;
typedef struct
{
byte magic[4]<name="Magic", fgcolor=cRed>;
uint version<name="Version">;
uint dmat_length<name="DMAT Length">;
} header_t;
typedef struct
{
string texture<name="Texture">;
} texture_t;
typedef struct
{
uint semantic_hash;
uint d3dxparameter_class;
uint d3dxparameter_type;
uint data_length;
byte data[data_length];
} material_parameter_t;
typedef struct
{
uint name_hash<name="Name Hash">;
uint materials_length<name="Materials Length">;
uint material_definition_hash<name="Material Definition Hash">;
uint parameter_count<name="Parameter Count">;
material_parameter_t parameters[parameter_count]<name="Parameters", optimize=false>;
} material_t;
typedef struct
{
byte magic[4]<name="Magic", fgcolor=cRed>;
uint version<name="Version">;
uint textures_length<name="Textures Length">;
local uint tx_start_offset = FTell();
while(FTell() < tx_start_offset + textures_length)
{
texture_t texture<name="Texture">;
};
uint material_count<name="Material Count">;
material_t materials[material_count]<name="Materials", optimize=false>;
} dmat_t;
///////////////////////////////////////////////////////////////////////////////////////////
//
// VERTEX STREAM LAYOUT STURCTURES
//
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
//Null Layout
typedef struct
{
position_t position<name="Position">;
} null_layout_t;
///////////////////////////////////////////////////////////////////////////////////////////
//Position Layout
typedef struct
{
position_t position<name="Position">;
} position_layout_t;
///////////////////////////////////////////////////////////////////////////////////////////
//POS_TEX Layout
typedef struct
{
position_t position<name="Position">;
texcoord_t texcoord<name="Texcoord">;
} pos_tex_layout_t;
///////////////////////////////////////////////////////////////////////////////////////////
//Structure Layout
typedef struct
{
position_t position<name="Position">;
} structure_layout_stream_0_t;
typedef struct
{
tangent_t tangent<name="Tangent">;
binormal_t binormal<name="Binormal">;
texcoord_t texcoord0<name="Texcoord0">;
texcoord_t texcoord1<name="Texcoord1">;
texcoord_t texcoord2<name="Texcoord2">;
} structure_layout_stream_1_t;
///////////////////////////////////////////////////////////////////////////////////////////
//Character Layout
typedef struct
{
position_t position<name="Position">;
blendweight_t blendweight<name="BlendWeight">;
blendindices_t blendindices<name="BlendIndices">;
} character_layout_stream_0_t;
typedef struct
{
tangent_t tangent<name="Tangent">;
binormal_t binormal<name="Binormal">;
texcoord_t uv0<name="UV0">;
texcoord_t uv1<name="UV1">;
texcoord_t uv2<name="UV2">;
} character_layout_stream_1_t;
///////////////////////////////////////////////////////////////////////////////////////////
//Vehicle Layout
typedef struct
{
position_t position<name="Position">;
} vehicle_layout_stream_0_t;
typedef struct
{
tangent_t tangent<name="Tangent">;
binormal_t binormal<name="Binormal">;
texcoord_t uv0<name="UV0">;
texcoord_t uv1<name="UV1">;
color_t color<name="Color">;
texcoord_t uv2<name="UV2">;
} vehicle_layout_stream_1_t;
///////////////////////////////////////////////////////////////////////////////////////////
//BumpRigid Layout
typedef struct
{
position_t position<name="Position">;
} bumprigid_layout_stream_0_t;
typedef struct
{
tangent_t tangent<name="Tangent">;
binormal_t binormal<name="Binormal">;
texcoord_t uv0<name="UV0">;
} bumprigid_layout_stream_1_t;
typedef struct
{
ushort vert_index_0<name="Vert_0">;
ushort vert_index_1<name="Vert_1">;
ushort vert_index_2<name="Vert_2">;
} triangle_t;
typedef struct
{
// uint unknown_1<name="Unknown_1">;
uint bone_start<name="Bone Start">;
uint bone_count<name="Bone Count">;
uint delta<name="Delta">;
uint unknown_2<name="Unknown_2">;
uint vertex_offset<name="Vertex Offset">;
uint vertex_count<name="Vertex Count">;
uint index_offset<name="Index Offset">;
uint index_count<name="Index Count">;
} drawcall_t;
typedef struct
{
ushort bone_index<name="Bone Index">;
ushort global_index<name="Global Index">;
} bone_map_entry_t;
typedef struct
{
xfrm_row_0_t row0<name="Row_0">;
xfrm_row_1_t row1<name="Row_1">;
xfrm_row_2_t row2<name="Row_2">;
xfrm_row_3_t row3<name="Row_3">;
} transform_t;
typedef struct
{
} mesh3_t;
typedef struct
{
uint material_index<name="Material Index">;
uint drawcall_count<name="Drawcall Count">;
uint bone_transform_count<name="Bone Transform Count">;
uint unknown<name="Unknown">;
uint vertex_stream_count<name="Vertex Stream Count">;
uint index_size<name="Index Size">;
uint index_count<name="Index Count">;
uint vertex_count<name="Vertex Count">;
local uint mat_def_hash = dmat.materials[material_index].material_definition_hash;
switch (mat_def_hash)
{
case 2201291178: //Character
{
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
character_layout_stream_0_t points[vertex_count]<name="Points", optimize=false>;
} character_stream_0_t;
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
character_layout_stream_1_t points[vertex_count]<name="Points", optimize=false>;
} character_stream_1_t;
character_stream_0_t stream0<name="Stream0">;
character_stream_1_t stream1<name="Stream1">;
break;
}
///////////////////////////////////////////////////////////////////////////////////////////
case 221567923: //Vehicle
{
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
vehicle_layout_stream_0_t points[vertex_count]<name="Points", optimize=false>;
} vehicle_stream_0_t;
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
vehicle_layout_stream_1_t points[vertex_count]<name="Points", optimize=false>;
} vehicle_stream_1_t;
vehicle_stream_0_t stream0<name="Stream0">;
vehicle_stream_1_t stream1<name="Stream1">;
break;
}
///////////////////////////////////////////////////////////////////////////////////////////
case 3731096925: //Structure
{
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
structure_layout_stream_0_t points[vertex_count]<name="Points", optimize=false>;
} structure_stream_0_t;
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
structure_layout_stream_1_t points[vertex_count]<name="Points", optimize=false>;
} structure_stream_1_t;
structure_stream_0_t stream0<name="Stream0">;
structure_stream_1_t stream1<name="Stream1">;
break;
}
case 1354477071: //BumpRigid
{
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
bumprigid_layout_stream_0_t points[vertex_count]<name="Points", optimize=false>;
} bumprigid_stream_0_t;
typedef struct
{
uint bytes_per_vertex<name="BytesPerVertex">;
bumprigid_layout_stream_1_t points[vertex_count]<name="Points", optimize=false>;
} bumprigid_stream_1_t;
bumprigid_stream_0_t stream0<name="Stream0">;
bumprigid_stream_1_t stream1<name="Stream1">;
break;
}
default:
{
break;
}
}
typedef struct
{
triangle_t faces[index_count / 3]<name="Triangles">;
} triangles_t;
triangles_t faces<name="Faces">;
/*
uint draw_call_count<name="Drawcall Count">;
//uint unknown_2<name="Unknown_2">;
FSkip(4);
drawcall_t drawcall<name="Drawcall">;
uint bone_map_entry_count<name="Bonemap Entry Count">;
typedef struct
{
bone_map_entry_t bonemap[bone_map_entry_count]<name="Bonemap", optimize=false>;
} bone_maps_t;
bone_maps_t bonemaps<name="Bonemaps">;
uint transform_count<name="Transform Count">;
transform_t transforms[transform_count]<name="Transforms">;
typedef struct
{
aabb_t transform_bbox[transform_count]<name="Transform BBox">;
} transform_bboxs_t;
transform_bboxs_t transform_bboxs<name="Transform BBox's">;
typedef struct
{
uint bone_name_hash[transform_count]<name="Bone Name Hash">;
} bone_name_hash_t;
bone_name_hash_t bone_name_hashs<name="Bone Name Hash's">;
*/
} mesh4_t;
typedef struct
{
aabb_t aabb<name="AABB">;
uint mesh_count<name="Mesh Count">;
mesh4_t mesh[mesh_count]<name="Mesh", optimize=false>;
} model4_t;
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
uint fn_Jenkins_Hash(string s, int upper)
{
if (Strlen(s) == 0)
return 0;
if (upper)
s = ToUpper(s);
int hash = 0;
int len = Strlen(s);
for (i = 0; i < len; i++)
{
hash += s[i];
hash += (hash << 10);
hash ^= (hash >> 6);
}
hash += (hash << 3);
hash ^= (hash >> 11);
hash += (hash << 15);
return (unsigned int)hash;
}
string fn_Read_AABB(aabb_t &aabb)
{
string s;
SPrintf(s, "min_xyz: %6.2f, %6.2f, %6.2f | max_xyz: %6.2f, %6.2f, %6.2f", aabb.min.x, aabb.min.y, aabb.min.z, aabb.max.x, aabb.max.y, aabb.max.z);
return s;
}
string fn_Read_position_t(position_t &pos)
{
string s;
SPrintf(s, "xyz: %6.6f, %6.6f, %6.6f", pos.x, pos.y, pos.z);
return s;
}
string fn_Read_BlendWeight(ubyte4n_t &weights)
{
string s;
float x = (float)weights.x / 255.0f;
float y = (float)weights.y / 255.0f;
float z = (float)weights.z / 255.0f;
float w = (float)weights.w / 255.0f;
return SPrintf(s, "xyzw: %6.6f, %6.6f, %6.6f, %6.6f", x, y, z, w);
}
string fn_Read_BlendIndices(d3dcolor_t &indices)
{
string s;
return SPrintf(s, "%u, %u, %u, %u", indices.a, indices.r, indices.g, indices.b);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
LittleEndian();
header_t header<name="Header">;
dmat_t dmat<name="Dmat">;
if (header.version == 3)
{
//Do nothing at this time
}
else if (header.version == 4)
{
model4_t model<name="Model">;
}
else
{
Warning( "Only able to process version 3 & 4 types of DME files." );
return -1;
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////