root/Cheat Engine/OpenSave.pas @ 311

Revision 311, 219.1 kB (checked in by dark_byte, 8 months ago)

mass commit for beta 6

Line 
1unit OpenSave;          //should be called loadsave but oh well...
2
3interface
4
5
6uses forms, mainunit,windows,standaloneunit,SysUtils,advancedoptionsunit,commentsunit,
7     cefuncproc,classes,formmemorymodifier,formMemoryTrainerUnit,shellapi,
8     MemoryTrainerDesignUnit,StdCtrls,ExtraTrainerComponents,Graphics,Controls,
9     ExtCtrls,Dialogs,newkernelhandler, hotkeyhandler, structuresfrm, XMLDoc, XMLIntf, KIcon, comctrls;
10
11
12var CurrentTableVersion: dword=9;
13procedure SaveTable(Filename: string);
14procedure LoadTable(Filename: string;merge: boolean);
15procedure SaveCEM(Filename:string;address,size:dword);
16
17procedure LoadExe(filename: string);
18
19
20procedure SaveCTEntryToXMLNode(i: integer; Entries: IXMLNode);
21
22
23{type TCEPointer=record
24  Address: Dword;  //only used when last pointer in list
25  offset: dword;
26end;}
27
28type
29  MemoryRecordV6 = record
30        Description : string;
31        Address : dword;
32        interpretableaddress: string;
33        VarType : byte;
34        unicode : boolean;
35        IsPointer: Boolean;
36        pointers: array of TCEPointer;
37        Bit     : Byte;
38        bitlength: integer;
39        Frozen : boolean;
40        FrozenValue : Int64;
41        OldValue: string;   //not saved
42        Frozendirection: integer; //0=always freeze,1=only freeze when going up,2=only freeze when going down
43        Group:  Byte;
44        ShowAsHex: boolean;
45        autoassemblescript: string;
46        allocs: TCEAllocArray;
47  end;
48
49  MemoryRecordV5 = record
50        Description : string;
51        Address : dword;
52        VarType : byte;
53        Unicode : boolean;
54        IsPointer: Boolean;
55        pointers: array of TCEPointer;
56        Bit     : Byte;
57        bitlength: integer;
58        Frozen : boolean;
59        FrozenValue : Int64;
60        Frozendirection: integer; //0=always freeze,1=only freeze when going up,2=only freeze when going down
61        Group:  Byte;
62        ShowAsHex: boolean;
63  end;
64
65  MemoryRecordV4 = record
66        Description : string[50];
67        Address : dword;
68        VarType : byte;
69        IsPointer: Boolean;
70        pointers: array of TCEPointer;
71        Bit     : Byte;
72        bitlength: integer;
73        Frozen : boolean;
74        FrozenValue : Int64;
75        Frozendirection: integer; //0=always freeze,1=only freeze when going up,2=only freeze when going down
76        Group:  Byte;
77        ShowAsHex: boolean;
78  end;
79
80
81  MemoryRecordV3 = record
82        Description : string[50];
83        Address : dword;
84        VarType : byte;
85        IsPointer: Boolean;
86        pointers: array of TCEPointer;
87        Bit     : Byte;
88        bitlength: integer;
89        Frozen : boolean;
90        FrozenValue : Int64;
91        Frozendirection: integer; //0=always freeze,1=only freeze when going up,2=only freeze when going down
92        Group:  Byte;
93  end;
94
95  MemoryRecordV2 = record
96        Description : string[50];
97        Address : dword;
98        VarType : byte;
99        Bit     : Byte;
100        bitlength: integer;
101        Frozen : boolean;
102        FrozenValue : Int64;
103        Frozendirection: integer; //0=always freeze,1=only freeze when going up,2=only freeze when going down
104        Group:  Byte;
105  end;
106
107  MemoryRecordV1 = record
108        Description : string[50];
109        Address : dword;
110        VarType : byte;
111        Bit     : Byte;
112        bitlength: integer;
113        Frozen : boolean;
114        FrozenValue : Int64;
115        Group:  Byte;
116        x,y: dword;
117  end;
118
119type
120  MemoryRecordcet3 = record
121        Description : string[50];
122        Address : dword;
123        VarType : byte;
124        Bit     : Byte;
125        Frozen : boolean;
126        FrozenValue : Int64;
127        Group:  Byte;
128  end;
129
130type
131  MemoryRecordOld = record
132        Description : string[50];
133        Address : dword;
134        VarType : byte;
135        Frozen : boolean;
136        FrozenValue : Dword;
137  end;
138
139function GetmemrecFromXMLNode(CheatEntry: IXMLNode): MemoryRecord;
140procedure LoadStructFromXMLNode(var struct: TbaseStructure; Structure: IXMLNode);
141procedure SaveStructToXMLNode(struct: TbaseStructure; Structures: IXMLNode);
142
143{$ifdef net}
144var processhandle: thandle;
145{$endif}
146
147resourcestring strunknowncomponent='There is a unknown component in the trainer! compnr=';
148
149implementation
150
151uses symbolhandler;
152
153
154{$ifndef net}
155procedure LoadTrainer8(trainer:TFilestream);
156var temp: dword;
157    tempb: boolean;
158    tempc: tcolor;
159    tempi: integer;
160    tempbc: tbevelcut;
161    tempbk: tbevelkind;
162    tempcursor: tcursor;
163    i,j,k:integer;
164    x: pchar;
165
166    image: pointer;
167    temps: string;
168    filecount: integer;
169    f: tfilestream;
170//    trainerdata1: array of TTrainerData1;
171begin
172  f:=nil;
173  filecount:=0;
174 
175  with frmMemoryModifier do
176  begin
177    //size of trainerdata
178    trainer.ReadBuffer(temp,4);
179    setlength(frmMemoryModifier.trainerdata,temp);
180
181    for i:=0 to length(trainerdata)-1 do
182    begin
183      //description
184      trainer.ReadBuffer(temp,4);
185      getmem(x,temp+1);
186      trainer.ReadBuffer(x^,temp);
187      x[temp]:=#0;
188      trainerdata[i].description:=x;
189      freemem(x);
190
191      //hotkeytext
192      trainer.ReadBuffer(temp,4);
193      getmem(x,temp+1);
194      trainer.ReadBuffer(x^,temp);
195      x[temp]:=#0;
196      trainerdata[i].hotkeytext:=x;
197      freemem(x);
198
199      trainer.readbuffer(trainerdata[i].hotkey,sizeof(trainerdata[i].hotkey));
200
201      trainer.ReadBuffer(temp,4);
202      setlength(trainerdata[i].codeentrys,temp);
203
204      //opcodes of this cheat
205      for j:=0 to length(trainerdata[i].codeentrys)-1 do
206      begin
207        //address
208        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
209
210        //modulename
211        trainer.ReadBuffer(temp,4);
212        getmem(x,temp+1);
213        trainer.ReadBuffer(x^,temp);
214        x[temp]:=#0;
215        trainerdata[i].codeentrys[j].modulename:=x;
216        freemem(x);
217
218        //module offset
219        trainer.ReadBuffer(trainerdata[i].codeentrys[j].moduleoffset,4);
220
221        //original opcode
222        trainer.ReadBuffer(temp,4);
223        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
224        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
225      end;
226
227      //address entrys
228      trainer.ReadBuffer(temp,4);
229      setlength(trainerdata[i].addressentrys,temp);
230      for j:=0 to length(trainerdata[i].addressentrys)-1 do
231      begin
232        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
233
234        //interpretable address
235        trainer.ReadBuffer(temp,4);
236        getmem(x,temp+1);
237        trainer.ReadBuffer(x^,temp);
238        x[temp]:=#0;
239        trainerdata[i].addressentrys[j].interpretableaddress:=x;
240        freemem(x);
241
242        trainer.ReadBuffer(trainerdata[i].addressentrys[j].ispointer,sizeof(trainerdata[i].addressentrys[j].ispointer));
243
244        trainer.ReadBuffer(tempi,4);
245        setlength(trainerdata[i].addressentrys[j].pointers,tempi);
246
247        for k:=0 to tempi-1 do
248        begin
249          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].address,sizeof(trainerdata[i].addressentrys[j].pointers[k].address));
250
251          //interpretable address
252          trainer.ReadBuffer(temp,4);
253          getmem(x,temp+1);
254          trainer.ReadBuffer(x^,temp);
255          x[temp]:=#0;
256          trainerdata[i].addressentrys[j].pointers[k].interpretableaddress:=x;
257          freemem(x);
258
259          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].offset,sizeof(trainerdata[i].addressentrys[j].pointers[k].offset));
260        end;
261
262
263        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
264        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
265        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
266        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
267        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
268        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
269
270        trainer.ReadBuffer(temp,4);
271        getmem(x,temp+1);
272        trainer.ReadBuffer(x^,temp);
273        x[temp]:=#0;
274        trainerdata[i].addressentrys[j].value:=x;
275        freemem(x);
276
277
278       // trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
279        if trainerdata[i].addressentrys[j].userinput then
280        begin
281          trainerdata[i].hasedit:=true;
282          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
283        end;
284
285        //interpretable address
286        trainer.ReadBuffer(temp,4);
287        getmem(x,temp+1);
288        trainer.ReadBuffer(x^,temp);
289        x[temp]:=#0;
290        trainerdata[i].addressentrys[j].autoassemblescript:=x;
291        freemem(x);
292      end;
293    end;
294
295    //title
296    trainer.ReadBuffer(temp,4);
297    getmem(x,temp+1);
298    trainer.ReadBuffer(x^,temp);
299    x[temp]:=#0;
300    edittitle.Text:=x;
301    freemem(x);
302
303    //launch filename
304    trainer.ReadBuffer(temp,4);
305    getmem(x,temp+1);
306    trainer.ReadBuffer(x^,temp);
307    x[temp]:=#0;
308    edit2.Text:=x;
309    freemem(x);
310
311    //autolaunch
312    trainer.ReadBuffer(tempb,sizeof(tempb));
313    checkbox2.Checked:=tempb;
314
315    //popup on keypress
316    trainer.ReadBuffer(tempb,sizeof(tempb));
317    checkbox1.Checked:=tempb;
318
319    //process name
320    trainer.ReadBuffer(temp,4);
321    getmem(x,temp+1);
322    trainer.ReadBuffer(x^,temp);
323    x[temp]:=#0;
324    combobox1.Text:=x;
325    freemem(x);
326
327    //hotkeytext
328    trainer.ReadBuffer(temp,4);
329    getmem(x,temp+1);
330    trainer.ReadBuffer(x^,temp);
331    x[temp]:=#0;
332    edithotkey.Text:=x;
333    freemem(x);
334
335    //hotkey+shiftstate
336    trainer.ReadBuffer(popuphotkey,sizeof(popuphotkey));
337
338    //abouttext
339    trainer.ReadBuffer(temp,4);
340    getmem(x,temp+1);
341    trainer.ReadBuffer(x^,temp);
342    x[temp]:=#0;
343    memo1.Text:=x;
344    freemem(x);
345
346    //freeze interval
347    trainer.ReadBuffer(tempi,sizeof(tempi));
348    editFreezeInterval.text:=inttostr(tempi);
349
350    trainer.ReadBuffer(temp,4);
351    if temp=$666 then
352    begin
353      //default
354      //leftside image
355      trainer.ReadBuffer(temp,4); //size of extension
356      getmem(x,temp+1);
357      trainer.ReadBuffer(x^,temp);
358      x[temp]:=#0;
359      leftimageext:=x;
360
361      temps:=tempdir+inttostr(getcurrentprocessid)+'-'+inttostr(filecount)+x;
362      freemem(x);
363
364      f:=tfilestream.Create(temps, fmCreate or fmShareDenyNone);
365      inc(filecount);
366
367      trainer.ReadBuffer(temp,4);
368      getmem(x,temp);
369      trainer.ReadBuffer(x^,temp);
370      f.WriteBuffer(x^,temp);
371      freemem(x);
372      f.free;
373
374      frmMemorytrainerpreview.Image1.Picture.LoadFromFile(temps);
375      if leftimage<>nil then
376        leftimage.Free;
377      leftimage:=tmemorystream.Create;
378      leftimage.LoadFromFile(temps);
379
380      DeleteFile(temps);
381
382      //windowwidth
383      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
384      frmMemorytrainerpreview.Width:=temp;
385
386      //windowheight
387      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
388      frmMemorytrainerpreview.height:=temp;
389
390      //leftsidewidth
391      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
392      frmMemorytrainerpreview.Panel1.Width:=temp;
393
394      //leftsideheight
395      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
396      frmMemorytrainerpreview.Panel1.height:=temp;
397    end
398    else
399    begin
400      //user defined
401      frmMemoryModifier.dontshowdefault:=true;       //obsolete
402      frmMemoryModifier.Button7.Click;
403
404      //windowwidth
405      trainer.readbuffer(temp,4);
406      frmTrainerDesigner.Width:=temp;
407
408      //windowheight
409      trainer.readbuffer(temp,4);
410      frmTrainerDesigner.height:=temp;
411
412
413      while true do
414      begin
415        trainer.ReadBuffer(temp,4);
416        case temp of
417          0: begin
418               //tbutton
419               with tbutton2.create(frmTrainerDesigner) do
420               begin
421                 trainer.ReadBuffer(temp,sizeof(integer));
422                 left:=temp;
423                 trainer.ReadBuffer(temp,sizeof(integer));
424                 top:=temp;
425                 trainer.ReadBuffer(temp,sizeof(integer));
426                 width:=temp;
427                 trainer.ReadBuffer(temp,sizeof(integer));
428                 height:=temp;
429
430                 //caption
431                 trainer.ReadBuffer(temp,4);
432                 getmem(x,temp+1);
433                 trainer.ReadBuffer(x^,temp);
434                 x[temp]:=#0;
435                 caption:=x;
436                 freemem(x);
437
438                 //wordwrap
439                 trainer.ReadBuffer(tempb,sizeof(boolean));
440                 wordwrap:=tempb;
441
442                 //onclick
443                 trainer.ReadBuffer(temp,sizeof(tag));
444                 tag:=temp;
445                 parent:=frmTrainerDesigner;
446
447                 //command
448                 trainer.ReadBuffer(temp,4);
449                 getmem(x,temp+1);
450                 trainer.ReadBuffer(x^,temp);
451                 x[temp]:=#0;
452                 command:=x;
453                 freemem(x);
454
455                 onmousedown:=frmTrainerDesigner.MouseDown;
456                 onmousemove:=frmTrainerDesigner.MouseMove;
457                 onmouseup:=frmTrainerDesigner.MouseUp;
458               end;
459             end;
460
461          1: begin
462               //cheatlist
463               with tcheatlist.create(frmTrainerDesigner) do
464               begin
465                 trainer.ReadBuffer(temp,sizeof(integer));
466                 left:=temp;
467                 trainer.ReadBuffer(temp,sizeof(integer));
468                 top:=temp;
469                 trainer.ReadBuffer(temp,sizeof(integer));
470                 width:=temp;
471                 trainer.ReadBuffer(temp,sizeof(integer));
472                 height:=temp;
473
474                 trainer.ReadBuffer(tempc,sizeof(tcolor));
475                 activationcolor:=tempc;
476                 trainer.ReadBuffer(tempc,sizeof(tcolor));
477                 color:=tempc;
478                 trainer.ReadBuffer(tempc,sizeof(tcolor));
479                 textcolor:=tempc;
480
481                 trainer.ReadBuffer(tempi,sizeof(integer));
482                 hotkeyleft:=tempi;
483                 trainer.ReadBuffer(tempi,sizeof(integer));
484                 descriptionleft:=tempi;
485                 trainer.ReadBuffer(tempi,sizeof(integer));
486                 editleft:=tempi;
487                 trainer.ReadBuffer(tempi,sizeof(integer));
488                 editwidth:=tempi;
489
490                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
491                 bevelinner:=tempbc;
492                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
493                 bevelouter:=tempbc;
494                 trainer.ReadBuffer(tempi,sizeof(integer));
495                 bevelwidth:=tempi;
496                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
497                 bevelkind:=tempbk;
498
499                 trainer.ReadBuffer(tempb,sizeof(boolean));
500                 hascheckbox:=tempb;
501                 trainer.ReadBuffer(tempb,sizeof(boolean));
502                 beepOnActivate:=tempb;                 
503                 trainer.ReadBuffer(tempb,sizeof(boolean));
504                 showhotkeys:=tempb;
505
506                 parent:=frmTrainerDesigner;
507                 onmousedown:=frmTrainerDesigner.MouseDown;
508                 onmousemove:=frmTrainerDesigner.MouseMove;
509                 onmouseup:=frmTrainerDesigner.MouseUp;
510               end;
511             end;
512
513          2: begin
514               //tcheat
515               with tcheat.create(frmTrainerDesigner) do
516               begin
517                 trainer.ReadBuffer(temp,sizeof(integer));
518                 left:=temp;
519                 trainer.ReadBuffer(temp,sizeof(integer));
520                 top:=temp;
521                 trainer.ReadBuffer(temp,sizeof(integer));
522                 width:=temp;
523                 trainer.ReadBuffer(temp,sizeof(integer));
524                 height:=temp;
525
526                 trainer.ReadBuffer(cheatnr,sizeof(integer));
527                 trainer.ReadBuffer(tempc,sizeof(tcolor));
528                 activationcolor:=tempc;
529                 trainer.ReadBuffer(tempc,sizeof(tcolor));
530                 color:=tempc;
531                 trainer.ReadBuffer(tempc,sizeof(tcolor));
532                 textcolor:=tempc;
533
534                 trainer.ReadBuffer(tempi,sizeof(integer));
535                 hotkeyleft:=tempi;
536                 trainer.ReadBuffer(tempi,sizeof(integer));
537                 descriptionleft:=tempi;
538                 trainer.ReadBuffer(tempi,sizeof(integer));
539                 editleft:=tempi;
540                 trainer.ReadBuffer(tempi,sizeof(integer));
541                 editwidth:=tempi;
542
543                 trainer.ReadBuffer(tempb,sizeof(boolean));
544                 hascheckbox:=tempb;
545                 trainer.ReadBuffer(tempb,sizeof(boolean));
546                 beeponactivate:=tempb;                 
547                 trainer.ReadBuffer(tempb,sizeof(boolean));
548                 showhotkey:=tempb;
549
550                 parent:=frmTrainerDesigner;
551                 onmousedown:=frmTrainerDesigner.MouseDown;
552                 onmousemove:=frmTrainerDesigner.MouseMove;
553                 onmouseup:=frmTrainerDesigner.MouseUp;
554               end;
555             end;
556
557          3: begin
558               //timage
559               with timage2.create(frmTrainerDesigner) do
560               begin
561                 trainer.ReadBuffer(temp,sizeof(integer));
562                 left:=temp;
563                 trainer.ReadBuffer(temp,sizeof(integer));
564                 top:=temp;
565                 trainer.ReadBuffer(temp,sizeof(integer));
566                 width:=temp;
567                 trainer.ReadBuffer(temp,sizeof(integer));
568                 height:=temp;
569
570                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
571                 cursor:=tempcursor;
572
573                 trainer.ReadBuffer(tempb,sizeof(tempb));
574                 stretch:=tempb;
575                 trainer.ReadBuffer(tempb,sizeof(tempb));
576                 transparent:=tempb;
577
578                 trainer.ReadBuffer(tempi,sizeof(integer));
579                 tag:=tempi;
580
581                 //-
582
583                 trainer.ReadBuffer(temp,4); //size of extension
584                 getmem(x,temp+1);
585                 trainer.ReadBuffer(x^,temp);  //extension
586                 x[temp]:=#0;
587                 extension:=x;
588
589                 temps:=tempdir+inttostr(getcurrentprocessid)+'-'+inttostr(filecount)+x;
590                 freemem(x);
591
592                 f:=tfilestream.Create(temps, fmCreate or fmShareDenyNone);
593                 inc(filecount);
594
595                 trainer.ReadBuffer(temp,4); //size of imagedata
596                 getmem(x,temp);
597                 trainer.ReadBuffer(x^,temp);
598                 f.WriteBuffer(x^,temp);
599                 freemem(x);
600                 f.free;
601
602                 Picture.LoadFromFile(temps);
603
604
605                 imagedata:=tmemorystream.Create;
606                 imagedata.LoadFromFile(temps);
607
608                 DeleteFile(temps);
609                 //-
610
611
612                 //command
613                 trainer.ReadBuffer(temp,4);
614                 getmem(x,temp+1);
615                 trainer.ReadBuffer(x^,temp);
616                 x[temp]:=#0;
617                 command:=x;
618                 freemem(x);
619
620                 parent:=frmTrainerDesigner;
621                 onmousedown:=frmTrainerDesigner.MouseDown;
622                 onmousemove:=frmTrainerDesigner.MouseMove;
623                 onmouseup:=frmTrainerDesigner.MouseUp;
624               end;
625             end;
626
627          4: begin
628               with tlabel2.Create(frmTrainerDesigner) do
629               begin
630                 trainer.ReadBuffer(temp,sizeof(integer));
631                 left:=temp;
632                 trainer.ReadBuffer(temp,sizeof(integer));
633                 top:=temp;
634                 trainer.ReadBuffer(temp,sizeof(integer));
635                 width:=temp;
636                 trainer.ReadBuffer(temp,sizeof(integer));
637                 height:=temp;
638
639                 //caption
640                 trainer.ReadBuffer(temp,4);
641                 getmem(x,temp+1);
642                 trainer.ReadBuffer(x^,temp);
643                 x[temp]:=#0;
644                 caption:=x;
645                 freemem(x);
646
647                 //wordwrap
648                 trainer.ReadBuffer(tempb,sizeof(boolean));
649                 wordwrap:=tempb;
650
651                 //color
652                 trainer.ReadBuffer(tempc,sizeof(tcolor));
653                 font.Color:=tempc;
654
655                 //command
656                 trainer.ReadBuffer(temp,4);
657                 getmem(x,temp+1);
658                 trainer.ReadBuffer(x^,temp);
659                 x[temp]:=#0;
660                 command:=x;
661                 freemem(x);
662
663                 //cursor
664                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
665                 cursor:=tempcursor;
666
667                 //tag
668                 trainer.ReadBuffer(tempi,sizeof(integer));
669                 tag:=tempi;
670
671                 trainer.ReadBuffer(tempb,sizeof(tempb));
672                 if tempb then
673                   Font.Style:=[fsUnderline]
674                 else
675                   Font.Style:=[];
676
677                   
678                 parent:=frmTrainerDesigner;
679                 onmousedown:=frmTrainerDesigner.MouseDown;
680                 onmousemove:=frmTrainerDesigner.MouseMove;
681                 onmouseup:=frmTrainerDesigner.MouseUp;
682               end;
683             end;
684          $ffffffff: break;
685          else raise exception.Create(strunknowncomponent+Inttostr(temp));
686        end;
687      end;
688    end;
689  end;
690
691  //fill in the list of cheats
692  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
693  begin
694    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
695    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
696  end;
697
698  frmMemoryTrainerPreview.UpdateScreen;
699  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
700end;
701
702
703procedure LoadTrainer7(trainer:TFilestream);
704var temp: dword;
705    tempb: boolean;
706    tempc: tcolor;
707    tempi: integer;
708    tempbc: tbevelcut;
709    tempbk: tbevelkind;
710    tempcursor: tcursor;
711    i,j,k:integer;
712    x: pchar;
713
714    image: pointer;
715//    trainerdata1: array of TTrainerData1;
716begin
717  with frmMemoryModifier do
718  begin
719    //size of trainerdata
720    trainer.ReadBuffer(temp,4);
721    setlength(frmMemoryModifier.trainerdata,temp);
722
723    for i:=0 to length(trainerdata)-1 do
724    begin
725      //description
726      trainer.ReadBuffer(temp,4);
727      getmem(x,temp+1);
728      trainer.ReadBuffer(x^,temp);
729      x[temp]:=#0;
730      trainerdata[i].description:=x;
731      freemem(x);
732
733      //hotkeytext
734      trainer.ReadBuffer(temp,4);
735      getmem(x,temp+1);
736      trainer.ReadBuffer(x^,temp);
737      x[temp]:=#0;
738      trainerdata[i].hotkeytext:=x;
739      freemem(x);
740
741      trainer.readbuffer(trainerdata[i].hotkey,sizeof(trainerdata[i].hotkey));
742
743      trainer.ReadBuffer(temp,4);
744      setlength(trainerdata[i].codeentrys,temp);
745
746      //opcodes of this cheat
747      for j:=0 to length(trainerdata[i].codeentrys)-1 do
748      begin
749        //address
750        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
751
752        //modulename
753        trainer.ReadBuffer(temp,4);
754        getmem(x,temp+1);
755        trainer.ReadBuffer(x^,temp);
756        x[temp]:=#0;
757        trainerdata[i].codeentrys[j].modulename:=x;
758        freemem(x);
759
760        //module offset
761        trainer.ReadBuffer(trainerdata[i].codeentrys[j].moduleoffset,4);
762
763        //original opcode
764        trainer.ReadBuffer(temp,4);
765        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
766        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
767      end;
768
769      //address entrys
770      trainer.ReadBuffer(temp,4);
771      setlength(trainerdata[i].addressentrys,temp);
772      for j:=0 to length(trainerdata[i].addressentrys)-1 do
773      begin
774        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
775
776        //interpretable address
777        trainer.ReadBuffer(temp,4);
778        getmem(x,temp+1);
779        trainer.ReadBuffer(x^,temp);
780        x[temp]:=#0;
781        trainerdata[i].addressentrys[j].interpretableaddress:=x;
782        freemem(x);
783
784        trainer.ReadBuffer(trainerdata[i].addressentrys[j].ispointer,sizeof(trainerdata[i].addressentrys[j].ispointer));
785
786        trainer.ReadBuffer(tempi,4);
787        setlength(trainerdata[i].addressentrys[j].pointers,tempi);
788
789        for k:=0 to tempi-1 do
790        begin
791          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].address,sizeof(trainerdata[i].addressentrys[j].pointers[k].address));
792
793          //interpretable address
794          trainer.ReadBuffer(temp,4);
795          getmem(x,temp+1);
796          trainer.ReadBuffer(x^,temp);
797          x[temp]:=#0;
798          trainerdata[i].addressentrys[j].pointers[k].interpretableaddress:=x;
799          freemem(x);
800
801          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].offset,sizeof(trainerdata[i].addressentrys[j].pointers[k].offset));
802        end;
803
804
805        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
806        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
807        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
808        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
809        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
810        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
811
812        trainer.ReadBuffer(temp,4);
813        getmem(x,temp+1);
814        trainer.ReadBuffer(x^,temp);
815        x[temp]:=#0;
816        trainerdata[i].addressentrys[j].value:=x;
817        freemem(x);
818
819
820       // trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
821        if trainerdata[i].addressentrys[j].userinput then
822        begin
823          trainerdata[i].hasedit:=true;
824          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
825        end;
826
827        //interpretable address
828        trainer.ReadBuffer(temp,4);
829        getmem(x,temp+1);
830        trainer.ReadBuffer(x^,temp);
831        x[temp]:=#0;
832        trainerdata[i].addressentrys[j].autoassemblescript:=x;
833        freemem(x);
834      end;
835    end;
836
837    //title
838    trainer.ReadBuffer(temp,4);
839    getmem(x,temp+1);
840    trainer.ReadBuffer(x^,temp);
841    x[temp]:=#0;
842    edittitle.Text:=x;
843    freemem(x);
844
845    //launch filename
846    trainer.ReadBuffer(temp,4);
847    getmem(x,temp+1);
848    trainer.ReadBuffer(x^,temp);
849    x[temp]:=#0;
850    edit2.Text:=x;
851    freemem(x);
852
853    //autolaunch
854    trainer.ReadBuffer(tempb,sizeof(tempb));
855    checkbox2.Checked:=tempb;
856
857    //popup on keypress
858    trainer.ReadBuffer(tempb,sizeof(tempb));
859    checkbox1.Checked:=tempb;
860
861    //process name
862    trainer.ReadBuffer(temp,4);
863    getmem(x,temp+1);
864    trainer.ReadBuffer(x^,temp);
865    x[temp]:=#0;
866    combobox1.Text:=x;
867    freemem(x);
868
869    //hotkeytext
870    trainer.ReadBuffer(temp,4);
871    getmem(x,temp+1);
872    trainer.ReadBuffer(x^,temp);
873    x[temp]:=#0;
874    edithotkey.Text:=x;
875    freemem(x);
876
877    //hotkey+shiftstate
878    trainer.ReadBuffer(popuphotkey,sizeof(popuphotkey));
879
880    //abouttext
881    trainer.ReadBuffer(temp,4);
882    getmem(x,temp+1);
883    trainer.ReadBuffer(x^,temp);
884    x[temp]:=#0;
885    memo1.Text:=x;
886    freemem(x);
887
888    //freeze interval
889    trainer.ReadBuffer(tempi,sizeof(tempi));
890    editFreezeInterval.text:=inttostr(tempi);
891
892    trainer.ReadBuffer(temp,4);
893    if temp=$666 then
894    begin
895      //default
896      //leftside image
897      trainer.ReadBuffer(temp,4);  //size of the image
898      if temp>0 then
899      begin
900        //getmem(image,temp);
901        //trainer.ReadBuffer(image^,temp);
902        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
903
904        leftimageext:='.bmp';
905        if leftimage<>nil then
906          leftimage.free;
907        leftimage:=tmemorystream.Create;
908        frmMemorytrainerpreview.Image1.Picture.Bitmap.SaveToStream(leftimage);
909      end;
910
911      //windowwidth
912      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
913      frmMemorytrainerpreview.Width:=temp;
914
915      //windowheight
916      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
917      frmMemorytrainerpreview.height:=temp;
918
919      //leftsidewidth
920      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
921      frmMemorytrainerpreview.Panel1.Width:=temp;
922
923      //leftsideheight
924      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
925      frmMemorytrainerpreview.Panel1.height:=temp;
926    end
927    else
928    begin
929      //user defined
930      frmMemoryModifier.dontshowdefault:=true;       //obsolete
931      frmMemoryModifier.Button7.Click;
932
933      //windowwidth
934      trainer.readbuffer(temp,4);
935      frmTrainerDesigner.Width:=temp;
936
937      //windowheight
938      trainer.readbuffer(temp,4);
939      frmTrainerDesigner.height:=temp;
940
941
942      while true do
943      begin
944        trainer.ReadBuffer(temp,4);
945        case temp of
946          0: begin
947               //tbutton
948               with tbutton2.create(frmTrainerDesigner) do
949               begin
950                 trainer.ReadBuffer(temp,sizeof(integer));
951                 left:=temp;
952                 trainer.ReadBuffer(temp,sizeof(integer));
953                 top:=temp;
954                 trainer.ReadBuffer(temp,sizeof(integer));
955                 width:=temp;
956                 trainer.ReadBuffer(temp,sizeof(integer));
957                 height:=temp;
958
959                 //caption
960                 trainer.ReadBuffer(temp,4);
961                 getmem(x,temp+1);
962                 trainer.ReadBuffer(x^,temp);
963                 x[temp]:=#0;
964                 caption:=x;
965                 freemem(x);
966
967                 //wordwrap
968                 trainer.ReadBuffer(tempb,sizeof(boolean));
969                 wordwrap:=tempb;
970
971                 //onclick
972                 trainer.ReadBuffer(temp,sizeof(tag));
973                 tag:=temp;
974                 parent:=frmTrainerDesigner;
975
976                 //command
977                 trainer.ReadBuffer(temp,4);
978                 getmem(x,temp+1);
979                 trainer.ReadBuffer(x^,temp);
980                 x[temp]:=#0;
981                 command:=x;
982                 freemem(x);
983
984                 onmousedown:=frmTrainerDesigner.MouseDown;
985                 onmousemove:=frmTrainerDesigner.MouseMove;
986                 onmouseup:=frmTrainerDesigner.MouseUp;
987               end;
988             end;
989
990          1: begin
991               //cheatlist
992               with tcheatlist.create(frmTrainerDesigner) do
993               begin
994                 trainer.ReadBuffer(temp,sizeof(integer));
995                 left:=temp;
996                 trainer.ReadBuffer(temp,sizeof(integer));
997                 top:=temp;
998                 trainer.ReadBuffer(temp,sizeof(integer));
999                 width:=temp;
1000                 trainer.ReadBuffer(temp,sizeof(integer));
1001                 height:=temp;
1002
1003                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1004                 activationcolor:=tempc;
1005                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1006                 color:=tempc;
1007                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1008                 textcolor:=tempc;
1009
1010                 trainer.ReadBuffer(tempi,sizeof(integer));
1011                 hotkeyleft:=tempi;
1012                 trainer.ReadBuffer(tempi,sizeof(integer));
1013                 descriptionleft:=tempi;
1014                 trainer.ReadBuffer(tempi,sizeof(integer));
1015                 editleft:=tempi;
1016                 trainer.ReadBuffer(tempi,sizeof(integer));
1017                 editwidth:=tempi;
1018
1019                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
1020                 bevelinner:=tempbc;
1021                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
1022                 bevelouter:=tempbc;
1023                 trainer.ReadBuffer(tempi,sizeof(integer));
1024                 bevelwidth:=tempi;
1025                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
1026                 bevelkind:=tempbk;
1027
1028                 trainer.ReadBuffer(tempb,sizeof(boolean));
1029                 hascheckbox:=tempb;
1030                 trainer.ReadBuffer(tempb,sizeof(boolean));
1031                 showhotkeys:=tempb;
1032
1033                 parent:=frmTrainerDesigner;
1034                 onmousedown:=frmTrainerDesigner.MouseDown;
1035                 onmousemove:=frmTrainerDesigner.MouseMove;
1036                 onmouseup:=frmTrainerDesigner.MouseUp;
1037               end;
1038             end;
1039
1040          2: begin
1041               //tcheat
1042               with tcheat.create(frmTrainerDesigner) do
1043               begin
1044                 trainer.ReadBuffer(temp,sizeof(integer));
1045                 left:=temp;
1046                 trainer.ReadBuffer(temp,sizeof(integer));
1047                 top:=temp;
1048                 trainer.ReadBuffer(temp,sizeof(integer));
1049                 width:=temp;
1050                 trainer.ReadBuffer(temp,sizeof(integer));
1051                 height:=temp;
1052
1053                 trainer.ReadBuffer(cheatnr,sizeof(integer));
1054                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1055                 activationcolor:=tempc;
1056                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1057                 color:=tempc;
1058                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1059                 textcolor:=tempc;
1060
1061                 trainer.ReadBuffer(tempi,sizeof(integer));
1062                 hotkeyleft:=tempi;
1063                 trainer.ReadBuffer(tempi,sizeof(integer));
1064                 descriptionleft:=tempi;
1065                 trainer.ReadBuffer(tempi,sizeof(integer));
1066                 editleft:=tempi;
1067                 trainer.ReadBuffer(tempi,sizeof(integer));
1068                 editwidth:=tempi;
1069
1070                 trainer.ReadBuffer(tempb,sizeof(boolean));
1071                 hascheckbox:=tempb;
1072                 trainer.ReadBuffer(tempb,sizeof(boolean));
1073                 showhotkey:=tempb;
1074
1075                 parent:=frmTrainerDesigner;
1076                 onmousedown:=frmTrainerDesigner.MouseDown;
1077                 onmousemove:=frmTrainerDesigner.MouseMove;
1078                 onmouseup:=frmTrainerDesigner.MouseUp;
1079               end;
1080             end;
1081
1082          3: begin
1083               //timage
1084               with timage2.create(frmTrainerDesigner) do
1085               begin
1086                 trainer.ReadBuffer(temp,sizeof(integer));
1087                 left:=temp;
1088                 trainer.ReadBuffer(temp,sizeof(integer));
1089                 top:=temp;
1090                 trainer.ReadBuffer(temp,sizeof(integer));
1091                 width:=temp;
1092                 trainer.ReadBuffer(temp,sizeof(integer));
1093                 height:=temp;
1094
1095                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
1096                 cursor:=tempcursor;
1097
1098                 trainer.ReadBuffer(tempb,sizeof(tempb));
1099                 stretch:=tempb;
1100                 trainer.ReadBuffer(tempb,sizeof(tempb));
1101                 transparent:=tempb;
1102
1103                 trainer.ReadBuffer(tempi,sizeof(integer));
1104                 tag:=tempi;
1105
1106                 trainer.ReadBuffer(temp,4);
1107                 if temp>0 then
1108                 begin
1109                   picture.Bitmap.LoadFromStream(trainer);
1110                   extension:='.bmp';
1111                   imagedata:=tmemorystream.Create;
1112                   picture.Bitmap.SaveToStream(imagedata);
1113
1114                 end;
1115
1116                 //command
1117                 trainer.ReadBuffer(temp,4);
1118                 getmem(x,temp+1);
1119                 trainer.ReadBuffer(x^,temp);
1120                 x[temp]:=#0;
1121                 command:=x;
1122                 freemem(x);
1123
1124                 parent:=frmTrainerDesigner;
1125                 onmousedown:=frmTrainerDesigner.MouseDown;
1126                 onmousemove:=frmTrainerDesigner.MouseMove;
1127                 onmouseup:=frmTrainerDesigner.MouseUp;
1128               end;
1129             end;
1130
1131          4: begin
1132               with tlabel2.Create(frmTrainerDesigner) do
1133               begin
1134                 trainer.ReadBuffer(temp,sizeof(integer));
1135                 left:=temp;
1136                 trainer.ReadBuffer(temp,sizeof(integer));
1137                 top:=temp;
1138                 trainer.ReadBuffer(temp,sizeof(integer));
1139                 width:=temp;
1140                 trainer.ReadBuffer(temp,sizeof(integer));
1141                 height:=temp;
1142
1143                 //caption
1144                 trainer.ReadBuffer(temp,4);
1145                 getmem(x,temp+1);
1146                 trainer.ReadBuffer(x^,temp);
1147                 x[temp]:=#0;
1148                 caption:=x;
1149                 freemem(x);
1150
1151                 //wordwrap
1152                 trainer.ReadBuffer(tempb,sizeof(boolean));
1153                 wordwrap:=tempb;
1154
1155                 //color
1156                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1157                 font.Color:=tempc;
1158
1159                 //command
1160                 trainer.ReadBuffer(temp,4);
1161                 getmem(x,temp+1);
1162                 trainer.ReadBuffer(x^,temp);
1163                 x[temp]:=#0;
1164                 command:=x;
1165                 freemem(x);
1166
1167                 //cursor
1168                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
1169                 cursor:=tempcursor;
1170
1171                 //tag
1172                 trainer.ReadBuffer(tempi,sizeof(integer));
1173                 tag:=tempi;
1174
1175                 trainer.ReadBuffer(tempb,sizeof(tempb));
1176                 if tempb then
1177                   Font.Style:=[fsUnderline]
1178                 else
1179                   Font.Style:=[];
1180
1181                   
1182                 parent:=frmTrainerDesigner;
1183                 onmousedown:=frmTrainerDesigner.MouseDown;
1184                 onmousemove:=frmTrainerDesigner.MouseMove;
1185                 onmouseup:=frmTrainerDesigner.MouseUp;
1186               end;
1187             end;
1188          $ffffffff: break;
1189          else raise exception.Create(strunknowncomponent+Inttostr(temp));
1190        end;
1191      end;
1192    end;
1193  end;
1194
1195  //fill in the list of cheats
1196  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
1197  begin
1198    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
1199    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
1200  end;
1201
1202  frmMemoryTrainerPreview.UpdateScreen;
1203  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
1204end;
1205
1206
1207procedure LoadTrainer6(trainer:TFilestream);
1208var temp: dword;
1209    tempb: boolean;
1210    tempc: tcolor;
1211    tempi: integer;
1212    tempbc: tbevelcut;
1213    tempbk: tbevelkind;
1214    tempcursor: tcursor;
1215    i,j,k:integer;
1216    x: pchar;
1217
1218    image: pointer;
1219    laststate: word;
1220    lastshiftstate:word;
1221
1222    keycombo: tkeycombo;
1223//    trainerdata1: array of TTrainerData1;
1224begin
1225  with frmMemoryModifier do
1226  begin
1227    //size of trainerdata
1228    trainer.ReadBuffer(temp,4);
1229    setlength(frmMemoryModifier.trainerdata,temp);
1230
1231    for i:=0 to length(trainerdata)-1 do
1232    begin
1233      //description
1234      trainer.ReadBuffer(temp,4);
1235      getmem(x,temp+1);
1236      trainer.ReadBuffer(x^,temp);
1237      x[temp]:=#0;
1238      trainerdata[i].description:=x;
1239      freemem(x);
1240
1241      //hotkeytext
1242      trainer.ReadBuffer(temp,4);
1243      getmem(x,temp+1);
1244      trainer.ReadBuffer(x^,temp);
1245      x[temp]:=#0;
1246      trainerdata[i].hotkeytext:=x;
1247      freemem(x);
1248
1249      //read and convert
1250      trainer.ReadBuffer(laststate,sizeof(laststate));
1251      trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
1252      ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, trainerdata[i].hotkey);
1253
1254
1255
1256      trainer.ReadBuffer(temp,4);
1257      setlength(trainerdata[i].codeentrys,temp);
1258
1259      //opcodes of this cheat
1260      for j:=0 to length(trainerdata[i].codeentrys)-1 do
1261      begin
1262        //address
1263        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
1264
1265        //modulename
1266        trainer.ReadBuffer(temp,4);
1267        getmem(x,temp+1);
1268        trainer.ReadBuffer(x^,temp);
1269        x[temp]:=#0;
1270        trainerdata[i].codeentrys[j].modulename:=x;
1271        freemem(x);
1272
1273        //module offset
1274        trainer.ReadBuffer(trainerdata[i].codeentrys[j].moduleoffset,4);
1275
1276        //original opcode
1277        trainer.ReadBuffer(temp,4);
1278        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
1279        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
1280      end;
1281
1282      //address entrys
1283      trainer.ReadBuffer(temp,4);
1284      setlength(trainerdata[i].addressentrys,temp);
1285      for j:=0 to length(trainerdata[i].addressentrys)-1 do
1286      begin
1287        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
1288
1289        //interpretable address
1290        trainer.ReadBuffer(temp,4);
1291        getmem(x,temp+1);
1292        trainer.ReadBuffer(x^,temp);
1293        x[temp]:=#0;
1294        trainerdata[i].addressentrys[j].interpretableaddress:=x;
1295        freemem(x);
1296
1297        trainer.ReadBuffer(trainerdata[i].addressentrys[j].ispointer,sizeof(trainerdata[i].addressentrys[j].ispointer));
1298
1299        trainer.ReadBuffer(tempi,4);
1300        setlength(trainerdata[i].addressentrys[j].pointers,tempi);
1301
1302        for k:=0 to tempi-1 do
1303        begin
1304          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].address,sizeof(trainerdata[i].addressentrys[j].pointers[k].address));
1305
1306          //interpretable address
1307          trainer.ReadBuffer(temp,4);
1308          getmem(x,temp+1);
1309          trainer.ReadBuffer(x^,temp);
1310          x[temp]:=#0;
1311          trainerdata[i].addressentrys[j].pointers[k].interpretableaddress:=x;
1312          freemem(x);
1313
1314          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].offset,sizeof(trainerdata[i].addressentrys[j].pointers[k].offset));
1315        end;
1316
1317
1318        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
1319        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
1320        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
1321        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
1322        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
1323        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
1324
1325        trainer.ReadBuffer(temp,4);
1326        getmem(x,temp+1);
1327        trainer.ReadBuffer(x^,temp);
1328        x[temp]:=#0;
1329        trainerdata[i].addressentrys[j].value:=x;
1330        freemem(x);
1331
1332
1333       // trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
1334        if trainerdata[i].addressentrys[j].userinput then
1335        begin
1336          trainerdata[i].hasedit:=true;
1337          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
1338        end;
1339
1340        //interpretable address
1341        trainer.ReadBuffer(temp,4);
1342        getmem(x,temp+1);
1343        trainer.ReadBuffer(x^,temp);
1344        x[temp]:=#0;
1345        trainerdata[i].addressentrys[j].autoassemblescript:=x;
1346        freemem(x);
1347      end;
1348    end;
1349
1350    //title
1351    trainer.ReadBuffer(temp,4);
1352    getmem(x,temp+1);
1353    trainer.ReadBuffer(x^,temp);
1354    x[temp]:=#0;
1355    edittitle.Text:=x;
1356    freemem(x);
1357
1358    //launch filename
1359    trainer.ReadBuffer(temp,4);
1360    getmem(x,temp+1);
1361    trainer.ReadBuffer(x^,temp);
1362    x[temp]:=#0;
1363    edit2.Text:=x;
1364    freemem(x);
1365
1366    //autolaunch
1367    trainer.ReadBuffer(tempb,sizeof(tempb));
1368    checkbox2.Checked:=tempb;
1369
1370    //popup on keypress
1371    trainer.ReadBuffer(tempb,sizeof(tempb));
1372    checkbox1.Checked:=tempb;
1373
1374    //process name
1375    trainer.ReadBuffer(temp,4);
1376    getmem(x,temp+1);
1377    trainer.ReadBuffer(x^,temp);
1378    x[temp]:=#0;
1379    combobox1.Text:=x;
1380    freemem(x);
1381
1382    //hotkeytext
1383    trainer.ReadBuffer(temp,4);
1384    getmem(x,temp+1);
1385    trainer.ReadBuffer(x^,temp);
1386    x[temp]:=#0;
1387    edithotkey.Text:=x;
1388    freemem(x);
1389
1390    //hotkey+shiftstate
1391    trainer.ReadBuffer(laststate,sizeof(laststate));
1392    trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
1393    ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, popuphotkey);
1394   
1395
1396    //abouttext
1397    trainer.ReadBuffer(temp,4);
1398    getmem(x,temp+1);
1399    trainer.ReadBuffer(x^,temp);
1400    x[temp]:=#0;
1401    memo1.Text:=x;
1402    freemem(x);
1403
1404    //freeze interval
1405    trainer.ReadBuffer(tempi,sizeof(tempi));
1406    editFreezeInterval.text:=inttostr(tempi);
1407
1408    trainer.ReadBuffer(temp,4);
1409    if temp=$666 then
1410    begin
1411      //default
1412      //leftside image
1413      trainer.ReadBuffer(temp,4);  //size of the image
1414      if temp>0 then
1415      begin
1416        //getmem(image,temp);
1417        //trainer.ReadBuffer(image^,temp);
1418        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
1419         leftimageext:='.bmp';
1420         if leftimage<>nil then
1421           leftimage.free;
1422         leftimage:=tmemorystream.Create;
1423         frmMemorytrainerpreview.Image1.Picture.Bitmap.SaveToStream(leftimage);
1424
1425      end;
1426
1427      //windowwidth
1428      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
1429      frmMemorytrainerpreview.Width:=temp;
1430
1431      //windowheight
1432      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
1433      frmMemorytrainerpreview.height:=temp;
1434
1435      //leftsidewidth
1436      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
1437      frmMemorytrainerpreview.Panel1.Width:=temp;
1438
1439      //leftsideheight
1440      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
1441      frmMemorytrainerpreview.Panel1.height:=temp;
1442    end
1443    else
1444    begin
1445      //user defined
1446      frmMemoryModifier.dontshowdefault:=true;       //obsolete
1447      frmMemoryModifier.Button7.Click;
1448
1449      //windowwidth
1450      trainer.readbuffer(temp,4);
1451      frmTrainerDesigner.Width:=temp;
1452
1453      //windowheight
1454      trainer.readbuffer(temp,4);
1455      frmTrainerDesigner.height:=temp;
1456
1457
1458      while true do
1459      begin
1460        trainer.ReadBuffer(temp,4);
1461        case temp of
1462          0: begin
1463               //tbutton
1464               with tbutton2.create(frmTrainerDesigner) do
1465               begin
1466                 trainer.ReadBuffer(temp,sizeof(integer));
1467                 left:=temp;
1468                 trainer.ReadBuffer(temp,sizeof(integer));
1469                 top:=temp;
1470                 trainer.ReadBuffer(temp,sizeof(integer));
1471                 width:=temp;
1472                 trainer.ReadBuffer(temp,sizeof(integer));
1473                 height:=temp;
1474
1475                 //caption
1476                 trainer.ReadBuffer(temp,4);
1477                 getmem(x,temp+1);
1478                 trainer.ReadBuffer(x^,temp);
1479                 x[temp]:=#0;
1480                 caption:=x;
1481                 freemem(x);
1482
1483                 //wordwrap
1484                 trainer.ReadBuffer(tempb,sizeof(boolean));
1485                 wordwrap:=tempb;
1486
1487                 //onclick
1488                 trainer.ReadBuffer(temp,sizeof(tag));
1489                 tag:=temp;
1490                 parent:=frmTrainerDesigner;
1491
1492                 //command
1493                 trainer.ReadBuffer(temp,4);
1494                 getmem(x,temp+1);
1495                 trainer.ReadBuffer(x^,temp);
1496                 x[temp]:=#0;
1497                 command:=x;
1498                 freemem(x);
1499
1500                 onmousedown:=frmTrainerDesigner.MouseDown;
1501                 onmousemove:=frmTrainerDesigner.MouseMove;
1502                 onmouseup:=frmTrainerDesigner.MouseUp;
1503               end;
1504             end;
1505
1506          1: begin
1507               //cheatlist
1508               with tcheatlist.create(frmTrainerDesigner) do
1509               begin
1510                 trainer.ReadBuffer(temp,sizeof(integer));
1511                 left:=temp;
1512                 trainer.ReadBuffer(temp,sizeof(integer));
1513                 top:=temp;
1514                 trainer.ReadBuffer(temp,sizeof(integer));
1515                 width:=temp;
1516                 trainer.ReadBuffer(temp,sizeof(integer));
1517                 height:=temp;
1518
1519                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1520                 activationcolor:=tempc;
1521                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1522                 color:=tempc;
1523                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1524                 textcolor:=tempc;
1525
1526                 trainer.ReadBuffer(tempi,sizeof(integer));
1527                 hotkeyleft:=tempi;
1528                 trainer.ReadBuffer(tempi,sizeof(integer));
1529                 descriptionleft:=tempi;
1530                 trainer.ReadBuffer(tempi,sizeof(integer));
1531                 editleft:=tempi;
1532                 trainer.ReadBuffer(tempi,sizeof(integer));
1533                 editwidth:=tempi;
1534
1535                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
1536                 bevelinner:=tempbc;
1537                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
1538                 bevelouter:=tempbc;
1539                 trainer.ReadBuffer(tempi,sizeof(integer));
1540                 bevelwidth:=tempi;
1541                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
1542                 bevelkind:=tempbk;
1543
1544                 trainer.ReadBuffer(tempb,sizeof(boolean));
1545                 hascheckbox:=tempb;
1546                 trainer.ReadBuffer(tempb,sizeof(boolean));
1547                 showhotkeys:=tempb;
1548
1549                 parent:=frmTrainerDesigner;
1550                 onmousedown:=frmTrainerDesigner.MouseDown;
1551                 onmousemove:=frmTrainerDesigner.MouseMove;
1552                 onmouseup:=frmTrainerDesigner.MouseUp;
1553               end;
1554             end;
1555
1556          2: begin
1557               //tcheat
1558               with tcheat.create(frmTrainerDesigner) do
1559               begin
1560                 trainer.ReadBuffer(temp,sizeof(integer));
1561                 left:=temp;
1562                 trainer.ReadBuffer(temp,sizeof(integer));
1563                 top:=temp;
1564                 trainer.ReadBuffer(temp,sizeof(integer));
1565                 width:=temp;
1566                 trainer.ReadBuffer(temp,sizeof(integer));
1567                 height:=temp;
1568
1569                 trainer.ReadBuffer(cheatnr,sizeof(integer));
1570                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1571                 activationcolor:=tempc;
1572                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1573                 color:=tempc;
1574                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1575                 textcolor:=tempc;
1576
1577                 trainer.ReadBuffer(tempi,sizeof(integer));
1578                 hotkeyleft:=tempi;
1579                 trainer.ReadBuffer(tempi,sizeof(integer));
1580                 descriptionleft:=tempi;
1581                 trainer.ReadBuffer(tempi,sizeof(integer));
1582                 editleft:=tempi;
1583                 trainer.ReadBuffer(tempi,sizeof(integer));
1584                 editwidth:=tempi;
1585
1586                 trainer.ReadBuffer(tempb,sizeof(boolean));
1587                 hascheckbox:=tempb;
1588                 trainer.ReadBuffer(tempb,sizeof(boolean));
1589                 showhotkey:=tempb;
1590
1591                 parent:=frmTrainerDesigner;
1592                 onmousedown:=frmTrainerDesigner.MouseDown;
1593                 onmousemove:=frmTrainerDesigner.MouseMove;
1594                 onmouseup:=frmTrainerDesigner.MouseUp;
1595               end;
1596             end;
1597
1598          3: begin
1599               //timage
1600               with timage2.create(frmTrainerDesigner) do
1601               begin
1602                 trainer.ReadBuffer(temp,sizeof(integer));
1603                 left:=temp;
1604                 trainer.ReadBuffer(temp,sizeof(integer));
1605                 top:=temp;
1606                 trainer.ReadBuffer(temp,sizeof(integer));
1607                 width:=temp;
1608                 trainer.ReadBuffer(temp,sizeof(integer));
1609                 height:=temp;
1610
1611                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
1612                 cursor:=tempcursor;
1613
1614                 trainer.ReadBuffer(tempb,sizeof(tempb));
1615                 stretch:=tempb;
1616                 trainer.ReadBuffer(tempb,sizeof(tempb));
1617                 transparent:=tempb;
1618
1619                 trainer.ReadBuffer(tempi,sizeof(integer));
1620                 tag:=tempi;
1621
1622                 trainer.ReadBuffer(temp,4);
1623                 if temp>0 then
1624                 begin
1625                   picture.Bitmap.LoadFromStream(trainer);
1626                   extension:='.bmp';
1627                   imagedata:=tmemorystream.Create;
1628                   picture.Bitmap.SaveToStream(leftimage);
1629                 end;
1630
1631                 //command
1632                 trainer.ReadBuffer(temp,4);
1633                 getmem(x,temp+1);
1634                 trainer.ReadBuffer(x^,temp);
1635                 x[temp]:=#0;
1636                 command:=x;
1637                 freemem(x);
1638
1639                 parent:=frmTrainerDesigner;
1640                 onmousedown:=frmTrainerDesigner.MouseDown;
1641                 onmousemove:=frmTrainerDesigner.MouseMove;
1642                 onmouseup:=frmTrainerDesigner.MouseUp;
1643               end;
1644             end;
1645
1646          4: begin
1647               with tlabel2.Create(frmTrainerDesigner) do
1648               begin
1649                 trainer.ReadBuffer(temp,sizeof(integer));
1650                 left:=temp;
1651                 trainer.ReadBuffer(temp,sizeof(integer));
1652                 top:=temp;
1653                 trainer.ReadBuffer(temp,sizeof(integer));
1654                 width:=temp;
1655                 trainer.ReadBuffer(temp,sizeof(integer));
1656                 height:=temp;
1657
1658                 //caption
1659                 trainer.ReadBuffer(temp,4);
1660                 getmem(x,temp+1);
1661                 trainer.ReadBuffer(x^,temp);
1662                 x[temp]:=#0;
1663                 caption:=x;
1664                 freemem(x);
1665
1666                 //wordwrap
1667                 trainer.ReadBuffer(tempb,sizeof(boolean));
1668                 wordwrap:=tempb;
1669
1670                 //color
1671                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1672                 font.Color:=tempc;
1673
1674                 //command
1675                 trainer.ReadBuffer(temp,4);
1676                 getmem(x,temp+1);
1677                 trainer.ReadBuffer(x^,temp);
1678                 x[temp]:=#0;
1679                 command:=x;
1680                 freemem(x);
1681
1682                 //cursor
1683                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
1684                 cursor:=tempcursor;
1685
1686                 //tag
1687                 trainer.ReadBuffer(tempi,sizeof(integer));
1688                 tag:=tempi;
1689
1690                 trainer.ReadBuffer(tempb,sizeof(tempb));
1691                 if tempb then
1692                   Font.Style:=[fsUnderline]
1693                 else
1694                   Font.Style:=[];
1695
1696                   
1697                 parent:=frmTrainerDesigner;
1698                 onmousedown:=frmTrainerDesigner.MouseDown;
1699                 onmousemove:=frmTrainerDesigner.MouseMove;
1700                 onmouseup:=frmTrainerDesigner.MouseUp;
1701               end;
1702             end;
1703          $ffffffff: break;
1704          else raise exception.Create(strunknowncomponent+Inttostr(temp));
1705        end;
1706      end;
1707    end;
1708  end;
1709
1710  //fill in the list of cheats
1711  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
1712  begin
1713    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
1714    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
1715  end;
1716
1717  frmMemoryTrainerPreview.UpdateScreen;
1718  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
1719end;
1720
1721
1722procedure LoadTrainer5(trainer:TFilestream);
1723var temp: dword;
1724    tempb: boolean;
1725    tempc: tcolor;
1726    tempi: integer;
1727    tempbc: tbevelcut;
1728    tempbk: tbevelkind;
1729    tempcursor: tcursor;
1730    i,j,k:integer;
1731    x: pchar;
1732
1733    image: pointer;
1734    laststate: word;
1735    lastshiftstate: word;
1736//    trainerdata1: array of TTrainerData1;
1737begin
1738  with frmMemoryModifier do
1739  begin
1740    //size of trainerdata
1741    trainer.ReadBuffer(temp,4);
1742    setlength(frmMemoryModifier.trainerdata,temp);
1743
1744    for i:=0 to length(trainerdata)-1 do
1745    begin
1746      //description
1747      trainer.ReadBuffer(temp,4);
1748      getmem(x,temp+1);
1749      trainer.ReadBuffer(x^,temp);
1750      x[temp]:=#0;
1751      trainerdata[i].description:=x;
1752      freemem(x);
1753
1754      //hotkeytext
1755      trainer.ReadBuffer(temp,4);
1756      getmem(x,temp+1);
1757      trainer.ReadBuffer(x^,temp);
1758      x[temp]:=#0;
1759      trainerdata[i].hotkeytext:=x;
1760      freemem(x);
1761
1762      trainer.ReadBuffer(laststate,2);
1763      trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
1764      ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, trainerdata[i].hotkey);
1765
1766
1767      trainer.ReadBuffer(temp,4);
1768      setlength(trainerdata[i].codeentrys,temp);
1769
1770      //opcodes of this cheat
1771      for j:=0 to length(trainerdata[i].codeentrys)-1 do
1772      begin
1773        //address
1774        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
1775
1776        //original opcode
1777        trainer.ReadBuffer(temp,4);
1778        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
1779        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
1780      end;
1781
1782      //address entrys
1783      trainer.ReadBuffer(temp,4);
1784      setlength(trainerdata[i].addressentrys,temp);
1785      for j:=0 to length(trainerdata[i].addressentrys)-1 do
1786      begin
1787        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
1788        trainer.ReadBuffer(trainerdata[i].addressentrys[j].ispointer,sizeof(trainerdata[i].addressentrys[j].ispointer));
1789
1790        trainer.ReadBuffer(tempi,4);
1791        setlength(trainerdata[i].addressentrys[j].pointers,tempi);
1792
1793        for k:=0 to tempi-1 do
1794        begin
1795          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].address,sizeof(trainerdata[i].addressentrys[j].pointers[k].address));
1796          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].offset,sizeof(trainerdata[i].addressentrys[j].pointers[k].offset));
1797        end;
1798
1799
1800        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
1801        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
1802        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
1803        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
1804        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
1805        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
1806
1807        trainer.ReadBuffer(temp,4);
1808        getmem(x,temp+1);
1809        trainer.ReadBuffer(x^,temp);
1810        x[temp]:=#0;
1811        trainerdata[i].addressentrys[j].value:=x;
1812        freemem(x);
1813
1814
1815       // trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
1816        if trainerdata[i].addressentrys[j].userinput then
1817        begin
1818          trainerdata[i].hasedit:=true;
1819          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
1820        end;
1821
1822      end;
1823    end;
1824
1825    //title
1826    trainer.ReadBuffer(temp,4);
1827    getmem(x,temp+1);
1828    trainer.ReadBuffer(x^,temp);
1829    x[temp]:=#0;
1830    edittitle.Text:=x;
1831    freemem(x);
1832
1833    //launch filename
1834    trainer.ReadBuffer(temp,4);
1835    getmem(x,temp+1);
1836    trainer.ReadBuffer(x^,temp);
1837    x[temp]:=#0;
1838    edit2.Text:=x;
1839    freemem(x);
1840
1841    //autolaunch
1842    trainer.ReadBuffer(tempb,sizeof(tempb));
1843    checkbox2.Checked:=tempb;
1844
1845    //popup on keypress
1846    trainer.ReadBuffer(tempb,sizeof(tempb));
1847    checkbox1.Checked:=tempb;
1848
1849    //process name
1850    trainer.ReadBuffer(temp,4);
1851    getmem(x,temp+1);
1852    trainer.ReadBuffer(x^,temp);
1853    x[temp]:=#0;
1854    combobox1.Text:=x;
1855    freemem(x);
1856
1857    //hotkeytext
1858    trainer.ReadBuffer(temp,4);
1859    getmem(x,temp+1);
1860    trainer.ReadBuffer(x^,temp);
1861    x[temp]:=#0;
1862    edithotkey.Text:=x;
1863    freemem(x);
1864
1865    //hotkey+shiftstate
1866    trainer.ReadBuffer(laststate,2);
1867    trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
1868    ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, popuphotkey);
1869
1870
1871    //abouttext
1872    trainer.ReadBuffer(temp,4);
1873    getmem(x,temp+1);
1874    trainer.ReadBuffer(x^,temp);
1875    x[temp]:=#0;
1876    memo1.Text:=x;
1877    freemem(x);
1878
1879    //freeze interval
1880    trainer.ReadBuffer(tempi,sizeof(tempi));
1881    editFreezeInterval.text:=inttostr(tempi);
1882
1883    trainer.ReadBuffer(temp,4);
1884    if temp=$666 then
1885    begin
1886      //default
1887      //leftside image
1888      trainer.ReadBuffer(temp,4);  //size of the image
1889      if temp>0 then
1890      begin
1891        //getmem(image,temp);
1892        //trainer.ReadBuffer(image^,temp);
1893        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
1894      end;
1895
1896      //windowwidth
1897      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
1898      frmMemorytrainerpreview.Width:=temp;
1899
1900      //windowheight
1901      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
1902      frmMemorytrainerpreview.height:=temp;
1903
1904      //leftsidewidth
1905      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
1906      frmMemorytrainerpreview.Panel1.Width:=temp;
1907
1908      //leftsideheight
1909      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
1910      frmMemorytrainerpreview.Panel1.height:=temp;
1911    end
1912    else
1913    begin
1914      //user defined
1915      frmMemoryModifier.dontshowdefault:=true;       //obsolete
1916      frmMemoryModifier.Button7.Click;
1917
1918      //windowwidth
1919      trainer.readbuffer(temp,4);
1920      frmTrainerDesigner.Width:=temp;
1921
1922      //windowheight
1923      trainer.readbuffer(temp,4);
1924      frmTrainerDesigner.height:=temp;
1925
1926
1927      while true do
1928      begin
1929        trainer.ReadBuffer(temp,4);
1930        case temp of
1931          0: begin
1932               //tbutton
1933               with tbutton2.create(frmTrainerDesigner) do
1934               begin
1935                 trainer.ReadBuffer(temp,sizeof(integer));
1936                 left:=temp;
1937                 trainer.ReadBuffer(temp,sizeof(integer));
1938                 top:=temp;
1939                 trainer.ReadBuffer(temp,sizeof(integer));
1940                 width:=temp;
1941                 trainer.ReadBuffer(temp,sizeof(integer));
1942                 height:=temp;
1943
1944                 //caption
1945                 trainer.ReadBuffer(temp,4);
1946                 getmem(x,temp+1);
1947                 trainer.ReadBuffer(x^,temp);
1948                 x[temp]:=#0;
1949                 caption:=x;
1950                 freemem(x);
1951
1952                 //wordwrap
1953                 trainer.ReadBuffer(tempb,sizeof(boolean));
1954                 wordwrap:=tempb;
1955
1956                 //onclick
1957                 trainer.ReadBuffer(temp,sizeof(tag));
1958                 tag:=temp;
1959                 parent:=frmTrainerDesigner;
1960
1961                 //command
1962                 trainer.ReadBuffer(temp,4);
1963                 getmem(x,temp+1);
1964                 trainer.ReadBuffer(x^,temp);
1965                 x[temp]:=#0;
1966                 command:=x;
1967                 freemem(x);
1968
1969                 onmousedown:=frmTrainerDesigner.MouseDown;
1970                 onmousemove:=frmTrainerDesigner.MouseMove;
1971                 onmouseup:=frmTrainerDesigner.MouseUp;
1972               end;
1973             end;
1974
1975          1: begin
1976               //cheatlist
1977               with tcheatlist.create(frmTrainerDesigner) do
1978               begin
1979                 trainer.ReadBuffer(temp,sizeof(integer));
1980                 left:=temp;
1981                 trainer.ReadBuffer(temp,sizeof(integer));
1982                 top:=temp;
1983                 trainer.ReadBuffer(temp,sizeof(integer));
1984                 width:=temp;
1985                 trainer.ReadBuffer(temp,sizeof(integer));
1986                 height:=temp;
1987
1988                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1989                 activationcolor:=tempc;
1990                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1991                 color:=tempc;
1992                 trainer.ReadBuffer(tempc,sizeof(tcolor));
1993                 textcolor:=tempc;
1994
1995                 trainer.ReadBuffer(tempi,sizeof(integer));
1996                 hotkeyleft:=tempi;
1997                 trainer.ReadBuffer(tempi,sizeof(integer));
1998                 descriptionleft:=tempi;
1999                 trainer.ReadBuffer(tempi,sizeof(integer));
2000                 editleft:=tempi;
2001                 trainer.ReadBuffer(tempi,sizeof(integer));
2002                 editwidth:=tempi;
2003
2004                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
2005                 bevelinner:=tempbc;
2006                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
2007                 bevelouter:=tempbc;
2008                 trainer.ReadBuffer(tempi,sizeof(integer));
2009                 bevelwidth:=tempi;
2010                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
2011                 bevelkind:=tempbk;
2012                 parent:=frmTrainerDesigner;
2013                 onmousedown:=frmTrainerDesigner.MouseDown;
2014                 onmousemove:=frmTrainerDesigner.MouseMove;
2015                 onmouseup:=frmTrainerDesigner.MouseUp;
2016               end;
2017             end;
2018
2019          2: begin
2020               //tcheat
2021               with tcheat.create(frmTrainerDesigner) do
2022               begin
2023                 trainer.ReadBuffer(temp,sizeof(integer));
2024                 left:=temp;
2025                 trainer.ReadBuffer(temp,sizeof(integer));
2026                 top:=temp;
2027                 trainer.ReadBuffer(temp,sizeof(integer));
2028                 width:=temp;
2029                 trainer.ReadBuffer(temp,sizeof(integer));
2030                 height:=temp;
2031
2032                 trainer.ReadBuffer(cheatnr,sizeof(integer));
2033                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2034                 activationcolor:=tempc;
2035                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2036                 color:=tempc;
2037                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2038                 textcolor:=tempc;
2039
2040                 trainer.ReadBuffer(tempi,sizeof(integer));
2041                 hotkeyleft:=tempi;
2042                 trainer.ReadBuffer(tempi,sizeof(integer));
2043                 descriptionleft:=tempi;
2044                 trainer.ReadBuffer(tempi,sizeof(integer));
2045                 editleft:=tempi;
2046                 trainer.ReadBuffer(tempi,sizeof(integer));
2047                 editwidth:=tempi;
2048                 parent:=frmTrainerDesigner;
2049                 onmousedown:=frmTrainerDesigner.MouseDown;
2050                 onmousemove:=frmTrainerDesigner.MouseMove;
2051                 onmouseup:=frmTrainerDesigner.MouseUp;
2052               end;
2053             end;
2054
2055          3: begin
2056               //timage
2057               with timage2.create(frmTrainerDesigner) do
2058               begin
2059                 trainer.ReadBuffer(temp,sizeof(integer));
2060                 left:=temp;
2061                 trainer.ReadBuffer(temp,sizeof(integer));
2062                 top:=temp;
2063                 trainer.ReadBuffer(temp,sizeof(integer));
2064                 width:=temp;
2065                 trainer.ReadBuffer(temp,sizeof(integer));
2066                 height:=temp;
2067
2068                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
2069                 cursor:=tempcursor;
2070
2071                 trainer.ReadBuffer(tempb,sizeof(tempb));
2072                 stretch:=tempb;
2073                 trainer.ReadBuffer(tempb,sizeof(tempb));
2074                 transparent:=tempb;
2075
2076                 trainer.ReadBuffer(tempi,sizeof(integer));
2077                 tag:=tempi;
2078
2079                 trainer.ReadBuffer(temp,4);
2080                 if temp>0 then
2081                 begin
2082                   picture.Bitmap.LoadFromStream(trainer);
2083                 end;
2084
2085                 //command
2086                 trainer.ReadBuffer(temp,4);
2087                 getmem(x,temp+1);
2088                 trainer.ReadBuffer(x^,temp);
2089                 x[temp]:=#0;
2090                 command:=x;
2091                 freemem(x);
2092
2093                 parent:=frmTrainerDesigner;
2094                 onmousedown:=frmTrainerDesigner.MouseDown;
2095                 onmousemove:=frmTrainerDesigner.MouseMove;
2096                 onmouseup:=frmTrainerDesigner.MouseUp;
2097               end;
2098             end;
2099
2100          4: begin
2101               with tlabel2.Create(frmTrainerDesigner) do
2102               begin
2103                 trainer.ReadBuffer(temp,sizeof(integer));
2104                 left:=temp;
2105                 trainer.ReadBuffer(temp,sizeof(integer));
2106                 top:=temp;
2107                 trainer.ReadBuffer(temp,sizeof(integer));
2108                 width:=temp;
2109                 trainer.ReadBuffer(temp,sizeof(integer));
2110                 height:=temp;
2111
2112                 //caption
2113                 trainer.ReadBuffer(temp,4);
2114                 getmem(x,temp+1);
2115                 trainer.ReadBuffer(x^,temp);
2116                 x[temp]:=#0;
2117                 caption:=x;
2118                 freemem(x);
2119
2120                 //wordwrap
2121                 trainer.ReadBuffer(tempb,sizeof(boolean));
2122                 wordwrap:=tempb;
2123
2124                 //color
2125                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2126                 font.Color:=tempc;
2127
2128                 //command
2129                 trainer.ReadBuffer(temp,4);
2130                 getmem(x,temp+1);
2131                 trainer.ReadBuffer(x^,temp);
2132                 x[temp]:=#0;
2133                 command:=x;
2134                 freemem(x);
2135
2136                 //cursor
2137                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
2138                 cursor:=tempcursor;
2139
2140                 //tag
2141                 trainer.ReadBuffer(tempi,sizeof(integer));
2142                 tag:=tempi;
2143
2144                 trainer.ReadBuffer(tempb,sizeof(tempb));
2145                 if tempb then
2146                   Font.Style:=[fsUnderline]
2147                 else
2148                   Font.Style:=[];
2149
2150                   
2151                 parent:=frmTrainerDesigner;
2152                 onmousedown:=frmTrainerDesigner.MouseDown;
2153                 onmousemove:=frmTrainerDesigner.MouseMove;
2154                 onmouseup:=frmTrainerDesigner.MouseUp;
2155               end;
2156             end;
2157          $ffffffff: break;
2158          else raise exception.Create(strunknowncomponent+Inttostr(temp));
2159        end;
2160      end;
2161    end;
2162  end;
2163
2164  //fill in the list of cheats
2165  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
2166  begin
2167    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
2168    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
2169  end;
2170
2171  frmMemoryTrainerPreview.UpdateScreen;
2172  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
2173end;
2174
2175
2176procedure LoadTrainer4(trainer:TFilestream);
2177var temp: dword;
2178    tempb: boolean;
2179    tempc: tcolor;
2180    tempi: integer;
2181    tempbc: tbevelcut;
2182    tempbk: tbevelkind;
2183    tempcursor: tcursor;
2184    i,j,k:integer;
2185    x: pchar;
2186
2187    image: pointer;
2188    laststate: word;
2189    lastshiftstate: word;     
2190//    trainerdata1: array of TTrainerData1;
2191begin
2192  with frmMemoryModifier do
2193  begin
2194    //size of trainerdata
2195    trainer.ReadBuffer(temp,4);
2196    setlength(frmMemoryModifier.trainerdata,temp);
2197
2198    for i:=0 to length(trainerdata)-1 do
2199    begin
2200      //description
2201      trainer.ReadBuffer(temp,4);
2202      getmem(x,temp+1);
2203      trainer.ReadBuffer(x^,temp);
2204      x[temp]:=#0;
2205      trainerdata[i].description:=x;
2206      freemem(x);
2207
2208      //hotkeytext
2209      trainer.ReadBuffer(temp,4);
2210      getmem(x,temp+1);
2211      trainer.ReadBuffer(x^,temp);
2212      x[temp]:=#0;
2213      trainerdata[i].hotkeytext:=x;
2214      freemem(x);
2215
2216      trainer.ReadBuffer(laststate,2);
2217      trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
2218      ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, trainerdata[i].hotkey);
2219
2220
2221      trainer.ReadBuffer(temp,4);
2222      setlength(trainerdata[i].codeentrys,temp);
2223
2224      //opcodes of this cheat
2225      for j:=0 to length(trainerdata[i].codeentrys)-1 do
2226      begin
2227        //address
2228        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
2229
2230        //original opcode
2231        trainer.ReadBuffer(temp,4);
2232        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
2233        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
2234      end;
2235
2236      //address entrys
2237      trainer.ReadBuffer(temp,4);
2238      setlength(trainerdata[i].addressentrys,temp);
2239      for j:=0 to length(trainerdata[i].addressentrys)-1 do
2240      begin
2241        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
2242        trainer.ReadBuffer(trainerdata[i].addressentrys[j].ispointer,sizeof(trainerdata[i].addressentrys[j].ispointer));
2243
2244        trainer.ReadBuffer(tempi,4);
2245        setlength(trainerdata[i].addressentrys[j].pointers,tempi);
2246
2247        for k:=0 to tempi-1 do
2248        begin
2249          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].address,sizeof(trainerdata[i].addressentrys[j].pointers[k].address));
2250          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].offset,sizeof(trainerdata[i].addressentrys[j].pointers[k].offset));
2251        end;
2252
2253
2254        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
2255        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
2256        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
2257        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
2258        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
2259        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
2260
2261        trainer.ReadBuffer(temp,4);
2262        getmem(x,temp+1);
2263        trainer.ReadBuffer(x^,temp);
2264        x[temp]:=#0;
2265        trainerdata[i].addressentrys[j].value:=x;
2266        freemem(x);
2267
2268
2269       // trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
2270        if trainerdata[i].addressentrys[j].userinput then
2271        begin
2272          trainerdata[i].hasedit:=true;
2273          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
2274        end;
2275
2276      end;
2277    end;
2278
2279    //title
2280    trainer.ReadBuffer(temp,4);
2281    getmem(x,temp+1);
2282    trainer.ReadBuffer(x^,temp);
2283    x[temp]:=#0;
2284    edittitle.Text:=x;
2285    freemem(x);
2286
2287    //launch filename
2288    trainer.ReadBuffer(temp,4);
2289    getmem(x,temp+1);
2290    trainer.ReadBuffer(x^,temp);
2291    x[temp]:=#0;
2292    edit2.Text:=x;
2293    freemem(x);
2294
2295    //autolaunch
2296    trainer.ReadBuffer(tempb,sizeof(tempb));
2297    checkbox2.Checked:=tempb;
2298
2299    //popup on keypress
2300    trainer.ReadBuffer(tempb,sizeof(tempb));
2301    checkbox1.Checked:=tempb;
2302
2303    //process name
2304    trainer.ReadBuffer(temp,4);
2305    getmem(x,temp+1);
2306    trainer.ReadBuffer(x^,temp);
2307    x[temp]:=#0;
2308    combobox1.Text:=x;
2309    freemem(x);
2310
2311    //hotkeytext
2312    trainer.ReadBuffer(temp,4);
2313    getmem(x,temp+1);
2314    trainer.ReadBuffer(x^,temp);
2315    x[temp]:=#0;
2316    edithotkey.Text:=x;
2317    freemem(x);
2318
2319    //hotkey+shiftstate
2320    trainer.ReadBuffer(laststate,2);
2321    trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
2322    ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, popuphotkey);
2323
2324
2325    //abouttext
2326    trainer.ReadBuffer(temp,4);
2327    getmem(x,temp+1);
2328    trainer.ReadBuffer(x^,temp);
2329    x[temp]:=#0;
2330    memo1.Text:=x;
2331    freemem(x);
2332
2333    trainer.ReadBuffer(temp,4);
2334    if temp=$666 then
2335    begin
2336      //default
2337      //leftside image
2338      trainer.ReadBuffer(temp,4);  //size of the image
2339      if temp>0 then
2340      begin
2341        //getmem(image,temp);
2342        //trainer.ReadBuffer(image^,temp);
2343        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
2344      end;
2345
2346      //windowwidth
2347      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
2348      frmMemorytrainerpreview.Width:=temp;
2349
2350      //windowheight
2351      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
2352      frmMemorytrainerpreview.height:=temp;
2353
2354      //leftsidewidth
2355      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
2356      frmMemorytrainerpreview.Panel1.Width:=temp;
2357
2358      //leftsideheight
2359      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
2360      frmMemorytrainerpreview.Panel1.height:=temp;
2361    end
2362    else
2363    begin
2364      //user defined
2365      frmMemoryModifier.dontshowdefault:=true;       //obsolete
2366      frmMemoryModifier.Button7.Click;
2367
2368      //windowwidth
2369      trainer.readbuffer(temp,4);
2370      frmTrainerDesigner.Width:=temp;
2371
2372      //windowheight
2373      trainer.readbuffer(temp,4);
2374      frmTrainerDesigner.height:=temp;
2375
2376
2377      while true do
2378      begin
2379        trainer.ReadBuffer(temp,4);
2380        case temp of
2381          0: begin
2382               //tbutton
2383               with tbutton2.create(frmTrainerDesigner) do
2384               begin
2385                 trainer.ReadBuffer(temp,sizeof(integer));
2386                 left:=temp;
2387                 trainer.ReadBuffer(temp,sizeof(integer));
2388                 top:=temp;
2389                 trainer.ReadBuffer(temp,sizeof(integer));
2390                 width:=temp;
2391                 trainer.ReadBuffer(temp,sizeof(integer));
2392                 height:=temp;
2393
2394                 //caption
2395                 trainer.ReadBuffer(temp,4);
2396                 getmem(x,temp+1);
2397                 trainer.ReadBuffer(x^,temp);
2398                 x[temp]:=#0;
2399                 caption:=x;
2400                 freemem(x);
2401
2402                 //onclick
2403                 trainer.ReadBuffer(temp,sizeof(tag));
2404                 tag:=temp;
2405                 parent:=frmTrainerDesigner;
2406
2407                 //command
2408                 trainer.ReadBuffer(temp,4);
2409                 getmem(x,temp+1);
2410                 trainer.ReadBuffer(x^,temp);
2411                 x[temp]:=#0;
2412                 command:=x;
2413                 freemem(x);
2414
2415                 onmousedown:=frmTrainerDesigner.MouseDown;
2416                 onmousemove:=frmTrainerDesigner.MouseMove;
2417                 onmouseup:=frmTrainerDesigner.MouseUp;
2418               end;
2419             end;
2420
2421          1: begin
2422               //cheatlist
2423               with tcheatlist.create(frmTrainerDesigner) do
2424               begin
2425                 trainer.ReadBuffer(temp,sizeof(integer));
2426                 left:=temp;
2427                 trainer.ReadBuffer(temp,sizeof(integer));
2428                 top:=temp;
2429                 trainer.ReadBuffer(temp,sizeof(integer));
2430                 width:=temp;
2431                 trainer.ReadBuffer(temp,sizeof(integer));
2432                 height:=temp;
2433
2434                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2435                 activationcolor:=tempc;
2436                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2437                 color:=tempc;
2438                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2439                 textcolor:=tempc;
2440
2441                 trainer.ReadBuffer(tempi,sizeof(integer));
2442                 hotkeyleft:=tempi;
2443                 trainer.ReadBuffer(tempi,sizeof(integer));
2444                 descriptionleft:=tempi;
2445                 trainer.ReadBuffer(tempi,sizeof(integer));
2446                 editleft:=tempi;
2447                 trainer.ReadBuffer(tempi,sizeof(integer));
2448                 editwidth:=tempi;
2449
2450                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
2451                 bevelinner:=tempbc;
2452                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
2453                 bevelouter:=tempbc;
2454                 trainer.ReadBuffer(tempi,sizeof(integer));
2455                 bevelwidth:=tempi;
2456                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
2457                 bevelkind:=tempbk;
2458                 parent:=frmTrainerDesigner;
2459                 onmousedown:=frmTrainerDesigner.MouseDown;
2460                 onmousemove:=frmTrainerDesigner.MouseMove;
2461                 onmouseup:=frmTrainerDesigner.MouseUp;
2462               end;
2463             end;
2464
2465          2: begin
2466               //tcheat
2467               with tcheat.create(frmTrainerDesigner) do
2468               begin
2469                 trainer.ReadBuffer(temp,sizeof(integer));
2470                 left:=temp;
2471                 trainer.ReadBuffer(temp,sizeof(integer));
2472                 top:=temp;
2473                 trainer.ReadBuffer(temp,sizeof(integer));
2474                 width:=temp;
2475                 trainer.ReadBuffer(temp,sizeof(integer));
2476                 height:=temp;
2477
2478                 trainer.ReadBuffer(cheatnr,sizeof(integer));
2479                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2480                 activationcolor:=tempc;
2481                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2482                 color:=tempc;
2483                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2484                 textcolor:=tempc;
2485
2486                 trainer.ReadBuffer(tempi,sizeof(integer));
2487                 hotkeyleft:=tempi;
2488                 trainer.ReadBuffer(tempi,sizeof(integer));
2489                 descriptionleft:=tempi;
2490                 trainer.ReadBuffer(tempi,sizeof(integer));
2491                 editleft:=tempi;
2492                 trainer.ReadBuffer(tempi,sizeof(integer));
2493                 editwidth:=tempi;
2494                 parent:=frmTrainerDesigner;
2495                 onmousedown:=frmTrainerDesigner.MouseDown;
2496                 onmousemove:=frmTrainerDesigner.MouseMove;
2497                 onmouseup:=frmTrainerDesigner.MouseUp;
2498               end;
2499             end;
2500
2501          3: begin
2502               //timage
2503               with timage2.create(frmTrainerDesigner) do
2504               begin
2505                 trainer.ReadBuffer(temp,sizeof(integer));
2506                 left:=temp;
2507                 trainer.ReadBuffer(temp,sizeof(integer));
2508                 top:=temp;
2509                 trainer.ReadBuffer(temp,sizeof(integer));
2510                 width:=temp;
2511                 trainer.ReadBuffer(temp,sizeof(integer));
2512                 height:=temp;
2513
2514                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
2515                 cursor:=tempcursor;
2516
2517                 trainer.ReadBuffer(tempb,sizeof(tempb));
2518                 stretch:=tempb;
2519                 trainer.ReadBuffer(tempb,sizeof(tempb));
2520                 transparent:=tempb;
2521
2522                 trainer.ReadBuffer(tempi,sizeof(integer));
2523                 tag:=tempi;
2524
2525                 trainer.ReadBuffer(temp,4);
2526                 if temp>0 then
2527                 begin
2528                   picture.Bitmap.LoadFromStream(trainer);
2529                 end;
2530
2531                 //command
2532                 trainer.ReadBuffer(temp,4);
2533                 getmem(x,temp+1);
2534                 trainer.ReadBuffer(x^,temp);
2535                 x[temp]:=#0;
2536                 command:=x;
2537                 freemem(x);
2538
2539                 parent:=frmTrainerDesigner;
2540                 onmousedown:=frmTrainerDesigner.MouseDown;
2541                 onmousemove:=frmTrainerDesigner.MouseMove;
2542                 onmouseup:=frmTrainerDesigner.MouseUp;
2543               end;
2544             end;
2545
2546          4: begin
2547               with tlabel2.Create(frmTrainerDesigner) do
2548               begin
2549                 trainer.ReadBuffer(temp,sizeof(integer));
2550                 left:=temp;
2551                 trainer.ReadBuffer(temp,sizeof(integer));
2552                 top:=temp;
2553                 trainer.ReadBuffer(temp,sizeof(integer));
2554                 width:=temp;
2555                 trainer.ReadBuffer(temp,sizeof(integer));
2556                 height:=temp;
2557
2558                 //caption
2559                 trainer.ReadBuffer(temp,4);
2560                 getmem(x,temp+1);
2561                 trainer.ReadBuffer(x^,temp);
2562                 x[temp]:=#0;
2563                 caption:=x;
2564                 freemem(x);
2565
2566                 //wordwrap
2567                 trainer.ReadBuffer(tempb,sizeof(boolean));
2568                 wordwrap:=tempb;
2569
2570                 //color
2571                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2572                 font.Color:=tempc;
2573
2574                 //command
2575                 trainer.ReadBuffer(temp,4);
2576                 getmem(x,temp+1);
2577                 trainer.ReadBuffer(x^,temp);
2578                 x[temp]:=#0;
2579                 command:=x;
2580                 freemem(x);
2581
2582                 //cursor
2583                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
2584                 cursor:=tempcursor;
2585
2586                 //tag
2587                 trainer.ReadBuffer(tempi,sizeof(integer));
2588                 tag:=tempi;
2589
2590                 trainer.ReadBuffer(tempb,sizeof(tempb));
2591                 if tempb then
2592                   Font.Style:=[fsUnderline]
2593                 else
2594                   Font.Style:=[];
2595
2596                   
2597                 parent:=frmTrainerDesigner;
2598                 onmousedown:=frmTrainerDesigner.MouseDown;
2599                 onmousemove:=frmTrainerDesigner.MouseMove;
2600                 onmouseup:=frmTrainerDesigner.MouseUp;
2601               end;
2602             end;
2603          $ffffffff: break;
2604          else raise exception.Create(strunknowncomponent+Inttostr(temp));
2605        end;
2606      end;
2607    end;
2608  end;
2609
2610  //fill in the list of cheats
2611  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
2612  begin
2613    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
2614    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
2615  end;
2616
2617  frmMemoryTrainerPreview.UpdateScreen;
2618  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
2619end;
2620
2621procedure LoadTrainer3(trainer:tfilestream);
2622var temp: dword;
2623    tempb: boolean;
2624    tempc: tcolor;
2625    tempi: integer;
2626    tempbc: tbevelcut;
2627    tempbk: tbevelkind;
2628    tempcursor: tcursor;
2629    i,j,k:integer;
2630    x: pchar;
2631
2632    image: pointer;
2633    laststate: word;
2634    lastshiftstate: word;
2635//    trainerdata1: array of TTrainerData1;
2636begin
2637  with frmMemoryModifier do
2638  begin
2639    //size of trainerdata
2640    trainer.ReadBuffer(temp,4);
2641    setlength(frmMemoryModifier.trainerdata,temp);
2642
2643    for i:=0 to length(trainerdata)-1 do
2644    begin
2645      //description
2646      trainer.ReadBuffer(temp,4);
2647      getmem(x,temp+1);
2648      trainer.ReadBuffer(x^,temp);
2649      x[temp]:=#0;
2650      trainerdata[i].description:=x;
2651      freemem(x);
2652
2653      //hotkeytext
2654      trainer.ReadBuffer(temp,4);
2655      getmem(x,temp+1);
2656      trainer.ReadBuffer(x^,temp);
2657      x[temp]:=#0;
2658      trainerdata[i].hotkeytext:=x;
2659      freemem(x);
2660
2661      trainer.ReadBuffer(laststate,2);
2662      trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
2663      ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, trainerdata[i].hotkey);
2664
2665
2666      trainer.ReadBuffer(temp,4);
2667      setlength(trainerdata[i].codeentrys,temp);
2668
2669      //opcodes of this cheat
2670      for j:=0 to length(trainerdata[i].codeentrys)-1 do
2671      begin
2672        //address
2673        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
2674
2675        //original opcode
2676        trainer.ReadBuffer(temp,4);
2677        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
2678        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
2679      end;
2680
2681      //address entrys
2682      trainer.ReadBuffer(temp,4);
2683      setlength(trainerdata[i].addressentrys,temp);
2684      for j:=0 to length(trainerdata[i].addressentrys)-1 do
2685      begin
2686        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
2687        trainer.ReadBuffer(trainerdata[i].addressentrys[j].ispointer,sizeof(trainerdata[i].addressentrys[j].ispointer));
2688
2689        trainer.ReadBuffer(temp,4);
2690        setlength(trainerdata[i].addressentrys[j].pointers,temp);
2691
2692        trainer.WriteBuffer(temp,4);
2693        for k:=0 to temp-1 do
2694        begin
2695          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].address,sizeof(trainerdata[i].addressentrys[j].pointers[k].address));
2696          trainer.readBuffer(trainerdata[i].addressentrys[j].pointers[k].offset,sizeof(trainerdata[i].addressentrys[j].pointers[k].offset));
2697        end;
2698
2699
2700        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
2701        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
2702        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
2703        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
2704        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
2705        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
2706        trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
2707        if trainerdata[i].addressentrys[j].userinput then
2708        begin
2709          trainerdata[i].hasedit:=true;
2710          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
2711        end;
2712
2713      end;
2714    end;
2715
2716    //title
2717    trainer.ReadBuffer(temp,4);
2718    getmem(x,temp+1);
2719    trainer.ReadBuffer(x^,temp);
2720    x[temp]:=#0;
2721    edittitle.Text:=x;
2722    freemem(x);
2723
2724    //launch filename
2725    trainer.ReadBuffer(temp,4);
2726    getmem(x,temp+1);
2727    trainer.ReadBuffer(x^,temp);
2728    x[temp]:=#0;
2729    edit2.Text:=x;
2730    freemem(x);
2731
2732    //autolaunch
2733    trainer.ReadBuffer(tempb,sizeof(tempb));
2734    checkbox2.Checked:=tempb;
2735
2736    //popup on keypress
2737    trainer.ReadBuffer(tempb,sizeof(tempb));
2738    checkbox1.Checked:=tempb;
2739
2740    //process name
2741    trainer.ReadBuffer(temp,4);
2742    getmem(x,temp+1);
2743    trainer.ReadBuffer(x^,temp);
2744    x[temp]:=#0;
2745    combobox1.Text:=x;
2746    freemem(x);
2747
2748    //hotkeytext
2749    trainer.ReadBuffer(temp,4);
2750    getmem(x,temp+1);
2751    trainer.ReadBuffer(x^,temp);
2752    x[temp]:=#0;
2753    edithotkey.Text:=x;
2754    freemem(x);
2755
2756    //hotkey+shiftstate
2757    trainer.ReadBuffer(laststate,2);
2758    trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
2759    ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, popuphotkey);
2760
2761
2762    //abouttext
2763    trainer.ReadBuffer(temp,4);
2764    getmem(x,temp+1);
2765    trainer.ReadBuffer(x^,temp);
2766    x[temp]:=#0;
2767    memo1.Text:=x;
2768    freemem(x);
2769
2770    trainer.ReadBuffer(temp,4);
2771    if temp=$666 then
2772    begin
2773      //default
2774      //leftside image
2775      trainer.ReadBuffer(temp,4);  //size of the image
2776      if temp>0 then
2777      begin
2778        //getmem(image,temp);
2779        //trainer.ReadBuffer(image^,temp);
2780        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
2781      end;
2782
2783      //windowwidth
2784      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
2785      frmMemorytrainerpreview.Width:=temp;
2786
2787      //windowheight
2788      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
2789      frmMemorytrainerpreview.height:=temp;
2790
2791      //leftsidewidth
2792      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
2793      frmMemorytrainerpreview.Panel1.Width:=temp;
2794
2795      //leftsideheight
2796      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
2797      frmMemorytrainerpreview.Panel1.height:=temp;
2798    end
2799    else
2800    begin
2801      //user defined
2802      frmMemoryModifier.dontshowdefault:=true;       //obsolete
2803      frmMemoryModifier.Button7.Click;
2804
2805      //windowwidth
2806      trainer.readbuffer(temp,4);
2807      frmTrainerDesigner.Width:=temp;
2808
2809      //windowheight
2810      trainer.readbuffer(temp,4);
2811      frmTrainerDesigner.height:=temp;
2812
2813
2814      while true do
2815      begin
2816        trainer.ReadBuffer(temp,4);
2817        case temp of
2818          0: begin
2819               //tbutton
2820               with tbutton.create(frmTrainerDesigner) do
2821               begin
2822                 trainer.ReadBuffer(temp,sizeof(integer));
2823                 left:=temp;
2824                 trainer.ReadBuffer(temp,sizeof(integer));
2825                 top:=temp;
2826                 trainer.ReadBuffer(temp,sizeof(integer));
2827                 width:=temp;
2828                 trainer.ReadBuffer(temp,sizeof(integer));
2829                 height:=temp;
2830
2831                 //caption
2832                 trainer.ReadBuffer(temp,4);
2833                 getmem(x,temp+1);
2834                 trainer.ReadBuffer(x^,temp);
2835                 x[temp]:=#0;
2836                 caption:=x;
2837                 freemem(x);
2838
2839                 trainer.ReadBuffer(temp,sizeof(tag));
2840                 tag:=temp;
2841                 parent:=frmTrainerDesigner;
2842
2843                 onmousedown:=frmTrainerDesigner.MouseDown;
2844                 onmousemove:=frmTrainerDesigner.MouseMove;
2845                 onmouseup:=frmTrainerDesigner.MouseUp;
2846               end;
2847             end;
2848
2849          1: begin
2850               //cheatlist
2851               with tcheatlist.create(frmTrainerDesigner) do
2852               begin
2853                 trainer.ReadBuffer(temp,sizeof(integer));
2854                 left:=temp;
2855                 trainer.ReadBuffer(temp,sizeof(integer));
2856                 top:=temp;
2857                 trainer.ReadBuffer(temp,sizeof(integer));
2858                 width:=temp;
2859                 trainer.ReadBuffer(temp,sizeof(integer));
2860                 height:=temp;
2861
2862                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2863                 activationcolor:=tempc;
2864                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2865                 color:=tempc;
2866                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2867                 textcolor:=tempc;
2868
2869                 trainer.ReadBuffer(tempi,sizeof(integer));
2870                 hotkeyleft:=tempi;
2871                 trainer.ReadBuffer(tempi,sizeof(integer));
2872                 descriptionleft:=tempi;
2873                 trainer.ReadBuffer(tempi,sizeof(integer));
2874                 editleft:=tempi;
2875                 trainer.ReadBuffer(tempi,sizeof(integer));
2876                 editwidth:=tempi;
2877
2878                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
2879                 bevelinner:=tempbc;
2880                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
2881                 bevelouter:=tempbc;
2882                 trainer.ReadBuffer(tempi,sizeof(integer));
2883                 bevelwidth:=tempi;
2884                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
2885                 bevelkind:=tempbk;
2886                 parent:=frmTrainerDesigner;
2887                 onmousedown:=frmTrainerDesigner.MouseDown;
2888                 onmousemove:=frmTrainerDesigner.MouseMove;
2889                 onmouseup:=frmTrainerDesigner.MouseUp;
2890               end;
2891             end;
2892
2893          2: begin
2894               //tcheat
2895               with tcheat.create(frmTrainerDesigner) do
2896               begin
2897                 trainer.ReadBuffer(temp,sizeof(integer));
2898                 left:=temp;
2899                 trainer.ReadBuffer(temp,sizeof(integer));
2900                 top:=temp;
2901                 trainer.ReadBuffer(temp,sizeof(integer));
2902                 width:=temp;
2903                 trainer.ReadBuffer(temp,sizeof(integer));
2904                 height:=temp;
2905
2906                 trainer.ReadBuffer(cheatnr,sizeof(integer));
2907                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2908                 activationcolor:=tempc;
2909                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2910                 color:=tempc;
2911                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2912                 textcolor:=tempc;
2913
2914                 trainer.ReadBuffer(tempi,sizeof(integer));
2915                 hotkeyleft:=tempi;
2916                 trainer.ReadBuffer(tempi,sizeof(integer));
2917                 descriptionleft:=tempi;
2918                 trainer.ReadBuffer(tempi,sizeof(integer));
2919                 editleft:=tempi;
2920                 trainer.ReadBuffer(tempi,sizeof(integer));
2921                 editwidth:=tempi;
2922                 parent:=frmTrainerDesigner;
2923                 onmousedown:=frmTrainerDesigner.MouseDown;
2924                 onmousemove:=frmTrainerDesigner.MouseMove;
2925                 onmouseup:=frmTrainerDesigner.MouseUp;
2926               end;
2927             end;
2928
2929          3: begin
2930               //timage
2931               with timage.create(frmTrainerDesigner) do
2932               begin
2933                 trainer.ReadBuffer(temp,sizeof(integer));
2934                 left:=temp;
2935                 trainer.ReadBuffer(temp,sizeof(integer));
2936                 top:=temp;
2937                 trainer.ReadBuffer(temp,sizeof(integer));
2938                 width:=temp;
2939                 trainer.ReadBuffer(temp,sizeof(integer));
2940                 height:=temp;
2941
2942                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
2943                 cursor:=tempcursor;
2944
2945                 trainer.ReadBuffer(tempb,sizeof(tempb));
2946                 stretch:=tempb;
2947                 trainer.ReadBuffer(tempb,sizeof(tempb));
2948                 transparent:=tempb;
2949
2950                 trainer.ReadBuffer(tempi,sizeof(integer));
2951                 tag:=tempi;
2952
2953                 trainer.ReadBuffer(temp,4);
2954                 if temp>0 then
2955                 begin
2956                   picture.Bitmap.LoadFromStream(trainer);
2957                 end;
2958
2959                 parent:=frmTrainerDesigner;
2960                 onmousedown:=frmTrainerDesigner.MouseDown;
2961                 onmousemove:=frmTrainerDesigner.MouseMove;
2962                 onmouseup:=frmTrainerDesigner.MouseUp;
2963               end;
2964             end;
2965
2966          4: begin
2967               with tlabel.Create(frmTrainerDesigner) do
2968               begin
2969                 trainer.ReadBuffer(temp,sizeof(integer));
2970                 left:=temp;
2971                 trainer.ReadBuffer(temp,sizeof(integer));
2972                 top:=temp;
2973                 trainer.ReadBuffer(temp,sizeof(integer));
2974                 width:=temp;
2975                 trainer.ReadBuffer(temp,sizeof(integer));
2976                 height:=temp;
2977
2978                 //caption
2979                 trainer.ReadBuffer(temp,4);
2980                 getmem(x,temp+1);
2981                 trainer.ReadBuffer(x^,temp);
2982                 x[temp]:=#0;
2983                 caption:=x;
2984                 freemem(x);
2985
2986                 trainer.ReadBuffer(tempc,sizeof(tcolor));
2987                 font.Color:=tempc;
2988                 parent:=frmTrainerDesigner;
2989                 onmousedown:=frmTrainerDesigner.MouseDown;
2990                 onmousemove:=frmTrainerDesigner.MouseMove;
2991                 onmouseup:=frmTrainerDesigner.MouseUp;                 
2992               end;
2993             end;
2994          $ffffffff: break;
2995          else raise exception.Create(strunknowncomponent+Inttostr(temp));
2996        end;
2997      end;
2998    end;
2999  end;
3000
3001  //fill in the list of cheats
3002  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
3003  begin
3004    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
3005    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
3006  end;
3007
3008  frmMemoryTrainerPreview.UpdateScreen;
3009  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
3010
3011  //freemem(x);
3012end;
3013
3014procedure LoadTrainer2(trainer:tfilestream);
3015{type TcodeEntry1 = record
3016  address: dword;
3017  originalopcode: array of byte;
3018end;
3019
3020type TAddressEntry1 = record
3021  address: dword;
3022  bit: byte;
3023  memtyp: integer;
3024  frozen: boolean;
3025  setvalue: boolean;
3026  userinput: boolean;
3027  value: string[50];
3028end;
3029
3030type Ttrainerdata1 = record
3031  description: string;
3032  hotkeytext: string;
3033  hotkey: word;
3034  hotshift: word;
3035  hasedit: boolean;
3036  editvalue: string;
3037
3038  codeentrys: array of TCodeEntry;
3039  addressentrys: array of TAddressEntry;
3040end;
3041 }
3042var temp: dword;
3043    tempb: boolean;
3044    tempc: tcolor;
3045    tempi: integer;
3046    tempbc: tbevelcut;
3047    tempbk: tbevelkind;
3048    tempcursor: tcursor;
3049    i,j:integer;
3050    x: pchar;
3051
3052    image: pointer;
3053    laststate: word;
3054    lastshiftstate: word;
3055//    trainerdata1: array of TTrainerData1;
3056begin
3057  with frmMemoryModifier do
3058  begin
3059    //size of trainerdata
3060    trainer.ReadBuffer(temp,4);
3061    setlength(frmMemoryModifier.trainerdata,temp);
3062
3063    for i:=0 to length(trainerdata)-1 do
3064    begin
3065      //description
3066      trainer.ReadBuffer(temp,4);
3067      getmem(x,temp+1);
3068      trainer.ReadBuffer(x^,temp);
3069      x[temp]:=#0;
3070      trainerdata[i].description:=x;
3071      freemem(x);
3072
3073      //hotkeytext
3074      trainer.ReadBuffer(temp,4);
3075      getmem(x,temp+1);
3076      trainer.ReadBuffer(x^,temp);
3077      x[temp]:=#0;
3078      trainerdata[i].hotkeytext:=x;
3079      freemem(x);
3080
3081      trainer.ReadBuffer(laststate,2);
3082      trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
3083      ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, trainerdata[i].hotkey);
3084
3085
3086      trainer.ReadBuffer(temp,4);
3087      setlength(trainerdata[i].codeentrys,temp);
3088
3089      //opcodes of this cheat
3090      for j:=0 to length(trainerdata[i].codeentrys)-1 do
3091      begin
3092        //address
3093        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
3094
3095        //original opcode
3096        trainer.ReadBuffer(temp,4);
3097        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
3098        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
3099      end;
3100
3101      //address entrys
3102      trainer.ReadBuffer(temp,4);
3103      setlength(trainerdata[i].addressentrys,temp);
3104      for j:=0 to length(trainerdata[i].addressentrys)-1 do
3105      begin
3106        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
3107        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
3108        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
3109        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
3110        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozendirection,sizeof(trainerdata[i].addressentrys[j].frozendirection));
3111        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
3112        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
3113        trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
3114        if trainerdata[i].addressentrys[j].userinput then
3115        begin
3116          trainerdata[i].hasedit:=true;
3117          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
3118        end;
3119
3120      end;
3121    end;
3122
3123    //title
3124    trainer.ReadBuffer(temp,4);
3125    getmem(x,temp+1);
3126    trainer.ReadBuffer(x^,temp);
3127    x[temp]:=#0;
3128    edittitle.Text:=x;
3129    freemem(x);
3130
3131    //launch filename
3132    trainer.ReadBuffer(temp,4);
3133    getmem(x,temp+1);
3134    trainer.ReadBuffer(x^,temp);
3135    x[temp]:=#0;
3136    edit2.Text:=x;
3137    freemem(x);
3138
3139    //autolaunch
3140    trainer.ReadBuffer(tempb,sizeof(tempb));
3141    checkbox2.Checked:=tempb;
3142
3143    //popup on keypress
3144    trainer.ReadBuffer(tempb,sizeof(tempb));
3145    checkbox1.Checked:=tempb;
3146
3147    //process name
3148    trainer.ReadBuffer(temp,4);
3149    getmem(x,temp+1);
3150    trainer.ReadBuffer(x^,temp);
3151    x[temp]:=#0;
3152    combobox1.Text:=x;
3153    freemem(x);
3154
3155    //hotkeytext
3156    trainer.ReadBuffer(temp,4);
3157    getmem(x,temp+1);
3158    trainer.ReadBuffer(x^,temp);
3159    x[temp]:=#0;
3160    edithotkey.Text:=x;
3161    freemem(x);
3162
3163    trainer.ReadBuffer(laststate,2);
3164    trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
3165    ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, popuphotkey);
3166
3167
3168    //abouttext
3169    trainer.ReadBuffer(temp,4);
3170    getmem(x,temp+1);
3171    trainer.ReadBuffer(x^,temp);
3172    x[temp]:=#0;
3173    memo1.Text:=x;
3174    freemem(x);
3175
3176    trainer.ReadBuffer(temp,4);
3177    if temp=$666 then
3178    begin
3179      //default
3180      //leftside image
3181      trainer.ReadBuffer(temp,4);  //size of the image
3182      if temp>0 then
3183      begin
3184        //getmem(image,temp);
3185        //trainer.ReadBuffer(image^,temp);
3186        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
3187      end;
3188
3189      //windowwidth
3190      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
3191      frmMemorytrainerpreview.Width:=temp;
3192
3193      //windowheight
3194      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
3195      frmMemorytrainerpreview.height:=temp;
3196
3197      //leftsidewidth
3198      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
3199      frmMemorytrainerpreview.Panel1.Width:=temp;
3200
3201      //leftsideheight
3202      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
3203      frmMemorytrainerpreview.Panel1.height:=temp;
3204    end
3205    else
3206    begin
3207      //user defined
3208      frmMemoryModifier.dontshowdefault:=true;       //obsolete
3209      frmMemoryModifier.Button7.Click;
3210
3211      //windowwidth
3212      trainer.readbuffer(temp,4);
3213      frmTrainerDesigner.Width:=temp;
3214
3215      //windowheight
3216      trainer.readbuffer(temp,4);
3217      frmTrainerDesigner.height:=temp;
3218
3219
3220      while true do
3221      begin
3222        trainer.ReadBuffer(temp,4);
3223        case temp of
3224          0: begin
3225               //tbutton
3226               with tbutton.create(frmTrainerDesigner) do
3227               begin
3228                 trainer.ReadBuffer(temp,sizeof(integer));
3229                 left:=temp;
3230                 trainer.ReadBuffer(temp,sizeof(integer));
3231                 top:=temp;
3232                 trainer.ReadBuffer(temp,sizeof(integer));
3233                 width:=temp;
3234                 trainer.ReadBuffer(temp,sizeof(integer));
3235                 height:=temp;
3236
3237                 //caption
3238                 trainer.ReadBuffer(temp,4);
3239                 getmem(x,temp+1);
3240                 trainer.ReadBuffer(x^,temp);
3241                 x[temp]:=#0;
3242                 caption:=x;
3243                 freemem(x);
3244
3245                 trainer.ReadBuffer(temp,sizeof(tag));
3246                 tag:=temp;
3247                 parent:=frmTrainerDesigner;
3248
3249                 onmousedown:=frmTrainerDesigner.MouseDown;
3250                 onmousemove:=frmTrainerDesigner.MouseMove;
3251                 onmouseup:=frmTrainerDesigner.MouseUp;
3252               end;
3253             end;
3254
3255          1: begin
3256               //cheatlist
3257               with tcheatlist.create(frmTrainerDesigner) do
3258               begin
3259                 trainer.ReadBuffer(temp,sizeof(integer));
3260                 left:=temp;
3261                 trainer.ReadBuffer(temp,sizeof(integer));
3262                 top:=temp;
3263                 trainer.ReadBuffer(temp,sizeof(integer));
3264                 width:=temp;
3265                 trainer.ReadBuffer(temp,sizeof(integer));
3266                 height:=temp;
3267
3268                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3269                 activationcolor:=tempc;
3270                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3271                 color:=tempc;
3272                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3273                 textcolor:=tempc;
3274
3275                 trainer.ReadBuffer(tempi,sizeof(integer));
3276                 hotkeyleft:=tempi;
3277                 trainer.ReadBuffer(tempi,sizeof(integer));
3278                 descriptionleft:=tempi;
3279                 trainer.ReadBuffer(tempi,sizeof(integer));
3280                 editleft:=tempi;
3281                 trainer.ReadBuffer(tempi,sizeof(integer));
3282                 editwidth:=tempi;
3283
3284                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
3285                 bevelinner:=tempbc;
3286                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
3287                 bevelouter:=tempbc;
3288                 trainer.ReadBuffer(tempi,sizeof(integer));
3289                 bevelwidth:=tempi;
3290                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
3291                 bevelkind:=tempbk;
3292                 parent:=frmTrainerDesigner;
3293                 onmousedown:=frmTrainerDesigner.MouseDown;
3294                 onmousemove:=frmTrainerDesigner.MouseMove;
3295                 onmouseup:=frmTrainerDesigner.MouseUp;
3296               end;
3297             end;
3298
3299          2: begin
3300               //tcheat
3301               with tcheat.create(frmTrainerDesigner) do
3302               begin
3303                 trainer.ReadBuffer(temp,sizeof(integer));
3304                 left:=temp;
3305                 trainer.ReadBuffer(temp,sizeof(integer));
3306                 top:=temp;
3307                 trainer.ReadBuffer(temp,sizeof(integer));
3308                 width:=temp;
3309                 trainer.ReadBuffer(temp,sizeof(integer));
3310                 height:=temp;
3311
3312                 trainer.ReadBuffer(cheatnr,sizeof(integer));
3313                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3314                 activationcolor:=tempc;
3315                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3316                 color:=tempc;
3317                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3318                 textcolor:=tempc;
3319
3320                 trainer.ReadBuffer(tempi,sizeof(integer));
3321                 hotkeyleft:=tempi;
3322                 trainer.ReadBuffer(tempi,sizeof(integer));
3323                 descriptionleft:=tempi;
3324                 trainer.ReadBuffer(tempi,sizeof(integer));
3325                 editleft:=tempi;
3326                 trainer.ReadBuffer(tempi,sizeof(integer));
3327                 editwidth:=tempi;
3328                 parent:=frmTrainerDesigner;
3329                 onmousedown:=frmTrainerDesigner.MouseDown;
3330                 onmousemove:=frmTrainerDesigner.MouseMove;
3331                 onmouseup:=frmTrainerDesigner.MouseUp;
3332               end;
3333             end;
3334
3335          3: begin
3336               //timage
3337               with timage.create(frmTrainerDesigner) do
3338               begin
3339                 trainer.ReadBuffer(temp,sizeof(integer));
3340                 left:=temp;
3341                 trainer.ReadBuffer(temp,sizeof(integer));
3342                 top:=temp;
3343                 trainer.ReadBuffer(temp,sizeof(integer));
3344                 width:=temp;
3345                 trainer.ReadBuffer(temp,sizeof(integer));
3346                 height:=temp;
3347
3348                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
3349                 cursor:=tempcursor;
3350
3351                 trainer.ReadBuffer(tempb,sizeof(tempb));
3352                 stretch:=tempb;
3353                 trainer.ReadBuffer(tempb,sizeof(tempb));
3354                 transparent:=tempb;
3355
3356                 trainer.ReadBuffer(tempi,sizeof(integer));
3357                 tag:=tempi;
3358
3359                 trainer.ReadBuffer(temp,4);
3360                 if temp>0 then
3361                 begin
3362                   picture.Bitmap.LoadFromStream(trainer);
3363                 end;
3364
3365                 parent:=frmTrainerDesigner;
3366                 onmousedown:=frmTrainerDesigner.MouseDown;
3367                 onmousemove:=frmTrainerDesigner.MouseMove;
3368                 onmouseup:=frmTrainerDesigner.MouseUp;
3369               end;
3370             end;
3371
3372          4: begin
3373               with tlabel.Create(frmTrainerDesigner) do
3374               begin
3375                 trainer.ReadBuffer(temp,sizeof(integer));
3376                 left:=temp;
3377                 trainer.ReadBuffer(temp,sizeof(integer));
3378                 top:=temp;
3379                 trainer.ReadBuffer(temp,sizeof(integer));
3380                 width:=temp;
3381                 trainer.ReadBuffer(temp,sizeof(integer));
3382                 height:=temp;
3383
3384                 //caption
3385                 trainer.ReadBuffer(temp,4);
3386                 getmem(x,temp+1);
3387                 trainer.ReadBuffer(x^,temp);
3388                 x[temp]:=#0;
3389                 caption:=x;
3390                 freemem(x);
3391
3392                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3393                 font.Color:=tempc;
3394                 parent:=frmTrainerDesigner;
3395                 onmousedown:=frmTrainerDesigner.MouseDown;
3396                 onmousemove:=frmTrainerDesigner.MouseMove;
3397                 onmouseup:=frmTrainerDesigner.MouseUp;                 
3398               end;
3399             end;
3400          $ffffffff: break;
3401          else raise exception.Create(strunknowncomponent+Inttostr(temp));
3402        end;
3403      end;
3404    end;
3405  end;
3406
3407  //fill in the list of cheats
3408  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
3409  begin
3410    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
3411    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
3412  end;
3413
3414  frmMemoryTrainerPreview.UpdateScreen;
3415  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats
3416
3417  //freemem(x);
3418end;
3419
3420
3421procedure LoadTrainer1(trainer:tfilestream);
3422{type TcodeEntry1 = record
3423  address: dword;
3424  originalopcode: array of byte;
3425end;
3426
3427type TAddressEntry1 = record
3428  address: dword;
3429  bit: byte;
3430  memtyp: integer;
3431  frozen: boolean;
3432  setvalue: boolean;
3433  userinput: boolean;
3434  value: string[50];
3435end;
3436
3437type Ttrainerdata1 = record
3438  description: string;
3439  hotkeytext: string;
3440  hotkey: word;
3441  hotshift: word;
3442  hasedit: boolean;
3443  editvalue: string;
3444
3445  codeentrys: array of TCodeEntry;
3446  addressentrys: array of TAddressEntry;
3447end;
3448 }
3449var temp: dword;
3450    tempb: boolean;
3451    tempc: tcolor;
3452    tempi: integer;
3453    tempbc: tbevelcut;
3454    tempbk: tbevelkind;
3455    tempcursor: tcursor;
3456    i,j:integer;
3457    x: pchar;
3458
3459    image: pointer;
3460    laststate: word;
3461    lastshiftstate: word;
3462//    trainerdata1: array of TTrainerData1;
3463begin
3464  with frmMemoryModifier do
3465  begin
3466    //size of trainerdata
3467    trainer.ReadBuffer(temp,4);
3468    setlength(frmMemoryModifier.trainerdata,temp);
3469
3470    for i:=0 to length(trainerdata)-1 do
3471    begin
3472      //description
3473      trainer.ReadBuffer(temp,4);
3474      getmem(x,temp+1);
3475      trainer.ReadBuffer(x^,temp);
3476      x[temp]:=#0;
3477      trainerdata[i].description:=x;
3478      freemem(x);
3479
3480      //hotkeytext
3481      trainer.ReadBuffer(temp,4);
3482      getmem(x,temp+1);
3483      trainer.ReadBuffer(x^,temp);
3484      x[temp]:=#0;
3485      trainerdata[i].hotkeytext:=x;
3486      freemem(x);
3487
3488      trainer.ReadBuffer(laststate,2);
3489      trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
3490      ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, trainerdata[i].hotkey);
3491
3492
3493      trainer.ReadBuffer(temp,4);
3494      setlength(trainerdata[i].codeentrys,temp);
3495
3496      //opcodes of this cheat
3497      for j:=0 to length(trainerdata[i].codeentrys)-1 do
3498      begin
3499        //address
3500        trainer.ReadBuffer(trainerdata[i].codeentrys[j].address,4);
3501
3502        //original opcode
3503        trainer.ReadBuffer(temp,4);
3504        setlength(trainerdata[i].codeentrys[j].originalopcode,temp);
3505        trainer.ReadBuffer(pointer(trainerdata[i].codeentrys[j].originalopcode)^,temp);
3506      end;
3507
3508      //address entrys
3509      trainer.ReadBuffer(temp,4);
3510      setlength(trainerdata[i].addressentrys,temp);
3511      for j:=0 to length(trainerdata[i].addressentrys)-1 do
3512      begin
3513        trainer.ReadBuffer(trainerdata[i].addressentrys[j].address,sizeof(trainerdata[i].addressentrys[j].address));
3514        trainer.ReadBuffer(trainerdata[i].addressentrys[j].bit,sizeof(trainerdata[i].addressentrys[j].bit));
3515        trainer.ReadBuffer(trainerdata[i].addressentrys[j].memtyp,sizeof(trainerdata[i].addressentrys[j].memtyp));
3516        trainer.Readbuffer(trainerdata[i].addressentrys[j].frozen,sizeof(trainerdata[i].addressentrys[j].frozen));
3517        trainerdata[i].addressentrys[j].frozendirection:=0;
3518        trainer.Readbuffer(trainerdata[i].addressentrys[j].setvalue,sizeof(trainerdata[i].addressentrys[j].setvalue));
3519        trainer.ReadBuffer(trainerdata[i].addressentrys[j].userinput,sizeof(trainerdata[i].addressentrys[j].userinput));
3520        trainer.Readbuffer(trainerdata[i].addressentrys[j].value,50);
3521        if trainerdata[i].addressentrys[j].userinput then
3522        begin
3523          trainerdata[i].hasedit:=true;
3524          trainerdata[i].editvalue:=trainerdata[i].addressentrys[j].value;
3525        end;
3526
3527      end;
3528    end;
3529
3530    //title
3531    trainer.ReadBuffer(temp,4);
3532    getmem(x,temp+1);
3533    trainer.ReadBuffer(x^,temp);
3534    x[temp]:=#0;
3535    edittitle.Text:=x;
3536    freemem(x);
3537
3538    //launch filename
3539    trainer.ReadBuffer(temp,4);
3540    getmem(x,temp+1);
3541    trainer.ReadBuffer(x^,temp);
3542    x[temp]:=#0;
3543    edit2.Text:=x;
3544    freemem(x);
3545
3546    //autolaunch
3547    trainer.ReadBuffer(tempb,sizeof(tempb));
3548    checkbox2.Checked:=tempb;
3549
3550    //popup on keypress
3551    trainer.ReadBuffer(tempb,sizeof(tempb));
3552    checkbox1.Checked:=tempb;
3553
3554    //process name
3555    trainer.ReadBuffer(temp,4);
3556    getmem(x,temp+1);
3557    trainer.ReadBuffer(x^,temp);
3558    x[temp]:=#0;
3559    combobox1.Text:=x;
3560    freemem(x);
3561
3562    //hotkeytext
3563    trainer.ReadBuffer(temp,4);
3564    getmem(x,temp+1);
3565    trainer.ReadBuffer(x^,temp);
3566    x[temp]:=#0;
3567    edithotkey.Text:=x;
3568    freemem(x);
3569
3570    //hotkey+shiftstate     (convert)
3571    trainer.ReadBuffer(laststate,2);
3572    trainer.ReadBuffer(lastshiftstate,sizeof(lastshiftstate));
3573    ConvertOldHotkeyToKeyCombo(lastshiftstate, laststate, popuphotkey);
3574
3575
3576    //abouttext
3577    trainer.ReadBuffer(temp,4);
3578    getmem(x,temp+1);
3579    trainer.ReadBuffer(x^,temp);
3580    x[temp]:=#0;
3581    memo1.Text:=x;
3582    freemem(x);
3583
3584    trainer.ReadBuffer(temp,4);
3585    if temp=$666 then
3586    begin
3587      //default
3588      //leftside image
3589      trainer.ReadBuffer(temp,4);  //size of the image
3590      if temp>0 then
3591      begin
3592        //getmem(image,temp);
3593        //trainer.ReadBuffer(image^,temp);
3594        frmMemorytrainerpreview.Image1.Picture.Bitmap.LoadFromStream(trainer);
3595      end;
3596
3597      //windowwidth
3598      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Width));
3599      frmMemorytrainerpreview.Width:=temp;
3600
3601      //windowheight
3602      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.height));
3603      frmMemorytrainerpreview.height:=temp;
3604
3605      //leftsidewidth
3606      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.Width));
3607      frmMemorytrainerpreview.Panel1.Width:=temp;
3608
3609      //leftsideheight
3610      trainer.readbuffer(temp,sizeof(frmMemorytrainerpreview.Panel1.height));
3611      frmMemorytrainerpreview.Panel1.height:=temp;
3612    end
3613    else
3614    begin
3615      //user defined
3616      frmMemoryModifier.dontshowdefault:=true;       //obsolete
3617      frmMemoryModifier.Button7.Click;
3618
3619      //windowwidth
3620      trainer.readbuffer(temp,4);
3621      frmTrainerDesigner.Width:=temp;
3622
3623      //windowheight
3624      trainer.readbuffer(temp,4);
3625      frmTrainerDesigner.height:=temp;
3626
3627
3628      while true do
3629      begin
3630        trainer.ReadBuffer(temp,4);
3631        case temp of
3632          0: begin
3633               //tbutton
3634               with tbutton.create(frmTrainerDesigner) do
3635               begin
3636                 trainer.ReadBuffer(temp,sizeof(integer));
3637                 left:=temp;
3638                 trainer.ReadBuffer(temp,sizeof(integer));
3639                 top:=temp;
3640                 trainer.ReadBuffer(temp,sizeof(integer));
3641                 width:=temp;
3642                 trainer.ReadBuffer(temp,sizeof(integer));
3643                 height:=temp;
3644
3645                 //caption
3646                 trainer.ReadBuffer(temp,4);
3647                 getmem(x,temp+1);
3648                 trainer.ReadBuffer(x^,temp);
3649                 x[temp]:=#0;
3650                 caption:=x;
3651                 freemem(x);
3652
3653                 trainer.ReadBuffer(temp,sizeof(tag));
3654                 tag:=temp;
3655                 parent:=frmTrainerDesigner;
3656
3657                 onmousedown:=frmTrainerDesigner.MouseDown;
3658                 onmousemove:=frmTrainerDesigner.MouseMove;
3659                 onmouseup:=frmTrainerDesigner.MouseUp;
3660               end;
3661             end;
3662
3663          1: begin
3664               //cheatlist
3665               with tcheatlist.create(frmTrainerDesigner) do
3666               begin
3667                 trainer.ReadBuffer(temp,sizeof(integer));
3668                 left:=temp;
3669                 trainer.ReadBuffer(temp,sizeof(integer));
3670                 top:=temp;
3671                 trainer.ReadBuffer(temp,sizeof(integer));
3672                 width:=temp;
3673                 trainer.ReadBuffer(temp,sizeof(integer));
3674                 height:=temp;
3675
3676                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3677                 activationcolor:=tempc;
3678                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3679                 color:=tempc;
3680                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3681                 textcolor:=tempc;
3682
3683                 trainer.ReadBuffer(tempi,sizeof(integer));
3684                 hotkeyleft:=tempi;
3685                 trainer.ReadBuffer(tempi,sizeof(integer));
3686                 descriptionleft:=tempi;
3687                 trainer.ReadBuffer(tempi,sizeof(integer));
3688                 editleft:=tempi;
3689                 trainer.ReadBuffer(tempi,sizeof(integer));
3690                 editwidth:=tempi;
3691
3692                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
3693                 bevelinner:=tempbc;
3694                 trainer.ReadBuffer(tempbc,sizeof(tbevelcut));
3695                 bevelouter:=tempbc;
3696                 trainer.ReadBuffer(tempi,sizeof(integer));
3697                 bevelwidth:=tempi;
3698                 trainer.ReadBuffer(tempbk,sizeof(tbevelkind));
3699                 bevelkind:=tempbk;
3700                 parent:=frmTrainerDesigner;
3701                 onmousedown:=frmTrainerDesigner.MouseDown;
3702                 onmousemove:=frmTrainerDesigner.MouseMove;
3703                 onmouseup:=frmTrainerDesigner.MouseUp;
3704               end;
3705             end;
3706
3707          2: begin
3708               //tcheat
3709               with tcheat.create(frmTrainerDesigner) do
3710               begin
3711                 trainer.ReadBuffer(temp,sizeof(integer));
3712                 left:=temp;
3713                 trainer.ReadBuffer(temp,sizeof(integer));
3714                 top:=temp;
3715                 trainer.ReadBuffer(temp,sizeof(integer));
3716                 width:=temp;
3717                 trainer.ReadBuffer(temp,sizeof(integer));
3718                 height:=temp;
3719
3720                 trainer.ReadBuffer(cheatnr,sizeof(integer));
3721                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3722                 activationcolor:=tempc;
3723                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3724                 color:=tempc;
3725                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3726                 textcolor:=tempc;
3727
3728                 trainer.ReadBuffer(tempi,sizeof(integer));
3729                 hotkeyleft:=tempi;
3730                 trainer.ReadBuffer(tempi,sizeof(integer));
3731                 descriptionleft:=tempi;
3732                 trainer.ReadBuffer(tempi,sizeof(integer));
3733                 editleft:=tempi;
3734                 trainer.ReadBuffer(tempi,sizeof(integer));
3735                 editwidth:=tempi;
3736                 parent:=frmTrainerDesigner;
3737                 onmousedown:=frmTrainerDesigner.MouseDown;
3738                 onmousemove:=frmTrainerDesigner.MouseMove;
3739                 onmouseup:=frmTrainerDesigner.MouseUp;
3740               end;
3741             end;
3742
3743          3: begin
3744               //timage
3745               with timage.create(frmTrainerDesigner) do
3746               begin
3747                 trainer.ReadBuffer(temp,sizeof(integer));
3748                 left:=temp;
3749                 trainer.ReadBuffer(temp,sizeof(integer));
3750                 top:=temp;
3751                 trainer.ReadBuffer(temp,sizeof(integer));
3752                 width:=temp;
3753                 trainer.ReadBuffer(temp,sizeof(integer));
3754                 height:=temp;
3755
3756                 trainer.ReadBuffer(tempcursor,sizeof(tcursor));
3757                 cursor:=tempcursor;
3758
3759                 trainer.ReadBuffer(tempb,sizeof(tempb));
3760                 stretch:=tempb;
3761                 trainer.ReadBuffer(tempb,sizeof(tempb));
3762                 transparent:=tempb;
3763
3764                 trainer.ReadBuffer(tempi,sizeof(integer));
3765                 tag:=tempi;
3766
3767                 trainer.ReadBuffer(temp,4);
3768                 if temp>0 then
3769                 begin
3770                   picture.Bitmap.LoadFromStream(trainer);
3771                 end;
3772
3773                 parent:=frmTrainerDesigner;
3774                 onmousedown:=frmTrainerDesigner.MouseDown;
3775                 onmousemove:=frmTrainerDesigner.MouseMove;
3776                 onmouseup:=frmTrainerDesigner.MouseUp;
3777               end;
3778             end;
3779
3780          4: begin
3781               with tlabel.Create(frmTrainerDesigner) do
3782               begin
3783                 trainer.ReadBuffer(temp,sizeof(integer));
3784                 left:=temp;
3785                 trainer.ReadBuffer(temp,sizeof(integer));
3786                 top:=temp;
3787                 trainer.ReadBuffer(temp,sizeof(integer));
3788                 width:=temp;
3789                 trainer.ReadBuffer(temp,sizeof(integer));
3790                 height:=temp;
3791
3792                 //caption
3793                 trainer.ReadBuffer(temp,4);
3794                 getmem(x,temp+1);
3795                 trainer.ReadBuffer(x^,temp);
3796                 x[temp]:=#0;
3797                 caption:=x;
3798                 freemem(x);
3799
3800                 trainer.ReadBuffer(tempc,sizeof(tcolor));
3801                 font.Color:=tempc;
3802                 parent:=frmTrainerDesigner;
3803                 onmousedown:=frmTrainerDesigner.MouseDown;
3804                 onmousemove:=frmTrainerDesigner.MouseMove;
3805                 onmouseup:=frmTrainerDesigner.MouseUp;                 
3806               end;
3807             end;
3808          $ffffffff: break;
3809          else raise exception.Create(strunknowncomponent+Inttostr(temp));
3810        end;
3811      end;
3812    end;
3813  end;
3814
3815  //fill in the list of cheats
3816  for i:=0 to length(frmMemoryModifier.trainerdata)-1 do
3817  begin
3818    frmMemoryModifier.recordview.Items.Add.caption:=frmMemoryModifier.trainerdata[i].description;
3819    frmMemoryModifier.recordview.Items[frmMemoryModifier.recordview.Items.count-1].SubItems.add(frmMemoryModifier.trainerdata[i].hotkeytext);
3820  end;
3821
3822  frmMemoryTrainerPreview.UpdateScreen;
3823  if frmtrainerdesigner<>nil then frmtrainerdesigner.updatecheats 
3824
3825  //freemem(x);
3826end;
3827
3828procedure LoadExe(filename: string);
3829resourcestring
3830  strCorruptIcon='The icon has been corrupted';
3831  strCantLoadFilepatcher='The file patcher can''t be loaded by Cheat Engine!';
3832  strNotACETrainer='This is not a trainer made by Cheat Engine (If it is a trainer at all!)';
3833  strUnknownTrainerVersion='This version of Cheat Engine doesn''t know how to read this trainer! Trainerversion=';
3834  strCantLoadProtectedfile='This trainer is protected from being opened by CE. Now go away!!!';
3835var trainer: tfilestream;
3836    temp: dword;
3837    hi: hicon;
3838begin
3839  if frmMemoryModifier<>nil then
3840    frmMemoryModifier.Close;
3841
3842  frmMemoryModifier:=TFrmMemoryModifier.create(nil);
3843  frmMemoryModifier.show;
3844
3845  //extract icon
3846  hi:=ExtractIcon(hinstance,pchar(filename),0);
3847  if (hi=0) or (hi=1) then
3848  begin
3849    frmMemorymodifier.Free;
3850    raise exception.Create(strCorruptIcon);
3851  end;
3852
3853  frmMemoryModifier.Icon.Picture.Icon.Handle:=hi;
3854  frmMemoryTrainerPreview.Icon:=frmMemoryModifier.Icon.Picture.Icon;
3855
3856  frmMemoryModifier.CurrentIcon.LoadFromHandle(hi);
3857
3858  trainer:=tfilestream.Create(filename,fmopenread);
3859  try
3860    //load stuff from the trainer
3861    trainer.Position:=80;
3862    trainer.ReadBuffer(temp,4); //go to start of trainerstuff
3863
3864    if temp>trainer.Size then raise exception.Create(strNotACETrainer);
3865    trainer.Position:=temp;
3866
3867    //first check it is a suported trainer
3868    trainer.ReadBuffer(temp,4);
3869    if temp=$111111 then raise exception.Create(strCantLoadFilepatcher);
3870    if temp=$22322 then raise exception.Create(strCantLoadProtectedfile);
3871    if temp<>$22222 then raise exception.Create(strNotACETrainer);
3872
3873    //trainerversion
3874    trainer.ReadBuffer(temp,4);
3875    case temp of
3876      1: LoadTrainer1(trainer);
3877      2: LoadTrainer2(trainer);
3878      3: LoadTrainer3(trainer);
3879      4: LoadTrainer4(trainer);
3880      5: LoadTrainer5(trainer);
3881      6: LoadTrainer6(trainer);
3882      7: LoadTrainer7(trainer);
3883      8: LoadTrainer8(trainer);
3884      else raise exception.Create(strUnknownTrainerVersion+IntToStr(temp));
3885    end;
3886
3887    if frmTrainerDesigner<>nil then
3888      frmTrainerDesigner.Icon:=frmMemoryModifier.Icon.Picture.Icon;
3889
3890  finally
3891    trainer.Free;
3892  end;
3893
3894end;
3895{$endif}
3896
3897procedure LoadPTR(filename: string; merge: boolean);
3898var newrec: MemoryRecordV6;
3899    x: tfilestream;
3900    offsetlist: array of dword;
3901    invoffsetlist: array of dword;
3902    offsetsize: dword;
3903    stringlength: dword;
3904    i,j: integer;
3905
3906    ssize: integer;
3907    s: pchar;
3908    offset: dword;
3909begin
3910{$ifndef net}
3911  setlength(offsetlist,0);
3912
3913  x:=tfilestream.Create(filename,fmopenread or fmShareDenyNone);
3914  getmem(s,100);
3915  ssize:=100;
3916  try
3917    while x.Position<x.Size do
3918    begin
3919      //get the size of the string
3920      x.ReadBuffer(stringlength,sizeof(stringlength));
3921      if ssize<=stringlength then
3922      begin
3923        freemem(s);
3924        s:=nil;
3925        getmem(s,stringlength+1);
3926        ssize:=stringlength+1;
3927      end;
3928
3929      //read the string
3930      x.ReadBuffer(s^,stringlength);
3931      s[stringlength]:=#0; //and place a 0 terminator
3932
3933      x.ReadBuffer(offset,sizeof(offset)); //read the offset part of modulename+offset
3934
3935      x.ReadBuffer(offsetsize,sizeof(offsetsize));
3936
3937      if offsetsize>0 then
3938      begin
3939        if length(offsetlist)<(offsetsize+1) then
3940        begin
3941          setlength(offsetlist,offsetsize*2);
3942          setlength(invoffsetlist,length(offsetlist));
3943        end;
3944
3945        x.ReadBuffer(offsetlist[0],offsetsize*sizeof(offsetlist[0]));
3946        j:=0;
3947        for i:=offsetsize-1 downto 0 do
3948        begin
3949          invoffsetlist[j]:=offsetlist[i];
3950          inc(j);
3951        end;
3952      end;
3953
3954      with mainform do
3955      begin
3956        inc(numberofrecords);
3957        reservemem;
3958
3959        memrec[numberofrecords-1].Description:='pointerscan result';
3960        memrec[numberofrecords-1].VarType:=2;
3961        memrec[numberofrecords-1].Address:=0;
3962        memrec[numberofrecords-1].interpretableaddress:=s+'+'+inttohex(offset,8);
3963        memrec[numberofrecords-1].IsPointer:=offsetsize>0;
3964        setlength(memrec[numberofrecords-1].pointers, offsetsize);
3965        for i:=0 to offsetsize-1 do
3966        begin
3967          memrec[numberofrecords-1].pointers[i].Interpretableaddress:=s+'+'+inttohex(offset,8);
3968          memrec[numberofrecords-1].pointers[i].offset:=invoffsetlist[i];
3969        end;
3970      end;
3971
3972
3973      //mainform.addaddress('pointerscan result',offsetlist[0],invoffsetlist[0],offsetsize-1,true,2,0,0,false,false);
3974    end;
3975  finally
3976    x.free;
3977    if s<>nil then freemem(s);
3978  end;
3979
3980  mainform.UpdateScreen;
3981  mainform.updatelist;
3982{$endif}
3983end;
3984
3985function GetmemrecFromXMLNode(CheatEntry: IXMLNode): MemoryRecord;
3986var newrec: MemoryRecord;
3987    tempnode, tempnode2: IXMLNode;
3988    Offsets: IXMLNode;
3989    addrecord: boolean;
3990    j: integer;   
3991begin
3992  if CheatEntry.NodeName='CheatEntry' then
3993  begin
3994    tempnode:=CheatEntry.ChildNodes.FindNode('Description');
3995    if tempnode<>nil then
3996      newrec.Description:=tempnode.Text
3997    else
3998      newrec.Description:='...';
3999
4000
4001    newrec.Address:=0;
4002    tempnode:=CheatEntry.ChildNodes.FindNode('Address');
4003    if tempnode<>nil then
4004    begin
4005      try
4006        newrec.Address:=StrToInt('$'+tempnode.text);
4007      except
4008
4009      end;
4010    end;
4011
4012    tempnode:=CheatEntry.ChildNodes.FindNode('InterpretableAddress');
4013    if tempnode<>nil then
4014      newrec.interpretableaddress:=tempnode.Text
4015    else
4016      newrec.interpretableaddress:='';
4017
4018    tempnode:=CheatEntry.ChildNodes.FindNode('SpecialCode');
4019    if tempnode<>nil then
4020      newrec.autoassemblescript:=tempnode.Text
4021    else
4022      newrec.autoassemblescript:='';
4023
4024    tempnode:=CheatEntry.ChildNodes.FindNode('Type');
4025    if tempnode<>nil then
4026      newrec.VarType:=tempnode.NodeValue
4027    else
4028      newrec.VarType:=0;
4029
4030    tempnode:=CheatEntry.ChildNodes.FindNode('Unicode');
4031    if tempnode<>nil then
4032      newrec.unicode:=tempnode.Text='1'
4033    else
4034      newrec.unicode:=false;
4035
4036    newrec.Bit:=0;
4037    newrec.bitlength:=0;
4038    tempnode:=CheatEntry.ChildNodes.FindNode('Length');
4039    if tempnode<>nil then
4040    begin
4041      if newrec.VarType in [7,8] then //string,array of byte
4042        newrec.Bit:=tempnode.NodeValue;
4043
4044      if newrec.VarType = 5 then //binary
4045        newrec.bitlength:=tempnode.NodeValue;
4046    end;
4047
4048    tempnode:=CheatEntry.ChildNodes.FindNode('Bit');
4049    if (tempnode<>nil) and (newrec.VarType = 5) then
4050      newrec.Bit:=tempnode.NodeValue;
4051
4052    tempnode:=CheatEntry.ChildNodes.FindNode('Group');
4053    if tempnode<>nil then
4054      newrec.Group:=tempnode.NodeValue
4055    else
4056      newrec.Group:=0;
4057
4058    tempnode:=CheatEntry.ChildNodes.FindNode('HexadecimalDisplay');
4059    if tempnode<>nil then
4060      newrec.ShowAsHex:=tempnode.Text='1';
4061
4062
4063    tempnode:=CheatEntry.ChildNodes.FindNode('Pointer');
4064    if tempnode<>nil then
4065    begin
4066      //it's a pointer
4067      Offsets:=tempnode.ChildNodes.FindNode('Offsets');
4068      setlength(newrec.pointers, Offsets.ChildNodes.Count);
4069
4070
4071      for j:=0 to Offsets.ChildNodes.Count-1 do
4072      begin
4073        if Offsets.ChildNodes[j].NodeName='Offset' then
4074        begin
4075          try
4076            newrec.pointers[j].offset:=strtoint('$'+Offsets.ChildNodes[j].text);
4077          except
4078
4079          end;
4080        end;
4081      end;
4082
4083      tempnode2:=tempnode.ChildNodes.FindNode('Address');
4084      if tempnode2<>nil then
4085        newrec.pointers[Offsets.ChildNodes.Count-1].Address:=strtoint('$'+tempnode2.text);
4086
4087
4088      tempnode2:=tempnode.ChildNodes.FindNode('InterpretableAddress');
4089      if tempnode2<>nil then
4090        newrec.pointers[Offsets.ChildNodes.Count-1].Interpretableaddress:=tempnode2.Text;
4091
4092      newrec.IsPointer:=true;
4093    end;
4094
4095    result:=newrec;
4096  end;
4097end;
4098
4099procedure LoadStructFromXMLNode(var struct: TbaseStructure; Structure: IXMLNode);
4100var tempnode: IXMLNode;
4101    elements: IXMLNode;
4102    element: IXMLNode;
4103    i: integer;
4104    currentOffset: dword;
4105    findoffset: boolean;
4106begin
4107
4108  currentoffset:=0;
4109  if Structure.NodeName='Structure' then
4110  begin
4111    tempnode:=Structure.ChildNodes.FindNode('Name');
4112    if tempnode<>nil then
4113      struct.name:=tempnode.Text;
4114
4115    elements:=Structure.ChildNodes.FindNode('Elements');
4116    setlength(struct.structelement, elements.ChildNodes.Count);
4117
4118    for i:=0 to length(struct.structelement)-1 do
4119    begin
4120      element:=elements.ChildNodes[i];
4121
4122      findoffset:=true;
4123      tempnode:=element.ChildNodes.FindNode('Offset');
4124      if tempnode<>nil then
4125      begin
4126        try
4127          struct.structelement[i].offset:=strtoint('$'+tempnode.text);
4128          findoffset:=false;
4129        except
4130
4131        end;
4132      end;
4133
4134      if findoffset then
4135      begin
4136        //no offset given, or faulty offset
4137        struct.structelement[i].offset:=currentoffset;
4138      end;
4139
4140
4141      tempnode:=element.ChildNodes.FindNode('Description');
4142      if tempnode<>nil then
4143        struct.structelement[i].description:=tempnode.Text;
4144
4145      tempnode:=element.ChildNodes.FindNode('PointerTo');
4146      struct.structelement[i].pointerto:=(tempnode<>nil) and (tempnode.Text='1');
4147       
4148      tempnode:=element.ChildNodes.FindNode('PointerToSize');
4149      if tempnode<>nil then
4150        struct.structelement[i].pointertosize:=strtoint(tempnode.Text);
4151
4152      tempnode:=element.ChildNodes.FindNode('Structurenr');
4153      if tempnode<>nil then
4154        struct.structelement[i].structurenr:=strtoint(tempnode.Text);
4155
4156      tempnode:=element.ChildNodes.FindNode('Bytesize');
4157      if tempnode<>nil then
4158        struct.structelement[i].Bytesize:=strtoint(tempnode.Text);
4159
4160      currentoffset:=struct.structelement[i].offset+struct.structelement[i].Bytesize;
4161    end;
4162  end;
4163
4164  sortStructure(struct);
4165end;
4166{
4167procedure SaveStructToXMLNode(struct: TbaseStructure; Structures: IXMLNode);
4168var structure: IXMLNode;
4169    elements: IXMLNode;
4170    element: IXMLNode;
4171    i: integer;
4172begin
4173  Structure:=Structures.addChild('Structure');
4174  Structure.AddChild('Name').Text:=struct.name;
4175  elements:=Structure.AddChild('Elements');
4176  for i:=0 to length(struct.structelement)-1 do
4177  begin
4178    element:=elements.AddChild('Element');
4179    element.AddChild('Description').Text:=struct.structelement[i].description;
4180
4181    if struct.structelement[i].pointerto then
4182    begin
4183      element.AddChild('PointerTo').Text:='1';
4184      element.AddChild('PointerToSize').text:=inttostr(struct.structelement[i].pointertosize);
4185    end;
4186
4187    element.AddChild('Structurenr').Text:=inttostr(struct.structelement[i].structurenr);
4188    element.AddChild('Bytesize').Text:=inttostr(struct.structelement[i].bytesize);
4189  end;
4190
4191end;
4192
4193}
4194
4195procedure LoadCTEntryFromXMLNode(CheatEntry: IXMLNode; merge: boolean);
4196var newrec: MemoryRecord;
4197    tempnode, tempnode2: IXMLNode;
4198    Offsets: IXMLNode;
4199    addrecord: boolean;
4200    j: integer;
4201begin
4202  if CheatEntry.NodeName='CheatEntry' then
4203  begin
4204    newrec:=GetmemrecFromXMLNode(CheatEntry);
4205
4206    addrecord:=true;
4207    if merge then
4208    begin
4209      //find it in the current list, if it is in, dont add
4210      for j:=0 to mainform.NumberOfRecords-1 do
4211      begin
4212        if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
4213        begin
4214          if (newrec.VarType=5) then
4215            if (newrec.Bit<>mainform.memrec[j].bit) or (newrec.bitlength<>mainform.memrec[j].bitlength) then continue;
4216          addrecord:=false;
4217          break;
4218        end;
4219      end;
4220    end;
4221
4222    if addrecord then
4223    begin
4224      with mainform do
4225      begin
4226        inc(numberofrecords);
4227        reservemem;
4228        memrec[numberofrecords-1].Description:=newrec.Description;
4229        memrec[numberofrecords-1].Address:=newrec.Address;
4230        memrec[numberofrecords-1].interpretableaddress:=newrec.interpretableaddress;
4231        memrec[numberofrecords-1].VarType:=newrec.VarType;
4232        memrec[numberofrecords-1].unicode:=newrec.Unicode;
4233        memrec[numberofrecords-1].Group:=newrec.Group;
4234        memrec[numberofrecords-1].Bit:=newrec.Bit;
4235        memrec[numberofrecords-1].bitlength:=newrec.bitlength;
4236        memrec[numberofrecords-1].Frozen:=false;
4237        memrec[numberofrecords-1].FrozenValue:=0;
4238        memrec[numberofrecords-1].Frozendirection:=0;
4239        memrec[numberofrecords-1].ShowAsHex:=newrec.showashex;
4240        memrec[numberofrecords-1].autoassemblescript:=newrec.autoassemblescript;
4241
4242        memrec[numberofrecords-1].IsPointer:=newrec.IsPointer;
4243        setlength(memrec[numberofrecords-1].pointers,length(newrec.pointers));
4244        for j:=0 to length(newrec.pointers)-1 do
4245        begin
4246          memrec[numberofrecords-1].pointers[j].Address:=newrec.pointers[j].Address;
4247          memrec[numberofrecords-1].pointers[j].offset:=newrec.pointers[j].offset;
4248          memrec[numberofrecords-1].pointers[j].Interpretableaddress:=newrec.pointers[j].Interpretableaddress;
4249        end;
4250
4251      end;
4252    end;
4253           
4254  end;
4255end;
4256
4257procedure LoadXML(filename: string; merge: boolean);
4258var newrec: MemoryRecordV6;
4259    doc: TXMLDocument;
4260    CheatTable: IXMLNode;
4261    Entries, Codes, Symbols, Comments: IXMLNode;
4262    CheatEntry, CodeEntry, SymbolEntry: IXMLNode;
4263    Structures, Structure: IXMLNode;
4264    Offsets: IXMLNode;
4265
4266    tempnode, tempnode2: IXMLNode;
4267    i,j: integer;
4268    addrecord: boolean;
4269
4270    tempbefore: array of byte;
4271    tempactual: array of byte;
4272    tempafter: array of byte;
4273    tempaddress: dword;
4274    tempdescription,tempmodulename: string;
4275    tempoffset: dword;
4276
4277    symbolname: string;
4278    address: dword;
4279    li: tlistitem;
4280begin
4281  doc:=TXMLDocument.Create(application);
4282  try
4283    doc.FileName:=filename;
4284    doc.Active:=true;
4285    CheatTable:=doc.ChildNodes.FindNode('CheatTable');
4286
4287    if cheattable<>nil then
4288    begin
4289      Entries:=cheattable.ChildNodes.FindNode('CheatEntries');
4290      Codes:=cheattable.ChildNodes.FindNode('CheatCodes');
4291      Symbols:=cheattable.ChildNodes.FindNode('UserdefinedSymbols');
4292      Structures:=cheattable.ChildNodes.FindNode('Structures');
4293      Comments:=cheattable.ChildNodes.FindNode('Comments');
4294
4295      if entries<>nil then
4296      begin
4297        for i:=0 to entries.ChildNodes.Count-1 do
4298        begin
4299          CheatEntry:=entries.ChildNodes[i];
4300          LoadCTEntryFromXMLNode(CheatEntry, merge);
4301        end;
4302      end;
4303
4304      if codes<>nil then
4305      begin
4306        for i:=0 to codes.ChildNodes.Count-1 do
4307        begin
4308          CodeEntry:=codes.ChildNodes[i];
4309          if CodeEntry.NodeName='CodeEntry' then
4310          begin
4311            tempnode:=CodeEntry.ChildNodes.FindNode('Description');
4312            if tempnode<>nil then
4313              tempdescription:=tempnode.Text
4314            else
4315              tempdescription:='...';
4316
4317            tempaddress:=0;
4318            tempnode:=CodeEntry.ChildNodes.FindNode('Address');
4319            if tempnode<>nil then
4320            begin
4321              try
4322                tempaddress:=strtoint('$'+tempnode.text);
4323              except
4324
4325              end;
4326            end;
4327
4328            tempnode:=CodeEntry.ChildNodes.FindNode('ModuleName');
4329            if tempnode<>nil then
4330              tempmodulename:=tempnode.Text
4331            else
4332              tempmodulename:='';
4333
4334            tempoffset:=0;
4335            tempnode:=CodeEntry.ChildNodes.FindNode('ModuleNameOffset');
4336            if tempnode<>nil then
4337            begin
4338              try
4339                tempoffset:=strtoint('$'+tempnode.text);
4340              except
4341
4342              end;
4343            end;
4344
4345            tempnode:=CodeEntry.ChildNodes.FindNode('Before');
4346            if tempnode<>nil then
4347            begin
4348              setlength(tempbefore,tempnode.ChildNodes.Count);
4349              for j:=0 to tempnode.ChildNodes.Count-1 do
4350              begin
4351                try
4352                  tempbefore[j]:=strtoint('$'+tempnode.ChildNodes[j].Text);
4353                except
4354
4355                end;
4356              end;
4357            end else setlength(tempbefore,0);
4358
4359            tempnode:=CodeEntry.ChildNodes.FindNode('Actual');
4360            if tempnode<>nil then
4361            begin
4362              setlength(tempactual,tempnode.ChildNodes.Count);
4363              for j:=0 to tempnode.ChildNodes.Count-1 do
4364              begin
4365                try
4366                  tempactual[j]:=strtoint('$'+tempnode.ChildNodes[j].Text);
4367                except
4368
4369                end;
4370              end;
4371            end else setlength(tempactual,0);
4372
4373            tempnode:=CodeEntry.ChildNodes.FindNode('After');
4374            if tempnode<>nil then
4375            begin
4376              setlength(tempafter,tempnode.ChildNodes.Count);
4377              for j:=0 to tempnode.ChildNodes.Count-1 do
4378              begin
4379                try
4380                  tempafter[j]:=strtoint('$'+tempnode.ChildNodes[j].Text);
4381                except
4382
4383                end;
4384              end;
4385            end else setlength(tempafter,0);
4386
4387          end;
4388
4389          with advancedoptions do
4390          begin
4391            inc(numberofcodes);
4392            setlength(code,numberofcodes);
4393
4394            setlength(code[numberofcodes-1].before,length(tempbefore));
4395            for j:=0 to length(tempbefore)-1 do
4396              code[numberofcodes-1].before[j]:=tempbefore[j];
4397
4398            setlength(code[numberofcodes-1].actualopcode,length(tempactual));
4399            for j:=0 to length(tempactual)-1 do
4400              code[numberofcodes-1].actualopcode[j]:=tempactual[j];
4401
4402            setlength(code[numberofcodes-1].after,length(tempafter));
4403            for j:=0 to length(tempafter)-1 do
4404              code[numberofcodes-1].after[j]:=tempafter[j];
4405
4406            code[numberofcodes-1].Address:=tempaddress;
4407            code[numberofcodes-1].modulename:=tempmodulename;
4408            code[numberofcodes-1].offset:=tempoffset;
4409
4410            li:=codelist2.Items.Add;
4411            if code[numberofcodes-1].modulename<>'' then
4412              li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
4413            else
4414              li.Caption:=inttohex(tempaddress,8);
4415
4416            li.SubItems.Add(tempdescription);
4417          end;
4418
4419        end;
4420      end;
4421
4422      if symbols<>nil then
4423      begin
4424        for i:=0 to symbols.ChildNodes.Count-1 do
4425        begin
4426          SymbolEntry:=symbols.ChildNodes[i];
4427          if SymbolEntry.NodeName='SymbolEntry' then
4428          begin
4429            tempnode:=SymbolEntry.ChildNodes.FindNode('Name');
4430            if tempnode<>nil then
4431              symbolname:=tempnode.Text
4432            else
4433              symbolname:='...';
4434
4435            address:=0;
4436            tempnode:=SymbolEntry.ChildNodes.FindNode('Address');
4437            if tempnode<>nil then
4438            begin
4439              try
4440                symhandler.DeleteUserdefinedSymbol(symbolname);
4441                symhandler.AddUserdefinedSymbol(tempnode.Text,symbolname);
4442              except
4443
4444              end;
4445            end;
4446
4447
4448          end;
4449        end;
4450      end;
4451
4452      if Structures<>nil then
4453      begin
4454        setlength(definedstructures, Structures.ChildNodes.Count);
4455        for i:=0 to Structures.ChildNodes.Count-1 do
4456        begin
4457          Structure:=Structures.ChildNodes[i];
4458          LoadStructFromXMLNode(definedstructures[i], Structure);
4459        end;
4460      end;
4461
4462      if comments<>nil then
4463      begin
4464        Commentsunit.Comments.Memo1.Lines.Add(filename);
4465        Commentsunit.Comments.Memo1.Lines.Add('---');
4466
4467        for i:=0 to comments.ChildNodes.Count-1 do
4468        begin
4469          if comments.ChildNodes[i].NodeName='Comment' then
4470            Commentsunit.Comments.Memo1.Lines.Add(comments.ChildNodes[i].Text);
4471        end;
4472
4473      end;
4474    end;
4475  finally
4476    doc.free;
4477  end;
4478
4479
4480end;
4481
4482procedure LoadV6(filename: string; ctfile: tfilestream;merge: boolean);
4483var newrec: MemoryRecordV6;
4484    records, subrecords, pointers: dword;
4485    i,j,k: integer;
4486    addrecord: boolean;
4487    temp:dword;
4488    tableversion: integer;
4489
4490    x: pchar;
4491    nrofbytes:  byte;
4492    tempbefore: array of byte;
4493    tempactual: array of byte;
4494    tempafter: array of byte;
4495    tempaddress: dword;
4496    tempdescription,tempmodulename: string;
4497    tempoffset: dword;
4498
4499    address: dword;
4500    symbolname: string;
4501    addressstring: string;
4502    li: tlistitem;
4503begin
4504    ctfile.ReadBuffer(records,4);
4505    for i:=0 to records-1 do
4506    begin
4507      //ctfile.ReadBuffer(newrec,sizeof(MemoryRecordV2));
4508      ctfile.ReadBuffer(j,sizeof(j));
4509      getmem(x,j+1);
4510      ctfile.readbuffer(x^,j);
4511      x[j]:=#0;
4512      newrec.description:=x;
4513      freemem(x);
4514     
4515      ctfile.ReadBuffer(newrec.Address,sizeof(newrec.Address));
4516
4517      //interpretableaddress
4518      ctfile.ReadBuffer(j,sizeof(j));
4519      getmem(x,j+1);
4520      ctfile.readbuffer(x^,j);
4521      x[j]:=#0;
4522      newrec.interpretableaddress:=x;
4523      freemem(x);
4524
4525      ctfile.ReadBuffer(newrec.VarType,sizeof(newrec.VarType));
4526      ctfile.ReadBuffer(newrec.unicode,sizeof(newrec.VarType));
4527      ctfile.ReadBuffer(newrec.Bit,sizeof(newrec.Bit));
4528      ctfile.ReadBuffer(newrec.bitlength,sizeof(newrec.bitlength));
4529      ctfile.ReadBuffer(newrec.Group,sizeof(newrec.Group));
4530      ctfile.ReadBuffer(newrec.showashex,sizeof(newrec.showashex));
4531      ctfile.ReadBuffer(newrec.ispointer,sizeof(newrec.ispointer));
4532
4533      ctfile.ReadBuffer(temp,sizeof(temp));
4534      setlength(newrec.pointers,temp);
4535
4536      for j:=0 to temp-1 do
4537      begin
4538        ctfile.ReadBuffer(newrec.pointers[j].address,sizeof(newrec.pointers[j].address));
4539        ctfile.ReadBuffer(newrec.pointers[j].offset,sizeof(newrec.pointers[j].offset));
4540
4541        //interpretableaddress for pointer
4542        ctfile.ReadBuffer(k,sizeof(k));
4543        getmem(x,k+1);
4544        ctfile.readbuffer(x^,k);
4545        x[k]:=#0;
4546        newrec.pointers[j].interpretableaddress:=x;
4547        freemem(x);
4548
4549      end;
4550
4551      ctfile.ReadBuffer(j,sizeof(j));
4552      getmem(x,j+1);
4553      ctfile.readbuffer(x^,j);
4554      x[j]:=#0;
4555      newrec.autoassemblescript:=x;
4556      freemem(x);
4557
4558     
4559      addrecord:=true;
4560      if merge then
4561        //find it in the current list, if it is in, dont add
4562        for j:=0 to mainform.NumberOfRecords-1 do
4563          if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
4564          begin
4565            if (newrec.VarType=5) then
4566              if (newrec.Bit<>mainform.memrec[j].bit) or (newrec.bitlength<>mainform.memrec[j].bitlength) then continue;
4567            addrecord:=false;
4568            break;
4569          end;
4570
4571      if addrecord then
4572      begin
4573        with mainform do
4574        begin
4575          inc(numberofrecords);
4576          reservemem;
4577          memrec[numberofrecords-1].Description:=newrec.Description;
4578          memrec[numberofrecords-1].Address:=newrec.Address;
4579          memrec[numberofrecords-1].interpretableaddress:=newrec.interpretableaddress;
4580          memrec[numberofrecords-1].VarType:=newrec.VarType;
4581          memrec[numberofrecords-1].unicode:=newrec.Unicode;
4582          memrec[numberofrecords-1].Group:=newrec.Group;
4583          memrec[numberofrecords-1].Bit:=newrec.Bit;
4584          memrec[numberofrecords-1].bitlength:=newrec.bitlength;
4585          memrec[numberofrecords-1].Frozen:=false;
4586          memrec[numberofrecords-1].FrozenValue:=0;
4587          memrec[numberofrecords-1].Frozendirection:=0;
4588          memrec[numberofrecords-1].ShowAsHex:=newrec.showashex;
4589          memrec[numberofrecords-1].autoassemblescript:=newrec.autoassemblescript;
4590
4591          {$ifndef net} //no pointer handling for the client/server yet
4592          memrec[numberofrecords-1].IsPointer:=newrec.IsPointer;
4593          setlength(memrec[numberofrecords-1].pointers,length(newrec.pointers));
4594          for j:=0 to length(newrec.pointers)-1 do
4595          begin
4596            memrec[numberofrecords-1].pointers[j].Address:=newrec.pointers[j].Address;
4597            memrec[numberofrecords-1].pointers[j].offset:=newrec.pointers[j].offset;
4598            memrec[numberofrecords-1].pointers[j].Interpretableaddress:=newrec.pointers[j].Interpretableaddress;
4599          end;
4600          {$endif}
4601        end;
4602      end;
4603    end;
4604
4605
4606    ctfile.ReadBuffer(records,4);
4607    for i:=0 to records-1 do
4608    begin
4609      ctfile.ReadBuffer(tempaddress,4);
4610
4611      ctfile.ReadBuffer(nrofbytes,1);
4612      getmem(x,nrofbytes+1);
4613      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
4614      x[nrofbytes]:=#0;
4615      tempmodulename:=x;
4616      freemem(x);
4617      ctfile.ReadBuffer(tempoffset,4);
4618
4619      ctfile.ReadBuffer(nrofbytes,1);
4620      setlength(tempbefore,nrofbytes);
4621      ctfile.ReadBuffer(pointer(tempbefore)^,nrofbytes);
4622
4623      ctfile.ReadBuffer(nrofbytes,1);
4624      setlength(tempactual,nrofbytes);
4625      ctfile.ReadBuffer(pointer(tempactual)^,nrofbytes);
4626
4627      ctfile.ReadBuffer(nrofbytes,1);
4628      setlength(tempafter,nrofbytes);
4629      ctfile.ReadBuffer(pointer(tempafter)^,nrofbytes);
4630
4631      ctfile.ReadBuffer(nrofbytes,1);
4632      getmem(x,nrofbytes+1);
4633      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
4634      x[nrofbytes]:=#0;
4635      tempdescription:=x;
4636      freemem(x);
4637
4638      addrecord:=true;
4639
4640{      if merge then
4641      begin
4642        for j:=0 to advancedoptions.numberofcodes-1 do
4643          if (advancedoptions.addresses[j]=tempaddress) then
4644          begin
4645            addrecord:=false;
4646            break;
4647          end;
4648
4649      end; }
4650
4651      if addrecord then
4652      begin
4653        with advancedoptions do
4654        begin
4655          inc(numberofcodes);
4656          setlength(code,numberofcodes);
4657
4658          setlength(code[numberofcodes-1].before,length(tempbefore));
4659          for k:=0 to length(tempbefore)-1 do
4660            code[numberofcodes-1].before[k]:=tempbefore[k];
4661
4662          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
4663          for k:=0 to length(tempactual)-1 do
4664            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
4665
4666          setlength(code[numberofcodes-1].after,length(tempafter));
4667          for k:=0 to length(tempafter)-1 do
4668            code[numberofcodes-1].after[k]:=tempafter[k];
4669
4670          code[numberofcodes-1].Address:=tempaddress;
4671          code[numberofcodes-1].modulename:=tempmodulename;
4672          code[numberofcodes-1].offset:=tempoffset;
4673
4674          li:=codelist2.Items.Add;
4675          if code[numberofcodes-1].modulename<>'' then
4676            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
4677          else
4678            li.Caption:=inttohex(tempaddress,8);
4679
4680          li.SubItems.Add(tempdescription);
4681        end;
4682      end;
4683
4684    end;
4685
4686    i:=ctfile.Position;
4687    ctfile.Position:=11;
4688    ctfile.ReadBuffer(tableversion,4);
4689    ctfile.Position:=i;
4690
4691    if tableversion>=7 then
4692    begin
4693      //version 7 also contains some stuff about symbols
4694      ctfile.ReadBuffer(records,sizeof(records));
4695      for i:=0 to records-1 do
4696      begin
4697        ctfile.ReadBuffer(address,sizeof(address));
4698        ctfile.ReadBuffer(j,sizeof(j));
4699
4700        getmem(x,j+1);
4701        try
4702          ctfile.ReadBuffer(x^,j);
4703          x[j]:=#0;
4704          symbolname:=x;
4705        finally
4706          freemem(x);
4707        end;
4708
4709        if tableversion>=9 then //version 9 adds the addressstring
4710        begin
4711          ctfile.ReadBuffer(j,sizeof(j));
4712          getmem(x,j+1);
4713          try
4714            ctfile.ReadBuffer(x^,j);
4715            x[j]:=#0;
4716            addressstring:=x;
4717          finally
4718            freemem(x);
4719          end;
4720
4721
4722          try
4723            symhandler.DeleteUserdefinedSymbol(symbolname);
4724            symhandler.AddUserdefinedSymbol(addressstring,symbolname);
4725          except
4726
4727          end;
4728        end
4729        else
4730        begin
4731          //before version 9
4732          try
4733            symhandler.DeleteUserdefinedSymbol(symbolname);
4734            symhandler.AddUserdefinedSymbol(inttohex(address,8),symbolname);
4735          except
4736
4737          end;
4738        end;
4739      end;
4740    end;
4741
4742    if tableversion>=8 then
4743    begin
4744      //version 8 added structure data
4745      ctfile.ReadBuffer(records,4);
4746      setlength(definedstructures,records);
4747      for i:=0 to records-1 do
4748      begin
4749        ctfile.ReadBuffer(j,sizeof(j));
4750        getmem(x,j+1);
4751        ctfile.readbuffer(x^,j);
4752        x[j]:=#0;
4753        definedstructures[i].name:=x;
4754        freemem(x);
4755
4756        ctfile.ReadBuffer(subrecords,4);
4757        setlength(definedstructures[i].structelement,subrecords);
4758        for j:=0 to subrecords-1 do
4759        begin
4760          ctfile.ReadBuffer(k,sizeof(k));
4761          getmem(x,k+1);
4762          ctfile.readbuffer(x^,k);
4763          x[k]:=#0;
4764          definedstructures[i].structelement[j].description:=x;
4765          freemem(x);
4766
4767          ctfile.ReadBuffer(definedstructures[i].structelement[j].pointerto,sizeof(definedstructures[i].structelement[j].pointerto));
4768          ctfile.ReadBuffer(definedstructures[i].structelement[j].pointertoSize,sizeof(definedstructures[i].structelement[j].pointertoSize));
4769          ctfile.ReadBuffer(definedstructures[i].structelement[j].structurenr,sizeof(definedstructures[i].structelement[j].structurenr));
4770          ctfile.ReadBuffer(definedstructures[i].structelement[j].bytesize,sizeof(definedstructures[i].structelement[j].bytesize));
4771          if tableversion>=9 then //version 9 added offsets
4772            ctfile.ReadBuffer(definedstructures[i].structelement[j].offset,sizeof(definedstructures[i].structelement[j].offset));
4773
4774        end;
4775      end;
4776    end;
4777
4778    //comments
4779    if merge then comments.Memo1.Lines.Add(filename);
4780    i:=ctfile.Size-ctfile.Position;
4781    getmem(x,i+1);
4782    ctfile.readbuffer(x^,i);
4783
4784    x[i]:=chr(0);
4785    comments.Memo1.Text:=comments.Memo1.Text+x;
4786
4787    freemem(x);
4788end;
4789
4790
4791procedure LoadV5(filename: string; ctfile: tfilestream;merge: boolean);
4792var newrec: MemoryRecordV5;
4793    records,pointers: dword;
4794    i,j,k: integer;
4795    addrecord: boolean;
4796    temp:dword;
4797
4798    x: pchar;
4799    nrofbytes:  byte;
4800    tempbefore: array of byte;
4801    tempactual: array of byte;
4802    tempafter: array of byte;
4803    tempaddress: dword;
4804    tempdescription: string;
4805    li: tlistitem;
4806begin
4807    ctfile.ReadBuffer(records,4);
4808    for i:=0 to records-1 do
4809    begin
4810      //ctfile.ReadBuffer(newrec,sizeof(MemoryRecordV2));
4811      ctfile.ReadBuffer(j,sizeof(j));
4812      getmem(x,j+1);
4813      ctfile.readbuffer(x^,j);
4814      x[j]:=#0;
4815      newrec.description:=x;
4816      freemem(x);
4817     
4818      ctfile.ReadBuffer(newrec.Address,sizeof(newrec.Address));
4819      ctfile.ReadBuffer(newrec.VarType,sizeof(newrec.VarType));
4820      ctfile.ReadBuffer(newrec.unicode,sizeof(newrec.VarType));
4821      ctfile.ReadBuffer(newrec.Bit,sizeof(newrec.Bit));
4822      ctfile.ReadBuffer(newrec.bitlength,sizeof(newrec.bitlength));
4823      ctfile.ReadBuffer(newrec.Group,sizeof(newrec.Group));
4824      ctfile.ReadBuffer(newrec.showashex,sizeof(newrec.showashex));
4825      ctfile.ReadBuffer(newrec.ispointer,sizeof(newrec.ispointer));
4826
4827      ctfile.ReadBuffer(temp,sizeof(temp));
4828      setlength(newrec.pointers,temp);
4829
4830      for j:=0 to temp-1 do
4831      begin
4832        ctfile.ReadBuffer(newrec.pointers[j].address,sizeof(newrec.pointers[j].address));
4833        ctfile.ReadBuffer(newrec.pointers[j].offset,sizeof(newrec.pointers[j].offset));
4834      end;
4835
4836      addrecord:=true;
4837      if merge then
4838        //find it in the current list, if it is in, dont add
4839        for j:=0 to mainform.NumberOfRecords-1 do
4840          if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
4841          begin
4842            if (newrec.VarType=5) then
4843              if (newrec.Bit<>mainform.memrec[j].bit) or (newrec.bitlength<>mainform.memrec[j].bitlength) then continue;
4844            addrecord:=false;
4845            break;
4846          end;
4847
4848      if addrecord then
4849      begin
4850        with mainform do
4851        begin
4852          inc(numberofrecords);
4853          reservemem;
4854          memrec[numberofrecords-1].Description:=newrec.Description;
4855          memrec[numberofrecords-1].Address:=newrec.Address;
4856          memrec[numberofrecords-1].VarType:=newrec.VarType;
4857          memrec[numberofrecords-1].unicode:=newrec.Unicode;
4858          memrec[numberofrecords-1].Group:=newrec.Group;
4859          memrec[numberofrecords-1].Bit:=newrec.Bit;
4860          memrec[numberofrecords-1].bitlength:=newrec.bitlength;
4861          memrec[numberofrecords-1].Frozen:=false;
4862          memrec[numberofrecords-1].FrozenValue:=0;
4863          memrec[numberofrecords-1].Frozendirection:=0;
4864          memrec[numberofrecords-1].ShowAsHex:=newrec.showashex;
4865
4866          {$ifndef net} //no pointer handling for the client/server yet
4867          memrec[numberofrecords-1].IsPointer:=newrec.IsPointer;
4868          setlength(memrec[numberofrecords-1].pointers,length(newrec.pointers));
4869          for j:=0 to length(newrec.pointers)-1 do
4870          begin
4871            memrec[numberofrecords-1].pointers[j].Address:=newrec.pointers[j].Address;
4872            memrec[numberofrecords-1].pointers[j].offset:=newrec.pointers[j].offset;
4873          end;
4874          {$endif}
4875        end;
4876      end;
4877    end;
4878
4879
4880    ctfile.ReadBuffer(records,4);
4881    for i:=0 to records-1 do
4882    begin
4883      ctfile.ReadBuffer(tempaddress,4);
4884
4885      ctfile.ReadBuffer(nrofbytes,1);
4886      setlength(tempbefore,nrofbytes);
4887      ctfile.ReadBuffer(pointer(tempbefore)^,nrofbytes);
4888
4889      ctfile.ReadBuffer(nrofbytes,1);
4890      setlength(tempactual,nrofbytes);
4891      ctfile.ReadBuffer(pointer(tempactual)^,nrofbytes);
4892
4893      ctfile.ReadBuffer(nrofbytes,1);
4894      setlength(tempafter,nrofbytes);
4895      ctfile.ReadBuffer(pointer(tempafter)^,nrofbytes);
4896
4897      ctfile.ReadBuffer(nrofbytes,1);
4898      getmem(x,nrofbytes+1);
4899      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
4900      x[nrofbytes]:=#0;
4901      tempdescription:=x;
4902      freemem(x);
4903
4904      addrecord:=true;
4905
4906{      if merge then
4907      begin
4908        for j:=0 to advancedoptions.numberofcodes-1 do
4909          if (advancedoptions.addresses[j]=tempaddress) then
4910          begin
4911            addrecord:=false;
4912            break;
4913          end;
4914
4915      end; }
4916
4917      if addrecord then
4918      begin
4919        with advancedoptions do
4920        begin
4921          inc(numberofcodes);
4922          setlength(code,numberofcodes);
4923
4924          setlength(code[numberofcodes-1].before,length(tempbefore));
4925          for k:=0 to length(tempbefore)-1 do
4926            code[numberofcodes-1].before[k]:=tempbefore[k];
4927
4928          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
4929          for k:=0 to length(tempactual)-1 do
4930            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
4931
4932          setlength(code[numberofcodes-1].after,length(tempafter));
4933          for k:=0 to length(tempafter)-1 do
4934            code[numberofcodes-1].after[k]:=tempafter[k];
4935
4936          code[numberofcodes-1].Address:=tempaddress;
4937
4938          li:=codelist2.Items.Add;
4939          if code[numberofcodes-1].modulename<>'' then
4940            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
4941          else
4942            li.Caption:=inttohex(tempaddress,8);
4943
4944          li.SubItems.Add(tempdescription);
4945        end;
4946      end;
4947
4948    end;
4949
4950    //comments
4951    if merge then comments.Memo1.Lines.Add(filename);
4952    i:=ctfile.Size-ctfile.Position;
4953    getmem(x,i+1);
4954    ctfile.readbuffer(x^,i);
4955
4956    x[i]:=chr(0);
4957    comments.Memo1.Text:=comments.Memo1.Text+x;
4958
4959    freemem(x);
4960end;
4961
4962procedure LoadV4(filename: string; ctfile: tfilestream;merge: boolean);
4963var newrec: MemoryRecordV4;
4964    records,pointers: dword;
4965    i,j,k: integer;
4966    addrecord: boolean;
4967    temp:dword;
4968
4969    x: pchar;
4970    nrofbytes:  byte;
4971    tempbefore: array of byte;
4972    tempactual: array of byte;
4973    tempafter: array of byte;
4974    tempaddress: dword;
4975    tempdescription: string;
4976    li: tlistitem;
4977begin
4978    ctfile.ReadBuffer(records,4);
4979    for i:=0 to records-1 do
4980    begin
4981      //ctfile.ReadBuffer(newrec,sizeof(MemoryRecordV2));
4982
4983      ctfile.ReadBuffer(newrec.Description,sizeof(newrec.Description));
4984      ctfile.ReadBuffer(newrec.Address,sizeof(newrec.Address));
4985      ctfile.ReadBuffer(newrec.VarType,sizeof(newrec.VarType));
4986      ctfile.ReadBuffer(newrec.Bit,sizeof(newrec.Bit));
4987      ctfile.ReadBuffer(newrec.bitlength,sizeof(newrec.bitlength));
4988      ctfile.ReadBuffer(newrec.Group,sizeof(newrec.Group));
4989      ctfile.ReadBuffer(newrec.showashex,sizeof(newrec.showashex));
4990      ctfile.ReadBuffer(newrec.ispointer,sizeof(newrec.ispointer));
4991
4992      ctfile.ReadBuffer(temp,sizeof(temp));
4993      setlength(newrec.pointers,temp);
4994
4995      for j:=0 to temp-1 do
4996      begin
4997        ctfile.ReadBuffer(newrec.pointers[j].address,sizeof(newrec.pointers[j].address));
4998        ctfile.ReadBuffer(newrec.pointers[j].offset,sizeof(newrec.pointers[j].offset));
4999      end;
5000
5001      addrecord:=true;
5002      //goodbye merge, just add
5003
5004      if addrecord then
5005      begin
5006        with mainform do
5007        begin
5008          inc(numberofrecords);
5009          reservemem;
5010          memrec[numberofrecords-1].Description:=newrec.Description;
5011          memrec[numberofrecords-1].Address:=newrec.Address;
5012          memrec[numberofrecords-1].VarType:=newrec.VarType;
5013          memrec[numberofrecords-1].unicode:=false;
5014          memrec[numberofrecords-1].Group:=newrec.Group;
5015          memrec[numberofrecords-1].Bit:=newrec.Bit;
5016          memrec[numberofrecords-1].bitlength:=newrec.bitlength;
5017          memrec[numberofrecords-1].Frozen:=false;
5018          memrec[numberofrecords-1].FrozenValue:=0;
5019          memrec[numberofrecords-1].Frozendirection:=0;
5020          memrec[numberofrecords-1].ShowAsHex:=newrec.showashex;
5021
5022          {$ifndef net} //no pointer handling for the client/server yet
5023          memrec[numberofrecords-1].IsPointer:=newrec.IsPointer;
5024          setlength(memrec[numberofrecords-1].pointers,length(newrec.pointers));
5025          for j:=0 to length(newrec.pointers)-1 do
5026          begin
5027            memrec[numberofrecords-1].pointers[j].Address:=newrec.pointers[j].Address;
5028            memrec[numberofrecords-1].pointers[j].offset:=newrec.pointers[j].offset;
5029          end;
5030          {$endif}
5031        end;
5032      end;
5033    end;
5034
5035
5036    ctfile.ReadBuffer(records,4);
5037    for i:=0 to records-1 do
5038    begin
5039      ctfile.ReadBuffer(tempaddress,4);
5040
5041      ctfile.ReadBuffer(nrofbytes,1);
5042      setlength(tempbefore,nrofbytes);
5043      ctfile.ReadBuffer(pointer(tempbefore)^,nrofbytes);
5044
5045      ctfile.ReadBuffer(nrofbytes,1);
5046      setlength(tempactual,nrofbytes);
5047      ctfile.ReadBuffer(pointer(tempactual)^,nrofbytes);
5048
5049      ctfile.ReadBuffer(nrofbytes,1);
5050      setlength(tempafter,nrofbytes);
5051      ctfile.ReadBuffer(pointer(tempafter)^,nrofbytes);
5052
5053      ctfile.ReadBuffer(nrofbytes,1);
5054      getmem(x,nrofbytes+1);
5055      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
5056      x[nrofbytes]:=#0;
5057      tempdescription:=x;
5058      freemem(x);
5059
5060      addrecord:=true;
5061
5062      if merge then
5063      begin
5064        for j:=0 to advancedoptions.numberofcodes-1 do
5065          if (advancedoptions.code[j].Address=tempaddress) then
5066          begin
5067            addrecord:=false;
5068            break;
5069          end;
5070
5071      end;
5072
5073      if addrecord then
5074      begin
5075        with advancedoptions do
5076        begin
5077          inc(numberofcodes);
5078          setlength(code,numberofcodes);
5079
5080          setlength(code[numberofcodes-1].before,length(tempbefore));
5081          for k:=0 to length(tempbefore)-1 do
5082            code[numberofcodes-1].before[k]:=tempbefore[k];
5083
5084          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
5085          for k:=0 to length(tempactual)-1 do
5086            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
5087
5088          setlength(code[numberofcodes-1].after,length(tempafter));
5089          for k:=0 to length(tempafter)-1 do
5090            code[numberofcodes-1].after[k]:=tempafter[k];
5091
5092          code[numberofcodes-1].Address:=tempaddress;
5093
5094          li:=codelist2.Items.Add;
5095          if code[numberofcodes-1].modulename<>'' then
5096            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
5097          else
5098            li.Caption:=inttohex(tempaddress,8);
5099
5100          li.SubItems.Add(tempdescription);
5101        end;
5102      end;
5103
5104    end;
5105
5106    //comments
5107    if merge then comments.Memo1.Lines.Add(filename);
5108    i:=ctfile.Size-ctfile.Position;
5109    getmem(x,i+1);
5110    ctfile.readbuffer(x^,i);
5111
5112    x[i]:=chr(0);
5113    comments.Memo1.Text:=comments.Memo1.Text+x;
5114
5115    freemem(x);
5116end;
5117
5118
5119procedure LoadV3(filename: string; ctfile: tfilestream;merge: boolean);
5120var newrec: MemoryRecordV3;
5121    records,pointers: dword;
5122    i,j,k: integer;
5123    addrecord: boolean;
5124    temp:dword;
5125
5126    x: pchar;
5127    nrofbytes:  byte;
5128    tempbefore: array of byte;
5129    tempactual: array of byte;
5130    tempafter: array of byte;
5131    tempaddress: dword;
5132    tempdescription: string;
5133    li: tlistitem;
5134begin
5135    ctfile.ReadBuffer(records,4);
5136    for i:=0 to records-1 do
5137    begin
5138      //ctfile.ReadBuffer(newrec,sizeof(MemoryRecordV2));
5139
5140      ctfile.ReadBuffer(newrec.Description,sizeof(newrec.Description));
5141      ctfile.ReadBuffer(newrec.Address,sizeof(newrec.Address));
5142      ctfile.ReadBuffer(newrec.VarType,sizeof(newrec.VarType));
5143      ctfile.ReadBuffer(newrec.Bit,sizeof(newrec.Bit));
5144      ctfile.ReadBuffer(newrec.bitlength,sizeof(newrec.bitlength));
5145      ctfile.ReadBuffer(newrec.Group,sizeof(newrec.Group));
5146      ctfile.ReadBuffer(newrec.ispointer,sizeof(newrec.ispointer));
5147
5148      ctfile.ReadBuffer(temp,sizeof(temp));
5149      setlength(newrec.pointers,temp);
5150
5151      for j:=0 to temp-1 do
5152      begin
5153        ctfile.ReadBuffer(newrec.pointers[j].address,sizeof(newrec.pointers[j].address));
5154        ctfile.ReadBuffer(newrec.pointers[j].offset,sizeof(newrec.pointers[j].offset));
5155      end;
5156
5157      addrecord:=true;
5158      if merge then
5159        //find it in the current list, if it is in, dont add
5160        for j:=0 to mainform.NumberOfRecords-1 do
5161          if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
5162          begin
5163            if (newrec.VarType=5) then
5164              if (newrec.Bit<>mainform.memrec[j].bit) or (newrec.bitlength<>mainform.memrec[j].bitlength) then continue;
5165            addrecord:=false;
5166            break;
5167          end;
5168
5169      if addrecord then
5170      begin
5171        with mainform do
5172        begin
5173          inc(numberofrecords);
5174          reservemem;
5175          memrec[numberofrecords-1].Description:=newrec.Description;
5176          memrec[numberofrecords-1].Address:=newrec.Address;
5177          memrec[numberofrecords-1].VarType:=newrec.VarType;
5178          memrec[numberofrecords-1].unicode:=false;
5179          memrec[numberofrecords-1].Bit:=newrec.Bit;
5180          memrec[numberofrecords-1].bitlength:=newrec.bitlength;
5181          memrec[numberofrecords-1].Frozen:=false;
5182          memrec[numberofrecords-1].FrozenValue:=0;
5183          memrec[numberofrecords-1].Frozendirection:=0;
5184          memrec[numberofrecords-1].ShowAsHex:=false;
5185
5186          {$ifndef net}
5187          memrec[numberofrecords-1].IsPointer:=newrec.IsPointer;
5188          setlength(memrec[numberofrecords-1].pointers,length(newrec.pointers));
5189          for j:=0 to length(newrec.pointers)-1 do
5190          begin
5191            memrec[numberofrecords-1].pointers[j].Address:=newrec.pointers[j].Address;
5192            memrec[numberofrecords-1].pointers[j].offset:=newrec.pointers[j].offset;
5193          end;
5194          {$endif}
5195        end;
5196      end;
5197    end;
5198
5199
5200    ctfile.ReadBuffer(records,4);
5201    for i:=0 to records-1 do
5202    begin
5203      ctfile.ReadBuffer(tempaddress,4);
5204
5205      ctfile.ReadBuffer(nrofbytes,1);
5206      setlength(tempbefore,nrofbytes);
5207      ctfile.ReadBuffer(pointer(tempbefore)^,nrofbytes);
5208
5209      ctfile.ReadBuffer(nrofbytes,1);
5210      setlength(tempactual,nrofbytes);
5211      ctfile.ReadBuffer(pointer(tempactual)^,nrofbytes);
5212
5213      ctfile.ReadBuffer(nrofbytes,1);
5214      setlength(tempafter,nrofbytes);
5215      ctfile.ReadBuffer(pointer(tempafter)^,nrofbytes);
5216
5217      ctfile.ReadBuffer(nrofbytes,1);
5218      getmem(x,nrofbytes+1);
5219      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
5220      x[nrofbytes]:=#0;
5221      tempdescription:=x;
5222      freemem(x);
5223
5224      addrecord:=true;
5225
5226      if merge then
5227      begin
5228        for j:=0 to advancedoptions.numberofcodes-1 do
5229          if (advancedoptions.code[j].Address=tempaddress) then
5230          begin
5231            addrecord:=false;
5232            break;
5233          end;
5234
5235      end;
5236
5237      if addrecord then
5238      begin
5239        with advancedoptions do
5240        begin
5241          inc(numberofcodes);
5242          setlength(code,numberofcodes);
5243
5244          setlength(code[numberofcodes-1].before,length(tempbefore));
5245          for k:=0 to length(tempbefore)-1 do
5246            code[numberofcodes-1].before[k]:=tempbefore[k];
5247
5248          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
5249          for k:=0 to length(tempactual)-1 do
5250            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
5251
5252          setlength(code[numberofcodes-1].after,length(tempafter));
5253          for k:=0 to length(tempafter)-1 do
5254            code[numberofcodes-1].after[k]:=tempafter[k];
5255
5256          code[numberofcodes-1].Address:=tempaddress;
5257
5258          li:=codelist2.Items.Add;
5259          if code[numberofcodes-1].modulename<>'' then
5260            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
5261          else
5262            li.Caption:=inttohex(tempaddress,8);
5263
5264          li.SubItems.Add(tempdescription);
5265        end;
5266      end;
5267
5268    end;
5269
5270    //comments
5271    if merge then comments.Memo1.Lines.Add(filename);
5272    i:=ctfile.Size-ctfile.Position;
5273    getmem(x,i+1);
5274    ctfile.readbuffer(x^,i);
5275
5276    x[i]:=chr(0);
5277    comments.Memo1.Text:=comments.Memo1.Text+x;
5278
5279    freemem(x);
5280end;
5281
5282
5283procedure LoadV2(filename: string; ctfile: tfilestream;merge: boolean);
5284var newrec: MemoryRecordV2;
5285    records: dword;
5286    i,j,k: integer;
5287    addrecord: boolean;
5288
5289    x: pchar;
5290    nrofbytes:  byte;
5291    tempbefore: array of byte;
5292    tempactual: array of byte;
5293    tempafter: array of byte;
5294    tempaddress: dword;
5295    tempdescription: string;
5296    li: tlistitem;
5297begin
5298    ctfile.ReadBuffer(records,4);
5299    for i:=0 to records-1 do
5300    begin
5301      ctfile.ReadBuffer(newrec,sizeof(MemoryRecordV2));
5302
5303      addrecord:=true;
5304      if merge then
5305        //find it in the current list, if it is in, dont add
5306        for j:=0 to mainform.NumberOfRecords-1 do
5307          if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
5308          begin
5309            if (newrec.VarType=5) then
5310              if (newrec.Bit<>mainform.memrec[j].bit) or (newrec.bitlength<>mainform.memrec[j].bitlength) then continue;
5311            addrecord:=false;
5312            break;
5313          end;
5314
5315      if addrecord then
5316      begin
5317        with mainform do
5318        begin
5319         
5320          inc(numberofrecords);
5321          reservemem;
5322          memrec[numberofrecords-1].Description:=newrec.Description;
5323          memrec[numberofrecords-1].Address:=newrec.Address;
5324          memrec[numberofrecords-1].VarType:=newrec.VarType;
5325          memrec[numberofrecords-1].unicode:=false;
5326          memrec[numberofrecords-1].Bit:=newrec.Bit;
5327          memrec[numberofrecords-1].bitlength:=newrec.bitlength;
5328          memrec[numberofrecords-1].Frozen:=false;
5329          memrec[numberofrecords-1].FrozenValue:=0;
5330          memrec[numberofrecords-1].Frozendirection:=0;
5331          memrec[numberofrecords-1].ShowAsHex:=false;
5332        end;
5333      end;
5334    end;
5335
5336
5337    ctfile.ReadBuffer(records,4);
5338    for i:=0 to records-1 do
5339    begin
5340      ctfile.ReadBuffer(tempaddress,4);
5341
5342      ctfile.ReadBuffer(nrofbytes,1);
5343      setlength(tempbefore,nrofbytes);
5344      ctfile.ReadBuffer(pointer(tempbefore)^,nrofbytes);
5345
5346      ctfile.ReadBuffer(nrofbytes,1);
5347      setlength(tempactual,nrofbytes);
5348      ctfile.ReadBuffer(pointer(tempactual)^,nrofbytes);
5349
5350      ctfile.ReadBuffer(nrofbytes,1);
5351      setlength(tempafter,nrofbytes);
5352      ctfile.ReadBuffer(pointer(tempafter)^,nrofbytes);
5353
5354      ctfile.ReadBuffer(nrofbytes,1);
5355      getmem(x,nrofbytes+1);
5356      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
5357      x[nrofbytes]:=#0;
5358      tempdescription:=x;
5359      freemem(x);
5360
5361      addrecord:=true;
5362
5363      if merge then
5364      begin
5365        for j:=0 to advancedoptions.numberofcodes-1 do
5366          if (advancedoptions.code[j].Address=tempaddress) then
5367          begin
5368            addrecord:=false;
5369            break;
5370          end;
5371
5372      end;
5373
5374      if addrecord then
5375      begin
5376        with advancedoptions do
5377        begin
5378          inc(numberofcodes);
5379          setlength(code,numberofcodes);
5380
5381          setlength(code[numberofcodes-1].before,length(tempbefore));
5382          for k:=0 to length(tempbefore)-1 do
5383            code[numberofcodes-1].before[k]:=tempbefore[k];
5384
5385          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
5386          for k:=0 to length(tempactual)-1 do
5387            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
5388
5389          setlength(code[numberofcodes-1].after,length(tempafter));
5390          for k:=0 to length(tempafter)-1 do
5391            code[numberofcodes-1].after[k]:=tempafter[k];
5392
5393          code[numberofcodes-1].Address:=tempaddress;
5394
5395          li:=codelist2.Items.Add;
5396          if code[numberofcodes-1].modulename<>'' then
5397            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
5398          else
5399            li.Caption:=inttohex(tempaddress,8);
5400
5401          li.SubItems.Add(tempdescription);
5402        end;
5403      end;
5404
5405    end;
5406
5407    //comments
5408    if merge then comments.Memo1.Lines.Add(filename);
5409    i:=ctfile.Size-ctfile.Position;
5410    getmem(x,i+1);
5411    ctfile.readbuffer(x^,i);
5412
5413    x[i]:=chr(0);
5414    comments.Memo1.Text:=comments.Memo1.Text+x;
5415
5416    freemem(x);
5417end;
5418
5419procedure LoadV1(filename: string; ctfile: tfilestream;merge: boolean);
5420var newrec: MemoryRecordV1;
5421    records: dword;
5422    i,j,k: integer;
5423    addrecord: boolean;
5424
5425    x: pchar;
5426    nrofbytes:  byte;
5427    tempbefore: array of byte;
5428    tempactual: array of byte;
5429    tempafter: array of byte;
5430    tempaddress: dword;
5431    tempdescription: string;
5432    li: tlistitem;
5433begin
5434    ctfile.ReadBuffer(records,4);
5435    for i:=0 to records-1 do
5436    begin
5437      ctfile.ReadBuffer(newrec,sizeof(MemoryRecordV1));
5438
5439      addrecord:=true;
5440      if merge then
5441        //find it in the current list, if it is in, dont add
5442        for j:=0 to mainform.NumberOfRecords-1 do
5443          if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
5444          begin
5445            if (newrec.VarType=5) then
5446              if (newrec.Bit<>mainform.memrec[j].bit) or (newrec.bitlength<>mainform.memrec[j].bitlength) then continue;
5447            addrecord:=false;
5448            break;
5449          end;
5450
5451      if addrecord then
5452      begin
5453        with mainform do
5454        begin
5455          inc(numberofrecords);
5456          reservemem;
5457          memrec[numberofrecords-1].Description:=newrec.Description;
5458          memrec[numberofrecords-1].Address:=newrec.Address;
5459          memrec[numberofrecords-1].VarType:=newrec.VarType;
5460          memrec[numberofrecords-1].unicode:=false;
5461          memrec[numberofrecords-1].Bit:=newrec.Bit;
5462          memrec[numberofrecords-1].bitlength:=newrec.bitlength;
5463          memrec[numberofrecords-1].Frozen:=false;
5464          memrec[numberofrecords-1].FrozenValue:=0;
5465          memrec[numberofrecords-1].Frozendirection:=0;
5466          memrec[numberofrecords-1].ShowAsHex:=false;
5467        end;
5468      end;
5469    end;
5470
5471
5472    ctfile.ReadBuffer(records,4);
5473    for i:=0 to records-1 do
5474    begin
5475      ctfile.ReadBuffer(tempaddress,4);
5476
5477      ctfile.ReadBuffer(nrofbytes,1);
5478      setlength(tempbefore,nrofbytes);
5479      ctfile.ReadBuffer(pointer(tempbefore)^,nrofbytes);
5480
5481      ctfile.ReadBuffer(nrofbytes,1);
5482      setlength(tempactual,nrofbytes);
5483      ctfile.ReadBuffer(pointer(tempactual)^,nrofbytes);
5484
5485      ctfile.ReadBuffer(nrofbytes,1);
5486      setlength(tempafter,nrofbytes);
5487      ctfile.ReadBuffer(pointer(tempafter)^,nrofbytes);
5488
5489      ctfile.ReadBuffer(nrofbytes,1);
5490      getmem(x,nrofbytes+1);
5491      ctfile.ReadBuffer(pointer(x)^,nrofbytes);
5492      x[nrofbytes]:=#0;
5493      tempdescription:=x;
5494      freemem(x);
5495
5496      addrecord:=true;
5497
5498      if merge then
5499      begin
5500        for j:=0 to advancedoptions.numberofcodes-1 do
5501          if (advancedoptions.code[j].Address=tempaddress) then
5502          begin
5503            addrecord:=false;
5504            break;
5505          end;
5506
5507      end;
5508
5509      if addrecord then
5510      begin
5511        with advancedoptions do
5512        begin
5513          inc(numberofcodes);
5514          setlength(code,numberofcodes);
5515
5516          setlength(code[numberofcodes-1].before,length(tempbefore));
5517          for k:=0 to length(tempbefore)-1 do
5518            code[numberofcodes-1].before[k]:=tempbefore[k];
5519
5520          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
5521          for k:=0 to length(tempactual)-1 do
5522            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
5523
5524          setlength(code[numberofcodes-1].after,length(tempafter));
5525          for k:=0 to length(tempafter)-1 do
5526            code[numberofcodes-1].after[k]:=tempafter[k];
5527
5528          code[numberofcodes-1].Address:=tempaddress;
5529
5530          li:=codelist2.Items.Add;
5531          if code[numberofcodes-1].modulename<>'' then
5532            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
5533          else
5534            li.Caption:=inttohex(tempaddress,8);
5535
5536          li.SubItems.Add(tempdescription);
5537        end;
5538      end;
5539
5540    end;
5541
5542    //comments
5543    if merge then comments.Memo1.Lines.Add(filename);
5544    i:=ctfile.Size-ctfile.Position;
5545    getmem(x,i+1);
5546    ctfile.readbuffer(x^,i);
5547
5548    x[i]:=chr(0);
5549    comments.Memo1.Text:=comments.Memo1.Text+x;
5550
5551    freemem(x);
5552end;
5553
5554procedure SaveCEM(Filename:string;address,size:dword);
5555var memfile: TFilestream;
5556    buf: pointer;
5557    temp:dword;
5558begin
5559  memfile:=Tfilestream.Create(filename,fmCreate);
5560  buf:=nil;
5561  try
5562    getmem(buf,size);
5563    if readprocessmemory(processhandle,pointer(address),buf,size,temp) then
5564    begin
5565      memfile.WriteBuffer(pchar('CHEATENGINE')^,11);
5566      temp:=1; //version
5567      memfile.WriteBuffer(temp,4);
5568      memfile.WriteBuffer(address,4);
5569      memfile.WriteBuffer(buf^,size);
5570    end else messagedlg('The region at '+IntToHex(address,8)+' was partially or completly unreadable',mterror,[mbok],0);
5571  finally
5572    memfile.free;
5573    freemem(buf);
5574  end;
5575end;
5576
5577procedure LoadCEM(filename:string);
5578var memfile: TFilestream;
5579    check: pchar;
5580    mem: pointer;
5581    temp,ar:dword;
5582    a:dword;
5583begin
5584  check:=nil;
5585  try
5586    memfile:=Tfilestream.Create(filename,fmopenread);
5587    getmem(check,12);
5588    memfile.ReadBuffer(check^,11);
5589    check[11]:=#0;
5590    if check='CHEATENGINE' then
5591    begin
5592      memfile.ReadBuffer(temp,4);
5593      if temp<>1 then raise exception.Create('The version of '+filename+' is incompatible with this CE version');
5594      memfile.ReadBuffer(temp,4);
5595      //temp=startaddress
5596
5597      getmem(mem,memfile.Size-memfile.Position);
5598      memfile.ReadBuffer(mem^,memfile.Size-memfile.Position);
5599
5600
5601      RewriteCode(processhandle,temp,mem,memfile.Size-memfile.Position);
5602    end else raise exception.Create(filename+' doesn''t contain needed information where to place the memory');
5603  finally
5604    freemem(check);
5605    memfile.free;
5606  end;
5607end;
5608
5609
5610
5611procedure LoadCT(filename: string; merge: boolean);
5612var ctfile: TFilestream;
5613    version: dword;
5614    x: pchar;
5615    f: TSearchRec;
5616begin
5617  ctfile:=Tfilestream.Create(filename,fmopenread);
5618  try
5619    getmem(x,12);
5620    ctfile.ReadBuffer(x^,11);
5621    x[11]:=#0;
5622
5623    if x<>'CHEATENGINE' then
5624    begin
5625      if messagedlg('This is NOT a valid Cheat Engine table. Are you sure you want to load it?',mtWarning, [mbyes,mbno],0) = mrno then exit;
5626    end;
5627
5628    ctfile.ReadBuffer(version,4);
5629    if version>CurrentTableVersion then
5630      raise exception.Create('This table was made with a newer version of Cheat Engine and isn''t supported. Download the latest version from the Cheat Engine website');
5631
5632    //now load the table loader for each supported version
5633    case version of
5634      1: LoadV1(filename,ctfile,merge);
5635      2: LoadV2(filename,ctfile,merge);
5636      3: LoadV3(filename,ctfile,merge);
5637      4: LoadV4(filename,ctfile,merge);
5638      5: LoadV5(filename,ctfile,merge);
5639      6,7,8,9: LoadV6(filename,ctfile,merge);
5640      else raise exception.Create('This table was made with a version of Cheat Engine that isn''t supported anymore! (The table is propably messed up)');
5641    end;
5642
5643    //see if there are filename.m* files
5644    zeromemory(@f,sizeof(f));
5645    if findfirst(filename+'.m*',faAnyFile,f)=0 then
5646    begin
5647      if messagedlg('Some memory files where detected for this table. Do you want to load them now?',mtConfirmation,[mbyes,mbno],0)=mryes then
5648      begin
5649        loadcem(extractfilepath(filename)+f.Name);
5650        while findnext(f)=0 do loadcem(extractfilepath(filename)+f.Name);
5651      end;
5652    end;
5653  finally
5654    ctfile.free;
5655  end;
5656
5657
5658end;
5659
5660procedure LoadCT3(filename: string; merge: boolean);
5661var loadfile: File;
5662    i,j,k: integer;
5663    actualread: dword;
5664    Controle: String[6];
5665    records:  dword;
5666    ct3rec:   MemoryRecordcet3;
5667
5668    addrecord: boolean;
5669    x: pchar;
5670
5671    nrofbytes:  byte;
5672    tempbefore: array of byte;
5673    tempactual: array of byte;
5674    tempafter: array of byte;
5675    tempaddress: dword;
5676    tempdescription: string;
5677    li: tlistitem;
5678begin
5679  assignfile(LoadFile,filename);
5680  reset(LoadFile,1);
5681
5682
5683  //check version
5684  blockread(LoadFile,controle,sizeof(controle),actualread);
5685  if controle<>'CET3' then
5686  begin
5687    closefile(LoadFile);
5688    Raise Exception.Create('Invalid Cheat Engine table');
5689  end;
5690
5691  blockread(Loadfile,records,4,actualread);
5692
5693  i:=0;
5694  actualread:=sizeof(MemoryRecordCET3);
5695  while (i<records) and (actualread=sizeof(MemoryRecordCET3)) do
5696  begin
5697    blockread(LoadFile,ct3rec,sizeof(MemoryRecordCET3),actualread);
5698    if actualread=sizeof(MemoryRecordCET3) then
5699    begin
5700      addrecord:=true;
5701      if merge then
5702        //find it in the current list, if it is in, dont add
5703        for j:=0 to mainform.NumberOfRecords-1 do
5704          if (mainform.memrec[j].Address=ct3rec.Address) and (mainform.memrec[j].VarType=ct3rec.VarType) then
5705          begin
5706            if (ct3rec.VarType=5) then
5707              if (ct3rec.Bit<>mainform.memrec[j].bit) then continue;
5708
5709            addrecord:=false;
5710            break;
5711          end;
5712
5713      if addrecord then
5714      begin
5715        with mainform do
5716        begin
5717          inc(numberofrecords);
5718          reservemem;
5719          memrec[numberofrecords-1].Description:=ct3rec.Description;
5720          memrec[numberofrecords-1].Address:=ct3rec.Address;
5721          memrec[numberofrecords-1].VarType:=ct3rec.VarType;
5722          memrec[numberofrecords-1].Bit:=ct3rec.Bit;
5723          memrec[numberofrecords-1].bitlength:=1;
5724          memrec[numberofrecords-1].Frozen:=false;
5725          memrec[numberofrecords-1].FrozenValue:=0;
5726        end;
5727      end;
5728
5729
5730    end;
5731
5732    inc(i);
5733  end;
5734
5735  blockread(LoadFile,controle,sizeof(controle),actualread);
5736  if (actualread>0) then
5737  begin
5738    if (controle<>'CET3AA') then
5739    begin
5740      //old version of CT3
5741      if merge then comments.Memo1.Lines.Add(filename);
5742
5743      seek(loadfile,filepos(loadfile)-sizeof(controle));
5744      i:=filesize(loadfile)-filepos(Loadfile);
5745      getmem(x,i+1);
5746      blockread(loadfile,x^,i,actualread);
5747
5748      x[i]:=chr(0);
5749      comments.Memo1.Text:=comments.Memo1.Text+x;
5750      freemem(x);
5751
5752      closefile(loadfile);
5753      exit;
5754    end;
5755
5756
5757
5758    blockread(Loadfile,records,4,actualread);
5759
5760    for i:=0 to records-1 do
5761    begin
5762      blockread(loadfile,nrofbytes,1,actualread);
5763      setlength(tempbefore,nrofbytes);
5764      blockread(loadfile,pointer(tempbefore)^,nrofbytes,actualread);
5765
5766      blockread(loadfile,nrofbytes,1,actualread);
5767      setlength(tempactual,nrofbytes);
5768      blockread(loadfile,pointer(tempactual)^,nrofbytes,actualread);
5769
5770      blockread(loadfile,nrofbytes,1,actualread);
5771      setlength(tempafter,nrofbytes);
5772      blockread(loadfile,pointer(tempafter)^,nrofbytes,actualread);
5773
5774      blockread(loadfile,nrofbytes,1,actualread);
5775      getmem(x,nrofbytes+1);
5776      blockread(loadfile,pointer(x)^,nrofbytes,actualread);
5777      x[nrofbytes]:=#0;
5778      tempdescription:=x;
5779      freemem(x);
5780
5781      blockread(loadfile,tempaddress,4,actualread);
5782
5783      addrecord:=true;
5784
5785      if merge then
5786      begin
5787        for j:=0 to advancedoptions.numberofcodes-1 do
5788          if (advancedoptions.code[j].Address=tempaddress) then
5789          begin
5790            addrecord:=false;
5791            break;
5792          end;
5793
5794      end;
5795
5796      if addrecord then
5797      begin
5798        with advancedoptions do
5799        begin
5800          inc(numberofcodes);
5801          setlength(code,numberofcodes);
5802
5803          setlength(code[numberofcodes-1].before,length(tempbefore));
5804          for k:=0 to length(tempbefore)-1 do
5805            code[numberofcodes-1].before[k]:=tempbefore[k];
5806
5807          setlength(code[numberofcodes-1].actualopcode,length(tempactual));
5808          for k:=0 to length(tempactual)-1 do
5809            code[numberofcodes-1].actualopcode[k]:=tempactual[k];
5810
5811          setlength(code[numberofcodes-1].after,length(tempafter));
5812          for k:=0 to length(tempafter)-1 do
5813            code[numberofcodes-1].after[k]:=tempafter[k];
5814
5815          code[numberofcodes-1].Address:=tempaddress;
5816
5817          li:=codelist2.Items.Add;
5818          if code[numberofcodes-1].modulename<>'' then
5819            li.Caption:=code[numberofcodes-1].modulename+'+'+inttohex(code[numberofcodes-1].offset,1)
5820          else
5821            li.Caption:=inttohex(tempaddress,8);
5822
5823          li.SubItems.Add(tempdescription);
5824        end;
5825      end;
5826    end;
5827
5828    advancedoptions.numberofcodes:=records;
5829
5830    //comments
5831    if merge then comments.Memo1.Lines.Add(filename);
5832    i:=filesize(loadfile)-filepos(Loadfile);
5833    getmem(x,i+1);
5834    blockread(loadfile,x^,i,actualread);
5835
5836    x[i]:=chr(0);
5837    comments.Memo1.Text:=comments.Memo1.Text+x;
5838
5839    freemem(x);
5840
5841  end;
5842
5843  closefile(loadfile);
5844end;
5845
5846procedure LoadCT2(filename: string; merge: boolean);
5847var loadfile: File;
5848    actualread: dword;
5849    oldrec: MemoryrecordOld;
5850    i,j: integer;
5851    addrecord: boolean;
5852begin
5853  assignfile(LoadFile,filename);
5854  reset(LoadFile,1);
5855
5856  i:=0;
5857
5858  blockread(LoadFile,oldrec,sizeof(memoryrecordold),actualread);
5859  while actualread=sizeof(MemoryRecordold) do
5860  begin
5861    addrecord:=true;
5862    if merge then
5863      //find it in the current list, if it is in, dont add
5864      for j:=0 to mainform.NumberOfRecords-1 do
5865        if (mainform.memrec[j].Address=oldrec.Address) and (mainform.memrec[j].VarType=oldrec.VarType) then
5866        begin
5867          addrecord:=false;
5868          break;
5869        end;
5870
5871    if addrecord then
5872    begin
5873      with mainform do
5874      begin
5875        inc(numberofrecords);
5876        reservemem;
5877        memrec[numberofrecords-1].Description:=oldrec.Description;
5878        memrec[numberofrecords-1].Address:=oldrec.Address;
5879        memrec[numberofrecords-1].VarType:=oldrec.VarType;
5880        memrec[numberofrecords-1].Bit:=0;
5881        memrec[numberofrecords-1].bitlength:=0;
5882        memrec[numberofrecords-1].Frozen:=false;
5883        memrec[numberofrecords-1].FrozenValue:=0;
5884      end;
5885    end;
5886
5887    inc(i);
5888    blockread(LoadFile,oldrec,sizeof(memoryrecordold),actualread);
5889  end;
5890
5891  closefile(LoadFile);
5892end;
5893
5894procedure LoadCET(filename: string; merge: boolean);
5895var CETFile: Textfile;
5896    i,j: integer;
5897    str: string;
5898    inuse: array [0..255] of boolean;
5899    NewRec: array [0..255] of MemoryrecordV2;
5900    addrecord:boolean;
5901begin
5902  //set it in memrec at once, I'll handle the counter later
5903  assignfile(CETfile,filename);
5904  reset(CETFile);
5905
5906  for i:=0 to 254 do
5907    readln(CETFile,str);      //frozen state
5908
5909  for i:=0 to 254 do
5910    readln(CETFile,str); //frozenvalue
5911
5912  for i:=0 to 254 do //if the record is active or not
5913  begin
5914    readln(CETFile,str);
5915    inuse[i]:=str='1';
5916  end;
5917
5918  for i:=0 to 254 do
5919  begin
5920    readln(CETFile,str);
5921    newrec[i].Address:=StrToInt(str);
5922  end;
5923
5924  for i:=0 to 254 do
5925  begin
5926    readln(CETFile,str);
5927    newrec[i].VarType:=StrToInt(str);  //vartype assignments should be the same. (I hope)
5928  end;
5929
5930  for i:=0 to 254 do
5931  begin
5932    readln(CETFile,str);
5933    newrec[i].Description:=str;
5934  end;
5935
5936  //now add to the list
5937  for i:=0 to 254 do
5938  begin
5939    if inuse[i] then
5940    begin
5941      addrecord:=true;
5942      if merge then
5943      begin
5944        //find it in the current list, if it is in, dont add
5945        for j:=0 to mainform.NumberOfRecords-1 do
5946          if (mainform.memrec[j].Address=newrec[i].Address) and (mainform.memrec[j].VarType=newrec[i].VarType) then
5947          begin
5948            addrecord:=false;
5949            break;
5950          end;
5951      end;
5952
5953      if addrecord then
5954      begin
5955        inc(mainform.numberofrecords);
5956        mainform.reserveMem;
5957        mainform.memrec[mainform.NumberOfRecords-1].Address:=newrec[i].Address;
5958        mainform.memrec[mainform.NumberOfRecords-1].VarType:=newrec[i].VarType;
5959        mainform.memrec[mainform.NumberOfRecords-1].Description:=newrec[i].Description;
5960      end;
5961
5962    end;
5963  end;
5964
5965  closefile(CETFile);
5966
5967end;
5968
5969Procedure LoadAMT(filename:string;merge:boolean);
5970var x,y,z: string;
5971    f: textfile;
5972    i,j: integer;
5973
5974    first: boolean;
5975    linenr: integer;
5976    lines: array of string;
5977
5978    records: integer;
5979    tempmemrec: array of MemoryrecordV3;
5980
5981    addrecord: boolean;
5982begin
5983  linenr:=0;
5984  assignfile(f,filename);
5985  reset(f);
5986
5987  try
5988    readln(f,x);
5989
5990    //parse the text
5991    firsT:=false;
5992    for i:=1 to length(x) do
5993    begin
5994      if x[i]='"' then
5995      begin
5996        if not first then
5997        begin
5998          first:=true;
5999          y:='';
6000          continue;
6001        end
6002        else
6003        begin
6004          inc(linenr);
6005          setlength(lines,linenr);
6006          lines[linenr-1]:=y;
6007          first:=false;
6008        end;
6009
6010      end
6011      else if first then y:=y+x[i];
6012    end;
6013
6014    if lines[0]<>'ArtMoney Table' then raise exception.Create('This is not a valid ArtMoney Table');
6015    if lines[1]='4' then
6016    begin
6017      records:=(length(lines)-17) div 5;
6018
6019      setlength(tempmemrec,records);
6020
6021      for i:=0 to records-1 do
6022      begin
6023        tempmemrec[i].Description:=lines[17+5*i];
6024
6025        x:=lines[(17+5*i)+1]; //address
6026        y:=lines[(17+5*i)+4]; //valuetype
6027
6028        if length(x)=8 then
6029        begin
6030          try
6031            tempmemrec[i].address:=StrToInt('$'+x)
6032          except
6033            ;
6034          end;
6035        end
6036        else
6037        begin
6038          //example:  P6F71C7B8,1688
6039          z:='';
6040          z:=copy(x,pos(',',x)+1,length(x));
6041
6042          tempmemrec[i].address:=0;
6043          tempmemrec[i].ispointer:=true;
6044          //pointer stuff
6045          setlength(tempmemrec[i].pointers,1);
6046          try
6047            tempmemrec[i].pointers[0].address:=0;
6048            tempmemrec[i].pointers[0].offset:=StrToInt(z);
6049          except
6050            setlength(tempmemrec[i].pointers,0);
6051            tempmemrec[i].IsPointer:=false;
6052          end;
6053        end;
6054
6055        if length(y)<3 then continue;
6056        if y[2]+y[3]='i1' then tempmemrec[i].vartype:=0;
6057        if y[2]+y[3]='i2' then tempmemrec[i].vartype:=1;
6058        if y[2]+y[3]='i4' then tempmemrec[i].vartype:=2;
6059        if y[2]+y[3]='i8' then tempmemrec[i].vartype:=6;
6060        if y[2]+y[3]='f4' then tempmemrec[i].vartype:=3;
6061        if y[2]+y[3]='f8' then tempmemrec[i].vartype:=4;
6062        if y[1]+y[2]='nt' then tempmemrec[i].VarType:=7;
6063        if y[1]+y[2]='ns' then tempmemrec[i].VarType:=7;
6064        if y[1]+y[2]='np' then tempmemrec[i].VarType:=7;
6065      end;
6066    end
6067    else if lines[1]='5' then
6068    begin
6069
6070      records:=(length(lines)-18) div 7;
6071
6072      setlength(tempmemrec,records);
6073
6074      for i:=0 to records-1 do
6075      begin
6076        tempmemrec[i].Description:=lines[18+7*i];
6077
6078        x:=lines[(18+7*i)+1]; //address
6079        y:=lines[(18+7*i)+5]; //valuetype
6080
6081        if length(x)=8 then
6082        begin
6083          try
6084            tempmemrec[i].address:=StrToInt('$'+x)
6085          except
6086            ;
6087          end;
6088        end
6089        else
6090        begin
6091          //example:  P6F71C7B8,1688
6092          z:='';
6093          z:=copy(x,pos(',',x)+1,length(x));
6094
6095          tempmemrec[i].address:=0;
6096          tempmemrec[i].ispointer:=true;
6097          //pointer stuff
6098          setlength(tempmemrec[i].pointers,1);
6099          try
6100            tempmemrec[i].pointers[0].address:=0;
6101            tempmemrec[i].pointers[0].offset:=StrToInt(z);
6102          except
6103            setlength(tempmemrec[i].pointers,0);
6104            tempmemrec[i].IsPointer:=false;
6105          end;
6106        end;
6107
6108        if length(y)<3 then continue;
6109        if y[2]+y[3]='i1' then tempmemrec[i].vartype:=0;
6110        if y[2]+y[3]='i2' then tempmemrec[i].vartype:=1;
6111        if y[2]+y[3]='i4' then tempmemrec[i].vartype:=2;
6112        if y[2]+y[3]='i8' then tempmemrec[i].vartype:=6;
6113        if y[2]+y[3]='f4' then tempmemrec[i].vartype:=3;
6114        if y[2]+y[3]='f8' then tempmemrec[i].vartype:=4;
6115        if y[1]+y[2]='nt' then tempmemrec[i].VarType:=7;
6116        if y[1]+y[2]='ns' then tempmemrec[i].VarType:=7;
6117        if y[1]+y[2]='np' then tempmemrec[i].VarType:=7;
6118      end;
6119    end else raise exception.Create('Cheat Engine can''t load this version of ArtMoney tables:'+lines[1]);
6120
6121    for i:=0 to records-1 do
6122    begin
6123      addrecord:=true;
6124      if merge then
6125      begin
6126        //find it in the current list, if it is in, dont add
6127        for j:=0 to mainform.NumberOfRecords-1 do
6128          if (mainform.memrec[j].Address=tempmemrec[i].Address) and (mainform.memrec[j].VarType=tempmemrec[i].VarType) then
6129          begin
6130            addrecord:=false;
6131            break;
6132          end;
6133      end;
6134
6135      if addrecord then
6136      begin
6137        inc(mainform.numberofrecords);
6138        mainform.reserveMem;
6139        mainform.memrec[mainform.NumberOfRecords-1].Address:=tempmemrec[i].Address;
6140        mainform.memrec[mainform.NumberOfRecords-1].VarType:=tempmemrec[i].VarType;
6141        mainform.memrec[mainform.NumberOfRecords-1].Description:=tempmemrec[i].Description;
6142        mainform.memrec[mainform.NumberOfRecords-1].bit:=5;
6143{$ifndef net}
6144        mainform.memrec[mainform.NumberOfRecords-1].IsPointer:=tempmemrec[i].IsPointer;
6145        if tempmemrec[i].IsPointer then
6146        begin
6147          setlength(mainform.memrec[mainform.NumberOfRecords-1].pointers,1);
6148          mainform.memrec[mainform.NumberOfRecords-1].pointers[0].address:=tempmemrec[i].pointers[0].Address;
6149          mainform.memrec[mainform.NumberOfRecords-1].pointers[0].offset:=tempmemrec[i].pointers[0].offset;
6150        end;
6151{$endif}
6152      end;
6153    end;
6154
6155  finally
6156    closefile(f);
6157  end;
6158
6159  //load a ArtMoneyTable
6160  {
61610 "ArtMoney Table":Identifier
61621 "5":version???
61632 "7.06":Artmoney version
61643 "19783D10"
61654 "1C673566": crc?
61665 "SE": SE version
61676 "Tutorial":Application title
61687 "Tutorial.exe":Application processname
61698 "12/23/2003":Date
61709 "2":???
617110 "5":system
617211 "1":system
617312 "Service Pack 1":Service pack nr
617413 "Eric":user
617514 "":???
617615 "":???
617716 "":???
617817 "":???
6179
618018+0 "Value 1":Description
618118+1 "008B2768":address
618218+2 ""
618318+3 ""
618418+4 ""
618518+5 "ni4":integer 4 byte
618618+6 ""
6187
618818+7 "Value 2":description
618918+8 "008B6CF8"
619018+9 ""
619118+10 ""
619218+11 ""
619318+12 "ni4":integer 4 byte
619418+13 ""
6195
6196//---------------------------------------------
6197"ArtMoney Table":Identifier
6198"5":???
6199"7.06":version of artmoney
6200"1978830A":??
6201"382F0805":??
6202"SE":SE version
6203"Warcraft 3":process title
6204"War3.exe":process exe
6205"10/12/2002":date created
6206"2":??
6207"5":system
6208"1":system
6209"":special info about system
6210"ArtMoney Team":name
6211"Russia, Samara":location
6212"artmoney@mail.ru":email
6213"":???
6214"":???
6215
6216"Experience":Description
6217"P6F71C7B8,1684":address
6218"90,6,0,0,88,6,,1":???
6219"hero 1"
6220""
6221"ni4":integer 4 bytes
6222"":
6223
6224
6225
6226"Points":description
6227"P6F71C7B8,1688":address
6228"90,6,0,0,88,6,,1":??
6229"hero 1":
6230"":?
6231"ni4":integer 4 bytes
6232""
6233
6234"Power"
6235"P6F71C7B8,1692"
6236"90,6,0,0,88,6,,1"
6237"hero 1"
6238""
6239"ni4"
6240""
6241
6242"Dexterity"
6243"P6F71C7B8,1712"
6244"90,6,0,0,88,6,,1"
6245"hero 1"
6246""
6247"ni4"
6248""
6249
6250"Health"
6251"P6F71C7B8,1708"
6252"90,6,0,0,88,6,,1"
6253"hero 1"
6254""
6255"nf4":float 4 bytes
6256""
6257
6258"Manna"
6259"P6F71C7B8,1744"
6260"90,6,0,0,88,6,,1"
6261"hero 1"
6262""
6263"nf4":float 4 bytes
6264""
6265  }
6266
6267{
62680 "ArtMoney Table": ?
62691 "4":?
62702 "6.21":?
62713 "19786E3F":?
62724 "382F0805":?
62735 "Warcraft 3":?
62746 "War3.exe":?
62757 "10/12/2002":?
62768 "2":?
62779 "5":?
627810 "1":?
627911 "":?
628012 "John Sazonov":?
628113 "Russia, Perm":?
628214 "evg-sazonov@yandex.ru":?
628315 "":?
628416 "":?
6285
628617 "Experience":?
6287"0390242C":?
6288"90,6,0,0,88,6,,1":?
6289"":?
6290"ni4":?
6291
6292"Points":?
6293"03902430":?
6294"90,6,0,0,88,6,,1":?
6295"":?
6296"ni4":?
6297
6298"Power":?
6299"03902434":?
6300"90,6,0,0,88,6,,1":?
6301"":?
6302"ni4":?
6303
6304"Dexterity":?
6305"03902448":?
6306"90,6,0,0,88,6,,1":?
6307"":?
6308"ni4":?
6309
6310"Health":?
6311"03902444":?
6312"90,6,0,0,88,6,,1":?
6313"":?
6314"nf4":?
6315
6316"Manna":?
6317"03902468":?
6318"90,6,0,0,88,6,,1":?
6319"":?
6320"nf4"
6321
6322}
6323
6324end;
6325
6326Procedure LoadGH(Filename: string; merge: boolean);
6327var
6328  i,j: integer;
6329  loadfile: file;
6330
6331  count: integer;
6332  NewRec: MemoryrecordV2;
6333  charstoread: byte;
6334
6335  addrecord: boolean;
6336
6337  x: pchar;
6338  ar: dword;
6339begin
6340  assignfile(loadfile,filename);
6341  reset(loadfile,1);
6342
6343  count:=0;
6344  blockread(loadfile,count,2,ar);
6345  if ar<>2 then raise exception.create('error while loading this table');
6346
6347  //first the part that tells it's valid
6348  seek(loadfile,8);
6349  getmem(x,11);
6350  blockread(loadfile,x^,10);
6351  x[10]:=chr(0);
6352  if x<>'CDireccion' then
6353  begin
6354    closefile(loadfile);
6355    raise exception.create('This is not an valid GameHack table!');
6356  end;
6357
6358  for i:=0 to count-1 do
6359  begin
6360    //get address
6361    blockread(loadfile,newrec.Address,4);
6362
6363    //get VarType
6364    getmem(x,2);
6365    blockread(loadfile,x^,1);
6366    x[1]:=chr(0);
6367    if x='1' then newrec.VarType:=0 else
6368    if x='2' then newrec.VarType:=1 else
6369    if x='4' then newrec.VarType:=2 else
6370                  newrec.VarType:=0;
6371
6372    //get Description
6373    blockread(loadfile,CharsToRead,1);
6374    getmem(x,CharsToRead+1);
6375    blockread(loadfile,x^,CharsToRead);
6376    x[CharsToRead]:=chr(0);
6377    newrec.Description:=x;
6378    freemem(x);
6379
6380    //
6381    newrec.Frozen:=false;
6382
6383    getmem(x,7);
6384    if i<>count-1 then blockread(loadfile,x^,6);
6385    freemem(x);
6386
6387    addrecord:=true;
6388    if merge then
6389    begin
6390      //find it in the current list, if it is in, dont add
6391      for j:=0 to mainform.NumberOfRecords-1 do
6392        if (mainform.memrec[j].Address=newrec.Address) and (mainform.memrec[j].VarType=newrec.VarType) then
6393        begin
6394          addrecord:=false;
6395          break;
6396        end;
6397    end;
6398
6399    if addrecord then
6400    begin
6401      inc(mainform.numberofrecords);
6402      mainform.reserveMem;
6403      mainform.memrec[mainform.NumberOfRecords-1].Address:=newrec.Address;
6404      mainform.memrec[mainform.NumberOfRecords-1].VarType:=newrec.VarType;
6405      mainform.memrec[mainform.NumberOfRecords-1].Description:=newrec.Description;
6406    end;
6407  end;
6408end;
6409
6410procedure LoadTable(Filename: string;merge: boolean);
6411var
6412    actualread: Integer;
6413    i,j: Integer;
6414
6415    oldrec: MemoryrecordOld;
6416    ct3rec: MemoryRecordCET3;
6417
6418    NewRec: MemoryRecordV2;
6419    NewRec2: array [0..255] of MemoryrecordV2;
6420    Extension: String;
6421    Str: String;
6422    records: Dword;
6423    x: Pchar;
6424    charstoread: byte;
6425
6426    nrofbytes:  byte;
6427begin
6428  Extension:=uppercase(extractfileext(filename));
6429  {$ifndef net}
6430  If Extension='.EXE' then
6431  begin
6432    LoadExe(filename);
6433    exit;
6434  end;
6435  {$endif}
6436
6437  if not merge then
6438  begin
6439    //delete everything
6440
6441    with advancedoptions do
6442    begin
6443      for i:=0 to numberofcodes-1 do
6444      begin
6445        setlength(code[i].before,0);
6446        setlength(code[i].before,0);
6447        setlength(code[i].actualopcode,0);
6448        setlength(code[i].after,0);
6449      end;
6450
6451      Codelist2.Clear;
6452      setlength(code,0);
6453      numberofcodes:=0;
6454    end;
6455
6456    mainform.numberofrecords:=0;
6457    mainform.reservemem;  //erased...
6458
6459    Comments.Memo1.Text:='';
6460
6461  end;
6462
6463  if Extension='.PTR' then LoadPTR(filename,merge) else
6464  if Extension='.AMT' then LoadAMT(filename,merge) else
6465  if Extension='.GH' then LoadGH(filename,merge) else
6466  if Extension='.CET' then LoadCET(filename,merge) else
6467  if Extension='.CT2' then LoadCT2(filename,merge) else
6468  if Extension='.CT3' then LoadCT3(filename,merge) else
6469  if Extension='.CT' then LoadCT(filename,merge) else
6470  if Extension='.XML' then LoadXML(filename,merge) else
6471  raise exception.create('Unknown extention');
6472
6473  with mainform do
6474  begin
6475    oldnumberofrecords:=numberofrecords;
6476    oldcodelistcount:=advancedoptions.codelist2.Items.Count;
6477
6478    setlength(oldmemrec,numberofrecords);
6479    for i:=0 to numberofrecords-1 do
6480    begin
6481      oldmemrec[i].Description:=memrec[i].Description;
6482      oldmemrec[i].Address:=memrec[i].Address;
6483      oldmemrec[i].VarType:=memrec[i].VarType;
6484{$ifndef net}
6485      oldmemrec[i].IsPointer:=memrec[i].IsPointer;
6486      setlength(oldmemrec[i].pointers,length(memrec[i].pointers));
6487      for j:=0 to length(memrec[i].pointers)-1 do
6488      begin
6489        oldmemrec[i].pointers[j].Address:=memrec[i].pointers[j].Address;
6490        oldmemrec[i].pointers[j].offset:=memrec[i].pointers[j].offset;
6491      end;
6492{$endif}
6493      oldmemrec[i].Bit:=memrec[i].Bit;
6494      oldmemrec[i].bitlength:=memrec[i].bitlength;
6495      oldmemrec[i].Group:=memrec[i].Group;
6496    end;
6497
6498    oldcomments:=comments.Memo1.Text;
6499  end;
6500
6501
6502  mainform.scrollbar1.position:=0;
6503  mainform.savedialog1.FileName:='';
6504  for i:=0 to mainform.numberofrecords-1 do
6505  begin
6506    if mainform.hotkeys[i]>=10 then
6507      unregisterhotkey(mainform.handle,mainform.hotkeys[i]);
6508    mainform.hotkeys[i]:=-1;
6509    mainform.hotkeystrings[i]:='';
6510  end;
6511
6512  mainform.editedsincelastsave:=false;
6513
6514  if comments.memo1.Lines.Count>0 then
6515    mainform.Commentbutton.font.style:=mainform.Commentbutton.font.style+[fsBold]
6516  else
6517    mainform.Commentbutton.font.style:=mainform.Commentbutton.font.style-[fsBold];
6518end;
6519
6520type TExtradata=record
6521  address: dword;
6522  allocsize: dword;
6523end;
6524
6525procedure SaveStructToXMLNode(struct: TbaseStructure; Structures: IXMLNode);
6526var structure: IXMLNode;
6527    elements: IXMLNode;
6528    element: IXMLNode;
6529    i: integer;
6530begin
6531  Structure:=Structures.addChild('Structure');
6532  Structure.AddChild('Name').Text:=struct.name;
6533  elements:=Structure.AddChild('Elements');
6534  for i:=0 to length(struct.structelement)-1 do
6535  begin
6536    element:=elements.AddChild('Element');
6537    element.AddChild('Offset').Text:=inttostr(struct.structelement[i].offset);
6538    element.AddChild('Description').Text:=struct.structelement[i].description;
6539
6540    if struct.structelement[i].pointerto then
6541    begin
6542      element.AddChild('PointerTo').Text:='1';
6543      element.AddChild('PointerToSize').text:=inttostr(struct.structelement[i].pointertosize);
6544    end;
6545
6546    element.AddChild('Structurenr').Text:=inttostr(struct.structelement[i].structurenr);
6547    element.AddChild('Bytesize').Text:=inttostr(struct.structelement[i].bytesize);
6548
6549  end;
6550end;
6551
6552procedure SaveCTEntryToXMLNode(i: integer; Entries: IXMLNode);
6553var CheatRecord: IXMLNode;
6554    Pointers: IXMLNode;
6555    Offsets: IXMLNode;
6556    j: integer;
6557begin
6558  CheatRecord:=Entries.AddChild('CheatEntry');
6559  CheatRecord.AddChild('Description').Text:=mainform.memrec[i].Description;
6560
6561  if mainform.memrec[i].VarType<>255 then
6562  begin
6563    //normal address
6564    CheatRecord.AddChild('Address').Text:=inttohex(mainform.memrec[i].Address,8);
6565
6566    if (mainform.memrec[i].interpretableaddress<>'') and
6567       (uppercase(mainform.memrec[i].interpretableaddress)<>uppercase(inttohex(mainform.memrec[i].Address,8))) then
6568    CheatRecord.AddChild('InterpretableAddress').Text:=mainform.memrec[i].interpretableaddress;
6569  end
6570  else
6571  begin
6572    //auto assembler
6573    CheatRecord.AddChild('SpecialCode').Text:=mainform.memrec[i].autoassemblescript;
6574  end;
6575
6576  CheatRecord.AddChild('Type').Text:=inttostr(mainform.memrec[i].VarType);
6577
6578  if mainform.memrec[i].unicode then
6579    CheatRecord.AddChild('Unicode').Text:='1';
6580
6581  if mainform.memrec[i].VarType in [7,8] then
6582    CheatRecord.AddChild('Length').Text:=inttostr(mainform.memrec[i].Bit);
6583
6584  if mainform.memrec[i].VarType=5 then
6585  begin
6586    CheatRecord.AddChild('Bit').Text:=inttostr(mainform.memrec[i].Bit);
6587    CheatRecord.AddChild('Length').Text:=inttostr(mainform.memrec[i].BitLength);
6588  end;
6589
6590  if mainform.memrec[i].Group>0 then
6591    CheatRecord.AddChild('Group').text:=inttostr(mainform.memrec[i].Group);
6592       
6593  if mainform.memrec[i].ShowAsHex then
6594    CheatRecord.AddChild('HexadecimalDisplay').text:='1';
6595
6596  if mainform.memrec[i].ispointer then
6597  begin
6598    pointers:=CheatRecord.AddChild('Pointer');
6599    offsets:=pointers.AddChild('Offsets');
6600    for j:=0 to length(mainform.memrec[i].pointers)-1 do
6601      offsets.AddChild('Offset').Text:=inttohex(mainform.memrec[i].pointers[j].offset,4);
6602
6603    j:=length(mainform.memrec[i].pointers)-1;
6604    pointers.AddChild('Address').Text:=inttohex(mainform.memrec[i].pointers[j].Address,8);
6605    pointers.AddChild('InterpretableAddress').Text:=mainform.memrec[i].pointers[j].interpretableaddress;
6606  end;
6607end;
6608
6609
6610procedure SaveXML(Filename: string);
6611var doc: TXMLDocument;
6612    CheatTable: IXMLNode;
6613    Entries,Codes,Symbols, Structures, Comment: IXMLNode;
6614    CheatRecord, CodeRecord, SymbolRecord: IXMLNode;
6615    CodeBytes: IXMLNode;
6616    Offsets: IXMLNode;
6617
6618    CodeList: IXMLNode;
6619    Pointers: IXMLNode;
6620    i,j: integer;
6621
6622    sl: tstringlist;
6623    extradata: ^TExtraData;
6624    x: dword;
6625begin
6626  doc:=TXMLDocument.Create(application);
6627  try
6628
6629    doc.Options:=doc.Options+[doNodeAutoIndent];
6630    doc.Active:=true;
6631
6632    CheatTable:=doc.AddChild('CheatTable');
6633
6634    Entries:=CheatTable.AddChild('CheatEntries');
6635    for i:=0 to mainform.NumberOfRecords-1 do
6636    begin
6637      SaveCTEntryToXMLNode(i,entries);
6638
6639    end;
6640
6641    if advancedoptions.numberofcodes>0 then
6642    begin
6643      codes:=CheatTable.AddChild('CheatCodes');
6644      for i:=0 to advancedoptions.numberofcodes-1 do
6645      begin
6646        CodeRecord:=codes.AddChild('CodeEntry');
6647        CodeRecord.AddChild('Description').Text:=advancedoptions.codelist2.Items[i].SubItems[0];
6648        CodeRecord.AddChild('Address').Text:=inttohex(advancedoptions.code[i].Address,8);
6649        CodeRecord.AddChild('ModuleName').Text:=advancedoptions.code[i].modulename;
6650        CodeRecord.AddChild('ModuleNameOffset').Text:=inttohex(advancedoptions.code[i].offset,4);
6651
6652        //before
6653        CodeBytes:=CodeRecord.AddChild('Before');
6654        for j:=0 to length(advancedoptions.code[i].before)-1 do
6655          CodeBytes.AddChild('Byte').Text:=inttohex(advancedoptions.code[i].before[j],2);
6656
6657        //actual
6658        CodeBytes:=CodeRecord.AddChild('Actual');
6659        for j:=0 to length(advancedoptions.code[i].actualopcode)-1 do
6660          CodeBytes.AddChild('Byte').Text:=inttohex(advancedoptions.code[i].actualopcode[j],2);
6661
6662        //after
6663        CodeBytes:=CodeRecord.AddChild('After');
6664        for j:=0 to length(advancedoptions.code[i].after)-1 do
6665          CodeBytes.AddChild('Byte').Text:=inttohex(advancedoptions.code[i].after[j],2);
6666      end;
6667    end;
6668
6669    sl:=tstringlist.Create;
6670    try
6671      symhandler.EnumerateUserdefinedSymbols(sl);
6672      if sl.Count>0 then
6673      begin
6674        symbols:=CheatTable.AddChild('UserdefinedSymbols');
6675        for i:=0 to sl.Count-1 do
6676        begin
6677
6678          SymbolRecord:=symbols.AddChild('SymbolEntry');
6679          SymbolRecord.AddChild('Name').Text:=sl[i];
6680
6681          extradata:=pointer(sl.Objects[i]);
6682          SymbolRecord.AddChild('Address').Text:=IntToHex(extradata.address,8);
6683        end;
6684      end;
6685    finally
6686      sl.free;
6687    end;
6688
6689    if length(definedstructures)>0 then
6690    begin
6691      Structures:=CheatTable.AddChild('Structures');
6692      for i:=0 to length(definedstructures)-1 do
6693        SaveStructToXMLNode(definedstructures[i],Structures);
6694    end;
6695
6696    if comments.memo1.Lines.Count>0 then
6697    begin
6698      comment:=CheatTable.AddChild('Comments');
6699      for i:=0 to comments.Memo1.Lines.Count-1 do
6700        comment.AddChild('Comment').Text:=comments.Memo1.Lines[i]
6701    end;
6702
6703    doc.SaveToFile(filename);
6704  finally
6705    doc.Free;
6706  end;
6707end;
6708
6709procedure SaveTable(Filename: string);
6710var savefile: File;
6711    actualwritten: Integer;
6712    Controle: String[11];
6713    records, subrecords: dword;
6714    x: Pchar;
6715    i,j,k: integer;
6716    nrofbytes: byte;
6717
6718    temp: dword;
6719
6720    sl: tstringlist;
6721    extradata: ^TUDSEnum;
6722begin
6723//version=3;
6724  try
6725    if Uppercase(extractfileext(filename))='.XML' then
6726    begin
6727      SaveXML(filename);
6728      exit;
6729    end;
6730
6731    if Uppercase(extractfileext(filename))<>'.EXE' then
6732    begin
6733      assignfile(SaveFile,filename);
6734      rewrite(SaveFile,1); //sizeof(memoryrecord));
6735
6736      blockwrite(savefile,'CHEATENGINE',11,actualwritten);
6737      blockwrite(savefile,CurrentTableVersion,4,actualwritten);
6738
6739      Records:=mainform.numberofrecords;
6740
6741      blockwrite(savefile,records,4,actualwritten);
6742
6743      for i:=0 to mainform.NumberOfRecords-1 do
6744      begin
6745        j:=length(mainform.memrec[i].Description);
6746        blockwrite(savefile,j,sizeof(j),actualwritten);
6747        blockwrite(savefile,mainform.memrec[i].Description[1],length(mainform.memrec[i].Description),actualwritten);
6748        blockwrite(savefile,mainform.memrec[i].Address,sizeof(mainform.memrec[i].Address),actualwritten);
6749
6750        //interpretableaddress
6751        j:=length(mainform.memrec[i].interpretableaddress);
6752        x:=pchar(mainform.memrec[i].interpretableaddress);
6753        blockwrite(savefile,j,sizeof(j),actualwritten);
6754        blockwrite(savefile,pointer(x)^,j,actualwritten);
6755
6756
6757        blockwrite(savefile,mainform.memrec[i].VarType,sizeof(mainform.memrec[i].VarType),actualwritten);
6758        blockwrite(savefile,mainform.memrec[i].unicode,sizeof(mainform.memrec[i].unicode),actualwritten);
6759        blockwrite(savefile,mainform.memrec[i].Bit,sizeof(mainform.memrec[i].Bit),actualwritten);
6760        blockwrite(savefile,mainform.memrec[i].bitlength,sizeof(mainform.memrec[i].bitlength),actualwritten);
6761        blockwrite(savefile,mainform.memrec[i].Group,sizeof(mainform.memrec[i].Group),actualwritten);
6762        blockwrite(savefile,mainform.memrec[i].ShowAsHex,sizeof(mainform.memrec[i].showashex),actualwritten);
6763        blockwrite(savefile,mainform.memrec[i].ispointer,sizeof(mainform.memrec[i].ispointer),actualwritten);
6764
6765        temp:=length(mainform.memrec[i].pointers);
6766        blockwrite(savefile,temp,sizeof(temp),actualwritten);
6767        for j:=0 to temp-1 do
6768        begin
6769          blockwrite(savefile,mainform.memrec[i].pointers[j].Address,sizeof(mainform.memrec[i].pointers[j].Address),actualwritten);
6770          blockwrite(savefile,mainform.memrec[i].pointers[j].offset,sizeof(mainform.memrec[i].pointers[j].offset),actualwritten);
6771
6772          //interpretableaddress for pointer
6773          k:=length(mainform.memrec[i].pointers[j].interpretableaddress);
6774          x:=pchar(mainform.memrec[i].pointers[j].interpretableaddress);
6775          blockwrite(savefile,k,sizeof(k),actualwritten);
6776          blockwrite(savefile,pointer(x)^,k,actualwritten);
6777        end;
6778
6779
6780        //autoassemble script
6781        j:=length(mainform.memrec[i].autoassemblescript);
6782        x:=pchar(mainform.memrec[i].autoassemblescript);
6783
6784        blockwrite(savefile,j,sizeof(j),actualwritten);
6785        blockwrite(savefile,pointer(x)^,j,actualwritten);
6786
6787
6788      end;
6789
6790      records:=advancedoptions.numberofcodes;
6791      blockwrite(savefile,records,4,actualwritten);
6792
6793      //save the code list
6794
6795      for i:=0 to records-1 do
6796      begin
6797        //read the before, actual, and after codes
6798        //first byte is the number of bytes
6799        blockwrite(savefile,advancedoptions.code[i].Address,4,actualwritten);
6800
6801        x:=pchar(advancedoptions.code[i].modulename);
6802        nrofbytes:=length(advancedoptions.code[i].modulename);
6803        blockwrite(savefile,nrofbytes,1,actualwritten);
6804        blockwrite(savefile,pointer(x)^,nrofbytes,actualwritten);
6805
6806        blockwrite(savefile,advancedoptions.code[i].offset,4);
6807     
6808
6809        nrofbytes:=length(advancedoptions.code[i].before);
6810        blockwrite(savefile,nrofbytes,1,actualwritten);
6811        blockwrite(savefile,pointer(advancedoptions.code[i].before)^,nrofbytes,actualwritten);
6812
6813        nrofbytes:=length(advancedoptions.code[i].actualopcode);
6814        blockwrite(savefile,nrofbytes,1,actualwritten);
6815        blockwrite(savefile,pointer(advancedoptions.code[i].actualopcode)^,nrofbytes,actualwritten);
6816
6817        nrofbytes:=length(advancedoptions.code[i].after);
6818        blockwrite(savefile,nrofbytes,1,actualwritten);
6819        blockwrite(savefile,pointer(advancedoptions.code[i].after)^,nrofbytes,actualwritten);
6820
6821        x:=pchar(advancedoptions.codelist2.Items[i].SubItems[0]);
6822        nrofbytes:=length(x);
6823        blockwrite(savefile,nrofbytes,1,actualwritten);
6824        blockwrite(savefile,pointer(x)^,nrofbytes,actualwritten);
6825      end;
6826
6827      //symbollist
6828      sl:=tstringlist.Create;
6829      try
6830        symhandler.EnumerateUserdefinedSymbols(sl);
6831        records:=sl.Count;
6832        blockwrite(savefile,records,sizeof(records),actualwritten);
6833        for i:=0 to records-1 do
6834        begin
6835          extradata:=pointer(sl.Objects[i]);
6836          temp:=extradata^.address;
6837          //temp:=dword(sl.Objects[i]);
6838          blockwrite(savefile,temp,sizeof(temp),actualwritten);
6839          x:=pchar(sl[i]);
6840          temp:=length(x);
6841          blockwrite(savefile,temp,sizeof(temp),actualwritten);
6842          blockwrite(savefile,pointer(x)^,temp,actualwritten);
6843
6844          //write the addressstring
6845          x:=extradata^.addressstring;
6846          temp:=length(x);
6847          blockwrite(savefile,temp,sizeof(temp),actualwritten);
6848          blockwrite(savefile,pointer(x)^,temp,actualwritten);
6849
6850
6851          freemem(extradata);
6852        end;
6853      finally
6854        sl.free;
6855      end;
6856
6857      //structure definitions
6858      records:=length(definedstructures);
6859      blockwrite(savefile,records,sizeof(temp));
6860      for i:=0 to records-1 do
6861      begin
6862        x:=pchar(definedstructures[i].name);
6863        temp:=length(x);
6864        blockwrite(savefile,temp,sizeof(temp));
6865        blockwrite(savefile,pointer(x)^,temp);
6866
6867        subrecords:=length(definedstructures[i].structelement);
6868        blockwrite(savefile,subrecords,sizeof(temp));
6869        for j:=0 to subrecords-1 do
6870        begin
6871          x:=pchar(definedstructures[i].structelement[j].description);
6872          temp:=length(x);
6873          blockwrite(savefile,temp,sizeof(temp));
6874          blockwrite(savefile,pointer(x)^,temp);
6875
6876          blockwrite(savefile, definedstructures[i].structelement[j].pointerto, sizeof(definedstructures[i].structelement[j].pointerto));
6877          blockwrite(savefile, definedstructures[i].structelement[j].pointertoSize, sizeof(definedstructures[i].structelement[j].pointertoSize));
6878          blockwrite(savefile, definedstructures[i].structelement[j].structurenr, sizeof(definedstructures[i].structelement[j].structurenr));
6879          blockwrite(savefile, definedstructures[i].structelement[j].bytesize, sizeof(definedstructures[i].structelement[j].bytesize));
6880          blockwrite(savefile, definedstructures[i].structelement[j].offset, sizeof(definedstructures[i].structelement[j].offset));         
6881        end;
6882      end;
6883
6884
6885      //comments
6886      x:=pchar(comments.memo1.text);
6887      blockwrite(Savefile,x^,length(comments.memo1.text),actualwritten);
6888      closefile(savefile);
6889
6890
6891
6892      with mainform do
6893      begin
6894        oldnumberofrecords:=numberofrecords;
6895        oldcodelistcount:=advancedoptions.codelist2.items.count;
6896
6897        setlength(oldmemrec,numberofrecords);
6898        for i:=0 to numberofrecords-1 do
6899        begin
6900          oldmemrec[i].Description:=memrec[i].Description;
6901          oldmemrec[i].Address:=memrec[i].Address;
6902          oldmemrec[i].VarType:=memrec[i].VarType;
6903          oldmemrec[i].IsPointer:=memrec[i].IsPointer;
6904
6905          setlength(oldmemrec[i].pointers,length(memrec[i].pointers));
6906          for j:=0 to length(memrec[i].pointers)-1 do
6907          begin
6908            oldmemrec[i].pointers[j].Address:=memrec[i].pointers[j].Address;
6909            oldmemrec[i].pointers[j].offset:=memrec[i].pointers[j].offset;
6910          end;
6911
6912          oldmemrec[i].Bit:=memrec[i].Bit;
6913          oldmemrec[i].bitlength:=memrec[i].bitlength;
6914          oldmemrec[i].Group:=memrec[i].Group;
6915        end;
6916
6917        oldcomments:=comments.Memo1.Text;
6918      end;
6919
6920    end
6921    else
6922    begin
6923      {$ifndef net}
6924      if standalone<>nil then
6925      begin
6926        StandAlone.filename:=filename;
6927        standAlone.showmodal;
6928      end;
6929      {$endif}
6930    end;
6931    mainform.editedsincelastsave:=false;
6932
6933  finally
6934    mainform.editedsincelastsave:=false;
6935  end;
6936end;
6937
6938
6939end.
6940
6941
6942
Note: See TracBrowser for help on using the browser.