Skip to content
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
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ This page lists all the individual contributions to the project by their author.
- Fix the bug that building with `CloningFacility=true` and `WeaponsFactory=true` may cloning multiple vehicles and then they get stuck
- Customize Ares's radar jam logic
- Customize if cloning need power
- Typeselect consider ifv mode
- **Apollo** - Translucent SHP drawing patches
- **ststl**:
- Customizable `ShowTimer` priority of superweapons
Expand Down
17 changes: 17 additions & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,23 @@ In `rulesmd.ini`:
AllowDeployControlledMCV=false ; boolean
```

## Customize type selection for IFV

In vanilla game, when using type selection command on IFVs, all of them will be selected regardless of their current modes, which is allowed to customize now.
- `WeaponGroupAsN` determines which group the IFV is in when enabling `WeaponN`, where N stands for 1-based weapon mode index. IFVs in the same group will be selected together during type a selection, while not included those in different groups.
- `TypeSelectUseIFVMode` determines whether all IFV modes will be considered as its own group by default during a type selection.
- If it's set to true, `WeaponGroupAsN` will be default to N for each `WeaponN`, which makes each of them become a standalone type during a type selection.
- If it's set to false, `WeaponGroupAsN` will be default to 0 for all weapons, which makes type selection on IFVs work the same as before.

In `rulesmd.ini`:
```ini
[General]
TypeSelectUseIFVMode=false ; boolean

