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