Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mix4 mj #1

Merged
merged 8 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Ext/BuildingType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/BuildingType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class BuildingTypeExt
Valueable<bool> JustHasRallyPoint;
Nullable<CoordStruct> JumpjetExitCoord;
Valueable<bool> AnimDontDelayBurst;
Nullable<int> RallySpeedType;
Nullable<int> RallyMovementZone;

Valueable<bool> AutoUpgrade;
Valueable<bool> LimboBuild;
Expand Down Expand Up @@ -128,6 +130,8 @@ class BuildingTypeExt
, JustHasRallyPoint { false }
, JumpjetExitCoord { }
, AnimDontDelayBurst { false }
, RallySpeedType { }
, RallyMovementZone { }
, AutoUpgrade { false }
, LimboBuild { false }
, LimboBuildID { -1 }
Expand Down
40 changes: 40 additions & 0 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

#include <WWMouseClass.h>
#include <TacticalClass.h>
#include <TargetClass.h>
#include <EventClass.h>

// TechnoClass_AI_0x6F9E50
// It's not recommended to do anything more here it could have a better place for performance consideration
Expand Down Expand Up @@ -51,6 +53,23 @@ 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;
}
}

if (this->HasCachedClick)
{
if (EventClass::OutList->Count < 128)
{
this->ProcessCachedClick();
}
}
}

void TechnoExt::ExtData::ApplyInterceptor()
Expand Down Expand Up @@ -1228,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();
}
13 changes: 13 additions & 0 deletions src/Ext/Techno/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ void TechnoExt::ExtData::Serialize(T& Stm)
.Process(this->ShouldUpdateGattlingValue)
.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)
Expand All @@ -533,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<TechnoClass>::LoadFromStream(Stm);
Expand Down
14 changes: 13 additions & 1 deletion src/Ext/Techno/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class TechnoExt
bool ShouldUpdateGattlingValue;
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.
Expand Down Expand Up @@ -115,6 +120,11 @@ class TechnoExt
, ShouldUpdateGattlingValue { false }
, 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 }
Expand Down Expand Up @@ -153,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;

Expand Down
47 changes: 46 additions & 1 deletion src/Ext/Techno/Hooks.Others.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,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
Expand Down Expand Up @@ -1730,6 +1743,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
Expand Down Expand Up @@ -2053,7 +2079,7 @@ DEFINE_HOOK(0x6521CE, EventClass_AddEvent, 0x5)

return 0;
}

/*
DEFINE_HOOK(0x646EF5, EventClass_AddMegaMissionEvent, 0xA)
{
GET(EventClass*, pEvent, EAX);
Expand Down Expand Up @@ -2102,6 +2128,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

Expand Down
21 changes: 17 additions & 4 deletions src/Misc/Hooks.BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<JumpjetLocomotionClass*>(pThis->Locomotor) && pThis->Target)
auto pJumpjetLoco = locomotion_cast<JumpjetLocomotionClass*>(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();
}

Expand All @@ -994,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<JumpjetLocomotionClass*>(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();
}

Expand Down
Loading