| 1 | unit RawEdit; | 
 
 
 
 
 | 2 | interface | 
 
 
 
 
 | 3 | uses | 
 
 
 
 
 | 4 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, | 
 
 
 
 
 | 5 | Dialogs, Template, StdCtrls, ExtCtrls, Menus, Grids, Wrapgrid, | 
 
 
 
 
 | 6 | MPHexEditor, Clipbrd, StrUtils, TypeDefs, | 
 
 
 
 
 | 7 | Data, Functions, DatStructureLoader, ConnectionManager, Buttons; | 
 
 
 
 
 | 8 |  | 
 
 
 
 
 | 9 | type | 
 
 
 
 
 | 10 | TForm_RawEdit = class(TForm_ToolTemplate) | 
 
 
 
 
 | 11 | Splitter4: TSplitter; | 
 
 
 
 
 | 12 | panel_imexport: TPanel; | 
 
 
 
 
 | 13 | btn_export: TButton; | 
 
 
 
 
 | 14 | btn_import: TButton; | 
 
 
 
 
 | 15 | GroupBox1: TGroupBox; | 
 
 
 
 
 | 16 | list_offset: TListBox; | 
 
 
 
 
 | 17 | hex: TMPHexEditor; | 
 
 
 
 
 | 18 | Splitter2: TSplitter; | 
 
 
 
 
 | 19 | value_viewer: TWrapGrid; | 
 
 
 
 
 | 20 | value_viewer_context: TPopupMenu; | 
 
 
 
 
 | 21 | value_viewer_context_copy: TMenuItem; | 
 
 
 
 
 | 22 | value_viewer_context_copyasdec: TMenuItem; | 
 
 
 
 
 | 23 | value_viewer_context_copyasfloat: TMenuItem; | 
 
 
 
 
 | 24 | value_viewer_context_copyasbitset: TMenuItem; | 
 
 
 
 
 | 25 | value_viewer_context_copyasstring: TMenuItem; | 
 
 
 
 
 | 26 | value_viewer_context_copyashex: TMenuItem; | 
 
 
 
 
 | 27 | opend: TOpenDialog; | 
 
 
 
 
 | 28 | saved: TSaveDialog; | 
 
 
 
 
 | 29 | procedure list_offsetClick(Sender: TObject); | 
 
 
 
 
 | 30 | procedure NewFile(fileinfo: TFileInfo); | 
 
 
 
 
 | 31 | procedure LoadRaw(raw_info: TRawDataInfo); | 
 
 
 
 
 | 32 | function Save: Boolean; | 
 
 
 
 
 | 33 |  | 
 
 
 
 
 | 34 | procedure btn_importClick(Sender: TObject); | 
 
 
 
 
 | 35 | procedure btn_exportClick(Sender: TObject); | 
 
 
 
 
 | 36 |  | 
 
 
 
 
 | 37 | procedure FormCreate(Sender: TObject); | 
 
 
 
 
 | 38 | procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); | 
 
 
 
 
 | 39 | procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); | 
 
 
 
 
 | 40 |  | 
 
 
 
 
 | 41 | function GetValue(datatype: Word; offset: Integer): String; | 
 
 
 
 
 | 42 | procedure ClearValues; | 
 
 
 
 
 | 43 | procedure WriteValues; | 
 
 
 
 
 | 44 | procedure SetNewValue(datatype: Word; offset: Integer; Value: String); | 
 
 
 
 
 | 45 |  | 
 
 
 
 
 | 46 | procedure value_viewerDblClick(Sender: TObject); | 
 
 
 
 
 | 47 | procedure value_viewer_context_copyClick(Sender: TObject); | 
 
 
 
 
 | 48 | procedure value_viewerMouseDown(Sender: TObject; Button: TMouseButton; | 
 
 
 
 
 | 49 | Shift: TShiftState; X, Y: Integer); | 
 
 
 
 
 | 50 | procedure value_viewer_contextPopup(Sender: TObject); | 
 
 
 
 
 | 51 |  | 
 
 
 
 
 | 52 | procedure hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); | 
 
 
 
 
 | 53 | procedure hexSelectionChanged(Sender: TObject); | 
 
 
 
 
 | 54 | procedure hexChange(Sender: TObject); | 
 
 
 
 
 | 55 | private | 
 
 
 
 
 | 56 | fileid, datoffset: Integer; | 
 
 
 
 
 | 57 | public | 
 
 
 
 
 | 58 | end; | 
 
 
 
 
 | 59 |  | 
 
 
 
 
 | 60 | var | 
 
 
 
 
 | 61 | Form_RawEdit: TForm_RawEdit; | 
 
 
 
 
 | 62 |  | 
 
 
 
 
 | 63 | implementation | 
 
 
 
 
 | 64 | {$R *.dfm} | 
 
 
 
 
 | 65 | uses Main, ValueEdit, RawList; | 
 
 
 
 
 | 66 |  | 
 
 
 
 
 | 67 | procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo); | 
 
 
 
 
 | 68 | var | 
 
 
 
 
 | 69 | offsets: TRawDataList; | 
 
 
 
 
 | 70 | i: Integer; | 
 
 
 
 
 | 71 | begin | 
 
 
 
 
 | 72 | if fileinfo.ID >= 0 then | 
 
 
 
 
 | 73 | begin | 
 
 
 
 
 | 74 | if hex.Modified then | 
 
 
 
 
 | 75 | if not Save then | 
 
 
 
 
 | 76 | Exit; | 
 
 
 
 
 | 77 | ClearValues; | 
 
 
 
 
 | 78 | hex.DataSize := 0; | 
 
 
 
 
 | 79 | fileid := fileinfo.ID; | 
 
 
 
 
 | 80 | list_offset.Enabled := False; | 
 
 
 
 
 | 81 | if fileinfo.size > 0 then | 
 
 
 
 
 | 82 | begin | 
 
 
 
 
 | 83 | offsets := ConManager.Connection[ConnectionID].GetRawList(fileid); | 
 
 
 
 
 | 84 | list_offset.Items.Clear; | 
 
 
 
 
 | 85 | if Length(offsets) > 0 then | 
 
 
 
 
 | 86 | for i := 0 to High(offsets) do | 
 
 
 
 
 | 87 | list_offset.Items.Add('0x' + IntToHex(offsets[i].SrcOffset, 8) + | 
 
 
 
 
 | 88 | ', ' + IntToStr(offsets[i].RawSize) + ' Bytes'); | 
 
 
 
 
 | 89 | list_offset.Enabled := True; | 
 
 
 
 
 | 90 | end; | 
 
 
 
 
 | 91 | end | 
 
 
 
 
 | 92 | else | 
 
 
 
 
 | 93 | begin | 
 
 
 
 
 | 94 | ClearValues; | 
 
 
 
 
 | 95 | hex.DataSize := 0; | 
 
 
 
 
 | 96 | fileid := -1; | 
 
 
 
 
 | 97 | list_offset.Items.Clear; | 
 
 
 
 
 | 98 | end; | 
 
 
 
 
 | 99 | end; | 
 
 
 
 
 | 100 |  | 
 
 
 
 
 | 101 | procedure TForm_RawEdit.LoadRaw(raw_info: TRawDataInfo); | 
 
 
 
 
 | 102 | var | 
 
 
 
 
 | 103 | i:    Integer; | 
 
 
 
 
 | 104 | mem: TMemoryStream; | 
 
 
 
 
 | 105 | begin | 
 
 
 
 
 | 106 | if hex.Modified then | 
 
 
 
 
 | 107 | begin | 
 
 
 
 
 | 108 | if not Save then | 
 
 
 
 
 | 109 | begin | 
 
 
 
 
 | 110 | Exit; | 
 
 
 
 
 | 111 | end; | 
 
 
 
 
 | 112 | end; | 
 
 
 
 
 | 113 | if list_offset.Count = 0 then | 
 
 
 
 
 | 114 | begin | 
 
 
 
 
 | 115 | for i := 0 to filelist.Count - 1 do | 
 
 
 
 
 | 116 | begin | 
 
 
 
 
 | 117 | if ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then | 
 
 
 
 
 | 118 | begin | 
 
 
 
 
 | 119 | filelist.ItemIndex := i; | 
 
 
 
 
 | 120 | listClick(Self); | 
 
 
 
 
 | 121 | Break; | 
 
 
 
 
 | 122 | end; | 
 
 
 
 
 | 123 | end; | 
 
 
 
 
 | 124 | for i := 0 to list_offset.Count - 1 do | 
 
 
 
 
 | 125 | begin | 
 
 
 
 
 | 126 | if MidStr(list_offset.Items.Strings[i], 3, 8) = IntToHex(raw_info.SrcOffset, 8) then | 
 
 
 
 
 | 127 | begin | 
 
 
 
 
 | 128 | list_offset.ItemIndex := i; | 
 
 
 
 
 | 129 | Break; | 
 
 
 
 
 | 130 | end; | 
 
 
 
 
 | 131 | end; | 
 
 
 
 
 | 132 | end; | 
 
 
 
 
 | 133 | mem := nil; | 
 
 
 
 
 | 134 | ConManager.Connection[ConnectionID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem)); | 
 
 
 
 
 | 135 | hex.LoadFromStream(mem); | 
 
 
 
 
 | 136 | ClearValues; | 
 
 
 
 
 | 137 | hexSelectionChanged(Self); | 
 
 
 
 
 | 138 | end; | 
 
 
 
 
 | 139 |  | 
 
 
 
 
 | 140 |  | 
 
 
 
 
 | 141 |  | 
 
 
 
 
 | 142 |  | 
 
 
 
 
 | 143 |  | 
 
 
 
 
 | 144 |  | 
 
 
 
 
 | 145 | procedure TForm_RawEdit.list_offsetClick(Sender: TObject); | 
 
 
 
 
 | 146 | begin | 
 
 
 
 
 | 147 | ClearValues; | 
 
 
 
 
 | 148 | datoffset := StrToInt('$' + MidStr( | 
 
 
 
 
 | 149 | list_offset.Items.Strings[list_offset.ItemIndex], 3, 8)); | 
 
 
 
 
 | 150 | LoadRaw(ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset)); | 
 
 
 
 
 | 151 | end; | 
 
 
 
 
 | 152 |  | 
 
 
 
 
 | 153 |  | 
 
 
 
 
 | 154 |  | 
 
 
 
 
 | 155 |  | 
 
 
 
 
 | 156 | function TForm_RawEdit.GetValue(datatype: Word; offset: Integer): String; | 
 
 
 
 
 | 157 | var | 
 
 
 
 
 | 158 | Data: TByteData; | 
 
 
 
 
 | 159 | i:    Word; | 
 
 
 
 
 | 160 | floatformat: TFormatSettings; | 
 
 
 
 
 | 161 | begin | 
 
 
 
 
 | 162 | floatformat.DecimalSeparator := '.'; | 
 
 
 
 
 | 163 | case datatype of | 
 
 
 
 
 | 164 | 1: | 
 
 
 
 
 | 165 | Result := IntToStr(hex.Data[offset]); | 
 
 
 
 
 | 166 | 2: | 
 
 
 
 
 | 167 | Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256); | 
 
 
 
 
 | 168 | 3: | 
 
 
 
 
 | 169 | Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] * 256 * 256); | 
 
 
 
 
 | 170 | 4: | 
 
 
 
 
 | 171 | Result := IntToStr(hex.Data[offset] + hex.Data[offset + 1] * 256 + hex.Data[offset + 2] * | 
 
 
 
 
 | 172 | 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256); | 
 
 
 
 
 | 173 | 5: | 
 
 
 
 
 | 174 | Result := '0x' + IntToHex(hex.Data[offset], 2); | 
 
 
 
 
 | 175 | 6: | 
 
 
 
 
 | 176 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256, 4); | 
 
 
 
 
 | 177 | 7: | 
 
 
 
 
 | 178 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 + | 
 
 
 
 
 | 179 | hex.Data[offset + 2] * 256 * 256, 6); | 
 
 
 
 
 | 180 | 8: | 
 
 
 
 
 | 181 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 + | 
 
 
 
 
 | 182 | hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8); | 
 
 
 
 
 | 183 | 9: | 
 
 
 
 
 | 184 | begin | 
 
 
 
 
 | 185 | SetLength(Data, 4); | 
 
 
 
 
 | 186 | Data[0] := hex.Data[offset]; | 
 
 
 
 
 | 187 | Data[1] := hex.Data[offset + 1]; | 
 
 
 
 
 | 188 | Data[2] := hex.Data[offset + 2]; | 
 
 
 
 
 | 189 | Data[3] := hex.Data[offset + 3]; | 
 
 
 
 
 | 190 | Result  := FloatToStr(Decode_Float(Data), floatformat); | 
 
 
 
 
 | 191 | end; | 
 
 
 
 
 | 192 | 10: | 
 
 
 
 
 | 193 | Result := IntToBin(hex.Data[offset]); | 
 
 
 
 
 | 194 | 11: | 
 
 
 
 
 | 195 | Result := '0x' + IntToHex(hex.Data[offset] + hex.Data[offset + 1] * 256 + | 
 
 
 
 
 | 196 | hex.Data[offset + 2] * 256 * 256 + hex.Data[offset + 3] * 256 * 256 * 256, 8); | 
 
 
 
 
 | 197 | 10000..65535: | 
 
 
 
 
 | 198 | begin | 
 
 
 
 
 | 199 | Result := ''; | 
 
 
 
 
 | 200 | for i := 1 to datatype - 10000 do | 
 
 
 
 
 | 201 | begin | 
 
 
 
 
 | 202 | if hex.Data[offset + i - 1] >= 32 then | 
 
 
 
 
 | 203 | Result := Result + Chr(hex.Data[offset + i - 1]) | 
 
 
 
 
 | 204 | else | 
 
 
 
 
 | 205 | Result := Result + '.'; | 
 
 
 
 
 | 206 | end; | 
 
 
 
 
 | 207 | end; | 
 
 
 
 
 | 208 | end; | 
 
 
 
 
 | 209 | end; | 
 
 
 
 
 | 210 |  | 
 
 
 
 
 | 211 |  | 
 
 
 
 
 | 212 |  | 
 
 
 
 
 | 213 |  | 
 
 
 
 
 | 214 | procedure TForm_RawEdit.ClearValues; | 
 
 
 
 
 | 215 | var | 
 
 
 
 
 | 216 | i: Byte; | 
 
 
 
 
 | 217 | begin | 
 
 
 
 
 | 218 | for i := 1 to value_viewer.RowCount - 1 do | 
 
 
 
 
 | 219 | value_viewer.Cells[1, i] := ''; | 
 
 
 
 
 | 220 | end; | 
 
 
 
 
 | 221 |  | 
 
 
 
 
 | 222 |  | 
 
 
 
 
 | 223 |  | 
 
 
 
 
 | 224 |  | 
 
 
 
 
 | 225 | procedure TForm_RawEdit.WriteValues; | 
 
 
 
 
 | 226 | var | 
 
 
 
 
 | 227 | i, j:  Integer; | 
 
 
 
 
 | 228 | Data:  TByteData; | 
 
 
 
 
 | 229 | str:   String; | 
 
 
 
 
 | 230 | Value: Integer; | 
 
 
 
 
 | 231 | floatformat: TFormatSettings; | 
 
 
 
 
 | 232 | begin | 
 
 
 
 
 | 233 | floatformat.DecimalSeparator := '.'; | 
 
 
 
 
 | 234 | for i := 1 to value_viewer.RowCount - 1 do | 
 
 
 
 
 | 235 | begin | 
 
 
 
 
 | 236 | if value_viewer.Cells[0, i] = '1 byte, unsigned' then | 
 
 
 
 
 | 237 | begin | 
 
 
 
 
 | 238 | if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 239 | ((hex.SelStart + 1) > hex.DataSize) then | 
 
 
 
 
 | 240 | begin | 
 
 
 
 
 | 241 | Value := hex.Data[hex.SelStart]; | 
 
 
 
 
 | 242 | value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 2); | 
 
 
 
 
 | 243 | end | 
 
 
 
 
 | 244 | else | 
 
 
 
 
 | 245 | value_viewer.Cells[1, i] := ''; | 
 
 
 
 
 | 246 | end; | 
 
 
 
 
 | 247 | if value_viewer.Cells[0, i] = '2 bytes, unsigned' then | 
 
 
 
 
 | 248 | begin | 
 
 
 
 
 | 249 | if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 250 | ((hex.SelStart + 2) > hex.DataSize) then | 
 
 
 
 
 | 251 | begin | 
 
 
 
 
 | 252 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256; | 
 
 
 
 
 | 253 | value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 4); | 
 
 
 
 
 | 254 | end | 
 
 
 
 
 | 255 | else | 
 
 
 
 
 | 256 | value_viewer.Cells[1, i] := ''; | 
 
 
 
 
 | 257 | end; | 
 
 
 
 
 | 258 | if value_viewer.Cells[0, i] = '4 bytes, unsigned' then | 
 
 
 
 
 | 259 | begin | 
 
 
 
 
 | 260 | if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 261 | ((hex.SelStart + 4) > hex.DataSize) then | 
 
 
 
 
 | 262 | begin | 
 
 
 
 
 | 263 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 + | 
 
 
 
 
 | 264 | hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256; | 
 
 
 
 
 | 265 | value_viewer.Cells[1, i] := IntToStr(Value) + ' / 0x' + IntToHex(Value, 8); | 
 
 
 
 
 | 266 | end | 
 
 
 
 
 | 267 | else | 
 
 
 
 
 | 268 | value_viewer.Cells[1, i] := ''; | 
 
 
 
 
 | 269 | end; | 
 
 
 
 
 | 270 | if value_viewer.Cells[0, i] = 'Bitset' then | 
 
 
 
 
 | 271 | begin | 
 
 
 
 
 | 272 | if (hex.SelCount <= 8) then | 
 
 
 
 
 | 273 | begin | 
 
 
 
 
 | 274 | if hex.SelCount = 0 then | 
 
 
 
 
 | 275 | begin | 
 
 
 
 
 | 276 | SetLength(Data, 1); | 
 
 
 
 
 | 277 | Data[0] := hex.Data[hex.SelStart]; | 
 
 
 
 
 | 278 | end | 
 
 
 
 
 | 279 | else | 
 
 
 
 
 | 280 | begin | 
 
 
 
 
 | 281 | SetLength(Data, hex.SelCount); | 
 
 
 
 
 | 282 | for j := 0 to hex.SelCount - 1 do | 
 
 
 
 
 | 283 | Data[j] := hex.Data[hex.SelStart + j]; | 
 
 
 
 
 | 284 | end; | 
 
 
 
 
 | 285 | value_viewer.Cells[1, i] := DataToBin(Data); | 
 
 
 
 
 | 286 | end | 
 
 
 
 
 | 287 | else | 
 
 
 
 
 | 288 | value_viewer.Cells[1, i] := ''; | 
 
 
 
 
 | 289 | end; | 
 
 
 
 
 | 290 | if value_viewer.Cells[0, i] = 'Float' then | 
 
 
 
 
 | 291 | begin | 
 
 
 
 
 | 292 | if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 293 | ((hex.SelStart + 4) > hex.DataSize) then | 
 
 
 
 
 | 294 | begin | 
 
 
 
 
 | 295 | SetLength(Data, 4); | 
 
 
 
 
 | 296 | for j := 0 to 3 do | 
 
 
 
 
 | 297 | Data[j] := hex.Data[hex.SelStart + j]; | 
 
 
 
 
 | 298 | value_viewer.Cells[1, i] := FloatToStr(Decode_Float(Data), floatformat); | 
 
 
 
 
 | 299 | end | 
 
 
 
 
 | 300 | else | 
 
 
 
 
 | 301 | value_viewer.Cells[1, i] := ''; | 
 
 
 
 
 | 302 | end; | 
 
 
 
 
 | 303 | if value_viewer.Cells[0, i] = 'Selected length' then | 
 
 
 
 
 | 304 | begin | 
 
 
 
 
 | 305 | value_viewer.Cells[1, i] := IntToStr(hex.SelCount) + ' bytes'; | 
 
 
 
 
 | 306 | end; | 
 
 
 
 
 | 307 | if value_viewer.Cells[0, i] = 'String' then | 
 
 
 
 
 | 308 | begin | 
 
 
 
 
 | 309 | j   := 0; | 
 
 
 
 
 | 310 | str := ''; | 
 
 
 
 
 | 311 | if hex.SelCount = 0 then | 
 
 
 
 
 | 312 | begin | 
 
 
 
 
 | 313 | while (hex.SelStart + j) < hex.DataSize do | 
 
 
 
 
 | 314 | begin | 
 
 
 
 
 | 315 | if hex.Data[hex.SelStart + j] = 0 then | 
 
 
 
 
 | 316 | Break; | 
 
 
 
 
 | 317 | if hex.Data[hex.selstart + j] >= 32 then | 
 
 
 
 
 | 318 | str := str + Char(hex.Data[hex.SelStart + j]) | 
 
 
 
 
 | 319 | else | 
 
 
 
 
 | 320 | str := str + '.'; | 
 
 
 
 
 | 321 | Inc(j); | 
 
 
 
 
 | 322 | end; | 
 
 
 
 
 | 323 | end | 
 
 
 
 
 | 324 | else | 
 
 
 
 
 | 325 | begin | 
 
 
 
 
 | 326 | for j := 0 to hex.SelCount - 1 do | 
 
 
 
 
 | 327 | if hex.Data[hex.selstart + j] >= 32 then | 
 
 
 
 
 | 328 | str := str + Char(hex.Data[hex.SelStart + j]) | 
 
 
 
 
 | 329 | else if hex.Data[hex.selstart + j] > 0 then | 
 
 
 
 
 | 330 | str := str + '.' | 
 
 
 
 
 | 331 | else | 
 
 
 
 
 | 332 | Break; | 
 
 
 
 
 | 333 | end; | 
 
 
 
 
 | 334 | value_viewer.Cells[1, i] := str; | 
 
 
 
 
 | 335 | end; | 
 
 
 
 
 | 336 | end; | 
 
 
 
 
 | 337 | end; | 
 
 
 
 
 | 338 |  | 
 
 
 
 
 | 339 |  | 
 
 
 
 
 | 340 |  | 
 
 
 
 
 | 341 |  | 
 
 
 
 
 | 342 | procedure TForm_RawEdit.FormCreate(Sender: TObject); | 
 
 
 
 
 | 343 | var | 
 
 
 
 
 | 344 | i:     Integer; | 
 
 
 
 
 | 345 | exts: String; | 
 
 
 
 
 | 346 | begin | 
 
 
 
 
 | 347 | inherited; | 
 
 
 
 
 | 348 | Self.OnNewFileSelected := Self.NewFile; | 
 
 
 
 
 | 349 |  | 
 
 
 
 
 | 350 | exts := ''; | 
 
 
 
 
 | 351 | if Length(RawLists.RawListHandlers) > 0 then | 
 
 
 
 
 | 352 | begin | 
 
 
 
 
 | 353 | for i := 0 to High(RawLists.RawListHandlers) do | 
 
 
 
 
 | 354 | if Length(exts) > 0 then | 
 
 
 
 
 | 355 | exts := exts + ',' + RawLists.RawListHandlers[i].Ext | 
 
 
 
 
 | 356 | else | 
 
 
 
 
 | 357 | exts := RawLists.RawListHandlers[i].Ext; | 
 
 
 
 
 | 358 | end; | 
 
 
 
 
 | 359 | Self.AllowedExts := exts; | 
 
 
 
 
 | 360 |  | 
 
 
 
 
 | 361 | Self.Caption := ''; | 
 
 
 
 
 | 362 | fileid     := -1; | 
 
 
 
 
 | 363 |  | 
 
 
 
 
 | 364 | { | 
 
 
 
 
 | 365 | value_viewer.ColCount := 2; | 
 
 
 
 
 | 366 | value_viewer.RowCount := 8; | 
 
 
 
 
 | 367 | } | 
 
 
 
 
 | 368 | value_viewer.FixedRows := 1; | 
 
 
 
 
 | 369 | value_viewer.FixedCols := 1; | 
 
 
 
 
 | 370 | value_viewer.Cells[0, 0] := 'Type'; | 
 
 
 
 
 | 371 | value_viewer.Cells[1, 0] := 'Value'; | 
 
 
 
 
 | 372 | value_viewer.Cells[0, 1] := '1 byte, unsigned'; | 
 
 
 
 
 | 373 | value_viewer.Cells[0, 2] := '2 bytes, unsigned'; | 
 
 
 
 
 | 374 | value_viewer.Cells[0, 3] := '4 bytes, unsigned'; | 
 
 
 
 
 | 375 | value_viewer.Cells[0, 4] := 'Bitset'; | 
 
 
 
 
 | 376 | value_viewer.Cells[0, 5] := 'Float'; | 
 
 
 
 
 | 377 | value_viewer.Cells[0, 6] := 'String'; | 
 
 
 
 
 | 378 | value_viewer.Cells[0, 7] := 'Selected length'; | 
 
 
 
 
 | 379 | value_viewer.ColWidths[0] := 125; | 
 
 
 
 
 | 380 | value_viewer.ColWidths[1] := 1000; | 
 
 
 
 
 | 381 | // | 
 
 
 
 
 | 382 | value_viewer.Font.Charset := AppSettings.CharSet; | 
 
 
 
 
 | 383 | // | 
 
 
 
 
 | 384 | end; | 
 
 
 
 
 | 385 |  | 
 
 
 
 
 | 386 |  | 
 
 
 
 
 | 387 |  | 
 
 
 
 
 | 388 |  | 
 
 
 
 
 | 389 | function TForm_RawEdit.Save: Boolean; | 
 
 
 
 
 | 390 | var | 
 
 
 
 
 | 391 | mem:  TMemoryStream; | 
 
 
 
 
 | 392 | i:    Integer; | 
 
 
 
 
 | 393 | begin | 
 
 
 
 
 | 394 | case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' + | 
 
 
 
 
 | 395 | ConManager.Connection[ConnectionID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'), | 
 
 
 
 
 | 396 | MB_YESNOCANCEL) of | 
 
 
 
 
 | 397 | idYes: | 
 
 
 
 
 | 398 | begin | 
 
 
 
 
 | 399 | mem := TMemoryStream.Create; | 
 
 
 
 
 | 400 | hex.SaveToStream(mem); | 
 
 
 
 
 | 401 | mem.Seek(0, soFromBeginning); | 
 
 
 
 
 | 402 | ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, mem); | 
 
 
 
 
 | 403 | mem.Free; | 
 
 
 
 
 | 404 | hex.Modified := False; | 
 
 
 
 
 | 405 | for i := 0 to hex.Datasize - 1 do | 
 
 
 
 
 | 406 | hex.ByteChanged[i] := False; | 
 
 
 
 
 | 407 | Result := True; | 
 
 
 
 
 | 408 | end; | 
 
 
 
 
 | 409 | idNo: | 
 
 
 
 
 | 410 | Result := True; | 
 
 
 
 
 | 411 | idCancel: | 
 
 
 
 
 | 412 | Result := False; | 
 
 
 
 
 | 413 | end; | 
 
 
 
 
 | 414 | end; | 
 
 
 
 
 | 415 |  | 
 
 
 
 
 | 416 |  | 
 
 
 
 
 | 417 |  | 
 
 
 
 
 | 418 |  | 
 
 
 
 
 | 419 | procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean); | 
 
 
 
 
 | 420 | begin | 
 
 
 
 
 | 421 | if hex.Modified then | 
 
 
 
 
 | 422 | if not Save then | 
 
 
 
 
 | 423 | CanClose := False; | 
 
 
 
 
 | 424 | end; | 
 
 
 
 
 | 425 |  | 
 
 
 
 
 | 426 |  | 
 
 
 
 
 | 427 |  | 
 
 
 
 
 | 428 |  | 
 
 
 
 
 | 429 | procedure TForm_RawEdit.hexChange(Sender: TObject); | 
 
 
 
 
 | 430 | begin | 
 
 
 
 
 | 431 | ClearValues; | 
 
 
 
 
 | 432 | if hex.DataSize > 0 then | 
 
 
 
 
 | 433 | begin | 
 
 
 
 
 | 434 | {      WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension)); | 
 
 
 
 
 | 435 | WriteValues; | 
 
 
 
 
 | 436 | }    end; | 
 
 
 
 
 | 437 | end; | 
 
 
 
 
 | 438 |  | 
 
 
 
 
 | 439 |  | 
 
 
 
 
 | 440 |  | 
 
 
 
 
 | 441 |  | 
 
 
 
 
 | 442 | procedure TForm_RawEdit.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); | 
 
 
 
 
 | 443 | //var | 
 
 
 
 
 | 444 | //  temps: String; | 
 
 
 
 
 | 445 | begin | 
 
 
 
 
 | 446 | if (Shift = [ssCtrl]) and (Key = Ord('C')) then | 
 
 
 
 
 | 447 | begin | 
 
 
 
 
 | 448 | if hex.SelCount > 0 then | 
 
 
 
 
 | 449 | begin | 
 
 
 
 
 | 450 | if hex.InCharField then | 
 
 
 
 
 | 451 | Clipboard.AsText := hex.SelectionAsText | 
 
 
 
 
 | 452 | else | 
 
 
 
 
 | 453 | Clipboard.AsText := hex.SelectionAsHex; | 
 
 
 
 
 | 454 | end; | 
 
 
 
 
 | 455 | end; | 
 
 
 
 
 | 456 | if (Shift = [ssCtrl]) and (Key = Ord('V')) then | 
 
 
 
 
 | 457 | begin | 
 
 
 
 
 | 458 | {      temps:=Clipboard.AsText; | 
 
 
 
 
 | 459 | IF hex.SelStart+Length(temps)>hex.DataSize THEN | 
 
 
 
 
 | 460 | SetLength(temps, hex.DataSize-hex.SelStart); | 
 
 
 
 
 | 461 | hex.Sel | 
 
 
 
 
 | 462 | hex.SelCount:=Length(temps); | 
 
 
 
 
 | 463 | hex.ReplaceSelection(temps,Length(temps)); | 
 
 
 
 
 | 464 | }    end; | 
 
 
 
 
 | 465 | end; | 
 
 
 
 
 | 466 |  | 
 
 
 
 
 | 467 |  | 
 
 
 
 
 | 468 |  | 
 
 
 
 
 | 469 |  | 
 
 
 
 
 | 470 | procedure TForm_RawEdit.hexSelectionChanged(Sender: TObject); | 
 
 
 
 
 | 471 | //var | 
 
 
 
 
 | 472 | //  selstart: Integer; | 
 
 
 
 
 | 473 | //  i, j:     Word; | 
 
 
 
 
 | 474 | begin | 
 
 
 
 
 | 475 | {    FOR i:=1 TO structs.RowCount-1 DO BEGIN | 
 
 
 
 
 | 476 | FOR j:=0 TO structs.ColCount-1 DO BEGIN | 
 
 
 
 
 | 477 | structs.CellColors[j,i]:=clWhite; | 
 
 
 
 
 | 478 | structs.CellFontColors[j,i]:=clBlack; | 
 
 
 
 
 | 479 | END; | 
 
 
 
 
 | 480 | END; | 
 
 
 
 
 | 481 | }    if hex.DataSize > 0 then | 
 
 
 
 
 | 482 | begin | 
 
 
 
 
 | 483 | {      selstart:=hex.SelStart; | 
 
 
 
 
 | 484 | IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN | 
 
 
 
 
 | 485 | WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN | 
 
 
 
 
 | 486 | FOR i:=0 TO High(entries) DO BEGIN | 
 
 
 
 
 | 487 | IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN | 
 
 
 
 
 | 488 | FOR j:=0 TO structs.ColCount-1 DO BEGIN | 
 
 
 
 
 | 489 | structs.CellColors[j,i+1]:=clBlue; | 
 
 
 
 
 | 490 | structs.CellFontColors[j,i+1]:=clWhite; | 
 
 
 
 
 | 491 | END; | 
 
 
 
 
 | 492 | structs.Row:=i+1; | 
 
 
 
 
 | 493 | END; | 
 
 
 
 
 | 494 | END; | 
 
 
 
 
 | 495 | END; | 
 
 
 
 
 | 496 | END; | 
 
 
 
 
 | 497 | }      WriteValues; | 
 
 
 
 
 | 498 | end; | 
 
 
 
 
 | 499 | end; | 
 
 
 
 
 | 500 |  | 
 
 
 
 
 | 501 |  | 
 
 
 
 
 | 502 |  | 
 
 
 
 
 | 503 |  | 
 
 
 
 
 | 504 |  | 
 
 
 
 
 | 505 | procedure TForm_RawEdit.btn_exportClick(Sender: TObject); | 
 
 
 
 
 | 506 | var | 
 
 
 
 
 | 507 | fs: TFileStream; | 
 
 
 
 
 | 508 | begin | 
 
 
 
 
 | 509 | saved.Filter     := 'Files of matching extension (*.' + | 
 
 
 
 
 | 510 | ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' + | 
 
 
 
 
 | 511 | ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + | 
 
 
 
 
 | 512 | '|All files|*.*'; | 
 
 
 
 
 | 513 | saved.DefaultExt := ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension; | 
 
 
 
 
 | 514 | if saved.Execute then | 
 
 
 
 
 | 515 | begin | 
 
 
 
 
 | 516 | fs := TFileStream.Create(saved.FileName, fmCreate); | 
 
 
 
 
 | 517 | hex.SaveToStream(fs); | 
 
 
 
 
 | 518 | fs.Free; | 
 
 
 
 
 | 519 | end; | 
 
 
 
 
 | 520 | end; | 
 
 
 
 
 | 521 |  | 
 
 
 
 
 | 522 |  | 
 
 
 
 
 | 523 |  | 
 
 
 
 
 | 524 |  | 
 
 
 
 
 | 525 | procedure TForm_RawEdit.btn_importClick(Sender: TObject); | 
 
 
 
 
 | 526 | var | 
 
 
 
 
 | 527 | //  Data: Tdata; | 
 
 
 
 
 | 528 | fs:   TFileStream; | 
 
 
 
 
 | 529 | i: Integer; | 
 
 
 
 
 | 530 | rawinfo: TRawDataInfo; | 
 
 
 
 
 | 531 | begin | 
 
 
 
 
 | 532 | opend.Filter := 'Files of matching extension (*.' + | 
 
 
 
 
 | 533 | ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' + | 
 
 
 
 
 | 534 | ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + | 
 
 
 
 
 | 535 | '|All files|*.*'; | 
 
 
 
 
 | 536 | if opend.Execute then | 
 
 
 
 
 | 537 | begin | 
 
 
 
 
 | 538 | fs := TFileStream.Create(opend.FileName, fmOpenRead); | 
 
 
 
 
 | 539 | if fs.Size <> hex.DataSize then | 
 
 
 
 
 | 540 | begin | 
 
 
 
 
 | 541 | if (not (CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then | 
 
 
 
 
 | 542 | begin | 
 
 
 
 
 | 543 | ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) + | 
 
 
 
 
 | 544 | ', file has to have same size as file in .raw with this backend.' + CrLf + | 
 
 
 
 
 | 545 | 'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf + | 
 
 
 
 
 | 546 | 'Size of chosen file: ' + FormatFileSize(fs.Size)); | 
 
 
 
 
 | 547 | Exit; | 
 
 
 
 
 | 548 | end else begin | 
 
 
 
 
 | 549 | if MessageBox(Self.Handle, | 
 
 
 
 
 | 550 | PChar('File has different size from the file in the .raw.' + CrLf + | 
 
 
 
 
 | 551 | 'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf + | 
 
 
 
 
 | 552 | 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf + | 
 
 
 
 
 | 553 | 'Replace anyway?' + CrLf + | 
 
 
 
 
 | 554 | 'WARNING: This only replaces the raw-data. It doesn''t' + CrLf + | 
 
 
 
 
 | 555 | 'do the according changes in the .dat. Oni probably' + CrLf + | 
 
 
 
 
 | 556 | 'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then | 
 
 
 
 
 | 557 | begin | 
 
 
 
 
 | 558 | Exit; | 
 
 
 
 
 | 559 | end; | 
 
 
 
 
 | 560 | end; | 
 
 
 
 
 | 561 | rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset); | 
 
 
 
 
 | 562 | if CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights then | 
 
 
 
 
 | 563 | ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs) | 
 
 
 
 
 | 564 | else if CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights then | 
 
 
 
 
 | 565 | i := ConManager.Connection[ConnectionID].AppendRawFile(rawinfo.LocSep, fs); | 
 
 
 
 
 | 566 | ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, datoffset, 4, @i); | 
 
 
 
 
 | 567 | end else begin | 
 
 
 
 
 | 568 | ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs); | 
 
 
 
 
 | 569 | end; | 
 
 
 
 
 | 570 | fs.Seek(0, soFromBeginning); | 
 
 
 
 
 | 571 | hex.LoadFromStream(fs); | 
 
 
 
 
 | 572 | hex.Modified := False; | 
 
 
 
 
 | 573 | for i := 0 to hex.Datasize - 1 do | 
 
 
 
 
 | 574 | hex.ByteChanged[i] := False; | 
 
 
 
 
 | 575 | fs.Free; | 
 
 
 
 
 | 576 | end; | 
 
 
 
 
 | 577 | end; | 
 
 
 
 
 | 578 |  | 
 
 
 
 
 | 579 |  | 
 
 
 
 
 | 580 |  | 
 
 
 
 
 | 581 |  | 
 
 
 
 
 | 582 | procedure TForm_RawEdit.value_viewer_contextPopup(Sender: TObject); | 
 
 
 
 
 | 583 | var | 
 
 
 
 
 | 584 | i: Byte; | 
 
 
 
 
 | 585 | begin | 
 
 
 
 
 | 586 | for i := 0 to value_viewer_context.Items.Count - 1 do | 
 
 
 
 
 | 587 | value_viewer_context.Items.Items[i].Visible := False; | 
 
 
 
 
 | 588 | with value_viewer do | 
 
 
 
 
 | 589 | begin | 
 
 
 
 
 | 590 | if (Col = 1) and (Row > 0) and (Length(Cells[Col, Row]) > 0) then | 
 
 
 
 
 | 591 | begin | 
 
 
 
 
 | 592 | if Pos(' byte', Cells[0, Row]) = 2 then | 
 
 
 
 
 | 593 | begin | 
 
 
 
 
 | 594 | value_viewer_context.Items.Find('Copy to &clipboard').Visible := True; | 
 
 
 
 
 | 595 | value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible := True; | 
 
 
 
 
 | 596 | value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible := True; | 
 
 
 
 
 | 597 | end; | 
 
 
 
 
 | 598 | if Pos('Float', Cells[0, Row]) = 1 then | 
 
 
 
 
 | 599 | value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible := True; | 
 
 
 
 
 | 600 | if Pos('Bitset', Cells[0, Row]) = 1 then | 
 
 
 
 
 | 601 | value_viewer_context.Items.Find( | 
 
 
 
 
 | 602 | 'Copy to clipboard (as &bitset)').Visible := True; | 
 
 
 
 
 | 603 | if Pos('String', Cells[0, Row]) = 1 then | 
 
 
 
 
 | 604 | value_viewer_context.Items.Find( | 
 
 
 
 
 | 605 | 'Copy to clipboard (as &string)').Visible := True; | 
 
 
 
 
 | 606 | if Pos('Selected length', Cells[0, Row]) = 1 then | 
 
 
 
 
 | 607 | value_viewer_context.Items.Find('Copy to &clipboard').Visible := True; | 
 
 
 
 
 | 608 | end; | 
 
 
 
 
 | 609 | end; | 
 
 
 
 
 | 610 | end; | 
 
 
 
 
 | 611 |  | 
 
 
 
 
 | 612 |  | 
 
 
 
 
 | 613 |  | 
 
 
 
 
 | 614 |  | 
 
 
 
 
 | 615 | procedure TForm_RawEdit.value_viewerMouseDown(Sender: TObject; Button: TMouseButton; | 
 
 
 
 
 | 616 | Shift: TShiftState; X, Y: Integer); | 
 
 
 
 
 | 617 | var | 
 
 
 
 
 | 618 | ACol, ARow: Integer; | 
 
 
 
 
 | 619 | begin | 
 
 
 
 
 | 620 | if Button = mbRight then | 
 
 
 
 
 | 621 | begin | 
 
 
 
 
 | 622 | value_viewer.MouseToCell(x, y, ACol, ARow); | 
 
 
 
 
 | 623 | if ARow > 0 then | 
 
 
 
 
 | 624 | begin | 
 
 
 
 
 | 625 | value_viewer.Col := ACol; | 
 
 
 
 
 | 626 | value_viewer.Row := ARow; | 
 
 
 
 
 | 627 | end; | 
 
 
 
 
 | 628 | end; | 
 
 
 
 
 | 629 | end; | 
 
 
 
 
 | 630 |  | 
 
 
 
 
 | 631 |  | 
 
 
 
 
 | 632 |  | 
 
 
 
 
 | 633 |  | 
 
 
 
 
 | 634 | procedure TForm_RawEdit.value_viewer_context_copyClick(Sender: TObject); | 
 
 
 
 
 | 635 | var | 
 
 
 
 
 | 636 | //  i:     Byte; | 
 
 
 
 
 | 637 | Name:  String; | 
 
 
 
 
 | 638 | Value: Integer; | 
 
 
 
 
 | 639 | begin | 
 
 
 
 
 | 640 | Name := TMenuItem(Sender).Name; | 
 
 
 
 
 | 641 | if Pos('asstring', Name) > 0 then | 
 
 
 
 
 | 642 | begin | 
 
 
 
 
 | 643 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row]; | 
 
 
 
 
 | 644 | end | 
 
 
 
 
 | 645 | else if Pos('asfloat', Name) > 0 then | 
 
 
 
 
 | 646 | begin | 
 
 
 
 
 | 647 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row]; | 
 
 
 
 
 | 648 | end | 
 
 
 
 
 | 649 | else if Pos('asbitset', Name) > 0 then | 
 
 
 
 
 | 650 | begin | 
 
 
 
 
 | 651 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row]; | 
 
 
 
 
 | 652 | end | 
 
 
 
 
 | 653 | else if (Pos('ashex', Name) > 0) or (Pos('asdec', Name) > 0) then | 
 
 
 
 
 | 654 | begin | 
 
 
 
 
 | 655 | if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then | 
 
 
 
 
 | 656 | begin | 
 
 
 
 
 | 657 | if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 658 | ((hex.SelStart + 1) > hex.DataSize) then | 
 
 
 
 
 | 659 | Value := hex.Data[hex.SelStart]; | 
 
 
 
 
 | 660 | end; | 
 
 
 
 
 | 661 | if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then | 
 
 
 
 
 | 662 | begin | 
 
 
 
 
 | 663 | if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 664 | ((hex.SelStart + 2) > hex.DataSize) then | 
 
 
 
 
 | 665 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256; | 
 
 
 
 
 | 666 | end; | 
 
 
 
 
 | 667 | if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then | 
 
 
 
 
 | 668 | begin | 
 
 
 
 
 | 669 | if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not | 
 
 
 
 
 | 670 | ((hex.SelStart + 4) > hex.DataSize) then | 
 
 
 
 
 | 671 | Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 + | 
 
 
 
 
 | 672 | hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256; | 
 
 
 
 
 | 673 | end; | 
 
 
 
 
 | 674 | if Pos('asdec', Name) > 0 then | 
 
 
 
 
 | 675 | begin | 
 
 
 
 
 | 676 | Clipboard.AsText := IntToStr(Value); | 
 
 
 
 
 | 677 | end | 
 
 
 
 
 | 678 | else | 
 
 
 
 
 | 679 | begin | 
 
 
 
 
 | 680 | if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then | 
 
 
 
 
 | 681 | Clipboard.AsText := '0x' + IntToHex(Value, 2); | 
 
 
 
 
 | 682 | if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then | 
 
 
 
 
 | 683 | Clipboard.AsText := '0x' + IntToHex(Value, 4); | 
 
 
 
 
 | 684 | if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then | 
 
 
 
 
 | 685 | Clipboard.AsText := '0x' + IntToHex(Value, 8); | 
 
 
 
 
 | 686 | end; | 
 
 
 
 
 | 687 | end | 
 
 
 
 
 | 688 | else | 
 
 
 
 
 | 689 | begin | 
 
 
 
 
 | 690 | Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row]; | 
 
 
 
 
 | 691 | end; | 
 
 
 
 
 | 692 | end; | 
 
 
 
 
 | 693 |  | 
 
 
 
 
 | 694 |  | 
 
 
 
 
 | 695 |  | 
 
 
 
 
 | 696 |  | 
 
 
 
 
 | 697 | procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: Integer; Value: String); | 
 
 
 
 
 | 698 | var | 
 
 
 
 
 | 699 | Data: TByteData; | 
 
 
 
 
 | 700 | value_int: LongWord; | 
 
 
 
 
 | 701 | value_float: Single; | 
 
 
 
 
 | 702 | i: Word; | 
 
 
 
 
 | 703 | begin | 
 
 
 
 
 | 704 | case datatype of | 
 
 
 
 
 | 705 | 1..4: | 
 
 
 
 
 | 706 | begin | 
 
 
 
 
 | 707 | value_int := StrToInt(Value); | 
 
 
 
 
 | 708 | SetLength(Data, datatype); | 
 
 
 
 
 | 709 | for i := 0 to datatype - 1 do | 
 
 
 
 
 | 710 | begin | 
 
 
 
 
 | 711 | Data[i]   := value_int mod 256; | 
 
 
 
 
 | 712 | value_int := value_int div 256; | 
 
 
 
 
 | 713 | end; | 
 
 
 
 
 | 714 | end; | 
 
 
 
 
 | 715 | 5..8: | 
 
 
 
 
 | 716 | begin | 
 
 
 
 
 | 717 | value_int := StrToInt('$' + Value); | 
 
 
 
 
 | 718 | SetLength(Data, datatype - 4); | 
 
 
 
 
 | 719 | for i := 0 to datatype - 5 do | 
 
 
 
 
 | 720 | begin | 
 
 
 
 
 | 721 | Data[i]   := value_int mod 256; | 
 
 
 
 
 | 722 | value_int := value_int div 256; | 
 
 
 
 
 | 723 | end; | 
 
 
 
 
 | 724 | end; | 
 
 
 
 
 | 725 | 9: | 
 
 
 
 
 | 726 | begin | 
 
 
 
 
 | 727 | value_float := StrToFloat(Value); | 
 
 
 
 
 | 728 | Data := Encode_Float(value_float); | 
 
 
 
 
 | 729 | end; | 
 
 
 
 
 | 730 | 10: | 
 
 
 
 
 | 731 | begin | 
 
 
 
 
 | 732 | value_int := BinToInt(Value); | 
 
 
 
 
 | 733 | SetLength(Data, 1); | 
 
 
 
 
 | 734 | Data[0] := value_int; | 
 
 
 
 
 | 735 | end; | 
 
 
 
 
 | 736 | 10000..65535: | 
 
 
 
 
 | 737 | begin | 
 
 
 
 
 | 738 | SetLength(Data, datatype - 10000); | 
 
 
 
 
 | 739 | for i := 1 to datatype - 10000 do | 
 
 
 
 
 | 740 | begin | 
 
 
 
 
 | 741 | if i <= Length(Value) then | 
 
 
 
 
 | 742 | Data[i - 1] := Ord(Value[i]) | 
 
 
 
 
 | 743 | else | 
 
 
 
 
 | 744 | Data[i - 1] := 0; | 
 
 
 
 
 | 745 | end; | 
 
 
 
 
 | 746 | end; | 
 
 
 
 
 | 747 | end; | 
 
 
 
 
 | 748 | for i := 0 to High(Data) do | 
 
 
 
 
 | 749 | begin | 
 
 
 
 
 | 750 | if hex.Data[offset + i] <> Data[i] then | 
 
 
 
 
 | 751 | hex.ByteChanged[offset + i] := True; | 
 
 
 
 
 | 752 | hex.Data[offset + i] := Data[i]; | 
 
 
 
 
 | 753 | end; | 
 
 
 
 
 | 754 | hex.Modified := True; | 
 
 
 
 
 | 755 | hexChange(Self); | 
 
 
 
 
 | 756 | hex.Repaint; | 
 
 
 
 
 | 757 | end; | 
 
 
 
 
 | 758 |  | 
 
 
 
 
 | 759 |  | 
 
 
 
 
 | 760 |  | 
 
 
 
 
 | 761 |  | 
 
 
 
 
 | 762 | procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject); | 
 
 
 
 
 | 763 | var | 
 
 
 
 
 | 764 | offset:     Integer; | 
 
 
 
 
 | 765 | datatype:   Word; | 
 
 
 
 
 | 766 | objectname: String; | 
 
 
 
 
 | 767 | Value:      String; | 
 
 
 
 
 | 768 | begin | 
 
 
 
 
 | 769 | if (value_viewer.Col = 1) and (Length(value_viewer.Cells[1, value_viewer.Row]) > 0) then | 
 
 
 
 
 | 770 | begin | 
 
 
 
 
 | 771 | offset := hex.SelStart; | 
 
 
 
 
 | 772 | if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then | 
 
 
 
 
 | 773 | datatype := 1; | 
 
 
 
 
 | 774 | if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then | 
 
 
 
 
 | 775 | datatype := 2; | 
 
 
 
 
 | 776 | if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then | 
 
 
 
 
 | 777 | datatype := 4; | 
 
 
 
 
 | 778 | if value_viewer.Cells[0, value_viewer.Row] = 'Bitset' then | 
 
 
 
 
 | 779 | datatype := 10; | 
 
 
 
 
 | 780 | if value_viewer.Cells[0, value_viewer.Row] = 'Float' then | 
 
 
 
 
 | 781 | datatype := 9; | 
 
 
 
 
 | 782 | if value_viewer.Cells[0, value_viewer.Row] = 'Selected length' then | 
 
 
 
 
 | 783 | Exit; | 
 
 
 
 
 | 784 | if value_viewer.Cells[0, value_viewer.Row] = 'String' then | 
 
 
 
 
 | 785 | begin | 
 
 
 
 
 | 786 | if hex.SelCount > 0 then | 
 
 
 
 
 | 787 | datatype := 10000 + hex.SelCount | 
 
 
 
 
 | 788 | else | 
 
 
 
 
 | 789 | datatype := 10000 + Length(value_viewer.Cells[1, value_viewer.Row]); | 
 
 
 
 
 | 790 | end; | 
 
 
 
 
 | 791 | objectname := ''; | 
 
 
 
 
 | 792 | Value      := GetValue(datatype, offset); | 
 
 
 
 
 | 793 | Form_ValueEdit.MakeVarInput(objectname, offset, datatype, Value, Self); | 
 
 
 
 
 | 794 | end; | 
 
 
 
 
 | 795 | end; | 
 
 
 
 
 | 796 |  | 
 
 
 
 
 | 797 |  | 
 
 
 
 
 | 798 |  | 
 
 
 
 
 | 799 |  | 
 
 
 
 
 | 800 | procedure TForm_RawEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); | 
 
 
 
 
 | 801 | begin | 
 
 
 
 
 | 802 | if (Shift = [ssCtrl]) and (Key = 83) then | 
 
 
 
 
 | 803 | if hex.Modified then | 
 
 
 
 
 | 804 | if not Save then | 
 
 
 
 
 | 805 | Exit; | 
 
 
 
 
 | 806 | end; | 
 
 
 
 
 | 807 |  | 
 
 
 
 
 | 808 | begin | 
 
 
 
 
 | 809 | AddToolListEntry('rawedit', 'Binary .raw-Editor', ''); | 
 
 
 
 
 | 810 | end. |