| 1 | unit UGame;
|
|---|
| 2 |
|
|---|
| 3 | {$mode delphi}{$H+}
|
|---|
| 4 |
|
|---|
| 5 | interface
|
|---|
| 6 |
|
|---|
| 7 | uses
|
|---|
| 8 | Classes, SysUtils, Graphics, UFile1, UEngFile, UShpFile, UDecode, Types,
|
|---|
| 9 | UWsaFile;
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 |
|
|---|
| 13 | { TGame }
|
|---|
| 14 |
|
|---|
| 15 | TGame = class
|
|---|
| 16 | private
|
|---|
| 17 | TileData: array of Byte;
|
|---|
| 18 | PaletteData: array of Byte;
|
|---|
| 19 | TableData: array of Byte;
|
|---|
| 20 | IconMap: array of Word;
|
|---|
| 21 | procedure DrawTile(Canvas: TCanvas; Pos: TPoint; Index: Integer);
|
|---|
| 22 | procedure LoadIconMap;
|
|---|
| 23 | procedure LoadIcons;
|
|---|
| 24 | procedure LoadMap;
|
|---|
| 25 | procedure LoadPalette;
|
|---|
| 26 | procedure LoadTexts;
|
|---|
| 27 | procedure LoadUnits;
|
|---|
| 28 | procedure LoadUnitsFile(FileName: string);
|
|---|
| 29 | procedure LoadWsa;
|
|---|
| 30 | public
|
|---|
| 31 | Bitmap: TBitmap;
|
|---|
| 32 | Palette: TIntegerDynArray;
|
|---|
| 33 | IW: Integer;
|
|---|
| 34 | procedure Paint(Canvas: TCanvas);
|
|---|
| 35 | constructor Create;
|
|---|
| 36 | destructor Destroy; override;
|
|---|
| 37 | procedure LoadData;
|
|---|
| 38 | end;
|
|---|
| 39 |
|
|---|
| 40 | implementation
|
|---|
| 41 |
|
|---|
| 42 | uses
|
|---|
| 43 | UFormLog, UFormMain;
|
|---|
| 44 |
|
|---|
| 45 | { TGame }
|
|---|
| 46 |
|
|---|
| 47 | procedure TGame.Paint(Canvas: TCanvas);
|
|---|
| 48 | begin
|
|---|
| 49 | Canvas.Line(10, 10, 100, 100);
|
|---|
| 50 | Canvas.StretchDraw(Rect(0, 0, 2000, 1400), Bitmap);
|
|---|
| 51 | end;
|
|---|
| 52 |
|
|---|
| 53 | constructor TGame.Create;
|
|---|
| 54 | begin
|
|---|
| 55 | Bitmap := TBitmap.Create;
|
|---|
| 56 | end;
|
|---|
| 57 |
|
|---|
| 58 | destructor TGame.Destroy;
|
|---|
| 59 | begin
|
|---|
| 60 | FreeAndNil(Bitmap);
|
|---|
| 61 | inherited Destroy;
|
|---|
| 62 | end;
|
|---|
| 63 |
|
|---|
| 64 | procedure TGame.LoadPalette;
|
|---|
| 65 | var
|
|---|
| 66 | F: TFileStream;
|
|---|
| 67 | I: Integer;
|
|---|
| 68 | begin
|
|---|
| 69 | SetLength(Palette, 256);
|
|---|
| 70 | F := TFileStream.Create('extracted/DUNE.PAK/IBM.PAL', fmOpenRead);
|
|---|
| 71 | for I := 0 to 255 do begin
|
|---|
| 72 | //Palette[I] := (I shl 16) or (I shl 8) or (I shl 0);
|
|---|
| 73 | Palette[I] := ((F.ReadByte * 4) shl 0) or ((F.ReadByte * 4) shl 8) + ((F.ReadByte * 4) shl 16);
|
|---|
| 74 | end;
|
|---|
| 75 | F.Free;
|
|---|
| 76 | end;
|
|---|
| 77 |
|
|---|
| 78 | procedure TGame.LoadIcons;
|
|---|
| 79 | var
|
|---|
| 80 | I: Integer;
|
|---|
| 81 | W, H: Integer;
|
|---|
| 82 | F: TFileStream;
|
|---|
| 83 | IconFile: TFile1;
|
|---|
| 84 | X, Y: Integer;
|
|---|
| 85 | ItemSize: Integer;
|
|---|
| 86 | C: Byte;
|
|---|
| 87 | Color: TColor;
|
|---|
| 88 | Index: Integer;
|
|---|
| 89 | begin
|
|---|
| 90 | LoadPalette;
|
|---|
| 91 | Bitmap.SetSize(500, 300);
|
|---|
| 92 | IconFile := TFile1.Create;
|
|---|
| 93 | IconFile.Open('extracted/DUNE.PAK/ICON.ICN');
|
|---|
| 94 | TileData := TFile1Block(IconFile.Blocks[1]).Read;
|
|---|
| 95 | PaletteData := TFile1Block(IconFile.Blocks[2]).Read;
|
|---|
| 96 | TableData := TFile1Block(IconFile.Blocks[3]).Read;
|
|---|
| 97 |
|
|---|
| 98 | // Show all tiles
|
|---|
| 99 | W := 16;
|
|---|
| 100 | H := 16;
|
|---|
| 101 | ItemSize := (W div 2 * H);
|
|---|
| 102 | for I := 0 to Length(IconMap) - 1 do begin
|
|---|
| 103 | //Index := IconMap[I];
|
|---|
| 104 | Index := I;
|
|---|
| 105 | if Index >= Length(TileData) div ItemSize then
|
|---|
| 106 | Index := 0;
|
|---|
| 107 | DrawTile(Bitmap.Canvas, Point((I div 16) * 16, (I mod 16) * 16), Index);
|
|---|
| 108 | Bitmap.Canvas.Brush.Style := bsClear;
|
|---|
| 109 | Bitmap.Canvas.Font.Size := 4;
|
|---|
| 110 | Bitmap.Canvas.Font.Color := clWhite;
|
|---|
| 111 | Bitmap.Canvas.TextOut((I div 16) * 16, (I mod 16) * 16, IntToHex(I, 2));
|
|---|
| 112 | end;
|
|---|
| 113 |
|
|---|
| 114 | IconFile.Free;
|
|---|
| 115 | //IconMap.Canvas.TextOut(0, 0, IntToStr(Length(PaletteData) div 16) + ' ' + IntToStr(Length(Data) div ItemSize));
|
|---|
| 116 | end;
|
|---|
| 117 |
|
|---|
| 118 | procedure TGame.DrawTile(Canvas: TCanvas; Pos: TPoint; Index: Integer);
|
|---|
| 119 | var
|
|---|
| 120 | X, Y: Integer;
|
|---|
| 121 | H, W: Integer;
|
|---|
| 122 | C: Byte;
|
|---|
| 123 | Color: TColor;
|
|---|
| 124 | ItemSize: Integer;
|
|---|
| 125 | begin
|
|---|
| 126 | W := 16;
|
|---|
| 127 | H := 16;
|
|---|
| 128 | ItemSize := (W div 2 * H);
|
|---|
| 129 | if Index >= (Length(TileData) div ItemSize) then
|
|---|
| 130 | raise Exception.Create('Tile index ' + IntToStr(Index) + ' out of range');
|
|---|
| 131 | for Y := 0 to H - 1 do
|
|---|
| 132 | for X := 0 to W - 1 do begin
|
|---|
| 133 | C := TileData[Index * ItemSize + Y * (W div 2) + X div 2 + 8];
|
|---|
| 134 | if (X and 1) = 0 then C := C shr 4
|
|---|
| 135 | else C := C and $f;
|
|---|
| 136 |
|
|---|
| 137 | C := PaletteData[C + TableData[Index] * 16];
|
|---|
| 138 | Color := Palette[C];
|
|---|
| 139 | Canvas.Pixels[Pos.X + X, Pos.Y + Y] := Color;
|
|---|
| 140 | end;
|
|---|
| 141 | end;
|
|---|
| 142 |
|
|---|
| 143 | procedure TGame.LoadMap;
|
|---|
| 144 | var
|
|---|
| 145 | DataFile: TFileStream;
|
|---|
| 146 | F2: TFileStream;
|
|---|
| 147 | Buffer1: array of Byte;
|
|---|
| 148 | Buffer2: array of Byte;
|
|---|
| 149 | Color: TColor;
|
|---|
| 150 | I, II: Integer;
|
|---|
| 151 | W, H: Integer;
|
|---|
| 152 | Size: Integer;
|
|---|
| 153 | Size2: Integer;
|
|---|
| 154 | X, Y: Integer;
|
|---|
| 155 | S: String;
|
|---|
| 156 | B: Byte;
|
|---|
| 157 | begin
|
|---|
| 158 | Bitmap.SetSize(2000, 1000);
|
|---|
| 159 | DataFile := TFileStream.Create('extracted/DUNE.PAK/FAME.CPS', fmOpenRead);
|
|---|
| 160 | SetLength(Buffer2, $ffff);
|
|---|
| 161 | Size := DataFile.ReadWord;
|
|---|
| 162 | DataFile.Position := DataFile.Position + 8;
|
|---|
| 163 | Dec(Size, 8);
|
|---|
| 164 | SetLength(Buffer1, Size);
|
|---|
| 165 | DataFile.Read(Buffer1[0], Length(Buffer1));
|
|---|
| 166 | Buffer2 := Format80(Buffer1);
|
|---|
| 167 |
|
|---|
| 168 | F2 := TFileStream.Create('dump.bin', fmCreate);
|
|---|
| 169 | for Y := 0 to 199 do begin
|
|---|
| 170 | S := '';
|
|---|
| 171 | for X := 0 to 319 do begin
|
|---|
| 172 | B := Buffer2[X + Y * 320];
|
|---|
| 173 | if B = $54 then S := S + ' '
|
|---|
| 174 | else if B = $5a then S := S + '.. '
|
|---|
| 175 | else if B = $68 then S := S + ',, '
|
|---|
| 176 | else S := S + IntToHex(B, 2) + ' ';
|
|---|
| 177 | end;
|
|---|
| 178 | S := S + #13;
|
|---|
| 179 | F2.Write(S[1], Length(S));
|
|---|
| 180 | end;
|
|---|
| 181 | F2.Free;
|
|---|
| 182 |
|
|---|
| 183 | W := 320;
|
|---|
| 184 | H := 500;
|
|---|
| 185 | for Y := 0 to 199 do
|
|---|
| 186 | for X := 0 to 319 do begin
|
|---|
| 187 | I := (Y) * W + (X);
|
|---|
| 188 | //Color := Buffer2[I] shl 1;
|
|---|
| 189 | //Color := RGBToColor(Color, Color, Color);
|
|---|
| 190 | //II := I;
|
|---|
| 191 | //IconMap.Canvas.Pixels[II mod W, II div W] := Color;
|
|---|
| 192 | //DrawTile(Bitmap.Canvas, Point(X * 16, Y * 16), IconMap[IconMap[9] + Buffer2[I]]);
|
|---|
| 193 | Bitmap.Canvas.Pixels[X, Y] := Palette[Buffer2[I]];
|
|---|
| 194 |
|
|---|
| 195 | { Color := (Buffer2[I] shr 4) shl 4;
|
|---|
| 196 | Color := RGBToColor(Color, Color, Color);
|
|---|
| 197 | II := I * 2 + 1;
|
|---|
| 198 | Bitmap.Canvas.Pixels[II mod W, II div W] := Color;
|
|---|
| 199 | }
|
|---|
| 200 | end;
|
|---|
| 201 | DataFile.Free;
|
|---|
| 202 | Bitmap.Canvas.Font.Size := 10;
|
|---|
| 203 | Bitmap.Canvas.TextOut(0, 0, IntToStr(Size) + ' ' + IntToStr(Size2) + ' ' + IntToStr(IW));
|
|---|
| 204 | end;
|
|---|
| 205 |
|
|---|
| 206 | procedure TGame.LoadTexts;
|
|---|
| 207 | var
|
|---|
| 208 | F: TEngFile;
|
|---|
| 209 | begin
|
|---|
| 210 | F := TEngFile.Create;
|
|---|
| 211 | F.LoadFromFile('extracted/ENGLISH.PAK/HERALD.ENG');
|
|---|
| 212 | FormLog.Memo1.Lines.Assign(F.Lines);
|
|---|
| 213 | FormLog.Show;
|
|---|
| 214 | end;
|
|---|
| 215 |
|
|---|
| 216 | procedure TGame.LoadIconMap;
|
|---|
| 217 | var
|
|---|
| 218 | F: TFileStream;
|
|---|
| 219 | begin
|
|---|
| 220 | F := TFileStream.Create('extracted/DUNE.PAK/ICON.MAP', fmOpenRead);
|
|---|
| 221 | SetLength(IconMap, F.Size div SizeOf(Word));
|
|---|
| 222 | F.Read(IconMap[0], F.Size);
|
|---|
| 223 | F.Free;
|
|---|
| 224 | end;
|
|---|
| 225 |
|
|---|
| 226 | procedure TGame.LoadUnitsFile(FileName: string);
|
|---|
| 227 | var
|
|---|
| 228 | F: TShpFile;
|
|---|
| 229 | Bitmap: TBitmap;
|
|---|
| 230 | I: Integer;
|
|---|
| 231 | OutDir: string;
|
|---|
| 232 | begin
|
|---|
| 233 | LoadPalette;
|
|---|
| 234 | F := TShpFile.Create;
|
|---|
| 235 | F.Open(FileName);
|
|---|
| 236 | F.Palette := @Palette;
|
|---|
| 237 | FormMain.Caption := IntToStr(F.Items.Count);
|
|---|
| 238 | Bitmap := TBitmap.Create;
|
|---|
| 239 | OutDir := FileName + '.DIR';
|
|---|
| 240 | ForceDirectories(OutDir);
|
|---|
| 241 | for I := 0 to F.Items.Count - 2 do begin
|
|---|
| 242 | TShpFileItem(F.Items[I]).GetBitmap(Bitmap);
|
|---|
| 243 | Bitmap.SaveToFile(OutDir + DirectorySeparator + IntToStr(I) + '.bmp');
|
|---|
| 244 | end;
|
|---|
| 245 | Bitmap.Free;
|
|---|
| 246 | F.Free;
|
|---|
| 247 | end;
|
|---|
| 248 |
|
|---|
| 249 | procedure TGame.LoadUnits;
|
|---|
| 250 | begin
|
|---|
| 251 | LoadUnitsFile('extracted/DUNE.PAK/UNITS.SHP');
|
|---|
| 252 | LoadUnitsFile('extracted/DUNE.PAK/UNITS1.SHP');
|
|---|
| 253 | LoadUnitsFile('extracted/DUNE.PAK/UNITS2.SHP');
|
|---|
| 254 | LoadUnitsFile('extracted/DUNE.PAK/ARROWS.SHP');
|
|---|
| 255 | LoadUnitsFile('extracted/DUNE.PAK/MENSHPA.SHP');
|
|---|
| 256 | LoadUnitsFile('extracted/DUNE.PAK/MENSHPH.SHP');
|
|---|
| 257 | LoadUnitsFile('extracted/DUNE.PAK/MENSHPM.SHP');
|
|---|
| 258 | LoadUnitsFile('extracted/DUNE.PAK/MENSHPO.SHP');
|
|---|
| 259 | LoadUnitsFile('extracted/DUNE.PAK/MOUSE.SHP');
|
|---|
| 260 | LoadUnitsFile('extracted/DUNE.PAK/PIECES.SHP');
|
|---|
| 261 | LoadUnitsFile('extracted/DUNE.PAK/SHAPES.SHP');
|
|---|
| 262 | end;
|
|---|
| 263 |
|
|---|
| 264 | procedure TGame.LoadWsa;
|
|---|
| 265 | var
|
|---|
| 266 | F: TWsaFile;
|
|---|
| 267 | begin
|
|---|
| 268 | F := TWsaFile.Create;
|
|---|
| 269 | F.Open('extracted/DUNE.PAK/WIN1.WSA');
|
|---|
| 270 | F.Free;
|
|---|
| 271 | end;
|
|---|
| 272 |
|
|---|
| 273 | procedure TGame.LoadData;
|
|---|
| 274 | begin
|
|---|
| 275 | LoadIconMap;
|
|---|
| 276 | LoadIcons;
|
|---|
| 277 | //LoadMap;
|
|---|
| 278 | //LoadTexts;
|
|---|
| 279 | LoadUnits;
|
|---|
| 280 | LoadWSA;
|
|---|
| 281 | end;
|
|---|
| 282 |
|
|---|
| 283 | end.
|
|---|
| 284 |
|
|---|