source: Daodan/src/Daodan_BSL.c@ 679

Last change on this file since 679 was 677, checked in by alloc, 12 years ago

Daodan: Updated src to work with MinGW

File size: 28.5 KB
RevLine 
[443]1#include <stdio.h>
[677]2#include "bool.h"
[440]3#include <time.h>
[677]4//#include <ffi.h>
[481]5#include <math.h>
[451]6#include "inifile.h"
[439]7#include "Daodan_BSL.h"
[444]8#include "Daodan_Utility.h"
[447]9#include "Daodan_Patch.h"
[444]10#include "Daodan_Console.h"
[445]11#include "BFW_ScriptLang.h"
[441]12#include "Oni.h"
13#include "Oni_Character.h"
[447]14#include "oni_gl.h"
[446]15#include "Daodan_Character.h"
[677]16#include "BFW_Utility.h"
[440]17
[484]18
[474]19uint16_t ONICALL bsl_int32mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[439]20{
21 ret->value_int32 = args[0].value_int32 * args[1].value_int32;
22 ret->type = sl_int32;
23 return 0;
24}
25
[474]26uint16_t ONICALL bsl_mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[439]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
[474]46uint16_t ONICALL bsl_int32div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[439]47{
48 ret->value_int32 = args[0].value_int32 / args[1].value_int32;
49 ret->type = sl_int32;
50 return 0;
51}
[474]52uint16_t ONICALL bsl_div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[439]53{
54 double val1;
55 double val2;
56
57 if (args[0].type == sl_int32)
58 val1 = args[0].value_int32;
59 else
60 val1 = args[0].value_float;
61
62 if (args[1].type == sl_int32)
63 val2 = args[1].value_int32;
64 else
65 val2 = args[1].value_float;
66
67 ret->value_float = (float)(val1 / val2);
68 ret->type = sl_float;
69 return 0;
70}
[443]71
[474]72uint16_t ONICALL bsl_int32rand(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[443]73{
74 int32_t start = 0;
75 int32_t end = 0;
76
77 if (args[0].value_int32 == args[1].value_int32)
78 return 1;
79 else if (args[0].value_int32 > args[1].value_int32)
80 {
81 start = args[1].value_int32;
82 end = args[0].value_int32;
83 }
84 else
85 {
86 start = args[0].value_int32;
87 end = args[1].value_int32;
88 }
89
[677]90 ret->value_int32 = start + (rand() % (uint32_t)(end - start + 1));
[443]91 ret->type = sl_int32;
92 return 0;
93}
94
[474]95uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[443]96{
97 int index;
98 if (numargs == 0) index = 0;
[446]99 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
[443]100 else index = args[0].value_int32;
[677]101 //killcount = ONgGameState->CharacterStorage[index].Kills;
102 //ONgGameState + index * 0x16A0 + 0x1260 + 0x1670;
103 ret->value_int32 = ONgGameState->CharacterStorage[index].Kills;
[443]104 ret->type = sl_int32;
105 return 0;
106}
107
[474]108uint16_t ONICALL bsl_getdamage(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[443]109{
110 int index;
111 if (numargs == 0) index = 0;
[446]112 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
[443]113 else index = args[0].value_int32;
[677]114 ret->value_int32 = ONgGameState->CharacterStorage[index].Damage;
[443]115 ret->type = sl_int32;
116 return 0;
117}
[446]118
[470]119
120
[474]121uint16_t ONICALL bsl_powerup(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]122{
123 int index;
[677]124 void* returnval;
125 bool is_lsi = 0;
126 Character* Chr = ONgGameState->CharacterStorage;
127
[446]128 if (numargs < 2 || args[1].type != sl_str32) return 1;
129 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
130 else index = args[0].value_int32;
[677]131
132
133
[450]134 if(!strcmp(args[1].value_str32,"ammo"))
[446]135 {
[677]136 returnval = &(Chr[index].Inventory.AmmoUsed);
[450]137 }
138 else if(!strcmp(args[1].value_str32,"hypo"))
139 {
[677]140 returnval = &(Chr[index].Inventory.HypoUsed);
[450]141 }
142 else if(!strcmp(args[1].value_str32,"cells"))
143 {
[677]144 returnval = &(Chr[index].Inventory.CellsUsed);
[450]145 }
146 else if(!strcmp(args[1].value_str32,"invis"))
147 {
[677]148 returnval = &(Chr[index].Inventory.CloakUsed);
[450]149 }
150 else if(!strcmp(args[1].value_str32,"shield"))
151 {
[677]152 returnval = &(Chr[index].Inventory.ShieldUsed);
[450]153 }
154 else if(!strcmp(args[1].value_str32,"lsi"))
155 {
[677]156 returnval = &(Chr[index].Inventory.hasLSI);
[450]157 is_lsi = 1;
158 }
[451]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// }
[450]169 else return 1;
[446]170 //todo, add setting
171
[450]172 if(is_lsi) ret->value_int32 = (int)*(bool*)returnval;
173 else ret->value_int32 = *(int*)returnval;
174 ret->type = sl_int32;
175
176 if (numargs >= 3)
[446]177 {
[450]178 if(is_lsi) *(bool*)returnval = args[2].value_int32;
179 else *(int*)returnval = args[2].value_int32;
[446]180 }
[450]181
182
[446]183 return 0;
184}
185
[474]186uint16_t ONICALL bsl_health(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]187{
188 int index;
[677]189 Character* Chr;
190 int* health;
[446]191 if (numargs == 0) index = 0;
192 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
193 else index = args[0].value_int32;
[677]194 Chr = ONgGameState->CharacterStorage;
195 health = &Chr[index].Health;
[446]196
197 ret->value_int32 = *health;
198 ret->type = sl_int32;
199
[677]200 if (args[1].value_int32) {
[446]201 *health = args[1].value_int32;
202 }
203 ret->value_int32 = *health;
204 ret->type = sl_int32;
205 return 0;
206}
207
[474]208uint16_t ONICALL bsl_regen(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[470]209{
210 int index;
[677]211 Character* Chr;
[470]212 if (numargs == 0) index = 0;
213 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
214 else index = args[0].value_int32;
[677]215 Chr = ONgGameState->CharacterStorage ;
[484]216
[677]217
[484]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 */
[677]229 ret->value_int32 = Chr[index].RegenHax;
[470]230 ret->type = sl_int32;
231
232 if (numargs >= 2) {
[677]233 Chr[index].RegenHax = args[1].value_int32;
[470]234 }
235 return 0;
236}
237
[677]238//wow this is broken.
[481]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;
[677]242 Character* Chr = ONgGameState->CharacterStorage;
243 Character* Char1;
244 Character* Char2;
245
246 if (numargs < 2) return 1;
247
[481]248 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
249 else index = args[0].value_int32;
250 if (index == -1) index = args[0].value_int32;
[470]251
[481]252 if (args[1].type == sl_str32) index2 = DDrGetCharacterIndexFromName(args[1].value_str32);
253 else index2 = args[1].value_int32;
254 if (index2 == -1) index2 = args[1].value_int32;
[677]255 Char1 = &Chr[index];
256 Char2 = &Chr[index2];
[481]257
[677]258
[481]259 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));
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) {
[677]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
[481]274 if (numargs < 2) return 1;
275 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
276 else index = args[0].value_int32;
277 if (index == -1) index = args[0].value_int32;
[677]278 Chr = ONgGameState->CharacterStorage;
279 if(numargs == 3)
280 {
281 if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x"))
282 loc = &(Chr[index].Position.X);
283 else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y"))
284 loc = &(Chr[index].Position.Y);
285 else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z"))
286 loc = &(Chr[index].Position.Z);
287 }
[481]288 else if (numargs == 4) {
[677]289 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
290 Chr[index].Location.X = args[1].value_float;
291 Chr[index].Location.Y = args[2].value_float;
292 Chr[index].Location.Z = args[3].value_float;
293 if(Active)
294 {
295 Active->PhyContext->Position = Chr[index].Location;
296 }
[481]297 ret->value_float = 1;
298 ret->type = sl_float;
299 return 0;
300 }
301 else return 1;
302
303 ret->value_float = *loc;
304 ret->type = sl_float;
305
306 if(numargs == 3) {
307 //currently broken, does nothing.
308 *loc = args[2].value_float;
309 }
310 return 0;
311}
312
[474]313uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]314{
315 int index;
316 if (numargs == 0) index = 0;
317 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
318 else index = args[0].value_int32;
[677]319 if(1) {
320 Character* Chr = ONgGameState->CharacterStorage ;
[446]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].value_int32;
326 }
327 if (numargs >= 3 && args[2].value_bool) {
328 Chr->Health = (int)(((float)args[1].value_int32 / (float)oldmaxhealth) * (float)oldhealth);
329 }
330 ret->value_int32 = oldmaxhealth;
331 ret->type = sl_int32;
332 return 0;
[677]333 }
[446]334}
335
[474]336uint16_t ONICALL bsl_getattacker(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]337{
[470]338 //broken
339
[446]340 int index;
[450]341 if (numargs == 0) index = 0;
342 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
[446]343 else index = args[0].value_int32;
[677]344 if(1) {
345 Character* Chr = ONgGameState->CharacterStorage;
[450]346 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
[677]347 if (!Active) return 1;
[451]348// ret->value_int32 = Active->LastDamageSourceCharacter;
[446]349 ret->type = sl_int32;
350 return 0;
[677]351 }
[446]352}
353
354
[450]355
[474]356uint16_t ONICALL bsl_chrname(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]357{
358 int index;
[677]359 char* name;
360
[446]361 if (numargs == 0) index = 0;
362 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
363 else index = args[0].value_int32;
364 if (index == -1) {
365 ret->type = sl_str32;
366 ret->value_str32 = "NULL";
367 return 0;
368 }
[677]369 name = &ONgGameState->CharacterStorage[index].Name;
[446]370 if (numargs == 2) {
371 strncpy(name, (char*)args[1].value_str32, 31);
372 }
373
374 ret->type = sl_str32;
375 ret->value_str32 = name;
376
377 return 0;
378}
379
380
[474]381uint16_t ONICALL bsl_count(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]382{
383 //testing numargs...
384 ret->type = sl_int32;
385 ret->value_int32 = numargs;
386 return 0;
387}
388
[474]389uint16_t ONICALL bsl_dprintcolored(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]390{
391 //TODO: figure out why our implementation of dprint shows after dev mode is turned off
392 RGBA color;
393 RGBA shade;
[677]394 int i;
395 numargs = 0;
396 for(i = 0; args[i].type < sl_void; i++)
397 {
398 numargs++;
399 }
[446]400 if(numargs == 0) return 0;
401 if(numargs > 1 ) color.R = (char)args[1].value_int32;
402 else color.R = 255;
403 if(numargs > 2 ) color.G = (char)args[2].value_int32;
404 else color.G = 255;
405 if(numargs > 3 ) color.B = (char)args[3].value_int32;
406 else color.B = 255;
407 color.A = 0;
408 if(numargs > 5 ) shade.R = (char)args[5].value_int32;
409 else shade.R = 0x3F;
410 if(numargs > 6 ) shade.G = (char)args[6].value_int32;
411 else shade.G = 0x3F;
412 if(numargs > 7 ) shade.B = (char)args[7].value_int32;
413 else shade.B = 0x3F;
414 shade.A = 0;
415
416 DDrConsole_PrintColored(args[0].value_str32, 1, color, shade);
417 return 0;
418}
419
420
[474]421uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[446]422{
[481]423
[446]424 ret->type = sl_int32;
425 ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32);
[481]426
[446]427 return 0;
428}
[450]429
[470]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};
[474]481uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[677]482{
483 uint32_t index;
484 uint32_t i = 2;
485 uint32_t j = 0;
[470]486 int Input1 = 0;
487 int Input2 = 0;
[677]488 Character* Chr;
489 ActiveCharacter* Active;
490 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
491 else index = args[0].value_int32;
492
493 Chr = &(ONgGameState->CharacterStorage[index]);
494 Active = ONrGetActiveCharacter(Chr);
495 if (!Active) return 1;
496
[481]497 for(i = 1; i < numargs - 1; i++) {
[470]498 for(j = 0; j < 32; j++) {
[481]499 if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
500 Input1 = Input1 | Actions1[j].Bit;
501 }
[470]502 }
503 for(j = 0; j < 9; j++) {
[481]504 if(!strcmp(args[i].value_str32, Actions2[j].Name)) {
505 Input2 = Input2 | Actions2[j].Bit;
506 }
[470]507 }
508 }
[481]509 Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1;
[677]510 Active->Input.Current.Actions2 = Active->Input.Current.Actions2 | Input2;
[481]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].value_int32 <= 0) {
516 return 0;
517 }
518 else {
519 args[numargs - 1].value_int32 -= 1;
520 *dontuse2 = 1;
521 *dontuse1 = 1;
522 }
[470]523 return 0;
524}
525
[474]526uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[470]527 {
528// int index;
529// if (numargs < 4) index = 0;
530// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
531// else index = args[0].value_int32;
532
[677]533// Character* Chr = ONgGameState->CharacterStorage;
[470]534// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
535// if ((int)Active == 0) return 1;
[677]536 uint32_t i = 2;
537 uint32_t j = 0;
[470]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].value_str32, Actions1[j].Name, Actions1[j].Bit);
543 if(!strcmp(args[i].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].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->value_int32 = 0;
556 ret->type = sl_int32;
[677]557 if ( (ONgGameState->Input.Current.Actions1 == Input1) && (ONgGameState->Input.Current.Actions2 == Input2)) ret->value_int32 = 1;
[470]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].value_str32);
566// else index = args[0].value_int32;
567
[677]568// Character* Chr = ONgGameState->CharacterStorage;
[470]569// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
570// if ((int)Active == 0) return 1;
[677]571
[470]572 int i = 2;
573 int j = 0;
574 int Input1 = 0;
575 int Input2 = 0;
[677]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].value == 0) return;
585 //for(i = 0; i < numargs; i++) {
586 */
587 i = 0;
[470]588 for(j = 0; j < 32; j++) {
589 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
590 if(!strcmp(args[i].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].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
598
599 }
[677]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!");
[470]608 }
609 else {
610 //else (int)*ret = 1;
611 *dontuse2 = 1;
612 *dontuse1 = 1;
613 }
[677]614 return 0;
[470]615}
616
[677]617
[474]618uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[441]619{
[677]620 char output[1024];
621 char buffer[1024];
622 int i;
623 char* placeinoutput = output;
624 char* placeininput = args[0].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)
[441]636 return 1;
[445]637
[677]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
[444]669 for(i = 1; i < numargs; i++) {
[677]670 //sprintf(output, output, args[i].value_str32);
671 memcpy(buffer, output, 1024);
672 if(args[i].value == 0) break;
673 switch(args[i].type)
674 {
675 case sl_bool:
676 case sl_int32:
677 sprintf(output, buffer, args[i].value_int32);
678 break;
679 case sl_float:
680 //crashes oni, why?
681 // sprintf(output, output, args[i].value_float);
682 break;
683 case sl_str32:
684 sprintf(output, buffer, args[i].value_str32);
685 break;
686 case sl_void:
687 default:
688 break;
689 }
[441]690 }
[677]691 //output[32] = 0;
[441]692 ret->value_str32 = output;
693 ret->type = sl_str32;
694 return 0;
695}
[677]696
697//Sorry rossy, I broke this. FFI isnt in windows
698/*
[474]699uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[440]700{
[677]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
[445]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
[440]728
729
[443]730 ffi_args[0] = &ffi_type_pointer;
[444]731 values[0] = &str;
[443]732 ffi_args[1] = &ffi_type_uint32;
[444]733 values[1] = &size;
[443]734
[677]735
[443]736 for(i = 2; i < numargs + 2; i ++)
[440]737 {
[444]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 }
[440]752 }
753
[444]754 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK)
[445]755 return 1;
[677]756 ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values);
[444]757 str = malloc(ffi_ret + 1);
758 size = ffi_ret + 1;
[677]759 ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values);
[444]760 ret->value_str32 = str;
[443]761 ret->type = sl_str32;
[440]762 return 0;
763}
[677]764*/
[447]765// Widescreen patch for talking heads.
[474]766uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[447]767{
[677]768 args[1].value_int32 = (double)args[1].value_int32 / (double)(gl_eng->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl_eng->DisplayMode.Height));
[447]769 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
770}
771
[451]772bool ini_inbsl = false;
773bool SLrIniCallback(char* section, bool newsection, char* name, char* value)
774{
[677]775 if (newsection && !_stricmp(section, "bsl"))
[451]776 ini_inbsl = true;
777
778 if (ini_inbsl)
779 {
[677]780 char* type = value;
[451]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
[677]791
[451]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
[677]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 sprintf_s(argfmt2, 512, "%s [|]", argfmt);
867 errornum = SLrScript_Command_Register_ReturnType(name, desc, argfmt2, type, callback);
868 if(errornum)
869 {
870 DDrStartupMessage("Registration of script command %s failed with error %i", name, errornum);
871 }
872
873}
874
875void* TSrTest = 0;
876uint16_t ONICALL new_text(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
[439]877{
[677]878 void* TSFFTahoma;
879 int returnval;
[470]880
[677]881 if(!TSrTest){
882 TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma);
883 returnval = TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest);
884 }
885 DDrPatch_MakeCall(0x004FBCEA, DDrText_Hook);
886
887 *dontuse2 = 1;
888 return 0;
889}
[470]890
[677]891void SLrDaodan_Initalize()
892{
893 SLrConfig();
[484]894
[677]895 SLrScript_Command_Register_Void("debug_daodan","Adds text to screen", "", new_text);
[484]896
[439]897 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
898 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
899 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
900 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
[677]901 srand((uint32_t)time(NULL));
[443]902 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
[677]903 SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:string | script_id:int] [|]", sl_int32, bsl_getkills);
[446]904 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);
[677]905 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);
[481]906 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
[677]907 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);
908 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);
909 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);
910 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);
911 //d_holdkey is broken!
912 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);
913 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);
914 SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "", sl_float, bsl_location);
915 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);
916 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "key:string", bsl_waitforkey);
[470]917
[481]918 //broken, only works for one damage type.
[677]919 //SLrDaodan_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
[441]920
[481]921 //used for debugging.
[677]922// SLrDaodan_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
[450]923
[677]924 SLrScript_Command_Register_Void("sprintf", "C-style sprintf.", "", bsl_sprintf);
925 SLrScript_Command_Register_ReturnType("st", "prints to console in color", "", sl_void, bsl_dprintcolored);
926 SLrScript_Command_Register_ReturnType("d_dprint", "prints to console in color", "", sl_void, bsl_dprintcolored);
[447]927}
[451]928
[447]929void SLrDaodan_Patch()
930{
931 DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch);
932}
Note: See TracBrowser for help on using the repository browser.