source: OniTrainer/current/Unit3.pas@ 323

Last change on this file since 323 was 251, checked in by alloc, 17 years ago
File size: 13.6 KB
Line 
1UNIT Unit3;
2INTERFACE
3USES
4 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
5 Dialogs, StrUtils, Menus, ExtCtrls, StdCtrls,Unit2,Unit8, Math, Buttons;
6
7TYPE
8 TCharForm = Class(TForm)
9 timer_actualize: TTimer;
10 memo: TMemo;
11 timer_freeze: TTimer;
12 Timer1: TTimer;
13 PROCEDURE timer_freezeTimer(Sender: TObject);
14 PROCEDURE timer_actualizeTimer(Sender: TObject);
15 PROCEDURE FormCloseQuery(Sender: TObject; var CanClose: Boolean);
16 PROCEDURE EditClick(Sender: TObject);
17 PROCEDURE OpenCloseClick(Sender: TObject);
18 PRIVATE
19 PUBLIC
20 END;
21
22FUNCTION GetItemNumber(name:String):Byte;
23
24VAR
25 CharForm: TCharForm;
26 _charformsinitialized:Boolean;
27 CharData: Array[0..ais_controlled] OF TStructures;
28 CharGroups: Array[0..ais_controlled] OF Array[1..number_char_groups] OF TGroup;
29
30IMPLEMENTATION
31USES Unit1, Unit7;
32{$R *.dfm}
33
34FUNCTION GetItemNumber(name:String):Byte;
35 VAR i:Byte;
36 BEGIN
37 result:=0;
38 END;
39
40PROCEDURE TCharForm.EditClick(Sender: TObject);
41 VAR bytes,charnumber,itemnumber:Byte;
42 tempint:Integer;
43 tempfloat:Single;
44 address:LongWord;
45 BEGIN
46 charnumber:=StrToInt(MidStr(TComponent(Sender).GetParentComponent.GetParentComponent.Name, 5, 10));
47 IF NOT _connected THEN exit;
48 IF _ais_active[charnumber] THEN BEGIN
49 itemnumber:=StrToInt(MidStr(TComponent(Sender).Name, 5, 10));
50 IF CharData[charnumber].Items[itemnumber].updating THEN exit;
51 WITH CharData[charnumber] DO BEGIN
52 IF Items[itemnumber].struct=0 THEN address:=Items[itemnumber].offset
53 ELSE address:=Structs[Items[itemnumber].struct]+Items[itemnumber].offset;
54 WITH Items[itemnumber] DO BEGIN
55 CASE data_type OF
56 1..4:BEGIN
57 bytes:=data_type;
58 IF TryStrToInt(TEdit(Sender).Text,tempint) THEN BEGIN
59 IF range>0 THEN BEGIN
60 IF tempint>range THEN tempint:=Floor(range);
61 IF tempint<0 THEN tempint:=0;
62 TEdit(Sender).Text:=IntToStr(tempint);
63 WriteMem(address,bytes,Encode_Int(tempint));
64 END ELSE BEGIN
65 IF tempint>=Floor(Power(256,bytes)) THEN tempint:=Floor(Power(256,bytes))-1;
66 IF tempint<0 THEN tempint:=0;
67 TEdit(Sender).Text:=IntToStr(tempint);
68 WriteMem(address,bytes,Encode_Int(tempint));
69 END;
70 END;
71 END;
72 5: BEGIN
73 bytes:=4;
74 IF TryStrToFloat(TEdit(Sender).Text,tempfloat) THEN BEGIN
75 IF Pos('[0-360]',CharData[charnumber].Items[itemnumber].name)>0 THEN BEGIN
76 tempfloat:=tempfloat*pi/180;
77 END;
78 IF range>0 THEN BEGIN
79 IF tempfloat>range THEN BEGIN
80 tempfloat:=range;
81 IF Pos('[0-360]',CharData[charnumber].Items[itemnumber].name)>0 THEN BEGIN
82 TEdit(Sender).Text:=FloatToStr(tempfloat*180/pi);
83 END ELSE BEGIN
84 TEdit(Sender).Text:=FloatToStr(tempfloat);
85 END;
86 END;
87 IF tempfloat<0 THEN BEGIN
88 tempfloat:=0;
89 IF Pos('[0-360]',CharData[charnumber].Items[itemnumber].name)>0 THEN BEGIN
90 TEdit(Sender).Text:=FloatToStr(tempfloat*180/pi);
91 END ELSE BEGIN
92 TEdit(Sender).Text:=FloatToStr(tempfloat);
93 END;
94 END;
95 WriteMem(address,bytes,Encode_Float(tempfloat));
96 END ELSE BEGIN
97 WriteMem(address,bytes,Encode_Float(tempfloat));
98 END;
99 END;
100 END;
101 6: BEGIN
102 bytes:=Floor(range);
103 WriteMem(address,bytes,Encode_Str(TEdit(Sender).Text,bytes));
104 END;
105 END;
106 END;
107 END;
108 END;
109 END;
110
111PROCEDURE TCharForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
112 VAR charnumber:Byte;
113 BEGIN
114 Self.Visible:=False;
115 charnumber:=StrToInt(MidStr(Self.Name, 5, 10));
116 CharMenus[charnumber].Checked:=False;
117 CanClose:=False;
118 END;
119
120FUNCTION Check_Addresses_Changed(charnumber:Byte):Boolean;
121 VAR struct3_id:byte;
122 BEGIN
123 result:=False;
124 _temp:=ReadMem(PointerStruct1PointerArray1,4);
125 _ais_active[charnumber]:=True;
126 IF NOT (_temp[250]=123) THEN BEGIN
127 _tempvalue:=Decode_Int(_temp);
128 _temp:=ReadMem(_tempvalue+4*charnumber,4);
129 IF NOT (_temp[250]=123) THEN BEGIN
130 _tempvalue:=Decode_Int(_temp);
131 IF NOT (_tempvalue=CharData[charnumber].Structs[1]) THEN BEGIN
132 CharForms[charnumber].memo.lines.Strings[0]:='Struct1-Addy ('+IntToStr(_temp[250])+'): 0x'+IntToHex(_tempvalue,8);
133 CharData[charnumber].Structs[1]:=_tempvalue;
134 result:=True;
135 END;
136 END ELSE BEGIN
137 _ais_active[charnumber]:=False;
138 END;
139
140 struct3_id:=charnumber;//Decode_Int(ReadMem(CharData[charnumber].Structs[1]+$000,1));
141
142 _tempvalue:=Decode_Int(ReadMem(PointerStruct3,4));
143 _tempvalue:=_tempvalue+(struct3_id*$2838);
144 CharForms[charnumber].memo.Lines.Strings[2]:='Struct3-Addy: 0x'+IntToHex(_tempvalue,8);
145 CharData[charnumber].Structs[3]:=_tempvalue;
146
147 _temp:=ReadMem(CharData[charnumber].Structs[3]+4,4);
148 IF NOT (_temp[250]=123) THEN BEGIN
149 _tempvalue:=Decode_Int(_temp);
150 IF NOT (_tempvalue=CharData[charnumber].Structs[2]) THEN BEGIN
151 CharForms[charnumber].memo.lines.Strings[1]:='Struct2-Addy ('+IntToStr(_temp[250])+'): 0x'+IntToHex(_tempvalue,8);
152 CharData[charnumber].Structs[2]:=_tempvalue;
153 result:=True;
154 END;
155 END;
156 END ELSE BEGIN
157 _ais_active[charnumber]:=False;
158 END;
159 IF Decode_Str(ReadMem(CharData[charnumber].Structs[1]+$14,100))='' THEN _ais_active[charnumber]:=False;
160 IF charnumber>0 THEN Check_CharInOverview(charnumber);
161 END;
162
163PROCEDURE TCharForm.OpenCloseClick(Sender: TObject);
164 VAR number,i,charnumber:Byte;
165 _top:Word;
166 BEGIN
167 number:=StrToInt(MidStr(TSpeedButton(Sender).Name, 10, 10));
168 charnumber:=StrToInt(MidStr(Self.Name,5,10));
169 IF CharGroups[charnumber][number].OpenClose.Down THEN BEGIN
170 CharGroups[charnumber][number].Item.Height:=20;
171 FOR i:=1 TO number_items DO BEGIN
172 WITH CharData[charnumber].Items[i] DO BEGIN
173 IF group=number THEN BEGIN
174 Item_Freeze.Visible:=False;
175 Item_Edit.Visible:=False;
176 break;
177 END;
178 END;
179 END;
180 _top:=1;
181 FOR i:=1 TO number_char_groups DO BEGIN
182 WITH CharGroups[charnumber][i] DO BEGIN
183 Item.Top:=_top;
184 _top:=_top+Item.Height;
185 END;
186 END;
187 CharForms[charnumber].memo.Top:=_top+4;
188 CharForms[charnumber].Height:=_top+CharForms[charnumber].memo.Height+30;
189 END ELSE BEGIN
190 CharGroups[charnumber][number].Item.Height:=CharGroups[charnumber][number].Count*19+20;
191 FOR i:=1 TO number_items DO BEGIN
192 WITH CharData[charnumber].Items[i] DO BEGIN
193 IF group=number THEN BEGIN
194 Item_Freeze.Visible:=True;
195 Item_Edit.Visible:=True;
196 break;
197 END;
198 END;
199 END;
200 _top:=1;
201 FOR i:=1 TO number_char_groups DO BEGIN
202 WITH CharGroups[charnumber][i] DO BEGIN
203 Item.Top:=_top;
204 _top:=_top+Item.Height;
205 END;
206 END;
207 CharForms[charnumber].memo.Top:=_top+4;
208 CharForms[charnumber].Height:=_top+CharForms[charnumber].memo.Height+30;
209 END;
210 END;
211
212FUNCTION Get_Data_Struct(charnumber:Byte):Boolean;
213 VAR i:Byte;
214 bytes:Byte;
215 address:LongWord;
216 floatval:Single;
217 charoverviewcol:Byte;
218 BEGIN
219 IF charnumber=0 THEN charoverviewcol:=1
220 ELSE charoverviewcol:=GetCharOverviewCol(charnumber);
221 WITH CharData[charnumber] DO BEGIN
222 FOR i:=1 TO number_items DO BEGIN
223 CASE Items[i].data_type OF
224 1: bytes:=1;
225 2: bytes:=2;
226 3: bytes:=3;
227 4: bytes:=4;
228 5: bytes:=4;
229 6: bytes:=100;
230 END;
231 IF Items[i].Struct=0 THEN address:=Items[i].offset
232 ELSE address:=Structs[Items[i].struct]+Items[i].offset;
233 _temp:=ReadMem(address,bytes);
234 CASE Items[i].data_type OF
235 1..4: BEGIN
236 IF (NOT Items[i].Item_Edit.Focused) AND (NOT Items[i].Item_Freeze.Checked) THEN BEGIN
237 Items[i].updating:=True;
238 Items[i].Item_Edit.Text:=IntToStr(Decode_Int(_temp));
239 Items[i].updating:=False;
240 END;
241 Form7.grid.Cells[charoverviewcol,i]:=IntToStr(Decode_Int(_temp));
242 END;
243 5: IF Pos('[0-360]',Items[i].hint)=0 THEN BEGIN
244 IF (NOT Items[i].Item_Edit.Focused) AND (NOT Items[i].Item_Freeze.Checked) THEN BEGIN
245 Items[i].updating:=True;
246 Items[i].Item_Edit.Text:=FloatToStr(Decode_Float(_temp));
247 Items[i].updating:=False;
248 END;
249 Form7.grid.Cells[charoverviewcol,i]:=FloatToStr(Decode_Float(_temp));
250 END ELSE BEGIN
251 floatval:=Decode_Float(_temp);
252 IF (NOT Items[i].Item_Edit.Focused) AND (NOT Items[i].Item_Freeze.Checked) THEN BEGIN
253 Items[i].updating:=True;
254 Items[i].Item_Edit.Text:=FloatToStr((floatval/pi)*180);
255 Items[i].updating:=False;
256 END;
257 Form7.grid.Cells[charoverviewcol,i]:=FloatToStr((floatval/pi)*180);
258 END;
259 6: BEGIN
260 IF (NOT Items[i].Item_Edit.Focused) AND (NOT Items[i].Item_Freeze.Checked) THEN BEGIN
261 Items[i].updating:=True;
262 Items[i].Item_Edit.Text:=Decode_Str(_temp);
263 Items[i].updating:=False;
264 END;
265 Form7.grid.Cells[charoverviewcol,i]:=Decode_Str(_temp);
266 END;
267 END;
268 END;
269 END;
270 END;
271
272PROCEDURE TCharForm.timer_actualizeTimer(Sender: TObject);
273 VAR charnumber,i:Byte;
274 BEGIN
275 IF _connected THEN BEGIN
276 charnumber:=StrToInt(MidStr(Self.Name, 5, 10));
277
278 Check_Addresses_Changed(charnumber);
279 IF _ais_active[charnumber] THEN Get_Data_Struct(charnumber);
280 END;
281 END;
282
283PROCEDURE TCharForm.timer_freezeTimer(Sender: TObject);
284 VAR charnumber,i,bytes:Byte;
285 tempint:Integer;
286 tempfloat:Single;
287 address:LongWord;
288 charstring:string;
289 _component:TComponent;
290 framename:String;
291 BEGIN
292 charnumber:=StrToInt(MidStr(Self.Name, 5, 10));
293 IF NOT _ais_active[charnumber] THEN exit;
294 IF NOT _connected THEN exit;
295 WITH CharData[charnumber] DO BEGIN
296 FOR i:=1 TO number_items DO BEGIN
297 IF Items[i].Item_Freeze.Checked THEN BEGIN
298 IF Items[i].struct=0 THEN address:=Items[i].offset
299 ELSE address:=Structs[Items[i].struct]+Items[i].offset;
300 WITH Items[i] DO BEGIN
301 CASE data_type OF
302 1..4:BEGIN
303 bytes:=data_type;
304 IF TryStrToInt(Item_Edit.Text,tempint) THEN BEGIN
305 IF range>0 THEN BEGIN
306 IF tempint>range THEN tempint:=Floor(range);
307 IF tempint<0 THEN tempint:=0;
308 Item_Edit.Text:=IntToStr(tempint);
309 WriteMem(address,bytes,Encode_Int(tempint));
310 END ELSE BEGIN
311 WriteMem(address,bytes,Encode_Int(tempint));
312 END;
313 END;
314 END;
315 5: BEGIN
316 bytes:=4;
317 IF TryStrToFloat(Item_Edit.Text,tempfloat) THEN BEGIN
318 IF Pos('[0-360]',CharData[charnumber].Items[i].name)>0 THEN BEGIN
319 tempfloat:=tempfloat*pi/180;
320 END;
321 IF range>0 THEN BEGIN
322 IF tempfloat>range THEN BEGIN
323 tempfloat:=range;
324 IF Pos('[0-360]',CharData[charnumber].Items[i].name)>0 THEN BEGIN
325 Item_Edit.Text:=FloatToStr(tempfloat*180/pi);
326 END ELSE BEGIN
327 Item_Edit.Text:=FloatToStr(tempfloat);
328 END;
329 END;
330 IF tempfloat<0 THEN BEGIN
331 tempfloat:=0;
332 IF Pos('[0-360]',CharData[charnumber].Items[i].name)>0 THEN BEGIN
333 Item_Edit.Text:=FloatToStr(tempfloat*180/pi);
334 END ELSE BEGIN
335 Item_Edit.Text:=FloatToStr(tempfloat);
336 END;
337 END;
338 WriteMem(address,bytes,Encode_Float(tempfloat));
339 END ELSE BEGIN
340 WriteMem(address,bytes,Encode_Float(tempfloat));
341 END;
342 END;
343 END;
344 6: BEGIN
345 bytes:=Floor(range);
346 WriteMem(address,bytes,Encode_Str(Item_Edit.Text,bytes));
347 END;
348 END;
349 END;
350 END;
351 END;
352 END;
353 END;
354
355END.
Note: See TracBrowser for help on using the repository browser.