Changeset 240 for oup/current/FileClasses
- Timestamp:
- Jul 15, 2007, 1:12:26 AM (17 years ago)
- Location:
- oup/current/FileClasses
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
oup/current/FileClasses/SUBT.pas
r233 r240 4 4 5 5 uses 6 _FileTypes ;6 _FileTypes, Grids, StdCtrls, ExtCtrls; 7 7 8 8 type 9 9 TFile_SUBT = class(TFile) 10 procedure SetOpened(Opened: Boolean); override; 11 private 12 grid: TStringGrid; 13 panel: TPanel; 14 save: TButton; 15 procedure saveclick(Sender: TObject); 10 16 public 11 17 procedure InitDataFields; override; … … 16 22 17 23 uses 18 ConnectionManager, Math, Classes, TypeDefs, _DataTypes, Forms, StdCtrls, Grids; 24 ConnectionManager, Math, Classes, TypeDefs, _DataTypes, Forms, 25 Controls; 19 26 20 27 procedure TFile_SUBT.InitDataFields; 21 var22 tempi: Integer;23 28 begin 24 29 inherited; 25 FDataFields := TBlock.Create(Self, nil, 0, 'Base', '', nil);30 FDataFields := TBlock.Create(Self, nil, 'Base', '', []); 26 31 with FDataFields do 27 32 begin 28 AddField(TFileID, $00, 'FileID', '', nil); 33 AddField(TFileID, 'FileID', '', []); 34 AddField(TLevelID, 'LevelID', '', []); 35 AddField(TUnused, 'Unused data', '', [16]); 29 36 30 AddField(T LevelID, $04, 'LevelID', '', nil);37 AddField(TRawLink, 'Raw Address', '', []); 31 38 32 tempi := 16; 33 AddField(TUnused, $08, 'Unused data', '', @tempi); 34 35 AddField(TRawLink, $18, 'Raw Address', '', nil); 36 37 tempi := 4; 38 with AddField(TArray, $1C, 'SUBT offsets array', '', @tempi) do 39 with TArray(AddField(TArray, 'SUBT offsets array', '', [4])) do 39 40 begin 40 tempi := 4;41 AddField(TInt, $00, 'Offset', '', @tempi);41 AddField(TInt, 'Offset', '', [4]); 42 SetCount; 42 43 end; 43 44 end; 45 FDataFields.Update(0, -1); 46 44 47 FFileStream.Free; 45 48 FFileStream := nil; 46 49 end; 47 50 48 49 51 procedure TFile_SUBT.InitEditor; 50 var51 grid: TStringGrid;52 52 begin 53 53 FEditor := TFrame.Create(nil); 54 54 grid := TStringGrid.Create(FEditor); 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]; 55 68 grid.Parent := FEditor; 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; 81 end; 82 83 procedure TFile_SUBT.saveclick(Sender: TObject); 84 var 85 i,j: Integer; 86 temps: String; 87 fs: TFileStream; 88 offset: Integer; 89 begin 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; 117 end; 118 119 120 procedure TFile_SUBT.SetOpened(Opened: Boolean); 121 var 122 i,j: Integer; 123 offset: Integer; 124 temps: String; 125 pos: Integer; 126 begin 127 inherited; 128 if Opened then 129 begin 130 CacheFile; 131 CacheRawFile($18); 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); 146 FRawCaches[0].Seek(offset, soFromBeginning); 147 end; 148 SetLength(temps, 200); 149 pos := 0; 150 repeat 151 Inc(pos); 152 FRawCaches[0].Read(temps[pos], 1); 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; 56 163 end; 57 164 -
oup/current/FileClasses/_DataTypes.pas
r237 r240 28 28 29 29 procedure Update(Offset, Length: Integer); virtual; abstract; 30 procedure WriteData(stream: TStream); virtual; abstract; 30 31 31 32 property Offset: Integer read FOffset; … … 56 57 Name, Description: String; ExtraArgs: array of const); override; 57 58 procedure Update(Offset, Length: Integer); override; 59 procedure WriteData(stream: TStream); override; 58 60 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset; 59 61 … … 73 75 Name, Description: String; ExtraArgs: array of const); override; 74 76 procedure Update(Offset, Length: Integer); override; 77 procedure WriteData(stream: TStream); override; 75 78 end; 76 79 … … 85 88 Name, Description: String; ExtraArgs: array of const); override; 86 89 procedure Update(Offset, Length: Integer); override; 90 procedure WriteData(stream: TStream); override; 87 91 end; 88 92 … … 98 102 Name, Description: String; ExtraArgs: array of const); override; 99 103 procedure Update(Offset, Length: Integer); override; 104 procedure WriteData(stream: TStream); override; 100 105 end; 101 106 … … 110 115 Name, Description: String; ExtraArgs: array of const); override; 111 116 procedure Update(Offset, Length: Integer); override; 117 procedure WriteData(stream: TStream); override; 112 118 end; 113 119 … … 122 128 Name, Description: String; ExtraArgs: array of const); override; 123 129 procedure Update(Offset, Length: Integer); override; 124 end; 125 126 127 TLinkByID = class(TDataField) 130 procedure WriteData(stream: TStream); override; 131 end; 132 133 134 TDatLink = class(TDataField) 135 private 136 function GetTarget: TObject; virtual; abstract; 137 public 138 property TargetFile: TObject read GetTarget; 139 end; 140 141 142 TLinkByID = class(TDatLink) 128 143 function GetChildCount: Integer; override; 129 144 function GetChild(ID: Integer): TTreeElement; override; … … 132 147 FPosExts: String; 133 148 function GetValueAsString: String; override; 149 function GetTarget: TObject; override; 134 150 public 135 151 // ExtraArgs: Pointer auf String: Possible Exts … … 137 153 Name, Description: String; ExtraArgs: array of const); override; 138 154 procedure Update(Offset, Length: Integer); override; 155 procedure WriteData(stream: TStream); override; 139 156 end; 140 157 … … 149 166 Name, Description: String; ExtraArgs: array of const); override; 150 167 procedure Update(Offset, Length: Integer); override; 168 procedure WriteData(stream: TStream); override; 151 169 end; 152 170 … … 168 186 Name, Description: String; ExtraArgs: array of const); override; 169 187 procedure Update(Offset, Length: Integer); override; 188 procedure WriteData(stream: TStream); override; 170 189 171 190 function AddField(fieldtype: TFieldType; Name, Description: String; … … 186 205 Name, Description: String; ExtraArgs: array of const); override; 187 206 procedure Update(Offset, Length: Integer); override; 207 procedure WriteData(stream: TStream); override; 188 208 end; 189 209 … … 197 217 Name, Description: String; ExtraArgs: array of const); override; 198 218 procedure Update(Offset, Length: Integer); override; 219 procedure WriteData(stream: TStream); override; 199 220 end; 200 221 … … 283 304 end; 284 305 306 procedure TString.WriteData(stream: TStream); 307 var 308 temps: String; 309 i: Integer; 310 begin 311 temps := FString; 312 SetLength(temps, FDataLength); 313 for i := Length(FString) + 1 to FDataLength do 314 temps[i] := #0; 315 stream.Write(temps[1], FDataLength); 316 end; 317 285 318 286 319 … … 307 340 fstream.Seek(FOffset, soFromBeginning); 308 341 fstream.Read(FInt, FDataLength); 342 end; 343 344 procedure TInt.WriteData(stream: TStream); 345 begin 346 stream.Write(FInt, FDataLength); 309 347 end; 310 348 … … 418 456 419 457 procedure TArray.Update(Offset, Length: Integer); 458 var 459 i: Integer; 460 field: TDataField; 461 begin 462 if System.Length(FDataFields) > 0 then 463 begin 464 if Length > 0 then 465 begin 466 for i := 0 to High(FDataFields) do 467 begin 468 field := FDataFields[i]; 469 if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or 470 ((field.Offset > Offset) and (field.Offset < Offset + Length)) or 471 ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then 472 field.Update(Offset, Length); 473 end; 474 end else begin 475 for i := 0 to High(FDataFields) do 476 FDataFields[i].Update(Offset, Length); 477 end; 478 end; 479 end; 480 481 procedure TArray.UpdateSize; 482 var 483 i: Integer; 484 begin 485 FDataLength := FCounterSize; 486 if Length(FDataFields) > 0 then 487 for i := 0 to High(FDataFields) do 488 FDataLength := FDataLength + FDataFields[i].DataLength; 489 FParentBlock.UpdateSize; 490 end; 491 492 procedure TArray.WriteData(stream: TStream); 493 var 494 i: Integer; 495 begin 496 if FCounterSize > 0 then 497 stream.Write(FBlockCount, FCounterSize); 498 if Length(FDataFields) > 0 then 499 for i := 0 to High(FDataFields) do 500 FDataFields[i].WriteData(stream); 501 end; 502 503 504 505 { TBlock } 506 507 function TBlock.AddField(fieldtype: TFieldType; Name, 508 Description: String; ExtraArgs: array of const): TDataField; 509 begin 510 SetLength(FDataFields, Length(FDataFields) + 1); 511 FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create( 512 FParentFile, Self, Name, Description, ExtraArgs); 513 Result := FDataFields[High(FDataFields)]; 514 FDataLength := FDataLength + Result.DataLength; 515 if Assigned(FParentBlock) then 516 FParentBlock.UpdateSize; 517 end; 518 519 constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer; 520 Name, Description: String; ExtraArgs: array of const); 521 begin 522 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs); 523 end; 524 525 function TBlock.GetChild(ID: Integer): TTreeElement; 526 begin 527 Result := FDataFields[ID]; 528 end; 529 530 function TBlock.GetChildCount: Integer; 531 begin 532 Result := Length(FDataFields); 533 end; 534 535 function TBlock.GetFieldByOffset(Offset: Integer): TDataField; 536 begin 537 Exit; 538 end; 539 540 procedure TBlock.Update(Offset, Length: Integer); 420 541 var 421 542 i: Integer; … … 443 564 end; 444 565 445 procedure TArray.UpdateSize;446 var447 i: Integer;448 begin449 FDataLength := FCounterSize;450 if Length(FDataFields) > 0 then451 for i := 0 to High(FDataFields) do452 FDataLength := FDataLength + FDataFields[i].DataLength;453 FParentBlock.UpdateSize;454 end;455 456 457 458 { TBlock }459 460 function TBlock.AddField(fieldtype: TFieldType; Name,461 Description: String; ExtraArgs: array of const): TDataField;462 begin463 SetLength(FDataFields, Length(FDataFields) + 1);464 FDataFields[High(FDataFields)] := TFieldType(fieldtype).Create(465 FParentFile, Self, Name, Description, ExtraArgs);466 Result := FDataFields[High(FDataFields)];467 FDataLength := FDataLength + Result.DataLength;468 if Assigned(FParentBlock) then469 FParentBlock.UpdateSize;470 end;471 472 constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;473 Name, Description: String; ExtraArgs: array of const);474 begin475 inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);476 end;477 478 function TBlock.GetChild(ID: Integer): TTreeElement;479 begin480 Result := FDataFields[ID];481 end;482 483 function TBlock.GetChildCount: Integer;484 begin485 Result := Length(FDataFields);486 end;487 488 function TBlock.GetFieldByOffset(Offset: Integer): TDataField;489 begin490 Exit;491 end;492 493 procedure TBlock.Update(Offset, Length: Integer);494 var495 i: Integer;496 field: TDataField;497 begin498 if System.Length(FDataFields) > 0 then499 begin500 if Length > 0 then501 begin502 for i := 0 to High(FDataFields) do503 begin504 field := FDataFields[i];505 if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or506 ((field.Offset > Offset) and (field.Offset < Offset + Length)) or507 ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then508 field.Update(Offset, Length);509 end;510 end else begin511 for i := 0 to High(FDataFields) do512 begin513 FDataFields[i].Update(Offset, Length);514 end;515 end;516 end;517 end;518 519 566 procedure TBlock.UpdateSize; 520 567 var … … 529 576 end; 530 577 578 procedure TBlock.WriteData(stream: TStream); 579 var 580 i: Integer; 581 begin 582 if Length(FDataFields) > 0 then 583 for i := 0 to High(FDataFields) do 584 FDataFields[i].WriteData(stream); 585 end; 531 586 532 587 … … 554 609 fstream.Read(FLevelID, 4); 555 610 FLevelID := FLevelID div 256 div 256 div 256 div 2; 611 end; 612 613 procedure TLevelID.WriteData(stream: TStream); 614 var 615 tempi: Integer; 616 begin 617 tempi := FLevelID * 256 * 256 * 256 * 2 + 1; 618 stream.Write(tempi, 4); 556 619 end; 557 620 … … 586 649 end; 587 650 651 procedure TFileID.WriteData(stream: TStream); 652 var 653 tempi: Integer; 654 begin 655 if FFileID >= 0 then 656 tempi := FFileID * 256 + 1 657 else 658 tempi := 0; 659 stream.Write(tempi, 4); 660 end; 661 588 662 589 663 … … 616 690 else 617 691 Result := 0; 692 end; 693 694 function TLinkByID.GetTarget: TObject; 695 begin 696 if FFileID > 0 then 697 Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID] 698 else 699 Result := nil; 618 700 end; 619 701 … … 639 721 end; 640 722 723 procedure TLinkByID.WriteData(stream: TStream); 724 var 725 tempi: Integer; 726 begin 727 if FFileID >= 0 then 728 tempi := FFileID * 256 + 1 729 else 730 tempi := 0; 731 stream.Write(tempi, 4); 732 end; 733 641 734 642 735 … … 667 760 end; 668 761 762 procedure TRawLink.WriteData(stream: TStream); 763 begin 764 stream.Write(FRawAddress, 4); 765 end; 766 669 767 670 768 … … 686 784 begin 687 785 Exit; 786 end; 787 788 procedure TUnused.WriteData(stream: TStream); 789 var 790 i: Integer; 791 tempb: Byte; 792 begin 793 tempb := 0; 794 for i := 1 to FDataLength do 795 stream.Write(tempb, 1); 688 796 end; 689 797 … … 732 840 end; 733 841 842 procedure TBitSet.WriteData(stream: TStream); 843 begin 844 stream.Write(FBits, FDataLength); 845 end; 846 734 847 735 848 … … 758 871 end; 759 872 873 procedure TFloat.WriteData(stream: TStream); 874 begin 875 stream.Write(FFloat, 4); 876 end; 877 760 878 761 879 end. -
oup/current/FileClasses/_FileTypes.pas
r238 r240 4 4 5 5 uses 6 TypeDefs, _ DataTypes, _TreeElement, Classes, Forms;6 TypeDefs, _TreeElement, Classes, Forms, _DataTypes; 7 7 8 8 … … 15 15 FFileInfo: TFileInfo; 16 16 FFileStream: TMemoryStream; 17 FRawCaches: array of TMemoryStream; 17 18 18 19 FCached: Boolean; … … 24 25 FOpened: Boolean; 25 26 27 function GetEditor: TFrame; 26 28 function GetFieldByOffset(Offset: Integer): TDataField; 27 published 29 procedure SetOpened(Opened: Boolean); virtual; 30 published 28 31 public 29 32 constructor Create(ConnectionID, FileID: Integer); virtual; … … 33 36 procedure InitEditor; virtual; 34 37 38 procedure ReCreateFile(fs: TStream); 39 40 procedure CacheFile; 41 procedure CacheRawFile(Offset: Integer); 42 35 43 property FileStream: TMemoryStream read FFileStream; 36 44 property FileInfo: TFileInfo read FFileInfo; 37 property ConnectionID: Integer read FConnectionID;38 45 39 46 property Cached: Boolean read FCached; 40 47 property Changed: Boolean read FChanged write FChanged; 41 48 42 property Editor: TFrame read FEditor;43 property Opened: Boolean read FOpened write FOpened;49 property Editor: TFrame read GetEditor; 50 property Opened: Boolean read FOpened write SetOpened; 44 51 45 52 property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset; … … 58 65 { TFileType } 59 66 67 procedure TFile.CacheFile; 68 begin 69 if not Assigned(FFileStream) then 70 begin 71 FFileStream := TMemoryStream.Create; 72 ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream)); 73 end; 74 end; 75 76 77 procedure TFile.CacheRawFile(Offset: Integer); 78 var 79 rawlist: TRawDataList; 80 i: Integer; 81 begin 82 rawlist := ConManager.Connection[ConnectionID].GetRawList(FFileInfo.ID); 83 if Length(rawlist) > 0 then 84 begin 85 for i := 0 to High(rawlist) do 86 begin 87 if rawlist[i].SrcOffset = Offset then 88 begin 89 if not Assigned(FRawCaches[i]) then 90 begin 91 FRawCaches[i] := TMemoryStream.Create; 92 ConManager.Connection[ConnectionID].LoadRawFile(FFileInfo.ID, Offset, TStream(FRawCaches[i])); 93 end; 94 end; 95 end; 96 end; 97 end; 98 99 100 procedure TFile.SetOpened(Opened: Boolean); 101 begin 102 FOpened := Opened; 103 end; 104 105 60 106 constructor TFile.Create(ConnectionID, FileID: Integer); 61 107 begin 62 108 FConnectionID := ConnectionID; 63 109 FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID); 110 111 SetLength(FRawCaches, Length(ConManager.Connection[ConnectionID].GetRawList(FileID))); 64 112 65 113 FCached := False; … … 107 155 108 156 157 function TFile.GetEditor: TFrame; 158 begin 159 if not Assigned(FEditor) then 160 InitEditor; 161 Result := FEditor; 162 end; 163 164 109 165 procedure TFile.InitDataFields; 110 166 begin … … 122 178 123 179 180 //********************************************************* 181 //********************************************************* 182 //********************************************************* 183 procedure TFile.ReCreateFile(fs: TStream); 184 const 185 temp0: array[0..31] of Byte = 186 ($AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE, 187 $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE, 188 $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE, 189 $AD,$DE,$AD,$DE,$AD,$DE,$AD,$DE); 190 var 191 count: Integer; 192 begin 193 FDataFields.WriteData(fs); 194 count := fs.Size mod 32; 195 if count > 0 then 196 fs.Write(temp0[count], 32 - count); 197 end; 198 //********************************************************* 199 //********************************************************* 200 //********************************************************* 201 124 202 end. -
oup/current/FileClasses/_MetaTypes.pas
r237 r240 5 5 uses 6 6 _FileTypes, _EmptyFile, _Unlinked, _DataTypes, _Extensions, _TreeElement, 7 AKVA, TXAN, TXMP;7 AKVA, SUBT, TXAN, TXMP; 8 8 // ABNA, AGDB, AGQC, AGQG, AGQM, AGQR, AISA, AITR, AIWA, AKAA, AKBA, AKBP, AKDA, 9 9 // AKEV, AKOT, AKVA, BINA, CBPI, CBPM, CONS, CRSA, DOOR, DPge, EDIA, ENVP, FILM, … … 24 24 TExtensions = _Extensions.TExtensions; 25 25 TDataField = _DataTypes.TDataField; 26 TDatLink = _DataTypes.TDatLink; 26 27 27 28 TFileClass = class of TFile; … … 32 33 33 34 const 34 FileDescs: array[0.. 2] of TFileDesc = (35 FileDescs: array[0..3] of TFileDesc = ( 35 36 (ext: 'AKVA'; ftype: TFile_AKVA), 37 (ext: 'SUBT'; ftype: TFile_SUBT), 36 38 (ext: 'TXAN'; ftype: TFile_TXAN), 37 39 (ext: 'TXMP'; ftype: TFile_TXMP)
Note:
See TracChangeset
for help on using the changeset viewer.