/
bspv66.bt
462 lines (363 loc) · 7.66 KB
/
bspv66.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
struct LTVector {
float x, y, z;
};
struct LTQuaternion {
float x, y, z, w;
};
struct LTString {
short Length;
char Value[Length];
};
typedef uint32 uint32_t;
// NOLF version 66 - PC
struct WorldHeader {
uint32_t Version;
uint32_t ObjectDataPosition;
uint32_t RenderDataPosition;
uint32_t Dummy[8];
};
struct WorldInfo {
uint32_t Length;
char Value[Length];
float LMGridSize;
LTVector BoundaryMin;
LTVector BoundaryMax;
};
struct WorldTree {
LTVector BoxMin;
LTVector BoxMax;
int NumNodes;
int DummyTerrainDepth;
};
struct WorldProp {
short Unknown[4];
uchar Padding;
short PropNameLength;
char PropName[PropNameLength];
};
struct WorldTexture (int NameLength) {
char Name[NameLength];
};
//low=input & 0xff
//high=(input>>8) & 0xff
struct HighLowByte {
uchar High;
uchar Low;
};
struct Vertex {
/*
union {
HighLowByte SplitByte;
ushort Bytes;
} Bytes;
*/
//ushort Count;
uchar Count;
uchar Extra;
};
struct LeafData {
short PortalID;
ushort Size;
uchar Contents[Size];
};
struct Leaf {
ushort LeafListCount;
if (LeafListCount == 0xFFFF) {
ushort LeafListIndex;
} else {
LeafData Data[LeafListCount] <optimize=false>;
}
int PolygonCount;
char Polygons[PolygonCount * 4] <optimize=false>;
int Unk1;
};
struct Plane {
LTVector Normal;
float Distance;
};
struct Surface {
LTVector UV1;
LTVector UV2;
LTVector UV3;
ushort Texture;
//uchar Unk[4];
int Unk1;
int Flags;
uchar Unk2[4];
uchar UseEffects;
if (UseEffects > 0) {
LTString Effect;
LTString EffectParam;
}
ushort TextureFlags;
};
struct Point {
LTVector Data;
LTVector Normals;
};
struct DiskVert {
short Verts;
uchar Dummy[3];
};
struct Polygon (Vertex &VertexInfo) {
LTVector Center;
short LightmapWidth;
short LightmapHeight;
short Unknown;
if (Unknown > 0) {
short MoreUnknown[Unknown * 2];
}
short SurfaceIndex;
short PlaneIndex;
/*
LTVector UV1;
LTVector UV2;
LTVector UV3;
*/
DiskVert Verts[VertexInfo.Count + VertexInfo.Extra];
};
struct Node {
int PolyIndex;
short LeafIndex;
int NodeIndexes[2];
};
struct UserPortal {
LTString Name;
int Unk1;
int Unk2;
ushort Unk3;
LTVector Center;
LTVector Dims;
};
struct PBlockContents {
uchar VertIndex;
uchar Padding;
uchar Quat[4];
};
struct PBlock {
short Size;
short Unk1;
PBlockContents Contents[Size];
};
struct PBlockTable {
//LTVector UnkVec[8]; // Physics?
int Unk1;
int Unk2;
int Unk3;
local int Size = Unk1*Unk2*Unk3;
LTVector Unk4;
LTVector Unk5;
PBlock Block[Size] <optimize=false>;
};
struct WorldBSP {
int InfoFlags;
int Unknown;
LTString WorldName;
int PointCount;
int PlaneCount;
int SurfaceCount;
int UserPortalCount;
int PolyCount;
int LeafCount;
int VertCount;
int TotalVisListSize;
int LeafListCount;
int NodeCount;
int Unknown2;
int Unknown3;
LTVector MinBox;
LTVector MaxBox;
LTVector WorldTranslation;
int TextureNameLength;
int TextureCount;
WorldTexture WorldTextures(TextureNameLength);
Vertex Vertices[PolyCount];
Leaf LeafList[LeafCount] <optimize=false>;
Plane Planes[PlaneCount];
Surface Surfaces[SurfaceCount] <optimize=false>;
local int i = 0;
for (i = 0; i < PolyCount; i++) {
Polygon Poly(Vertices[i]);
}
Node Nodes[NodeCount];
UserPortal Portals[UserPortalCount];
Point Points[PointCount];
PBlockTable BlockTable;
int RootNodeIndex;
int Sections;
};
struct WorldModel {
int NextWorldItem;
char Padding2[32];
WorldBSP BSPData;
if (BSPData.Sections > 0) {
FSeek(NextWorldItem);
}
};
struct WorldModelHeader {
int Count;
WorldModel model[Count] <optimize=false>;
};
struct WorldTreeNode {
int Children;
};
/*
{ PT_STRING = 0;
PT_VECTOR = 1;
PT_COLOR = 2;
PT_REAL = 3;
PT_FLAGS = 4;
PT_BOOL = 5;
PT_LONGINT = 6;
PT_ROTATION = 7; }
*/
struct ObjectProperty {
LTString Name;
char Code;
int Flags;
short DataLength;
switch(Code) {
case 0: // String
LTString Value;
break;
case 1: // Vector
case 2: // Color
LTVector Value;
break;
case 3: // Float
float Value;
break;
case 5: // Bool
char Value;
break;
case 4: // Flags
case 6: // Long Int
uint Value;
break;
case 7: // Rotation
LTQuaternion Value;
break;
};
};
struct WorldObject {
ushort DataLength;
LTString TypeString;
int PropertyCount;
ObjectProperty Properties[PropertyCount] <optimize=false>;
};
struct WorldObjectHeader {
int Count;
WorldObject objects[Count] <optimize=false>;
};
struct LightmapFrame {
short ModelIndex;
short PolyIndex;
};
struct BatchData (int Size) {
uchar Data[Size] <optimize=false>;
};
struct LightmapBatch (int FrameCount) {
local int i = 0;
// Frames?
for (i = 0; i < FrameCount; i++) {
int Size;
BatchData Data(Size);
}
};
// Vertex Colour
struct VertexColourBatch (int FrameCount) {
local int i = 0;
// Frames?
for (i = 0; i < FrameCount; i++) {
int Size;
//uchar Colour[Size] <optimize=false>;
BatchData Data(Size);
}
};
struct VertexColours {
uchar VertexCount;
if (VertexCount == 0) {
return;
}
uchar R[VertexCount];
uchar G[VertexCount];
uchar B[VertexCount];
};
struct LightmapData {
LTString Name;
int Type;
int BatchCount;
int FrameCount;
LightmapFrame Frames[FrameCount] <optimize=false>;
LightmapBatch Batches(FrameCount)[BatchCount] <optimize=false>;
//VertexColours Colours[FrameCount] <optimize=false>;
};
struct LightmapDataHeader {
int TotalFrames1;
int TotalAnimations;
int TotalMemory;
int TotalFrames2;
int Count;
LightmapData Data[Count] <optimize=false>;
};
struct RenderData {
LightmapDataHeader LightmapHeader;
};
void subdivide() {
// We need to set the nodes bounding box here based off the tree's bounding box.
/*
// -x -z
LTVector firstMin;
LTVector firstMax;
// -x +z
LTVector secondMin;
LTVector secondMax;
// +x -z
LTVector thirdMin;
LTVector thirdMax;
// +x +z
LTVector forthMin;
LTVector forthMax;
*/
};
struct DEBUG_BYTE {
byte val;
};
void read_layout(int ¤t_byte, int ¤t_bit, int ¤t_offset, int depth)
{
if (current_bit == 8)
{
DEBUG_BYTE subdivision_data;
current_byte = subdivision_data.val;//ReadByte();
current_bit = 0;
}
local int subdivide = false;
if ((current_byte & (1 << current_bit)) > 0) {
subdivide = true;
}
//local int subdivide = (current_byte & (1 << current_bit)) > 0;
current_bit++;
//Printf("Depth %d", depth);
if (depth > 16) {
return;
}
if (subdivide)
{
local int i = 0;
subdivide();
for ( i = 0; i < 4; i++ )
{
read_layout(current_byte, current_bit, current_offset, depth + 1);
}
}
}
WorldHeader header;
WorldInfo info;
WorldTree tree;
local int currentByte = 0;
local int currentBit = 8;
local int currentOffset = 0;
read_layout(currentByte, currentBit, currentOffset, 0);
WorldModelHeader modelHeader;
WorldObjectHeader objectHeader;
RenderData renderData;