source: oup/current/FileClasses/SUBT.pas@ 336

Last change on this file since 336 was 248, checked in by alloc, 17 years ago
File size: 3.8 KB
RevLine 
[215]1unit SUBT;
2
3interface
4
5uses
[240]6 _FileTypes, Grids, StdCtrls, ExtCtrls;
[215]7
8type
[248]9 TFile_SUBT = class(TResource)
[240]10 procedure SetOpened(Opened: Boolean); override;
11 private
12 grid: TStringGrid;
13 panel: TPanel;
14 save: TButton;
15 procedure saveclick(Sender: TObject);
[215]16 public
17 procedure InitDataFields; override;
18 procedure InitEditor; override;
19 end;
20
21implementation
22
23uses
[240]24 ConnectionManager, Math, Classes, TypeDefs, _DataTypes, Forms,
25 Controls;
[215]26
27procedure TFile_SUBT.InitDataFields;
28begin
29 inherited;
[240]30 FDataFields := TBlock.Create(Self, nil, 'Base', '', []);
[215]31 with FDataFields do
32 begin
[248]33 AddField(TResourceID, 'FileID', '', []);
[240]34 AddField(TLevelID, 'LevelID', '', []);
35 AddField(TUnused, 'Unused data', '', [16]);
[215]36
[241]37 AddField(TRawLink, 'Raw Address', '', ['SUBT']);
[215]38
[240]39 with TArray(AddField(TArray, 'SUBT offsets array', '', [4])) do
[215]40 begin
[240]41 AddField(TInt, 'Offset', '', [4]);
42 SetCount;
[215]43 end;
44 end;
[240]45 FDataFields.Update(0, -1);
46
[233]47 FFileStream.Free;
48 FFileStream := nil;
[215]49end;
50
51procedure TFile_SUBT.InitEditor;
52begin
53 FEditor := TFrame.Create(nil);
[233]54 grid := TStringGrid.Create(FEditor);
[240]55 grid.Align := alClient;
56 grid.DefaultRowHeight := 18;
57 grid.DefaultColWidth := 100;
58 grid.ColCount := 2;
59 grid.RowCount := 4;
60 grid.FixedRows := 1;
61 grid.FixedCols := 0;
62 grid.ColWidths[0] := 80;
63 grid.ColWidths[1] := 200;
64 grid.Cells[0, 0] := 'Name';
65 grid.Cells[1, 0] := 'Content';
66 grid.Options := [goColSizing,goEditing,
67 goVertLine,goHorzLine,goFixedVertLine,goFixedHorzLine];
[233]68 grid.Parent := FEditor;
[240]69 panel := TPanel.Create(FEditor);
70 panel.Align := alBottom;
71 panel.Height := 30;
72 panel.Parent := FEditor;
73 save := TButton.Create(panel);
74 save.Top := 2;
75 save.Left := 2;
76 save.Width := 100;
77 save.Height := 26;
78 save.Caption := 'Save';
79 save.OnClick := saveclick;
80 save.Parent := panel;
[215]81end;
82
[240]83procedure TFile_SUBT.saveclick(Sender: TObject);
84var
85 i,j: Integer;
86 temps: String;
87 fs: TFileStream;
88 offset: Integer;
89begin
90 fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\messages_raw_recreated.hex', fmCreate);
91
92 i := grid.RowCount - 2;
93 FFileStream.Seek($1C, soFromBeginning);
94 FFileStream.Write(i, 4);
95 FFileStream.Size := $20 + i * 4;
96
97 for i := 0 to grid.RowCount - 2 do
98 begin
99 for j := 0 to 1 do
100 begin
101 if j = 0 then
102 begin
103 offset := fs.Size;
104 FFileStream.Seek($20 + i*4, soFromBeginning);
105 FFileStream.Write(offset, 4);
106 end;
107 temps := grid.Cells[j, i+1];
108 SetLength(temps, Length(temps)+1);
109 temps[Length(temps)] := #0;
110 fs.Write(temps[1], Length(temps));
111 end;
112 end;
113 fs.Free;
114 fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\messages_dat_recreated.hex', fmCreate);
115 ReCreateFile(fs);
116 fs.Free;
117end;
118
119
120procedure TFile_SUBT.SetOpened(Opened: Boolean);
121var
122 i,j: Integer;
123 offset: Integer;
124 temps: String;
125 pos: Integer;
126begin
127 inherited;
128 if Opened then
129 begin
130 CacheFile;
[245]131 CacheAllRawFiles;
[240]132
133 FFileStream.Seek($1C, soFromBeginning);
134 FFileStream.Read(i, 4);
135
136 grid.RowCount := 1 + i;
137
138 for i := 0 to grid.RowCount - 2 do
139 begin
140 for j := 0 to 1 do
141 begin
142 if j = 0 then
143 begin
144 FFileStream.Seek($20 + i*4, soFromBeginning);
145 FFileStream.Read(offset, 4);
[245]146 FRawCaches[0].RawStream.Seek(offset, soFromBeginning);
[240]147 end;
148 SetLength(temps, 200);
149 pos := 0;
150 repeat
151 Inc(pos);
[245]152 FRawCaches[0].RawStream.Read(temps[pos], 1);
[240]153 until temps[pos] = #0;
154 SetLength(temps, pos - 1);
155 grid.Cells[j, i+1] := temps;
156 end;
157 end;
158
159 end else
160 begin
161 Exit;
162 end;
163end;
164
[215]165end.
Note: See TracBrowser for help on using the repository browser.