Skip to content

Commit 27e8735

Browse files
committed
Fix CanKill set health ignore AffectsXXX houses
1 parent af6b641 commit 27e8735

File tree

2 files changed

+32
-35
lines changed

2 files changed

+32
-35
lines changed

src/Ext/Techno/Hooks.ReceiveDamage.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,12 @@ DEFINE_HOOK(0x701900, TechnoClass_ReceiveDamage_Shield, 0x6)
125125
}
126126
}
127127

128-
if (pThis->Health > 0 && (!pWHExt->CanKill || pExt->AE.Unkillable) // Check if the warhead can not kill targets
129-
// Update remaining damage and check if the target will die and should be avoided
128+
if ((!pWHExt->CanKill || pExt->AE.Unkillable)
129+
&& pThis->Health > 0 && nDamageLeft != 0
130+
&& pWHExt->CanTargetHouse(pSourceHouse, pThis)
130131
&& MapClass::GetTotalDamage(nDamageLeft, args->WH, pThis->GetTechnoType()->Armor, args->DistanceToEpicenter) >= pThis->Health)
131132
{
133+
// Update remaining damage and check if the target will die and should be avoided
132134
*args->Damage = 0;
133135
pThis->Health = 1;
134136
pThis->EstimatedHealth = 1;

src/Misc/Hooks.BugFixes.cpp

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,125 +2056,120 @@ DEFINE_HOOK(0x4D6FE1, FootClass_ElectricAssultFix2, 0x7) // Mission_AreaGuard
20562056
#pragma endregion
20572057

20582058
#pragma region DamageAreaItemsFix
2059+
20592060
// Obviously, it is unreasonable for a large-scale damage like a nuke to only cause damage to units
20602061
// located on or under the bridge that are in the same position as the damage center point
20612062
namespace DamageAreaTemp
20622063
{
20632064
const CellClass* CheckingCell = nullptr;
20642065
bool CheckingCellAlt = false;
20652066
}
2067+
20662068
// Skip useless alt check, so it will only start checking from the cell's FirstObject
20672069
// Note: Ares hook at 0x489562(0x6) and return 0
20682070
DEFINE_JUMP(LJMP, 0x489568, 0x489592);
20692071

20702072
DEFINE_HOOK(0x4896BF, DamageArea_DamageItemsFix1, 0x6)
20712073
{
20722074
enum { CheckNextCell = 0x4899BE, CheckThisObject = 0x4896DD };
2073-
// Record the current cell for linked list getting
2075+
20742076
GET(const CellClass* const, pCell, EBX);
2077+
20752078
DamageAreaTemp::CheckingCell = pCell;
2076-
// First, check the FirstObject linked list
20772079
auto pObject = pCell->FirstObject;
2078-
// Check if there are objects in the linked list
2080+
20792081
if (pObject)
20802082
{
2081-
// When it exists, start the vanilla processing
20822083
R->ESI(pObject);
20832084
return CheckThisObject;
20842085
}
2085-
// When it does not exist, check AltObject linked list
2086+
20862087
pObject = pCell->AltObject;
2087-
// If there is also no object in the linked list, return directly to check the next cell
2088+
20882089
if (!pObject)
20892090
return CheckNextCell;
2090-
// If there is an object, record the flag
2091+
20912092
DamageAreaTemp::CheckingCellAlt = true;
2092-
// Then return and continue with the original execution
2093+
20932094
R->ESI(pObject);
20942095
return CheckThisObject;
20952096
}
20962097

20972098
DEFINE_HOOK(0x4899B3, DamageArea_DamageItemsFix2, 0x5)
20982099
{
20992100
enum { CheckNextCell = 0x4899BE, CheckThisObject = 0x4896DD };
2100-
// When there are no units in the FirstObject linked list, it will not enter this hook
2101+
21012102
GET(const ObjectClass*, pObject, ESI);
2102-
// As vanilla, first look at the next object in the linked list
2103+
21032104
pObject = pObject->NextObject;
2104-
// Check if there are still objects in the linked list
2105+
21052106
if (pObject)
21062107
{
2107-
// When it exists, return to continue the vanilla processing
21082108
R->ESI(pObject);
21092109
return CheckThisObject;
21102110
}
2111-
// When it does not exist, check which linked list it is currently in
2111+
21122112
if (DamageAreaTemp::CheckingCellAlt)
21132113
{
2114-
// If it is already in the AltObject linked list, reset the flag and return to check the next cell
21152114
DamageAreaTemp::CheckingCellAlt = false;
21162115
return CheckNextCell;
21172116
}
2118-
// If it is still in the FirstObject linked list, take the first object in the AltObject linked list and continue checking
2117+
21192118
pObject = DamageAreaTemp::CheckingCell->AltObject;
2120-
// If there is no object in the AltObject linked list, return directly to check the next cell
2119+
21212120
if (!pObject)
21222121
return CheckNextCell;
2123-
// If there is an object, record the flag
2122+
21242123
DamageAreaTemp::CheckingCellAlt = true;
2125-
// Then return and continue with the original execution
2124+
21262125
R->ESI(pObject);
21272126
return CheckThisObject;
21282127
}
21292128

21302129
DEFINE_HOOK(0x489BDB, DamageArea_RockerItemsFix1, 0x6)
21312130
{
21322131
enum { SkipGameCode = 0x489C29 };
2133-
// Get cell coordinates
2132+
21342133
GET(const short, cellX, ESI);
21352134
GET(const short, cellY, EBX);
2136-
// Record the current cell for linked list getting
2135+
21372136
const auto pCell = MapClass::Instance.GetCellAt(CellStruct { cellX, cellY });
21382137
DamageAreaTemp::CheckingCell = pCell;
2139-
// First, check the FirstObject linked list
21402138
auto pObject = pCell->FirstObject;
2141-
// Check if there are objects in the linked list
2139+
21422140
if (pObject)
21432141
{
2144-
// When it exists, start the vanilla processing
21452142
R->EAX(pObject);
21462143
return SkipGameCode;
21472144
}
2148-
// When it does not exist, check AltObject linked list
2145+
21492146
pObject = pCell->AltObject;
2150-
// If there is an object, record the flag
2147+
21512148
if (pObject)
21522149
DamageAreaTemp::CheckingCellAlt = true;
2153-
// Return the original check
2150+
21542151
R->EAX(pObject);
21552152
return SkipGameCode;
21562153
}
21572154

21582155
DEFINE_HOOK(0x489E47, DamageArea_RockerItemsFix2, 0x6)
21592156
{
2160-
// Prior to this, there was already pObject = pCell->FirstObject;
21612157
GET(const ObjectClass*, pObject, EDI);
2162-
// As vanilla, first look at the next object in the linked list
2158+
21632159
if (pObject)
21642160
return 0;
2165-
// When it does not exist, check which linked list it is currently in
2161+
21662162
if (DamageAreaTemp::CheckingCellAlt)
21672163
{
2168-
// If it is already in the AltObject linked list, reset the flag and return the original check
21692164
DamageAreaTemp::CheckingCellAlt = false;
21702165
return 0;
21712166
}
2172-
// If it is still in the FirstObject linked list, take the first object in the AltObject linked list and continue checking
2167+
21732168
pObject = DamageAreaTemp::CheckingCell->AltObject;
2174-
// If there is an object, record the flag
2169+
21752170
if (pObject)
21762171
DamageAreaTemp::CheckingCellAlt = true;
2177-
// Return the original check
2172+
21782173
R->EDI(pObject);
21792174
return 0;
21802175
}

0 commit comments

Comments
 (0)