From ef931915b4910a4d8884d8dc06a6a36b9d6e51f6 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Sun, 30 Jan 2022 15:57:12 +0100 Subject: [PATCH 1/2] Lasertrails fixes when units enter/leave transports --- src/Ext/Techno/Hooks.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index 5879d32e7b..c843d97998 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -344,3 +344,46 @@ DEFINE_HOOK(0x73DE90, UnitClass_SimpleDeployer_TransferLaserTrails, 0x6) return 0; } + +DEFINE_HOOK(0x71067B, TechnoClass_EnterTransport_LaserTrails, 0x7) +{ + GET(TechnoClass*, pTechno, EDI); + + auto pTechnoExt = TechnoExt::ExtMap.Find(pTechno); + auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pTechno->GetTechnoType()); + + if (pTechnoExt && pTechnoTypeExt) + { + if (pTechnoExt->LaserTrails.size()) + pTechnoExt->LaserTrails.clear(); + } + + return 0; +} + +DEFINE_HOOK(0x5F4F4E, ObjectClass_Unlimbo_LaserTrails, 0x7) +{ + GET(TechnoClass*, pTechno, ECX); + + auto pTechnoExt = TechnoExt::ExtMap.Find(pTechno); + if (pTechnoExt) + { + if (pTechnoExt->LaserTrails.size()) + pTechnoExt->LaserTrails.clear(); + + auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pTechno->GetTechnoType()); + if (pTechnoTypeExt && pTechnoTypeExt->LaserTrailData.size() > 0) + { + for (auto const& entry : pTechnoTypeExt->LaserTrailData) + { + if (auto const pLaserType = LaserTrailTypeClass::Array[entry.idxType].get()) + { + pTechnoExt->LaserTrails.push_back(std::make_unique( + pLaserType, pTechno->Owner, entry.FLH, entry.IsOnTurret)); + } + } + } + } + + return 0; +} From bc7d051c231559d1e27e32b662812881889d0c17 Mon Sep 17 00:00:00 2001 From: FS-21 Date: Thu, 3 Feb 2022 18:29:06 +0100 Subject: [PATCH 2/2] reworked code --- src/Ext/Techno/Hooks.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Ext/Techno/Hooks.cpp b/src/Ext/Techno/Hooks.cpp index c843d97998..582f7d3b0b 100644 --- a/src/Ext/Techno/Hooks.cpp +++ b/src/Ext/Techno/Hooks.cpp @@ -354,8 +354,11 @@ DEFINE_HOOK(0x71067B, TechnoClass_EnterTransport_LaserTrails, 0x7) if (pTechnoExt && pTechnoTypeExt) { - if (pTechnoExt->LaserTrails.size()) - pTechnoExt->LaserTrails.clear(); + for (auto &pLaserTrail : pTechnoExt->LaserTrails) + { + pLaserTrail->Visible = false; + pLaserTrail->LastLocation = { }; + } } return 0; @@ -368,20 +371,10 @@ DEFINE_HOOK(0x5F4F4E, ObjectClass_Unlimbo_LaserTrails, 0x7) auto pTechnoExt = TechnoExt::ExtMap.Find(pTechno); if (pTechnoExt) { - if (pTechnoExt->LaserTrails.size()) - pTechnoExt->LaserTrails.clear(); - - auto pTechnoTypeExt = TechnoTypeExt::ExtMap.Find(pTechno->GetTechnoType()); - if (pTechnoTypeExt && pTechnoTypeExt->LaserTrailData.size() > 0) + for (auto &pLaserTrail : pTechnoExt->LaserTrails) { - for (auto const& entry : pTechnoTypeExt->LaserTrailData) - { - if (auto const pLaserType = LaserTrailTypeClass::Array[entry.idxType].get()) - { - pTechnoExt->LaserTrails.push_back(std::make_unique( - pLaserType, pTechno->Owner, entry.FLH, entry.IsOnTurret)); - } - } + pLaserTrail->LastLocation = { }; + pLaserTrail->Visible = true; } }