source: Daodan/src/Daodan_BSL.c@ 992

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

Daodan: Removed unused MSVC tree, build folders; reorganized source layout; removed Flatline from current Daodan

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