From 5c3f10db91be52e7a9cf59896b3b589ccda46c62 Mon Sep 17 00:00:00 2001 From: NovaRain Date: Wed, 10 Apr 2019 09:46:31 +0800 Subject: [PATCH] Edited/reorganized some code. Updated proto offsets in define_extra.h. --- artifacts/scripting/headers/define_extra.h | 64 +++++--- sfall/Modules/BarBoxes.cpp | 2 +- sfall/Modules/HookScripts/CombatHs.cpp | 8 +- sfall/Modules/HookScripts/Common.cpp | 3 + sfall/Modules/HookScripts/MiscHs.cpp | 164 ++++++++++----------- sfall/Modules/HookScripts/MiscHs.h | 2 +- 6 files changed, 132 insertions(+), 111 deletions(-) diff --git a/artifacts/scripting/headers/define_extra.h b/artifacts/scripting/headers/define_extra.h index 89a28886..87e32ba6 100644 --- a/artifacts/scripting/headers/define_extra.h +++ b/artifacts/scripting/headers/define_extra.h @@ -105,17 +105,22 @@ #define RMOBJ_THROW 4266040 #define RMOBJ_SUB_CONTAINER 4683191 // search and remove the item from a container inside of an inventory -// offsets for get_proto_data +// common prototype offsets for get/set_proto_data #define PROTO_PID (1) #define PROTO_TEXTID (4) #define PROTO_FID (8) +#define PROTO_LDIST (12) +#define PROTO_LINT (16) +#define PROTO_FLAG (20) +#define PROTO_FLAG_EXT (24) +#define PROTO_SCRIPTID (28) // items -#define PROTO_IT_LDIST (12) -#define PROTO_IT_LINT (16) -#define PROTO_IT_FLAG (20) -#define PROTO_IT_FLAGS (24) -#define PROTO_IT_SCRIPTID (28) +#define PROTO_IT_LDIST PROTO_LDIST +#define PROTO_IT_LINT PROTO_LINT +#define PROTO_IT_FLAG PROTO_FLAG +#define PROTO_IT_FLAGS PROTO_FLAG_EXT +#define PROTO_IT_SCRIPTID PROTO_SCRIPTID #define PROTO_IT_TYPE (32) #define PROTO_IT_MATERIAL (108) #define PROTO_IT_SIZE (112) @@ -200,18 +205,31 @@ #define PROTO_DR_ADDICT_DELAY (100) // critters -#define PROTO_CR_LDIST (20) -#define PROTO_CR_LINT (24) -#define PROTO_CR_FLAG (28) -#define PROTO_CR_FLAGS (32) // Critter Flags -#define PROTO_CR_SCRIPTID (36) -#define PROTO_CR_HEAD_FID (40) -#define PROTO_CR_AI_PACKET (44) -#define PROTO_CR_TEAM_NUM (48) -#define PROTO_CR_BODY_TYPE (388) -#define PROTO_CR_KILL_EXP (392) -#define PROTO_CR_KILL_TYPE (396) -#define PROTO_CR_DMG_TYPE (400) +#define PROTO_CR_FLAGS (32) // Critter Flags +#define PROTO_CR_BONUS_SRENGTH (176) +#define PROTO_CR_BONUS_PRCEPTION (180) +#define PROTO_CR_BONUS_ENDURANCE (184) +#define PROTO_CR_BONUS_CHARISMA (188) +#define PROTO_CR_BONUS_INTELLIGENCE (192) +#define PROTO_CR_BONUS_AGILITY (196) +#define PROTO_CR_BONUS_LUCK (200) +#define PROTO_CR_BONUS_HP (204) +#define PROTO_CR_BONUS_AP (208) +#define PROTO_CR_BONUS_AC (212) +#define PROTO_CR_BONUS_UNARMED_DAMAGE (216) +#define PROTO_CR_BONUS_MELEE_DAMAGE (220) +#define PROTO_CR_BONUS_CARRY_WEIGHT (224) +#define PROTO_CR_BONUS_SEQUENCE (228) +#define PROTO_CR_BONUS_HEALING_RATE (232) +#define PROTO_CR_BONUS_CRITICAL_CHANCE (236) +#define PROTO_CR_BONUS_BETTER_CRITICALS (240) +#define PROTO_CR_BODY_TYPE (388) +#define PROTO_CR_KILL_EXP (392) +#define PROTO_CR_KILL_TYPE (396) +#define PROTO_CR_DMG_TYPE (400) +#define PROTO_CR_HEAD_FID (404) +#define PROTO_CR_AI_PACKET (408) +#define PROTO_CR_TEAM_NUM (412) // weapon calibers #define CALIBER_NONE (0) @@ -279,11 +297,11 @@ #define AI_CAP_MAX_DISTANCE (7) #define AI_CAP_MIN_HP (8) #define AI_CAP_MIN_TO_HIT (9) -#define AI_CAP_HURT_TOO_MUCH (10) // DAM_BLIND/DAM_CRIP_* flags -#define AI_CAP_RUN_AWAY_MODE (11) -#define AI_CAP_SECONDARY_FREQ (12) -#define AI_CAP_CALLED_FREQ (13) -#define AI_CAP_CHEM_PRIMARY_DESIRE (14) // array pid list +#define AI_CAP_HURT_TOO_MUCH (10) // DAM_BLIND/DAM_CRIP_* flags +#define AI_CAP_RUN_AWAY_MODE (11) +#define AI_CAP_SECONDARY_FREQ (12) +#define AI_CAP_CALLED_FREQ (13) +#define AI_CAP_CHEM_PRIMARY_DESIRE (14) // array pid list // AI attack area mode values #define ai_area_always (0) diff --git a/sfall/Modules/BarBoxes.cpp b/sfall/Modules/BarBoxes.cpp index 56f55c64..64a34021 100644 --- a/sfall/Modules/BarBoxes.cpp +++ b/sfall/Modules/BarBoxes.cpp @@ -31,7 +31,7 @@ static int initCount = 5; // init config counter (5 - vanilla bo static int sizeBox, setBoxIndex = 5; static long newBoxSlot[16]; -static long maxSlots; // maximum number of slots for the current game window resolution +static long maxSlots = 6; // maximum number of slots for the current game window resolution static long ifaceWidth; #define sSize (12) diff --git a/sfall/Modules/HookScripts/CombatHs.cpp b/sfall/Modules/HookScripts/CombatHs.cpp index d7316a1f..6da7e1e1 100644 --- a/sfall/Modules/HookScripts/CombatHs.cpp +++ b/sfall/Modules/HookScripts/CombatHs.cpp @@ -326,10 +326,10 @@ static void __declspec(naked) AmmoCostHook() { using namespace fo; __asm { xor ecx, ecx; // type of hook (0) - cmp dword ptr [esp + 0x1C + 4], ANIM_fire_burst; - jl skip; - cmp dword ptr [esp + 0x1C + 4], ANIM_fire_continuous; - jg skip; + cmp dword ptr [esp + 0x1C + 4], ANIM_fire_burst; + jl skip; + cmp dword ptr [esp + 0x1C + 4], ANIM_fire_continuous; + jg skip; mov ecx, 3; // hook type burst skip: xchg eax, edx; diff --git a/sfall/Modules/HookScripts/Common.cpp b/sfall/Modules/HookScripts/Common.cpp index efe1d543..589adabe 100644 --- a/sfall/Modules/HookScripts/Common.cpp +++ b/sfall/Modules/HookScripts/Common.cpp @@ -130,6 +130,9 @@ void _stdcall RunHookScript(DWORD hook) { } } else { cArg = 0; + #ifndef NDEBUG + dlog_f(">>> Try running hook ID: %d\n", DL_HOOK, hook); + #endif } } diff --git a/sfall/Modules/HookScripts/MiscHs.cpp b/sfall/Modules/HookScripts/MiscHs.cpp index 60820fe2..3175d4f4 100644 --- a/sfall/Modules/HookScripts/MiscHs.cpp +++ b/sfall/Modules/HookScripts/MiscHs.cpp @@ -90,6 +90,85 @@ static void __declspec(naked) OverrideCost_BarterPriceHack() { } } +static fo::GameObject* sourceSkillOn = nullptr; +void SourceUseSkillOnInit() { sourceSkillOn = fo::var::obj_dude; } + +static char resultSkillOn; +static long bakupCombatState; +static void __fastcall UseSkillOnHook_Script(DWORD source, DWORD target, register DWORD skillId) { + BeginHook(); + argCount = 3; + + args[0] = source; // user + args[1] = target; // target + args[2] = skillId; // skill id + + sourceSkillOn = fo::var::obj_dude; + resultSkillOn = 0; + bakupCombatState = -1; + + RunHookScript(HOOK_USESKILLON); + + if (skillId != fo::Skill::SKILL_STEAL && cRet > 0) { // not work for steal skill + if (rets[0] != 0) { + resultSkillOn = (rets[0] == -1) ? -1 : 1; + if (resultSkillOn == 1) { + sourceSkillOn = (fo::GameObject*)rets[0]; + } + } + if (resultSkillOn != -1 && cRet > 1 && rets[1] == 1) { + bakupCombatState = fo::var::combat_state; + fo::var::combat_state = 0; + } + } + EndHook(); +} + +static void __declspec(naked) UseSkillOnHook() { + __asm { + push eax; + push ecx; + push edx; + push ebx; // skill id + mov ecx, eax; // user + call UseSkillOnHook_Script; // edx - target + pop edx; + pop ecx; + pop eax; + cmp resultSkillOn, -1; // skip handler + jnz handler; + retn; +handler: + jmp fo::funcoffs::action_use_skill_on_; + } +} + +static void __declspec(naked) UseSkillOnHack() { + __asm { + cmp bakupCombatState, -1; + jz skip; + mov ebp, bakupCombatState; + mov dword ptr ds:[FO_VAR_combat_state], ebp; +skip: + cmp resultSkillOn, 0; + jz default; + mov edi, sourceSkillOn; + retn; // flag ZF = 0 +default: + // engine code + cmp eax, dword ptr ds:[FO_VAR_obj_dude]; + retn; + } +} + +static void __declspec(naked) skill_use_hack() { + __asm { + cmp ebp, dword ptr ds:[FO_VAR_obj_dude]; + setnz al; + retn; + } +} + static void __declspec(naked) UseSkillHook() { __asm { HookBegin; @@ -125,14 +204,14 @@ static void __declspec(naked) StealCheckHook() { mov args[4], edx; // target mov args[8], ebx; // item mov args[12], ecx; // is planting - pushad; + pushadc; } argCount = 4; RunHookScript(HOOK_STEAL); __asm { - popad; + popadc; cmp cRet, 1; jb defaultHandler; cmp rets[0], -1; @@ -415,84 +494,6 @@ end: } } -static fo::GameObject* sourceSkillOn = nullptr; -void SourceUseSkillOnInit() { sourceSkillOn = fo::var::obj_dude; } - -static char resultSkillOn; -static long bakupCombatState; -static void __fastcall UseSkillOnHook_Script(DWORD source, DWORD target, register DWORD skillId) { - BeginHook(); - argCount = 3; - - args[0] = source; // user - args[1] = target; // target - args[2] = skillId; // skill id - - sourceSkillOn = fo::var::obj_dude; - resultSkillOn = 0; - bakupCombatState = -1; - - RunHookScript(HOOK_USESKILLON); - - if (skillId != fo::Skill::SKILL_STEAL && cRet > 0) { // not work for steal skill - if (rets[0] != 0) { - resultSkillOn = (rets[0] == -1) ? -1 : 1; - if (resultSkillOn == 1) { - sourceSkillOn = (fo::GameObject*)rets[0]; - } - } - if (resultSkillOn != -1 && cRet > 1 && rets[1] == 1) { - bakupCombatState = fo::var::combat_state; - fo::var::combat_state = 0; - } - } - EndHook(); -} - -static void __declspec(naked) UseSkillOnHook() { - __asm { - push eax; - push ecx; - push edx; - push ebx; // skill id - mov ecx, eax; // user - call UseSkillOnHook_Script; // edx - target - pop edx; - pop ecx; - pop eax; - cmp resultSkillOn, -1; // skip handler - jnz handler; - retn; -handler: - jmp fo::funcoffs::action_use_skill_on_; - } -} - -static void __declspec(naked) UseSkillOnHack() { - __asm { - cmp bakupCombatState, -1; - jz skip; - mov ebp, bakupCombatState; - mov dword ptr ds:[FO_VAR_combat_state], ebp; -skip: - cmp resultSkillOn, 0; - jz default; - mov edi, sourceSkillOn; - retn; // flag ZF = 0 -default: - // engine code - cmp eax, dword ptr ds:[FO_VAR_obj_dude]; - retn; - } -} - -static void __declspec(naked) skill_use_hack() { - __asm { - cmp ebp, dword ptr ds:[FO_VAR_obj_dude]; - setnz al; - retn; - } -} void Inject_BarterPriceHook() { HookCalls(BarterPriceHook, { @@ -553,8 +554,8 @@ void Inject_UseSkillOnHook() { } void InitMiscHookScripts() { - LoadHookScript("hs_barterprice", HOOK_BARTERPRICE); + LoadHookScript("hs_useskillon", HOOK_USESKILLON); LoadHookScript("hs_useskill", HOOK_USESKILL); LoadHookScript("hs_steal", HOOK_STEAL); LoadHookScript("hs_withinperception", HOOK_WITHINPERCEPTION); @@ -562,7 +563,6 @@ void InitMiscHookScripts() { LoadHookScript("hs_setglobalvar", HOOK_SETGLOBALVAR); LoadHookScript("hs_resttimer", HOOK_RESTTIMER); LoadHookScript("hs_explosivetimer", HOOK_EXPLOSIVETIMER); - LoadHookScript("hs_useskillon", HOOK_USESKILLON); } } diff --git a/sfall/Modules/HookScripts/MiscHs.h b/sfall/Modules/HookScripts/MiscHs.h index 1da9f753..bcf98e07 100644 --- a/sfall/Modules/HookScripts/MiscHs.h +++ b/sfall/Modules/HookScripts/MiscHs.h @@ -6,6 +6,7 @@ namespace sfall void SourceUseSkillOnInit(); void Inject_BarterPriceHook(); + void Inject_UseSkillOnHook(); void Inject_UseSkillHook(); void Inject_StealCheckHook(); void Inject_WithinPerceptionHook(); @@ -13,5 +14,4 @@ namespace sfall void Inject_SetGlobalVarHook(); void Inject_RestTimerHook(); void Inject_ExplosiveTimerHook(); - void Inject_UseSkillOnHook(); }