[SOMEVEHICLE] ; VehicleType
WeaponGroupAsN= ; string, default to N if [General] -> TypeSelectUseIFVMode=true, and 0 if false
```

## RadialIndicator visibility

In vanilla game, a structure's radial indicator can be drawn only when it belongs to the player. Now it can also be visible to observer.
Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ New:
- [Allow deploy controlled MCV](Fixed-or-Improved-Logics.md#allow-deploy-controlled-mcv) (by NetsuNegi)
- [Customize if cloning need power](Fixed-or-Improved-Logics.md#customize-if-cloning-need-power) (by NetsuNegi)
- [Add Target Filtering Options to AttachEffect System](New-or-Enhanced-Logics.md#attached-effects) (by Flactine)
- [Customize type selection for IFV](Fixed-or-Improved-Logics.md#customize-type-selection-for-ifv) (by NetsuNegi)

Vanilla fixes:
- Fixed sidebar not updating queued unit numbers when adding or removing units when the production is on hold (by CrimRecya)
Expand Down
3 changes: 3 additions & 0 deletions src/Ext/Rules/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ void RulesExt::ExtData::LoadBeforeTypeData(RulesClass* pThis, CCINIClass* pINI)

this->AllowDeployControlledMCV.Read(exINI, GameStrings::General, "AllowDeployControlledMCV");

this->TypeSelectUseIFVMode.Read(exINI, GameStrings::General, "TypeSelectUseIFVMode");

this->IronCurtain_KeptOnDeploy.Read(exINI, GameStrings::CombatDamage, "IronCurtain.KeptOnDeploy");
this->IronCurtain_EffectOnOrganics.Read(exINI, GameStrings::CombatDamage, "IronCurtain.EffectOnOrganics");
this->IronCurtain_KillOrganicsWarhead.Read<true>(exINI, GameStrings::CombatDamage, "IronCurtain.KillOrganicsWarhead");
Expand Down Expand Up @@ -485,6 +487,7 @@ void RulesExt::ExtData::Serialize(T& Stm)
.Process(this->ForbidParallelAIQueues_Vehicle)
.Process(this->EnablePowerSurplus)
.Process(this->AllowDeployControlledMCV)
.Process(this->TypeSelectUseIFVMode)
.Process(this->IronCurtain_KeptOnDeploy)
.Process(this->IronCurtain_EffectOnOrganics)
.Process(this->IronCurtain_KillOrganicsWarhead)
Expand Down
4 changes: 4 additions & 0 deletions src/Ext/Rules/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class RulesExt

Valueable<bool> AllowDeployControlledMCV;

Valueable<bool> TypeSelectUseIFVMode;

Valueable<bool> IronCurtain_KeptOnDeploy;
Valueable<IronCurtainEffect> IronCurtain_EffectOnOrganics;
Nullable<WarheadTypeClass*> IronCurtain_KillOrganicsWarhead;
Expand Down Expand Up @@ -370,6 +372,8 @@ class RulesExt

, AllowDeployControlledMCV { false }

, TypeSelectUseIFVMode { false }

, IronCurtain_KeptOnDeploy { true }
, IronCurtain_EffectOnOrganics { IronCurtainEffect::Kill }
, IronCurtain_KillOrganicsWarhead { }
Expand Down
41 changes: 0 additions & 41 deletions src/Ext/Techno/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,47 +705,6 @@ DEFINE_HOOK(0x414665, AircraftClass_Draw_ExtraSHP, 0x6)
return Continue;
}

#pragma region BuildingTypeSelectable

namespace BuildingTypeSelectable
{
bool ProcessingIDMatches = false;
}

DEFINE_HOOK_AGAIN(0x732B28, TypeSelectExecute_SetContext, 0x6)
DEFINE_HOOK(0x732A85, TypeSelectExecute_SetContext, 0x7)
{
BuildingTypeSelectable::ProcessingIDMatches = true;
return 0;
}

// This func has two retn, but one of them is affected by Ares' hook. Thus we only hook the other one.
// If you have any problem, check Ares in IDA before making any changes.
DEFINE_HOOK(0x732C97, TechnoClass_IDMatches_ResetContext, 0x5)
{
BuildingTypeSelectable::ProcessingIDMatches = false;
return 0;
}

// If the context is set as well as the flags is enabled, this will make the vfunc CanBeSelectedNow return true to enable the type selection.
DEFINE_HOOK(0x465D40, BuildingClass_Is1x1AndUndeployable_BuildingMassSelectable, 0x6)
{
enum { SkipGameCode = 0x465D6A };

// Since Ares hooks around, we have difficulty juggling Ares and no Ares.
// So we simply disable this feature if no Ares.
if (!AresHelper::CanUseAres)
return 0;

if (!BuildingTypeSelectable::ProcessingIDMatches || !RulesExt::Global()->BuildingTypeSelectable)
return 0;

R->EAX(true);
return SkipGameCode;
}

#pragma endregion

DEFINE_HOOK(0x521D94, InfantryClass_CurrentSpeed_ProneSpeed, 0x6)
{
GET(InfantryClass*, pThis, ESI);
Expand Down
17 changes: 15 additions & 2 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,26 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
const char* pSection = pThis->ID;
INI_EX exINI(pINI);

char tempBuffer[40];

this->HealthBar_Hide.Read(exINI, pSection, "HealthBar.Hide");
this->HealthBar_HidePips.Read(exINI, pSection, "HealthBar.HidePips");
this->HealthBar_Permanent.Read(exINI, pSection, "HealthBar.Permanent");
this->HealthBar_Permanent_PipScale.Read(exINI, pSection, "HealthBar.Permanent.PipScale");
this->UIDescription.Read(exINI, pSection, "UIDescription");
this->LowSelectionPriority.Read(exINI, pSection, "LowSelectionPriority");

if (pThis->Gunner)
{
this->WeaponGroupAs.resize(pThis->WeaponCount);

for (int idx = 0; idx < pThis->WeaponCount; ++idx)
{
_snprintf_s(tempBuffer, sizeof(tempBuffer), "WeaponGroupAs%d", idx + 1);
this->WeaponGroupAs[idx].Read(pINI, pSection, tempBuffer);
}
}

this->RadarJamHouses.Read(exINI, pSection, "RadarJamHouses");
this->RadarJamDelay.Read(exINI, pSection, "RadarJamDelay");
this->RadarJamAffect.Read(exINI, pSection, "RadarJamAffect");
Expand Down Expand Up @@ -1029,8 +1043,6 @@ void TechnoTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI)
// Ares 2.0
this->Passengers_BySize.Read(exINI, pSection, "Passengers.BySize");

char tempBuffer[40];

if (pThis->Gunner)
{
size_t weaponCount = pThis->WeaponCount;
Expand Down Expand Up @@ -1289,6 +1301,7 @@ void TechnoTypeExt::ExtData::Serialize(T& Stm)
.Process(this->InterceptorType)

.Process(this->GroupAs)
.Process(this->WeaponGroupAs)
.Process(this->RadarJamRadius)
.Process(this->RadarJamHouses)
.Process(this->RadarJamDelay)
Expand Down
2 changes: 2 additions & 0 deletions src/Ext/TechnoType/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TechnoTypeExt
Valueable<CSFText> UIDescription;
Valueable<bool> LowSelectionPriority;
PhobosFixedString<0x20> GroupAs;
std::vector<PhobosFixedString<0x20>> WeaponGroupAs;
Valueable<int> RadarJamRadius;
Valueable<AffectedHouse> RadarJamHouses;
Valueable<int> RadarJamDelay;
Expand Down Expand Up @@ -447,6 +448,7 @@ class TechnoTypeExt
, UIDescription {}
, LowSelectionPriority { false }
, GroupAs { NONE_STR }
, WeaponGroupAs {}
, RadarJamRadius { 0 }
, RadarJamHouses { AffectedHouse::Enemies }
, RadarJamDelay { 30 }
Expand Down
108 changes: 106 additions & 2 deletions src/Misc/Selection.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Phobos.h"
#include "Utilities/Macro.h"
#include <Utilities/AresHelper.h>
#include "Ext/Techno/Body.h"
#include "Ext/TechnoType/Body.h"

Expand Down Expand Up @@ -31,6 +32,9 @@ class ExtSelection
}
} Array {};

static inline bool ProcessingIDMatches = false;
static inline std::vector<const char*> IFVGroups;

// Reversed from Is_Selectable, w/o Select call
static bool ObjectClass_IsSelectable(ObjectClass* pThis)
{
Expand All @@ -54,12 +58,14 @@ class ExtSelection
return true;
}
}

return false;
}

static bool Tactical_IsHighPriorityInRect(TacticalClass* pThis, LTRBStruct* rect)
{
for (const auto& selected : Array)
{
if (Tactical_IsInSelectionRect(pThis, rect, selected) && ObjectClass_IsSelectable(selected.Object))
{
if ((selected.Object->AbstractFlags & AbstractFlags::Techno) != AbstractFlags::None)
Expand All @@ -68,6 +74,7 @@ class ExtSelection
return true;
}
}
}

return false;
}
Expand Down Expand Up @@ -120,6 +127,38 @@ class ExtSelection
Unsorted::MoveFeedback = true;
}

static bool __fastcall TechnoClass_IDMatches(TechnoClass* pTechno, DynamicVectorClass<const char*>& names)
{
bool result = false;

do
{
const auto pTechnoType = pTechno->GetTechnoType();
const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pTechnoType);
const char* id = pTypeExt->GetSelectionGroupID();

if (std::ranges::none_of(names, [id](const char* pID) { return !_stricmp(pID, id); }))
break;

if (pTechnoType->Gunner && !ExtSelection::IFVGroups.empty())
{
char* gunnerID = pTypeExt->WeaponGroupAs[pTechno->CurrentWeaponNumber];

if (!GeneralUtils::IsValidString(gunnerID))
sprintf_s(gunnerID, 0x20, "%d", RulesExt::Global()->TypeSelectUseIFVMode ? pTechno->CurrentWeaponNumber + 1 : 0);

if (std::ranges::none_of(ExtSelection::IFVGroups, [gunnerID](const char* pID) { return !_stricmp(pID, gunnerID); }))
break;
}

result = pTechno->CanBeSelectedNow() || (pTechno->WhatAmI() == BuildingClass::AbsID && pTechnoType->UndeploysInto);
}
while (false);

ExtSelection::ProcessingIDMatches = false;
return result;
}

// Reversed from Tactical::MakeSelection
static void __fastcall Tactical_MakeFilteredSelection(TacticalClass* pThis, void* _, callback_type check_callback)
{
Expand All @@ -146,8 +185,73 @@ class ExtSelection
}
};

DEFINE_FUNCTION_JUMP(LJMP, 0x732C30, ExtSelection::TechnoClass_IDMatches)

// Replace single call
DEFINE_JUMP(CALL, 0x4ABCEB, GET_OFFSET(ExtSelection::Tactical_MakeFilteredSelection))
DEFINE_FUNCTION_JUMP(CALL, 0x4ABCEB, ExtSelection::Tactical_MakeFilteredSelection)

// Replace vanilla function. For in case another module tries to call the vanilla function at offset
DEFINE_JUMP(LJMP, 0x6D9FF0, GET_OFFSET(ExtSelection::Tactical_MakeFilteredSelection))
DEFINE_FUNCTION_JUMP(LJMP, 0x6D9FF0, ExtSelection::Tactical_MakeFilteredSelection)

DEFINE_HOOK(0x73298D, TypeSelectExecute_UseIFVMode, 0x5)
{
const bool useIFVMode = RulesExt::Global()->TypeSelectUseIFVMode;

for (const auto pObject : ObjectClass::CurrentObjects)
{
const auto pTechno = abstract_cast<TechnoClass*, true>(pObject);

if (!pTechno)
continue;

const auto pTechnoType = pTechno->GetTechnoType();

if (!pTechnoType->Gunner)
continue;

const auto pTypeExt = TechnoTypeExt::ExtMap.Find(pTechnoType);
char* gunnerID = pTypeExt->WeaponGroupAs[pTechno->CurrentWeaponNumber];

if (!GeneralUtils::IsValidString(gunnerID))
sprintf_s(gunnerID, 0x20, "%d", useIFVMode ? pTechno->CurrentWeaponNumber + 1 : 0);

if (std::ranges::none_of(ExtSelection::IFVGroups, [gunnerID](const char* pID) { return !_stricmp(pID, gunnerID); }))
ExtSelection::IFVGroups.emplace_back(gunnerID);
}

return 0;
}

DEFINE_HOOK(0x732C06, TypeSelectExecute_Clear, 0x6)
{
ExtSelection::IFVGroups.clear();
return 0;
}

#pragma region BuildingTypeSelectable

DEFINE_HOOK_AGAIN(0x732B28, TypeSelectExecute_SetContext, 0x6)
DEFINE_HOOK(0x732A85, TypeSelectExecute_SetContext, 0x7)
{
ExtSelection::ProcessingIDMatches = true;
return 0;
}

// If the context is set as well as the flags is enabled, this will make the vfunc CanBeSelectedNow return true to enable the type selection.
DEFINE_HOOK(0x465D40, BuildingClass_Is1x1AndUndeployable_BuildingMassSelectable, 0x6)
{
enum { SkipGameCode = 0x465D6A };

// Since Ares hooks around, we have difficulty juggling Ares and no Ares.
// So we simply disable this feature if no Ares.
if (!AresHelper::CanUseAres)
return 0;

if (!ExtSelection::ProcessingIDMatches || !RulesExt::Global()->BuildingTypeSelectable)
return 0;

R->EAX(true);
return SkipGameCode;
}

#pragma endregion