Skip to content

Commit

Permalink
Merge branch 'hotfix/v0.2.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Metadorius committed Sep 19, 2021
2 parents 6bbdb61 + 29c8bad commit 7a13cdc
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 9 deletions.
8 changes: 8 additions & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ In `FAData.ini`:

## Changelog

### 0.2.2.2

Phobos fixes:
- Fixed shield type info not saving properly (by Uranusian)
- Fixed extended building upgrades logic not properly interacting with Ares' BuildLimit check (by Uranusian)
- Fix more random crashes for Cameo Priority (by Uranusian)
- Fix aircraft weapons causing game freeze when burst index was not correctly reset after firing (by Starkku)

### 0.2.2.1

Phobos fixes:
Expand Down
5 changes: 1 addition & 4 deletions src/Ext/Aircraft/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ void AircraftExt::FireBurst(AircraftClass* pThis, AbstractClass* pTarget, int sh

if (weaponType->Burst > 0)
{
while (pThis->CurrentBurstIndex < weaponType->Burst)
for (int i = 0; i < weaponType->Burst; i++)
{
if (weaponType->Burst < 2 && pWeaponTypeExt->Strafing_SimulateBurst)
pThis->CurrentBurstIndex = shotNumber;

pThis->Fire(pThis->Target, weaponIndex);

if (pThis->CurrentBurstIndex == 0)
break;
}
}
}
2 changes: 1 addition & 1 deletion src/Ext/Aircraft/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DEFINE_HOOK(0x417FF1, AircraftClass_Mission_Attack_StrafeShots, 0x6)
GET(AircraftClass*, pThis, ESI);

if (pThis->MissionStatus < (int)AirAttackStatus::FireAtTarget2_Strafe
|| pThis->MissionStatus >(int)AirAttackStatus::FireAtTarget5_Strafe)
|| pThis->MissionStatus > (int)AirAttackStatus::FireAtTarget5_Strafe)
{
return 0;
}
Expand Down
95 changes: 95 additions & 0 deletions src/Ext/BuildingType/Hooks.Upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <HouseClass.h>
#include <Utilities/EnumFunctions.h>
#include "Body.h"
#include <FactoryClass.h>

bool BuildingTypeExt::CanUpgrade(BuildingClass* pBuilding, BuildingTypeClass* pUpgradeType, HouseClass* pUpgradeOwner) {
auto extUpgrade = BuildingTypeExt::ExtMap.Find(pUpgradeType);
Expand Down Expand Up @@ -56,3 +57,97 @@ DEFINE_HOOK(0x4408EB, BuildingClass_Unlimbo_UpgradeBuildings, 0xA)

return ForbidUpgrade;
}

#pragma region UpgradesInteraction

int CountOwnedNowTotal(HouseClass const* const pHouse, TechnoTypeClass const* const pItem)
{
int sum = 0;
const BuildingTypeClass* pBType = nullptr;
const char* pPowersUp = nullptr;

auto checkUpgrade = [pHouse, pBType, &sum](BuildingTypeClass* pTPowersUp)
{
for (auto const& pBld : pHouse->Buildings)
{
if (pBld->Type == pTPowersUp)
{
for (auto const& pUpgrade : pBld->Upgrades)
{
if (pUpgrade == pBType)
++sum;
}
}
}
};

switch (pItem->WhatAmI())
{
case AbstractType::BuildingType:
pBType = static_cast<BuildingTypeClass const*>(pItem);
pPowersUp = pBType->PowersUpBuilding;
if (pPowersUp[0])
{
if (auto const pTPowersUp = BuildingTypeClass::Find(pPowersUp))
checkUpgrade(pTPowersUp);
}

if (auto pBuildingExt = BuildingTypeExt::ExtMap.Find(pBType))
{
for (auto pTPowersUp : pBuildingExt->PowersUp_Buildings)
checkUpgrade(pTPowersUp);
}

break;

default:
__assume(0);
}

return sum;
}

int BuildLimitRemaining(HouseClass const* const pHouse, TechnoTypeClass const* const pItem)
{
auto const BuildLimit = pItem->BuildLimit;

if (BuildLimit >= 0)
return BuildLimit - CountOwnedNowTotal(pHouse, pItem);
else
return -BuildLimit - pHouse->CountOwnedEver(pItem);
}

