Ignore:
Timestamp:
Jul 15, 2007, 1:12:26 AM (17 years ago)
Author:
alloc
Message:
 
Location:
oup/current/FileClasses
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • oup/current/FileClasses/SUBT.pas

    r233 r240  
    44
    55uses
    6   _FileTypes;
     6  _FileTypes, Grids, StdCtrls, ExtCtrls;
    77
    88type
    99  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);
    1016    public
    1117      procedure InitDataFields; override;
     
    1622
    1723uses
    18   ConnectionManager, Math, Classes, TypeDefs, _DataTypes, Forms, StdCtrls, Grids;
     24  ConnectionManager, Math, Classes, TypeDefs, _DataTypes, Forms,
     25  Controls;
    1926
    2027procedure TFile_SUBT.InitDataFields;
    21 var
    22   tempi: Integer;
    2328begin
    2429  inherited;
    25   FDataFields := TBlock.Create(Self, nil, 0, 'Base', '', nil);
     30  FDataFields := TBlock.Create(Self, nil, 'Base', '', []);
    2631  with FDataFields do
    2732  begin
    28     AddField(TFileID, $00, 'FileID', '', nil);
     33    AddField(TFileID, 'FileID', '', []);
     34    AddField(TLevelID, 'LevelID', '', []);
     35    AddField(TUnused, 'Unused data', '', [16]);
    2936
    30     AddField(TLevelID, $04, 'LevelID', '', nil);
     37    AddField(TRawLink, 'Raw Address', '', []);
    3138
    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
    3940    begin
    40       tempi := 4;
    41       AddField(TInt, $00, 'Offset', '', @tempi);
     41      AddField(TInt, 'Offset', '', [4]);
     42      SetCount;
    4243    end;
    4344  end;
     45  FDataFields.Update(0, -1);
     46
    4447  FFileStream.Free;
    4548  FFileStream := nil;
    4649end;
    4750
    48 
    4951procedure TFile_SUBT.InitEditor;
    50 var
    51   grid: TStringGrid;
    5252begin
    5353  FEditor := TFrame.Create(nil);
    5454  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];
    5568  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;
     81end;
     82
     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;
     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;
    56163end;
    57164
  • oup/current/FileClasses/_DataTypes.pas

    r237 r240  
    2828
    2929      procedure Update(Offset, Length: Integer); virtual; abstract;
     30      procedure WriteData(stream: TStream); virtual; abstract;
    3031
    3132      property Offset: Integer read FOffset;
     
    5657          Name, Description: String; ExtraArgs: array of const); override;
    5758      procedure Update(Offset, Length: Integer); override;
     59      procedure WriteData(stream: TStream); override;
    5860      property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
    5961
     
    7375          Name, Description: String; ExtraArgs: array of const); override;
    7476      procedure Update(Offset, Length: Integer); override;
     77      procedure WriteData(stream: TStream); override;
    7578  end;
    7679
     
    8588          Name, Description: String; ExtraArgs: array of const); override;
    8689      procedure Update(Offset, Length: Integer); override;
     90      procedure WriteData(stream: TStream); override;
    8791  end;
    8892
     
    98102          Name, Description: String; ExtraArgs: array of const); override;
    99103      procedure Update(Offset, Length: Integer); override;
     104      procedure WriteData(stream: TStream); override;
    100105  end;
    101106
     
    110115          Name, Description: String; ExtraArgs: array of const); override;
    111116      procedure Update(Offset, Length: Integer); override;
     117      procedure WriteData(stream: TStream); override;
    112118  end;
    113119
     
    122128          Name, Description: String; ExtraArgs: array of const); override;
    123129      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)
    128143      function GetChildCount: Integer; override;
    129144      function GetChild(ID: Integer): TTreeElement; override;
     
    132147      FPosExts: String;
    133148      function GetValueAsString: String; override;
     149      function GetTarget: TObject; override;
    134150    public
    135151      // ExtraArgs: Pointer auf String: Possible Exts
     
    137153          Name, Description: String; ExtraArgs: array of const); override;
    138154      procedure Update(Offset, Length: Integer); override;
     155      procedure WriteData(stream: TStream); override;
    139156  end;
    140157
     
    149166          Name, Description: String; ExtraArgs: array of const); override;
    150167      procedure Update(Offset, Length: Integer); override;
     168      procedure WriteData(stream: TStream); override;
    151169  end;
    152170
     
    168186          Name, Description: String; ExtraArgs: array of const); override;
    169187      procedure Update(Offset, Length: Integer); override;
     188      procedure WriteData(stream: TStream); override;
    170189
    171190      function AddField(fieldtype: TFieldType; Name, Description: String;
     
    186205          Name, Description: String; ExtraArgs: array of const); override;
    187206      procedure Update(Offset, Length: Integer); override;
     207      procedure WriteData(stream: TStream); override;
    188208  end;
    189209
     
    197217          Name, Description: String; ExtraArgs: array of const); override;
    198218      procedure Update(Offset, Length: Integer); override;
     219      procedure WriteData(stream: TStream); override;
    199220  end;
    200221
     
    283304end;
    284305
     306procedure TString.WriteData(stream: TStream);
     307var
     308  temps: String;
     309  i: Integer;
     310begin
     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);
     316end;
     317
    285318
    286319
     
    307340  fstream.Seek(FOffset, soFromBeginning);
    308341  fstream.Read(FInt, FDataLength);
     342end;
     343
     344procedure TInt.WriteData(stream: TStream);
     345begin
     346  stream.Write(FInt, FDataLength);
    309347end;
    310348
     
    418456
    419457procedure TArray.Update(Offset, Length: Integer);
     458var
     459  i: Integer;
     460  field: TDataField;
     461begin
     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;
     479end;
     480
     481procedure TArray.UpdateSize;
     482var
     483  i: Integer;
     484begin
     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;
     490end;
     491
     492procedure TArray.WriteData(stream: TStream);
     493var
     494  i: Integer;
     495begin
     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);
     501end;
     502
     503
     504
     505{ TBlock }
     506
     507function TBlock.AddField(fieldtype: TFieldType; Name,
     508    Description: String; ExtraArgs: array of const): TDataField;
     509begin
     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;
     517end;
     518
     519constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;
     520    Name, Description: String; ExtraArgs: array of const);
     521begin
     522  inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
     523end;
     524
     525function TBlock.GetChild(ID: Integer): TTreeElement;
     526begin
     527  Result := FDataFields[ID];
     528end;
     529
     530function TBlock.GetChildCount: Integer;
     531begin
     532  Result := Length(FDataFields);
     533end;
     534
     535function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
     536begin
     537  Exit;
     538end;
     539
     540procedure TBlock.Update(Offset, Length: Integer);
    420541var
    421542  i: Integer;
     
    443564end;
    444565
    445 procedure TArray.UpdateSize;
    446 var
    447   i: Integer;
    448 begin
    449   FDataLength := FCounterSize;
    450   if Length(FDataFields) > 0 then
    451     for i := 0 to High(FDataFields) do
    452       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 begin
    463   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) then
    469     FParentBlock.UpdateSize;
    470 end;
    471 
    472 constructor TBlock.Create(ParentFile: TObject; ParentBlock: TContainer;
    473     Name, Description: String; ExtraArgs: array of const);
    474 begin
    475   inherited Create(ParentFile, ParentBlock, Name, Description, ExtraArgs);
    476 end;
    477 
    478 function TBlock.GetChild(ID: Integer): TTreeElement;
    479 begin
    480   Result := FDataFields[ID];
    481 end;
    482 
    483 function TBlock.GetChildCount: Integer;
    484 begin
    485   Result := Length(FDataFields);
    486 end;
    487 
    488 function TBlock.GetFieldByOffset(Offset: Integer): TDataField;
    489 begin
    490   Exit;
    491 end;
    492 
    493 procedure TBlock.Update(Offset, Length: Integer);
    494 var
    495   i: Integer;
    496   field: TDataField;
    497 begin
    498   if System.Length(FDataFields) > 0 then
    499   begin
    500     if Length > 0 then
    501     begin
    502       for i := 0 to High(FDataFields) do
    503       begin
    504         field := FDataFields[i];
    505         if ((field.Offset < Offset) and (field.Offset + field.DataLength > Offset + Length)) or
    506           ((field.Offset > Offset) and (field.Offset < Offset + Length)) or
    507           ((field.Offset + field.DataLength > Offset) and (field.Offset+field.DataLength < Offset + Length)) then
    508           field.Update(Offset, Length);
    509       end;
    510     end else begin
    511       for i := 0 to High(FDataFields) do
    512       begin
    513         FDataFields[i].Update(Offset, Length);
    514       end;
    515     end;
    516   end;
    517 end;
    518 
    519566procedure TBlock.UpdateSize;
    520567var
     
    529576end;
    530577
     578procedure TBlock.WriteData(stream: TStream);
     579var
     580  i: Integer;
     581begin
     582  if Length(FDataFields) > 0 then
     583    for i := 0 to High(FDataFields) do
     584      FDataFields[i].WriteData(stream);
     585end;
    531586
    532587
     
    554609  fstream.Read(FLevelID, 4);
    555610  FLevelID := FLevelID div 256 div 256 div 256 div 2;
     611end;
     612
     613procedure TLevelID.WriteData(stream: TStream);
     614var
     615  tempi: Integer;
     616begin
     617  tempi := FLevelID * 256 * 256 * 256 * 2 + 1;
     618  stream.Write(tempi, 4);
    556619end;
    557620
     
    586649end;
    587650
     651procedure TFileID.WriteData(stream: TStream);
     652var
     653  tempi: Integer;
     654begin
     655  if FFileID >= 0 then
     656    tempi := FFileID * 256 + 1
     657  else
     658    tempi := 0;
     659  stream.Write(tempi, 4);
     660end;
     661
    588662
    589663
     
    616690  else
    617691    Result := 0;
     692end;
     693
     694function TLinkByID.GetTarget: TObject;
     695begin
     696  if FFileID > 0 then
     697    Result := ConManager.Connection[FConnectionID].MetaData.FileById[FFileID]
     698  else
     699    Result := nil;
    618700end;
    619701
     
    639721end;
    640722
     723procedure TLinkByID.WriteData(stream: TStream);
     724var
     725  tempi: Integer;
     726begin
     727  if FFileID >= 0 then
     728    tempi := FFileID * 256 + 1
     729  else
     730    tempi := 0;
     731  stream.Write(tempi, 4);
     732end;
     733
    641734
    642735
     
    667760end;
    668761
     762procedure TRawLink.WriteData(stream: TStream);
     763begin
     764  stream.Write(FRawAddress, 4);
     765end;
     766
    669767
    670768
     
    686784begin
    687785  Exit;
     786end;
     787
     788procedure TUnused.WriteData(stream: TStream);
     789var
     790  i: Integer;
     791  tempb: Byte;
     792begin
     793  tempb := 0;
     794  for i := 1 to FDataLength do
     795    stream.Write(tempb, 1);
    688796end;
    689797
     
    732840end;
    733841
     842procedure TBitSet.WriteData(stream: TStream);
     843begin
     844  stream.Write(FBits, FDataLength);
     845end;
     846
    734847
    735848
     
    758871end;
    759872
     873procedure TFloat.WriteData(stream: TStream);
     874begin
     875  stream.Write(FFloat, 4);
     876end;
     877
    760878
    761879end.
  • oup/current/FileClasses/_FileTypes.pas

    r238 r240  
    44
    55uses
    6   TypeDefs, _DataTypes, _TreeElement, Classes, Forms;
     6  TypeDefs, _TreeElement, Classes, Forms, _DataTypes;
    77
    88
     
    1515      FFileInfo: TFileInfo;
    1616      FFileStream: TMemoryStream;
     17      FRawCaches: array of TMemoryStream;
    1718
    1819      FCached: Boolean;
     
    2425      FOpened: Boolean;
    2526
     27      function GetEditor: TFrame;
    2628      function GetFieldByOffset(Offset: Integer): TDataField;
    27   published
     29      procedure SetOpened(Opened: Boolean); virtual;
     30    published
    2831    public
    2932      constructor Create(ConnectionID, FileID: Integer); virtual;
     
    3336      procedure InitEditor; virtual;
    3437
     38      procedure ReCreateFile(fs: TStream);
     39
     40      procedure CacheFile;
     41      procedure CacheRawFile(Offset: Integer);
     42
    3543      property FileStream: TMemoryStream read FFileStream;
    3644      property FileInfo: TFileInfo read FFileInfo;
    37       property ConnectionID: Integer read FConnectionID;
    3845
    3946      property Cached: Boolean read FCached;
    4047      property Changed: Boolean read FChanged write FChanged;
    4148
    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;
    4451
    4552      property FieldByOffset[Offset: Integer]: TDataField read GetFieldByOffset;
     
    5865{ TFileType }
    5966
     67procedure TFile.CacheFile;
     68begin
     69  if not Assigned(FFileStream) then
     70  begin
     71    FFileStream := TMemoryStream.Create;
     72    ConManager.Connection[FConnectionID].LoadDatFile(FFileInfo.ID, TStream(FFileStream));
     73  end;
     74end;
     75
     76
     77procedure TFile.CacheRawFile(Offset: Integer);
     78var
     79  rawlist: TRawDataList;
     80  i: Integer;
     81begin
     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;
     97end;
     98
     99
     100procedure TFile.SetOpened(Opened: Boolean);
     101begin
     102  FOpened := Opened;
     103end;
     104
     105
    60106constructor TFile.Create(ConnectionID, FileID: Integer);
    61107begin
    62108  FConnectionID := ConnectionID;
    63109  FFileInfo := ConManager.Connection[ConnectionID].GetFileInfo(FileID);
     110
     111  SetLength(FRawCaches, Length(ConManager.Connection[ConnectionID].GetRawList(FileID)));
    64112
    65113  FCached := False;
     
    107155
    108156
     157function TFile.GetEditor: TFrame;
     158begin
     159  if not Assigned(FEditor) then
     160    InitEditor;
     161  Result := FEditor;
     162end;
     163
     164
    109165procedure TFile.InitDataFields;
    110166begin
     
    122178
    123179
     180//*********************************************************
     181//*********************************************************
     182//*********************************************************
     183procedure TFile.ReCreateFile(fs: TStream);
     184const
     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);
     190var
     191  count: Integer;
     192begin
     193  FDataFields.WriteData(fs);
     194  count := fs.Size mod 32;
     195  if count > 0 then
     196    fs.Write(temp0[count], 32 - count);
     197end;
     198//*********************************************************
     199//*********************************************************
     200//*********************************************************
     201
    124202end.
  • oup/current/FileClasses/_MetaTypes.pas

    r237 r240  
    55uses
    66  _FileTypes, _EmptyFile, _Unlinked, _DataTypes, _Extensions, _TreeElement,
    7   AKVA, TXAN, TXMP;
     7  AKVA, SUBT, TXAN, TXMP;
    88//  ABNA, AGDB, AGQC, AGQG, AGQM, AGQR, AISA, AITR, AIWA, AKAA, AKBA, AKBP, AKDA,
    99//  AKEV, AKOT, AKVA, BINA, CBPI, CBPM, CONS, CRSA, DOOR, DPge, EDIA, ENVP, FILM,
     
    2424  TExtensions = _Extensions.TExtensions;
    2525  TDataField = _DataTypes.TDataField;
     26  TDatLink = _DataTypes.TDatLink;
    2627
    2728  TFileClass = class of TFile;
     
    3233
    3334const
    34   FileDescs: array[0..2] of TFileDesc = (
     35  FileDescs: array[0..3] of TFileDesc = (
    3536    (ext: 'AKVA'; ftype: TFile_AKVA),
     37    (ext: 'SUBT'; ftype: TFile_SUBT),
    3638    (ext: 'TXAN'; ftype: TFile_TXAN),
    3739    (ext: 'TXMP'; ftype: TFile_TXMP)
Note: See TracChangeset for help on using the changeset viewer.