--- Daodan/src/Patches/BSL.c 2014/04/07 10:33:27 994 +++ Daodan/src/Patches/BSL.c 2021/10/24 02:50:22 1161 @@ -12,6 +12,11 @@ #include "Character.h" +bool ONICALL argumentEmpty(sl_arg* arg) { + if ((arg->type == sl_str32) && (strlen(arg->val.value_str32) == 0)) + return true; + return false; +} uint16_t ONICALL bsl_int32mul(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { @@ -92,7 +97,7 @@ uint16_t ONICALL bsl_int32rand(sl_callin uint16_t ONICALL bsl_getkills(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { int index; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; //killcount = ONgGameState->CharacterStorage[index].Kills; @@ -105,7 +110,7 @@ uint16_t ONICALL bsl_getkills(sl_callinf uint16_t ONICALL bsl_getdamage(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { int index; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; ret->val.value_int32 = ONgGameState->CharacterStorage[index].Damage; @@ -185,7 +190,7 @@ uint16_t ONICALL bsl_health(sl_callinfo* int index; Character* Chr; int* health; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; Chr = ONgGameState->CharacterStorage; @@ -206,12 +211,11 @@ uint16_t ONICALL bsl_regen(sl_callinfo* { int index; Character* Chr; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; Chr = ONgGameState->CharacterStorage ; - /* DDrConsole_PrintF("Character %s", Chr[index].Name); DDrConsole_PrintF("Spawn %s", Chr[index].ScriptSpawn); @@ -310,7 +314,7 @@ uint16_t ONICALL bsl_location(sl_callinf uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { int index; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; if(1) { @@ -335,7 +339,7 @@ uint16_t ONICALL bsl_getattacker(sl_call //broken int index; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; if(1) { @@ -355,7 +359,7 @@ uint16_t ONICALL bsl_chrname(sl_callinfo int index; char* name; - if (numargs == 0) index = 0; + if (argumentEmpty(&args[0])) index = 0; else if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); else index = args[0].val.value_int32; if (index == -1) { @@ -394,7 +398,7 @@ uint16_t ONICALL bsl_dprintcolored(sl_ca { numargs++; } - if(numargs == 0) return 0; + if(argumentEmpty(&args[0])) return 0; if(numargs > 1 ) color.R = (char)args[1].val.value_int32; else color.R = 255; if(numargs > 2 ) color.G = (char)args[2].val.value_int32; @@ -426,10 +430,10 @@ uint16_t ONICALL bsl_nametoindex(sl_call typedef struct { char Name[16]; -int Bit; +uint64_t Bit; } KeyBit; -KeyBit Actions1[32] = { +static KeyBit Actions[] = { {"Escape", Action_Escape}, {"Console", Action_Console}, {"PauseScreen", Action_PauseScreen}, @@ -440,17 +444,12 @@ KeyBit Actions1[32] = { {"F6", Action_F6 }, {"F7", Action_F7 }, {"F8", Action_F8 }, - {"StartRecord", Action_StartRecord }, - {"StopRecord", Action_StopRecord }, - {"PlayRecord", Action_PlayRecord }, + {"StartRecord", Action_StartRecord }, + {"StopRecord", Action_StopRecord }, + {"PlayRecord", Action_PlayRecord }, {"F12", Action_F12 }, - {"Unknown1", Action_Unknown1 }, {"LookMode", Action_LookMode }, - {"Screenshot", Action_Screenshot }, - {"Unknown2", Action_Unknown2 }, - {"Unknown3", Action_Unknown3 }, - {"Unknown4", Action_Unknown4 }, - {"Unknown5", Action_Unknown5 }, + {"Screenshot", Action_Screenshot }, {"Forward", Action_Forward }, {"Backward", Action_Backward }, {"TurnLeft", Action_TurnLeft }, @@ -461,27 +460,24 @@ KeyBit Actions1[32] = { {"Crouch", Action_Crouch }, {"Punch",Action_Punch }, {"Kick", Action_Kick }, - {"Block", Action_Block } + {"Block", Action_Block }, + {"Walk", Action_Walk}, + {"Action", Action_Action}, + {"Hypo", Action_Hypo}, + {"Reload", Action_Reload }, + {"Swap", Action_Swap }, + {"Drop", Action_Drop }, + {"Fire1", Action_Fire1 }, + {"Fire2", Action_Fire2 }, + {"Fire3", Action_Fire3 } }; -KeyBit Actions2[9] = { - {"Walk", Action2_Walk}, - {"Action", Action2_Action}, - {"Hypo", Action2_Hypo}, - {"Reload", Action2_Reload }, - {"Swap", Action2_Swap }, - {"Drop", Action2_Drop }, - {"Fire1", Action2_Fire1 }, - {"Fire2", Action2_Fire2 }, - {"Fire3", Action2_Fire3 } -}; uint16_t ONICALL bsl_holdkey(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { uint32_t index; uint32_t i = 2; uint32_t j = 0; - int Input1 = 0; - int Input2 = 0; + uint64_t Input = 0; Character* Chr; ActiveCharacter* Active; if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].val.value_str32); @@ -493,19 +489,13 @@ uint16_t ONICALL bsl_holdkey(sl_callinfo for(i = 1; i < numargs - 1; i++) { for(j = 0; j < 32; j++) { - if(!strcmp(args[i].val.value_str32, Actions1[j].Name)) { - Input1 = Input1 | Actions1[j].Bit; - } - } - for(j = 0; j < 9; j++) { - if(!strcmp(args[i].val.value_str32, Actions2[j].Name)) { - Input2 = Input2 | Actions2[j].Bit; + if(!strcmp(args[i].val.value_str32, Actions[j].Name)) { + Input = Input | Actions[j].Bit; } } } - Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1; - Active->Input.Current.Actions2 = Active->Input.Current.Actions2 | Input2; - if( Input1 + Input2 == 0 ) { + Active->Input.ActionsDown = Active->Input.ActionsDown | Input; + if( Input == 0 ) { DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name); return 0; } @@ -532,26 +522,21 @@ uint16_t ONICALL bsl_isheld(sl_callinfo* // if ((int)Active == 0) return 1; uint32_t i = 2; uint32_t j = 0; - int Input1 = 0; - int Input2 = 0; + uint64_t Input = 0; for(i = 0; i < numargs; i++) { for(j = 0; j < 32; j++) { //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].val.value_str32, Actions1[j].Name, Actions1[j].Bit); - if(!strcmp(args[i].val.value_str32, Actions1[j].Name)) { - Input1 = Input1 | Actions1[j].Bit; + if(!strcmp(args[i].val.value_str32, Actions[j].Name)) { + Input = Input | Actions[j].Bit; //DDrConsole_PrintF("Success!"); } - - } - for(j = 0; j < 9; j++) { - if(!strcmp(args[i].val.value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; - + } } //DDrConsole_PrintF("Testing: 0x%x Input: 0x%x",Input1, *(int*)(ONgGameState + 0xB8 + 0x10)); ret->val.value_int32 = 0; ret->type = sl_int32; - if ( (ONgGameState->Input.Current.Actions1 == Input1) && (ONgGameState->Input.Current.Actions2 == Input2)) ret->val.value_int32 = 1; + if (ONgGameState->Input.ActionsDown == Input) ret->val.value_int32 = 1; return 0; } @@ -568,8 +553,7 @@ uint16_t ONICALL bsl_waitforkey(sl_calli int i = 2; int j = 0; - int Input1 = 0; - int Input2 = 0; + uint64_t Input = 0; /* numargs = 0; for(i = 0; args[i].type <= sl_void; i++) @@ -584,22 +568,15 @@ uint16_t ONICALL bsl_waitforkey(sl_calli i = 0; for(j = 0; j < 32; j++) { //DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].val.value_str32, Actions1[j].Name, Actions1[j].Bit); - if(!strcmp(args[i].val.value_str32, Actions1[j].Name)) { - Input1 = Input1 | Actions1[j].Bit; + if(!strcmp(args[i].val.value_str32, Actions[j].Name)) { + Input = Input | Actions[j].Bit; //DDrConsole_PrintF("Success!"); } - - } - for(j = 0; j < 9; j++) { - if(!strcmp(args[i].val.value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit; - + } // } DDrConsole_PrintF("Waiting..."); - if ( - (( ONgGameState->Input.Current.Actions1 & Input1) == Input1) && - (( ONgGameState->Input.Current.Actions2 & Input2) == Input2) - ) + if (( ONgGameState->Input.ActionsDown & Input) == Input) { DDrConsole_PrintF("Found key!"); } @@ -692,6 +669,7 @@ uint16_t ONICALL bsl_sprintf(sl_callinfo uint16_t ONICALL cinematic_start_patch(sl_callinfo* callinfo, unsigned int numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) { args[1].val.value_int32 = (double)args[1].val.value_int32 / (double)(gl->DisplayMode.Width) * (4.0 / 3.0 * (double)(gl->DisplayMode.Height)); + // Call orig OCiCinematic_ScriptStart return ((sl_func)(OniExe + 0x000f3830))(callinfo, numargs, args, dontuse1, dontuse2, ret); } @@ -768,5 +746,6 @@ void SLrDaodan_Initialize() // Patch for cinematic_start to work on widescreen resolutions void SLrDaodan_Patch() { + // PUSH OCiCinematic_ScriptStart -> PUSH cinematic_start_patch DDrPatch_Int32((int*)(OniExe + 0x000f3755), (int)cinematic_start_patch); }