source: oup/releases/0.31a/Unit13_rawedit.pas@ 161

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