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

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