From c165f5beae8e34caa99a4092a79bfc8796be41ef Mon Sep 17 00:00:00 2001 From: Uranusian Date: Fri, 23 Apr 2021 21:51:07 +0800 Subject: [PATCH 1/5] Fix vanilla bug - twice die --- src/Misc/Hooks.BugFixes.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 68ef4db868..94adf80b13 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -26,3 +26,15 @@ DEFINE_HOOK(423365, Phobos_BugFixes_SHPShadowCheck, 8) DEFINE_LJMP(0x545CE2, 0x545CE9) //Phobos_BugFixes_Tileset255_RemoveNonMMArrayFill DEFINE_LJMP(0x546C23, 0x546C8B) //Phobos_BugFixes_Tileset255_RefNonMMArray + +// WW's shit code! Wrong check. +// To avoid units dying when they are already dead. +DEFINE_HOOK(5F53AA, ObjectClass_ReceiveDamage_DyingFix, 6) +{ + GET(int, health, EAX); + + if (health <= 0) + return 0x5F583E; + + return 0x5F53B0; +} \ No newline at end of file From 0cd623b7c4035fdea6f5334421e77491ccd6dce5 Mon Sep 17 00:00:00 2001 From: Uranusian Date: Sat, 24 Apr 2021 18:59:33 +0800 Subject: [PATCH 2/5] small fix --- src/Misc/Hooks.BugFixes.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 94adf80b13..eed07af927 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -27,13 +27,14 @@ DEFINE_LJMP(0x545CE2, 0x545CE9) //Phobos_BugFixes_Tileset255_RemoveNonMMArrayFil DEFINE_LJMP(0x546C23, 0x546C8B) //Phobos_BugFixes_Tileset255_RefNonMMArray -// WW's shit code! Wrong check. +// WWP's shit code! Wrong check. // To avoid units dying when they are already dead. DEFINE_HOOK(5F53AA, ObjectClass_ReceiveDamage_DyingFix, 6) { GET(int, health, EAX); + GET(ObjectClass*, pThis, ESI); - if (health <= 0) + if (health <= 0 || !pThis->IsAlive) return 0x5F583E; return 0x5F53B0; From 5756c454019d83e55e736cf21108c203b443ddf3 Mon Sep 17 00:00:00 2001 From: Uranusian Date: Sat, 24 Apr 2021 21:53:24 +0800 Subject: [PATCH 3/5] More checks --- src/Misc/Hooks.BugFixes.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index eed07af927..7055d60000 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -2,7 +2,7 @@ #include #include #include - +#include //Replace: checking of HasExtras = > checking of (HasExtras && Shadow) DEFINE_HOOK(423365, Phobos_BugFixes_SHPShadowCheck, 8) { @@ -33,8 +33,19 @@ DEFINE_HOOK(5F53AA, ObjectClass_ReceiveDamage_DyingFix, 6) { GET(int, health, EAX); GET(ObjectClass*, pThis, ESI); - - if (health <= 0 || !pThis->IsAlive) + UnitClass* pThisU = nullptr; + FootClass* pThisF = nullptr; + auto abs = pThis->WhatAmI(); + + if (abs == AbstractType::Unit|| abs == AbstractType::Aircraft || abs == AbstractType::Infantry) + pThisF = abstract_cast(pThis); + if (abs == AbstractType::Unit) + pThisU = abstract_cast(pThis); + + if (health <= 0 + || !pThis->IsAlive + || pThisU && pThisU->DeathFrameCounter > 0 + || pThisF && (pThisF->IsSinking || pThisF->IsCrashing)) return 0x5F583E; return 0x5F53B0; From 7cd7157d83c2862d55fc0aac1664e0f232c990df Mon Sep 17 00:00:00 2001 From: Uranusian Date: Sat, 24 Apr 2021 22:55:56 +0800 Subject: [PATCH 4/5] Separate hooks --- src/Misc/Hooks.BugFixes.cpp | 45 +++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 7055d60000..785e7a99b2 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -33,20 +33,31 @@ DEFINE_HOOK(5F53AA, ObjectClass_ReceiveDamage_DyingFix, 6) { GET(int, health, EAX); GET(ObjectClass*, pThis, ESI); - UnitClass* pThisU = nullptr; - FootClass* pThisF = nullptr; - auto abs = pThis->WhatAmI(); - - if (abs == AbstractType::Unit|| abs == AbstractType::Aircraft || abs == AbstractType::Infantry) - pThisF = abstract_cast(pThis); - if (abs == AbstractType::Unit) - pThisU = abstract_cast(pThis); - - if (health <= 0 - || !pThis->IsAlive - || pThisU && pThisU->DeathFrameCounter > 0 - || pThisF && (pThisF->IsSinking || pThisF->IsCrashing)) - return 0x5F583E; - - return 0x5F53B0; -} \ No newline at end of file + + if (health <= 0 || !pThis->IsAlive) + return 0x5F583E; // return DamageState::PostMortem + + return 0x5F53B0; //continue vanilla check +} + +DEFINE_HOOK(4D7431, FootClass_ReceiveDamage_DyingFix, 5) +{ + GET(FootClass*, pThis, ESI); + GET(DamageState, Result, EAX); + + if (Result != DamageState::PostMortem && (pThis->IsSinking || pThis->IsCrashing)) + R->EAX(DamageState::PostMortem); + + return 0; +} + +DEFINE_HOOK(737D57, UnitClass_ReceiveDamage_DyingFix, 7) +{ + GET(UnitClass*, pThis, ESI); + GET(DamageState, Result, EAX); + + if (Result != DamageState::PostMortem && pThis->DeathFrameCounter > 0) + R->EAX(DamageState::PostMortem); + + return 0; +} From 3fc08e76feb55f4b78b6c19fe30cf50564b75108 Mon Sep 17 00:00:00 2001 From: Uranusian Date: Sat, 24 Apr 2021 23:04:29 +0800 Subject: [PATCH 5/5] Pass and docs --- README.md | 2 +- docs/Fixed-or-Improved-Logics.md | 1 + docs/Whats-New.md | 1 + src/Misc/Hooks.BugFixes.cpp | 8 ++++---- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f7d5da7e8d..ca0eeb4b10 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Credits - SMxReaver - help with docs - 4SG - help with docs - wiktorderelf - overhauled Unicode font -- Thrifinesma (Uranusian) - Mind Control enhancement, custom warhead splash list, harvesters counter, promoted spawns, shields, overhauled Unicode font, help with docs +- Thrifinesma (Uranusian) - Mind Control enhancement, custom warhead splash list, harvesters counter, promoted spawns, shields, death after dead fix, overhauled Unicode font, help with docs - SEC-SOME (secsome) - debug info dump hotkey, refactoring & porting of Ares helper code, introducing more Ares-derived stuff, disguise removal warhead, Mind Control removal warhead, Mind Control enhancement, shields - Otamaa (BoredEXE) - help with CellSpread, ported and fixed custom RadType code, togglable ElectricBolt bolts, customizable Chrono Locomotor properties per TechnoClass - E1 Elite - TileSet 255 and above bridge repair fix diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 6a0e49010f..5b099a0fa0 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -5,6 +5,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho ## Bugfixes and miscellanous - Fixed the bug when deploying mindcontrolled vehicle into a building permanently trasferred the control to the house which mindcontrolled it. +- Fixed the bug when units are already dead but still in map (for sinking, crashing, dying animation, etc.), they could die again. - SHP debris shadows now respect the `Shadow` tag. - Allowed usage of TileSet of 255 and above without making NE-SW broken bridges unrepairable. - `TurretOffset` tag for voxel turreted technos now accepts FLH (forward, lateral, height) values like `TurretOffset=F,L` or `TurretOffset=F,L,H`, which means turret location can be adjusted in all three axes. diff --git a/docs/Whats-New.md b/docs/Whats-New.md index 34cb9248d9..056f863009 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -44,6 +44,7 @@ Vanilla fixes: - Tileset 255+ bridge fix (by E1 Elite) - Fixed fatal errors when `Blowfish.dll` couldn't be registered in the system properly due to missing admin rights (by Belonit) - Fix to take Burst into account for aircraft weapon shots beyond the first one (by Starkku) +- Fixed the bug when units are already dead but still in map (for sinking, crashing, dying animation, etc.), they could die again (by Uranusian) Phobos fixes: - Properly rewritten a fix for mind-controlled vehicles deploying into buildings (by FS-21) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 785e7a99b2..3abacce5ab 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -43,9 +43,9 @@ DEFINE_HOOK(5F53AA, ObjectClass_ReceiveDamage_DyingFix, 6) DEFINE_HOOK(4D7431, FootClass_ReceiveDamage_DyingFix, 5) { GET(FootClass*, pThis, ESI); - GET(DamageState, Result, EAX); + GET(DamageState, result, EAX); - if (Result != DamageState::PostMortem && (pThis->IsSinking || pThis->IsCrashing)) + if (result != DamageState::PostMortem && (pThis->IsSinking || pThis->IsCrashing)) R->EAX(DamageState::PostMortem); return 0; @@ -54,9 +54,9 @@ DEFINE_HOOK(4D7431, FootClass_ReceiveDamage_DyingFix, 5) DEFINE_HOOK(737D57, UnitClass_ReceiveDamage_DyingFix, 7) { GET(UnitClass*, pThis, ESI); - GET(DamageState, Result, EAX); + GET(DamageState, result, EAX); - if (Result != DamageState::PostMortem && pThis->DeathFrameCounter > 0) + if (result != DamageState::PostMortem && pThis->DeathFrameCounter > 0) R->EAX(DamageState::PostMortem); return 0;