source: oup/releases/0.28a/Unit13_rawedit.pas@ 33

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