Fixed the hang/freeze in combat (from commit b345140)

Added a fix for retargeting tile for multihex critters.
This commit is contained in:
NovaRain
2020-06-27 09:48:20 +08:00
parent 535595a997
commit 066280a7ca
+35 -12
View File
@@ -912,20 +912,33 @@ end:
} }
} }
static void __declspec(naked) MultiHexRetargetTileFix() {
__asm {
call tile_dist_;
test [ebp + 0x25], 0x08; // is source multihex?
jnz isMultiHex;
retn;
isMultiHex:
cmp eax, 2; // distance from target to retargeted tile
cmovl eax, edi;
retn;
}
}
static void __declspec(naked) MultiHexCombatMoveFix() { static void __declspec(naked) MultiHexCombatMoveFix() {
static const DWORD ai_move_steps_closer_move_object_ret = 0x42A192; static const DWORD ai_move_steps_closer_move_object_ret = 0x42A192;
__asm { __asm {
mov edx, [esp + 4]; // source's destination tilenum
cmp [edi + 0x4], edx; // target's tilenum
je checkObj;
retn; // tilenums are not equal, always move to tile
checkObj:
test [edi + 0x25], 0x08; // is target multihex? test [edi + 0x25], 0x08; // is target multihex?
jnz multiHex; jnz multiHex;
test [esi + 0x25], 0x08; // is source multihex? test [esi + 0x25], 0x08; // is source multihex?
jnz multiHex; jnz multiHex;
retn; // move to tile retn; // move to tile
multiHex: multiHex:
mov edx, [esp + 4]; // source's destination tilenum
cmp [edi + 0x4], edx; // target's tilenum
je moveToObject;
retn; // tilenums are not equal, always move to tile
moveToObject:
add esp, 4; add esp, 4;
jmp ai_move_steps_closer_move_object_ret; // move to object jmp ai_move_steps_closer_move_object_ret; // move to object
} }
@@ -934,17 +947,17 @@ multiHex:
static void __declspec(naked) MultiHexCombatRunFix() { static void __declspec(naked) MultiHexCombatRunFix() {
static const DWORD ai_move_steps_closer_run_object_ret = 0x42A169; static const DWORD ai_move_steps_closer_run_object_ret = 0x42A169;
__asm { __asm {
mov edx, [esp + 4]; // source's destination tilenum
cmp [edi + 0x4], edx; // target's tilenum
je checkObj;
retn; // tilenums are not equal, always run to tile
checkObj:
test [edi + 0x25], 0x08; // is target multihex? test [edi + 0x25], 0x08; // is target multihex?
jnz multiHex; jnz multiHex;
test [esi + 0x25], 0x08; // is source multihex? test [esi + 0x25], 0x08; // is source multihex?
jnz multiHex; jnz multiHex;
retn; // run to tile retn; // run to tile
multiHex: multiHex:
mov edx, [esp + 4]; // source's destination tilenum
cmp [edi + 0x4], edx; // target's tilenum
je runToObject;
retn; // tilenums are not equal, always run to tile
runToObject:
add esp, 4; add esp, 4;
jmp ai_move_steps_closer_run_object_ret; // run to object jmp ai_move_steps_closer_run_object_ret; // run to object
} }
@@ -2877,6 +2890,9 @@ void BugFixesInit()
// Fix for multihex critters moving too close and overlapping their targets in combat // Fix for multihex critters moving too close and overlapping their targets in combat
MakeCall(0x42A14F, MultiHexCombatRunFix, 1); MakeCall(0x42A14F, MultiHexCombatRunFix, 1);
MakeCall(0x42A178, MultiHexCombatMoveFix, 1); MakeCall(0x42A178, MultiHexCombatMoveFix, 1);
// Prevent retargeting to a tile if the distance from the tile to the target is less than 2 hexes
HookCall(0x42A3C1, MultiHexRetargetTileFix); // cai_retargetTileFromFriendlyFire_
// TODO: need to add the correct implementation of retargeting tile for multihex critters to SubFunc_
dlogr(" Done", DL_INIT); dlogr(" Done", DL_INIT);
//} //}
@@ -3342,6 +3358,13 @@ void BugFixesInit()
// Fix the code in combat_is_shot_blocked_ to correctly get the next tile from a multihex object instead of the previous // Fix the code in combat_is_shot_blocked_ to correctly get the next tile from a multihex object instead of the previous
// object or source tile // object or source tile
// Note: this bug does not cause an error in the function work // Note: this bug does not cause an error in the function work
__int64 data = 0x840F04708B90; // remove jnz and modify jmp > jz BYTE codeData[] = {
SafeWriteBytes(0x426D60, (BYTE*)&data, 6); 0x8B, 0x70, 0x04, // mov esi, [eax + 4]
0xF6, 0x40, 0x25, 0x08, // test [eax + flags2], MultiHex_
0x74, 0x1E, // jz 0x426D83
0x39, 0xEE, // cmp esi, ebp
0x74, 0x1A, // jz 0x426D83
0x90
};
SafeWriteBytes(0x426D5C, codeData, 14);
} }