source: Daodan/src/Patches/BSL.c@ 1008

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

Daodan: Revamped some code, added quite a few comments to patches, updated options/patches names and descriptions

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