1 |
#include <stdio.h> |
2 |
#include "bool.h" |
3 |
#include <time.h> |
4 |
//#include <ffi.h> |
5 |
#include <math.h> |
6 |
#include "inifile.h" |
7 |
|
8 |
#include "Daodan_BSL.h" |
9 |
#include "Flatline_BSL.h" |
10 |
#include "Daodan_Utility.h" |
11 |
#include "Daodan_Patch.h" |
12 |
#include "Daodan_Console.h" |
13 |
#include "BFW_ScriptLang.h" |
14 |
#include "Oni.h" |
15 |
#include "Oni_Character.h" |
16 |
#include "oni_gl.h" |
17 |
#include "dSFMT\dSFMT.h" |
18 |
#include "Daodan_Character.h" |
19 |
#include "BFW_Utility.h" |
20 |
|
21 |
|
22 |
uint16_t ONICALL bsl_int32mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
23 |
{ |
24 |
ret->value_int32 = args[0].value_int32 * args[1].value_int32; |
25 |
ret->type = sl_int32; |
26 |
return 0; |
27 |
} |
28 |
|
29 |
uint16_t ONICALL bsl_mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
30 |
{ |
31 |
double val1; |
32 |
double val2; |
33 |
|
34 |
if (args[0].type == sl_int32) |
35 |
val1 = args[0].value_int32; |
36 |
else |
37 |
val1 = args[0].value_float; |
38 |
|
39 |
if (args[1].type == sl_int32) |
40 |
val2 = args[1].value_int32; |
41 |
else |
42 |
val2 = args[1].value_float; |
43 |
|
44 |
ret->value_float = (float)(val1 * val2); |
45 |
ret->type = sl_float; |
46 |
return 0; |
47 |
} |
48 |
|
49 |
uint16_t ONICALL bsl_int32div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
50 |
{ |
51 |
ret->value_int32 = args[0].value_int32 / args[1].value_int32; |
52 |
ret->type = sl_int32; |
53 |
return 0; |
54 |
} |
55 |
uint16_t ONICALL bsl_div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
56 |
{ |
57 |
double val1; |
58 |
double val2; |
59 |
|
60 |
if (args[0].type == sl_int32) |
61 |
val1 = args[0].value_int32; |
62 |
else |
63 |
val1 = args[0].value_float; |
64 |
|
65 |
if (args[1].type == sl_int32) |
66 |
val2 = args[1].value_int32; |
67 |
else |
68 |
val2 = args[1].value_float; |
69 |
|
70 |
ret->value_float = (float)(val1 / val2); |
71 |
ret->type = sl_float; |
72 |
return 0; |
73 |
} |
74 |
|
75 |
uint16_t ONICALL bsl_int32rand(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
76 |
{ |
77 |
int32_t start = 0; |
78 |
int32_t end = 0; |
79 |
|
80 |
if (args[0].value_int32 == args[1].value_int32) |
81 |
return 1; |
82 |
else if (args[0].value_int32 > args[1].value_int32) |
83 |
{ |
84 |
start = args[1].value_int32; |
85 |
end = args[0].value_int32; |
86 |
} |
87 |
else |
88 |
{ |
89 |
start = args[0].value_int32; |
90 |
end = args[1].value_int32; |
91 |
} |
92 |
|
93 |
ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1)); |
94 |
ret->type = sl_int32; |
95 |
return 0; |
96 |
} |
97 |
|
98 |
uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
99 |
{ |
100 |
int index; |
101 |
if (numargs == 0) index = 0; |
102 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
103 |
else index = args[0].value_int32; |
104 |
//killcount = ONgGameState->CharacterStorage[index].Kills; |
105 |
//ONgGameState + index * 0x16A0 + 0x1260 + 0x1670; |
106 |
ret->value_int32 = ONgGameState->CharacterStorage[index].Kills; |
107 |
ret->type = sl_int32; |
108 |
return 0; |
109 |
} |
110 |
|
111 |
uint16_t ONICALL bsl_getdamage(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
112 |
{ |
113 |
int index; |
114 |
if (numargs == 0) index = 0; |
115 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
116 |
else index = args[0].value_int32; |
117 |
ret->value_int32 = ONgGameState->CharacterStorage[index].Damage; |
118 |
ret->type = sl_int32; |
119 |
return 0; |
120 |
} |
121 |
|
122 |
|
123 |
|
124 |
uint16_t ONICALL bsl_powerup(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
125 |
{ |
126 |
int index; |
127 |
void* returnval; |
128 |
bool is_lsi = 0; |
129 |
Character* Chr = ONgGameState->CharacterStorage; |
130 |
|
131 |
if (numargs < 2 || args[1].type != sl_str32) return 1; |
132 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
133 |
else index = args[0].value_int32; |
134 |
|
135 |
|
136 |
|
137 |
if(!strcmp(args[1].value_str32,"ammo")) |
138 |
{ |
139 |
returnval = &(Chr[index].Inventory.AmmoUsed); |
140 |
} |
141 |
else if(!strcmp(args[1].value_str32,"hypo")) |
142 |
{ |
143 |
returnval = &(Chr[index].Inventory.HypoUsed); |
144 |
} |
145 |
else if(!strcmp(args[1].value_str32,"cells")) |
146 |
{ |
147 |
returnval = &(Chr[index].Inventory.CellsUsed); |
148 |
} |
149 |
else if(!strcmp(args[1].value_str32,"invis")) |
150 |
{ |
151 |
returnval = &(Chr[index].Inventory.CloakUsed); |
152 |
} |
153 |
else if(!strcmp(args[1].value_str32,"shield")) |
154 |
{ |
155 |
returnval = &(Chr[index].Inventory.ShieldUsed); |
156 |
} |
157 |
else if(!strcmp(args[1].value_str32,"lsi")) |
158 |
{ |
159 |
returnval = &(Chr[index].Inventory.hasLSI); |
160 |
is_lsi = 1; |
161 |
} |
162 |
// else if(!strcmp(args[1].value_str32,"bossshield")) |
163 |
// { |
164 |
// ret->value_int32 = Chr[index].Flags & char_bossshield; |
165 |
// ret->type = sl_int32; |
166 |
// if (numargs >=3) { |
167 |
// if (Chr[index].Flags & char_bossshield) Chr[index].Flags = Chr[index].Flags & ~char_bossshield; |
168 |
// else Chr[index].Flags = Chr[index].Flags | char_bossshield; |
169 |
// } |
170 |
// return 0; |
171 |
// } |
172 |
else return 1; |
173 |
//todo, add setting |
174 |
|
175 |
if(is_lsi) ret->value_int32 = (int)*(bool*)returnval; |
176 |
else ret->value_int32 = *(int*)returnval; |
177 |
ret->type = sl_int32; |
178 |
|
179 |
if (numargs >= 3) |
180 |
{ |
181 |
if(is_lsi) *(bool*)returnval = args[2].value_int32; |
182 |
else *(int*)returnval = args[2].value_int32; |
183 |
} |
184 |
|
185 |
|
186 |
return 0; |
187 |
} |
188 |
|
189 |
uint16_t ONICALL bsl_health(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
190 |
{ |
191 |
int index; |
192 |
Character* Chr; |
193 |
int* health; |
194 |
if (numargs == 0) index = 0; |
195 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
196 |
else index = args[0].value_int32; |
197 |
Chr = ONgGameState->CharacterStorage; |
198 |
health = &Chr[index].Health; |
199 |
|
200 |
ret->value_int32 = *health; |
201 |
ret->type = sl_int32; |
202 |
|
203 |
if (numargs >= 2) { |
204 |
*health = args[1].value_int32; |
205 |
} |
206 |
ret->value_int32 = *health; |
207 |
ret->type = sl_int32; |
208 |
return 0; |
209 |
} |
210 |
|
211 |
uint16_t ONICALL bsl_regen(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
212 |
{ |
213 |
int index; |
214 |
Character* Chr; |
215 |
if (numargs == 0) index = 0; |
216 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
217 |
else index = args[0].value_int32; |
218 |
Chr = ONgGameState->CharacterStorage ; |
219 |
|
220 |
|
221 |
/* |
222 |
DDrConsole_PrintF("Character %s", Chr[index].Name); |
223 |
DDrConsole_PrintF("Spawn %s", Chr[index].ScriptSpawn); |
224 |
DDrConsole_PrintF("Death %s", Chr[index].ScriptDie); |
225 |
DDrConsole_PrintF("Aware %s", Chr[index].ScriptAware); |
226 |
DDrConsole_PrintF("Alarm %s", Chr[index].ScriptAlarm); |
227 |
DDrConsole_PrintF("Hurt %s", Chr[index].ScriptHurt); |
228 |
DDrConsole_PrintF("Defeat %s", Chr[index].ScriptDefeat); |
229 |
DDrConsole_PrintF("NoAmmo %s", Chr[index].ScriptNoAmmo); |
230 |
DDrConsole_PrintF("NoPath %s", Chr[index].ScriptNoPath); |
231 |
*/ |
232 |
ret->value_int32 = Chr[index].RegenHax; |
233 |
ret->type = sl_int32; |
234 |
|
235 |
if (numargs >= 2) { |
236 |
Chr[index].RegenHax = args[1].value_int32; |
237 |
} |
238 |
return 0; |
239 |
} |
240 |
|
241 |
//wow this is broken. |
242 |
uint16_t ONICALL bsl_distance(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { |
243 |
int index; |
244 |
int index2; |
245 |
Character* Chr = ONgGameState->CharacterStorage; |
246 |
Character* Char1; |
247 |
Character* Char2; |
248 |
|
249 |
if (numargs < 2) return 1; |
250 |
|
251 |
if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
252 |
else index = args[0].value_int32; |
253 |
if (index == -1) index = args[0].value_int32; |
254 |
|
255 |
if (args[1].type == sl_str32) index2 = DDrGetCharacterIndexFromName(args[1].value_str32); |
256 |
else index2 = args[1].value_int32; |
257 |
if (index2 == -1) index2 = args[1].value_int32; |
258 |
Char1 = &Chr[index]; |
259 |
Char2 = &Chr[index2]; |
260 |
|
261 |
|
262 |
ret->value_float = sqrt( pow((Char1->Location.X - Char2->Location.X), 2) + pow((Char1->Location.Y - Char2->Location.Y), 2) + pow((Char1->Location.Z - Char2->Location.Z),2)); |
263 |
ret->type = sl_float; |
264 |
return 0; |
265 |
} |
266 |
uint16_t ONICALL bsl_location(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { |
267 |
int index; |
268 |
float* loc; |
269 |
Character* Chr; |
270 |
if (numargs < 2) return 1; |
271 |
if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
272 |
else index = args[0].value_int32; |
273 |
if (index == -1) index = args[0].value_int32; |
274 |
Chr = ONgGameState->CharacterStorage; |
275 |
|
276 |
if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x")) |
277 |
loc = &(Chr[index].Position.X); |
278 |
else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y")) |
279 |
loc = &(Chr[index].Position.Y); |
280 |
else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z")) |
281 |
loc = &(Chr[index].Position.Z); |
282 |
else if (numargs == 4) { |
283 |
//currently broken. crashes oni. |
284 |
Chr[index].Position.X = args[1].value_float; |
285 |
Chr[index].Position.Y = args[2].value_float; |
286 |
Chr[index].Position.Z = args[3].value_float; |
287 |
ret->value_float = 1; |
288 |
ret->type = sl_float; |
289 |
return 0; |
290 |
} |
291 |
else return 1; |
292 |
|
293 |
ret->value_float = *loc; |
294 |
ret->type = sl_float; |
295 |
|
296 |
if(numargs == 3) { |
297 |
//currently broken, does nothing. |
298 |
*loc = args[2].value_float; |
299 |
} |
300 |
return 0; |
301 |
} |
302 |
|
303 |
uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
304 |
{ |
305 |
int index; |
306 |
if (numargs == 0) index = 0; |
307 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
308 |
else index = args[0].value_int32; |
309 |
if(1) { |
310 |
Character* Chr = ONgGameState->CharacterStorage ; |
311 |
int* maxhealth = &Chr[index].MaxHealth; |
312 |
int oldmaxhealth = Chr[index].MaxHealth; |
313 |
int oldhealth = Chr->Health; |
314 |
if (numargs >= 2) { |
315 |
*maxhealth = args[1].value_int32; |
316 |
} |
317 |
if (numargs >= 3 && args[2].value_bool) { |
318 |
Chr->Health = (int)(((float)args[1].value_int32 / (float)oldmaxhealth) * (float)oldhealth); |
319 |
} |
320 |
ret->value_int32 = oldmaxhealth; |
321 |
ret->type = sl_int32; |
322 |
return 0; |
323 |
} |
324 |
} |
325 |
|
326 |
uint16_t ONICALL bsl_getattacker(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
327 |
{ |
328 |
//broken |
329 |
|
330 |
int index; |
331 |
if (numargs == 0) index = 0; |
332 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
333 |
else index = args[0].value_int32; |
334 |
if(1) { |
335 |
Character* Chr = ONgGameState->CharacterStorage; |
336 |
ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
337 |
if (!Active) return 1; |
338 |
// ret->value_int32 = Active->LastDamageSourceCharacter; |
339 |
ret->type = sl_int32; |
340 |
return 0; |
341 |
} |
342 |
} |
343 |
|
344 |
|
345 |
|
346 |
uint16_t ONICALL bsl_chrname(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
347 |
{ |
348 |
int index; |
349 |
char* name; |
350 |
if (numargs == 0) index = 0; |
351 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
352 |
else index = args[0].value_int32; |
353 |
if (index == -1) { |
354 |
ret->type = sl_str32; |
355 |
ret->value_str32 = "NULL"; |
356 |
return 0; |
357 |
} |
358 |
name = &ONgGameState->CharacterStorage[index].Name; |
359 |
if (numargs == 2) { |
360 |
strncpy(name, (char*)args[1].value_str32, 31); |
361 |
} |
362 |
|
363 |
ret->type = sl_str32; |
364 |
ret->value_str32 = name; |
365 |
|
366 |
return 0; |
367 |
} |
368 |
|
369 |
|
370 |
uint16_t ONICALL bsl_count(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
371 |
{ |
372 |
//testing numargs... |
373 |
ret->type = sl_int32; |
374 |
ret->value_int32 = numargs; |
375 |
return 0; |
376 |
} |
377 |
|
378 |
uint16_t ONICALL bsl_dprintcolored(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
379 |
{ |
380 |
//TODO: figure out why our implementation of dprint shows after dev mode is turned off |
381 |
RGBA color; |
382 |
RGBA shade; |
383 |
|
384 |
if(numargs == 0) return 0; |
385 |
if(numargs > 1 ) color.R = (char)args[1].value_int32; |
386 |
else color.R = 255; |
387 |
if(numargs > 2 ) color.G = (char)args[2].value_int32; |
388 |
else color.G = 255; |
389 |
if(numargs > 3 ) color.B = (char)args[3].value_int32; |
390 |
else color.B = 255; |
391 |
color.A = 0; |
392 |
if(numargs > 5 ) shade.R = (char)args[5].value_int32; |
393 |
else shade.R = 0x3F; |
394 |
if(numargs > 6 ) shade.G = (char)args[6].value_int32; |
395 |
else shade.G = 0x3F; |
396 |
if(numargs > 7 ) shade.B = (char)args[7].value_int32; |
397 |
else shade.B = 0x3F; |
398 |
shade.A = 0; |
399 |
|
400 |
DDrConsole_PrintColored(args[0].value_str32, 1, color, shade); |
401 |
return 0; |
402 |
} |
403 |
|
404 |
|
405 |
uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
406 |
{ |
407 |
|
408 |
ret->type = sl_int32; |
409 |
ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32); |
410 |
|
411 |
return 0; |
412 |
} |
413 |
|
414 |
typedef struct { |
415 |
char Name[16]; |
416 |
int Bit; |
417 |
} KeyBit; |
418 |
|
419 |
KeyBit Actions1[32] = { |
420 |
{"Escape", Action_Escape}, |
421 |
{"Console", Action_Console}, |
422 |
{"PauseScreen", Action_PauseScreen}, |
423 |
{"Cutscene1", Action_Cutscene_1 }, |
424 |
{"Cutscene2", Action_Cutscene_2 }, |
425 |
{"F4", Action_F4 }, |
426 |
{"F5", Action_F5 }, |
427 |
{"F6", Action_F6 }, |
428 |
{"F7", Action_F7 }, |
429 |
{"F8", Action_F8 }, |
430 |
{"StartRecorn", Action_StartRecord }, |
431 |
{"StopRecord", Action_StopRecord }, |
432 |
{"PlayRecord", Action_PlayRecord }, |
433 |
{"F12", Action_F12 }, |
434 |
{"Unknown1", Action_Unknown1 }, |
435 |
{"LookMode", Action_LookMode }, |
436 |
{"Screenshot", Action_Screenshot }, |
437 |
{"Unknown2", Action_Unknown2 }, |
438 |
{"Unknown3", Action_Unknown3 }, |
439 |
{"Unknown4", Action_Unknown4 }, |
440 |
{"Unknown5", Action_Unknown5 }, |
441 |
{"Forward", Action_Forward }, |
442 |
{"Backward", Action_Backward }, |
443 |
{"TurnLeft", Action_TurnLeft }, |
444 |
{"TurnRight", Action_TurnRight }, |
445 |
{"StepLeft", Action_StepLeft }, |
446 |
{"StepRight", Action_StepRight }, |
447 |
{"Jump", Action_Jump }, |
448 |
{"Crouch", Action_Crouch }, |
449 |
{"Punch",Action_Punch }, |
450 |
{"Kick", Action_Kick }, |
451 |
{"Block", Action_Block } |
452 |
}; |
453 |
|
454 |
KeyBit Actions2[9] = { |
455 |
{"Walk", Action2_Walk}, |
456 |
{"Action", Action2_Action}, |
457 |
{"Hypo", Action2_Hypo}, |
458 |
{"Reload", Action2_Reload }, |
459 |
{"Swap", Action2_Swap }, |
460 |
{"Drop", Action2_Drop }, |
461 |
{"Fire1", Action2_Fire1 }, |
462 |
{"Fire2", Action2_Fire2 }, |
463 |
{"Fire3", Action2_Fire3 } |
464 |
}; |
465 |
uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
466 |
{ |
467 |
uint32_t index; |
468 |
uint32_t i = 2; |
469 |
uint32_t j = 0; |
470 |
int Input1 = 0; |
471 |
int Input2 = 0; |
472 |
Character* Chr; |
473 |
ActiveCharacter* Active; |
474 |
if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
475 |
else index = args[0].value_int32; |
476 |
|
477 |
Chr = &(ONgGameState->CharacterStorage[index]); |
478 |
Active = ONrGetActiveCharacter(Chr); |
479 |
if (!Active) return 1; |
480 |
|
481 |
for(i = 1; i < numargs - 1; i++) { |
482 |
for(j = 0; j < 32; j++) { |
483 |
if(!strcmp(args[i].value_str32, Actions1[j].Name)) { |
484 |
Input1 = Input1 | Actions1[j].Bit; |
485 |
} |
486 |
} |
487 |
for(j = 0; j < 9; j++) { |
488 |
if(!strcmp(args[i].value_str32, Actions2[j].Name)) { |
489 |
Input2 = Input2 | Actions2[j].Bit; |
490 |
} |
491 |
} |
492 |
} |
493 |
Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1; |
494 |
Active->Input.Current.Actions2 = Active->Input.Current.Actions1 | Input2; |
495 |
if( Input1 + Input2 == 0 ) { |
496 |
DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name); |
497 |
return 0; |
498 |
} |
499 |
if ( args[numargs - 1].value_int32 <= 0) { |
500 |
return 0; |
501 |
} |
502 |
else { |
503 |
args[numargs - 1].value_int32 -= 1; |
504 |
*dontuse2 = 1; |
505 |
*dontuse1 = 1; |
506 |
} |
507 |
return 0; |
508 |
} |
509 |
|
510 |
uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
511 |
{ |
512 |
// int index; |
513 |
// if (numargs < 4) index = 0; |
514 |
// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
515 |
// else index = args[0].value_int32; |
516 |
|
517 |
// Character* Chr = ONgGameState->CharacterStorage; |
518 |
// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
519 |
// if ((int)Active == 0) return 1; |
520 |
uint32_t i = 2; |
521 |
uint32_t j = 0; |
522 |
int Input1 = 0; |
523 |
int Input2 = 0; |
524 |
for(i = 0; i < numargs; i++) { |
525 |
for(j = 0; j < 32; j++) { |
526 |
//DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit); |
527 |
if(!strcmp(args[i].value_str32, Actions1[j].Name)) { |
528 |
Input1 = Input1 | Actions1[j].Bit; |
529 |
//DDrConsole_PrintF("Success!"); |
530 |
} |
531 |
|
532 |
} |
533 |
for(j = 0; j < 9; j++) { |
534 |
if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; |
535 |
|
536 |
} |
537 |
} |
538 |
//DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10)); |
539 |
ret->value_int32 = 0; |
540 |
ret->type = sl_int32; |
541 |
if ( (ONgGameState->Input.Current.Actions1 == Input1) && (ONgGameState->Input.Current.Actions2 == Input2)) ret->value_int32 = 1; |
542 |
return 0; |
543 |
} |
544 |
|
545 |
uint16_t ONICALL bsl_waitforkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
546 |
{ |
547 |
// int index; |
548 |
// if (numargs < 4) index = 0; |
549 |
// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
550 |
// else index = args[0].value_int32; |
551 |
|
552 |
// Character* Chr = ONgGameState->CharacterStorage; |
553 |
// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
554 |
// if ((int)Active == 0) return 1; |
555 |
|
556 |
int i = 2; |
557 |
int j = 0; |
558 |
int Input1 = 0; |
559 |
int Input2 = 0; |
560 |
/* |
561 |
numargs = 0; |
562 |
for(i = 0; args[i].type <= sl_void; i++) |
563 |
{ |
564 |
//DDrConsole_PrintF("%i", args[i].type ); |
565 |
numargs++; |
566 |
|
567 |
} |
568 |
if(numargs < 1 || args[0].value == 0) return; |
569 |
//for(i = 0; i < numargs; i++) { |
570 |
*/ |
571 |
i = 0; |
572 |
for(j = 0; j < 32; j++) { |
573 |
//DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit); |
574 |
if(!strcmp(args[i].value_str32, Actions1[j].Name)) { |
575 |
Input1 = Input1 | Actions1[j].Bit; |
576 |
//DDrConsole_PrintF("Success!"); |
577 |
} |
578 |
|
579 |
} |
580 |
for(j = 0; j < 9; j++) { |
581 |
if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; |
582 |
|
583 |
} |
584 |
// } |
585 |
DDrConsole_PrintF("Waiting..."); |
586 |
if ( |
587 |
(( ONgGameState->Input.Current.Actions1 & Input1) == Input1) && |
588 |
(( ONgGameState->Input.Current.Actions2 & Input2) == Input2) |
589 |
) |
590 |
{ |
591 |
DDrConsole_PrintF("Found key!"); |
592 |
} |
593 |
else { |
594 |
//else (int)*ret = 1; |
595 |
*dontuse2 = 1; |
596 |
*dontuse1 = 1; |
597 |
} |
598 |
return 0; |
599 |
} |
600 |
|
601 |
|
602 |
uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
603 |
{ |
604 |
char output[1024]; |
605 |
char buffer[1024]; |
606 |
int i; |
607 |
char* placeinoutput = output; |
608 |
char* placeininput = args[0].value_str32; |
609 |
int formatnum = 0; |
610 |
//fix the broken bsl numargs... |
611 |
numargs = 0; |
612 |
|
613 |
for(i = 0; args[i].type < sl_void; i++) |
614 |
{ |
615 |
numargs++; |
616 |
} |
617 |
|
618 |
|
619 |
if (numargs < 1) |
620 |
return 1; |
621 |
|
622 |
while(1) |
623 |
{ |
624 |
int size; |
625 |
//s is the pointer to the args |
626 |
char* s = strchr(placeininput , '%'); |
627 |
//we didnt find a %, break! |
628 |
if(!s) |
629 |
{ |
630 |
strcpy(placeinoutput, placeininput); |
631 |
break; |
632 |
} |
633 |
size = (int)s - (int)placeininput ; |
634 |
//we found one, so copy the portion of string |
635 |
|
636 |
|
637 |
|
638 |
memcpy( placeinoutput,placeininput, size); |
639 |
placeininput += size; |
640 |
placeinoutput += size; |
641 |
|
642 |
memset( placeinoutput, '%', (int)pow(2, formatnum)); |
643 |
placeinoutput += (int)pow(2, formatnum); |
644 |
|
645 |
|
646 |
placeininput += 1; |
647 |
*placeinoutput = 0; |
648 |
formatnum++; |
649 |
|
650 |
} |
651 |
//strcpy( output, args[0].value_str32 ); |
652 |
|
653 |
for(i = 1; i < numargs; i++) { |
654 |
//sprintf(output, output, args[i].value_str32); |
655 |
memcpy(buffer, output, 1024); |
656 |
if(args[i].value == 0) break; |
657 |
switch(args[i].type) |
658 |
{ |
659 |
case sl_bool: |
660 |
case sl_int32: |
661 |
sprintf(output, buffer, args[i].value_int32); |
662 |
break; |
663 |
case sl_float: |
664 |
//crashes oni, why? |
665 |
// sprintf(output, output, args[i].value_float); |
666 |
break; |
667 |
case sl_str32: |
668 |
sprintf(output, buffer, args[i].value_str32); |
669 |
break; |
670 |
case sl_void: |
671 |
default: |
672 |
break; |
673 |
} |
674 |
} |
675 |
//output[32] = 0; |
676 |
ret->value_str32 = output; |
677 |
ret->type = sl_str32; |
678 |
return 0; |
679 |
} |
680 |
|
681 |
//Sorry rossy, I broke this. FFI isnt in windows |
682 |
/* |
683 |
uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
684 |
{ |
685 |
|
686 |
|
687 |
int ffi_ret; |
688 |
char* str = NULL; |
689 |
int size = 0; |
690 |
|
691 |
ffi_cif cif; |
692 |
ffi_type* ffi_args[256]; |
693 |
void* values[256]; |
694 |
int i; |
695 |
numargs = 0; |
696 |
for(i = 0; args[i].type <= sl_void; i++) |
697 |
{ |
698 |
//DDrConsole_PrintF("%i", args[i].type ); |
699 |
numargs++; |
700 |
|
701 |
} |
702 |
|
703 |
if (numargs < 1 || args[0].type != sl_str32) |
704 |
{ |
705 |
DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": parameter list does not match: format:string arg1 arg2 ...", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name); |
706 |
return 0; |
707 |
} |
708 |
|
709 |
if (!args[0].value_str32) |
710 |
args[0].value_str32 = ""; |
711 |
|
712 |
|
713 |
|
714 |
ffi_args[0] = &ffi_type_pointer; |
715 |
values[0] = &str; |
716 |
ffi_args[1] = &ffi_type_uint32; |
717 |
values[1] = &size; |
718 |
|
719 |
|
720 |
for(i = 2; i < numargs + 2; i ++) |
721 |
{ |
722 |
if (args[i - 2].type == sl_float) |
723 |
{ |
724 |
float value_float = args[i - 2].value_float; |
725 |
double* value_double = (double*)&(args[i - 2]); |
726 |
*value_double = value_float; |
727 |
|
728 |
ffi_args[i] = &ffi_type_double; |
729 |
values[i] = value_double; |
730 |
} |
731 |
else |
732 |
{ |
733 |
ffi_args[i] = &ffi_type_pointer; |
734 |
values[i] = &(args[i - 2].value); |
735 |
} |
736 |
} |
737 |
|
738 |
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK) |
739 |
return 1; |
740 |
ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values); |
741 |
str = malloc(ffi_ret + 1); |
742 |
size = ffi_ret + 1; |
743 |
ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values); |
744 |
ret->value_str32 = str; |
745 |
ret->type = sl_str32; |
746 |
return 0; |
747 |
} |
748 |
*/ |
749 |
// Widescreen patch for talking heads. |
750 |
uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
751 |
{ |
752 |
args[1].value_int32 = (double)args[1].value_int32 / (double)(gl_eng->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl_eng->DisplayMode.Height)); |
753 |
return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret); |
754 |
} |
755 |
|
756 |
bool ini_inbsl = false; |
757 |
bool SLrIniCallback(char* section, bool newsection, char* name, char* value) |
758 |
{ |
759 |
if (newsection && !_stricmp(section, "bsl")) |
760 |
ini_inbsl = true; |
761 |
|
762 |
if (ini_inbsl) |
763 |
{ |
764 |
char* type = value; |
765 |
bool isptr = false; |
766 |
sl_type bsl_type; |
767 |
|
768 |
if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':') |
769 |
{ |
770 |
isptr = true; |
771 |
value += 4; |
772 |
} |
773 |
|
774 |
|
775 |
|
776 |
for (; *type; type++) |
777 |
if (*type == ':') |
778 |
{ |
779 |
*type = '\0'; |
780 |
type++; |
781 |
break; |
782 |
} |
783 |
|
784 |
if (!*type) |
785 |
DDrStartupMessage("badly formed bsl definition for \"%s\"", name); |
786 |
|
787 |
if (!strcmp(type, "int")) |
788 |
bsl_type = sl_int32; |
789 |
else if (!strcmp(type, "string")) |
790 |
bsl_type = sl_str32; |
791 |
else if (!strcmp(type, "float")) |
792 |
bsl_type = sl_float; |
793 |
else if (!strcmp(type, "bool")) |
794 |
bsl_type = sl_bool; |
795 |
else |
796 |
{ |
797 |
DDrStartupMessage("unknown type in bsl definition for \"%s\"", name); |
798 |
return true; |
799 |
} |
800 |
|
801 |
if (isptr) |
802 |
{ |
803 |
char* bsl_var = malloc(strlen(name) + 1); |
804 |
memcpy(bsl_var, name, strlen(name) + 1); |
805 |
switch (bsl_type) |
806 |
{ |
807 |
case sl_int32: |
808 |
SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false)); |
809 |
break; |
810 |
case sl_float: |
811 |
SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false)); |
812 |
break; |
813 |
default: |
814 |
break; |
815 |
} |
816 |
} |
817 |
else |
818 |
{ |
819 |
char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t)); |
820 |
int32_t* bsl_val = (int32_t*)bsl_var; |
821 |
bsl_var += sizeof(int32_t); |
822 |
memcpy(bsl_var, name, strlen(name) + 1); |
823 |
|
824 |
switch (bsl_type) |
825 |
{ |
826 |
case sl_int32: |
827 |
*bsl_val = inifile_parseint(value, false); |
828 |
SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val); |
829 |
break; |
830 |
case sl_float: |
831 |
break; |
832 |
default: |
833 |
break; |
834 |
} |
835 |
} |
836 |
} |
837 |
return true; |
838 |
} |
839 |
|
840 |
void SLrConfig() |
841 |
{ |
842 |
DDrStartupMessage("re-parsing daodan.ini for bsl..."); |
843 |
inifile_read("daodan.ini", SLrIniCallback); |
844 |
DDrStartupMessage("finished parsing"); |
845 |
} |
846 |
|
847 |
void ONICALL SLrDaodan_Register_ReturnType(char* name, char* desc, char* argfmt, sl_type type, sl_func callback) { |
848 |
char argfmt2[512]; |
849 |
uint16_t errornum; |
850 |
sprintf_s(argfmt2, 512, "%s [|]", argfmt); |
851 |
errornum = SLrScript_Command_Register_ReturnType(name, desc, argfmt2, type, callback); |
852 |
if(errornum) |
853 |
{ |
854 |
DDrStartupMessage("Registration of script command %s failed with error %i", name, errornum); |
855 |
} |
856 |
|
857 |
} |
858 |
void* TSrTest = 0; |
859 |
uint16_t ONICALL new_text(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
860 |
{ |
861 |
void* TSFFTahoma; |
862 |
int returnval; |
863 |
TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma); |
864 |
returnval = TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest); |
865 |
return 0; |
866 |
} |
867 |
|
868 |
void SLrDaodan_Initalize() |
869 |
{ |
870 |
SLrConfig(); |
871 |
|
872 |
SLrScript_Command_Register_Void("debug_daodan","Adds text to screen", "", new_text); |
873 |
|
874 |
SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); |
875 |
SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul); |
876 |
SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); |
877 |
SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); |
878 |
dsfmt_gv_init_gen_rand((uint32_t)time(NULL)); |
879 |
SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand); |
880 |
SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:string | script_id:int] [|]", sl_int32, bsl_getkills); |
881 |
SLrScript_Command_Register_ReturnType("d_getdamage","Gets the amount of damage a character has caused", "[ai_name:string | script_id:int]", sl_int32, bsl_getdamage); |
882 |
SLrScript_Command_Register_ReturnType("d_name","Gets or sets a character's name", "[ai_name:string | script_id:int] [newname:string|]", sl_str32, bsl_chrname); |
883 |
SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex); |
884 |
SLrScript_Command_Register_ReturnType("d_health","Gets or sets a character's health", "[ai_name:string | script_id:int] [newhealth:int]", sl_str32, bsl_health); |
885 |
SLrScript_Command_Register_ReturnType("d_regen","Gets or sets a character's health", "[ai_name:string | script_id:int] [newhealth:int]", sl_str32, bsl_regen); |
886 |
SLrScript_Command_Register_ReturnType("d_maxhealth","Gets or sets a character's maximum health", "[ai_name:string | script_id:int] [newmaxhealth:int] [scalehealth:bool]", sl_str32, bsl_maxhealth); |
887 |
SLrScript_Command_Register_ReturnType("d_powerup","Gets or sets a character's powerups", "[ai_name:string | script_id:int] powerup:string", sl_int32, bsl_powerup); |
888 |
//d_holdkey is broken! |
889 |
SLrScript_Command_Register_ReturnType("d_holdkey","Makes a character hold a key", "[ai_name:string | script_id:int] frames:int keys:string", sl_int32, bsl_holdkey); |
890 |
SLrScript_Command_Register_ReturnType("d_isheld","Checks if player is holding a key", "[ai_name:string | script_id:int] [keys:string]", sl_int32, bsl_isheld); |
891 |
SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "ai_name:string | script_id:int xyz:string [newlocation:float]", sl_float, bsl_location); |
892 |
SLrScript_Command_Register_ReturnType("d_distance","Returns the distance between two characters", "ai_name:string | script_id:int ai_name:string | script_id:int", sl_float, bsl_distance); |
893 |
SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "key:string", bsl_waitforkey); |
894 |
|
895 |
//broken, only works for one damage type. |
896 |
//SLrDaodan_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker); |
897 |
|
898 |
//used for debugging. |
899 |
// SLrDaodan_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset); |
900 |
|
901 |
SLrScript_Command_Register_Void("sprintf", "C-style sprintf.", "", bsl_sprintf); |
902 |
SLrScript_Command_Register_ReturnType("st", "prints to console in color", "text:string color1:int color2:int", sl_void, bsl_dprintcolored); |
903 |
|
904 |
//Flatline |
905 |
//#ifdef FLATLINE |
906 |
SLrFlatline_Initialize(); |
907 |
//#endif |
908 |
} |
909 |
|
910 |
void SLrDaodan_Patch() |
911 |
{ |
912 |
DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch); |
913 |
} |