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

Last change on this file since 1163 was 1161, checked in by rossy, 3 years ago

Daodan: Use uint64_t for Oni's action state

File size: 24.8 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];
433uint64_t Bit;
434} KeyBit;
435
436static KeyBit Actions[] = {
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 {"LookMode", Action_LookMode },
452 {"Screenshot", Action_Screenshot },
453 {"Forward", Action_Forward },
454 {"Backward", Action_Backward },
455 {"TurnLeft", Action_TurnLeft },
456 {"TurnRight", Action_TurnRight },
457 {"StepLeft", Action_StepLeft },
458 {"StepRight", Action_StepRight },
459 {"Jump", Action_Jump },
460 {"Crouch", Action_Crouch },
461 {"Punch",Action_Punch },
462 {"Kick", Action_Kick },
463 {"Block", Action_Block },
464 {"Walk", Action_Walk},
465 {"Action", Action_Action},
466 {"Hypo", Action_Hypo},
467 {"Reload", Action_Reload },
468 {"Swap", Action_Swap },
469 {"Drop", Action_Drop },
470 {"Fire1", Action_Fire1 },
471 {"Fire2", Action_Fire2 },
472 {"Fire3", Action_Fire3 }
473};
474
475uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
476{
477 uint32_t index;
478 uint32_t i = 2;
479 uint32_t j = 0;
480 uint64_t Input = 0;
481 Character* Chr;
482 ActiveCharacter* Active;
483 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
484 else index = args[0].val.value_int32;
485
486 Chr = &(ONgGameState->CharacterStorage[index]);
487 Active = ONrGetActiveCharacter(Chr);
488 if (!Active) return 1;
489
490 for(i = 1; i < numargs - 1; i++) {
491 for(j = 0; j < 32; j++) {
492 if(!strcmp(args[i].val.value_str32, Actions[j].Name)) {
493 Input = Input | Actions[j].Bit;
494 }
495 }
496 }
497 Active->Input.ActionsDown = Active->Input.ActionsDown | Input;
498 if( Input == 0 ) {
499 DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name);
500 return 0;
501 }
502 if ( args[numargs - 1].val.value_int32 <= 0) {
503 return 0;
504 }
505 else {
506 args[numargs - 1].val.value_int32 -= 1;
507 *dontuse2 = 1;
508 *dontuse1 = 1;
509 }
510 return 0;
511}
512
513uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
514 {
515// int index;
516// if (numargs < 4) index = 0;
517// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
518// else index = args[0].val.value_int32;
519
520// Character* Chr = ONgGameState->CharacterStorage;
521// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
522// if ((int)Active == 0) return 1;
523 uint32_t i = 2;
524 uint32_t j = 0;
525 uint64_t Input = 0;
526 for(i = 0; i < numargs; i++) {
527 for(j = 0; j < 32; j++) {
528 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].val.value_str32, Actions1[j].Name, Actions1[j].Bit);
529 if(!strcmp(args[i].val.value_str32, Actions[j].Name)) {
530 Input = Input | Actions[j].Bit;
531 //DDrConsole_PrintF("Success!");
532 }
533
534 }
535 }
536 //DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10));
537 ret->val.value_int32 = 0;
538 ret->type = sl_int32;
539 if (ONgGameState->Input.ActionsDown == Input) ret->val.value_int32 = 1;
540 return 0;
541}
542
543uint16_t ONICALL bsl_waitforkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
544 {
545// int index;
546// if (numargs < 4) index = 0;
547// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
548// else index = args[0].val.value_int32;
549
550// Character* Chr = ONgGameState->CharacterStorage;
551// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
552// if ((int)Active == 0) return 1;
553
554 int i = 2;
555 int j = 0;
556 uint64_t Input = 0;
557/*
558 numargs = 0;
559 for(i = 0; args[i].type <= sl_void; i++)
560 {
561 //DDrConsole_PrintF("%i", args[i].type );
562 numargs++;
563
564 }
565 if(numargs < 1 || args[0].val.value == 0) return;
566 //for(i = 0; i < numargs; i++) {
567 */
568 i = 0;
569 for(j = 0; j < 32; j++) {
570 //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].val.value_str32, Actions1[j].Name, Actions1[j].Bit);
571 if(!strcmp(args[i].val.value_str32, Actions[j].Name)) {
572 Input = Input | Actions[j].Bit;
573 //DDrConsole_PrintF("Success!");
574 }
575
576 }
577 // }
578 DDrConsole_PrintF("Waiting...");
579 if (( ONgGameState->Input.ActionsDown & Input) == Input)
580 {
581 DDrConsole_PrintF("Found key!");
582 }
583 else {
584 //else (int)*ret = 1;
585 *dontuse2 = 1;
586 *dontuse1 = 1;
587 }
588 return 0;
589}
590
591
592uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
593{
594 char output[1024];
595 char buffer[1024];
596 unsigned int i;
597 char* placeinoutput = output;
598 char* placeininput = args[0].val.value_str32;
599 int formatnum = 0;
600 //fix the broken bsl numargs...
601 numargs = 0;
602
603 for(i = 0; args[i].type < sl_void; i++)
604 {
605 numargs++;
606 }
607
608
609 if (numargs < 1)
610 return 1;
611
612 while(1)
613 {
614 int size;
615 //s is the pointer to the args
616 char* s = strchr(placeininput , '%');
617 //we didnt find a %, break!
618 if(!s)
619 {
620 strcpy(placeinoutput, placeininput);
621 break;
622 }
623 size = (int)s - (int)placeininput ;
624 //we found one, so copy the portion of string
625
626
627
628 memcpy( placeinoutput,placeininput, size);
629 placeininput += size;
630 placeinoutput += size;
631
632 memset( placeinoutput, '%', (int)pow(2, formatnum));
633 placeinoutput += (int)pow(2, formatnum);
634
635
636 placeininput += 1;
637 *placeinoutput = 0;
638 formatnum++;
639
640 }
641
642 for(i = 1; i < numargs; i++) {
643 //sprintf(output, output, args[i].value_str32);
644 memcpy(buffer, output, 1024);
645 if(args[i].val.value == 0) break;
646 switch(args[i].type)
647 {
648 case sl_bool:
649 case sl_int32:
650 sprintf(output, buffer, args[i].val.value_int32);
651 break;
652 case sl_float:
653 sprintf(output, buffer, args[i].val.value_float);
654 break;
655 case sl_str32:
656 sprintf(output, buffer, args[i].val.value_str32);
657 break;
658 case sl_void:
659 default:
660 break;
661 }
662 }
663 ret->val.value_str32 = output;
664 ret->type = sl_str32;
665 return 0;
666}
667
668// Widescreen patch for talking heads.
669uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
670{
671 args[1].val.value_int32 = (double)args[1].val.value_int32 / (double)(gl->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl->DisplayMode.Height));
672 // Call orig OCiCinematic_ScriptStart
673 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
674}
675
676void ONICALL SLrDaodan_Register_ReturnType(char* name, char* desc, char* argfmt, sl_type type, sl_func callback) {
677 char argfmt2[512];
678 uint16_t errornum;
679 if (argfmt && strlen(argfmt) < 507) {
680 sprintf(argfmt2, "%s [|]", argfmt);
681 errornum = SLrScript_Command_Register_ReturnType(name, desc, argfmt2, type, callback);
682 if(errornum)
683 {
684 STARTUPMESSAGE("Registration of script command %s failed with error %i", name, errornum);
685 }
686 } else {
687 STARTUPMESSAGE("Registration of script command %s failed because of a too long argfmt", name);
688 }
689}
690
691void* TSrTest = 0;
692uint16_t ONICALL new_text(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
693{
694 void* TSFFTahoma;
695
696 if(!TSrTest){
697 TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma);
698 TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest);
699 }
700 DDrPatch_MakeCall((void*)0x004FBCEA, (void*)DDrText_Hook);
701
702 *dontuse2 = 1;
703 return 0;
704}
705
706void SLrDaodan_Initialize()
707{
708// SLrConfig();
709
710 SLrScript_Command_Register_Void("debug_daodan","Adds text to screen", "", new_text);
711
712 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
713 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
714 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
715 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
716 srand((uint32_t)time(NULL));
717 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
718 SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:string | script_id:int] [|]", sl_int32, bsl_getkills);
719 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);
720 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);
721 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
722 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);
723 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);
724 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);
725 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);
726 //d_holdkey is broken!
727 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);
728 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);
729 SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "", sl_float, bsl_location);
730 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);
731 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "key:string", bsl_waitforkey);
732
733 //broken, only works for one damage type.
734 //SLrDaodan_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
735
736 //used for debugging.
737// SLrDaodan_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
738
739 SLrScript_Command_Register_Void("sprintf", "C-style sprintf.", "", bsl_sprintf);
740 SLrScript_Command_Register_ReturnType("st", "Prints to console in color", "", sl_void, bsl_dprintcolored);
741 SLrScript_Command_Register_ReturnType("d_dprint", "Prints to console in color", "", sl_void, bsl_dprintcolored);
742
743 SLrGlobalVariable_Register_Int32("show_triggervolumes", "Show trigger volumes", &OBJgTriggerVolume_Visible);
744}
745
746// Patch for cinematic_start to work on widescreen resolutions
747void SLrDaodan_Patch()
748{
749 // PUSH OCiCinematic_ScriptStart -> PUSH cinematic_start_patch
750 DDrPatch_Int32((int*)(OniExe + 0x000f3755), (int)cinematic_start_patch);
751}
Note: See TracBrowser for help on using the repository browser.