-
Notifications
You must be signed in to change notification settings - Fork 2
/
LemDosStructures.pas
476 lines (421 loc) · 16.2 KB
/
LemDosStructures.pas
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
{$include lem_directives.inc}
unit LemDosStructures;
interface
uses
Types, GR32;
// NeoLemmix Save Data Structure
type
TNeoRecordsTableEntry = packed record
BestTime : LongWord;
BestSave : Word;
Removed2 : Word;
Reserved : array[0..21] of Byte;
Zeroed : Word;
end;
TNeoLevelTable = packed array[0..31] of byte;
TNeoRecordTable = packed array[0..255] of TNeoRecordsTableEntry;
TNeoConfigRecord = packed record
ToggleOptions : LongWord;
Removed1 : array[0..2] of Byte;
PercentOption : Byte;
Removed3 : LongWord;
ForceSkillset : Word;
Removed4 : Byte;
TestOption : Byte;
SoundOption : Byte;
Removed7 : LongWord;
Removed8 : Longword;
Reserved : array[0..6] of Byte;
PackName : array[0..31] of AnsiChar;
PrefixName : array[0..15] of AnsiChar;
end;
TNeoSaveRecord = packed record
UnlockTable : packed array[0..14] of TNeoLevelTable;
CompleteTable : packed array[0..14] of TNeoLevelTable;
RecordTable : packed array[0..14] of TNeoRecordTable;
Config : TNeoConfigRecord;
end;
{-------------------------------------------------------------------------------
LVL raw level file structure as used by dos en winlemmings.
-------------------------------------------------------------------------------}
const
LVL_MAXOBJECTCOUNT = 32;
LVL_MAXTERRAINCOUNT = 400;
LVL_MAXSTEELCOUNT = 32;
type
TLVLObject = packed record
case Byte of
0: ( AsInt64: Int64 );
1: ( D0, D1: DWord);
2: ( W0, W1, W2, W3: Word);
3: ( B0, B1, B2, B3, B4, B5, B6, B7: Byte);
4: (
XPos : Word; // swap lo and hi
YPos : Word; // swap lo and hi
ObjectID : Word;
Modifier : Byte;
DisplayMode : Byte; // $8F = invert; $0F = normal
);
end;
{
bits 0..3 = modifier
bits 4..7 shl 8 for xpos
bits 8..15 add to xpos
bits 16..24 9 bits number YPos
}
TLVLTerrain = packed record
case Byte of
0: ( D0: DWord );
1: ( W0, W1: Word );
2: ( B0, B1, B2, B3: Byte );
3: (
XPos : Word;
YPos : Byte; // 9 bits
TerrainID : Byte;
);
end;
TLVLSteel = packed record
case Byte of
0: ( D0: DWord );
1: ( W0, W1: Word);
2: ( B0, B1, B2, B3: Byte);
3: (
XPos : Byte; // 9 bits
YPos : Byte; // 7 bits bits 1..7
Area : Byte; // bits 0..3 is height in 4 pixel units (then add 4)
// bit 4..7 is width in 4 pixel units (then add 4)
b : Byte; // always zero
);
end;
TLVLObjects = array[0..LVL_MAXOBJECTCOUNT - 1] of TLVLObject;
TLVLTerrains = array[0..LVL_MAXTERRAINCOUNT - 1] of TLVLTerrain;
TLVLSteels = array[0..LVL_MAXSTEELCOUNT - 1] of TLVLSteel;
// the main record 2048 bytes
TLVLRec = packed record
{0000} ReleaseRate : Word; // big endian, swap!
{ } LemmingsCount : Word; // big endian, swap!
{ } RescueCount : Word; // big endian, swap!
TimeSeconds : Byte;
{ } TimeMinutes : Byte; // big endian, swap!
{0008} ClimberCount : Word; // big endian, swap!
{ } FloaterCount : Word; // big endian, swap!
{ } BomberCount : Word; // big endian, swap!
{ } BlockerCount : Word; // big endian, swap!
{ } BuilderCount : Word; // big endian, swap!
{ } BasherCount : Word; // big endian, swap!
{ } MinerCount : Word; // big endian, swap!
{ } DiggerCount : Word; // big endian, swap!
{0018} ScreenPosition : Word; // big endian, swap!
{001A} GraphicSet : Word; // big endian, swap!
LevelOptions : Byte;
{ } GraphicSetEx : Byte; // big endian, swap!
{001E} Reserved : Word; // big endian, swap! $FFFF if SuperLemming else $0000
{0020} Objects : TLVLObjects;
{0120} Terrain : TLVLTerrains;
{0760} Steel : TLVLSteels;
{07E0} LevelName : array[0..31] of AnsiChar;
end;
const
LVL_SIZE = SizeOf(TLVLRec);
type
TNewNeoLVLObject = packed record
XPos : LongInt;
YPos : LongInt;
ObjectID : Word;
SValue : Byte;
LValue : Byte;
ObjectFlags : Word;
GSIndex : Byte;
Reserved : Array[0..3] of Byte;
Locked : Byte; // editor use only, but keeping consistency
end;
TNewNeoLVLTerrain = packed record
XPos : LongInt;
YPos : LongInt;
TerrainID : Word;
TerrainFlags : Word;
GSIndex : Byte;
TerReserved : Array[0..1] of Byte;
Locked : Byte; // editor use only
end;
TNewNeoLVLSteel = packed record
XPos : LongInt; // 9 bits
YPos : LongInt; // 7 bits bits 1..7
SteelWidth : LongWord;
SteelHeight : LongWord;
SteelFlags : Byte;
SteReserved : Array[0..1] of Byte;
Locked : Byte; // editor use only
end;
TNeoLVLHeader = packed record
{0000} FormatTag : Byte;
MusicNumber : Byte;
LemmingsCount : Word;
RescueCount : Word;
TimeLimit : Word;
{0008} ReleaseRate : Byte;
LevelOptions : Byte;
Resolution : Byte;
BgIndex : Byte;
ScreenPosition : Word;
ScreenYPosition : Word;
{0010} WalkerCount : Byte;
ClimberCount : Byte;
SwimmerCount : Byte;
FloaterCount : Byte;
GliderCount : Byte;
DisarmerCount : Byte;
BomberCount : Byte;
StonerCount : Byte;
{0018} BlockerCount : Byte;
PlatformerCount : Byte;
BuilderCount : Byte;
StackerCount : Byte;
BasherCount : Byte;
MinerCount : Byte;
DiggerCount : Byte;
ClonerCount : Byte;
{0020} Gimmick : LongWord;
Skillset : Word;
RefSection : Byte;
RefLevel : Byte;
{0028} Width : LongWord;
Height : LongWord;
VgaspecX : LongInt;
VgaspecY : LongInt;
LevelID : LongWord;
LevelOptions2 : Byte;
FencerCount : Byte;
Reserved2 : array[0..1] of Byte;
{0040} LevelAuthor : array[0..15] of AnsiChar;
{0050} LevelName : array[0..31] of AnsiChar;
{0070} StyleName : array[0..15] of AnsiChar;
{0080} VgaspecName : array[0..15] of AnsiChar;
{0090} ReservedStr : array[0..31] of AnsiChar;
end;
TNeoLVLSecondHeader = packed record
{0000} ScreenPosition: LongInt;
ScreenYPosition: LongInt;
GimmickFlags2: LongWord;
GimmickFlags3: LongWord;
{0010} MusicName: array[0..15] of AnsiChar;
{0020} SecRedirectRank: Byte;
SecRedirectLevel: Byte;
BnsRedirectRank: Byte;
BnsRedirectLevel: Byte;
ClockGimStart: Word;
ClockGimEnd: Word;
ClockGimPieces: Word;
{002A}
end;
TNeoLVLObject = packed record
case Byte of
0: ( AsInt64: Int64 );
1: ( D0, D1: DWord);
2: ( W0, W1, W2, W3: Word);
3: ( B0, B1, B2, B3, B4, B5, B6, B7: Byte);
4: (
XPos : SmallInt;
YPos : SmallInt;
ObjectID : Byte;
SValue : Byte;
LValue : Byte;
ObjectFlags : Byte;
);
end;
TNeoLVLTerrain = packed record
case Byte of
0: ( AsInt64: Int64);
1: ( D0, D1: DWord );
2: ( W0, W1, W2, W3: Word );
3: ( B0, B1, B2, B3, B4, B5, B6, B7: Byte );
4: (
XPos : SmallInt;
YPos : SmallInt;
TerrainID : Byte;
TerrainFlags : Byte;
TerReserved : Word;
);
end;
TNeoLVLSteel = packed record
case Byte of
0: ( AsInt64: Int64);
1: ( D0, D1: DWord );
2: ( W0, W1, W2, W3: Word );
3: ( B0, B1, B2, B3, B4, B5, B6, B7: Byte );
4: (
XPos : SmallInt; // 9 bits
YPos : SmallInt; // 7 bits bits 1..7
SteelWidth : Byte;
SteelHeight : Byte;
SteelFlags : Byte;
SteReserved : Byte;
);
end;
TNeoLVLObjects = array[0..127] of TNeoLVLObject;
TNeoLVLTerrains = array[0..999] of TNeoLVLTerrain;
TNeoLVLSteels = array[0..127] of TNeoLVLSteel;
TNeoLVLRec = packed record
{0000} FormatTag : Byte;
MusicNumber : Byte;
LemmingsCount : Word;
RescueCount : Word;
TimeLimit : Word;
{0008} ReleaseRate : Byte;
LevelOptions : Byte;
GraphicSet : Byte;
GraphicSetEx : Byte;
ScreenPosition : Word;
ScreenYPosition : Word;
{0010} WalkerCount : Byte;
ClimberCount : Byte;
SwimmerCount : Byte;
FloaterCount : Byte;
GliderCount : Byte;
DisarmerCount : Byte;
BomberCount : Byte;
StonerCount : Byte;
{0018} BlockerCount : Byte;
PlatformerCount : Byte;
BuilderCount : Byte;
StackerCount : Byte;
BasherCount : Byte;
MinerCount : Byte;
DiggerCount : Byte;
ClonerCount : Byte;
{0020} Gimmick : LongWord;
Skillset : Word;
RefSection : Byte;
RefLevel : Byte;
{0028} WidthAdjust : SmallInt;
HeightAdjust : SmallInt;
VgaspecX : SmallInt;
VgaspecY : SmallInt;
{0030} LevelAuthor : array[0..15] of AnsiChar;
{0040} LevelName : array[0..31] of AnsiChar;
{0060} StyleName : array[0..15] of AnsiChar;
{0070} VgaspecName : array[0..15] of AnsiChar;
{0080} WindowOrder : array[0..31] of Byte;
{00A0} ReservedStr : array[0..31] of AnsiChar;
{00C0} Objects : TNeoLVLObjects;
{04C0} Terrain : TNeoLVLTerrains;
{2400} Steel : TNeoLVLSteels;
end;
const
NEO_LVL_SIZE = SizeOf(TNeoLVLRec);
type
{SYSTEM.DAT for Flexi player}
TSysDatRec = packed record
{0000} PackName : array[0..31] of AnsiChar;
SecondLine : array[0..31] of AnsiChar;
RankNames : array[0..14] of array[0..15] of AnsiChar;
RankCount : Byte;
Removed : array[0..14] of Byte;
TrackCount : Byte;
CodeSeed : Byte;
CheatCode : array[0..9] of AnsiChar;
Options : Byte;
Options2 : Byte;
Options3 : Byte; //$20 here is highest currently used
Options4 : Byte;
KResult : array[0..2] of array[0..1] of array[0..35] of AnsiChar;
SResult : array[0..8] of array[0..1] of array[0..35] of AnsiChar;
Congrats : array[0..17] of array[0..35] of AnsiChar;
ScrollerTexts : array[0..15] of array[0..35] of AnsiChar;
StyleNames : array[0..255] of array[0..15] of AnsiChar;
VgaspecNames : array[0..255] of array[0..15] of AnsiChar;
end;
const
SYSDAT_SIZE = SizeOf(TSysDatRec);
{-------------------------------------------------------------------------------
GROUNDXX.DAT files (1056 bytes) (16 objects, 64 terrain, color palette)
o See documentation for details
o Little Endian words, so we can just load them from disk halleluyah!
-------------------------------------------------------------------------------}
type
TDosEGAPalette8 = packed array[0..7] of Byte;
TDosVgaColorRec = packed record
R, G, B: Byte;
end;
TDosVGAPalette8 = packed array[0..7] of TDosVGAColorRec;
TDosVGAPalette16 = packed array[0..15] of TDosVGAColorRec;
TDosVgaSpecPaletteHeader = packed record
VgaPal: TDosVGAPalette8; // 24
EgaPal: TDosEGAPalette8; // 8
UnknownPal: array[0..7] of Byte; // maybe even less colors
end;
const
DosInLevelPalette: TDosVGAPalette8 =
(
(R: 000; G: 000; B: 000), // black
(R: 016; G: 016; B: 056), // blue
(R: 000; G: 044; B: 000), // green
(R: 060; G: 052; B: 052), // white
(R: 044; G: 044; B: 000), // yellow
(R: 060; G: 008; B: 008), // red
(R: 032; G: 032; B: 032), // gray
(R: 000; G: 000; B: 000) // not used: probably this color is replaced with the standard palette entry in ground??.dat
);
const
{ TODO : do not mix original rgb and converted rgb }
DosMainMenuPalette: TDosVGAPalette16 = (
(R: 000; G: 000; B: 000), // black
(R: 128; G: 064; B: 032), // browns
(R: 096; G: 048; B: 032),
(R: 048; G: 000; B: 016),
(R: 032; G: 008; B: 124), // purples
(R: 064; G: 044; B: 144),
(R: 104; G: 088; B: 164),
(R: 152; G: 140; B: 188),
(R: 000; G: 080; B: 000), // greens
(R: 000; G: 096; B: 016),
(R: 000; G: 112; B: 032),
(R: 000; G: 128; B: 064),
(R: 208; G: 208; B: 208), // white
(R: 176; G: 176; B: 000), // yellow
(R: 064; G: 080; B: 176), // blue
(R: 224; G: 128; B: 144) // pink
);
function DosVgaColorToColor32(const ColorRec: TDosVgaColorRec): TColor32;
function GetDosMainMenuPaletteColors32(UseXmas: Boolean = false): TArrayOfColor32;
implementation
function GetDosMainMenuPaletteColors32(UseXmas: Boolean = false): TArrayOfColor32;
var
i: Integer;
P: PColor32;
begin
SetLength(Result, 16);
{ TODO : move this conversion somewhere else }
for i := 0 to 15 do // bad code
begin
P := @Result[i];
TColor32Entry(P^).A := 0;
TColor32Entry(P^).R := DosMainMenuPalette[i].R;
TColor32Entry(P^).G := DosMainMenuPalette[i].G;
TColor32Entry(P^).B := DosMainMenuPalette[i].B;
end;
if UseXmas then
begin
P := @Result[3];
TColor32Entry(P^).A := 0;
TColor32Entry(P^).R := 0;
TColor32Entry(P^).G := 0;
TColor32Entry(P^).B := 0;
P := @Result[14];
TColor32Entry(P^).A := 0;
TColor32Entry(P^).R := 240;
TColor32Entry(P^).G := 32;
TColor32Entry(P^).B := 32;
end;
end;
function DosVgaColorToColor32(const ColorRec: TDosVgaColorRec): TColor32;
begin
with TColor32Entry(Result) do
begin
A := $FF;
R := ColorRec.R * 4;
G := ColorRec.G * 4;
B := ColorRec.B * 4;
end;
end;
end.