From fc194108cf5061c88fe8c59da4b7e0e6387ab2e1 Mon Sep 17 00:00:00 2001 From: CrimRecya <335958461@qq.com> Date: Mon, 23 Feb 2026 12:08:53 +0800 Subject: [PATCH] Core --- src/Ext/Techno/Body.cpp | 6 +----- src/Misc/Hooks.BugFixes.cpp | 40 +++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/Ext/Techno/Body.cpp b/src/Ext/Techno/Body.cpp index ed4ebd3ce3..cfead9c0d3 100644 --- a/src/Ext/Techno/Body.cpp +++ b/src/Ext/Techno/Body.cpp @@ -329,10 +329,6 @@ bool TechnoExt::ConvertToType(FootClass* pThis, TechnoTypeClass* pToType) if (AresFunctions::ConvertTypeTo(pThis, pToType)) { - // Fixed an issue where morphing could result in -1 health. - const double ratio = static_cast(pToType->Strength) / pType->Strength; - pThis->Health = static_cast(oldHealth * ratio + 0.5); - auto const pTypeExt = TechnoExt::ExtMap.Find(pThis); pTypeExt->UpdateTypeData(pToType); pTypeExt->UpdateTypeData_Foot(); @@ -833,7 +829,7 @@ bool TechnoExt::SimpleDeployerAllowedToDeploy(UnitClass* pThis, bool defaultValu const bool isLander = pType->DeployToLand && (isJumpjet || isHover); disallowedLandTypes = isLander ? (LandTypeFlags)(LandTypeFlags::Water | LandTypeFlags::Beach) : LandTypeFlags::None; } - + if (IsLandTypeInFlags(disallowedLandTypes, pThis->GetCell()->LandType)) return false; diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 7daaf0d933..9c0f74b154 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -3077,3 +3077,43 @@ DEFINE_HOOK(0x6EA870, TeamClass_LiberateMember_Start, 0x6) pMember->RecruitableB = true; return 0; } + +#pragma region SetHealthPercentageFix + +DEFINE_HOOK(0x5F5C80, ObjectClass_SetHealthPercentage_Round, 0xA) +{ + enum { SkipGameCode = 0x5F5CBA }; + + GET(ObjectClass* const, pThis, ECX); + GET_STACK(const double, percentage, STACK_OFFSET(0x0, 0x4)); + + pThis->Health = (percentage <= 0.0) ? 0 : Math::max(1, Game::F2I(pThis->GetType()->Strength * percentage + 0.5)); + + return SkipGameCode; +} + +DEFINE_HOOK(0x44A010, BuildingClass_Mission_Selling_SetUnitHealthPercentage, 0xA) +{ + enum { SkipGameCode = 0x44A03C }; + + GET(UnitClass* const, pUnit, EBX); + GET_STACK(const double, percentage, STACK_OFFSET(0xD0, -0xAC)); + + pUnit->SetHealthPercentage(percentage); + pUnit->EstimatedHealth = pUnit->Health; + return SkipGameCode; +} + +DEFINE_HOOK(0x73992B, UnitClass_TryToDeploy_SetBuildingHealthPercentage, 0x7) +{ + enum { SkipGameCode = 0x739956 }; + + GET(const UnitClass* const, pThis, EBP); + GET(BuildingClass* const, pBuilding, EBX); + + pBuilding->SetHealthPercentage(pThis->GetHealthPercentage()); + pBuilding->EstimatedHealth = pBuilding->Health; + return SkipGameCode; +} + +#pragma endregion