int CheckBuildLimit(HouseClass const* const pHouse, TechnoTypeClass const* const pItem, bool const includeQueued)
{
enum { NotReached = 1, ReachedPermanently = -1, ReachedTemporarily = 0 };

int BuildLimit = pItem->BuildLimit;
int Remaining = BuildLimitRemaining(pHouse, pItem);

if (BuildLimit >= 0 && Remaining <= 0)
return (includeQueued && FactoryClass::FindByOwnerAndProduct(pHouse, pItem)) ? NotReached : ReachedPermanently;

return Remaining > 0 ? NotReached : ReachedTemporarily;

}

DEFINE_HOOK(0x4F8361, HouseClass_CanBuild_UpgradesInteraction, 0x3)
{
GET(HouseClass const* const, pThis, ECX);
GET_STACK(TechnoTypeClass const* const, pItem, 0x4);
GET_STACK(bool const, includeInProduction, 0xC);
GET(CanBuildResult const, resultOfAres, EAX);

if (auto pBuilding = static_cast<BuildingTypeClass const*>(pItem))
{
if (auto pBuildingExt = BuildingTypeExt::ExtMap.Find(pBuilding))
{
if (pBuildingExt->PowersUp_Buildings.size() > 0 && resultOfAres == CanBuildResult::Buildable)
R->EAX(CheckBuildLimit(pThis, pItem, includeInProduction));
}
}

return 0;
}

#pragma endregion
8 changes: 6 additions & 2 deletions src/Misc/Hooks.UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,14 @@ DEFINE_HOOK(0x6A8463, StripClass_OperatorLessThan_CameoPriority, 0x5)
GET_STACK(TechnoTypeClass*, pRight, STACK_OFFS(0x1C, 0x4));
GET_STACK(int, idxLeft, STACK_OFFS(0x1C, -0x8));
GET_STACK(int, idxRight, STACK_OFFS(0x1C, -0x10));
GET_STACK(AbstractType, rttiLeft, STACK_OFFS(0x1C, -0x4));
GET_STACK(AbstractType, rttiRight, STACK_OFFS(0x1C, -0xC));
auto pLeftTechnoExt = TechnoTypeExt::ExtMap.Find(pLeft);
auto pRightTechnoExt = TechnoTypeExt::ExtMap.Find(pRight);
auto pLeftSWExt = pLeftTechnoExt ? SWTypeExt::ExtMap.Find(SuperWeaponTypeClass::Array->GetItem(idxLeft)) : nullptr;
auto pRightSWExt = pRightTechnoExt ? SWTypeExt::ExtMap.Find(SuperWeaponTypeClass::Array->GetItem(idxRight)) : nullptr;
auto pLeftSWExt = (rttiLeft == AbstractType::Special || rttiLeft == AbstractType::Super || rttiLeft == AbstractType::SuperWeaponType)
? SWTypeExt::ExtMap.Find(SuperWeaponTypeClass::Array->GetItem(idxLeft)) : nullptr;
auto pRightSWExt = (rttiRight == AbstractType::Special || rttiRight == AbstractType::Super || rttiRight == AbstractType::SuperWeaponType)
? SWTypeExt::ExtMap.Find(SuperWeaponTypeClass::Array->GetItem(idxRight)) : nullptr;

if ((pLeftTechnoExt || pLeftSWExt) && (pRightTechnoExt || pRightSWExt))
{
Expand Down
1 change: 1 addition & 0 deletions src/New/Entity/ShieldClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ bool ShieldClass::Serialize(T& Stm)
.Process(this->Online)
.Process(this->Temporal)
.Process(this->Available)
.Process(this->Type)
.Success();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Phobos.version.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#define VERSION_REVISION 2

// Indicates Phobos-related bugfixes only
#define VERSION_PATCH 1
#define VERSION_PATCH 2

#pragma endregion

// Build number. Incremented on each released build.
#define BUILD_NUMBER 21
#define BUILD_NUMBER 23

// Nightly defines GIT_COMMIT and GIT_BRANCH in GH Actions

Expand Down

0 comments on commit 7a13cdc

Please sign in to comment.