source: oup/releases/0.30a/Unit13_rawedit.pas@ 748

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