source: oup/current/FileClasses/BINA.pas@ 1144

Last change on this file since 1144 was 248, checked in by alloc, 17 years ago
File size: 8.3 KB
Line 
1unit BINA;
2
3interface
4
5uses
6 _FileTypes, Grids;
7
8type
9 TFile_BINA = class(TResource)
10 procedure SetOpened(Opened: Boolean); override;
11 private
12 maintype: String;
13 subtype: String;
14 grid: TStringGrid;
15(* panel: TPanel;
16 save: TButton; *)
17 procedure saveclick(Sender: TObject);
18 public
19 procedure InitDataFields; override;
20 procedure InitEditor; override;
21 end;
22
23implementation
24
25uses
26 ConnectionManager, Math, Classes, TypeDefs, _DataTypes, Forms, StdCtrls,
27 Controls, StrUtils, Functions, SysUtils;
28
29procedure TFile_BINA.InitDataFields;
30begin
31 inherited;
32 FDataFields := TBlock.Create(Self, nil, 'Base', '', []);
33 with FDataFields do
34 begin
35 AddField(TResourceID, 'FileID', '', []);
36 AddField(TLevelID, 'LevelID', '', []);
37
38 AddField(TInt, 'RawSize', 'Size of the part in the raw file', [4]);
39 AddField(TRawLink, 'RawOffset', 'At this position starts the part in the raw/sep file', []);
40
41 AddField(TUnused, 'Not used', '', [16]);
42 end;
43 FDataFields.Update(0, -1);
44 FFileStream.Free;
45 FFileStream := nil;
46end;
47
48procedure TFile_BINA.InitEditor;
49var
50 subsize: Integer;
51begin
52 CacheAllRawFiles;
53 SetLength(maintype, 4);
54 FRawCaches[0].RawStream.Read(maintype[1], 4);
55 maintype := ReverseString(maintype);
56 if maintype = 'OBJC' then
57 begin
58 FRawCaches[0].RawStream.Seek($0C, soFromBeginning);
59 FRawCaches[0].RawStream.Read(subsize, 4);
60 if subsize > 0 then
61 begin
62 SetLength(subtype, 4);
63 FRawCaches[0].RawStream.Seek($10, soFromBeginning);
64 FRawCaches[0].RawStream.Read(subtype[1], 4);
65 subtype := ReverseString(subtype);
66 if subtype = 'CHAR' then
67 begin
68 end
69 else if subtype = 'CMBT' then
70 begin
71 end
72 else if subtype = 'CONS' then
73 begin
74 end
75 else if subtype = 'DOOR' then
76 begin
77 end
78 else if subtype = 'FLAG' then
79 begin
80 end
81 else if subtype = 'FURN' then
82 begin
83 end
84 else if subtype = 'MELE' then
85 begin
86 end
87 else if subtype = 'NEUT' then
88 begin
89 end
90 else if subtype = 'PART' then
91 begin
92 end
93 else if subtype = 'PATR' then
94 begin
95 end
96 else if subtype = 'PWRU' then
97 begin
98 end
99 else if subtype = 'SNDG' then
100 begin
101 end
102 else if subtype = 'TRGV' then
103 begin
104 FEditor := TFrame.Create(nil);
105 grid := TStringGrid.Create(FEditor);
106 grid.Align := alClient;
107 grid.DefaultRowHeight := 18;
108 grid.DefaultColWidth := 100;
109 grid.ColCount := 8;
110 grid.RowCount := 2;
111 grid.FixedRows := 1;
112 grid.FixedCols := 0;
113 grid.ColWidths[0] := 150;
114 grid.ColWidths[1] := 125;
115 grid.ColWidths[2] := 125;
116 grid.ColWidths[3] := 125;
117 grid.Cells[0, 0] := 'TrgName';
118 grid.Cells[1, 0] := 'FuncName Enter';
119 grid.Cells[2, 0] := 'FuncName Inside';
120 grid.Cells[3, 0] := 'FuncName Leave';
121 grid.Cells[4, 0] := 'Teams';
122 grid.Cells[5, 0] := 'Settings';
123 grid.Cells[6, 0] := 'X, Y, Z';
124 grid.Cells[7, 0] := 'Size X, Y, Z';
125 grid.Options := [goColSizing,goEditing,
126 goVertLine,goHorzLine,goFixedVertLine,goFixedHorzLine];
127 grid.Parent := FEditor;
128 end
129 else if subtype = 'TRIG' then
130 begin
131 end
132 else if subtype = 'TURR' then
133 begin
134 end
135 else if subtype = 'WEAP' then
136 begin
137 end;
138 end;
139 end
140 else if maintype = 'ONIE' then
141 begin
142 end
143 else if maintype = 'PAR3' then
144 begin
145 end
146 else if maintype = 'SABD' then
147 begin
148 end
149 else if maintype = 'TMBD' then
150 begin
151 end;
152
153 DiscardAllRawCaches;
154
155(*
156 panel := TPanel.Create(FEditor);
157 panel.Align := alBottom;
158 panel.Height := 30;
159 panel.Parent := FEditor;
160 save := TButton.Create(panel);
161 save.Top := 2;
162 save.Left := 2;
163 save.Width := 100;
164 save.Height := 26;
165 save.Caption := 'Save';
166 save.OnClick := saveclick;
167 save.Parent := panel; *)
168end;
169
170procedure TFile_BINA.saveclick(Sender: TObject);
171var
172 i,j: Integer;
173 temps: String;
174 fs: TFileStream;
175 offset: Integer;
176begin
177(* fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\messages_raw_recreated.hex', fmCreate);
178
179 i := grid.RowCount - 2;
180 FFileStream.Seek($1C, soFromBeginning);
181 FFileStream.Write(i, 4);
182 FFileStream.Size := $20 + i * 4;
183
184 for i := 0 to grid.RowCount - 2 do
185 begin
186 for j := 0 to 1 do
187 begin
188 if j = 0 then
189 begin
190 offset := fs.Size;
191 FFileStream.Seek($20 + i*4, soFromBeginning);
192 FFileStream.Write(offset, 4);
193 end;
194 temps := grid.Cells[j, i+1];
195 SetLength(temps, Length(temps)+1);
196 temps[Length(temps)] := #0;
197 fs.Write(temps[1], Length(temps));
198 end;
199 end;
200 fs.Free;
201 fs := TFileStream.Create('C:\Spiele\Oni\GameDataFolder\tests\messages_dat_recreated.hex', fmCreate);
202 ReCreateFile(fs);
203 fs.Free;
204*)end;
205
206
207procedure TFile_BINA.SetOpened(Opened: Boolean);
208var
209 i: Integer;
210 cursize: Integer;
211 curoffset: Integer;
212 raw: TMemoryStream;
213 tempi: Integer;
214 temps: String;
215 j: Integer;
216 tempf: Single;
217begin
218 inherited;
219 if Opened then
220 begin
221 CacheAllRawFiles;
222 raw := FRawCaches[0].RawStream;
223
224 if maintype = 'OBJC' then
225 begin
226 if subtype = 'TRGV' then
227 begin
228 i := 0;
229 curoffset := $0C;
230 raw.Seek(curoffset, soFromBeginning);
231 raw.Read(cursize, 4);
232
233 while cursize > 0 do
234 begin
235 Inc(i);
236 grid.RowCount := 1 + i;
237 grid.Cells[0, i] := ReadString(raw, curoffset + 4 + $24);
238 grid.Cells[1, i] := ReadString(raw, curoffset + 4 + $63);
239 grid.Cells[2, i] := ReadString(raw, curoffset + 4 + $83);
240 grid.Cells[3, i] := ReadString(raw, curoffset + 4 + $A3);
241
242 raw.Seek(curoffset + 4 + $C3, soFromBeginning);
243 tempi := 0;
244 raw.Read(tempi, 1);
245 if tempi > 0 then
246 begin
247 temps := '';
248 for j := 0 to 7 do
249 begin
250 if tempi and (1 shl j) > 0 then
251 begin
252 if Length(temps) > 0 then
253 temps := temps + ', ' + IntToStr(1 shl j)
254 else
255 temps := IntToStr(1 shl j);
256 end;
257 end;
258 end
259 else
260 temps := '0';
261 grid.Cells[4, i] := temps;
262
263 raw.Seek(curoffset + 4 + $15C, soFromBeginning);
264 tempi := 0;
265 raw.Read(tempi, 1);
266 if tempi > 0 then
267 begin
268 temps := '';
269 for j := 0 to 7 do
270 begin
271 if tempi and (1 shl j) > 0 then
272 begin
273 if Length(temps) > 0 then
274 temps := temps + ', ' + IntToStr(1 shl j)
275 else
276 temps := IntToStr(1 shl j);
277 end;
278 end;
279 end
280 else
281 temps := '0';
282 grid.Cells[5, i] := temps;
283
284 raw.Seek(curoffset + 4 + $0C, soFromBeginning);
285 raw.Read(tempf, 4);
286 temps := FormatFloat('#0', tempf);
287 raw.Seek(curoffset + 4 + $10, soFromBeginning);
288 raw.Read(tempf, 4);
289 temps := temps + ', ' + FormatFloat('#0', tempf);
290 raw.Seek(curoffset + 4 + $14, soFromBeginning);
291 raw.Read(tempf, 4);
292 temps := temps + ', ' + FormatFloat('#0', tempf);
293 grid.Cells[6, i] := temps;
294
295 raw.Seek(curoffset + 4 + $C7, soFromBeginning);
296 raw.Read(tempf, 4);
297 temps := FormatFloat('#0', tempf);
298 raw.Seek(curoffset + 4 + $CB, soFromBeginning);
299 raw.Read(tempf, 4);
300 temps := temps + ', ' + FormatFloat('#0', tempf);
301 raw.Seek(curoffset + 4 + $CF, soFromBeginning);
302 raw.Read(tempf, 4);
303 temps := temps + ', ' + FormatFloat('#0', tempf);
304 grid.Cells[7, i] := temps;
305
306 curoffset := curoffset + cursize + 4;
307 raw.Seek(curoffset, soFromBeginning);
308 raw.Read(cursize, 4);
309 end;
310 end;
311 end;
312 end else
313 begin
314 Exit;
315 end;
316end;
317
318end.
Note: See TracBrowser for help on using the repository browser.