source: Daodan/src/Daodan_BSL.c@ 782

Last change on this file since 782 was 739, checked in by iritscen, 12 years ago

Fixed significant misspellings.

File size: 29.1 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 //strcpy( output, args[0].value_str32 );
666
667 for(i = 1; i < numargs; i++) {
668 //sprintf(output, output, args[i].value_str32);
669 memcpy(buffer, output, 1024);
670 if(args[i].val.value == 0) break;
671 switch(args[i].type)
672 {
673 case sl_bool:
674 case sl_int32:
675 sprintf(output, buffer, args[i].val.value_int32);
676 break;
677 case sl_float:
678 //crashes oni, why?
679 // sprintf(output, output, args[i].val.value_float);
680 break;
681 case sl_str32:
682 sprintf(output, buffer, args[i].val.value_str32);
683 break;
684 case sl_void:
685 default:
686 break;
687 }
688 }
689 //output[32] = 0;
690 ret->val.value_str32 = output;
691 ret->type = sl_str32;
692 return 0;
693}
694
695//Sorry rossy, I broke this. FFI isnt in windows
696/*
697uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
698{
699
700
701 int ffi_ret;
702 char* str = NULL;
703 int size = 0;
704
705 ffi_cif cif;
706 ffi_type* ffi_args[256];
707 void* values[256];
708 int i;
709 numargs = 0;
710 for(i = 0; args[i].type <= sl_void; i++)
711 {
712 //DDrConsole_PrintF("%i", args[i].type );
713 numargs++;
714
715 }
716
717 if (numargs < 1 || args[0].type != sl_str32)
718 {
719 DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": parameter list does not match: format:string arg1 arg2 ...", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name);
720 return 0;
721 }
722
723 if (!args[0].value_str32)
724 args[0].value_str32 = "";
725
726
727
728 ffi_args[0] = &ffi_type_pointer;
729 values[0] = &str;
730 ffi_args[1] = &ffi_type_uint32;
731 values[1] = &size;
732
733
734 for(i = 2; i < numargs + 2; i ++)
735 {
736 if (args[i - 2].type == sl_float)
737 {
738 float value_float = args[i - 2].value_float;
739 double* value_double = (double*)&(args[i - 2]);
740 *value_double = value_float;
741
742 ffi_args[i] = &ffi_type_double;
743 values[i] = value_double;
744 }
745 else
746 {
747 ffi_args[i] = &ffi_type_pointer;
748 values[i] = &(args[i - 2].value);
749 }
750 }
751
752 if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK)
753 return 1;
754 ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values);
755 str = malloc(ffi_ret + 1);
756 size = ffi_ret + 1;
757 ffi_call(&cif, (void*)_snprintf, (void*)&ffi_ret, values);
758 ret->value_str32 = str;
759 ret->type = sl_str32;
760 return 0;
761}
762*/
763// Widescreen patch for talking heads.
764uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
765{
766 args[1].val.value_int32 = (double)args[1].val.value_int32 / (double)(gl->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl->DisplayMode.Height));
767 return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret);
768}
769
770bool ini_inbsl = false;
771bool SLrIniCallback(char* section, bool newsection, char* name, char* value)
772{
773 if (newsection && !_stricmp(section, "bsl"))
774 ini_inbsl = true;
775
776 if (ini_inbsl)
777 {
778 char* type = value;
779 bool isptr = false;
780 sl_type bsl_type;
781
782 if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':')
783 {
784 isptr = true;
785 value += 4;
786 }
787
788
789
790 for (; *type; type++)
791 if (*type == ':')
792 {
793 *type = '\0';
794 type++;
795 break;
796 }
797
798 if (!*type)
799 DDrStartupMessage("badly formed bsl definition for \"%s\"", name);
800
801 if (!strcmp(type, "int"))
802 bsl_type = sl_int32;
803 else if (!strcmp(type, "string"))
804 bsl_type = sl_str32;
805 else if (!strcmp(type, "float"))
806 bsl_type = sl_float;
807 else if (!strcmp(type, "bool"))
808 bsl_type = sl_bool;
809 else
810 {
811 DDrStartupMessage("unknown type in bsl definition for \"%s\"", name);
812 return true;
813 }
814
815 if (isptr)
816 {
817 char* bsl_var = malloc(strlen(name) + 1);
818 memcpy(bsl_var, name, strlen(name) + 1);
819 switch (bsl_type)
820 {
821 case sl_int32:
822 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false));
823 break;
824 case sl_float:
825 SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false));
826 break;
827 default:
828 break;
829 }
830 }
831 else
832 {
833 char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t));
834 int32_t* bsl_val = (int32_t*)bsl_var;
835 bsl_var += sizeof(int32_t);
836 memcpy(bsl_var, name, strlen(name) + 1);
837
838 switch (bsl_type)
839 {
840 case sl_int32:
841 *bsl_val = inifile_parseint(value, false);
842 SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val);
843 break;
844 case sl_float:
845 break;
846 default:
847 break;
848 }
849 }
850 }
851 return true;
852}
853
854void SLrConfig()
855{
856 DDrStartupMessage("re-parsing daodan.ini for bsl...");
857 inifile_read("daodan.ini", SLrIniCallback);
858 DDrStartupMessage("finished parsing");
859}
860
861void ONICALL SLrDaodan_Register_ReturnType(char* name, char* desc, char* argfmt, sl_type type, sl_func callback) {
862 char argfmt2[512];
863 uint16_t errornum;
864 if (argfmt && strlen(argfmt) < 507) {
865 sprintf(argfmt2, "%s [|]", argfmt);
866 errornum = SLrScript_Command_Register_ReturnType(name, desc, argfmt2, type, callback);
867 if(errornum)
868 {
869 DDrStartupMessage("Registration of script command %s failed with error %i", name, errornum);
870 }
871 } else {
872 DDrStartupMessage("Registration of script command %s failed because of a too long argfmt", name);
873 }
874}
875
876void* TSrTest = 0;
877uint16_t ONICALL new_text(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
878{
879 void* TSFFTahoma;
880 int returnval;
881
882 if(!TSrTest){
883 TMrInstance_GetDataPtr( 'TSFF', "Tahoma", &TSFFTahoma);
884 returnval = TSrContext_New( TSFFTahoma, 7, 1, 1, 0, &TSrTest);
885 }
886 DDrPatch_MakeCall((void*)0x004FBCEA, (void*)DDrText_Hook);
887
888 *dontuse2 = 1;
889 return 0;
890}
891
892void SLrDaodan_Initialize()
893{
894 SLrConfig();
895
896 SLrScript_Command_Register_Void("debug_daodan","Adds text to screen", "", new_text);
897
898 SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
899 SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul);
900 SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div);
901 SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div);
902 srand((uint32_t)time(NULL));
903 SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand);
904 SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:string | script_id:int] [|]", sl_int32, bsl_getkills);
905 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);
906 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);
907 SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
908 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);
909 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);
910 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);
911 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);
912 //d_holdkey is broken!
913 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);
914 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);
915 SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "", sl_float, bsl_location);
916 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);
917 SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "key:string", bsl_waitforkey);
918
919 //broken, only works for one damage type.
920 //SLrDaodan_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
921
922 //used for debugging.
923// SLrDaodan_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
924
925 SLrScript_Command_Register_Void("sprintf", "C-style sprintf.", "", bsl_sprintf);
926 SLrScript_Command_Register_ReturnType("st", "Prints to console in color", "", sl_void, bsl_dprintcolored);
927 SLrScript_Command_Register_ReturnType("d_dprint", "Prints to console in color", "", sl_void, bsl_dprintcolored);
928}
929
930void SLrDaodan_Patch()
931{
932 DDrPatch_Int32((int*)(OniExe + 0x000f3755), (int)cinematic_start_patch);
933}
Note: See TracBrowser for help on using the repository browser.