From 85d3d221fabf4f534883bbae3deb0430fc30681e Mon Sep 17 00:00:00 2001 From: TaranDahl Date: Sat, 21 Dec 2024 10:46:18 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=8A=A8a?= =?UTF-8?q?=E5=A2=99=E7=BB=8F=E5=B8=B8=E5=81=9C=E4=B8=8D=E4=B8=8B=E6=9D=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ext/Techno/Body.Update.cpp | 9 +++++++++ src/Ext/Techno/Body.cpp | 1 + src/Ext/Techno/Body.h | 2 ++ src/Ext/Techno/Hooks.Others.cpp | 13 +++++++++++++ 4 files changed, 25 insertions(+) diff --git a/src/Ext/Techno/Body.Update.cpp b/src/Ext/Techno/Body.Update.cpp index 9c102ab4a7..8d2ca6ffac 100644 --- a/src/Ext/Techno/Body.Update.cpp +++ b/src/Ext/Techno/Body.Update.cpp @@ -51,6 +51,15 @@ void TechnoExt::ExtData::OnEarlyUpdate() if (this->AttackMoveFollowerTempCount) this->AttackMoveFollowerTempCount--; + + if (auto pCell = this->AutoTargetedWallCell) + { + if (pCell->OverlayTypeIndex == -1) + { + this->OwnerObject()->SetTarget(nullptr); + this->AutoTargetedWallCell = nullptr; + } + } } void TechnoExt::ExtData::ApplyInterceptor() diff --git a/src/Ext/Techno/Body.cpp b/src/Ext/Techno/Body.cpp index a853c8f514..175bb3f7a3 100644 --- a/src/Ext/Techno/Body.cpp +++ b/src/Ext/Techno/Body.cpp @@ -523,6 +523,7 @@ void TechnoExt::ExtData::Serialize(T& Stm) .Process(this->ShouldUpdateGattlingValue) .Process(this->MyTargetingFrame) .Process(this->AttackMoveFollowerTempCount) + .Process(this->AutoTargetedWallCell) .Process(this->FiringObstacleCell) .Process(this->KeepTargetOnMove) .Process(this->IsDetachingForCloak) diff --git a/src/Ext/Techno/Body.h b/src/Ext/Techno/Body.h index 23a0fedf19..42ba8ee24c 100644 --- a/src/Ext/Techno/Body.h +++ b/src/Ext/Techno/Body.h @@ -63,6 +63,7 @@ class TechnoExt bool ShouldUpdateGattlingValue; int MyTargetingFrame; int AttackMoveFollowerTempCount; + CellClass* AutoTargetedWallCell; CellClass* FiringObstacleCell; // Set on firing if there is an obstacle cell between target and techno, used for updating WaveClass target etc. bool KeepTargetOnMove; bool IsDetachingForCloak; // Used for checking animation detaching, set to true before calling Detach_All() on techno when this anim is attached to and to false after when cloaking only. @@ -115,6 +116,7 @@ class TechnoExt , ShouldUpdateGattlingValue { false } , MyTargetingFrame { ScenarioClass::Instance->Random.RandomRanged(0,15) } , AttackMoveFollowerTempCount { 0 } + , AutoTargetedWallCell{ nullptr } , FiringObstacleCell {} , KeepTargetOnMove { false } , IsDetachingForCloak { false } diff --git a/src/Ext/Techno/Hooks.Others.cpp b/src/Ext/Techno/Hooks.Others.cpp index cfb05baef2..51abc2cd99 100644 --- a/src/Ext/Techno/Hooks.Others.cpp +++ b/src/Ext/Techno/Hooks.Others.cpp @@ -1197,6 +1197,19 @@ DEFINE_HOOK(0x6F8D32, TechnoClass_ScanToAttackWall_DestroyOwnerlessWalls, 0x9) return GoOtherChecks; } +DEFINE_HOOK(0x6F9B64, TechnoClass_SelectAutoTarget_RecordAttackWall, 0x7) +{ + GET(TechnoClass*, pThis, ESI); + GET(CellClass*, pCell, EAX); + + if (auto pExt = TechnoExt::ExtMap.Find(pThis)) + { + pExt->AutoTargetedWallCell = pCell; + } + + return 0; +} + #pragma endregion #pragma region CylinderRange From 78f195544b3113bfb7fbf31a279a1c3e4e795aee Mon Sep 17 00:00:00 2001 From: TaranDahl Date: Sat, 21 Dec 2024 10:47:03 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8DJJ=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E4=B8=AD=E8=8E=B7=E5=8F=96=E5=88=B0=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E6=97=B6=E6=9C=89=E6=97=B6=E4=BC=9A=E5=A4=B1=E5=8E=BB?= =?UTF-8?q?megamission=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Misc/Hooks.BugFixes.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 6e6f7c3671..2dcdc47ada 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -979,11 +979,17 @@ DEFINE_HOOK(0x51AB5C, InfantryClass_SetDestination_JJInfFix, 0x6) GET(InfantryClass* const, pThis, EBP); GET(AbstractClass* const, pDest, EBX); - if (pThis->Type->BalloonHover && !pDest && pThis->Destination && locomotion_cast(pThis->Locomotor) && pThis->Target) + auto pJumpjetLoco = locomotion_cast(pThis->Locomotor); + + if (pThis->Type->BalloonHover && !pDest && pThis->Destination && pJumpjetLoco && pThis->Target) { if (pThis->IsCloseEnoughToAttack(pThis->Target)) { - pThis->StopMoving(); + auto crd = pThis->GetCoords(); + pJumpjetLoco->DestinationCoords.X = crd.X; + pJumpjetLoco->DestinationCoords.Y = crd.Y; + pJumpjetLoco->CurrentSpeed = 0; + pJumpjetLoco->MaxSpeed = 0; pThis->AbortMotion(); } From 74f6702b7fe281c7f51c02881e9c8c50927a28ac Mon Sep 17 00:00:00 2001 From: TaranDahl Date: Sat, 21 Dec 2024 11:48:36 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=BD=BD=E5=85=B7=E7=9A=84=E5=BF=98?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Misc/Hooks.BugFixes.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Misc/Hooks.BugFixes.cpp b/src/Misc/Hooks.BugFixes.cpp index 2dcdc47ada..dd33a8a630 100644 --- a/src/Misc/Hooks.BugFixes.cpp +++ b/src/Misc/Hooks.BugFixes.cpp @@ -1000,13 +1000,20 @@ DEFINE_HOOK(0x51AB5C, InfantryClass_SetDestination_JJInfFix, 0x6) return 0; } +// For vehicles. If in range, then stop. DEFINE_HOOK(0x741A66, UnitClass_SetDestination_JJVehFix, 0x5) { GET(UnitClass* const, pThis, EBP); - if (pThis->IsCloseEnoughToAttack(pThis->Target)) + auto pJumpjetLoco = locomotion_cast(pThis->Locomotor); + + if (pThis->IsCloseEnough(pThis->Target, pThis->SelectWeapon(pThis->Target)) && pJumpjetLoco) { - pThis->StopMoving(); + auto crd = pThis->GetCoords(); + pJumpjetLoco->DestinationCoords.X = crd.X; + pJumpjetLoco->DestinationCoords.Y = crd.Y; + pJumpjetLoco->CurrentSpeed = 0; + pJumpjetLoco->MaxSpeed = 0; pThis->AbortMotion(); } From 1c0cd4a270249c81c43a755dc74bfcf58141e2e4 Mon Sep 17 00:00:00 2001 From: TaranDahl Date: Sun, 22 Dec 2024 19:33:31 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=9B=86=E7=BB=93=E7=82=B9=E5=AF=BB?= =?UTF-8?q?=E8=B7=AF=E5=A2=9E=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Ext/BuildingType/Body.cpp | 4 ++++ src/Ext/BuildingType/Body.h | 4 ++++ src/Ext/Techno/Hooks.Others.cpp | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/Ext/BuildingType/Body.cpp b/src/Ext/BuildingType/Body.cpp index 6896a83fbe..f54d21ab41 100644 --- a/src/Ext/BuildingType/Body.cpp +++ b/src/Ext/BuildingType/Body.cpp @@ -865,6 +865,8 @@ void BuildingTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->JustHasRallyPoint.Read(exINI, pSection, "JustHasRallyPoint"); this->JumpjetExitCoord.Read(exINI, pSection, "JumpjetExitCoord"); + this->RallySpeedType.Read(exINI, pSection, "RallySpeedType"); + this->RallyMovementZone.Read(exINI,pSection,"RallyMovementZone"); this->AutoUpgrade.Read(exINI, pSection, "AutoUpgrade"); this->LimboBuild.Read(exINI, pSection, "LimboBuild"); @@ -999,6 +1001,8 @@ void BuildingTypeExt::ExtData::Serialize(T& Stm) .Process(this->JustHasRallyPoint) .Process(this->JumpjetExitCoord) .Process(this->AnimDontDelayBurst) + .Process(this->RallySpeedType) + .Process(this->RallyMovementZone) .Process(this->AutoUpgrade) .Process(this->LimboBuild) .Process(this->LimboBuildID) diff --git a/src/Ext/BuildingType/Body.h b/src/Ext/BuildingType/Body.h index 8203551f16..977cd53023 100644 --- a/src/Ext/BuildingType/Body.h +++ b/src/Ext/BuildingType/Body.h @@ -68,6 +68,8 @@ class BuildingTypeExt Valueable JustHasRallyPoint; Nullable JumpjetExitCoord; Valueable AnimDontDelayBurst; + Nullable RallySpeedType; + Nullable RallyMovementZone; Valueable AutoUpgrade; Valueable LimboBuild; @@ -128,6 +130,8 @@ class BuildingTypeExt , JustHasRallyPoint { false } , JumpjetExitCoord { } , AnimDontDelayBurst { false } + , RallySpeedType { } + , RallyMovementZone { } , AutoUpgrade { false } , LimboBuild { false } , LimboBuildID { -1 } diff --git a/src/Ext/Techno/Hooks.Others.cpp b/src/Ext/Techno/Hooks.Others.cpp index 51abc2cd99..4c0dd97038 100644 --- a/src/Ext/Techno/Hooks.Others.cpp +++ b/src/Ext/Techno/Hooks.Others.cpp @@ -1888,6 +1888,19 @@ DEFINE_HOOK(0x73AAB3, UnitClass_UpdateMoving_RallyPointAreaGuard, 0x5) return 0; } +DEFINE_HOOK(0x4438C9, BuildingClass_SetRallyPoint_PathFinding, 0x6) +{ + GET(BuildingClass* const, pThis, EBP); + GET(int, movementzone, ESI); + GET_STACK(int, speedtype, STACK_OFFSET(0xA4, -0x84)); + + auto const pExt = BuildingTypeExt::ExtMap.Find(pThis->Type); + R->ESI(pExt->RallyMovementZone.Get(movementzone)); + R->Stack(STACK_OFFSET(0xA4, -0x84), pExt->RallySpeedType.Get(speedtype)); + + return 0; +} + #pragma endregion #pragma region CrushBuildingOnAnyCell From ecbf5b35409243f1c2f2e191c952a0a1bf502571 Mon Sep 17 00:00:00 2001 From: TaranDahl Date: Tue, 24 Dec 2024 12:42:37 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=9B=B4=E6=8D=A2=E4=BA=86=E6=8A=80?= =?UTF-8?q?=E6=9C=AF=E8=B7=AF=E7=BA=BF=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=94=AF=E6=8C=81=E4=BB=BB=E4=BD=95=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E6=97=A0=E4=B8=8A=E9=99=90=E6=93=8D=E7=BA=B5=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=81=94=E6=9C=BA=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 就是不知道如果单位状态变化会不会导致问题 --- src/Ext/Techno/Body.Update.cpp | 31 +++++++++++++++++++++++++++++++ src/Ext/Techno/Body.cpp | 12 ++++++++++++ src/Ext/Techno/Body.h | 12 +++++++++++- src/Ext/Techno/Hooks.Others.cpp | 21 ++++++++++++++++++++- 4 files changed, 74 insertions(+), 2 deletions(-) diff --git a/src/Ext/Techno/Body.Update.cpp b/src/Ext/Techno/Body.Update.cpp index 8d2ca6ffac..be89ada110 100644 --- a/src/Ext/Techno/Body.Update.cpp +++ b/src/Ext/Techno/Body.Update.cpp @@ -15,6 +15,8 @@ #include #include +#include +#include // TechnoClass_AI_0x6F9E50 // It's not recommended to do anything more here it could have a better place for performance consideration @@ -60,6 +62,14 @@ void TechnoExt::ExtData::OnEarlyUpdate() this->AutoTargetedWallCell = nullptr; } } + + if (this->HasCachedClick) + { + if (EventClass::OutList->Count < 128) + { + this->ProcessCachedClick(); + } + } } void TechnoExt::ExtData::ApplyInterceptor() @@ -1237,3 +1247,24 @@ void TechnoExt::ExtData::RecalculateStatMultipliers() if (forceDecloak && pThis->CloakState == CloakState::Cloaked) pThis->Uncloak(true); } + +void TechnoExt::ExtData::ClearCachedClick() +{ + this->HasCachedClick = false; + this->CachedMission = Mission::None; + this->CachedCell = nullptr; + this->CachedTarget = nullptr; +} + +void TechnoExt::ExtData::ProcessCachedClick() +{ + TargetClass target1 = TargetClass(this->CachedCell); + TargetClass target2 = TargetClass(this->CachedTarget); + TargetClass target3 = TargetClass(this->OwnerObject()); + TargetClass target4; + target4.m_ID = target3.m_ID; + target4.m_RTTI = 0; + EventClass event = EventClass(HouseClass::CurrentPlayer->ArrayIndex, target3, this->CachedMission, target2, target1, target4); + EventClass::AddEvent(event); + this->ClearCachedClick(); +} diff --git a/src/Ext/Techno/Body.cpp b/src/Ext/Techno/Body.cpp index 175bb3f7a3..0b52e4231b 100644 --- a/src/Ext/Techno/Body.cpp +++ b/src/Ext/Techno/Body.cpp @@ -524,6 +524,10 @@ void TechnoExt::ExtData::Serialize(T& Stm) .Process(this->MyTargetingFrame) .Process(this->AttackMoveFollowerTempCount) .Process(this->AutoTargetedWallCell) + .Process(this->HasCachedClick) + .Process(this->CachedMission) + .Process(this->CachedCell) + .Process(this->CachedTarget) .Process(this->FiringObstacleCell) .Process(this->KeepTargetOnMove) .Process(this->IsDetachingForCloak) @@ -534,6 +538,14 @@ void TechnoExt::ExtData::Serialize(T& Stm) ; } +void TechnoExt::ExtData::InvalidatePointer(void* ptr, bool bRemoved) +{ + if (this->HasCachedClick && this->CachedTarget == ptr) + { + this->ClearCachedClick(); + } +} + void TechnoExt::ExtData::LoadFromStream(PhobosStreamReader& Stm) { Extension::LoadFromStream(Stm); diff --git a/src/Ext/Techno/Body.h b/src/Ext/Techno/Body.h index 42ba8ee24c..06a7730f56 100644 --- a/src/Ext/Techno/Body.h +++ b/src/Ext/Techno/Body.h @@ -64,6 +64,10 @@ class TechnoExt int MyTargetingFrame; int AttackMoveFollowerTempCount; CellClass* AutoTargetedWallCell; + bool HasCachedClick; + Mission CachedMission; + AbstractClass* CachedCell; + AbstractClass* CachedTarget; CellClass* FiringObstacleCell; // Set on firing if there is an obstacle cell between target and techno, used for updating WaveClass target etc. bool KeepTargetOnMove; bool IsDetachingForCloak; // Used for checking animation detaching, set to true before calling Detach_All() on techno when this anim is attached to and to false after when cloaking only. @@ -117,6 +121,10 @@ class TechnoExt , MyTargetingFrame { ScenarioClass::Instance->Random.RandomRanged(0,15) } , AttackMoveFollowerTempCount { 0 } , AutoTargetedWallCell{ nullptr } + , HasCachedClick { false } + , CachedMission { Mission::None } + , CachedCell { nullptr } + , CachedTarget { nullptr } , FiringObstacleCell {} , KeepTargetOnMove { false } , IsDetachingForCloak { false } @@ -155,9 +163,11 @@ class TechnoExt void ApplyIdleAction(); void ManualIdleAction(); void StopRotateWithNewROT(int ROT = -1); + void ClearCachedClick(); + void ProcessCachedClick(); virtual ~ExtData() override; - virtual void InvalidatePointer(void* ptr, bool bRemoved) override { } + virtual void InvalidatePointer(void* ptr, bool bRemoved) override; virtual void LoadFromStream(PhobosStreamReader& Stm) override; virtual void SaveToStream(PhobosStreamWriter& Stm) override; diff --git a/src/Ext/Techno/Hooks.Others.cpp b/src/Ext/Techno/Hooks.Others.cpp index 12fe56abe8..11a5085a5c 100644 --- a/src/Ext/Techno/Hooks.Others.cpp +++ b/src/Ext/Techno/Hooks.Others.cpp @@ -2225,7 +2225,7 @@ DEFINE_HOOK(0x6521CE, EventClass_AddEvent, 0x5) return 0; } - +/* DEFINE_HOOK(0x646EF5, EventClass_AddMegaMissionEvent, 0xA) { GET(EventClass*, pEvent, EAX); @@ -2274,6 +2274,25 @@ DEFINE_HOOK(0x64C739, Game_ProcessDoList_AddMegaMissionEvent, 0xA) return 0; } +*/ +DEFINE_HOOK(0x6FFDA5, TechnoClass_ClickedMission_CacheClickedMission, 0x7) +{ + GET_STACK(AbstractClass* const, pCell, STACK_OFFSET(0x98, 0xC)); + GET(TechnoClass* const, pThis, ECX); + GET(AbstractClass* const, pTarget, EBP); + GET(Mission const, mission, EDI); + + if (EventClass::OutList->Count >= 128) + { + auto const pExt = TechnoExt::ExtMap.Find(pThis); + pExt->HasCachedClick = true; + pExt->CachedMission = mission; + pExt->CachedCell = pCell; + pExt->CachedTarget = pTarget; + } + + return 0; +} #pragma endregion