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