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