Skip to content

Commit 57c6ef0

Browse files
committed
A couple of cloak-related fixes / additions
- Fix a regression in AE cloak code - Fix DecloakToFire=no not preventing decloaking when having a target in range - Move cloak-related code to its own file
1 parent 947ed42 commit 57c6ef0

File tree

7 files changed

+131
-102
lines changed

7 files changed

+131
-102
lines changed

Phobos.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</ProjectConfiguration>
1919
</ItemGroup>
2020
<ItemGroup>
21+
<ClCompile Include="src\Ext\Techno\Hooks.Cloak.cpp" />
2122
<ClCompile Include="src\New\Entity\AttachEffectClass.cpp" />
2223
<ClCompile Include="src\New\Type\AttachEffectTypeClass.cpp" />
2324
<ClCompile Include="src\Commands\Commands.cpp" />

docs/Fixed-or-Improved-Logics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
156156
- Tint effects are now correctly applied to SHP vehicles and all types of aircraft as well as building animations regardless of their position.
157157
- Iron Curtained / Force Shielded objects now always use the correct tint color.
158158
- Objects in invalid map coordinates are no longer used for starting view and AI base center calculations.
159+
- Units & buildings with `DecloakToFire=false` weapons can now cloak even while having a target in range.
159160

160161
## Fixes / interactions with other extensions
161162

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ Vanilla fixes:
469469
- Tint effects are now correctly applied to SHP vehicles and all types of aircraft as well as building animations regardless of their position (by Starkku)
470470
- Iron Curtained / Force Shielded objects now always use the correct tint color (by Starkku)
471471
- Objects in invalid map coordinates are no longer used for starting view and AI base center calculations (by Starkku)
472+
- Units & buildings with `DecloakToFire=false` weapons can now cloak even while having a target in range (by Starkku)
472473
473474
Phobos fixes:
474475
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)

src/Ext/Techno/Body.Update.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ void TechnoExt::ExtData::RecalculateStatMultipliers()
859859
double armor = 1.0;
860860
double speed = 1.0;
861861
double ROF = 1.0;
862-
bool cloak = pThis->Cloakable;
862+
bool cloak = false;
863863
bool forceDecloak = false;
864864
bool disableWeapons = false;
865865

@@ -882,11 +882,10 @@ void TechnoExt::ExtData::RecalculateStatMultipliers()
882882
this->AE_ArmorMultiplier = armor;
883883
this->AE_SpeedMultiplier = speed;
884884
this->AE_ROFMultiplier = ROF;
885-
pThis->Cloakable = cloak;
885+
this->AE_Cloakable = cloak;
886886
this->AE_ForceDecloak = forceDecloak;
887887
this->AE_DisableWeapons = disableWeapons;
888888

889889
if (forceDecloak && pThis->CloakState == CloakState::Cloaked)
890890
pThis->Uncloak(true);
891891
}
892-

src/Ext/Techno/Hooks.AttachEffect.cpp

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -38,72 +38,6 @@ DEFINE_HOOK(0x6FE352, TechnoClass_FirepowerMultiplier, 0x8) // TechnoClass
3838
return 0;
3939
}
4040

