source: Daodan/src/Daodan_BSL.c@ 845

Last change on this file since 845 was 839, checked in by alloc, 12 years ago

Daodan:

  • Fixes #42
  • Breaking out patches to own file
File size: 27.5 KB
Line 
1#include <stdio.h>
2#include "stdint.h"
3#include <time.h>
4#include <math.h>
5#include "Inifile_Reader.h"
6#include "Daodan_BSL.h"
7#include "Daodan_Utility.h"
8#include "Daodan_Patch.h"
9#include "Daodan_Console.h"
10#include "BFW_ScriptLang.h"
11#include "Oni.h"
12#include "Oni_Character.h"
13#include "Oni_GL.h"
14#include "Daodan_Character.h"
15
16
17uint16_t ONICALL bsl_int32mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
18{
19 ret->val.value_int32 = args[0].val.value_int32 * args[1].val.value_int32;
20 ret->type = sl_int32;
21 return 0;
22}
23
24uint16_t ONICALL bsl_mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
25{
26 double val1;
27 double val2;
28
29 if (args[0].type == sl_int32)
30 val1 = args[0].val.value_int32;
31 else
32 val1 = args[0].val.value_float;
33
34 if (args[1].type == sl_int32)
35 val2 = args[1].val.value_int32;
36 else
37 val2 = args[1].val.value_float;
38
39 ret->val.value_float = (float)(val1 * val2);
40 ret->type = sl_float;
41 return 0;
42}
43
44uint16_t ONICALL bsl_int32div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
45{
46 ret->val.value_int32 = args[0].val.value_int32 / args[1].val.value_int32;
47 ret->type = sl_int32;
48 return 0;
49}
50uint16_t ONICALL bsl_div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
51{
52 double val1;
53 double val2;
54
55 if (args[0].type == sl_int32)
56 val1 = args[0].val.value_int32;
57 else
58 val1 = args[0].val.value_float;
59
60 if (args[1].type == sl_int32)
61 val2 = args[1].val.value_int32;
62 else
63 val2 = args[1].val.value_float;
64
65 ret->val.value_float = (float)(val1 / val2);
66 ret->type = sl_float;
67 return 0;
68}
69
70uint16_t ONICALL bsl_int32rand(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
71{
72 int32_t start = 0;
73 int32_t end = 0;
74
75 if (args[0].val.value_int32 == args[1].val.value_int32)
76 return 1;
77 else if (args[0].val.value_int32 > args[1].val.value_int32)
78 {
79 start = args[1].val.value_int32;
80 end = args[0].val.value_int32;
81 }
82 else
83 {
84 start = args[0].val.value_int32;
85 end = args[1].val.value_int32;
86 }
87
88 ret->val.value_int32 = start + (rand() % (uint32_t)(end - start + 1));
89 ret->type = sl_int32;
90 return 0;
91}
92
93uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
94{
95 int index;
96 if (numargs == 0) index = 0;
97 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
98 else index = args[0].val.value_int32;
99 //killcount = ONgGameState->CharacterStorage[index].Kills;
100 //ONgGameState + index * 0x16A0 + 0x1260 + 0x1670;
101 ret->val.value_int32 = ONgGameState->CharacterStorage[index].Kills;
102 ret->type = sl_int32;
103 return 0;
104}
105
106uint16_t ONICALL bsl_getdamage(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
107{
108 int index;
109 if (numargs == 0) index = 0;
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;
113 ret->type = sl_int32;
114 return 0;
115}
116
117
118
119uint16_t ONICALL bsl_powerup(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
120{
121 int index;
122 void* returnval;
123 bool is_lsi = 0;
124 Character* Chr = ONgGameState->CharacterStorage;
125
126 if (numargs < 2 || args[1].type != sl_str32) return 1;
127 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
128 else index = args[0].val.value_int32;
129
130
131
132 if(!strcmp(args[1].val.value_str32,"ammo"))
133 {
134 returnval = &(Chr[index].Inventory.AmmoUsed);
135 }
136 else if(!strcmp(args[1].val.value_str32,"hypo"))
137 {
138 returnval = &(Chr[index].Inventory.HypoUsed);
139 }
140 else if(!strcmp(args[1].val.value_str32,"cells"))
141 {
142 returnval = &(Chr[index].Inventory.CellsUsed);
143 }
144 else if(!strcmp(args[1].val.value_str32,"invis"))
145 {
146 returnval = &(Chr[index].Inventory.CloakUsed);
147 }
148 else if(!strcmp(args[1].val.value_str32,"shield"))
149 {
150 returnval = &(Chr[index].Inventory.ShieldUsed);
151 }
152 else if(!strcmp(args[1].val.value_str32,"lsi"))
153 {
154 returnval = &(Chr[index].Inventory.hasLSI);
155 is_lsi = 1;
156 }
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// }
167 else return 1;
168 //todo, add setting
169
170 if(is_lsi) ret->val.value_int32 = (int)*(bool*)returnval;
171 else ret->val.value_int32 = *(int*)returnval;
172 ret->type = sl_int32;
173
174 if (numargs >= 3)
175 {
176 if(is_lsi) *(bool*)returnval = args[2].val.value_int32;
177 else *(int*)returnval = args[2].val.value_int32;
178 }
179
180
181 return 0;
182}
183
184uint16_t ONICALL bsl_health(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
185{
186 int index;
187 Character* Chr;
188 int* health;
189 if (numargs == 0) index = 0;
190 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
191 else index = args[0].val.value_int32;
192 Chr = ONgGameState->CharacterStorage;
193 health = &Chr[index].Health;
194
195 ret->val.value_int32 = *health;
196 ret->type = sl_int32;
197
198 if (args[1].val.value_int32) {
199 *health = args[1].val.value_int32;
200 }
201 ret->val.value_int32 = *health;
202 ret->type = sl_int32;
203 return 0;
204}
205
206uint16_t ONICALL bsl_regen(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
207{
208 int index;
209 Character* Chr;
210 if (numargs == 0) index = 0;
211 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
212 else index = args[0].val.value_int32;
213 Chr = ONgGameState->CharacterStorage ;
214
215
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 */
227 ret->val.value_int32 = Chr[index].RegenHax;
228 ret->type = sl_int32;
229
230 if (numargs >= 2) {
231 Chr[index].RegenHax = args[1].val.value_int32;
232 }
233 return 0;
234}
235
236//wow this is broken.
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;
240 Character* Chr = ONgGameState->CharacterStorage;
241 Character* Char1;
242 Character* Char2;
243
244 if (numargs < 2) return 1;
245
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;
249
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;
253 Char1 = &Chr[index];
254 Char2 = &Chr[index2];
255
256
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));
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) {
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
272 if (numargs < 2) return 1;
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;
276 Chr = ONgGameState->CharacterStorage;
277 if(numargs == 3)
278 {
279 if (!strcmp(args[1].val.value_str32,"X") || !strcmp(args[1].val.value_str32,"x"))
280 loc = &(Chr[index].Position.X);
281 else if (!strcmp(args[1].val.value_str32,"Y") || !strcmp(args[1].val.value_str32,"y"))
282 loc = &(Chr[index].Position.Y);
283 else if (!strcmp(args[1].val.value_str32,"Z") || !strcmp(args[1].val.value_str32,"z"))
284 loc = &(Chr[index].Position.Z);
285 }
286 else if (numargs == 4) {
287 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
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;
291 if(Active)
292 {
293 Active->PhyContext->Position = Chr[index].Location;
294 }
295 ret->val.value_float = 1;
296 ret->type = sl_float;
297 return 0;
298 }
299 else return 1;
300
301 ret->val.value_float = *loc;
302 ret->type = sl_float;
303
304 if(numargs == 3) {
305 //currently broken, does nothing.
306 *loc = args[2].val.value_float;
307 }
308 return 0;
309}
310
311uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
312{
313 int index;
314 if (numargs == 0) index = 0;
315 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
316 else index = args[0].val.value_int32;
317 if(1) {
318 Character* Chr = ONgGameState->CharacterStorage ;
319 int* maxhealth = &Chr[index].MaxHealth;
320 int oldmaxhealth = Chr[index].MaxHealth;
321 int oldhealth = Chr->Health;
322 if (numargs >= 2) {
323 *maxhealth = args[1].val.value_int32;
324 }
325 if (numargs >= 3 && args[2].val.value_bool) {
326 Chr->Health = (int)(((float)args[1].val.value_int32 / (float)oldmaxhealth) * (float)oldhealth);
327 }
328 ret->val.value_int32 = oldmaxhealth;
329 ret->type = sl_int32;
330 return 0;
331 }
332}
333
334uint16_t ONICALL bsl_getattacker(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
335{
336 //broken
337
338 int index;
339 if (numargs == 0) index = 0;
340 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
341 else index = args[0].val.value_int32;
342 if(1) {
343 Character* Chr = ONgGameState->CharacterStorage;
344 ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
345 if (!Active) return 1;
346// ret->val.value_int32 = Active->LastDamageSourceCharacter;
347 ret->type = sl_int32;
348 return 0;
349 }
350}
351
352
353
354uint16_t ONICALL bsl_chrname(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
355{
356 int index;
357 char* name;
358
359 if (numargs == 0) index = 0;
360 else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
361 else index = args[0].val.value_int32;
362 if (index == -1) {
363 ret->type = sl_str32;
364 ret->val.value_str32 = "NULL";
365 return 0;
366 }
367 name = (char*)(&ONgGameState->CharacterStorage[index].Name);
368 if (numargs == 2) {
369 strncpy(name, (char*)args[1].val.value_str32, 31);
370 }
371
372 ret->type = sl_str32;
373 ret->val.value_str32 = name;
374
375 return 0;
376}
377
378
379uint16_t ONICALL bsl_count(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
380{
381 //testing numargs...
382 ret->type = sl_int32;
383 ret->val.value_int32 = numargs;
384 return 0;
385}
386
387uint16_t ONICALL bsl_dprintcolored(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
388{
389 //TODO: figure out why our implementation of dprint shows after dev mode is turned off
390 RGBA color;
391 RGBA shade;
392 int i;
393 numargs = 0;
394 for(i = 0; args[i].type < sl_void; i++)
395 {
396 numargs++;
397 }
398 if(numargs == 0) return 0;
399 if(numargs > 1 ) color.R = (char)args[1].val.value_int32;
400 else color.R = 255;
401 if(numargs > 2 ) color.G = (char)args[2].val.value_int32;
402 else color.G = 255;
403 if(numargs > 3 ) color.B = (char)args[3].val.value_int32;
404 else color.B = 255;
405 color.A = 0;
406 if(numargs > 5 ) shade.R = (char)args[5].val.value_int32;
407 else shade.R = 0x3F;
408 if(numargs > 6 ) shade.G = (char)args[6].val.value_int32;
409 else shade.G = 0x3F;
410 if(numargs > 7 ) shade.B = (char)args[7].val.value_int32;
411 else shade.B = 0x3F;
412 shade.A = 0;
413
414 DDrConsole_PrintColored(args[0].val.value_str32, 1, color, shade);
415 return 0;
416}
417
418
419uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
420{
421
422 ret->type = sl_int32;
423 ret->val.value_int32 = DDrGetCharacterIndexFromName(args[0].val.value_str32);
424
425 return 0;
426}
427
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 },
444 {"StartRecord", Action_StartRecord },
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};
479uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
480{
481 uint32_t index;
482 uint32_t i = 2;
483 uint32_t j = 0;
484 int Input1 = 0;
485 int Input2 = 0;
486 Character* Chr;
487 ActiveCharacter* Active;
488 if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
489 else index = args[0].val.value_int32;
490
491 Chr = &(ONgGameState->CharacterStorage[index]);
492 Active = ONrGetActiveCharacter(Chr);
493 if (!Active) return 1;
494
495 for(i = 1; i < numargs - 1; i++) {
496 for(j = 0; j < 32; j++) {
497 if(!strcmp(args[i].val.value_str32, Actions1[j].Name)) {
498 Input1 = Input1 | Actions1[j].Bit;
499 }
500 }
501 for(j = 0; j < 9; j++) {
502 if(!strcmp(args[i].val.value_str32, Actions2[j].Name)) {
503 Input2 = Input2 | Actions2[j].Bit;
504 }
505 }
506 }
507 Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1;
508 Active->Input.Current.Actions2 = Active->Input.Current.Actions2 | Input2;
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 }
513 if ( args[numargs - 1].val.value_int32 <= 0) {
514 return 0;
515 }
516 else {
517 args[numargs - 1].val.value_int32 -= 1;
518 *dontuse2 = 1;
519 *dontuse1 = 1;
520 }
521 return 0;
522}
523
524uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
525 {
526// int index;
527// if (numargs < 4) index = 0;
528// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
529// else index = args[0].val.value_int32;
530
531// Character* Chr = ONgGameState->CharacterStorage;
532// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
533// if ((int)Active == 0) return 1;
534 uint32_t i = 2;
535 uint32_t j = 0;
536 int Input1 = 0;
537 int Input2 = 0;
538 for(i = 0; i < numargs; i++) {
539 for(j = 0; j < 32; j++) {
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)) {
542 Input1 = Input1 | Actions1[j].Bit;
543 //DDrConsole_PrintF("Success!");
544 }
545
546 }
547 for(j = 0; j < 9; j++) {
548 if(!strcmp(args[i].val.value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
549
550 }
551 }
552 //DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10));
553 ret->val.value_int32 = 0;
554 ret->type = sl_int32;
555 if ( (ONgGameState->Input.Current.Actions1 == Input1) && (ONgGameState->Input.Current.Actions2 == Input2)) ret->val.value_int32 = 1;
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;
563// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32);
564// else index = args[0].val.value_int32;
565
566// Character* Chr = ONgGameState->CharacterStorage;
567// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
568// if ((int)Active == 0) return 1;
569
570 int i = 2;
571 int j = 0;
572 int Input1 = 0;
573 int Input2 = 0;
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 }
582 if(numargs < 1 || args[0].val.value == 0) return;
583 //for(i = 0; i < numargs; i++) {
584 */
585 i = 0;
586 for(j = 0; j < 32; j++) {
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)) {
589 Input1 = Input1 | Actions1[j].Bit;
590 //DDrConsole_PrintF("Success!");
591 }
592
593 }
594 for(j = 0; j < 9; j++) {
595 if(!strcmp(args[i].val.value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
596
597 }
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!");
606 }
607 else {
608 //else (int)*ret = 1;
609 *dontuse2 = 1;
610 *dontuse1 = 1;
611 }
612 return 0;
613}
614
615
616uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
617{
618 char output[1024];
619 char buffer[1024];
620 unsigned int i;
621 char* placeinoutput = output;
622 char* placeininput = args[0].val.value_str32;
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)
634 return 1;
635
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
666 for(i = 1; i < numargs; i++) {
667 //sprintf(output, output, args[i].value_str32);
668 memcpy(buffer, output, 1024);
669 if(args[i].val.value == 0) break;
670 switch(args[i].type)
671 {
672 case sl_bool:
673 case sl_int32:
674 sprintf(output, buffer, args[i].val.value_int32);
675 break;
676 case sl_float:
677 sprintf(output, buffer, args[i].val.value_float);
678 break;
679 case sl_str32:
680 sprintf(output, buffer, args[i].val.value_str32);
681 break;
682 case sl_void:
683 default:
684 break;
685 }
686 }
687 ret->val.value_str32 = output;
688 ret->type = sl_str32;
689 return 0;
690}
691
692// Widescreen patch for talking heads.
693uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
694{
695 args[1].val.value_int32 = (double)args[1].val.value_int32 / (double)(gl->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl->DisplayMode.Height));
696 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
697}
698
699/*
700bool ini_inbsl = false;
701bool SLrIniCallback(char* section, bool newsection, char* name, char* value)
702{
703 if (newsection)
704 ini_inbsl = !_stricmp(section, "bsl");
705
706 if (ini_inbsl)
707 {
708 char* type = value;
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
719
720 for (; *type; type++)
721 if (*type == ':')
722 {
723 *type = '\0';
724 type++;
725 break;
726 }
727
728 if (!*type)
729 DDrStartupMessage("Daodan: Badly formed bsl definition for \"%s\"", name);
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 {
741 DDrStartupMessage("Daodan: Unknown type in bsl definition for \"%s\"", name);
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{
786 DDrStartupMessage("Daodan: Re-parsing daodan.ini for bsl...");
787 inifile_read("daodan.ini", SLrIniCallback);
788 DDrStartupMessage("Daodan: Finished parsing");
789}
790*/
791
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;
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 {
800 DDrStartupMessage("Daodan: Registration of script command %s failed with error %i", name, errornum);
801 }
802 } else {
803 DDrStartupMessage("Daodan: Registration of script command %s failed because of a too long argfmt", name);
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)
809{
810 void* TSFFTahoma;
811 int returnval;
812
813 if(!TSrTest){
814 TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma);
815 returnval = TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest);
816 }
817 DDrPatch_MakeCall((void*)0x004FBCEA, (void*)DDrText_Hook);
818
819 *dontuse2 = 1;
820 return 0;
821}
822
823void SLrDaodan_Initialize()
824{
825// SLrConfig();
826
827 SLrScript_Command_Register_Void("debug_daodan","Adds text to screen", "", new_text);
828
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);
833 srand((uint32_t)time(NULL));
834 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
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);
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);
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);
838 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
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);
849
850 //broken, only works for one damage type.
851 //SLrDaodan_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
852
853 //used for debugging.
854// SLrDaodan_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
855
856 SLrScript_Command_Register_Void("sprintf", "C-style sprintf.", "", bsl_sprintf);
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);
859}
860
861// Patch for cinematic_start to work on widescreen resolutions
862void SLrDaodan_Patch()
863{
864 DDrPatch_Int32((int*)(OniExe + 0x000f3755), (int)cinematic_start_patch);
865}
Note: See TracBrowser for help on using the repository browser.