1 | unit _DataTypes;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes;
|
---|
7 |
|
---|
8 | type
|
---|
9 | TDataField = class
|
---|
10 | protected
|
---|
11 | FOffset: Integer;
|
---|
12 | FName: String;
|
---|
13 | FDescription: String;
|
---|
14 | FDataLength: Integer;
|
---|
15 | FParentFile: TObject;
|
---|
16 | FChanged: Boolean;
|
---|
17 | function GetValueAsString: String; virtual; abstract;
|
---|
18 | public
|
---|
19 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
20 | Name, Description: String; ExtraArgs: Pointer); virtual;
|
---|
21 |
|
---|
22 | procedure Update(Offset, Length: Integer); virtual; abstract;
|
---|
23 |
|
---|
24 | property Offset: Integer read FOffset;
|
---|
25 | property Name: String read FName;
|
---|
26 | property Description: String read FDescription;
|
---|
27 | property DataLength: Integer read FDataLength;
|
---|
28 | property ValueAsString: String read GetValueAsString;
|
---|
29 | end;
|
---|
30 |
|
---|
31 | TFieldType = class of TDataField;
|
---|
32 |
|
---|
33 |
|
---|
34 | TBlock = class(TDataField)
|
---|
35 | private
|
---|
36 | FDataFields: array of TDataField;
|
---|
37 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
38 | function GetFieldByIndex(ID: Integer): TDataField;
|
---|
39 | function GetFieldCount: Integer;
|
---|
40 | public
|
---|
41 | // ExtraArgs: keine
|
---|
42 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
43 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
44 | procedure Update(Offset, Length: Integer); override;
|
---|
45 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
46 | property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
|
---|
47 | property FieldCount: Integer read GetFieldCount;
|
---|
48 |
|
---|
49 | procedure AddField(fieldtype: TFieldType; Offset: Integer;
|
---|
50 | Name, Description: String; ExtraArgs: Pointer);
|
---|
51 | end;
|
---|
52 |
|
---|
53 |
|
---|
54 | TInt = class(TDataField)
|
---|
55 | private
|
---|
56 | FInt: Integer;
|
---|
57 | function GetValueAsString: String; override;
|
---|
58 | public
|
---|
59 | // ExtraArgs: Pointer auf Integer: Bytes of TInt
|
---|
60 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
61 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
62 | procedure Update(Offset, Length: Integer); override;
|
---|
63 | end;
|
---|
64 |
|
---|
65 |
|
---|
66 | TBitSet = class(TDataField)
|
---|
67 | private
|
---|
68 | FBits: Byte;
|
---|
69 | FNames: TStringList;
|
---|
70 | function GetValueAsString: String; override;
|
---|
71 | public
|
---|
72 | // ExtraArgs: Pointer auf TStringList
|
---|
73 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
74 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
75 | procedure Update(Offset, Length: Integer); override;
|
---|
76 | end;
|
---|
77 |
|
---|
78 |
|
---|
79 | TLevelID = class(TDataField)
|
---|
80 | private
|
---|
81 | FLevelID: Integer;
|
---|
82 | function GetValueAsString: String; override;
|
---|
83 | public
|
---|
84 | // ExtraArgs: keine
|
---|
85 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
86 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
87 | procedure Update(Offset, Length: Integer); override;
|
---|
88 | end;
|
---|
89 |
|
---|
90 |
|
---|
91 | TFileID = class(TDataField)
|
---|
92 | private
|
---|
93 | FFileID: Integer;
|
---|
94 | function GetValueAsString: String; override;
|
---|
95 | public
|
---|
96 | // ExtraArgs: keine
|
---|
97 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
98 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
99 | procedure Update(Offset, Length: Integer); override;
|
---|
100 | end;
|
---|
101 |
|
---|
102 |
|
---|
103 | TLinkByID = class(TDataField)
|
---|
104 | private
|
---|
105 | FFileID: Integer;
|
---|
106 | FPosExts: String;
|
---|
107 | function GetValueAsString: String; override;
|
---|
108 | public
|
---|
109 | // ExtraArgs: Pointer auf String: Possible Exts
|
---|
110 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
111 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
112 | procedure Update(Offset, Length: Integer); override;
|
---|
113 | end;
|
---|
114 |
|
---|
115 |
|
---|
116 | TString = class(TDataField)
|
---|
117 | private
|
---|
118 | FString: String;
|
---|
119 | function GetValueAsString: String; override;
|
---|
120 | public
|
---|
121 | // ExtraArgs: Pointer auf Integer: Length
|
---|
122 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
123 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
124 | procedure Update(Offset, Length: Integer); override;
|
---|
125 | end;
|
---|
126 |
|
---|
127 |
|
---|
128 | TArray = class(TDataField)
|
---|
129 | private
|
---|
130 | FDataFields: array of TDataField;
|
---|
131 | function GetFieldByOffset(Offset: Integer): TDataField;
|
---|
132 | function GetFieldByIndex(ID: Integer): TDataField;
|
---|
133 | function GetFieldCount: Integer;
|
---|
134 | public
|
---|
135 | // ExtraArgs: Pointer auf 2 Integer: Length+Count (packed record...)
|
---|
136 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
137 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
138 | procedure Update(Offset, Length: Integer); override;
|
---|
139 | property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
|
---|
140 | property FieldByIndex[ID: Integer]: TDataField read GetFieldByIndex;
|
---|
141 | property FieldCount: Integer read GetFieldCount;
|
---|
142 |
|
---|
143 | procedure AddField(fieldtype: TFieldType; Offset: Integer;
|
---|
144 | Name, Description: String; ExtraArgs: Pointer);
|
---|
145 | end;
|
---|
146 |
|
---|
147 |
|
---|
148 | TRawLink = class(TDataField)
|
---|
149 | private
|
---|
150 | FRawAddress: Integer;
|
---|
151 | function GetValueAsString: String; override;
|
---|
152 | public
|
---|
153 | // ExtraArgs: keine
|
---|
154 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
155 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
156 | procedure Update(Offset, Length: Integer); override;
|
---|
157 | end;
|
---|
158 |
|
---|
159 |
|
---|
160 | TUnused = class(TDataField)
|
---|
161 | private
|
---|
162 | function GetValueAsString: String; override;
|
---|
163 | public
|
---|
164 | // ExtraArgs: Pointer auf Integer: Length
|
---|
165 | constructor Create(ParentFile: TObject; Offset: Integer;
|
---|
166 | Name, Description: String; ExtraArgs: Pointer); override;
|
---|
167 | procedure Update(Offset, Length: Integer); override;
|
---|
168 | end;
|
---|
169 |
|
---|
170 |
|
---|
171 |
|
---|
172 |
|
---|
173 | implementation
|
---|
174 |
|
---|
175 | uses
|
---|
176 | SysUtils, Dialogs, _FileTypes, ConnectionManager;
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 |
|
---|
181 | { TDataType }
|
---|
182 |
|
---|
183 | constructor TDataField.Create(ParentFile: TObject; Offset: Integer;
|
---|
184 | Name, Description: String; ExtraArgs: Pointer);
|
---|
185 | begin
|
---|
186 | FOffset := Offset;
|
---|
187 | FName := Name;
|
---|
188 | FDescription := Description;
|
---|
189 | FParentFile := ParentFile;
|
---|
190 | end;
|
---|
191 |
|
---|
192 |
|
---|
193 |
|
---|
194 | { TString }
|
---|
195 |
|
---|
196 | constructor TString.Create(ParentFile: TObject; Offset: Integer;
|
---|
197 | Name, Description: String; ExtraArgs: Pointer);
|
---|
198 | var
|
---|
199 | fstream: TMemoryStream;
|
---|
200 | i: Integer;
|
---|
201 | begin
|
---|
202 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
203 | FDataLength := Integer(ExtraArgs^);
|
---|
204 | fstream := TFile(ParentFile).FileStream;
|
---|
205 | fstream.Seek(Offset, soFromBeginning);
|
---|
206 | SetLength(FString, FDataLength);
|
---|
207 | fstream.Read(FString[1], FDataLength);
|
---|
208 | for i := 1 to FDataLength do
|
---|
209 | if FString[i] = Chr(0) then
|
---|
210 | begin
|
---|
211 | SetLength(FString, i - 1);
|
---|
212 | Break;
|
---|
213 | end;
|
---|
214 | end;
|
---|
215 |
|
---|
216 | function TString.GetValueAsString: String;
|
---|
217 | begin
|
---|
218 | Result := FString;
|
---|
219 | end;
|
---|
220 |
|
---|
221 | procedure TString.Update(Offset, Length: Integer);
|
---|
222 | begin
|
---|
223 | Exit;
|
---|
224 | end;
|
---|
225 |
|
---|
226 |
|
---|
227 |
|
---|
228 | { TInt }
|
---|
229 |
|
---|
230 | constructor TInt.Create(ParentFile: TObject; Offset: Integer;
|
---|
231 | Name, Description: String; ExtraArgs: Pointer);
|
---|
232 | var
|
---|
233 | fstream: TMemoryStream;
|
---|
234 | begin
|
---|
235 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
236 | FDataLength := Integer(ExtraArgs^);
|
---|
237 | FInt := 0;
|
---|
238 | fstream := TFile(ParentFile).FileStream;
|
---|
239 | fstream.Seek(Offset, soFromBeginning);
|
---|
240 | fstream.Read(FInt, FDataLength);
|
---|
241 | end;
|
---|
242 |
|
---|
243 | function TInt.GetValueAsString: String;
|
---|
244 | begin
|
---|
245 | Result := IntToStr(FInt);
|
---|
246 | end;
|
---|
247 |
|
---|
248 | procedure TInt.Update(Offset, Length: Integer);
|
---|
249 | begin
|
---|
250 | Exit;
|
---|
251 | end;
|
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 | { TArray }
|
---|
256 |
|
---|
257 | procedure TArray.AddField(fieldtype: TFieldType; Offset: Integer;
|
---|
258 | Name, Description: String; ExtraArgs: Pointer);
|
---|
259 | begin
|
---|
260 | Exit;
|
---|
261 | end;
|
---|
262 |
|
---|
263 | constructor TArray.Create(ParentFile: TObject; Offset: Integer;
|
---|
264 | Name, Description: String; ExtraArgs: Pointer);
|
---|
265 | begin
|
---|
266 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
267 | end;
|
---|
268 |
|
---|
269 | function TArray.GetFieldByIndex(ID: Integer): TDataField;
|
---|
270 | begin
|
---|
271 | if ID < Length(FDataFields) then
|
---|
272 | Result := FDataFields[ID]
|
---|
273 | else
|
---|
274 | Result := nil;
|
---|
275 | end;
|
---|
276 |
|
---|
277 | function TArray.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
278 | var
|
---|
279 | i: Integer;
|
---|
280 | begin
|
---|
281 | Result := nil;
|
---|
282 |
|
---|
283 | if Length(FDataFields) > 0 then
|
---|
284 | begin
|
---|
285 | for i := 0 to High(FDataFields) do
|
---|
286 | if FDataFields[i].Offset = Offset then
|
---|
287 | break;
|
---|
288 | if i < Length(FDataFields) then
|
---|
289 | Result := FDataFields[i];
|
---|
290 | end;
|
---|
291 | end;
|
---|
292 |
|
---|
293 | function TArray.GetFieldCount: Integer;
|
---|
294 | begin
|
---|
295 | Result := Length(FDataFields);
|
---|
296 | end;
|
---|
297 |
|
---|
298 | procedure TArray.Update(Offset, Length: Integer);
|
---|
299 | begin
|
---|
300 | Exit;
|
---|
301 | end;
|
---|
302 |
|
---|
303 |
|
---|
304 |
|
---|
305 | { TBlock }
|
---|
306 |
|
---|
307 | procedure TBlock.AddField(fieldtype: TFieldType; Offset: Integer; Name,
|
---|
308 | Description: String; ExtraArgs: Pointer);
|
---|
309 | var
|
---|
310 | i: Integer;
|
---|
311 | begin
|
---|
312 | if Length(FDataFields) > 0 then
|
---|
313 | begin
|
---|
314 | for i := 0 to High(FDataFields) do
|
---|
315 | if FDataFields[i].FOffset = Offset then
|
---|
316 | Break;
|
---|
317 | if i < Length(FDataFields) then
|
---|
318 | begin
|
---|
319 | ShowMessage('Field exists');
|
---|
320 | Exit;
|
---|
321 | end;
|
---|
322 | end;
|
---|
323 | SetLength(FDataFields, Length(FDataFields) + 1);
|
---|
324 | FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(
|
---|
325 | FParentFile, Offset, Name, Description, ExtraArgs);
|
---|
326 | end;
|
---|
327 |
|
---|
328 | constructor TBlock.Create(ParentFile: TObject; Offset: Integer;
|
---|
329 | Name, Description: String; ExtraArgs: Pointer);
|
---|
330 | begin
|
---|
331 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
332 | end;
|
---|
333 |
|
---|
334 | function TBlock.GetFieldByIndex(ID: Integer): TDataField;
|
---|
335 | begin
|
---|
336 | Result := FDataFields[ID];
|
---|
337 | end;
|
---|
338 |
|
---|
339 | function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
|
---|
340 | begin
|
---|
341 | Exit;
|
---|
342 | end;
|
---|
343 |
|
---|
344 | function TBlock.GetFieldCount: Integer;
|
---|
345 | begin
|
---|
346 | Result := Length(FDataFields);
|
---|
347 | end;
|
---|
348 |
|
---|
349 | procedure TBlock.Update(Offset, Length: Integer);
|
---|
350 | begin
|
---|
351 | Exit;
|
---|
352 | end;
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 | { TLevelID }
|
---|
357 |
|
---|
358 | constructor TLevelID.Create(ParentFile: TObject; Offset: Integer;
|
---|
359 | Name, Description: String; ExtraArgs: Pointer);
|
---|
360 | var
|
---|
361 | fstream: TMemoryStream;
|
---|
362 | begin
|
---|
363 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
364 | FDataLength := 4;
|
---|
365 | fstream := TFile(ParentFile).FileStream;
|
---|
366 | fstream.Seek(Offset, soFromBeginning);
|
---|
367 | fstream.Read(FLevelID, 4);
|
---|
368 | FLevelID := FLevelID div 256 div 256 div 256 div 2;
|
---|
369 | end;
|
---|
370 |
|
---|
371 | function TLevelID.GetValueAsString: String;
|
---|
372 | begin
|
---|
373 | Result := IntToStr(FLevelID);
|
---|
374 | end;
|
---|
375 |
|
---|
376 | procedure TLevelID.Update(Offset, Length: Integer);
|
---|
377 | begin
|
---|
378 | Exit;
|
---|
379 | end;
|
---|
380 |
|
---|
381 |
|
---|
382 |
|
---|
383 | { TFileID }
|
---|
384 |
|
---|
385 | constructor TFileID.Create(ParentFile: TObject; Offset: Integer;
|
---|
386 | Name, Description: String; ExtraArgs: Pointer);
|
---|
387 | var
|
---|
388 | fstream: TMemoryStream;
|
---|
389 | begin
|
---|
390 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
391 | FDataLength := 4;
|
---|
392 | fstream := TFile(ParentFile).FileStream;
|
---|
393 | fstream.Seek(Offset, soFromBeginning);
|
---|
394 | fstream.Read(FFileID, 4);
|
---|
395 | if FFileID > 0 then
|
---|
396 | FFileID := FFileID div 256
|
---|
397 | else
|
---|
398 | FFileID := -1;
|
---|
399 | end;
|
---|
400 |
|
---|
401 | function TFileID.GetValueAsString: String;
|
---|
402 | begin
|
---|
403 | Result := IntToStr(FFileID);
|
---|
404 | end;
|
---|
405 |
|
---|
406 | procedure TFileID.Update(Offset, Length: Integer);
|
---|
407 | begin
|
---|
408 | Exit;
|
---|
409 | end;
|
---|
410 |
|
---|
411 |
|
---|
412 |
|
---|
413 | { TLinkByID }
|
---|
414 |
|
---|
415 | constructor TLinkByID.Create(ParentFile: TObject; Offset: Integer; Name,
|
---|
416 | Description: String; ExtraArgs: Pointer);
|
---|
417 | var
|
---|
418 | fstream: TMemoryStream;
|
---|
419 | begin
|
---|
420 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
421 | FDataLength := 4;
|
---|
422 | FPosExts := String(ExtraArgs^);
|
---|
423 | fstream := TFile(ParentFile).FileStream;
|
---|
424 | fstream.Seek(Offset, soFromBeginning);
|
---|
425 | fstream.Read(FFileID, 4);
|
---|
426 | if FFileID > 0 then
|
---|
427 | FFileID := FFileID div 256
|
---|
428 | else
|
---|
429 | FFileID := -1;
|
---|
430 | end;
|
---|
431 |
|
---|
432 | function TLinkByID.GetValueAsString: String;
|
---|
433 | begin
|
---|
434 | Result := IntToStr(FFileID);
|
---|
435 | end;
|
---|
436 |
|
---|
437 | procedure TLinkByID.Update(Offset, Length: Integer);
|
---|
438 | begin
|
---|
439 | Exit;
|
---|
440 | end;
|
---|
441 |
|
---|
442 |
|
---|
443 |
|
---|
444 | { TRawLink }
|
---|
445 |
|
---|
446 | constructor TRawLink.Create(ParentFile: TObject; Offset: Integer; Name,
|
---|
447 | Description: String; ExtraArgs: Pointer);
|
---|
448 | var
|
---|
449 | fstream: TMemoryStream;
|
---|
450 | begin
|
---|
451 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
452 | FDataLength := 4;
|
---|
453 | fstream := TFile(ParentFile).FileStream;
|
---|
454 | fstream.Seek(Offset, soFromBeginning);
|
---|
455 | fstream.Read(FRawAddress, 4);
|
---|
456 | end;
|
---|
457 |
|
---|
458 | function TRawLink.GetValueAsString: String;
|
---|
459 | begin
|
---|
460 | Result := IntToStr(FRawAddress);
|
---|
461 | end;
|
---|
462 |
|
---|
463 | procedure TRawLink.Update(Offset, Length: Integer);
|
---|
464 | begin
|
---|
465 | Exit;
|
---|
466 | end;
|
---|
467 |
|
---|
468 |
|
---|
469 |
|
---|
470 | { TUnused }
|
---|
471 |
|
---|
472 | constructor TUnused.Create(ParentFile: TObject; Offset: Integer; Name,
|
---|
473 | Description: String; ExtraArgs: Pointer);
|
---|
474 | begin
|
---|
475 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
476 | FDataLength := Integer(ExtraArgs^);
|
---|
477 | end;
|
---|
478 |
|
---|
479 | function TUnused.GetValueAsString: String;
|
---|
480 | begin
|
---|
481 | Result := '';
|
---|
482 | end;
|
---|
483 |
|
---|
484 | procedure TUnused.Update(Offset, Length: Integer);
|
---|
485 | begin
|
---|
486 | Exit;
|
---|
487 | end;
|
---|
488 |
|
---|
489 |
|
---|
490 |
|
---|
491 | { TBitSet }
|
---|
492 |
|
---|
493 | constructor TBitSet.Create(ParentFile: TObject; Offset: Integer; Name,
|
---|
494 | Description: String; ExtraArgs: Pointer);
|
---|
495 | var
|
---|
496 | fstream: TMemoryStream;
|
---|
497 | begin
|
---|
498 | inherited Create(ParentFile, Offset, Name, Description, ExtraArgs);
|
---|
499 | FNames := TStringList.Create;
|
---|
500 | FNames.AddStrings(TStringList(ExtraArgs^));
|
---|
501 | FDataLength := 1;
|
---|
502 | FBits := 0;
|
---|
503 | fstream := TFile(ParentFile).FileStream;
|
---|
504 | fstream.Seek(Offset, soFromBeginning);
|
---|
505 | fstream.Read(FBits, FDataLength);
|
---|
506 | end;
|
---|
507 |
|
---|
508 | function TBitSet.GetValueAsString: String;
|
---|
509 | begin
|
---|
510 | Result := IntToStr(FBits);
|
---|
511 | end;
|
---|
512 |
|
---|
513 | procedure TBitSet.Update(Offset, Length: Integer);
|
---|
514 | begin
|
---|
515 | Exit;
|
---|
516 | end;
|
---|
517 |
|
---|
518 | end.
|
---|