source: oup/current/Tools/RawEdit.pas@ 72

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