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

Last change on this file since 173 was 113, checked in by alloc, 18 years ago
File size: 23.7 KB
RevLine 
[104]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, TypeDefs,
7 Data, Functions, DatStructureLoader, ConnectionManager, 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: 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
[111]41 function GetValue(datatype: Word; offset: Integer): String;
[104]42 procedure ClearValues;
43 procedure WriteValues;
[111]44 procedure SetNewValue(datatype: Word; offset: Integer; Value: String);
[104]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
[113]56 fileid, datoffset: Integer;
[104]57 public
58 end;
59
60var
61 Form_RawEdit: TForm_RawEdit;
62
63implementation
64{$R *.dfm}
[105]65uses Main, ValueEdit, RawList;
[104]66
67procedure TForm_RawEdit.NewFile(fileinfo: TFileInfo);
68var
69 offsets: TRawDataList;
70 i: Integer;
71begin
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;
99end;
100
101procedure TForm_RawEdit.LoadRaw(raw_info: TRawDataInfo);
102var
[111]103 i: Integer;
[104]104 mem: TMemoryStream;
105begin
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
[113]117 if ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then
[104]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;
[113]134 ConManager.Connection[ConnectionID].LoadRawFile(raw_info.SrcID, raw_info.SrcOffset, TStream(mem));
[104]135 hex.LoadFromStream(mem);
136 ClearValues;
137 hexSelectionChanged(Self);
138end;
139
140
141
142
143
144
145procedure TForm_RawEdit.list_offsetClick(Sender: TObject);
146begin
147 ClearValues;
[105]148 datoffset := StrToInt('$' + MidStr(
[104]149 list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
[113]150 LoadRaw(ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset));
[104]151end;
152
153
154
155
[111]156function TForm_RawEdit.GetValue(datatype: Word; offset: Integer): String;
[104]157var
[105]158 Data: TByteData;
[104]159 i: Word;
160 floatformat: TFormatSettings;
161begin
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;
209end;
210
211
212
213
214procedure TForm_RawEdit.ClearValues;
215var
216 i: Byte;
217begin
218 for i := 1 to value_viewer.RowCount - 1 do
219 value_viewer.Cells[1, i] := '';
220end;
221
222
223
224
225procedure TForm_RawEdit.WriteValues;
226var
227 i, j: Integer;
[105]228 Data: TByteData;
[104]229 str: String;
[111]230 Value: Integer;
[104]231 floatformat: TFormatSettings;
232begin
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.Data[hex.SelStart + j] > 0) and ((hex.SelStart + j) < hex.DataSize) do
314 begin
315 if hex.Data[hex.selstart + j] >= 32 then
316 str := str + Char(hex.Data[hex.SelStart + j])
317 else
318 str := str + '.';
319 Inc(j);
320 end;
321 end
322 else
323 begin
324 for j := 0 to hex.SelCount - 1 do
325 if hex.Data[hex.selstart + j] >= 32 then
326 str := str + Char(hex.Data[hex.SelStart + j])
327 else if hex.Data[hex.selstart + j] > 0 then
328 str := str + '.'
329 else
330 Break;
331 end;
332 value_viewer.Cells[1, i] := str;
333 end;
334 end;
335end;
336
337
338
339
340procedure TForm_RawEdit.FormCreate(Sender: TObject);
341var
[111]342 i: Integer;
[104]343 exts: String;
344begin
345 inherited;
346 Self.OnNewFileSelected := Self.NewFile;
347
348 exts := '';
[105]349 if Length(RawLists.RawListHandlers) > 0 then
[104]350 begin
[105]351 for i := 0 to High(RawLists.RawListHandlers) do
[104]352 if Length(exts) > 0 then
[105]353 exts := exts + ',' + RawLists.RawListHandlers[i].Ext
[104]354 else
[105]355 exts := RawLists.RawListHandlers[i].Ext;
[104]356 end;
357 Self.AllowedExts := exts;
358
359 Self.Caption := '';
360 fileid := -1;
361
362{
363 value_viewer.ColCount := 2;
364 value_viewer.RowCount := 8;
365}
366 value_viewer.FixedRows := 1;
367 value_viewer.FixedCols := 1;
368 value_viewer.Cells[0, 0] := 'Type';
369 value_viewer.Cells[1, 0] := 'Value';
370 value_viewer.Cells[0, 1] := '1 byte, unsigned';
371 value_viewer.Cells[0, 2] := '2 bytes, unsigned';
372 value_viewer.Cells[0, 3] := '4 bytes, unsigned';
373 value_viewer.Cells[0, 4] := 'Bitset';
374 value_viewer.Cells[0, 5] := 'Float';
375 value_viewer.Cells[0, 6] := 'String';
376 value_viewer.Cells[0, 7] := 'Selected length';
377 value_viewer.ColWidths[0] := 125;
378 value_viewer.ColWidths[1] := 1000;
379 //
380 value_viewer.Font.Charset := AppSettings.CharSet;
381 //
382end;
383
384
385
386
387function TForm_RawEdit.Save: Boolean;
388var
389 mem: TMemoryStream;
[111]390 i: Integer;
[104]391begin
392 case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
[113]393 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
[104]394 MB_YESNOCANCEL) of
395 idYes:
396 begin
397 mem := TMemoryStream.Create;
398 hex.SaveToStream(mem);
399 mem.Seek(0, soFromBeginning);
[113]400 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, mem);
[104]401 mem.Free;
402 hex.Modified := False;
403 for i := 0 to hex.Datasize - 1 do
404 hex.ByteChanged[i] := False;
405 Result := True;
406 end;
407 idNo:
408 Result := True;
409 idCancel:
410 Result := False;
411 end;
412end;
413
414
415
416
417procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
418begin
419 if hex.Modified then
420 if not Save then
421 CanClose := False;
422end;
423
424
425
426
427procedure TForm_RawEdit.hexChange(Sender: TObject);
428begin
429 ClearValues;
430 if hex.DataSize > 0 then
431 begin
432{ WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
433 WriteValues;
434} end;
435end;
436
437
438
439
440procedure TForm_RawEdit.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
441//var
442// temps: String;
443begin
444 if (Shift = [ssCtrl]) and (Key = Ord('C')) then
445 begin
446 if hex.SelCount > 0 then
447 begin
448 if hex.InCharField then
449 Clipboard.AsText := hex.SelectionAsText
450 else
451 Clipboard.AsText := hex.SelectionAsHex;
452 end;
453 end;
454 if (Shift = [ssCtrl]) and (Key = Ord('V')) then
455 begin
456{ temps:=Clipboard.AsText;
457 IF hex.SelStart+Length(temps)>hex.DataSize THEN
458 SetLength(temps, hex.DataSize-hex.SelStart);
459 hex.Sel
460 hex.SelCount:=Length(temps);
461 hex.ReplaceSelection(temps,Length(temps));
462} end;
463end;
464
465
466
467
468procedure TForm_RawEdit.hexSelectionChanged(Sender: TObject);
469//var
470// selstart: Integer;
471// i, j: Word;
472begin
473{ FOR i:=1 TO structs.RowCount-1 DO BEGIN
474 FOR j:=0 TO structs.ColCount-1 DO BEGIN
475 structs.CellColors[j,i]:=clWhite;
476 structs.CellFontColors[j,i]:=clBlack;
477 END;
478 END;
479} if hex.DataSize > 0 then
480 begin
481{ selstart:=hex.SelStart;
482 IF GetStructureInfoId(GetFileInfo(fileid).Extension)>=0 THEN BEGIN
483 WITH structure_infos[GetStructureInfoId(GetFileInfo(fileid).Extension)] DO BEGIN
484 FOR i:=0 TO High(entries) DO BEGIN
485 IF ((selstart-entries[i].offset)<GetTypeDataLength(entries[i].datatype)) AND ((selstart-entries[i].offset)>=0) THEN BEGIN
486 FOR j:=0 TO structs.ColCount-1 DO BEGIN
487 structs.CellColors[j,i+1]:=clBlue;
488 structs.CellFontColors[j,i+1]:=clWhite;
489 END;
490 structs.Row:=i+1;
491 END;
492 END;
493 END;
494 END;
495} WriteValues;
496 end;
497end;
498
499
500
501
502
503procedure TForm_RawEdit.btn_exportClick(Sender: TObject);
504var
505 fs: TFileStream;
506begin
[105]507 saved.Filter := 'Files of matching extension (*.' +
[113]508 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' +
509 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension +
[104]510 '|All files|*.*';
[113]511 saved.DefaultExt := ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension;
[104]512 if saved.Execute then
513 begin
514 fs := TFileStream.Create(saved.FileName, fmCreate);
515 hex.SaveToStream(fs);
516 fs.Free;
517 end;
518end;
519
520
521
522
523procedure TForm_RawEdit.btn_importClick(Sender: TObject);
524var
525// Data: Tdata;
526 fs: TFileStream;
[105]527 i: Integer;
528 rawinfo: TRawDataInfo;
[104]529begin
[105]530 opend.Filter := 'Files of matching extension (*.' +
[113]531 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' +
532 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension +
[104]533 '|All files|*.*';
534 if opend.Execute then
535 begin
536 fs := TFileStream.Create(opend.FileName, fmOpenRead);
537 if fs.Size <> hex.DataSize then
538 begin
[113]539 if (not (CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then
[105]540 begin
541 ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
542 ', file has to have same size as file in .raw with this backend.' + CrLf +
543 'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf +
544 'Size of chosen file: ' + FormatFileSize(fs.Size));
545 Exit;
546 end else begin
547 if MessageBox(Self.Handle,
548 PChar('File has different size from the file in the .raw.' + CrLf +
549 'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf +
550 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
551 'Replace anyway?' + CrLf +
552 'WARNING: This only replaces the raw-data. It doesn''t' + CrLf +
553 'do the according changes in the .dat. Oni probably' + CrLf +
554 'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
555 begin
556 Exit;
557 end;
558 end;
[113]559 rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset);
560 if CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights then
561 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs)
562 else if CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights then
563 i := ConManager.Connection[ConnectionID].AppendRawFile(rawinfo.LocSep, fs);
564 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, datoffset, 4, @i);
[105]565 end else begin
[113]566 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs);
[104]567 end;
[105]568 fs.Seek(0, soFromBeginning);
569 hex.LoadFromStream(fs);
570 hex.Modified := False;
571 for i := 0 to hex.Datasize - 1 do
572 hex.ByteChanged[i] := False;
[104]573 fs.Free;
574 end;
575end;
576
577
578
579
580procedure TForm_RawEdit.value_viewer_contextPopup(Sender: TObject);
581var
582 i: Byte;
583begin
584 for i := 0 to value_viewer_context.Items.Count - 1 do
585 value_viewer_context.Items.Items[i].Visible := False;
586 with value_viewer do
587 begin
588 if (Col = 1) and (Row > 0) and (Length(Cells[Col, Row]) > 0) then
589 begin
590 if Pos(' byte', Cells[0, Row]) = 2 then
591 begin
592 value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
593 value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible := True;
594 value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible := True;
595 end;
596 if Pos('Float', Cells[0, Row]) = 1 then
597 value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible := True;
598 if Pos('Bitset', Cells[0, Row]) = 1 then
599 value_viewer_context.Items.Find(
600 'Copy to clipboard (as &bitset)').Visible := True;
601 if Pos('String', Cells[0, Row]) = 1 then
602 value_viewer_context.Items.Find(
603 'Copy to clipboard (as &string)').Visible := True;
604 if Pos('Selected length', Cells[0, Row]) = 1 then
605 value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
606 end;
607 end;
608end;
609
610
611
612
613procedure TForm_RawEdit.value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
614 Shift: TShiftState; X, Y: Integer);
615var
616 ACol, ARow: Integer;
617begin
618 if Button = mbRight then
619 begin
620 value_viewer.MouseToCell(x, y, ACol, ARow);
621 if ARow > 0 then
622 begin
623 value_viewer.Col := ACol;
624 value_viewer.Row := ARow;
625 end;
626 end;
627end;
628
629
630
631
632procedure TForm_RawEdit.value_viewer_context_copyClick(Sender: TObject);
633var
634// i: Byte;
635 Name: String;
[111]636 Value: Integer;
[104]637begin
638 Name := TMenuItem(Sender).Name;
639 if Pos('asstring', Name) > 0 then
640 begin
641 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
642 end
643 else if Pos('asfloat', Name) > 0 then
644 begin
645 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
646 end
647 else if Pos('asbitset', Name) > 0 then
648 begin
649 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
650 end
651 else if (Pos('ashex', Name) > 0) or (Pos('asdec', Name) > 0) then
652 begin
653 if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
654 begin
655 if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
656 ((hex.SelStart + 1) > hex.DataSize) then
657 Value := hex.Data[hex.SelStart];
658 end;
659 if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
660 begin
661 if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
662 ((hex.SelStart + 2) > hex.DataSize) then
663 Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
664 end;
665 if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
666 begin
667 if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
668 ((hex.SelStart + 4) > hex.DataSize) then
669 Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
670 hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
671 end;
672 if Pos('asdec', Name) > 0 then
673 begin
674 Clipboard.AsText := IntToStr(Value);
675 end
676 else
677 begin
678 if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
679 Clipboard.AsText := '0x' + IntToHex(Value, 2);
680 if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
681 Clipboard.AsText := '0x' + IntToHex(Value, 4);
682 if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
683 Clipboard.AsText := '0x' + IntToHex(Value, 8);
684 end;
685 end
686 else
687 begin
688 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
689 end;
690end;
691
692
693
694
[111]695procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: Integer; Value: String);
[104]696var
[105]697 Data: TByteData;
[104]698 value_int: LongWord;
699 value_float: Single;
700 i: Word;
701begin
702 case datatype of
703 1..4:
704 begin
705 value_int := StrToInt(Value);
706 SetLength(Data, datatype);
707 for i := 0 to datatype - 1 do
708 begin
709 Data[i] := value_int mod 256;
710 value_int := value_int div 256;
711 end;
712 end;
713 5..8:
714 begin
715 value_int := StrToInt('$' + Value);
716 SetLength(Data, datatype - 4);
717 for i := 0 to datatype - 5 do
718 begin
719 Data[i] := value_int mod 256;
720 value_int := value_int div 256;
721 end;
722 end;
723 9:
724 begin
725 value_float := StrToFloat(Value);
726 Data := Encode_Float(value_float);
727 end;
728 10:
729 begin
730 value_int := BinToInt(Value);
731 SetLength(Data, 1);
732 Data[0] := value_int;
733 end;
734 10000..65535:
735 begin
736 SetLength(Data, datatype - 10000);
737 for i := 1 to datatype - 10000 do
738 begin
739 if i <= Length(Value) then
740 Data[i - 1] := Ord(Value[i])
741 else
742 Data[i - 1] := 0;
743 end;
744 end;
745 end;
746 for i := 0 to High(Data) do
747 begin
748 if hex.Data[offset + i] <> Data[i] then
749 hex.ByteChanged[offset + i] := True;
750 hex.Data[offset + i] := Data[i];
751 end;
752 hex.Modified := True;
753 hexChange(Self);
754 hex.Repaint;
755end;
756
757
758
759
760procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject);
761var
[111]762 offset: Integer;
[104]763 datatype: Word;
764 objectname: String;
765 Value: String;
766begin
767 if (value_viewer.Col = 1) and (Length(value_viewer.Cells[1, value_viewer.Row]) > 0) then
768 begin
769 offset := hex.SelStart;
770 if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
771 datatype := 1;
772 if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
773 datatype := 2;
774 if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
775 datatype := 4;
776 if value_viewer.Cells[0, value_viewer.Row] = 'Bitset' then
777 datatype := 10;
778 if value_viewer.Cells[0, value_viewer.Row] = 'Float' then
779 datatype := 9;
780 if value_viewer.Cells[0, value_viewer.Row] = 'Selected length' then
781 Exit;
782 if value_viewer.Cells[0, value_viewer.Row] = 'String' then
783 begin
784 if hex.SelCount > 0 then
785 datatype := 10000 + hex.SelCount
786 else
787 datatype := 10000 + Length(value_viewer.Cells[1, value_viewer.Row]);
788 end;
789 objectname := '';
790 Value := GetValue(datatype, offset);
791 Form_ValueEdit.MakeVarInput(objectname, offset, datatype, Value, Self);
792 end;
793end;
794
795
796
797
798procedure TForm_RawEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
799begin
800 if (Shift = [ssCtrl]) and (Key = 83) then
801 if hex.Modified then
802 if not Save then
803 Exit;
804end;
805
806begin
807 AddToolListEntry('rawedit', 'Binary .raw-Editor', '');
808end.
Note: See TracBrowser for help on using the repository browser.