source: Daodan/src/Daodan_BSL.c@ 691

Last change on this file since 691 was 689, checked in by alloc, 12 years ago

Daodan: Cleaned up code so no major warnings exist

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