diff --git a/CREDITS.md b/CREDITS.md index b04dd710cc..2aa1497cc1 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -398,6 +398,7 @@ This page lists all the individual contributions to the project by their author. - Fast access structure - Iron Curtain/Custom Tint Support for SHP Turreted Vehicles - Reactivate unused trigger events 2, 53, and 54 + - The target of death is excluded from automatic target selection - **NetsuNegi**: - Forbidding parallel AI queues by type - Jumpjet crash speed fix when crashing onto building diff --git a/docs/Fixed-or-Improved-Logics.md b/docs/Fixed-or-Improved-Logics.md index 5a61fb6e08..8c5efa4521 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -271,6 +271,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho - Reactivate unused trigger events 2, 53, and 54. - Fixed the bug that vehicle fall on infantry will make all cell content has been removed. - Fixed `MovementZone=Subterannean` harvesters being unable to find docks if in area enclosed by water, cliffs etc. +- The target of death is excluded from automatic target selection. ## Fixes / interactions with other extensions diff --git a/docs/Whats-New.md b/docs/Whats-New.md index bb745beab6..0f60e2970d 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -491,6 +491,7 @@ Vanilla fixes: - Fixed the bug that vehicle fall on infantry will make all cell content has been removed (by NetsuNegi) - Fixed buildings that have their owner changed during buildup skipping buildup and sometimes not correctly clearing the state (by Starkku) - Fixed `MovementZone=Subterannean` harvesters being unable to find docks if in area enclosed by water, cliffs etc. +- The target of death is excluded from automatic target selection (by FlyStar) Phobos fixes: - Fixed the bug that `AllowAirstrike=no` cannot completely prevent air strikes from being launched against it (by NetsuNegi) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 8b4bf8e4fe..6567d95628 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -2818,3 +2818,36 @@ DEFINE_HOOK(0x54CC9C, JumpjetLocomotionClass_ProcessCrashing_DropFix, 0x5) return fallOnSomething ? SkipGameCode2 : SkipGameCode; } + +#pragma region CanAutoTargetFix + +DEFINE_JUMP(LJMP, 0x6F7D88, 0x6F7DA9) // They should be placed at the front. + +DEFINE_HOOK_AGAIN(0x6F8B56, TechnoClass_CheckAutoTargetObject_OnMap, 0x5) // TechnoClass::TryAutoTargetObject +DEFINE_HOOK_AGAIN(0x6F9C89, TechnoClass_CheckAutoTargetObject_OnMap, 0x8) // TechnoClass::SelectAutoTargetObject_TechnoClass.Array +DEFINE_HOOK_AGAIN(0x6F9B9C, TechnoClass_CheckAutoTargetObject_OnMap, 0x8) // TechnoClass::SelectAutoTargetObject_AircraftClass.Array +DEFINE_HOOK(0x6F91F2, TechnoClass_CheckAutoTargetObject_OnMap, 0x9) // TechnoClass::SelectAutoTargetObject_AircraftTrackerClass +{ + const DWORD address = R->Origin(); + TechnoClass* const pTarget = (address == 0x6F91F2 || address == 0x6F8B56) ? + R->EBP() : R->EDI(); + + if (!pTarget->IsAlive || pTarget->Health <= 0 || pTarget->InLimbo) + { + switch (address) + { + case 0x6F91F2: + return 0x6F9377; + case 0x6F9B9C: + return 0x6F9C48; + case 0x6F8B56: + return 0x6F8C07; + default: + return 0x6F9D93; + } + } + + return 0; +} + +#pragma endregion