source: Daodan/MSVC/Daodan_BSL.c@ 764

Last change on this file since 764 was 572, checked in by gumby, 14 years ago

Stuff

File size: 28.7 KB
RevLine 
[567]1#include <stdio.h>
2#include "bool.h"
3#include <time.h>
4//#include <ffi.h>
5#include <math.h>
6#include "inifile.h"
[572]7#include "Flatline.h"
[567]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
22uint16_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
29uint16_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
49uint16_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}
55uint16_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
75uint16_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
98uint16_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
111uint16_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
124uint16_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
189uint16_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
[572]203 if (args[1].value_int32) {
[567]204 *health = args[1].value_int32;
205 }
206 ret->value_int32 = *health;
207 ret->type = sl_int32;
208 return 0;
209}
210
211uint16_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.
242uint16_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}
266uint16_t ONICALL bsl_location(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
[572]267 int index, i;
[567]268 float* loc;
269 Character* Chr;
[572]270 numargs = 0;
271 for(i = 0; args[i].type < sl_void; i++)
272 {
273 numargs++;
274 }
275
276
[567]277 if (numargs < 2) return 1;
278 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
279 else index = args[0].value_int32;
280 if (index == -1) index = args[0].value_int32;
281 Chr = ONgGameState->CharacterStorage;
[572]282 if(numargs == 3)
283 {
284 if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x"))
285 loc = &(Chr[index].Position.X);
286 else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y"))
287 loc = &(Chr[index].Position.Y);
288 else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z"))
289 loc = &(Chr[index].Position.Z);
290 }
[567]291 else if (numargs == 4) {
[572]292 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
293 Chr[index].Location.X = args[1].value_float;
294 Chr[index].Location.Y = args[2].value_float;
295 Chr[index].Location.Z = args[3].value_float;
296 if(Active)
297 {
298 Active->PhyContext->Position = Chr[index].Location;
299 }
[567]300 ret->value_float = 1;
301 ret->type = sl_float;
302 return 0;
303 }
304 else return 1;
305
306 ret->value_float = *loc;
307 ret->type = sl_float;
308
309 if(numargs == 3) {
310 //currently broken, does nothing.
311 *loc = args[2].value_float;
312 }
313 return 0;
314}
315
316uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
317{
318 int index;
319 if (numargs == 0) index = 0;
320 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
321 else index = args[0].value_int32;
322 if(1) {
323 Character* Chr = ONgGameState->CharacterStorage ;
324 int* maxhealth = &Chr[index].MaxHealth;
325 int oldmaxhealth = Chr[index].MaxHealth;
326 int oldhealth = Chr->Health;
327 if (numargs >= 2) {
328 *maxhealth = args[1].value_int32;
329 }
330 if (numargs >= 3 && args[2].value_bool) {
331 Chr->Health = (int)(((float)args[1].value_int32 / (float)oldmaxhealth) * (float)oldhealth);
332 }
333 ret->value_int32 = oldmaxhealth;
334 ret->type = sl_int32;
335 return 0;
336 }
337}
338
339uint16_t ONICALL bsl_getattacker(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
340{
341 //broken
342
343 int index;
344 if (numargs == 0) index = 0;
345 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
346 else index = args[0].value_int32;
347 if(1) {
348 Character* Chr = ONgGameState->CharacterStorage;
349 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
350 if (!Active) return 1;
351// ret->value_int32 = Active->LastDamageSourceCharacter;
352 ret->type = sl_int32;
353 return 0;
354 }
355}
356
357
358
359uint16_t ONICALL bsl_chrname(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
360{
361 int index;
362 char* name;
[572]363
[567]364 if (numargs == 0) index = 0;
365 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
366 else index = args[0].value_int32;
367 if (index == -1) {
368 ret->type = sl_str32;
369 ret->value_str32 = "NULL";
370 return 0;
371 }
372 name = &ONgGameState->CharacterStorage[index].Name;
373 if (numargs == 2) {
374 strncpy(name, (char*)args[1].value_str32, 31);
375 }
376
377 ret->type = sl_str32;
378 ret->value_str32 = name;
379
380 return 0;
381}
382
383
384uint16_t ONICALL bsl_count(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
385{
386 //testing numargs...
387 ret->type = sl_int32;
388 ret->value_int32 = numargs;
389 return 0;
390}
391
392uint16_t ONICALL bsl_dprintcolored(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
393{
394 //TODO: figure out why our implementation of dprint shows after dev mode is turned off
395 RGBA color;
396 RGBA shade;
[572]397 int i;
398 numargs = 0;
399 for(i = 0; args[i].type < sl_void; i++)
400 {
401 numargs++;
402 }
[567]403 if(numargs == 0) return 0;
404 if(numargs > 1 ) color.R = (char)args[1].value_int32;
405 else color.R = 255;
406 if(numargs > 2 ) color.G = (char)args[2].value_int32;
407 else color.G = 255;
408 if(numargs > 3 ) color.B = (char)args[3].value_int32;
409 else color.B = 255;
410 color.A = 0;
411 if(numargs > 5 ) shade.R = (char)args[5].value_int32;
412 else shade.R = 0x3F;
413 if(numargs > 6 ) shade.G = (char)args[6].value_int32;
414 else shade.G = 0x3F;
415 if(numargs > 7 ) shade.B = (char)args[7].value_int32;
416 else shade.B = 0x3F;
417 shade.A = 0;
418
419 DDrConsole_PrintColored(args[0].value_str32, 1, color, shade);
420 return 0;
421}
422
423
424uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
425{
426
427 ret->type = sl_int32;
428 ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32);
429
430 return 0;
431}
432
433typedef struct {
434char Name[16];
435int Bit;
436} KeyBit;
437
438KeyBit Actions1[32] = {
439 {"Escape", Action_Escape},
440 {"Console", Action_Console},
441 {"PauseScreen", Action_PauseScreen},
442 {"Cutscene1", Action_Cutscene_1 },
443 {"Cutscene2", Action_Cutscene_2 },
444 {"F4", Action_F4 },
445 {"F5", Action_F5 },
446 {"F6", Action_F6 },
447 {"F7", Action_F7 },
448 {"F8", Action_F8 },
449 {"StartRecorn", Action_StartRecord },
450 {"StopRecord", Action_StopRecord },
451 {"PlayRecord", Action_PlayRecord },
452 {"F12", Action_F12 },
453 {"Unknown1", Action_Unknown1 },
454 {"LookMode", Action_LookMode },
455 {"Screenshot", Action_Screenshot },
456 {"Unknown2", Action_Unknown2 },
457 {"Unknown3", Action_Unknown3 },
458 {"Unknown4", Action_Unknown4 },
459 {"Unknown5", Action_Unknown5 },
460 {"Forward", Action_Forward },
461 {"Backward", Action_Backward },
462 {"TurnLeft", Action_TurnLeft },
463 {"TurnRight", Action_TurnRight },
464 {"StepLeft", Action_StepLeft },
465 {"StepRight", Action_StepRight },
466 {"Jump", Action_Jump },
467 {"Crouch", Action_Crouch },
468 {"Punch",Action_Punch },
469 {"Kick", Action_Kick },
470 {"Block", Action_Block }
471};
472
473KeyBit Actions2[9] = {
474 {"Walk", Action2_Walk},
475 {"Action", Action2_Action},
476 {"Hypo", Action2_Hypo},
477 {"Reload", Action2_Reload },
478 {"Swap", Action2_Swap },
479 {"Drop", Action2_Drop },
480 {"Fire1", Action2_Fire1 },
481 {"Fire2", Action2_Fire2 },
482 {"Fire3", Action2_Fire3 }
483};
484uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
485{
486 uint32_t index;
487 uint32_t i = 2;
488 uint32_t j = 0;
489 int Input1 = 0;
490 int Input2 = 0;
491 Character* Chr;
492 ActiveCharacter* Active;
493 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
494 else index = args[0].value_int32;
495
[568]496 Chr = &(ONgGameState->CharacterStorage[index]);
497 Active = ONrGetActiveCharacter(Chr);
[567]498 if (!Active) return 1;
499
500 for(i = 1; i < numargs - 1; i++) {
501 for(j = 0; j < 32; j++) {
502 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
503 Input1 = Input1 | Actions1[j].Bit;
504 }
505 }
506 for(j = 0; j < 9; j++) {
507 if(!strcmp(args[i].value_str32, Actions2[j].Name)) {
508 Input2 = Input2 | Actions2[j].Bit;
509 }
510 }
511 }
512 Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1;
[572]513 Active->Input.Current.Actions2 = Active->Input.Current.Actions2 | Input2;
[567]514 if( Input1 + Input2 == 0 ) {
515 DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name);
516 return 0;
517 }
518 if ( args[numargs - 1].value_int32 <= 0) {
519 return 0;
520 }
521 else {
522 args[numargs - 1].value_int32 -= 1;
523 *dontuse2 = 1;
524 *dontuse1 = 1;
525 }
526 return 0;
527}
528
529uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
530 {
531// int index;
532// if (numargs < 4) index = 0;
533// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
534// else index = args[0].value_int32;
535
536// Character* Chr = ONgGameState->CharacterStorage;
537// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
538// if ((int)Active == 0) return 1;
539 uint32_t i = 2;
540 uint32_t j = 0;
541 int Input1 = 0;
542 int Input2 = 0;
543 for(i = 0; i < numargs; i++) {
544 for(j = 0; j < 32; j++) {
545 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
546 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
547 Input1 = Input1 | Actions1[j].Bit;
548 //DDrConsole_PrintF("Success!");
549 }
550
551 }
552 for(j = 0; j < 9; j++) {
553 if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
554
555 }
556 }
557 //DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10));
558 ret->value_int32 = 0;
559 ret->type = sl_int32;
560 if ( (ONgGameState->Input.Current.Actions1 == Input1) && (ONgGameState->Input.Current.Actions2 == Input2)) ret->value_int32 = 1;
561 return 0;
562}
563
564uint16_t ONICALL bsl_waitforkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
565 {
566// int index;
567// if (numargs < 4) index = 0;
568// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
569// else index = args[0].value_int32;
570
571// Character* Chr = ONgGameState->CharacterStorage;
572// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
573// if ((int)Active == 0) return 1;
[569]574
[567]575 int i = 2;
576 int j = 0;
577 int Input1 = 0;
578 int Input2 = 0;
[569]579/*
580 numargs = 0;
581 for(i = 0; args[i].type <= sl_void; i++)
582 {
583 //DDrConsole_PrintF("%i", args[i].type );
584 numargs++;
585
586 }
587 if(numargs < 1 || args[0].value == 0) return;
588 //for(i = 0; i < numargs; i++) {
589 */
590 i = 0;
[567]591 for(j = 0; j < 32; j++) {
592 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
593 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
594 Input1 = Input1 | Actions1[j].Bit;
595 //DDrConsole_PrintF("Success!");
596 }
597
598 }
599 for(j = 0; j < 9; j++) {
600 if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
601
602 }
[569]603 // }
604 DDrConsole_PrintF("Waiting...");
[567]605 if (
606 (( ONgGameState->Input.Current.Actions1 & Input1) == Input1) &&
607 (( ONgGameState->Input.Current.Actions2 & Input2) == Input2)
[569]608 )
609 {
610 DDrConsole_PrintF("Found key!");
[567]611 }
612 else {
613 //else (int)*ret = 1;
614 *dontuse2 = 1;
615 *dontuse1 = 1;
616 }
[569]617 return 0;
[567]618}
619
[569]620
[567]621uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
622{
[569]623 char output[1024];
624 char buffer[1024];
625 int i;
626 char* placeinoutput = output;
627 char* placeininput = args[0].value_str32;
628 int formatnum = 0;
629 //fix the broken bsl numargs...
630 numargs = 0;
631
632 for(i = 0; args[i].type < sl_void; i++)
633 {
634 numargs++;
635 }
636
637
638 if (numargs < 1)
[567]639 return 1;
640
[569]641 while(1)
642 {
643 int size;
644 //s is the pointer to the args
645 char* s = strchr(placeininput , '%');
646 //we didnt find a %, break!
647 if(!s)
648 {
649 strcpy(placeinoutput, placeininput);
650 break;
651 }
652 size = (int)s - (int)placeininput ;
653 //we found one, so copy the portion of string
654
655
656
657 memcpy( placeinoutput,placeininput, size);
658 placeininput += size;
659 placeinoutput += size;
660
661 memset( placeinoutput, '%', (int)pow(2, formatnum));
662 placeinoutput += (int)pow(2, formatnum);
663
664
665 placeininput += 1;
666 *placeinoutput = 0;
667 formatnum++;
668
669 }
670 //strcpy( output, args[0].value_str32 );
671
[567]672 for(i = 1; i < numargs; i++) {
[569]673 //sprintf(output, output, args[i].value_str32);
674 memcpy(buffer, output, 1024);
675 if(args[i].value == 0) break;
676 switch(args[i].type)
677 {
678 case sl_bool:
679 case sl_int32:
680 sprintf(output, buffer, args[i].value_int32);
681 break;
682 case sl_float:
683 //crashes oni, why?
684 // sprintf(output, output, args[i].value_float);
685 break;
686 case sl_str32:
687 sprintf(output, buffer, args[i].value_str32);
688 break;
689 case sl_void:
690 default:
691 break;
692 }
[567]693 }
[569]694 //output[32] = 0;
[567]695 ret->value_str32 = output;
696 ret->type = sl_str32;
697 return 0;
698}
[569]699
700//Sorry rossy, I broke this. FFI isnt in windows
[567]701/*
702uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
703{
[569]704
705
706 int ffi_ret;
707 char* str = NULL;
708 int size = 0;
709
710 ffi_cif cif;
711 ffi_type* ffi_args[256];
712 void* values[256];
713 int i;
714 numargs = 0;
715 for(i = 0; args[i].type <= sl_void; i++)
716 {
717 //DDrConsole_PrintF("%i", args[i].type );
718 numargs++;
719
720 }
721
[567]722 if (numargs < 1 || args[0].type != sl_str32)
723 {
724 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);
725 return 0;
726 }
727
728 if (!args[0].value_str32)
729 args[0].value_str32 = "";
730
731
732
733 ffi_args[0] = &ffi_type_pointer;
734 values[0] = &str;
735 ffi_args[1] = &ffi_type_uint32;
736 values[1] = &size;
737
[569]738
[567]739 for(i = 2; i < numargs + 2; i ++)
740 {
741 if (args[i - 2].type == sl_float)
742 {
743 float value_float = args[i - 2].value_float;
744 double* value_double = (double*)&(args[i - 2]);
745 *value_double = value_float;
746
747 ffi_args[i] = &ffi_type_double;
748 values[i] = value_double;
749 }
750 else
751 {
752 ffi_args[i] = &ffi_type_pointer;
753 values[i] = &(args[i - 2].value);
754 }
755 }
756
757 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK)
758 return 1;
[569]759 ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values);
[567]760 str = malloc(ffi_ret + 1);
761 size = ffi_ret + 1;
[569]762 ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values);
[567]763 ret->value_str32 = str;
764 ret->type = sl_str32;
765 return 0;
766}
767*/
768// Widescreen patch for talking heads.
769uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
770{
771 args[1].value_int32 = (double)args[1].value_int32 / (double)(gl_eng->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl_eng->DisplayMode.Height));
772 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
773}
774
775bool ini_inbsl = false;
776bool SLrIniCallback(char* section, bool newsection, char* name, char* value)
777{
778 if (newsection && !_stricmp(section, "bsl"))
779 ini_inbsl = true;
780
781 if (ini_inbsl)
782 {
783 char* type = value;
784 bool isptr = false;
785 sl_type bsl_type;
786
787 if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':')
788 {
789 isptr = true;
790 value += 4;
791 }
792
793
794
795 for (; *type; type++)
796 if (*type == ':')
797 {
798 *type = '\0';
799 type++;
800 break;
801 }
802
803 if (!*type)
804 DDrStartupMessage("badly formed bsl definition for \"%s\"", name);
805
806 if (!strcmp(type, "int"))
807 bsl_type = sl_int32;
808 else if (!strcmp(type, "string"))
809 bsl_type = sl_str32;
810 else if (!strcmp(type, "float"))
811 bsl_type = sl_float;
812 else if (!strcmp(type, "bool"))
813 bsl_type = sl_bool;
814 else
815 {
816 DDrStartupMessage("unknown type in bsl definition for \"%s\"", name);
817 return true;
818 }
819
820 if (isptr)
821 {
822 char* bsl_var = malloc(strlen(name) + 1);
823 memcpy(bsl_var, name, strlen(name) + 1);
824 switch (bsl_type)
825 {
826 case sl_int32:
827 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false));
828 break;
829 case sl_float:
830 SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false));
831 break;
832 default:
833 break;
834 }
835 }
836 else
837 {
838 char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t));
839 int32_t* bsl_val = (int32_t*)bsl_var;
840 bsl_var += sizeof(int32_t);
841 memcpy(bsl_var, name, strlen(name) + 1);
842
843 switch (bsl_type)
844 {
845 case sl_int32:
846 *bsl_val = inifile_parseint(value, false);
847 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val);
848 break;
849 case sl_float:
850 break;
851 default:
852 break;
853 }
854 }
855 }
856 return true;
857}
858
859void SLrConfig()
860{
861 DDrStartupMessage("re-parsing daodan.ini for bsl...");
862 inifile_read("daodan.ini", SLrIniCallback);
863 DDrStartupMessage("finished parsing");
864}
865
866void ONICALL SLrDaodan_Register_ReturnType(char* name, char* desc, char* argfmt, sl_type type, sl_func callback) {
867 char argfmt2[512];
868 uint16_t errornum;
869 sprintf_s(argfmt2, 512, "%s [|]", argfmt);
870 errornum = SLrScript_Command_Register_ReturnType(name, desc, argfmt2, type, callback);
871 if(errornum)
872 {
873 DDrStartupMessage("Registration of script command %s failed with error %i", name, errornum);
874 }
875
876}
[572]877
[567]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;
[572]883
884 if(!TSrTest){
885 TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma);
[567]886 returnval = TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest);
[572]887 }
888 DDrPatch_MakeCall(0x004FBCEA, DDrText_Hook);
889
890 *dontuse2 = 1;
[567]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 dsfmt_gv_init_gen_rand((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);
[572]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);
[567]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);
[568]914 //d_holdkey is broken!
[567]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);
[572]917 SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "", sl_float, bsl_location);
[567]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);
[569]919 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "key:string", bsl_waitforkey);
[567]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
[569]927 SLrScript_Command_Register_Void("sprintf", "C-style sprintf.", "", bsl_sprintf);
[572]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);
[567]930
931 //Flatline
932//#ifdef FLATLINE
933 SLrFlatline_Initialize();
934//#endif
935}
936
937void SLrDaodan_Patch()
938{
939 DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch);
940}
Note: See TracBrowser for help on using the repository browser.