source: OniTrainer/current/Unit4.pas@ 1080

Last change on this file since 1080 was 251, checked in by alloc, 17 years ago
File size: 8.1 KB
Line 
1UNIT Unit4;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StdCtrls, ExtCtrls, ComCtrls, StrUtils;
6TYPE
7 TForm4 = Class(TForm)
8 Label1: TLabel;
9 edit_char: TEdit;
10 list: TListBox;
11 Label2: TLabel;
12 btn_demo: TButton;
13 check_freeze: TCheckBox;
14 timer_anim: TTimer;
15 check_global: TRadioButton;
16 check_local: TRadioButton;
17 updown: TUpDown;
18 group_anim: TGroupBox;
19 lbl_lvl: TLabel;
20 memo: TMemo;
21 PROCEDURE listClick(Sender: TObject);
22 PROCEDURE btn_demoClick(Sender: TObject);
23 PROCEDURE updownClick(Sender: TObject; Button: TUDBtnType);
24 PROCEDURE FormCreate(Sender: TObject);
25 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
26 PROCEDURE check_localClick(Sender: TObject);
27 PROCEDURE check_globalClick(Sender: TObject);
28 PROCEDURE timer_animTimer(Sender: TObject);
29 PROCEDURE check_freezeClick(Sender: TObject);
30 PRIVATE
31 PUBLIC
32 END;
33VAR
34 Form4: TForm4;
35
36IMPLEMENTATION
37USES Unit1, Unit2, Unit8;
38VAR
39 demo_active:Boolean=False;
40 first_global:LongWord;
41 first_local:LongWord;
42{$R *.dfm}
43
44PROCEDURE TForm4.check_freezeClick(Sender: TObject);
45 BEGIN
46 btn_demo.Caption:='Start demo';
47 demo_active:=False;
48 END;
49
50FUNCTION patch_loader_loaded:Boolean;
51 CONST check_for:LongWord=$0010656EE9;
52 address_at:LongWord=$4228ED;
53 BEGIN
54 IF Decode_Int(ReadMem(address_at,4))=check_for THEN result:=True
55 ELSE result:=False;
56 END;
57
58FUNCTION GetAnimAddress:LongWord;
59 VAR offset:LongWord;
60 BEGIN
61 IF Form4.check_global.Checked THEN BEGIN
62 offset:=animations_l0[Form4.list.ItemIndex+1].offset;
63 result:=first_global+offset;
64 END ELSE BEGIN
65 CASE lvlnumber OF
66 1: offset:=animations_l1[Form4.list.ItemIndex+1].offset;
67 2: offset:=animations_l2[Form4.list.ItemIndex+1].offset;
68 3: offset:=animations_l3[Form4.list.ItemIndex+1].offset;
69 4: offset:=animations_l4[Form4.list.ItemIndex+1].offset;
70 5: offset:=animations_l5[Form4.list.ItemIndex+1].offset;
71 6: offset:=animations_l6[Form4.list.ItemIndex+1].offset;
72 7: offset:=animations_l7[Form4.list.ItemIndex+1].offset;
73 8: offset:=animations_l8[Form4.list.ItemIndex+1].offset;
74 9: offset:=animations_l9[Form4.list.ItemIndex+1].offset;
75 10: offset:=animations_l10[Form4.list.ItemIndex+1].offset;
76 11: offset:=animations_l11[Form4.list.ItemIndex+1].offset;
77 12: offset:=animations_l12[Form4.list.ItemIndex+1].offset;
78 13: offset:=animations_l13[Form4.list.ItemIndex+1].offset;
79 14: offset:=animations_l14[Form4.list.ItemIndex+1].offset;
80 END;
81 result:=first_local+offset;
82 END;
83 END;
84
85PROCEDURE TForm4.timer_animTimer(Sender: TObject);
86 VAR struct3:LongWord;
87 buffer:byte_array;
88 address:LongWord;
89 BEGIN
90 IF _connected AND (lvlnumber>0) AND patch_loader_loaded THEN BEGIN
91 first_global:=Decode_Int(ReadMem($10F08,4));
92 first_local:=Decode_Int(ReadMem($10F0C,4));
93 struct3:=Decode_Int(ReadMem(PointerStruct3,4))+StrToInt(Form4.edit_char.Text)*$2838;
94 address:=GetAnimAddress;
95
96 IF demo_active THEN BEGIN
97 IF Decode_Int(ReadMem(struct3+$1AF8,4))<>address THEN BEGIN
98 REPEAT
99 Form4.list.ItemIndex:=Form4.list.ItemIndex+1;
100 UNTIL (Pos('_tgt',Form4.list.Items.Strings[Form4.list.ItemIndex])=0);
101 address:=GetAnimAddress;
102 buffer:=Encode_Int(address);
103 WriteMem(struct3+$1AF8,4,buffer);
104 END;
105 END;
106 IF check_freeze.Checked THEN BEGIN
107 buffer:=Encode_Int(address);
108 WriteMem(struct3+$1AF8,4,buffer);
109 END;
110 END ELSE BEGIN
111 IF _connected AND (lvlnumber>0) AND (demo_active OR check_freeze.Checked) THEN BEGIN
112 MessageBox(Form4.Handle,PChar('Oni.exe is not patched.'),PChar('Error'),MB_OK);
113 END;
114 END;
115 END;
116
117PROCEDURE load_anim_list(anims:Array OF animation);
118 VAR i:Word;
119 BEGIN
120 Form4.list.Items.Clear;
121 FOR i:=0 TO High(anims) DO BEGIN
122 Form4.list.Items.Add(anims[i].name);
123 END;
124 END;
125
126PROCEDURE TForm4.check_globalClick(Sender: TObject);
127 BEGIN
128 IF check_global.Checked THEN BEGIN
129 load_anim_list(animations_l0);
130 END;
131 END;
132
133PROCEDURE TForm4.check_localClick(Sender: TObject);
134 BEGIN
135 IF check_local.Checked THEN BEGIN
136 IF lvlnumber>0 THEN BEGIN
137 CASE lvlnumber OF
138 1: load_anim_list(animations_l1);
139 2: load_anim_list(animations_l2);
140 3: load_anim_list(animations_l3);
141 4: load_anim_list(animations_l4);
142 5: load_anim_list(animations_l5);
143 6: load_anim_list(animations_l6);
144 7: load_anim_list(animations_l7);
145 8: load_anim_list(animations_l8);
146 9: load_anim_list(animations_l9);
147 10: load_anim_list(animations_l10);
148 11: load_anim_list(animations_l11);
149 12: load_anim_list(animations_l12);
150 13: load_anim_list(animations_l13);
151 14: load_anim_list(animations_l14);
152 END;
153 END ELSE BEGIN
154 check_global.Checked:=True;
155 END;
156 END;
157 END;
158
159PROCEDURE TForm4.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
160 BEGIN
161 Self.Visible:=False;
162 CanClose:=False;
163 Form1.menu_Anims.Checked:=False;
164 END;
165
166PROCEDURE TForm4.FormCreate(Sender: TObject);
167 BEGIN
168 load_anim_list(animations_l0);
169 list.ItemIndex:=0;
170 updown.Max:=ais_controlled;
171 END;
172
173PROCEDURE TForm4.updownClick(Sender: TObject; Button: TUDBtnType);
174 BEGIN
175 Form4.edit_char.Text:=IntToStr(updown.Position);
176 END;
177
178PROCEDURE TForm4.btn_demoClick(Sender: TObject);
179 VAR struct3,address:LongWord;
180 buffer:byte_array;
181 BEGIN
182 IF demo_active THEN BEGIN
183 check_freeze.Checked:=False;
184 btn_demo.Caption:='Start demo';
185 demo_active:=False;
186 END ELSE BEGIN
187 check_freeze.Checked:=False;
188 btn_demo.Caption:='Stop demo';
189 demo_active:=True;
190 IF _connected AND (lvlnumber>0) AND patch_loader_loaded THEN BEGIN
191 first_global:=Decode_Int(ReadMem($10F08,4));
192 first_local:=Decode_Int(ReadMem($10F0C,4));
193 struct3:=Decode_Int(ReadMem(PointerStruct3,4))+StrToInt(Form4.edit_char.Text)*$2838;
194 address:=GetAnimAddress;
195 buffer:=Encode_Int(address);
196 WriteMem(struct3+$1AF8,4,buffer);
197 END ELSE BEGIN
198 IF _connected AND (lvlnumber>0) THEN BEGIN
199 MessageBox(Form4.Handle,PChar('Oni.exe is not patched.'),PChar('Error'),MB_OK);
200 END;
201 END;
202 END;
203 END;
204
205PROCEDURE TForm4.listClick(Sender: TObject);
206 VAR address:LongWord;
207 buffer:byte_array;
208 i:Byte;
209 temp:String;
210 old:LongWord;
211 BEGIN
212 IF _connected AND (lvlnumber>0) AND patch_loader_loaded THEN BEGIN
213 first_global:=Decode_Int(ReadMem($10F08,4));
214 first_local:=Decode_Int(ReadMem($10F0C,4));
215 address:=GetAnimAddress;
216 Form4.lbl_lvl.Caption:='Lvl required (@'+IntToHex(address,8)+'): '+IntToStr(Decode_Int(ReadMem(address+$176,1)));
217// VirtualProtectEx(_ProcessHandle,address+$176,2,PAGE_READWRITE,old);
218// MessageBox(Form4.Handle,PChar('BLA: '+IntToStr(GetLastError)+'#'+IntToHex(GetLastError,8)),PChar('Error'),MB_OK);
219 WriteMem(address+$176,1,Encode_Int(0));
220// MessageBox(Form4.Handle,PChar('BLA: '+IntToStr(GetLastError)+'#'+IntToHex(GetLastError,8)),PChar('Error'),MB_OK);
221 Form4.memo.Lines.Clear;
222 temp:='';
223 buffer:=ReadMem(address,$D0);
224 FOR i:=0 TO ($D0 - 1) DO BEGIN
225 temp:=temp+IntToHex(buffer[i],2);
226 IF ((i+1) MOD $10)=0 THEN BEGIN
227 Form4.memo.Lines.Add(temp);
228 temp:='';
229 END;
230 END;
231 buffer:=ReadMem(address+$D0,$D0);
232 FOR i:=0 TO ($D0 - 1) DO BEGIN
233 temp:=temp+IntToHex(buffer[i],2);
234 IF ((i+1) MOD $10)=0 THEN BEGIN
235 Form4.memo.Lines.Add(temp);
236 temp:='';
237 END;
238 END;
239 END ELSE BEGIN
240 IF _connected AND (lvlnumber>0) THEN BEGIN
241 MessageBox(Form4.Handle,PChar('Oni.exe is not patched.'),PChar('Error'),MB_OK);
242 END;
243 END;
244 END;
245
246END.
Note: See TracBrowser for help on using the repository browser.