Added upper/lower limits to the hit chance value

Edited hookscript docs.
This commit is contained in:
NovaRain
2023-07-09 15:22:56 +08:00
parent 321f8e1ab2
commit ddb3cf9b6e
6 changed files with 26 additions and 8 deletions
+2 -3
View File
@@ -97,7 +97,7 @@ procedure remove_array_set(variable array, variable item);
// Creates a new array filled from a given array by transforming each value using given procedure name. // Creates a new array filled from a given array by transforming each value using given procedure name.
procedure array_transform(variable arr, variable valueFunc); procedure array_transform(variable arr, variable valueFunc);
// Create a new temp array filled from a given array by transforming each key and value using given procedure names. // Create a new temp array filled from a given array by transforming each key and value using given procedure name.
procedure array_transform_kv(variable arr, variable keyFunc, variable valueFunc); procedure array_transform_kv(variable arr, variable keyFunc, variable valueFunc);
@@ -423,8 +423,7 @@ procedure array_transform(variable arr, variable valueFunc) begin
return retArr; return retArr;
end end
// Create a new temp array filled from a given array by transforming each key and value using given procedure name.
// Create a new temp array filled from a given array by transforming each key and value using given procedure names.
procedure array_transform_kv(variable arr, variable keyFunc, variable valueFunc) begin procedure array_transform_kv(variable arr, variable keyFunc, variable valueFunc) begin
variable k, v, retArr := temp_array_map; variable k, v, retArr := temp_array_map;
foreach (k: v in arr) begin foreach (k: v in arr) begin
+1 -1
View File
@@ -23,7 +23,7 @@
int arg6 - Ranged flag. 1 if the hit chance calculation takes into account the distance to the target. This does not mean the attack is a ranged attack int arg6 - Ranged flag. 1 if the hit chance calculation takes into account the distance to the target. This does not mean the attack is a ranged attack
int arg7 - The raw hit chance before applying the cap int arg7 - The raw hit chance before applying the cap
int ret0 - the new hit chance int ret0 - The new hit chance. The value is limited to the range of -99 to 999
``` ```
- name: AfterHitRoll - name: AfterHitRoll
+1 -1
View File
@@ -108,7 +108,7 @@ int arg5 - Attack Type (see ATKTYPE_* constants)
int arg6 - Ranged flag. 1 if the hit chance calculation takes into account the distance to the target. This does not mean the attack is a ranged attack int arg6 - Ranged flag. 1 if the hit chance calculation takes into account the distance to the target. This does not mean the attack is a ranged attack
int arg7 - The raw hit chance before applying the cap int arg7 - The raw hit chance before applying the cap
int ret0 - the new hit chance int ret0 - The new hit chance. The value is limited to the range of -99 to 999
``` ```
------------------------------------------- -------------------------------------------
+15 -2
View File
@@ -264,11 +264,20 @@ static void __declspec(naked) determine_to_hit_func_hack() {
mov edx, edi; // critter mov edx, edi; // critter
mov ecx, esi; // base (calculated hit chance) mov ecx, esi; // base (calculated hit chance)
call HitChanceMod; call HitChanceMod;
mov esi, eax; mov esi, 999; // max
cmp eax, esi;
cmovl esi, eax;
retn; retn;
} }
} }
static void __declspec(naked) determine_to_hit_func_hook_min() {
__asm {
mov esi, -99; // min
jmp fo::funcoffs::debug_printf_;
}
}
bool Combat::IsBurstDisabled(fo::GameObject* critter) { bool Combat::IsBurstDisabled(fo::GameObject* critter) {
for (size_t i = 0; i < noBursts.size(); i++) { for (size_t i = 0; i < noBursts.size(); i++) {
if (noBursts[i] == critter->id) return true; if (noBursts[i] == critter->id) return true;
@@ -355,7 +364,7 @@ void __stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode) {
} }
} }
void __stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod) { void __stdcall SetHitChanceMax(fo::GameObject* critter, int maximum, int mod) {
if ((DWORD)critter == -1) { if ((DWORD)critter == -1) {
baseHitChance.maximum = maximum; baseHitChance.maximum = maximum;
baseHitChance.mod = mod; baseHitChance.mod = mod;
@@ -569,6 +578,10 @@ void Combat::init() {
MakeCall(0x424791, determine_to_hit_func_hack); // HitChanceMod MakeCall(0x424791, determine_to_hit_func_hack); // HitChanceMod
BlockCall(0x424796); BlockCall(0x424796);
// Add a lower limit of -99% to the calculated hit chance instead of only a debug message
SafeWrite8(0x42479D, -99); // was -100
HookCall(0x4247A5, determine_to_hit_func_hook_min);
// Disables secondary burst attacks for the critter // Disables secondary burst attacks for the critter
MakeCall(0x429E44, ai_pick_hit_mode_hack_noBurst, 1); MakeCall(0x429E44, ai_pick_hit_mode_hack_noBurst, 1);
+1 -1
View File
@@ -52,7 +52,7 @@ public:
static bool IsBurstDisabled(fo::GameObject* critter); static bool IsBurstDisabled(fo::GameObject* critter);
}; };
void __stdcall SetHitChanceMax(fo::GameObject* critter, DWORD maximum, DWORD mod); void __stdcall SetHitChanceMax(fo::GameObject* critter, int maximum, int mod);
void __stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWORD mode); void __stdcall KnockbackSetMod(fo::GameObject* object, DWORD type, float val, DWORD mode);
void __stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode); void __stdcall KnockbackRemoveMod(fo::GameObject* object, DWORD mode);
+6
View File
@@ -36,6 +36,12 @@ static void __declspec(naked) ToHitHook() {
__asm { __asm {
cmp cRet, 1; cmp cRet, 1;
cmovge ebx, rets[0]; cmovge ebx, rets[0];
mov eax, 999; // max
cmp ebx, eax;
cmovg ebx, eax;
mov eax, -99; // min
cmp ebx, eax;
cmovl ebx, eax;
call EndHook; call EndHook;
mov eax, ebx; mov eax, ebx;
retn 8; retn 8;