From 6954b8659a6cd06f0246fbdb3164ef242bc8aeb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E6=98=9F=E5=A6=82=E6=A2=A6?= <851903106@qq.com> Date: Sat, 21 Sep 2024 15:16:00 +0800 Subject: [PATCH 1/2] Fix a small issue that phobos didn't handle. --- src/Ext/House/Body.cpp | 11 +++++++ src/Ext/House/Body.h | 2 ++ src/Ext/Techno/Hooks.Cloak.cpp | 55 ++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) diff --git a/src/Ext/House/Body.cpp b/src/Ext/House/Body.cpp index 67cf9d0c54..8380df5ac5 100644 --- a/src/Ext/House/Body.cpp +++ b/src/Ext/House/Body.cpp @@ -1076,3 +1076,14 @@ bool HouseExt::ReachedBuildLimit(const HouseClass* pHouse, const TechnoTypeClass return false; } #pragma endregion + +bool HouseExt::CanSelectOwner(HouseClass* pThis, HouseClass* pPlayer) +{ + if (!pThis || !pPlayer) + return false; + + return pThis == pPlayer || + pPlayer->IsCurrentPlayerObserver() || + (pThis->IsAlliedWith(pPlayer) && + pPlayer->IsAlliedWith(pThis)); +} diff --git a/src/Ext/House/Body.h b/src/Ext/House/Body.h index a872b10457..e18e4b8364 100644 --- a/src/Ext/House/Body.h +++ b/src/Ext/House/Body.h @@ -169,4 +169,6 @@ class HouseExt static CanBuildResult BuildLimitGroupCheck(const HouseClass* pThis, const TechnoTypeClass* pItem, bool buildLimitOnly, bool includeQueued); static bool ReachedBuildLimit(const HouseClass* pHouse, const TechnoTypeClass* pType, bool ignoreQueued); + + static bool CanSelectOwner(HouseClass* pThis, HouseClass* pPlayer); }; diff --git a/src/Ext/Techno/Hooks.Cloak.cpp b/src/Ext/Techno/Hooks.Cloak.cpp index da9d162950..3f0369b39b 100644 --- a/src/Ext/Techno/Hooks.Cloak.cpp +++ b/src/Ext/Techno/Hooks.Cloak.cpp @@ -1,4 +1,5 @@ #include "Body.h" +#include namespace CloakTemp { @@ -148,3 +149,57 @@ DEFINE_HOOK(0x4579A5, BuildingClass_ShouldNotCloak_Sensors, 0x6) return Continue; } + +// When a friendly unit goes cloaked, UIName can be displayed normally when hovering the mouse. +DEFINE_HOOK(0x4AE616, DisplayClass_GetToolTip_PlayControl, 0x6) +{ + GET(TechnoClass*, pThis, ECX); + enum { SkipGameCode = 0x4AE654 }; + + R->ESI(pThis); + + return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + SkipGameCode : 0; +} + +// When a friendly unit goes cloaked, the DrawExtra() function can be triggered normally on mouse hover. +DEFINE_HOOK(0x69252D, DisplayClass_ProcessClickCoords_PlayControl, 0x6) +{ + GET(TechnoClass*, pThis, ESI); + enum { SkipGameCode = 0x692585 }; + + return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + SkipGameCode : 0; +} + +// When a friendly unit goes cloaked, the mouse pointer will change. +DEFINE_HOOK(0x692686, DisplayClass_DecideAction_PlayControl, 0x6) +{ + GET(TechnoClass*, pThis, EDI); + enum { SkipGameCode = 0x6926DB }; + + return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + SkipGameCode : 0; +} + +// Block out Deselect() when a friendly unit goes cloakd. +DEFINE_HOOK(0x6F4F10, TechnoClass_Sensed_DisableDSelect, 0x5) +{ + GET(TechnoClass* const, pThis, ESI); + enum { SkipGameCode = 0x6F4F3A, Continue = 0x6F4F21 }; + + R->EAX(HouseClass::CurrentPlayer()); + + return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + SkipGameCode : 0; +} + +// Block out Deselect() when a friendly unit goes cloakd. +DEFINE_HOOK(0x703819, TechnoClass_Cloak_DisableDSelect, 0x6) +{ + GET(TechnoClass* const, pThis, ESI); + enum { SkipGameCode = 0x70383C, Continue = 0x703828 }; + + return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + SkipGameCode : 0; +} From cff6a5b9f0c7ca4deaacaecc9f7451c96667cadf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=9E=E6=98=9F=E5=A6=82=E6=A2=A6?= <851903106@qq.com> Date: Mon, 23 Sep 2024 22:17:37 +0800 Subject: [PATCH 2/2] revised again. is that right? --- CREDITS.md | 1 + docs/Fixed-or-Improved-Logics.md | 1 + docs/Whats-New.md | 1 + src/Ext/House/Body.cpp | 12 ++++++------ src/Ext/House/Body.h | 2 +- src/Ext/Techno/Hooks.Cloak.cpp | 18 +++++++++--------- 6 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CREDITS.md b/CREDITS.md index 4276f3739f..4b3b90e416 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -323,6 +323,7 @@ This page lists all the individual contributions to the project by their author. - **FlyStar** - Campaign load screen PCX support - New condition for automatic self-destruction logic when TechnoTypes exist/don't exist + - Fix for friendly units that have been cloaked not being able to be selected - **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 36f1338c3a..328f70d71f 100644 --- a/docs/Fixed-or-Improved-Logics.md +++ b/docs/Fixed-or-Improved-Logics.md @@ -169,6 +169,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho - Fixed `Temporal=true` Warheads potentially crashing game if used to attack `Slaved=true` infantry. - Fixed some locomotors (Tunnel, Walk, Mech) getting stuck when moving too fast. - Animations with `MakeInfantry` and `UseNormalLight=false` that are drawn in unit palette will now have cell lighting changes applied on them (by Starkku) +- Fix for friendly units that have been cloaked not being able to be selected. ## Fixes / interactions with other extensions diff --git a/docs/Whats-New.md b/docs/Whats-New.md index c2ba9e42e4..819259e529 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -569,6 +569,7 @@ Phobos fixes: - Fixed Phobos Warhead effects not reliably being applied on damage area as opposed to full weapon-based Warhead detonation (by Starkku) - Fix `LimboKill` not working reliably (by CrimRecya) - Fixed `SelfHealGainType=none` not working (changed to `noheal`) (by Starkku) +- Fix for friendly units that have been cloaked not being able to be selected (by Fly-Star) Fixes / interactions with other extensions: - `IsSimpleDeployer` units with Hover locomotor and `DeployToLand` no longer get stuck after deploying or play their move sound indefinitely (by Starkku) diff --git a/src/Ext/House/Body.cpp b/src/Ext/House/Body.cpp index 8380df5ac5..084c7d3859 100644 --- a/src/Ext/House/Body.cpp +++ b/src/Ext/House/Body.cpp @@ -1077,13 +1077,13 @@ bool HouseExt::ReachedBuildLimit(const HouseClass* pHouse, const TechnoTypeClass } #pragma endregion -bool HouseExt::CanSelectOwner(HouseClass* pThis, HouseClass* pPlayer) +bool HouseExt::CanBeSelectedBy(HouseClass* pOwner, HouseClass* pSelectingPlayer) { - if (!pThis || !pPlayer) + if (!pOwner || !pSelectingPlayer) return false; - return pThis == pPlayer || - pPlayer->IsCurrentPlayerObserver() || - (pThis->IsAlliedWith(pPlayer) && - pPlayer->IsAlliedWith(pThis)); + return pOwner == pSelectingPlayer || + pSelectingPlayer->IsCurrentPlayerObserver() || + (pOwner->IsAlliedWith(pSelectingPlayer) && + pSelectingPlayer->IsAlliedWith(pOwner)); } diff --git a/src/Ext/House/Body.h b/src/Ext/House/Body.h index e18e4b8364..3f77d4e6db 100644 --- a/src/Ext/House/Body.h +++ b/src/Ext/House/Body.h @@ -170,5 +170,5 @@ class HouseExt static CanBuildResult BuildLimitGroupCheck(const HouseClass* pThis, const TechnoTypeClass* pItem, bool buildLimitOnly, bool includeQueued); static bool ReachedBuildLimit(const HouseClass* pHouse, const TechnoTypeClass* pType, bool ignoreQueued); - static bool CanSelectOwner(HouseClass* pThis, HouseClass* pPlayer); + static bool CanBeSelectedBy(HouseClass* pOwner, HouseClass* pSelectingPlayer); }; diff --git a/src/Ext/Techno/Hooks.Cloak.cpp b/src/Ext/Techno/Hooks.Cloak.cpp index 3f0369b39b..4feb6e656a 100644 --- a/src/Ext/Techno/Hooks.Cloak.cpp +++ b/src/Ext/Techno/Hooks.Cloak.cpp @@ -158,7 +158,7 @@ DEFINE_HOOK(0x4AE616, DisplayClass_GetToolTip_PlayControl, 0x6) R->ESI(pThis); - return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + return HouseExt::CanBeSelectedBy(pThis->Owner, HouseClass::CurrentPlayer()) ? SkipGameCode : 0; } @@ -168,7 +168,7 @@ DEFINE_HOOK(0x69252D, DisplayClass_ProcessClickCoords_PlayControl, 0x6) GET(TechnoClass*, pThis, ESI); enum { SkipGameCode = 0x692585 }; - return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + return HouseExt::CanBeSelectedBy(pThis->Owner, HouseClass::CurrentPlayer()) ? SkipGameCode : 0; } @@ -178,28 +178,28 @@ DEFINE_HOOK(0x692686, DisplayClass_DecideAction_PlayControl, 0x6) GET(TechnoClass*, pThis, EDI); enum { SkipGameCode = 0x6926DB }; - return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + return HouseExt::CanBeSelectedBy(pThis->Owner, HouseClass::CurrentPlayer()) ? SkipGameCode : 0; } -// Block out Deselect() when a friendly unit goes cloakd. +// Do not forcibly deselect when a friendly unit goes cloaked. DEFINE_HOOK(0x6F4F10, TechnoClass_Sensed_DisableDSelect, 0x5) { GET(TechnoClass* const, pThis, ESI); - enum { SkipGameCode = 0x6F4F3A, Continue = 0x6F4F21 }; + enum { SkipGameCode = 0x6F4F3A }; R->EAX(HouseClass::CurrentPlayer()); - return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + return HouseExt::CanBeSelectedBy(pThis->Owner, HouseClass::CurrentPlayer()) ? SkipGameCode : 0; } -// Block out Deselect() when a friendly unit goes cloakd. +// Do not forcibly deselect when a friendly unit goes cloaked. DEFINE_HOOK(0x703819, TechnoClass_Cloak_DisableDSelect, 0x6) { GET(TechnoClass* const, pThis, ESI); - enum { SkipGameCode = 0x70383C, Continue = 0x703828 }; + enum { SkipGameCode = 0x70383C }; - return HouseExt::CanSelectOwner(pThis->Owner, HouseClass::CurrentPlayer()) ? + return HouseExt::CanBeSelectedBy(pThis->Owner, HouseClass::CurrentPlayer()) ? SkipGameCode : 0; }