ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/current/Tools/BinEdit.pas
(Generate patch)

Comparing:
oup/rewrite/Tools/BinEdit.pas (file contents), Revision 104 by alloc, Tue Feb 20 22:03:11 2007 UTC vs.
oup/current/Tools/BinEdit.pas (file contents), Revision 179 by alloc, Sun May 13 22:18:18 2007 UTC

# Line 21 | Line 21 | type
21      value_viewer_context_copyasstring: TMenuItem;
22      value_viewer_context_copyashex: TMenuItem;
23      VTHPopup: TVTHeaderPopupMenu;
24 +    panel_imexport: TPanel;
25 +    btn_export: TButton;
26 +    btn_import: TButton;
27      procedure FormCreate(Sender: TObject);
28      procedure NewFile(fileinfo: TFileInfo);
29  
# Line 33 | Line 36 | type
36  
37      procedure LoadDat(_fileid: Integer);
38      function Save: Boolean;
39 <    function GetValue(datatype: Word; offset: LongWord): String;
40 <    procedure SetNewValue(datatype: Word; offset: LongWord; Value: String);
39 >    function GetValue(datatype: Word; offset: Integer): String;
40 >    procedure SetNewValue(datatype: Word; offset: Integer; Value: String);
41  
42      procedure WriteStructureInfos;
43      procedure ClearStructViewer;
# Line 58 | Line 61 | type
61    private
62      fileid: Integer;
63      ConID: Integer;
64 +    rawlist: TRawDataList;
65    public
66    end;
67  
# Line 66 | Line 70 | var
70  
71   implementation
72  
73 < uses ValueEdit, Main, Functions, DatStructureLoader{, RawEdit};
73 > uses ValueEdit, Main, Functions, DatStructureLoader, RawEdit;
74   {$R *.dfm}
75  
76   type
# Line 139 | Line 143 | end;
143   procedure TForm_BinEdit.LoadDat(_fileid: Integer);
144   var
145    mem:  TMemoryStream;
142  Data: TByteData;
146   begin
147    if ConID <> -1 then
148    begin
# Line 161 | Line 164 | begin
164      Self.ClearStructViewer;
165      mem := nil;
166      ConManager.Connection[ConID].LoadDatFile(fileid, TStream(mem));
167 +    rawlist := ConManager.Connection[ConID].GetRawList(fileid);
168      hex.LoadFromStream(mem);
169      mem.Free;
170      ClearValues;
# Line 173 | Line 177 | begin
177      Self.ClearStructViewer;
178      ClearValues;
179      hex.DataSize := 0;
180 +    SetLength(rawlist, 0);
181    end;
182   end;
183  
184  
185  
186 <
182 < function IntToBin(Value: Byte): String;
183 < var
184 <  i: Byte;
185 < begin
186 <  Result := '';
187 <  for i := 7 downto 0 do
188 <    Result := Result + IntToStr((Value shr i) and $01);
189 < end;
190 <
191 <
192 <
193 <
194 < function TForm_BinEdit.GetValue(datatype: Word; offset: LongWord): String;
186 > function TForm_BinEdit.GetValue(datatype: Word; offset: Integer): String;
187   var
188    Data: TByteData;
189 <  i:    Word;
189 >  i:    Integer;
190 >  tempi: Integer;
191    floatformat: TFormatSettings;
192   begin
193    floatformat.DecimalSeparator := '.';
# Line 230 | Line 223 | begin
223      10:
224        Result := IntToBin(hex.Data[offset]);
225      11:
226 <      Result := '0x' + IntToHex(ConManager.Connection[ConID].GetRawInfo(fileid, offset).RawAddr, 8);
226 >    begin
227 >      if Length(rawlist) > 0 then
228 >        for i := 0 to High(rawlist) do
229 >          if rawlist[i].SrcOffset = offset then
230 >          begin
231 >            if rawlist[i].RawAddr > 0 then
232 >              Result := '0x' + IntToHex(rawlist[i].RawAddr, 8)
233 >            else
234 >              Result := 'unused';
235 >            Break;
236 >          end;
237 >    end;
238      12:
239 <      Result := FormatNumber(hex.Data[offset + 1] + hex.Data[offset + 2] * 256 +
240 <        hex.Data[offset + 3] * 256 * 256, 5, '0');
239 >      if hex.Data[offset] = 1 then
240 >        Result := FormatNumber(hex.Data[offset + 1] + hex.Data[offset + 2] * 256 +
241 >          hex.Data[offset + 3] * 256 * 256, 5, '0')
242 >      else
243 >        Result := 'no link';
244      13:
245        Result := IntToStr(hex.Data[offset]);
246      14:
# Line 286 | Line 293 | end;
293  
294   procedure TForm_BinEdit.WriteStructureInfos;
295   var
296 <  i, j:    LongWord;
296 >  i, j:    Integer;
297    pdata:   PNodeData;
298    Data:    TNodeData;
299    node:    PVirtualNode;
# Line 320 | Line 327 | begin
327              begin
328                if Pos('#', SubName) > 0 then
329                begin
330 <                Data.Offset  := HexToLong(MidStr(SubName, Pos('#', SubName) + 1, 8));
331 <                Data.Value   :=
330 >                Data.Offset  := StrToInt('$'+MidStr(SubName, Pos('#', SubName) + 1, 8));
331 >                Data.Value   := '$' +
332                    MidStr(SubName, PosEx('#', SubName, Pos('#', SubName) + 1) + 1, 8);
333                  Data.Caption := MidStr(SubName, 1, Pos('#', SubName) - 1);
334                  Data.Description := SubDesc;
# Line 388 | Line 395 | var
395    i, j:  Integer;
396    Data:  TByteData;
397    str:   String;
398 <  Value: LongWord;
398 >  Value: Integer;
399    floatformat: TFormatSettings;
400   begin
401    floatformat.DecimalSeparator := '.';
# Line 471 | Line 478 | begin
478        str := '';
479        if hex.SelCount = 0 then
480        begin
481 <        while (hex.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do
481 >        while (hex.SelStart + j) < hex.DataSize do
482          begin
483 +          if hex.Data[hex.SelStart + j] = 0 then
484 +            Break;
485            if hex.Data[hex.selstart + j] >= 32 then
486              str := str + Char(hex.Data[hex.SelStart + j])
487            else
# Line 501 | Line 510 | end;
510   function TForm_BinEdit.Save: Boolean;
511   var
512    mem:  TMemoryStream;
513 <  i:    LongWord;
513 >  i:    Integer;
514   begin
515    case MessageBox(Self.Handle, PChar('Save changes to file ' +
516        ConManager.Connection[ConID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
# Line 683 | Line 692 | end;
692   procedure TForm_BinEdit.value_viewer_context_copyClick(Sender: TObject);
693   var
694    Name:  String;
695 <  Value: LongWord;
695 >  Value: Integer;
696   begin
697    Name := TMenuItem(Sender).Name;
698    if Pos('asstring', Name) > 0 then
# Line 746 | Line 755 | procedure TForm_BinEdit.VSTDblClick(Send
755   var
756    node: PVirtualNode;
757    nodedata: PNodeData;
758 +  rawinfo: TRawDataInfo;
759    form: TForm_ToolTemplate;
760   begin
761    if VST.FocusedColumn = 3 then
# Line 761 | Line 771 | begin
771      end
772      else
773      begin
774 <      if nodedata.DataType = 11 then
774 >      if (nodedata.DataType = 11) and (nodedata.Value <> 'unused') then
775        begin
776 <        if ConManager.Connection[ConID].GetRawInfo(fileid, nodedata.offset).RawSize > 0 then
777 <          Form_Main.open_child('rawedit', ConID, fileid);
776 >        rawinfo := ConManager.Connection[ConID].GetRawInfo(fileid, nodedata.offset);
777 >        if rawinfo.RawSize > 0 then
778 >        begin
779 >          form := nil;
780 >          form := Form_Main.open_child('rawedit', ConID, fileid);
781 >          if Assigned(form) then
782 >            TForm_RawEdit(form).LoadRaw(rawinfo);
783 >        end;
784        end;
785 <      if nodedata.DataType = 12 then
785 >      if (nodedata.DataType = 12) and (nodedata.Value <> 'no link') then
786        begin
787          if (StrToInt(nodedata.Value) < ConManager.Connection[ConID].GetFileCount) and
788            (StrToInt(nodedata.Value) > 0) and
# Line 806 | Line 822 | begin
822    else
823    begin
824      hex.SelStart := Data.Offset;
825 <    hex.SelEnd   := Data.Offset + HexToLong(Data.Value) - 1;
825 >    hex.SelEnd   := Data.Offset + StrToInt(Data.Value) - 1;
826    end;
827   end;
828  
# Line 837 | Line 853 | begin
853          if Data.DataType > 0 then
854            CellText := Data.Value //GetValue(data.DataType, data.Offset)
855          else if Length(Data.Value) > 0 then
856 <          CellText := IntToStr(HexToLong(Data.Value)) + ' Bytes';
856 >          CellText := IntToStr(StrToInt(Data.Value)) + ' Bytes';
857        4:
858          CellText := Data.Description;
859      end;
# Line 868 | Line 884 | end;
884  
885  
886  
887 < procedure TForm_BinEdit.SetNewValue(datatype: Word; offset: LongWord; Value: String);
887 > procedure TForm_BinEdit.SetNewValue(datatype: Word; offset: Integer; Value: String);
888   var
889    Data: TByteData;
890    value_int: LongWord;
# Line 935 | Line 951 | end;
951  
952   procedure TForm_BinEdit.value_viewerDblClick(Sender: TObject);
953   var
954 <  offset:     LongWord;
954 >  offset:     Integer;
955    datatype:   Word;
956    objectname: String;
957    Value:      String;

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)