source: Daodan/MSVC/Daodan_BSL.c@ 567

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

Daodan MSVC

File size: 27.1 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
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
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
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) {
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
303uint16_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
326uint16_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
346uint16_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
370uint16_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
378uint16_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
405uint16_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
414typedef struct {
415char Name[16];
416int Bit;
417} KeyBit;
418
419KeyBit 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
454KeyBit 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};
465uint16_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;
478 Active = ONrGetActiveCharacter(&Chr[index]);
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
510uint16_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
545uint16_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 int i = 2;
556 int j = 0;
557 int Input1 = 0;
558 int Input2 = 0;
559 for(i = 0; i < numargs; i++) {
560 for(j = 0; j < 32; j++) {
561 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
562 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
563 Input1 = Input1 | Actions1[j].Bit;
564 //DDrConsole_PrintF("Success!");
565 }
566
567 }
568 for(j = 0; j < 9; j++) {
569 if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
570
571 }
572 }
573 //DDrConsole_PrintF("Waiting...");
574 if (
575 (( ONgGameState->Input.Current.Actions1 & Input1) == Input1) &&
576 (( ONgGameState->Input.Current.Actions2 & Input2) == Input2)
577 ){
578 }
579 else {
580 //else (int)*ret = 1;
581 *dontuse2 = 1;
582 *dontuse1 = 1;
583 }
584/*
585 __asm__(
586 "movl 0x10(%esp), %edx\n\t"
587 "movl $1,(%eax)\n\t"
588 );
589 //ret->type = sl_void
590*/ return 0;
591}
592
593/*
594uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
595{
596 if (numargs < 2)
597 return 1;
598
599 char output[255];
600 int i;
601 for(i = 1; i < numargs; i++) {
602 sprintf(output, args[0].value_str32, args[i].value_str32);
603 }
604
605 ret->value_str32 = output;
606 ret->type = sl_str32;
607 return 0;
608}
609*/
610/*
611uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
612{
613 if (numargs < 1 || args[0].type != sl_str32)
614 {
615 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);
616 return 0;
617 }
618
619 if (!args[0].value_str32)
620 args[0].value_str32 = "";
621
622 int ffi_ret;
623 char* str = NULL;
624 int size = 0;
625
626 ffi_cif cif;
627 ffi_type* ffi_args[256];
628 void* values[256];
629
630 ffi_args[0] = &ffi_type_pointer;
631 values[0] = &str;
632 ffi_args[1] = &ffi_type_uint32;
633 values[1] = &size;
634
635 int i;
636 for(i = 2; i < numargs + 2; i ++)
637 {
638 if (args[i - 2].type == sl_float)
639 {
640 float value_float = args[i - 2].value_float;
641 double* value_double = (double*)&(args[i - 2]);
642 *value_double = value_float;
643
644 ffi_args[i] = &ffi_type_double;
645 values[i] = value_double;
646 }
647 else
648 {
649 ffi_args[i] = &ffi_type_pointer;
650 values[i] = &(args[i - 2].value);
651 }
652 }
653
654 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK)
655 return 1;
656 ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values);
657 str = malloc(ffi_ret + 1);
658 size = ffi_ret + 1;
659 ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values);
660 ret->value_str32 = str;
661 ret->type = sl_str32;
662 return 0;
663}
664*/
665// Widescreen patch for talking heads.
666uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
667{
668 args[1].value_int32 = (double)args[1].value_int32 / (double)(gl_eng->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl_eng->DisplayMode.Height));
669 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
670}
671
672bool ini_inbsl = false;
673bool SLrIniCallback(char* section, bool newsection, char* name, char* value)
674{
675 if (newsection && !_stricmp(section, "bsl"))
676 ini_inbsl = true;
677
678 if (ini_inbsl)
679 {
680 char* type = value;
681 bool isptr = false;
682 sl_type bsl_type;
683
684 if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':')
685 {
686 isptr = true;
687 value += 4;
688 }
689
690
691
692 for (; *type; type++)
693 if (*type == ':')
694 {
695 *type = '\0';
696 type++;
697 break;
698 }
699
700 if (!*type)
701 DDrStartupMessage("badly formed bsl definition for \"%s\"", name);
702
703 if (!strcmp(type, "int"))
704 bsl_type = sl_int32;
705 else if (!strcmp(type, "string"))
706 bsl_type = sl_str32;
707 else if (!strcmp(type, "float"))
708 bsl_type = sl_float;
709 else if (!strcmp(type, "bool"))
710 bsl_type = sl_bool;
711 else
712 {
713 DDrStartupMessage("unknown type in bsl definition for \"%s\"", name);
714 return true;
715 }
716
717 if (isptr)
718 {
719 char* bsl_var = malloc(strlen(name) + 1);
720 memcpy(bsl_var, name, strlen(name) + 1);
721 switch (bsl_type)
722 {
723 case sl_int32:
724 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false));
725 break;
726 case sl_float:
727 SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false));
728 break;
729 default:
730 break;
731 }
732 }
733 else
734 {
735 char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t));
736 int32_t* bsl_val = (int32_t*)bsl_var;
737 bsl_var += sizeof(int32_t);
738 memcpy(bsl_var, name, strlen(name) + 1);
739
740 switch (bsl_type)
741 {
742 case sl_int32:
743 *bsl_val = inifile_parseint(value, false);
744 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val);
745 break;
746 case sl_float:
747 break;
748 default:
749 break;
750 }
751 }
752 }
753 return true;
754}
755
756void SLrConfig()
757{
758 DDrStartupMessage("re-parsing daodan.ini for bsl...");
759 inifile_read("daodan.ini", SLrIniCallback);
760 DDrStartupMessage("finished parsing");
761}
762
763void ONICALL SLrDaodan_Register_ReturnType(char* name, char* desc, char* argfmt, sl_type type, sl_func callback) {
764 char argfmt2[512];
765 uint16_t errornum;
766 sprintf_s(argfmt2, 512, "%s [|]", argfmt);
767 errornum = SLrScript_Command_Register_ReturnType(name, desc, argfmt2, type, callback);
768 if(errornum)
769 {
770 DDrStartupMessage("Registration of script command %s failed with error %i", name, errornum);
771 }
772
773}
774void* TSrTest = 0;
775uint16_t ONICALL new_text(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
776{
777 void* TSFFTahoma;
778 int returnval;
779
780 TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma);
781 returnval = TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest);
782 return 0;
783}
784
785void SLrDaodan_Initalize()
786{
787 //Calculating the value of the needed offset is much more reliable when the compiler does it for you.
788
789 //TODO: fix moonshadow.
790 Character * Chr = 0;
791
792 int NoPath = (int)&(Chr[0].RegenHax) & 0x000000FF;
793
794
795
796 const char regen_patch[] =
797 {0x90, 0x90, 0x90, 0x90, 0x90, // mov al, _WPgRegenerationCheat
798 0x90, 0x90, // test al, al
799 0x90, 0x90, // jz short loc_51BB98
800 0x8B, 0x86, (char)NoPath, 0x01};
801 DDrPatch_Const(OniExe + 0x0011BB64, regen_patch);
802
803 SLrConfig();
804
805 SLrScript_Command_Register_Void("debug_daodan","Adds text to screen", "", new_text);
806
807 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
808 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
809 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
810 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
811 dsfmt_gv_init_gen_rand((uint32_t)time(NULL));
812 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
813 SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:string | script_id:int] [|]", sl_int32, bsl_getkills);
814 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);
815 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);
816 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
817 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);
818 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);
819 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);
820 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);
821 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);
822 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);
823 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);
824 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);
825 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "keys", bsl_waitforkey);
826
827 //broken, only works for one damage type.
828 //SLrDaodan_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
829
830 //used for debugging.
831// SLrDaodan_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
832
833 //SLrDaodan_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf);
834
835 SLrScript_Command_Register_ReturnType("st", "prints to console in color", "text:string color1:int color2:int", sl_void, bsl_dprintcolored);
836
837 //Flatline
838//#ifdef FLATLINE
839 SLrFlatline_Initialize();
840//#endif
841}
842
843void SLrDaodan_Patch()
844{
845 DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch);
846}
Note: See TracBrowser for help on using the repository browser.