ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/oup/rewrite/Tools/RawEdit.pas
Revision: 104
Committed: Tue Feb 20 22:03:11 2007 UTC (18 years, 7 months ago) by alloc
Content type: text/x-pascal
File size: 22686 byte(s)
Log Message:

File Contents

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