Skip to content

Commit 4c71c94

Browse files
committed
Fix issue that can cause crashes if FeedbackWeapon converts firer
- Also consolidated some hooks, there's additional one that could be merged but it requires more work due to use of temp variables within different file
1 parent 6335eaf commit 4c71c94

File tree

3 files changed

+52
-46
lines changed

3 files changed

+52
-46
lines changed

docs/Whats-New.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ Phobos fixes:
325325
- Fixed an issue with `UndeploysInto.Sellable` (by TaranDahl)
326326
- Fixed an issue with `Powered`/`PoweredSpecial` building animation ownership change fix (by Trsdy)
327327
- Fixed `DisplayIncome`, `Transact.Money` etc. display strings showing through shroud and for objects that are supposed to be hidden such as cloaked, undetected enemies (by Starkku)
328+
- Fixed an issue that could cause crashes when `FeedbackWeapon` was used to convert the firer to another TechnoType with less or no weapons (by Starkku)
328329
```
329330

330331
### 0.4

src/Ext/Techno/Hooks.Firing.cpp

Lines changed: 51 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -549,15 +549,35 @@ DEFINE_HOOK(0x6FF905, TechnoClass_FireAt_FireOnce, 0x6)
549549
return 0;
550550
}
551551

552-
DEFINE_HOOK(0x6FF660, TechnoClass_FireAt_Interceptor, 0x6)
552+
static inline void ToggleLaserWeaponIndex(TechnoClass* pThis, WeaponTypeClass* pWeapon, int weaponIndex)
553553
{
554-
GET(TechnoClass* const, pSource, ESI);
554+
if (pWeapon->IsLaser)
555+
{
556+
if (auto const pBuilding = abstract_cast<BuildingClass*>(pThis))
557+
{
558+
auto const pExt = BuildingExt::ExtMap.Find(pBuilding);
559+
560+
if (!pExt->CurrentLaserWeaponIndex.has_value())
561+
pExt->CurrentLaserWeaponIndex = weaponIndex;
562+
else
563+
pExt->CurrentLaserWeaponIndex.reset();
564+
}
565+
}
566+
}
567+
568+
DEFINE_HOOK(0x6FF660, TechnoClass_FireAt_LateLogic, 0x6)
569+
{
570+
GET(TechnoClass* const, pThis, ESI);
555571
GET_BASE(AbstractClass* const, pTarget, 0x8);
556572
GET_STACK(BulletClass* const, pBullet, STACK_OFFSET(0xB0, -0x74));
573+
GET(WeaponTypeClass* const, pWeapon, EBX);
574+
GET_BASE(const int, weaponIndex, 0xC);
557575

558-
const auto pSourceTypeExt = TechnoExt::ExtMap.Find(pSource)->TypeExtData;
576+
auto const pExt = TechnoExt::ExtMap.Find(pThis);
577+
const auto pTypeExt = pExt->TypeExtData;
559578

560-
if (const auto pInterceptorType = pSourceTypeExt->InterceptorType.get())
579+
// Interceptor.
580+
if (const auto pInterceptorType = pTypeExt->InterceptorType.get())
561581
{
562582
if (const auto pTargetBullet = abstract_cast<BulletClass*, true>(pTarget))
563583
{
@@ -568,35 +588,50 @@ DEFINE_HOOK(0x6FF660, TechnoClass_FireAt_Interceptor, 0x6)
568588

569589
const auto pBulletExt = BulletExt::ExtMap.Find(pBullet);
570590

571-
pBulletExt->InterceptorTechnoType = pSourceTypeExt;
591+
pBulletExt->InterceptorTechnoType = pTypeExt;
572592
pBulletExt->InterceptedStatus |= InterceptedStatus::Targeted;
573593
}
574594
}
575595

596+
// Laser weapon index toggle.
597+
ToggleLaserWeaponIndex(pThis, pWeapon, weaponIndex);
598+
599+
// Increment burst index, reset if needed.
600+
++pThis->CurrentBurstIndex;
601+
pThis->CurrentBurstIndex %= pWeapon->Burst;
602+
603+
// Force full rearm delay and reset burst index.
604+
if (pExt->ForceFullRearmDelay)
605+
{
606+
pExt->ForceFullRearmDelay = false;
607+
pThis->CurrentBurstIndex = 0;
608+
}
609+
576610
return 0;
577611
}
578612

579-
DEFINE_HOOK_AGAIN(0x6FF660, TechnoClass_FireAt_ToggleLaserWeaponIndex, 0x6)
580613
DEFINE_HOOK(0x6FF4CC, TechnoClass_FireAt_ToggleLaserWeaponIndex, 0x6)
581614
{
582615
GET(TechnoClass* const, pThis, ESI);
583616
GET(WeaponTypeClass* const, pWeapon, EBX);
584617
GET_BASE(int, weaponIndex, 0xC);
585618

586-
if (pWeapon->IsLaser)
587-
{
588-
if (auto const pExt = BuildingExt::ExtMap.Find(abstract_cast<BuildingClass*, true>(pThis)))
589-
{
590-
if (!pExt->CurrentLaserWeaponIndex.has_value())
591-
pExt->CurrentLaserWeaponIndex = weaponIndex;
592-
else
593-
pExt->CurrentLaserWeaponIndex.reset();
594-
}
595-
}
619+
ToggleLaserWeaponIndex(pThis, pWeapon, weaponIndex);
596620

597621
return 0;
598622
}
599623

624+
// Issue #46: Laser is mirrored relative to FireFLH
625+
// Author: Starkku
626+
DEFINE_HOOK(0x6FF2BE, TechnoClass_FireAt_BurstOffsetFix, 0x6)
627+
{
628+
GET(TechnoClass*, pThis, ESI);
629+
630+
--pThis->CurrentBurstIndex; // Restored in TechnoClass_FireAt_LateLogic hook.
631+
632+
return 0x6FF2D1;
633+
}
634+
600635
static inline void SetChargeTurretDelay(TechnoClass* pThis, int rearmDelay, WeaponTypeClass* pWeapon)
601636
{
602637
pThis->ChargeTurretDelay = rearmDelay;

src/Misc/Hooks.BugFixes.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,36 +223,6 @@ DEFINE_HOOK(0x4FB2DE, HouseClass_PlaceObject_HotkeyFix, 0x6)
223223
return 0;
224224
}
225225

226-
// Issue #46: Laser is mirrored relative to FireFLH
227-
// Author: Starkku
228-
DEFINE_HOOK(0x6FF2BE, TechnoClass_FireAt_BurstOffsetFix_1, 0x6)
229-
{
230-
GET(TechnoClass*, pThis, ESI);
231-
232-
--pThis->CurrentBurstIndex;
233-
234-
return 0x6FF2D1;
235-
}
236-
237-
DEFINE_HOOK(0x6FF660, TechnoClass_FireAt_BurstOffsetFix_2, 0x6)
238-
{
239-
GET(TechnoClass*, pThis, ESI);
240-
GET_BASE(int, weaponIndex, 0xC);
241-
242-
++pThis->CurrentBurstIndex;
243-
pThis->CurrentBurstIndex %= pThis->GetWeapon(weaponIndex)->WeaponType->Burst;
244-
245-
auto const pExt = TechnoExt::ExtMap.Find(pThis);
246-
247-
if (pExt->ForceFullRearmDelay)
248-
{
249-
pExt->ForceFullRearmDelay = false;
250-
pThis->CurrentBurstIndex = 0;
251-
}
252-
253-
return 0;
254-
}
255-
256226
// issue #290: Undeploy building into a unit plays EVA_NewRallyPointEstablished
257227
// Author: secsome
258228
DEFINE_HOOK(0x44377E, BuildingClass_ActiveClickWith, 0x6)

0 commit comments

Comments
 (0)