41-
bool __fastcall TechnoClass_IsReadyToCloak_Wrapper(TechnoClass* pThis)
42-
{
43-
bool cloak = pThis->Cloakable;
44-
TechnoExt::ExtData* pExt = nullptr;
45-
46-
if (!pThis->Cloakable)
47-
{
48-
pExt = TechnoExt::ExtMap.Find(pThis);
49-
pThis->Cloakable = pExt->AE_Cloakable;
50-
}
51-
52-
bool retVal = pThis->TechnoClass::IsReadyToCloak();
53-
pThis->Cloakable = cloak;
54-
55-
if (retVal)
56-
{
57-
if (!pExt)
58-
pExt = TechnoExt::ExtMap.Find(pThis);
59-
60-
if (pExt->AE_ForceDecloak)
61-
return false;
62-
}
63-
64-
return retVal;
65-
}
66-
67-
bool __fastcall TechnoClass_ShouldNotCloak_Wrapper(TechnoClass* pThis)
68-
{
69-
bool cloak = pThis->Cloakable;
70-
TechnoExt::ExtData* pExt = nullptr;
71-
72-
if (!pThis->Cloakable)
73-
{
74-
pExt = TechnoExt::ExtMap.Find(pThis);
75-
pThis->Cloakable = pExt->AE_Cloakable;
76-
}
77-
78-
bool retVal = pThis->TechnoClass::ShouldNotBeCloaked();
79-
pThis->Cloakable = cloak;
80-
81-
if (retVal)
82-
{
83-
if (!pExt)
84-
pExt = TechnoExt::ExtMap.Find(pThis);
85-
86-
if (pExt->AE_ForceDecloak)
87-
return true;
88-
}
89-
90-
return retVal;
91-
}
92-
93-
DEFINE_JUMP(VTABLE, 0x7E2544, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // AircraftClass
94-
DEFINE_JUMP(VTABLE, 0x7E8F34, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // FootClass
95-
DEFINE_JUMP(VTABLE, 0x7EB2F8, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // InfantryClass
96-
DEFINE_JUMP(VTABLE, 0x7F4C00, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // TechnoClass
97-
DEFINE_JUMP(VTABLE, 0x7F5F10, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // UnitClass
98-
DEFINE_JUMP(CALL, 0x457779, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)) // BuildingClass
99-
100-
DEFINE_JUMP(VTABLE, 0x7E2548, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // AircraftClass
101-
DEFINE_JUMP(VTABLE, 0x7E8F38, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // FootClass
102-
DEFINE_JUMP(VTABLE, 0x7EB2FC, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // InfantryClass
103-
DEFINE_JUMP(VTABLE, 0x7F4C04, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // TechnoClass
104-
DEFINE_JUMP(VTABLE, 0x7F5F14, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // UnitClass
105-
DEFINE_JUMP(CALL, 0x4578C9, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // BuildingClass
106-
10741
bool __fastcall TechnoClass_Limbo_Wrapper(TechnoClass* pThis)
10842
{
10943
auto const pExt = TechnoExt::ExtMap.Find(pThis);

src/Ext/Techno/Hooks.Cloak.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#include "Body.h"
2+
3+
namespace CloakTemp
4+
{
5+
bool IsInReadyToCloak = false;
6+
}
7+
8+
bool __fastcall TechnoClass_IsReadyToCloak_Wrapper(TechnoClass* pThis)
9+
{
10+
bool cloak = pThis->Cloakable;
11+
TechnoExt::ExtData* pExt = nullptr;
12+
13+
if (!pThis->Cloakable)
14+
{
15+
pExt = TechnoExt::ExtMap.Find(pThis);
16+
pThis->Cloakable = pExt->AE_Cloakable;
17+
}
18+
19+
CloakTemp::IsInReadyToCloak = true;
20+
bool retVal = pThis->TechnoClass::IsReadyToCloak();
21+
CloakTemp::IsInReadyToCloak = false;
22+
pThis->Cloakable = cloak;
23+
24+
if (retVal)
25+
{
26+
if (!pExt)
27+
pExt = TechnoExt::ExtMap.Find(pThis);
28+
29+
if (pExt->AE_ForceDecloak)
30+
return false;
31+
}
32+
33+
return retVal;
34+
}
35+
36+
bool __fastcall TechnoClass_ShouldNotCloak_Wrapper(TechnoClass* pThis)
37+
{
38+
bool cloak = pThis->Cloakable;
39+
TechnoExt::ExtData* pExt = nullptr;
40+
41+
if (!pThis->Cloakable)
42+
{
43+
pExt = TechnoExt::ExtMap.Find(pThis);
44+
pThis->Cloakable = pExt->AE_Cloakable;
45+
}
46+
47+
bool retVal = pThis->TechnoClass::ShouldNotBeCloaked();
48+
pThis->Cloakable = cloak;
49+
50+
if (!retVal)
51+
{
52+
if (!pExt)
53+
pExt = TechnoExt::ExtMap.Find(pThis);
54+
55+
if (pExt->AE_ForceDecloak)
56+
return true;
57+
}
58+
59+
return retVal;
60+
}
61+
62+
// Replaces the vanilla vtable calls & calls function from wrapper to retain compatibility with Ares.
63+
// The vanilla functions are completely overwritten by Ares.
64+
DEFINE_JUMP(VTABLE, 0x7E2544, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // AircraftClass
65+
DEFINE_JUMP(VTABLE, 0x7E8F34, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // FootClass
66+
DEFINE_JUMP(VTABLE, 0x7EB2F8, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // InfantryClass
67+
DEFINE_JUMP(VTABLE, 0x7F4C00, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // TechnoClass
68+
DEFINE_JUMP(VTABLE, 0x7F5F10, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)); // UnitClass
69+
DEFINE_JUMP(CALL, 0x457779, GET_OFFSET(TechnoClass_IsReadyToCloak_Wrapper)) // BuildingClass
70+
71+
DEFINE_JUMP(VTABLE, 0x7E2548, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // AircraftClass
72+
DEFINE_JUMP(VTABLE, 0x7E8F38, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // FootClass
73+
DEFINE_JUMP(VTABLE, 0x7EB2FC, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // InfantryClass
74+
DEFINE_JUMP(VTABLE, 0x7F4C04, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // TechnoClass
75+
DEFINE_JUMP(VTABLE, 0x7F5F14, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // UnitClass
76+
DEFINE_JUMP(CALL, 0x4578C9, GET_OFFSET(TechnoClass_ShouldNotCloak_Wrapper)); // BuildingClass
77+
78+
// Allow units with DecloakToFire=no weapons to cloak even when about to fire on target.
79+
DEFINE_HOOK(0x6F7792, TechnoClass_InWeaponRange_DecloakToFire, 0xA)
80+
{
81+
enum { SkipGameCode = 0x6F779C };
82+
83+
GET(TechnoClass*, pThis, ESI);
84+
GET(AbstractClass*, pTarget, EBX);
85+
GET(int, weaponIndex, EAX);
86+
87+
if (CloakTemp::IsInReadyToCloak && !pThis->GetWeapon(weaponIndex)->WeaponType->DecloakToFire)
88+
R->EAX(0);
89+
else
90+
R->EAX(pThis->IsCloseEnough(pTarget, weaponIndex));
91+
92+
return SkipGameCode;
93+
}
94+
95+
DEFINE_HOOK_AGAIN(0x703789, TechnoClass_CloakUpdateMCAnim, 0x6) // TechnoClass_Do_Cloak
96+
DEFINE_HOOK(0x6FB9D7, TechnoClass_CloakUpdateMCAnim, 0x6) // TechnoClass_Cloaking_AI
97+
{
98+
GET(TechnoClass*, pThis, ESI);
99+
100+
if (const auto pExt = TechnoExt::ExtMap.Find(pThis))
101+
pExt->UpdateMindControlAnim();
102+
103+
return 0;
104+
}
105+
106+
DEFINE_HOOK(0x703A09, TechnoClass_VisualCharacter_CloakVisibility, 0x7)
107+
{
108+
enum { UseShadowyVisual = 0x703A5A, CheckMutualAlliance = 0x703A16 };
109+
110+
// Allow observers to always see cloaked objects.
111+
// Skip IsCampaign check (confirmed being useless from Mental Omega mappers)
112+
if (HouseClass::IsCurrentPlayerObserver())
113+
return UseShadowyVisual;
114+
115+
return CheckMutualAlliance;
116+
}
117+
118+
DEFINE_HOOK(0x45455B, BuildingClass_VisualCharacter_CloakVisibility, 0x5)
119+
{
120+
enum { UseShadowyVisual = 0x45452D, CheckMutualAlliance = 0x454564 };
121+
122+
if (HouseClass::IsCurrentPlayerObserver())
123+
return UseShadowyVisual;
124+
125+
return CheckMutualAlliance;
126+
}

src/Ext/Techno/Hooks.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -269,39 +269,6 @@ DEFINE_HOOK(0x4D7221, FootClass_Unlimbo_LaserTrails, 0x6)
269269
return 0;
270270
}
271271

272-
DEFINE_HOOK_AGAIN(0x703789, TechnoClass_CloakUpdateMCAnim, 0x6) // TechnoClass_Do_Cloak
273-
DEFINE_HOOK(0x6FB9D7, TechnoClass_CloakUpdateMCAnim, 0x6) // TechnoClass_Cloaking_AI
274-
{
275-
GET(TechnoClass*, pThis, ESI);
276-
277-
if (const auto pExt = TechnoExt::ExtMap.Find(pThis))
278-
pExt->UpdateMindControlAnim();
279-
280-
return 0;
281-
}
282-
283-
DEFINE_HOOK(0x703A09, TechnoClass_VisualCharacter_CloakVisibility, 0x7)
284-
{
285-
enum { UseShadowyVisual = 0x703A5A, CheckMutualAlliance = 0x703A16 };
286-
287-
// Allow observers to always see cloaked objects.
288-
// Skip IsCampaign check (confirmed being useless from Mental Omega mappers)
289-
if (HouseClass::IsCurrentPlayerObserver())
290-
return UseShadowyVisual;
291-
292-
return CheckMutualAlliance;
293-
}
294-
295-
DEFINE_HOOK(0x45455B, BuildingClass_VisualCharacter_CloakVisibility, 0x5)
296-
{
297-
enum { UseShadowyVisual = 0x45452D, CheckMutualAlliance = 0x454564 };
298-
299-
if (HouseClass::IsCurrentPlayerObserver())
300-
return UseShadowyVisual;
301-
302-
return CheckMutualAlliance;
303-
}
304-
305272
DEFINE_HOOK(0x4DEAEE, FootClass_IronCurtain_Organics, 0x6)
306273
{
307274
GET(FootClass*, pThis, ESI);

0 commit comments

Comments
 (0)