source: Daodan/src/Daodan_BSL.c@ 990

Last change on this file since 990 was 882, checked in by alloc, 11 years ago

Daodan: Added BSL var "show_triggervolumes". Not yet working though

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