forked from ericlangedijk/Lemmix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dos.MainDat.pas
106 lines (90 loc) · 3.07 KB
/
Dos.MainDat.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
unit Dos.MainDat;
{$include lem_directives.inc}
interface
uses
Classes, GR32,
Base.Bitmaps,
Dos.Compression, Dos.Structures,
Prog.Base, Prog.Data, Dos.Bitmaps;
type
// Tool to extract data from the dos main dat file
TMainDatExtractor = class
private
fFileName: string;
fDecompressor: TDosDatDecompressor;
fSections: TDosDatSectionList;
fPlanar: TDosPlanarBitmap;
procedure EnsureLoaded;
procedure EnsureDecompressed(aSection: Integer);
protected
public
constructor Create;
destructor Destroy; override;
procedure ExtractBrownBackGround(Bmp: TBitmap32);
procedure ExtractLogo(Bmp: TBitmap32);
procedure ExtractBitmap(Bmp: TBitmap32; aSection, aPosition, aWidth, aHeight, BPP: Integer; const aPal: TArrayOfColor32);
procedure ExtractAnimation(Bmp: TBitmap32; aSection, aPos, aWidth, aHeight, aFrameCount: Integer; BPP: Byte; const aPal: TArrayOfColor32);
property FileName: string read fFileName write fFileName;
end;
implementation
{ TMainDatExtractor }
constructor TMainDatExtractor.Create;
begin
inherited Create;
fSections := TDosDatSectionList.Create;
fDecompressor := TDosDatDecompressor.Create;
end;
destructor TMainDatExtractor.Destroy;
begin
fSections.Free;
fDecompressor.Free;
inherited;
end;
procedure TMainDatExtractor.EnsureDecompressed(aSection: Integer);
var
Sec: TDosDatSection;
begin
EnsureLoaded;
Sec := fSections[aSection];
if Sec.DecompressedData.Size = 0 then
fDecompressor.DecompressSection(Sec.CompressedData, Sec.DecompressedData)
end;
procedure TMainDatExtractor.EnsureLoaded;
var
DataStream: TStream;
begin
if fSections.Count = 0 then
begin
DataStream := TData.CreateDataStream(Consts.StyleName, fFileName, TDataType.LemmingData);
try
fDecompressor.LoadSectionList(DataStream, fSections, False);
finally
DataStream.Free;
end;
end;
end;
procedure TMainDatExtractor.ExtractAnimation(Bmp: TBitmap32; aSection, aPos, aWidth, aHeight, aFrameCount: Integer; BPP: Byte; const aPal: TArrayOfColor32);
begin
EnsureDecompressed(aSection);
fPlanar.LoadAnimationFromStream(fSections[aSection].DecompressedData, Bmp, aPos, aWidth, aHeight, aFrameCount, BPP, aPal);
end;
procedure TMainDatExtractor.ExtractBitmap(Bmp: TBitmap32; aSection, aPosition, aWidth, aHeight, BPP: Integer; const aPal: TArrayOfColor32);
begin
EnsureDecompressed(aSection);
fPlanar.LoadFromStream(fSections[aSection].DecompressedData, Bmp, aPosition, aWidth, aHeight, BPP, aPal);
end;
procedure TMainDatExtractor.ExtractBrownBackGround(Bmp: TBitmap32);
// Extract hte brown background, used in several screens
begin
EnsureDecompressed(3);
fPlanar.LoadFromStream(fSections[3].DecompressedData, Bmp, 0, 320, 104, 2,
GetDosMainMenuPaletteColors32);
end;
procedure TMainDatExtractor.ExtractLogo(Bmp: TBitmap32);
// Extract the LemmingLogo
begin
EnsureDecompressed(3);
fPlanar.LoadFromStream(fSections[3].DecompressedData, Bmp, $2080, 632, 94, 4,
GetDosMainMenuPaletteColors32);
end;
end.