-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRSB.bt
493 lines (429 loc) · 14.3 KB
/
RSB.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
//------------------------------------------------
//--- 010 Editor v7.0 Binary Template
//
// File: RSB.bt
// Authors: Alexander Evdokimov
// Version: 1.4
// Purpose: Red storm bitmap (RSB) file
// Format Desription:
// English: https://github.com/AlexKimov/RSE-file-formats/wiki/RSB-File-Format
// Russian: https://github.com/AlexKimov/RSE-file-formats/wiki/RSB-File-Format-RUS
//
// History:
// 2018.04 v1.4 added commentaries, minor fixes
// 2018.01 v1.3 fix channel order (boristsr), new Channel struct
// 2017.12 v1.2 fix RSB version 0 structures
// 2017.05 v1.1 RSB with DXT1 compression and mipmaps added
// 2017.05 v0.9 RSB version 0 added
// 2017.01 v0.8
// New:
// - new structures, enums, vars,
// - speed optimization for pixel structure
// 2016.10 v0.6 initial release
//
//------------------------------------------------
struct {
local int height, width;
local int DXT = 0;
} locals <hidden=true>;
typedef enum <ubyte> {
no,
yes
} BOOL; // bool data type
typedef enum <int> {
DXT1,
DXT2, DXT3, DXT4,
DXT5,
none = 4294967295
} DXT_TYPE <comment="DXT comperssion formats">;
/*
Source function,
Destination function,
Compare function.
RSB's with alpha channels use these parameters to get different opacity effects.
By choosing different functions in each parameter will affect RSB transparency, when its
used in the game. Try them at your own to find out the result.
Use AlphaBlending boolean to enable or disable first 2 functions and AlphaTesting for the last one.
*/
typedef enum <uint> {
sZero,
sOne,
sSource_Alpha,
sInverse_Source_Alpha,
sSource_Color,
sInverse_Source_Color,
sDestination_Color,
sInverse_Destination_Color,
sBoth_Source_Alpha,
sBoth_Inverse_Source_Alpha
} SOURCE_FUNCTION_PARAMETER <comment="Source blending functions">;
typedef enum <uint> {
dZero,
dOne,
dSource_Alpha,
dInverse_Source_Alpha_Source_Color,
dInverse_Source_Color,
dDestination_Color,
dInverse_Destination_Color,
dBoth_Source_Alpha,
dBoth_Inverse_Source_Alpha
} DESTINATION_FUNCTION_PARAMETER <comment="Destination blending functions">;
typedef enum <uint> {
Never,
Less,
Equal,
Less_Equal,
Greater_Equal,
Always,
} COMPARE_FUNCTION_PARAMETER <comment="Compare function to set up texture transparency with reference value.">;
/*
Cycle - a repeating pattern that starts over when it finishes.
But if its attached to a billboard object it stop at the end and the billboard will disappear.
Oscillate - ping pong pattern
Constant - similar to cycle but wont disappear if attached to a billboard
*/
typedef enum <uint> {
Cycle,
Oscillate,
Constant
} ANIMATION_TYPE;
/*
Scrolling properties animates an RSB by moving it horizontally, vertically or rotate,
Horiz/Vert - moves a RSB horizontally or vertically.
Rate (Degrees_Sec) - how fast an RSB scrolls smaller numbers go faster bigger numbers go slower.
*/
typedef enum <uint> {
Rotate,
Degrees_Sec
} SCROLLING_TYPE;
/*
Surface Type - gives the RSB an appropriate sound effect when walked on and an appropriate
damage texture when shot.
*/
typedef enum <int> {
NONE,
Carpet,
Concrete,
Wood,
Metal,
Asphalt,
Sand,
Lowgrass,
Highgrass,
Puddle,
Water,
Drywall,
Thin_Metal,
Thick_Metal,
Metal_Gas_Tank,
Steam_Pipe,
Electrical_Panel,
Snow,
Safety_Glass,
Bullet_Resistant_Glass,
Ice,
Mud,
Glass,
Foliage,
Gravel,
Glass_Shards,
unset = 4294967295
} SURFACE_TYPE;
typedef struct {
UINT red_bits;
UINT green_bits;
UINT blue_bits;
UINT alpha_bits;
} BIT_MASK <name="Bit Mask">;
struct {
UINT version <name="RSB Version">; // *.rsb file version
/*
File Versions:
0 - 1 games released before Ghost Recon:
Dominant Species, Force 21, Rainbow six (1998) + addon, Rogue Spear(2000) + addons, Freedom First Resistance
0 - 9 Ghost Recon (+addons), The Summ of All Fears
9 - 11 Rainbow Six LockDown.
files with 3 and 7 are something virtual or may be hiding somewhere in a game folder, waiting, who knows...
*/
UINT width <name="Texture Width">; // texture width
UINT height <name="Texture Height">; // texture height
if (version == 0) {
UINT Palette <name="8BitImage">; // 1 - additional 8-bit texture copy + palette
if (Palette == 0) {
BIT_MASK BitMask;
}
}
else {
if (version > 7) {
UINT UnknownValue; // 0
BYTE UnknownVal[3]; //
};
BIT_MASK BitMask;
if (version >= 9) {
INT UnknownValue; //
DXT_TYPE dxtType <name="DXT type">;
if ((dxtType >= 0) & (dxtType < 5)) {
locals.DXT = 1;
};
};
}
} HEADER <name="File Header">;
/*
Some textures (version 0) have additional 8-bit image with palette
*/
typedef struct{
ubyte Blue <name="Blue">;
ubyte Green <name="Green">;
ubyte Red <name="Red">;
ubyte Alpha <name="Alpha">;
} PALETTE_COLOR <name="Palette Color">;
if (exists(HEADER.Palette))
if (HEADER.Palette == 1)
PALETTE_COLOR palette[256] <name="8-bit Palette">;
BitfieldDisablePadding();
typedef struct {
if (HEADER.version == 0) {
if (HEADER.Palette == 1) {
ubyte paletteColor <name="palette Color index">;
}
}
else {
// DXT compression structures
if (locals.DXT == 1 ) {
if (HEADER.dxtType != DXT1) {
struct {
if (HEADER.dxtType != DXT5) {
for (i = 0; i < 16; ++i) {
ubyte AlphaIndex : 4 <name="Alpha Index">;
}
}
else {
ubyte Alpha1;
ubyte Alpha2;
for (i = 0; i < 16; ++i) {
ubyte AlphaIndex : 3 <name="Alpha Index">;
}
}
} AlphaChannel <name="Alpha Channel Data">;
};
struct {
struct {
ubyte Red : 5 <name="Red">;
ubyte Green : 6 <name="Green">;
ubyte Blue : 5 <name="Blue">;
} Color1;
struct {
ubyte Red : 5 <name="Red">;
ubyte Green : 6 <name="Green">;
ubyte Blue : 5 <name="Blue">;
} Color2;
struct {
for (i = 0; i < 16; ++i) {
ubyte PixelIndex : 2 <name="Pixel Index">;
};
} INDEX_TABLE;
} COLOR_DATA <name="Color Data">;
}
else {
if (HEADER.BitMask.alpha_bits + HEADER.BitMask.red_bits + HEADER.BitMask.green_bits + HEADER.BitMask.blue_bits == 32) {
// ARGB order
ubyte Alpha : HEADER.BitMask.alpha_bits <name="Alpha">;
ubyte Red : HEADER.BitMask.red_bits <name="Red">;
ubyte Green : HEADER.BitMask.green_bits <name="Green">;
ubyte Blue : HEADER.BitMask.blue_bits <name="Blue">;
}
else {
// BGRA order
ubyte Blue : HEADER.BitMask.blue_bits <name="Blue">;
ubyte Green : HEADER.BitMask.green_bits <name="Green">;
ubyte Red : HEADER.BitMask.red_bits <name="Red">;
ubyte Alpha : HEADER.BitMask.alpha_bits <name="Alpha">;
};
};
};
} PIXEL <name="Pixel", size=sizePIXEL>;
int sizePIXEL( PIXEL &pixel )
{
if (exists(HEADER.Palette)) {
if (HEADER.Palette == 1)
return 1;
else
return 2;
}
else {
if (locals.DXT == 1) {
if (HEADER.dxtType == 0) {
return 8;
}
else
if (HEADER.dxtType > 0 && HEADER.dxtType < 5 ) {
return 16;
}
}
else {
return (HEADER.BitMask.red_bits +
HEADER.BitMask.green_bits +
HEADER.BitMask.blue_bits +
HEADER.BitMask.alpha_bits)/8;
}
}
}
typedef struct (int arraySize) {
PIXEL array[arraySize] <optimize=false>;
} PIXEL_ARRAY;
if (locals.DXT == 1) {
PIXEL_ARRAY PixelArray(HEADER.width*HEADER.height/16) <name="Pixel Array (DXT compression)", optimize=false>;
} else {
PIXEL_ARRAY PixelArray(HEADER.width*HEADER.height) <name="Pixel Array", optimize=false>;
};
if (HEADER.version == 0) {
if (HEADER.Palette == 1) {
BIT_MASK BitMask;
typedef struct {
ubyte Red : BitMask.red_bits <name="Red">;
ubyte Green : BitMask.green_bits <name="Green">;
ubyte Blue : BitMask.blue_bits <name="Blue">;
ubyte Alpha : BitMask.alpha_bits <name="Alpha">;
} PIXEL2 <name="Pixel">;
typedef struct (int arraySize) {
PIXEL2 array[arraySize];
} PIXEL_ARRAY2;
PIXEL_ARRAY2 PixelArray(HEADER.width*HEADER.height) <name="Pixel Array (16-bit image)">;
}
}
typedef struct {
locals.height = HEADER.height, locals.width = HEADER.width;
for (i = 0; i < RSB_PROPERTIES.MapsCount; ++i)
{
locals.height = locals.height/2;
locals.width = locals.width/2;
PIXEL_ARRAY MipMapArray(locals.height*locals.width) <name="MipMap">;
};
} MIP_MAPS <name="MipMaps">;
// -To Do- Check photoshop .psd format docs
typedef struct {
UINT Length;
char Name[Length];
UINT Count;
typedef struct {
UINT P1;
UINT P2;
SHORT X1;
SHORT Y1;
SHORT X2;
SHORT Y2;
} Coordinates;
Coordinates DATA[Count];
} Channel <name=channelName>;
string channelName(Channel &channel){
return channel.Name;
}
// Files with HEADER.version == 0..1 had no Properties section
// Last section for the HEADER.version == 2 is 46 bit long and seems always to be empty (filled with 0 bits), therefore ignore it
if (HEADER.version > 2) {
struct{
// Surface Channels, GR feature
if ((HEADER.version > 5) && (HEADER.version < 10)) {
struct {
UINT SurfaceChannelsCount <name="Count">;
if (SurfaceChannelsCount > 0) {
UINT size;
BYTE SurfaceChannelsData[size]; // garbage data
Channel Array[SurfaceChannelsCount] <optimize=false>;
};
}SurfaceData <name="Surface Channels">;
} ;
// -To Do- of course, it's something very very meaninfull, but i don't care
if (HEADER.version > 9) {
UINT Count;
UINT MN[Count];
UINT MN;
};
BOOL AlphaBlending <name="AlphaBlending", comment="Enables texture blending">;
BOOL AlphaTesting <name="AlphaTesting">;
BOOL Sampling <name="Sampling", comment="Enables Sampling properties">; // **
BOOL Animation <name="Animation", comment="Enables RSB flipbook animation">;
BOOL Scrolling <name="Scrolling", comment="Enables Scrolling animation">;
BOOL Tiled <name="Tiled">; // **
BOOL Compression <name="Compression">; // **
if (HEADER.version > 7) {
BOOL Distortion <name="Distortion">; // **
};
/*
Gunshot Transparent - RSB will let bullets pass through it. ex. a wire fence.
Grenade Transparent - Grenades and bombs can pass through and damage effects will also
effect through it.
Line-of-sight Transparent - enemies can see the player through it.
Foliage - sets foliage properties for the RSB. This hinders line-of-sight and causes leaves to fall
if the surface is shot through.
Water - set water properties for the RSB
*/
UINT GameProperties <name="Game Properties", comment="Additional texture properties">;
if (GameProperties == 16) {
Printf("Game Properties: Water");
}
else
if (GameProperties > 0) {
Printf("Game Properties: ");
if (GameProperties & 0b00000001) {
Printf("Gunshot Transparent,");
};
if (GameProperties & 0b00000010) {
Printf("Grenade Transparent,");
};
if (GameProperties & 0b00000100) {
Printf("Line-of-sight Transparent,");
};
if (GameProperties & 0b00001000) {
Printf("Foliage");
};
};
SOURCE_FUNCTION_PARAMETER SourceFunction <name="Source Function">;
DESTINATION_FUNCTION_PARAMETER DestinationFunction <name="Destination Function">;
COMPARE_FUNCTION_PARAMETER CompareFunction <name="Compare Function">;
BYTE ReferenceValue <name="Reference Value">;
struct {
SCROLLING_TYPE ScrollingType <name="Scrolling Type">;
FLOAT HorizontalRate <name="Horizontal Rate">;
FLOAT VerticalRate <name="Vertical Rate">;
} TEXTURE_SCROLLING <name="Scrolling Animation">;
struct {
ANIMATION_TYPE AnimationType <name="Animation Type">;
FLOAT AnimationInterval <name="Interval">;
UINT TextureCount <name="Count">;
if ((TextureCount)) {
typedef struct {
UINT TextureNameLength;
char TextureName[TextureNameLength];
} TEXTURE_NAME <optimize=false, name=textureName>;
typedef struct (int arraySize) {
TEXTURE_NAME array[arraySize];
} TEXTURE_ARRAY <optimize=false>;
TEXTURE_ARRAY RSBTextureArray(TextureCount) <optimize=false, name="Textures List">;
};
} ANIMATION <name="Flipbook Animation">;
if (HEADER.version > 4) {
UINT MapsCount <name="MipMaps Count">;
UINT SubsamplingPriority <name="Subsampling Priority">;
};
BOOL Damaged <name="Damaged">; // **
if (Damaged == yes) {
UINT TextureNameLength; //
if (TextureNameLength > 0) {
char DamagedTextureName[TextureNameLength];
};
};
SURFACE_TYPE SurfaceType <name="Surface Type">;
} RSB_PROPERTIES <name="Texture Properties">;
// mipmaps if exist are always in the end of the file, **
if (HEADER.version > 4) {
if (RSB_PROPERTIES.MapsCount > 0) {
MIP_MAPS MipMaps;
}
}
};
string textureName( TEXTURE_NAME &texturename )
{
return texturename.TextureName;
}
// ** "...Its best to leave these parameters alone unless you like crashing..."