Skip to content

Commit a1a18c0

Browse files
authored
[Minor] Try optimize TechnoClass_PointerGotInvalid_Airstrike (#1675)
1 parent a61143d commit a1a18c0

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

src/Ext/Techno/Body.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ void TechnoExt::ExtData::Serialize(T& Stm)
624624
;
625625
}
626626

627+
void TechnoExt::ExtData::InvalidatePointer(void* ptr, bool bRemoved)
628+
{
629+
AnnounceInvalidPointer(this->AirstrikeTargetingMe, ptr);
630+
}
631+
627632
void TechnoExt::ExtData::LoadFromStream(PhobosStreamReader& Stm)
628633
{
629634
Extension<TechnoClass>::LoadFromStream(Stm);

src/Ext/Techno/Body.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class TechnoExt
157157
UnitTypeClass* GetUnitTypeExtra() const;
158158

159159
virtual ~ExtData() override;
160-
virtual void InvalidatePointer(void* ptr, bool bRemoved) override { }
160+
virtual void InvalidatePointer(void* ptr, bool bRemoved) override;
161161
virtual void LoadFromStream(PhobosStreamReader& Stm) override;
162162
virtual void SaveToStream(PhobosStreamWriter& Stm) override;
163163

@@ -171,6 +171,19 @@ class TechnoExt
171171
public:
172172
ExtContainer();
173173
~ExtContainer();
174+
175+
virtual bool InvalidateExtDataIgnorable(void* const ptr) const override
176+
{
177+
auto const abs = static_cast<AbstractClass*>(ptr)->WhatAmI();
178+
179+
switch (abs)
180+
{
181+
case AbstractType::Airstrike:
182+
return false;
183+
default:
184+
return true;
185+
}
186+
}
174187
};
175188

176189
static ExtContainer ExtMap;

src/Ext/Techno/Hooks.Airstrike.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ DEFINE_HOOK(0x41D604, AirstrikeClass_PointerGotInvalid_ResetForTarget, 0x6)
134134

135135
GET(ObjectClass*, pTarget, EAX);
136136

137-
if (const auto pTargetTechnoExt = TechnoExt::ExtMap.Find(abstract_cast<TechnoClass*>(pTarget)))
137+
if (const auto pTargetTechnoExt = TechnoExt::ExtMap.Find(abstract_cast<TechnoClass*, true>(pTarget)))
138138
pTargetTechnoExt->AirstrikeTargetingMe = nullptr;
139139

140140
return SkipGameCode;
@@ -187,17 +187,6 @@ DEFINE_HOOK(0x51EAE0, TechnoClass_WhatAction_AllowAirstrike, 0x7)
187187
return Cannot;
188188
}
189189

190-
DEFINE_HOOK(0x70782D, TechnoClass_PointerGotInvalid_Airstrike, 0x6)
191-
{
192-
GET(AbstractClass*, pAbstract, EBP);
193-
GET(TechnoClass*, pThis, ESI);
194-
195-
if (const auto pExt = TechnoExt::ExtMap.Find(pThis)) // It's necessary
196-
AnnounceInvalidPointer(pExt->AirstrikeTargetingMe, pAbstract);
197-
198-
return 0;
199-
}
200-
201190
#pragma region GetEffectTintIntensity
202191

203192
DEFINE_HOOK(0x70E92F, TechnoClass_UpdateAirstrikeTint, 0x5)

0 commit comments

Comments
 (0)