This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
RES.bt
423 lines (387 loc) · 8.11 KB
/
RES.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
//------------------------------------------------
//--- 010 Editor v8.0.1 Binary Template
//
// File: RES.bt
// Authors: Alexandr Evdokimov
// Version: 1.0
// Purpose: Hard Truck: Road to Victory, Hard Truck 2 King of the road RES/RMP file
//
// History:
//
// 2018.10 v 1.0 minor fixes and changes
// 2018.08 v 0.3 add Hard Truck: RtV structures
// 2018.05 v 0.1 initial release
//
//------------------------------------------------
local uint count, size, n;
local uint passthrough = 0;
local char Name[4];
uint getNumber(string Str) {
local uint pos = 0, count = 0;
local string S;
pos = Strchr(Str, ' ');
S = SubStr(Str, pos + 1, Strlen(Str) - pos);
if (SScanf(S, "%d", count) > 0)
return count;
else
return 1;
}
string getID(string Str) {
local uint pos = 0;
local string S;
pos = Strchr(Str, ' ');
return SubStr(Str, 0, pos);
}
typedef enum <char> {
PFRM,
LVMP,
ENDR,
MS16,
MASK,
PALT,
OPAC,
INTE,
MSK8
} IDENTIFIER;
typedef struct {
UINT SectionSize;
UINT type;
UINT Width;
UINT Height;
UINT HS;
local uint w,h;
w = Width; h = Height;
while (w >= 1) {
typedef struct {
UBYTE Blue: 5;
UBYTE Green: 5;
UBYTE Red: 5;
UBYTE Alpha: 1;
} PIXEL_RGB16;
typedef struct (int arraySize) {
PIXEL_RGB16 array[arraySize];
} PIXEL_RGB16_Array;
PIXEL_RGB16_Array Pixels(w*h);
w = w/2; h = h/2;
};
BYTE A[2];
} LVMP;
typedef struct {
UINT Size;
UINT RedMask;
UINT GreenMask;
UINT BlueMask;
UINT AlphaMask;
BYTE Unknown[12];
} PFRM;
BitfieldDisablePadding();
typedef struct {
struct {
WORD W;
WORD H;
} HEADER;
BYTE Data[768];
} MS16 <optimize=false>;
typedef struct {
struct {
WORD W;
WORD H;
} HEADER;
BYTE Data[768];
} MASK <optimize=false>;
typedef struct {
struct {
WORD W;
WORD H;
} HEADER;
BYTE Data[768]; // empty
} MSKR <optimize=false>;
typedef struct {
struct {
WORD W;
WORD H;
} HEADER;
BYTE Data[768]; // empty
} MS8 <optimize=false>;
typedef struct {
struct {
string FileName;
UINT SectionSize;
IDENTIFIER identifier[4];
} HEADER;
switch (HEADER.identifier)
{
case "MSKR":
MSKR mskr;
break;
case "MS16":
MS16 ms16;
break;
case "MSK8":
MS8 ms8;
break;
default :
MASK mask;
break;
};
BYTE Data[HEADER.SectionSize - 776];
} MS <name=maskFileName>;
string maskFileName(MS &ms) {
return ms.HEADER.FileName;
}
typedef struct {
string Name;
} ID <name = idName>;
string idName(ID &id) {
return "ID: " + id.Name;
}
typedef struct {
string Name;
} NAME <name=Name>;
typedef struct (int arraySize) {
NAME array[arraySize] <optimize=false>;
} NAME_ARRAY;
string Name(NAME &n) {
return n.Name;
}
typedef struct {
struct {
UINT Width;
UINT Height;
UINT Size;
} HEADER;
struct {
BYTE Data[HEADER.Size];
} OPAC_FILE[HEADER.Width*HEADER.Height];
} OPAC;
typedef struct {
struct {
UINT Width;
UINT Height;
UINT Size;
} HEADER;
struct {
UINT16 Data[HEADER.Size/2];
} OPAC16_FILE[HEADER.Width*HEADER.Height];
} OP16;
typedef struct {
struct {
UBYTE Red;
UBYTE Green;
UBYTE Blue;
} COLOR[256];
} PALT;
typedef struct {
struct {
UINT Width;
UINT Height;
UINT Size;
} HEADER;
struct {
BYTE Data[HEADER.Size];
} FOG_FILE[HEADER.Height];
} FOG;
typedef struct {
struct {
UINT Width;
UINT Height;
UINT Size;
} HEADER;
struct {
BYTE Data[HEADER.Size];
} FO16_FILE[HEADER.Height];
} FO16;
typedef struct {
struct {
UINT Width;
UINT Height;
UINT Size;
} HEADER;
struct {
BYTE Data[HEADER.Size];
} INTE_FILE[HEADER.Height];
} INTE;
typedef struct {
struct {
UINT Width;
UINT Height;
UINT Size;
} HEADER;
struct {
UINT16 Data[HEADER.Size/2];
} IN16_FILE[HEADER.Height];
} IN16;
typedef struct {
UBYTE IDLength;
UBYTE ColorMapType;
UBYTE ImageType;
WORD FirstIndexEntry;
WORD ColorMapLength;
UBYTE ColorMapEntrySize;
WORD XOrigin;
WORD YOrigin;
WORD Width;
WORD Height;
UBYTE PixelDepth;
UBYTE ImageDescriptor;
} TGA_HEADER;
typedef struct {
string FileName;
UINT SectionSize;
TGA_HEADER TGAHEADER;
// LineOffset
n = ReadInt(FTell());
size = SectionSize - sizeof(TGA_HEADER);
if (n == 1179012940)
{ // "LOFF"
IDENTIFIER Loff[4];
UINT Size;
UINT Offset;
size = SectionSize - sizeof(TGA_HEADER) - 12 - 44;
BYTE ImageData[size];
if (Offset)
{
IDENTIFIER id[4];
if (id == "LVMP")
{
LVMP lvmp;
IDENTIFIER id[4];
PFRM pfrm;
} else
PFRM pfrm;
IDENTIFIER Endr[4];
UINT Size;
};
}
else
BYTE Data[size];
} TXR <optimize=false, name=txrName>;
string txrName(TXR &txr) {
return txr.FileName;
}
typedef struct {
char PLM[4]; // signature
UINT DataSize;
while (true)
{
struct {
IDENTIFIER id[4];
UINT DataSize;
} HEADER;
if (HEADER.id == "PALT")
PALT Palette;
else
if (HEADER.id == "OPAC")
OPAC Opac;
else
//if (HEADER.id == "OP16")
// OP16 Opac16;
//else
if (HEADER.id == "FOG")
FOG Fog;
else
//if (HEADER.id == "FO16")
// FO16 Fog16;
//else
if (HEADER.id == "INTE")
INTE Inte;
else
//if (HEADER.id == "IN16")
// IN16 Inte16;
//else
{
FSkip(-8);
break;
};
};
} PLM_FILE;
typedef struct {
string FileName;
UINT DataSize;
TGA_HEADER Header;
FSkip(DataSize - sizeof(Header));
} BACKFILE <optimize=false, name=bfName>;
typedef struct (int arraySize) {
BACKFILE array[arraySize] <optimize=false>;
} BACKFILE_ARRAY;
string bfName(BACKFILE &backfile) {
return backfile.FileName;
}
local uint i = 0;
local string idname;
while (!FEof()) {
ID identifier;
idname = getID(identifier.Name);
switch (idname) {
case "COLORS":
count = getNumber(identifier.Name);
if (count)
NAME_ARRAY Colors(count) <name="Colors">;
break;
case "TEXTUREFILES":
count = getNumber(identifier.Name);
if (count)
{
typedef struct (int arraySize) {
TXR array[arraySize] <optimize=false>;
} TXR_Array;
TXR_Array TXRs(count) <name="Texture files">;
};
break;
case "PALETTEFILES":
count = getNumber(identifier.Name);
if (count)
struct {
string FileName;
UINT DataSize;
//PLM_FILE plm;
BYTE Data[DataSize];
} PALETTE_FILES[count] <optimize=false>;
break;
case "SOUNDFILES":
count = getNumber(identifier.Name);
if (count)
{
typedef struct {
string FileName;
UINT DataSize;
struct {
char groupID[4]; // RIFF
long size;
char riffType[4]; // WAVE
} WAVRIFFHEADER;
FSkip(WAVRIFFHEADER.size - 4);
} SOUNDFILE <optimize=false>;
typedef struct (int arraySize) {
SOUNDFILE array[arraySize] <optimize=false>;
} SOUNDFILE_Array;
SOUNDFILE_Array SoundFiles(count) <name="Sound Files">;
};
break;
case "BACKFILES":
count = getNumber(identifier.Name);
if (count)
BACKFILE_ARRAY SoundFiles(count) <name="BACK Files">;
break;
case "MASKFILES":
count = getNumber(identifier.Name);
if (count)
{
typedef struct (int arraySize) {
MS array[arraySize] <optimize=false>;
} MASKS;
MASKS Masks(count) <name="Masks">;
};
break;
case "MATERIALS":
count = getNumber(identifier.Name);
if (count)
NAME_ARRAY Files(count) <name="Materials">;
break;
case "SOUNDS":
count = getNumber(identifier.Name);
if (count)
NAME_ARRAY Sounds(count) <name="Sounds">;
break;
};
};