source: Daodan/src/Daodan_BSL.c@ 481

Last change on this file since 481 was 481, checked in by gumby, 15 years ago

Added d_distance and d_location

File size: 26.0 KB
Line 
1#include <stdio.h>
2#include <stdbool.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 "Daodan_Utility.h"
10#include "Daodan_Patch.h"
11#include "Daodan_Console.h"
12#include "BFW_ScriptLang.h"
13#include "Oni.h"
14#include "Oni_Character.h"
15#include "oni_gl.h"
16#include "dSFMT\dSFMT.h"
17#include "Daodan_Character.h"
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->value_int32 = args[0].value_int32 * args[1].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].value_int32;
33 else
34 val1 = args[0].value_float;
35
36 if (args[1].type == sl_int32)
37 val2 = args[1].value_int32;
38 else
39 val2 = args[1].value_float;
40
41 ret->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->value_int32 = args[0].value_int32 / args[1].value_int32;
49 ret->type = sl_int32;
50 return 0;
51}
52
53uint16_t ONICALL bsl_div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
54{
55 double val1;
56 double val2;
57
58 if (args[0].type == sl_int32)
59 val1 = args[0].value_int32;
60 else
61 val1 = args[0].value_float;
62
63 if (args[1].type == sl_int32)
64 val2 = args[1].value_int32;
65 else
66 val2 = args[1].value_float;
67
68 ret->value_float = (float)(val1 / val2);
69 ret->type = sl_float;
70 return 0;
71}
72
73uint16_t ONICALL bsl_int32rand(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
74{
75 int32_t start = 0;
76 int32_t end = 0;
77
78 if (args[0].value_int32 == args[1].value_int32)
79 return 1;
80 else if (args[0].value_int32 > args[1].value_int32)
81 {
82 start = args[1].value_int32;
83 end = args[0].value_int32;
84 }
85 else
86 {
87 start = args[0].value_int32;
88 end = args[1].value_int32;
89 }
90
91 ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1));
92 ret->type = sl_int32;
93 return 0;
94}
95
96uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
97{
98 int index;
99 if (numargs == 0) index = 0;
100 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
101 else index = args[0].value_int32;
102 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1670;
103 ret->value_int32 = *killcount;
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].value_str32);
113 else index = args[0].value_int32;
114 int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1674;
115 ret->value_int32 = *killcount;
116 ret->type = sl_int32;
117 return 0;
118}
119
120uint16_t ONICALL bsl_returnoffset(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
121{
122 //int offset = 140;
123 //if (== 1) offset = 148;
124 //else index = args[0].value_int32;
125 int* killcount = ONgGameState + args[0].value_int32;
126 ret->value_int32 = *killcount;
127 ret->type = sl_int32;
128 return 0;
129}
130
131
132uint16_t ONICALL bsl_powerup(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
133{
134 int index;
135 if (numargs < 2 || args[1].type != sl_str32) return 1;
136 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
137 else index = args[0].value_int32;
138 void* returnval;
139 bool is_lsi = 0;
140 Character* Chr = ONgGameState + 0x1260;
141 if(!strcmp(args[1].value_str32,"ammo"))
142 {
143 returnval = &(Chr[index].Inventory_.AmmoUsed);
144 }
145 else if(!strcmp(args[1].value_str32,"hypo"))
146 {
147 returnval = &(Chr[index].Inventory_.HypoUsed);
148 }
149 else if(!strcmp(args[1].value_str32,"cells"))
150 {
151 returnval = &(Chr[index].Inventory_.CellsUsed);
152 }
153 else if(!strcmp(args[1].value_str32,"invis"))
154 {
155 returnval = &(Chr[index].Inventory_.CloakUsed);
156 }
157 else if(!strcmp(args[1].value_str32,"shield"))
158 {
159 returnval = &(Chr[index].Inventory_.ShieldUsed);
160 }
161 else if(!strcmp(args[1].value_str32,"lsi"))
162 {
163 returnval = &(Chr[index].Inventory_.hasLSI);
164 is_lsi = 1;
165 }
166// else if(!strcmp(args[1].value_str32,"bossshield"))
167// {
168// ret->value_int32 = Chr[index].Flags & char_bossshield;
169// ret->type = sl_int32;
170// if (numargs >=3) {
171// if (Chr[index].Flags & char_bossshield) Chr[index].Flags = Chr[index].Flags & ~char_bossshield;
172// else Chr[index].Flags = Chr[index].Flags | char_bossshield;
173// }
174// return 0;
175// }
176 else return 1;
177 //todo, add setting
178
179 if(is_lsi) ret->value_int32 = (int)*(bool*)returnval;
180 else ret->value_int32 = *(int*)returnval;
181 ret->type = sl_int32;
182
183 if (numargs >= 3)
184 {
185 if(is_lsi) *(bool*)returnval = args[2].value_int32;
186 else *(int*)returnval = args[2].value_int32;
187 }
188
189
190 return 0;
191}
192
193uint16_t ONICALL bsl_health(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
194{
195 int index;
196 if (numargs == 0) index = 0;
197 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
198 else index = args[0].value_int32;
199 Character* Chr = ONgGameState + 0x1260 ;
200 int* health = &Chr[index].Health;
201
202 ret->value_int32 = *health;
203 ret->type = sl_int32;
204
205 if (numargs >= 2) {
206 *health = args[1].value_int32;
207 }
208 ret->value_int32 = *health;
209 ret->type = sl_int32;
210 return 0;
211}
212
213uint16_t ONICALL bsl_regen(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
214{
215 int index;
216 if (numargs == 0) index = 0;
217 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
218 else index = args[0].value_int32;
219 Character* Chr = ONgGameState + 0x1260 ;
220 int* health = (int)&Chr[index] + 0x144;
221
222 ret->value_int32 = *health;
223 ret->type = sl_int32;
224
225 if (numargs >= 2) {
226 *health = args[1].value_int32;
227 }
228 return 0;
229}
230
231uint16_t ONICALL bsl_distance(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
232
233 if (numargs < 2) return 1;
234 int index;
235 int index2;
236 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
237 else index = args[0].value_int32;
238 if (index == -1) index = args[0].value_int32;
239
240 if (args[1].type == sl_str32) index2 = DDrGetCharacterIndexFromName(args[1].value_str32);
241 else index2 = args[1].value_int32;
242 if (index2 == -1) index2 = args[1].value_int32;
243
244 Character* Chr = ONgGameState + 0x1260;
245 Character* Char1 = &Chr[index];
246 Character* Char2 = &Chr[index2];
247
248 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));
249 ret->type = sl_float;
250 return 0;
251}
252uint16_t ONICALL bsl_location(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
253 int index;
254 if (numargs < 2) return 1;
255 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
256 else index = args[0].value_int32;
257 if (index == -1) index = args[0].value_int32;
258 Character* Chr = ONgGameState + 0x1260;
259 float* loc;
260 if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x"))
261 loc = &(Chr[index].Position.X);
262 else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y"))
263 loc = &(Chr[index].Position.Y);
264 else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z"))
265 loc = &(Chr[index].Position.Z);
266 else if (numargs == 4) {
267 //currently broken. crashes oni.
268 Chr[index].Position.X = args[1].value_float;
269 Chr[index].Position.Y = args[2].value_float;
270 Chr[index].Position.Z = args[3].value_float;
271 ret->value_float = 1;
272 ret->type = sl_float;
273 return 0;
274 }
275 else return 1;
276
277 ret->value_float = *loc;
278 ret->type = sl_float;
279
280 if(numargs == 3) {
281 //currently broken, does nothing.
282 *loc = args[2].value_float;
283 }
284 return 0;
285}
286
287uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
288{
289 int index;
290 if (numargs == 0) index = 0;
291 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
292 else index = args[0].value_int32;
293 Character* Chr = ONgGameState + 0x1260 ;
294 int* maxhealth = &Chr[index].MaxHealth;
295 int oldmaxhealth = Chr[index].MaxHealth;
296 int oldhealth = Chr->Health;
297 if (numargs >= 2) {
298 *maxhealth = args[1].value_int32;
299 }
300 if (numargs >= 3 && args[2].value_bool) {
301 Chr->Health = (int)(((float)args[1].value_int32 / (float)oldmaxhealth) * (float)oldhealth);
302 }
303 ret->value_int32 = oldmaxhealth;
304 ret->type = sl_int32;
305 return 0;
306}
307
308uint16_t ONICALL bsl_getattacker(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
309{
310 //broken
311
312 int index;
313 if (numargs == 0) index = 0;
314 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
315 else index = args[0].value_int32;
316
317 Character* Chr = ONgGameState + 0x1260;
318 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
319 if ((int)Active == 0) return 1;
320// ret->value_int32 = Active->LastDamageSourceCharacter;
321 ret->type = sl_int32;
322 return 0;
323}
324
325
326
327uint16_t ONICALL bsl_chrname(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
328{
329 int index;
330 if (numargs == 0) index = 0;
331 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
332 else index = args[0].value_int32;
333 if (index == -1) {
334 ret->type = sl_str32;
335 ret->value_str32 = "NULL";
336 return 0;
337 }
338 char* name = ONgGameState + 0x1260 + index * 0x16A0 + 0x14;
339 if (numargs == 2) {
340 strncpy(name, (char*)args[1].value_str32, 31);
341 }
342
343 ret->type = sl_str32;
344 ret->value_str32 = name;
345
346 return 0;
347}
348
349
350uint16_t ONICALL bsl_count(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
351{
352 //testing numargs...
353 ret->type = sl_int32;
354 ret->value_int32 = numargs;
355 return 0;
356}
357
358uint16_t ONICALL bsl_dprintcolored(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
359{
360 //TODO: figure out why our implementation of dprint shows after dev mode is turned off
361 RGBA color;
362 RGBA shade;
363
364 if(numargs == 0) return 0;
365 if(numargs > 1 ) color.R = (char)args[1].value_int32;
366 else color.R = 255;
367 if(numargs > 2 ) color.G = (char)args[2].value_int32;
368 else color.G = 255;
369 if(numargs > 3 ) color.B = (char)args[3].value_int32;
370 else color.B = 255;
371 color.A = 0;
372 if(numargs > 5 ) shade.R = (char)args[5].value_int32;
373 else shade.R = 0x3F;
374 if(numargs > 6 ) shade.G = (char)args[6].value_int32;
375 else shade.G = 0x3F;
376 if(numargs > 7 ) shade.B = (char)args[7].value_int32;
377 else shade.B = 0x3F;
378 shade.A = 0;
379
380 DDrConsole_PrintColored(args[0].value_str32, 1, color, shade);
381 return 0;
382}
383
384
385uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
386{
387
388 ret->type = sl_int32;
389 ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32);
390
391 return 0;
392}
393
394uint16_t ONICALL bsl_getactiveoffset(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
395{
396 DDrConsole_PrintF("Character: 0x%x",(int)ONgGameState + 0x1260);
397 DDrConsole_PrintF("ActiveChar: 0x%x",(int)ONrGetActiveCharacter((void*)((int)ONgGameState + 0x1260)));
398 return 0;
399}
400typedef struct {
401char Name[16];
402int Bit;
403} KeyBit;
404
405KeyBit Actions1[32] = {
406 {"Escape", Action_Escape},
407 {"Console", Action_Console},
408 {"PauseScreen", Action_PauseScreen},
409 {"Cutscene1", Action_Cutscene_1 },
410 {"Cutscene2", Action_Cutscene_2 },
411 {"F4", Action_F4 },
412 {"F5", Action_F5 },
413 {"F6", Action_F6 },
414 {"F7", Action_F7 },
415 {"F8", Action_F8 },
416 {"StartRecorn", Action_StartRecord },
417 {"StopRecord", Action_StopRecord },
418 {"PlayRecord", Action_PlayRecord },
419 {"F12", Action_F12 },
420 {"Unknown1", Action_Unknown1 },
421 {"LookMode", Action_LookMode },
422 {"Screenshot", Action_Screenshot },
423 {"Unknown2", Action_Unknown2 },
424 {"Unknown3", Action_Unknown3 },
425 {"Unknown4", Action_Unknown4 },
426 {"Unknown5", Action_Unknown5 },
427 {"Forward", Action_Forward },
428 {"Backward", Action_Backward },
429 {"TurnLeft", Action_TurnLeft },
430 {"TurnRight", Action_TurnRight },
431 {"StepLeft", Action_StepLeft },
432 {"StepRight", Action_StepRight },
433 {"Jump", Action_Jump },
434 {"Crouch", Action_Crouch },
435 {"Punch",Action_Punch },
436 {"Kick", Action_Kick },
437 {"Block", Action_Block }
438};
439
440KeyBit Actions2[9] = {
441 {"Walk", Action2_Walk},
442 {"Action", Action2_Action},
443 {"Hypo", Action2_Hypo},
444 {"Reload", Action2_Reload },
445 {"Swap", Action2_Swap },
446 {"Drop", Action2_Drop },
447 {"Fire1", Action2_Fire1 },
448 {"Fire2", Action2_Fire2 },
449 {"Fire3", Action2_Fire3 }
450};
451uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
452 {
453 int index;
454
455 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
456 else index = args[0].value_int32;
457
458 Character* Chr = ONgGameState + 0x1260;
459 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
460 if ((int)Active == 0) return 1;
461 int i = 2;
462 int j = 0;
463 int Input1 = 0;
464 int Input2 = 0;
465 for(i = 1; i < numargs - 1; i++) {
466 for(j = 0; j < 32; j++) {
467 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
468 Input1 = Input1 | Actions1[j].Bit;
469 }
470 }
471 for(j = 0; j < 9; j++) {
472 if(!strcmp(args[i].value_str32, Actions2[j].Name)) {
473 Input2 = Input2 | Actions2[j].Bit;
474 }
475 }
476 }
477 Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1;
478 Active->Input.Current.Actions2 = Active->Input.Current.Actions1 | Input2;
479 if( Input1 + Input2 == 0 ) {
480 DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name);
481 return 0;
482 }
483 if ( args[numargs - 1].value_int32 <= 0) {
484 return 0;
485 }
486 else {
487 args[numargs - 1].value_int32 -= 1;
488 *dontuse2 = 1;
489 *dontuse1 = 1;
490 }
491 return 0;
492}
493
494uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
495 {
496// int index;
497// if (numargs < 4) index = 0;
498// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
499// else index = args[0].value_int32;
500
501// Character* Chr = ONgGameState + 0x1260;
502// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
503// if ((int)Active == 0) return 1;
504 int i = 2;
505 int j = 0;
506 int Input1 = 0;
507 int Input2 = 0;
508 for(i = 0; i < numargs; i++) {
509 for(j = 0; j < 32; j++) {
510 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
511 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
512 Input1 = Input1 | Actions1[j].Bit;
513 //DDrConsole_PrintF("Success!");
514 }
515
516 }
517 for(j = 0; j < 9; j++) {
518 if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
519
520 }
521 }
522 //DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10));
523 ret->value_int32 = 0;
524 ret->type = sl_int32;
525 if ( ((*(int*)(ONgGameState + 0xB8 + 0x10) & Input1) == Input1) && ((*(int*)(ONgGameState + 0xB8 + 0x14) & Input2) == Input2)) ret->value_int32 = 1;
526 return 0;
527}
528
529uint16_t ONICALL bsl_waitforkey(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 + 0x1260;
537// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
538// if ((int)Active == 0) return 1;
539 int i = 2;
540 int 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("Waiting...");
558 if ( ((*(int*)(ONgGameState + 0xB8 + 0x10) & Input1) == Input1) && ((*(int*)(ONgGameState + 0xB8 + 0x14) & Input2) == Input2)) {
559 }
560 else {
561 //else (int)*ret = 1;
562 *dontuse2 = 1;
563 *dontuse1 = 1;
564 }
565/*
566 __asm__(
567 "movl 0x10(%esp), %edx\n\t"
568 "movl $1,(%eax)\n\t"
569 );
570 //ret->type = sl_void
571*/ return 0;
572}
573
574/*
575uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
576{
577 if (numargs < 2)
578 return 1;
579
580 char output[255];
581 int i;
582 for(i = 1; i < numargs; i++) {
583 sprintf(output, args[0].value_str32, args[i].value_str32);
584 }
585
586 ret->value_str32 = output;
587 ret->type = sl_str32;
588 return 0;
589}
590*/
591uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
592{
593 if (numargs < 1 || args[0].type != sl_str32)
594 {
595 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);
596 return 0;
597 }
598
599 if (!args[0].value_str32)
600 args[0].value_str32 = "";
601
602 int ffi_ret;
603 char* str = NULL;
604 int size = 0;
605
606 ffi_cif cif;
607 ffi_type* ffi_args[256];
608 void* values[256];
609
610 ffi_args[0] = &ffi_type_pointer;
611 values[0] = &str;
612 ffi_args[1] = &ffi_type_uint32;
613 values[1] = &size;
614
615 int i;
616 for(i = 2; i < numargs + 2; i ++)
617 {
618 if (args[i - 2].type == sl_float)
619 {
620 float value_float = args[i - 2].value_float;
621 double* value_double = (double*)&(args[i - 2]);
622 *value_double = value_float;
623
624 ffi_args[i] = &ffi_type_double;
625 values[i] = value_double;
626 }
627 else
628 {
629 ffi_args[i] = &ffi_type_pointer;
630 values[i] = &(args[i - 2].value);
631 }
632 }
633
634 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK)
635 return 1;
636 ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values);
637 str = malloc(ffi_ret + 1);
638 size = ffi_ret + 1;
639 ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values);
640 ret->value_str32 = str;
641 ret->type = sl_str32;
642 return 0;
643}
644
645// Widescreen patch for talking heads.
646uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
647{
648 args[1].value_int32 = (double)args[1].value_int32 / (double)(gl->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl->DisplayMode.Height));
649 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
650}
651
652bool ini_inbsl = false;
653bool SLrIniCallback(char* section, bool newsection, char* name, char* value)
654{
655 if (newsection && !stricmp(section, "bsl"))
656 ini_inbsl = true;
657
658 if (ini_inbsl)
659 {
660 bool isptr = false;
661 sl_type bsl_type;
662
663 if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':')
664 {
665 isptr = true;
666 value += 4;
667 }
668
669 char* type = value;
670
671 for (; *type; type++)
672 if (*type == ':')
673 {
674 *type = '\0';
675 type++;
676 break;
677 }
678
679 if (!*type)
680 DDrStartupMessage("badly formed bsl definition for \"%s\"", name);
681
682 if (!strcmp(type, "int"))
683 bsl_type = sl_int32;
684 else if (!strcmp(type, "string"))
685 bsl_type = sl_str32;
686 else if (!strcmp(type, "float"))
687 bsl_type = sl_float;
688 else if (!strcmp(type, "bool"))
689 bsl_type = sl_bool;
690 else
691 {
692 DDrStartupMessage("unknown type in bsl definition for \"%s\"", name);
693 return true;
694 }
695
696 if (isptr)
697 {
698 char* bsl_var = malloc(strlen(name) + 1);
699 memcpy(bsl_var, name, strlen(name) + 1);
700 switch (bsl_type)
701 {
702 case sl_int32:
703 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false));
704 break;
705 case sl_float:
706 SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false));
707 break;
708 default:
709 break;
710 }
711 }
712 else
713 {
714 char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t));
715 int32_t* bsl_val = (int32_t*)bsl_var;
716 bsl_var += sizeof(int32_t);
717 memcpy(bsl_var, name, strlen(name) + 1);
718
719 switch (bsl_type)
720 {
721 case sl_int32:
722 *bsl_val = inifile_parseint(value, false);
723 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val);
724 break;
725 case sl_float:
726 break;
727 default:
728 break;
729 }
730 }
731 }
732 return true;
733}
734
735void SLrConfig()
736{
737 DDrStartupMessage("re-parsing daodan.ini for bsl...");
738 inifile_read("daodan.ini", SLrIniCallback);
739 DDrStartupMessage("finished parsing");
740}
741
742void SLrDaodan_Initalize()
743{
744
745 //const char regen_patch[] = {0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90};
746 //DDrPatch_Const(OniExe + 0x0011BB6D, regen_patch);
747
748 //This one should work but doesn't.
749 //const char regen_patch[] ={0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x8B, 0x86, 0x44};
750 //DDrPatch_Const(OniExe + 0x0011BB64, regen_patch);
751
752 SLrConfig();
753
754 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
755 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
756
757 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
758 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
759
760 dsfmt_gv_init_gen_rand((uint32_t)time(NULL));
761 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
762
763 SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:str | script_id:int]", sl_int32, bsl_getkills);
764 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);
765 SLrScript_Command_Register_ReturnType("d_name","Gets or sets a character's name", "[ai_name:str | script_id:int] [newname:string]", sl_str32, bsl_chrname);
766 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
767 SLrScript_Command_Register_ReturnType("d_health","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_health);
768 SLrScript_Command_Register_ReturnType("d_regen","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_regen);
769 SLrScript_Command_Register_ReturnType("d_maxhealth","Gets or sets a character's maximum health", "[ai_name:str | script_id:int] [newmaxhealth:int] [scalehealth:bool]", sl_str32, bsl_maxhealth);
770 SLrScript_Command_Register_ReturnType("d_powerup","Gets or sets a character's powerups", "ai_name:str|script_id:int powerup:str", sl_int32, bsl_powerup);
771 SLrScript_Command_Register_ReturnType("d_holdkey","Makes a character hold a key", "[ai_name:string | script_id:int] keys frames:int", sl_int32, bsl_holdkey);
772 SLrScript_Command_Register_ReturnType("d_isheld","Checks if player is holding a key", "keys", sl_int32, bsl_isheld);
773 SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "ai_name:str | script_id:int xyz:string [newlocation:float]", sl_float, bsl_location);
774 SLrScript_Command_Register_ReturnType("d_distance","Returns the distance between two characters", "ai_name:str | script_id:int ai_name:str | script_id:int ", sl_float, bsl_distance);
775 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "keys", bsl_waitforkey);
776
777 //broken, only works for one damage type.
778 //SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
779
780 //used for debugging.
781 SLrScript_Command_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
782
783 SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf);
784
785 SLrScript_Command_Register_ReturnType("d_dprint", "prints to console in color", "text:string [color: r b g] [color: r b g]", sl_void, bsl_dprintcolored);
786
787 //SLrScript_Command_Register_ReturnType("d_offset", "a test", "thing:int", sl_int32, bsl_returnoffset);
788}
789
790void SLrDaodan_Patch()
791{
792 DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch);
793}
Note: See TracBrowser for help on using the repository browser.