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

Last change on this file since 178 was 177, 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]104begin
105 if hex.Modified then
106 begin
107 if not Save then
108 begin
109 Exit;
110 end;
111 end;
[177]112 for i := 0 to filelist.Count - 1 do
[104]113 begin
[177]114 if ConManager.Connection[ConnectionID].ExtractFileIDOfName(filelist.Items.Strings[i]) = Raw_Info.SrcID then
[104]115 begin
[177]116 filelist.ItemIndex := i;
117 listClick(Self);
118 Break;
[104]119 end;
[177]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
[104]124 begin
[177]125 list_offset.ItemIndex := i;
126 list_offsetClick(Self);
127 Break;
[104]128 end;
129 end;
130end;
131
132
133
134
135
136
137procedure TForm_RawEdit.list_offsetClick(Sender: TObject);
[177]138var
139 mem: TMemoryStream;
140 rawinfo: TRawDataInfo;
[104]141begin
[105]142 datoffset := StrToInt('$' + MidStr(
[104]143 list_offset.Items.Strings[list_offset.ItemIndex], 3, 8));
[177]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);
[104]152end;
153
154
155
156
[111]157function TForm_RawEdit.GetValue(datatype: Word; offset: Integer): String;
[104]158var
[105]159 Data: TByteData;
[104]160 i: Word;
161 floatformat: TFormatSettings;
162begin
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;
210end;
211
212
213
214
215procedure TForm_RawEdit.ClearValues;
216var
217 i: Byte;
218begin
219 for i := 1 to value_viewer.RowCount - 1 do
220 value_viewer.Cells[1, i] := '';
221end;
222
223
224
225
226procedure TForm_RawEdit.WriteValues;
227var
228 i, j: Integer;
[105]229 Data: TByteData;
[104]230 str: String;
[111]231 Value: Integer;
[104]232 floatformat: TFormatSettings;
233begin
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
[175]314 while (hex.SelStart + j) < hex.DataSize do
[104]315 begin
[175]316 if hex.Data[hex.SelStart + j] = 0 then
317 Break;
[104]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;
338end;
339
340
341
342
343procedure TForm_RawEdit.FormCreate(Sender: TObject);
344var
[111]345 i: Integer;
[104]346 exts: String;
347begin
348 inherited;
349 Self.OnNewFileSelected := Self.NewFile;
350
351 exts := '';
[105]352 if Length(RawLists.RawListHandlers) > 0 then
[104]353 begin
[105]354 for i := 0 to High(RawLists.RawListHandlers) do
[104]355 if Length(exts) > 0 then
[105]356 exts := exts + ',' + RawLists.RawListHandlers[i].Ext
[104]357 else
[105]358 exts := RawLists.RawListHandlers[i].Ext;
[104]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 //
385end;
386
387
388
389
390function TForm_RawEdit.Save: Boolean;
391var
392 mem: TMemoryStream;
[111]393 i: Integer;
[104]394begin
395 case MessageBox(Self.Handle, PChar('Save changes to .raw-part of file ' +
[113]396 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Name + '?'), PChar('Data changed...'),
[104]397 MB_YESNOCANCEL) of
398 idYes:
399 begin
400 mem := TMemoryStream.Create;
401 hex.SaveToStream(mem);
402 mem.Seek(0, soFromBeginning);
[113]403 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, mem);
[104]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;
415end;
416
417
418
419
420procedure TForm_RawEdit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
421begin
422 if hex.Modified then
423 if not Save then
424 CanClose := False;
425end;
426
427
428
429
430procedure TForm_RawEdit.hexChange(Sender: TObject);
431begin
432 ClearValues;
433 if hex.DataSize > 0 then
434 begin
435{ WriteStructureInfos(GetStructureInfoId(GetFileInfo(fileid).Extension));
436 WriteValues;
437} end;
438end;
439
440
441
442
443procedure TForm_RawEdit.hexKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
444//var
445// temps: String;
446begin
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;
466end;
467
468
469
470
471procedure TForm_RawEdit.hexSelectionChanged(Sender: TObject);
472//var
473// selstart: Integer;
474// i, j: Word;
475begin
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;
500end;
501
502
503
504
505
506procedure TForm_RawEdit.btn_exportClick(Sender: TObject);
507var
508 fs: TFileStream;
509begin
[105]510 saved.Filter := 'Files of matching extension (*.' +
[113]511 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' +
512 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension +
[104]513 '|All files|*.*';
[113]514 saved.DefaultExt := ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension;
[104]515 if saved.Execute then
516 begin
517 fs := TFileStream.Create(saved.FileName, fmCreate);
518 hex.SaveToStream(fs);
519 fs.Free;
520 end;
521end;
522
523
524
525
526procedure TForm_RawEdit.btn_importClick(Sender: TObject);
527var
528// Data: Tdata;
529 fs: TFileStream;
[105]530 i: Integer;
531 rawinfo: TRawDataInfo;
[104]532begin
[105]533 opend.Filter := 'Files of matching extension (*.' +
[113]534 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension + ')|*.' +
535 ConManager.Connection[ConnectionID].GetFileInfo(fileid).Extension +
[104]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
[113]542 if (not (CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights)) and (not (CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights)) then
[105]543 begin
544 ShowMessage('Can''t import ' + ExtractFilename(importd.FileName) +
545 ', file has to have same size as file in .raw with this backend.' + CrLf +
546 'Size of file in .raw: ' + FormatFileSize(hex.DataSize) + CrLf +
547 'Size of chosen file: ' + FormatFileSize(fs.Size));
548 Exit;
549 end else begin
550 if MessageBox(Self.Handle,
551 PChar('File has different size from the file in the .raw.' + CrLf +
552 'Size of file in .dat: ' + FormatFileSize(hex.DataSize) + CrLf +
553 'Size of chosen file: ' + FormatFileSize(fs.Size) + CrLf +
554 'Replace anyway?' + CrLf +
555 'WARNING: This only replaces the raw-data. It doesn''t' + CrLf +
556 'do the according changes in the .dat. Oni probably' + CrLf +
557 'won''t be able to use the data correctly!'), PChar('Different size'), MB_YESNO + MB_ICONWARNING) = ID_NO then
558 begin
559 Exit;
560 end;
561 end;
[113]562 rawinfo := ConManager.Connection[ConnectionID].GetRawInfo(fileid, datoffset);
563 if CR_ResizeRaw in ConManager.Connection[ConnectionID].ChangeRights then
564 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs)
565 else if CR_AppendRaw in ConManager.Connection[ConnectionID].ChangeRights then
566 i := ConManager.Connection[ConnectionID].AppendRawFile(rawinfo.LocSep, fs);
567 ConManager.Connection[ConnectionID].UpdateDatFilePart(fileid, datoffset, 4, @i);
[105]568 end else begin
[113]569 ConManager.Connection[ConnectionID].UpdateRawFile(fileid, datoffset, fs);
[104]570 end;
[105]571 fs.Seek(0, soFromBeginning);
572 hex.LoadFromStream(fs);
573 hex.Modified := False;
574 for i := 0 to hex.Datasize - 1 do
575 hex.ByteChanged[i] := False;
[104]576 fs.Free;
577 end;
578end;
579
580
581
582
583procedure TForm_RawEdit.value_viewer_contextPopup(Sender: TObject);
584var
585 i: Byte;
586begin
587 for i := 0 to value_viewer_context.Items.Count - 1 do
588 value_viewer_context.Items.Items[i].Visible := False;
589 with value_viewer do
590 begin
591 if (Col = 1) and (Row > 0) and (Length(Cells[Col, Row]) > 0) then
592 begin
593 if Pos(' byte', Cells[0, Row]) = 2 then
594 begin
595 value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
596 value_viewer_context.Items.Find('Copy to clipboard (as &dec)').Visible := True;
597 value_viewer_context.Items.Find('Copy to clipboard (as &hex)').Visible := True;
598 end;
599 if Pos('Float', Cells[0, Row]) = 1 then
600 value_viewer_context.Items.Find('Copy to clipboard (as &float)').Visible := True;
601 if Pos('Bitset', Cells[0, Row]) = 1 then
602 value_viewer_context.Items.Find(
603 'Copy to clipboard (as &bitset)').Visible := True;
604 if Pos('String', Cells[0, Row]) = 1 then
605 value_viewer_context.Items.Find(
606 'Copy to clipboard (as &string)').Visible := True;
607 if Pos('Selected length', Cells[0, Row]) = 1 then
608 value_viewer_context.Items.Find('Copy to &clipboard').Visible := True;
609 end;
610 end;
611end;
612
613
614
615
616procedure TForm_RawEdit.value_viewerMouseDown(Sender: TObject; Button: TMouseButton;
617 Shift: TShiftState; X, Y: Integer);
618var
619 ACol, ARow: Integer;
620begin
621 if Button = mbRight then
622 begin
623 value_viewer.MouseToCell(x, y, ACol, ARow);
624 if ARow > 0 then
625 begin
626 value_viewer.Col := ACol;
627 value_viewer.Row := ARow;
628 end;
629 end;
630end;
631
632
633
634
635procedure TForm_RawEdit.value_viewer_context_copyClick(Sender: TObject);
636var
637// i: Byte;
638 Name: String;
[111]639 Value: Integer;
[104]640begin
641 Name := TMenuItem(Sender).Name;
642 if Pos('asstring', Name) > 0 then
643 begin
644 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
645 end
646 else if Pos('asfloat', Name) > 0 then
647 begin
648 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
649 end
650 else if Pos('asbitset', Name) > 0 then
651 begin
652 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
653 end
654 else if (Pos('ashex', Name) > 0) or (Pos('asdec', Name) > 0) then
655 begin
656 if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
657 begin
658 if ((hex.SelCount = 1) or (hex.SelCount = 0)) and not
659 ((hex.SelStart + 1) > hex.DataSize) then
660 Value := hex.Data[hex.SelStart];
661 end;
662 if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
663 begin
664 if ((hex.SelCount = 2) or (hex.SelCount = 0)) and not
665 ((hex.SelStart + 2) > hex.DataSize) then
666 Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256;
667 end;
668 if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
669 begin
670 if ((hex.SelCount = 4) or (hex.SelCount = 0)) and not
671 ((hex.SelStart + 4) > hex.DataSize) then
672 Value := hex.Data[hex.SelStart] + hex.Data[hex.SelStart + 1] * 256 +
673 hex.Data[hex.SelStart + 2] * 256 * 256 + hex.Data[hex.SelStart + 3] * 256 * 256 * 256;
674 end;
675 if Pos('asdec', Name) > 0 then
676 begin
677 Clipboard.AsText := IntToStr(Value);
678 end
679 else
680 begin
681 if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
682 Clipboard.AsText := '0x' + IntToHex(Value, 2);
683 if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
684 Clipboard.AsText := '0x' + IntToHex(Value, 4);
685 if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
686 Clipboard.AsText := '0x' + IntToHex(Value, 8);
687 end;
688 end
689 else
690 begin
691 Clipboard.AsText := value_viewer.Cells[value_viewer.Col, value_viewer.Row];
692 end;
693end;
694
695
696
697
[111]698procedure TForm_RawEdit.SetNewValue(datatype: Word; offset: Integer; Value: String);
[104]699var
[105]700 Data: TByteData;
[104]701 value_int: LongWord;
702 value_float: Single;
703 i: Word;
704begin
705 case datatype of
706 1..4:
707 begin
708 value_int := StrToInt(Value);
709 SetLength(Data, datatype);
710 for i := 0 to datatype - 1 do
711 begin
712 Data[i] := value_int mod 256;
713 value_int := value_int div 256;
714 end;
715 end;
716 5..8:
717 begin
718 value_int := StrToInt('$' + Value);
719 SetLength(Data, datatype - 4);
720 for i := 0 to datatype - 5 do
721 begin
722 Data[i] := value_int mod 256;
723 value_int := value_int div 256;
724 end;
725 end;
726 9:
727 begin
728 value_float := StrToFloat(Value);
729 Data := Encode_Float(value_float);
730 end;
731 10:
732 begin
733 value_int := BinToInt(Value);
734 SetLength(Data, 1);
735 Data[0] := value_int;
736 end;
737 10000..65535:
738 begin
739 SetLength(Data, datatype - 10000);
740 for i := 1 to datatype - 10000 do
741 begin
742 if i <= Length(Value) then
743 Data[i - 1] := Ord(Value[i])
744 else
745 Data[i - 1] := 0;
746 end;
747 end;
748 end;
749 for i := 0 to High(Data) do
750 begin
751 if hex.Data[offset + i] <> Data[i] then
752 hex.ByteChanged[offset + i] := True;
753 hex.Data[offset + i] := Data[i];
754 end;
755 hex.Modified := True;
756 hexChange(Self);
757 hex.Repaint;
758end;
759
760
761
762
763procedure TForm_RawEdit.value_viewerDblClick(Sender: TObject);
764var
[111]765 offset: Integer;
[104]766 datatype: Word;
767 objectname: String;
768 Value: String;
769begin
770 if (value_viewer.Col = 1) and (Length(value_viewer.Cells[1, value_viewer.Row]) > 0) then
771 begin
772 offset := hex.SelStart;
773 if value_viewer.Cells[0, value_viewer.Row] = '1 byte, unsigned' then
774 datatype := 1;
775 if value_viewer.Cells[0, value_viewer.Row] = '2 bytes, unsigned' then
776 datatype := 2;
777 if value_viewer.Cells[0, value_viewer.Row] = '4 bytes, unsigned' then
778 datatype := 4;
779 if value_viewer.Cells[0, value_viewer.Row] = 'Bitset' then
780 datatype := 10;
781 if value_viewer.Cells[0, value_viewer.Row] = 'Float' then
782 datatype := 9;
783 if value_viewer.Cells[0, value_viewer.Row] = 'Selected length' then
784 Exit;
785 if value_viewer.Cells[0, value_viewer.Row] = 'String' then
786 begin
787 if hex.SelCount > 0 then
788 datatype := 10000 + hex.SelCount
789 else
790 datatype := 10000 + Length(value_viewer.Cells[1, value_viewer.Row]);
791 end;
792 objectname := '';
793 Value := GetValue(datatype, offset);
794 Form_ValueEdit.MakeVarInput(objectname, offset, datatype, Value, Self);
795 end;
796end;
797
798
799
800
801procedure TForm_RawEdit.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
802begin
803 if (Shift = [ssCtrl]) and (Key = 83) then
804 if hex.Modified then
805 if not Save then
806 Exit;
807end;
808
809begin
810 AddToolListEntry('rawedit', 'Binary .raw-Editor', '');
811end.
Note: See TracBrowser for help on using the repository browser.