| 1 |
#include <stdio.h> |
| 2 |
#include <stdbool.h> |
| 3 |
#include <time.h> |
| 4 |
#include <ffi.h> |
| 5 |
|
| 6 |
#include "inifile.h" |
| 7 |
|
| 8 |
#include "Daodan_BSL.h" |
| 9 |
#include "Daodan_Utility.h" |
| 10 |
#include "Daodan_Patch.h" |
| 11 |
#include "Daodan_Console.h" |
| 12 |
#include "BFW_ScriptLang.h" |
| 13 |
#include "Oni.h" |
| 14 |
#include "Oni_Character.h" |
| 15 |
#include "oni_gl.h" |
| 16 |
#include "dSFMT\dSFMT.h" |
| 17 |
#include "Daodan_Character.h" |
| 18 |
|
| 19 |
uint16_t ONICALL bsl_int32mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 20 |
{ |
| 21 |
ret->value_int32 = args[0].value_int32 * args[1].value_int32; |
| 22 |
ret->type = sl_int32; |
| 23 |
return 0; |
| 24 |
} |
| 25 |
|
| 26 |
uint16_t ONICALL bsl_mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 27 |
{ |
| 28 |
double val1; |
| 29 |
double val2; |
| 30 |
|
| 31 |
if (args[0].type == sl_int32) |
| 32 |
val1 = args[0].value_int32; |
| 33 |
else |
| 34 |
val1 = args[0].value_float; |
| 35 |
|
| 36 |
if (args[1].type == sl_int32) |
| 37 |
val2 = args[1].value_int32; |
| 38 |
else |
| 39 |
val2 = args[1].value_float; |
| 40 |
|
| 41 |
ret->value_float = (float)(val1 * val2); |
| 42 |
ret->type = sl_float; |
| 43 |
return 0; |
| 44 |
} |
| 45 |
|
| 46 |
uint16_t ONICALL bsl_int32div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 47 |
{ |
| 48 |
ret->value_int32 = args[0].value_int32 / args[1].value_int32; |
| 49 |
ret->type = sl_int32; |
| 50 |
return 0; |
| 51 |
} |
| 52 |
|
| 53 |
uint16_t ONICALL bsl_div(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 54 |
{ |
| 55 |
double val1; |
| 56 |
double val2; |
| 57 |
|
| 58 |
if (args[0].type == sl_int32) |
| 59 |
val1 = args[0].value_int32; |
| 60 |
else |
| 61 |
val1 = args[0].value_float; |
| 62 |
|
| 63 |
if (args[1].type == sl_int32) |
| 64 |
val2 = args[1].value_int32; |
| 65 |
else |
| 66 |
val2 = args[1].value_float; |
| 67 |
|
| 68 |
ret->value_float = (float)(val1 / val2); |
| 69 |
ret->type = sl_float; |
| 70 |
return 0; |
| 71 |
} |
| 72 |
|
| 73 |
uint16_t ONICALL bsl_int32rand(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 74 |
{ |
| 75 |
int32_t start = 0; |
| 76 |
int32_t end = 0; |
| 77 |
|
| 78 |
if (args[0].value_int32 == args[1].value_int32) |
| 79 |
return 1; |
| 80 |
else if (args[0].value_int32 > args[1].value_int32) |
| 81 |
{ |
| 82 |
start = args[1].value_int32; |
| 83 |
end = args[0].value_int32; |
| 84 |
} |
| 85 |
else |
| 86 |
{ |
| 87 |
start = args[0].value_int32; |
| 88 |
end = args[1].value_int32; |
| 89 |
} |
| 90 |
|
| 91 |
ret->value_int32 = start + (dsfmt_gv_genrand_uint32() % (uint32_t)(end - start + 1)); |
| 92 |
ret->type = sl_int32; |
| 93 |
return 0; |
| 94 |
} |
| 95 |
|
| 96 |
uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 97 |
{ |
| 98 |
int index; |
| 99 |
if (numargs == 0) index = 0; |
| 100 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 101 |
else index = args[0].value_int32; |
| 102 |
int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1670; |
| 103 |
ret->value_int32 = *killcount; |
| 104 |
ret->type = sl_int32; |
| 105 |
return 0; |
| 106 |
} |
| 107 |
|
| 108 |
uint16_t ONICALL bsl_getdamage(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 109 |
{ |
| 110 |
int index; |
| 111 |
if (numargs == 0) index = 0; |
| 112 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 113 |
else index = args[0].value_int32; |
| 114 |
int* killcount = ONgGameState + index * 0x16A0 + 0x1260 + 0x1674; |
| 115 |
ret->value_int32 = *killcount; |
| 116 |
ret->type = sl_int32; |
| 117 |
return 0; |
| 118 |
} |
| 119 |
|
| 120 |
uint16_t ONICALL bsl_returnoffset(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 121 |
{ |
| 122 |
//int offset = 140; |
| 123 |
//if (== 1) offset = 148; |
| 124 |
//else index = args[0].value_int32; |
| 125 |
int* killcount = ONgGameState + args[0].value_int32; |
| 126 |
ret->value_int32 = *killcount; |
| 127 |
ret->type = sl_int32; |
| 128 |
return 0; |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
uint16_t ONICALL bsl_powerup(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 133 |
{ |
| 134 |
int index; |
| 135 |
if (numargs < 2 || args[1].type != sl_str32) return 1; |
| 136 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 137 |
else index = args[0].value_int32; |
| 138 |
void* returnval; |
| 139 |
bool is_lsi = 0; |
| 140 |
Character* Chr = ONgGameState + 0x1260; |
| 141 |
if(!strcmp(args[1].value_str32,"ammo")) |
| 142 |
{ |
| 143 |
returnval = &(Chr[index].Inventory_.AmmoUsed); |
| 144 |
} |
| 145 |
else if(!strcmp(args[1].value_str32,"hypo")) |
| 146 |
{ |
| 147 |
returnval = &(Chr[index].Inventory_.HypoUsed); |
| 148 |
} |
| 149 |
else if(!strcmp(args[1].value_str32,"cells")) |
| 150 |
{ |
| 151 |
returnval = &(Chr[index].Inventory_.CellsUsed); |
| 152 |
} |
| 153 |
else if(!strcmp(args[1].value_str32,"invis")) |
| 154 |
{ |
| 155 |
returnval = &(Chr[index].Inventory_.CloakUsed); |
| 156 |
} |
| 157 |
else if(!strcmp(args[1].value_str32,"shield")) |
| 158 |
{ |
| 159 |
returnval = &(Chr[index].Inventory_.ShieldUsed); |
| 160 |
} |
| 161 |
else if(!strcmp(args[1].value_str32,"lsi")) |
| 162 |
{ |
| 163 |
returnval = &(Chr[index].Inventory_.hasLSI); |
| 164 |
is_lsi = 1; |
| 165 |
} |
| 166 |
// else if(!strcmp(args[1].value_str32,"bossshield")) |
| 167 |
// { |
| 168 |
// ret->value_int32 = Chr[index].Flags & char_bossshield; |
| 169 |
// ret->type = sl_int32; |
| 170 |
// if (numargs >=3) { |
| 171 |
// if (Chr[index].Flags & char_bossshield) Chr[index].Flags = Chr[index].Flags & ~char_bossshield; |
| 172 |
// else Chr[index].Flags = Chr[index].Flags | char_bossshield; |
| 173 |
// } |
| 174 |
// return 0; |
| 175 |
// } |
| 176 |
else return 1; |
| 177 |
//todo, add setting |
| 178 |
|
| 179 |
if(is_lsi) ret->value_int32 = (int)*(bool*)returnval; |
| 180 |
else ret->value_int32 = *(int*)returnval; |
| 181 |
ret->type = sl_int32; |
| 182 |
|
| 183 |
if (numargs >= 3) |
| 184 |
{ |
| 185 |
if(is_lsi) *(bool*)returnval = args[2].value_int32; |
| 186 |
else *(int*)returnval = args[2].value_int32; |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
return 0; |
| 191 |
} |
| 192 |
|
| 193 |
uint16_t ONICALL bsl_health(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 194 |
{ |
| 195 |
int index; |
| 196 |
if (numargs == 0) index = 0; |
| 197 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 198 |
else index = args[0].value_int32; |
| 199 |
Character* Chr = ONgGameState + 0x1260 ; |
| 200 |
int* health = &Chr[index].Health; |
| 201 |
|
| 202 |
ret->value_int32 = *health; |
| 203 |
ret->type = sl_int32; |
| 204 |
|
| 205 |
if (numargs >= 2) { |
| 206 |
*health = args[1].value_int32; |
| 207 |
} |
| 208 |
ret->value_int32 = *health; |
| 209 |
ret->type = sl_int32; |
| 210 |
return 0; |
| 211 |
} |
| 212 |
|
| 213 |
uint16_t ONICALL bsl_regen(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 214 |
{ |
| 215 |
int index; |
| 216 |
if (numargs == 0) index = 0; |
| 217 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 218 |
else index = args[0].value_int32; |
| 219 |
Character* Chr = ONgGameState + 0x1260 ; |
| 220 |
int* health = (int*)&Chr[index] + 0x144; |
| 221 |
|
| 222 |
ret->value_int32 = *health; |
| 223 |
ret->type = sl_int32; |
| 224 |
|
| 225 |
if (numargs >= 2) { |
| 226 |
*health = args[1].value_int32; |
| 227 |
} |
| 228 |
ret->value_int32 = *health; |
| 229 |
ret->type = sl_int32; |
| 230 |
return 0; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 235 |
{ |
| 236 |
int index; |
| 237 |
if (numargs == 0) index = 0; |
| 238 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 239 |
else index = args[0].value_int32; |
| 240 |
Character* Chr = ONgGameState + 0x1260 ; |
| 241 |
int* maxhealth = &Chr[index].MaxHealth; |
| 242 |
int oldmaxhealth = Chr[index].MaxHealth; |
| 243 |
int oldhealth = Chr->Health; |
| 244 |
if (numargs >= 2) { |
| 245 |
*maxhealth = args[1].value_int32; |
| 246 |
} |
| 247 |
if (numargs >= 3 && args[2].value_bool) { |
| 248 |
Chr->Health = (int)(((float)args[1].value_int32 / (float)oldmaxhealth) * (float)oldhealth); |
| 249 |
} |
| 250 |
ret->value_int32 = oldmaxhealth; |
| 251 |
ret->type = sl_int32; |
| 252 |
return 0; |
| 253 |
} |
| 254 |
|
| 255 |
uint16_t ONICALL bsl_getattacker(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 256 |
{ |
| 257 |
//broken |
| 258 |
|
| 259 |
int index; |
| 260 |
if (numargs == 0) index = 0; |
| 261 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 262 |
else index = args[0].value_int32; |
| 263 |
|
| 264 |
Character* Chr = ONgGameState + 0x1260; |
| 265 |
ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
| 266 |
if ((int)Active == 0) return 1; |
| 267 |
// ret->value_int32 = Active->LastDamageSourceCharacter; |
| 268 |
ret->type = sl_int32; |
| 269 |
return 0; |
| 270 |
} |
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
uint16_t ONICALL bsl_chrname(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 275 |
{ |
| 276 |
int index; |
| 277 |
if (numargs == 0) index = 0; |
| 278 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 279 |
else index = args[0].value_int32; |
| 280 |
if (index == -1) { |
| 281 |
ret->type = sl_str32; |
| 282 |
ret->value_str32 = "NULL"; |
| 283 |
return 0; |
| 284 |
} |
| 285 |
char* name = ONgGameState + 0x1260 + index * 0x16A0 + 0x14; |
| 286 |
if (numargs == 2) { |
| 287 |
strncpy(name, (char*)args[1].value_str32, 31); |
| 288 |
} |
| 289 |
|
| 290 |
ret->type = sl_str32; |
| 291 |
ret->value_str32 = name; |
| 292 |
|
| 293 |
return 0; |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
uint16_t ONICALL bsl_count(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 298 |
{ |
| 299 |
//testing numargs... |
| 300 |
ret->type = sl_int32; |
| 301 |
ret->value_int32 = numargs; |
| 302 |
return 0; |
| 303 |
} |
| 304 |
|
| 305 |
uint16_t ONICALL bsl_dprintcolored(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 306 |
{ |
| 307 |
//TODO: figure out why our implementation of dprint shows after dev mode is turned off |
| 308 |
RGBA color; |
| 309 |
RGBA shade; |
| 310 |
|
| 311 |
if(numargs == 0) return 0; |
| 312 |
if(numargs > 1 ) color.R = (char)args[1].value_int32; |
| 313 |
else color.R = 255; |
| 314 |
if(numargs > 2 ) color.G = (char)args[2].value_int32; |
| 315 |
else color.G = 255; |
| 316 |
if(numargs > 3 ) color.B = (char)args[3].value_int32; |
| 317 |
else color.B = 255; |
| 318 |
color.A = 0; |
| 319 |
if(numargs > 5 ) shade.R = (char)args[5].value_int32; |
| 320 |
else shade.R = 0x3F; |
| 321 |
if(numargs > 6 ) shade.G = (char)args[6].value_int32; |
| 322 |
else shade.G = 0x3F; |
| 323 |
if(numargs > 7 ) shade.B = (char)args[7].value_int32; |
| 324 |
else shade.B = 0x3F; |
| 325 |
shade.A = 0; |
| 326 |
|
| 327 |
DDrConsole_PrintColored(args[0].value_str32, 1, color, shade); |
| 328 |
return 0; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 333 |
{ |
| 334 |
ret->type = sl_int32; |
| 335 |
ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 336 |
return 0; |
| 337 |
} |
| 338 |
|
| 339 |
uint16_t ONICALL bsl_getactiveoffset(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 340 |
{ |
| 341 |
DDrConsole_PrintF("Character: 0x%x",(int)ONgGameState + 0x1260); |
| 342 |
DDrConsole_PrintF("ActiveChar: 0x%x",(int)ONrGetActiveCharacter((void*)((int)ONgGameState + 0x1260))); |
| 343 |
return 0; |
| 344 |
} |
| 345 |
typedef struct { |
| 346 |
char Name[16]; |
| 347 |
int Bit; |
| 348 |
} KeyBit; |
| 349 |
|
| 350 |
KeyBit Actions1[32] = { |
| 351 |
{"Escape", Action_Escape}, |
| 352 |
{"Console", Action_Console}, |
| 353 |
{"PauseScreen", Action_PauseScreen}, |
| 354 |
{"Cutscene1", Action_Cutscene_1 }, |
| 355 |
{"Cutscene2", Action_Cutscene_2 }, |
| 356 |
{"F4", Action_F4 }, |
| 357 |
{"F5", Action_F5 }, |
| 358 |
{"F6", Action_F6 }, |
| 359 |
{"F7", Action_F7 }, |
| 360 |
{"F8", Action_F8 }, |
| 361 |
{"StartRecorn", Action_StartRecord }, |
| 362 |
{"StopRecord", Action_StopRecord }, |
| 363 |
{"PlayRecord", Action_PlayRecord }, |
| 364 |
{"F12", Action_F12 }, |
| 365 |
{"Unknown1", Action_Unknown1 }, |
| 366 |
{"LookMode", Action_LookMode }, |
| 367 |
{"Screenshot", Action_Screenshot }, |
| 368 |
{"Unknown2", Action_Unknown2 }, |
| 369 |
{"Unknown3", Action_Unknown3 }, |
| 370 |
{"Unknown4", Action_Unknown4 }, |
| 371 |
{"Unknown5", Action_Unknown5 }, |
| 372 |
{"Forward", Action_Forward }, |
| 373 |
{"Backward", Action_Backward }, |
| 374 |
{"TurnLeft", Action_TurnLeft }, |
| 375 |
{"TurnRight", Action_TurnRight }, |
| 376 |
{"StepLeft", Action_StepLeft }, |
| 377 |
{"StepRight", Action_StepRight }, |
| 378 |
{"Jump", Action_Jump }, |
| 379 |
{"Crouch", Action_Crouch }, |
| 380 |
{"Punch",Action_Punch }, |
| 381 |
{"Kick", Action_Kick }, |
| 382 |
{"Block", Action_Block } |
| 383 |
}; |
| 384 |
|
| 385 |
KeyBit Actions2[9] = { |
| 386 |
{"Walk", Action2_Walk}, |
| 387 |
{"Action", Action2_Action}, |
| 388 |
{"Hypo", Action2_Hypo}, |
| 389 |
{"Reload", Action2_Reload }, |
| 390 |
{"Swap", Action2_Swap }, |
| 391 |
{"Drop", Action2_Drop }, |
| 392 |
{"Fire1", Action2_Fire1 }, |
| 393 |
{"Fire2", Action2_Fire2 }, |
| 394 |
{"Fire3", Action2_Fire3 } |
| 395 |
}; |
| 396 |
uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 397 |
{ |
| 398 |
int index; |
| 399 |
if (numargs < 4) index = 0; |
| 400 |
else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 401 |
else index = args[0].value_int32; |
| 402 |
|
| 403 |
Character* Chr = ONgGameState + 0x1260; |
| 404 |
ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
| 405 |
if ((int)Active == 0) return 1; |
| 406 |
int i = 2; |
| 407 |
int j = 0; |
| 408 |
int Input1 = 0; |
| 409 |
int Input2 = 0; |
| 410 |
for(i = 1; i < numargs; i++) { |
| 411 |
for(j = 0; j < 32; j++) { |
| 412 |
if(strcmp(args[i].value_str32, Actions1[j].Name)) Input1 = Input1 | Actions1[j].Bit; |
| 413 |
DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit); |
| 414 |
} |
| 415 |
for(j = 0; j < 9; j++) { |
| 416 |
if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; |
| 417 |
|
| 418 |
} |
| 419 |
} |
| 420 |
for(i = 0; i < numargs; i++) { |
| 421 |
DDrConsole_PrintF("%s", args[i].value_str32); |
| 422 |
} |
| 423 |
// if |
| 424 |
return 0; |
| 425 |
} |
| 426 |
|
| 427 |
uint16_t ONICALL bsl_isheld(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 428 |
{ |
| 429 |
// int index; |
| 430 |
// if (numargs < 4) index = 0; |
| 431 |
// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 432 |
// else index = args[0].value_int32; |
| 433 |
|
| 434 |
// Character* Chr = ONgGameState + 0x1260; |
| 435 |
// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
| 436 |
// if ((int)Active == 0) return 1; |
| 437 |
int i = 2; |
| 438 |
int j = 0; |
| 439 |
int Input1 = 0; |
| 440 |
int Input2 = 0; |
| 441 |
for(i = 0; i < numargs; i++) { |
| 442 |
for(j = 0; j < 32; j++) { |
| 443 |
//DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit); |
| 444 |
if(!strcmp(args[i].value_str32, Actions1[j].Name)) { |
| 445 |
Input1 = Input1 | Actions1[j].Bit; |
| 446 |
//DDrConsole_PrintF("Success!"); |
| 447 |
} |
| 448 |
|
| 449 |
} |
| 450 |
for(j = 0; j < 9; j++) { |
| 451 |
if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; |
| 452 |
|
| 453 |
} |
| 454 |
} |
| 455 |
//DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10)); |
| 456 |
ret->value_int32 = 0; |
| 457 |
ret->type = sl_int32; |
| 458 |
if ( ((*(int*)(ONgGameState + 0xB8 + 0x10) & Input1) == Input1) && ((*(int*)(ONgGameState + 0xB8 + 0x14) & Input2) == Input2)) ret->value_int32 = 1; |
| 459 |
return 0; |
| 460 |
} |
| 461 |
|
| 462 |
uint16_t ONICALL bsl_waitforkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 463 |
{ |
| 464 |
// int index; |
| 465 |
// if (numargs < 4) index = 0; |
| 466 |
// else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32); |
| 467 |
// else index = args[0].value_int32; |
| 468 |
|
| 469 |
// Character* Chr = ONgGameState + 0x1260; |
| 470 |
// ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]); |
| 471 |
// if ((int)Active == 0) return 1; |
| 472 |
int i = 2; |
| 473 |
int j = 0; |
| 474 |
int Input1 = 0; |
| 475 |
int Input2 = 0; |
| 476 |
for(i = 0; i < numargs; i++) { |
| 477 |
for(j = 0; j < 32; j++) { |
| 478 |
//DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit); |
| 479 |
if(!strcmp(args[i].value_str32, Actions1[j].Name)) { |
| 480 |
Input1 = Input1 | Actions1[j].Bit; |
| 481 |
//DDrConsole_PrintF("Success!"); |
| 482 |
} |
| 483 |
|
| 484 |
} |
| 485 |
for(j = 0; j < 9; j++) { |
| 486 |
if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; |
| 487 |
|
| 488 |
} |
| 489 |
} |
| 490 |
//DDrConsole_PrintF("Waiting..."); |
| 491 |
if ( ((*(int*)(ONgGameState + 0xB8 + 0x10) & Input1) == Input1) && ((*(int*)(ONgGameState + 0xB8 + 0x14) & Input2) == Input2)) { |
| 492 |
} |
| 493 |
else { |
| 494 |
//else (int)*ret = 1; |
| 495 |
*dontuse2 = 1; |
| 496 |
*dontuse1 = 1; |
| 497 |
} |
| 498 |
/* |
| 499 |
__asm__( |
| 500 |
"movl 0x10(%esp), %edx\n\t" |
| 501 |
"movl $1,(%eax)\n\t" |
| 502 |
); |
| 503 |
//ret->type = sl_void |
| 504 |
*/ return 0; |
| 505 |
} |
| 506 |
|
| 507 |
/* |
| 508 |
uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 509 |
{ |
| 510 |
if (numargs < 2) |
| 511 |
return 1; |
| 512 |
|
| 513 |
char output[255]; |
| 514 |
int i; |
| 515 |
for(i = 1; i < numargs; i++) { |
| 516 |
sprintf(output, args[0].value_str32, args[i].value_str32); |
| 517 |
} |
| 518 |
|
| 519 |
ret->value_str32 = output; |
| 520 |
ret->type = sl_str32; |
| 521 |
return 0; |
| 522 |
} |
| 523 |
*/ |
| 524 |
uint16_t ONICALL bsl_sprintf(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 525 |
{ |
| 526 |
if (numargs < 1 || args[0].type != sl_str32) |
| 527 |
{ |
| 528 |
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); |
| 529 |
return 0; |
| 530 |
} |
| 531 |
|
| 532 |
if (!args[0].value_str32) |
| 533 |
args[0].value_str32 = ""; |
| 534 |
|
| 535 |
int ffi_ret; |
| 536 |
char* str = NULL; |
| 537 |
int size = 0; |
| 538 |
|
| 539 |
ffi_cif cif; |
| 540 |
ffi_type* ffi_args[256]; |
| 541 |
void* values[256]; |
| 542 |
|
| 543 |
ffi_args[0] = &ffi_type_pointer; |
| 544 |
values[0] = &str; |
| 545 |
ffi_args[1] = &ffi_type_uint32; |
| 546 |
values[1] = &size; |
| 547 |
|
| 548 |
int i; |
| 549 |
for(i = 2; i < numargs + 2; i ++) |
| 550 |
{ |
| 551 |
if (args[i - 2].type == sl_float) |
| 552 |
{ |
| 553 |
float value_float = args[i - 2].value_float; |
| 554 |
double* value_double = (double*)&(args[i - 2]); |
| 555 |
*value_double = value_float; |
| 556 |
|
| 557 |
ffi_args[i] = &ffi_type_double; |
| 558 |
values[i] = value_double; |
| 559 |
} |
| 560 |
else |
| 561 |
{ |
| 562 |
ffi_args[i] = &ffi_type_pointer; |
| 563 |
values[i] = &(args[i - 2].value); |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
if (ffi_prep_cif(&cif, FFI_DEFAULT_ABI, i, &ffi_type_sint32, ffi_args) != FFI_OK) |
| 568 |
return 1; |
| 569 |
ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values); |
| 570 |
str = malloc(ffi_ret + 1); |
| 571 |
size = ffi_ret + 1; |
| 572 |
ffi_call(&cif, (void*)snprintf, (void*)&ffi_ret, values); |
| 573 |
ret->value_str32 = str; |
| 574 |
ret->type = sl_str32; |
| 575 |
return 0; |
| 576 |
} |
| 577 |
|
| 578 |
// Widescreen patch for talking heads. |
| 579 |
uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) |
| 580 |
{ |
| 581 |
args[1].value_int32 = (double)args[1].value_int32 / (double)(gl->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl->DisplayMode.Height)); |
| 582 |
return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret); |
| 583 |
} |
| 584 |
|
| 585 |
bool ini_inbsl = false; |
| 586 |
bool SLrIniCallback(char* section, bool newsection, char* name, char* value) |
| 587 |
{ |
| 588 |
if (newsection && !stricmp(section, "bsl")) |
| 589 |
ini_inbsl = true; |
| 590 |
|
| 591 |
if (ini_inbsl) |
| 592 |
{ |
| 593 |
bool isptr = false; |
| 594 |
sl_type bsl_type; |
| 595 |
|
| 596 |
if (value[0] == 'p' && value[1] == 't' && value[2] == 'r' && value[3] == ':') |
| 597 |
{ |
| 598 |
isptr = true; |
| 599 |
value += 4; |
| 600 |
} |
| 601 |
|
| 602 |
char* type = value; |
| 603 |
|
| 604 |
for (; *type; type++) |
| 605 |
if (*type == ':') |
| 606 |
{ |
| 607 |
*type = '\0'; |
| 608 |
type++; |
| 609 |
break; |
| 610 |
} |
| 611 |
|
| 612 |
if (!*type) |
| 613 |
DDrStartupMessage("badly formed bsl definition for \"%s\"", name); |
| 614 |
|
| 615 |
if (!strcmp(type, "int")) |
| 616 |
bsl_type = sl_int32; |
| 617 |
else if (!strcmp(type, "string")) |
| 618 |
bsl_type = sl_str32; |
| 619 |
else if (!strcmp(type, "float")) |
| 620 |
bsl_type = sl_float; |
| 621 |
else if (!strcmp(type, "bool")) |
| 622 |
bsl_type = sl_bool; |
| 623 |
else |
| 624 |
{ |
| 625 |
DDrStartupMessage("unknown type in bsl definition for \"%s\"", name); |
| 626 |
return true; |
| 627 |
} |
| 628 |
|
| 629 |
if (isptr) |
| 630 |
{ |
| 631 |
char* bsl_var = malloc(strlen(name) + 1); |
| 632 |
memcpy(bsl_var, name, strlen(name) + 1); |
| 633 |
switch (bsl_type) |
| 634 |
{ |
| 635 |
case sl_int32: |
| 636 |
SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", (int32_t*)(uint32_t)inifile_parseint(value, false)); |
| 637 |
break; |
| 638 |
case sl_float: |
| 639 |
SLrGlobalVariable_Register_Float(bsl_var, "see daodan.ini", (float*)(uint32_t)inifile_parseint(value, false)); |
| 640 |
break; |
| 641 |
default: |
| 642 |
break; |
| 643 |
} |
| 644 |
} |
| 645 |
else |
| 646 |
{ |
| 647 |
char* bsl_var = malloc(strlen(name) + 1 + sizeof(int32_t)); |
| 648 |
int32_t* bsl_val = (int32_t*)bsl_var; |
| 649 |
bsl_var += sizeof(int32_t); |
| 650 |
memcpy(bsl_var, name, strlen(name) + 1); |
| 651 |
|
| 652 |
switch (bsl_type) |
| 653 |
{ |
| 654 |
case sl_int32: |
| 655 |
*bsl_val = inifile_parseint(value, false); |
| 656 |
SLrGlobalVariable_Register_Int32(bsl_var, "see daodan.ini", bsl_val); |
| 657 |
break; |
| 658 |
case sl_float: |
| 659 |
break; |
| 660 |
default: |
| 661 |
break; |
| 662 |
} |
| 663 |
} |
| 664 |
} |
| 665 |
return true; |
| 666 |
} |
| 667 |
|
| 668 |
void SLrConfig() |
| 669 |
{ |
| 670 |
DDrStartupMessage("re-parsing daodan.ini for bsl..."); |
| 671 |
inifile_read("daodan.ini", SLrIniCallback); |
| 672 |
DDrStartupMessage("finished parsing"); |
| 673 |
} |
| 674 |
|
| 675 |
void SLrDaodan_Initalize() |
| 676 |
{ |
| 677 |
|
| 678 |
//const char regen_patch[] = {0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90}; |
| 679 |
//DDrPatch_Const(OniExe + 0x0011BB6D, regen_patch); |
| 680 |
|
| 681 |
//This one should work but doesn't. |
| 682 |
//const char regen_patch[] ={0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x8B, 0x86, 0x44}; |
| 683 |
//DDrPatch_Const(OniExe + 0x0011BB64, regen_patch); |
| 684 |
|
| 685 |
SLrConfig(); |
| 686 |
|
| 687 |
|
| 688 |
SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul); |
| 689 |
SLrScript_Command_Register_ReturnType("mul", "Multiplies two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_mul); |
| 690 |
|
| 691 |
SLrScript_Command_Register_ReturnType("int32div", "Divides two numbers", "n1:int n2:int", sl_int32, bsl_int32div); |
| 692 |
SLrScript_Command_Register_ReturnType("div", "Divides two numbers", "[int1:int|float1:float] [int2:int|float2:float]", sl_float, bsl_div); |
| 693 |
|
| 694 |
dsfmt_gv_init_gen_rand((uint32_t)time(NULL)); |
| 695 |
SLrScript_Command_Register_ReturnType("int32rand", "Returns a pseudo-random number between two numbers (inclusive).", "start:int end:int", sl_int32, bsl_int32rand); |
| 696 |
|
| 697 |
SLrScript_Command_Register_ReturnType("d_getkills","Gets the number of kills a character has", "[ai_name:str | script_id:int]", sl_int32, bsl_getkills); |
| 698 |
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); |
| 699 |
SLrScript_Command_Register_ReturnType("d_name","Gets or sets a character's name", "[ai_name:str | script_id:int] [newname:string]", sl_str32, bsl_chrname); |
| 700 |
SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "script_id:int", sl_int32, bsl_nametoindex); |
| 701 |
SLrScript_Command_Register_ReturnType("d_health","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_health); |
| 702 |
SLrScript_Command_Register_ReturnType("d_regen","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_regen); |
| 703 |
SLrScript_Command_Register_ReturnType("d_maxhealth","Gets or sets a character's maximum health", "[ai_name:str | script_id:int] [newmaxhealth:int] [scalehealth:bool]", sl_str32, bsl_maxhealth); |
| 704 |
SLrScript_Command_Register_ReturnType("d_powerup","Gets or sets a character's powerups", "ai_name:str|script_id:int powerup:str", sl_int32, bsl_powerup); |
| 705 |
SLrScript_Command_Register_ReturnType("d_holdkey","Makes an AI hold a key", "[ai_name:string | script_id:int] keys", sl_int32, bsl_holdkey); |
| 706 |
SLrScript_Command_Register_ReturnType("d_isheld","Checks for a held key", "keys", sl_int32, bsl_isheld); |
| 707 |
SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress.", "keys", bsl_waitforkey); |
| 708 |
|
| 709 |
//broken. sometimes crashes, and sometimes returns a string... : / |
| 710 |
SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker); |
| 711 |
|
| 712 |
SLrScript_Command_Register_ReturnType("d_active","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset); |
| 713 |
|
| 714 |
SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf); |
| 715 |
|
| 716 |
SLrScript_Command_Register_ReturnType("d_dprint", "prints to console in color", "text:string [color: r b g] [color: r b g]", sl_void, bsl_dprintcolored); |
| 717 |
|
| 718 |
//SLrScript_Command_Register_ReturnType("d_offset", "a test", "thing:int", sl_int32, bsl_returnoffset); |
| 719 |
} |
| 720 |
|
| 721 |
void SLrDaodan_Patch() |
| 722 |
{ |
| 723 |
DDrPatch_Int32(OniExe + 0x000f3755, (int)cinematic_start_patch); |
| 724 |
} |