From fca5e1f8bc66cc4a5dfb1d4b78baaecb46a01dd5 Mon Sep 17 00:00:00 2001 From: Netsu_Negi <71598172+NetsuNegi@users.noreply.github.com> Date: Tue, 24 Sep 2024 00:40:16 +0800 Subject: [PATCH] Assign Super Weapon cameo to any sidebar tab (#1387) - Now you can specific sw will insert to which tab of sidebar. In `rulesmd.ini` ```ini [SOMESW] ; Super Weapon TabIndex=1 ; integer ``` --------- Co-authored-by: MortonPL Co-authored-by: Kerbiter --- CREDITS.md | 1 + docs/New-or-Enhanced-Logics.md | 11 ++++++ docs/Whats-New.md | 1 + src/Ext/SWType/Body.cpp | 4 +++ src/Ext/SWType/Body.h | 3 ++ src/Ext/SWType/Hooks.cpp | 64 ++++++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+) diff --git a/CREDITS.md b/CREDITS.md index b92c4c9826..d6903a4bac 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -329,6 +329,7 @@ This page lists all the individual contributions to the project by their author. - Jumpjet crash speed fix when crashing onto building - Disguised units not using the correct palette if target has custom palette bugfix - Tunnel/Walk/Mech locomotor being stuck when moving too fast bugfix + - Assign Super Weapon cameo to any sidebar tab - **Apollo** - Translucent SHP drawing patches - **ststl** - Customizable ShowTimer priority of superweapons diff --git a/docs/New-or-Enhanced-Logics.md b/docs/New-or-Enhanced-Logics.md index 6cd47d7638..6eb539bd42 100644 --- a/docs/New-or-Enhanced-Logics.md +++ b/docs/New-or-Enhanced-Logics.md @@ -874,6 +874,17 @@ Detonate.Damage= ; integer Detonate.AtFirer=false ; boolean ``` +### Customize SuperWeapon TabIndex + +- You can now assign a Super Weapon's cameo to any sidebar tab using `TabIndex`. + - Valid values are: 0 (buildings tab), 1 (arsenal tab), 2 (infantry tab), 3 (vehicle tab). + +In `rulesmd.ini`: +```ini +[SOMESW] ; Super Weapon +TabIndex=1 ; integer +``` + ## Technos ### Aircraft spawner customizations diff --git a/docs/Whats-New.md b/docs/Whats-New.md index c2ba9e42e4..96ea81b0e0 100644 --- a/docs/Whats-New.md +++ b/docs/Whats-New.md @@ -452,6 +452,7 @@ New: - Nonprovocative Warheads (by Starkku) - Option to restore `PowerSurplus` setting for AI (by Starkku) - `FireOnce` infantry sequence reset toggle (by Starkku) +- Assign Super Weapon cameo to any sidebar tab (by NetsuNegi) Vanilla fixes: - Allow AI to repair structures built from base nodes/trigger action 125/SW delivery in single player missions (by Trsdy) diff --git a/src/Ext/SWType/Body.cpp b/src/Ext/SWType/Body.cpp index 93ebecc40f..53dfbd00b7 100644 --- a/src/Ext/SWType/Body.cpp +++ b/src/Ext/SWType/Body.cpp @@ -47,6 +47,7 @@ void SWTypeExt::ExtData::Serialize(T& Stm) .Process(this->ShowTimer_Priority) .Process(this->Convert_Pairs) .Process(this->ShowDesignatorRange) + .Process(this->TabIndex) .Process(this->UseWeeds) .Process(this->UseWeeds_Amount) .Process(this->UseWeeds_StorageTimer) @@ -160,6 +161,9 @@ void SWTypeExt::ExtData::LoadFromINIFile(CCINIClass* const pINI) this->ShowDesignatorRange.Read(exINI, pSection, "ShowDesignatorRange"); + this->TabIndex.Read(exINI, pSection, "TabIndex"); + GeneralUtils::IntValidCheck(&this->TabIndex, pSection, "TabIndex", 1, 0, 3); + this->UseWeeds.Read(exINI, pSection, "UseWeeds"); this->UseWeeds_Amount.Read(exINI, pSection, "UseWeeds.Amount"); this->UseWeeds_StorageTimer.Read(exINI, pSection, "UseWeeds.StorageTimer"); diff --git a/src/Ext/SWType/Body.h b/src/Ext/SWType/Body.h index 82bd9ad3f4..1a334f2f69 100644 --- a/src/Ext/SWType/Body.h +++ b/src/Ext/SWType/Body.h @@ -60,6 +60,8 @@ class SWTypeExt Valueable Detonate_AtFirer; Valueable ShowDesignatorRange; + Valueable TabIndex; + std::vector> LimboDelivery_RandomWeightsData; std::vector> SW_Next_RandomWeightsData; @@ -107,6 +109,7 @@ class SWTypeExt , ShowTimer_Priority { 0 } , Convert_Pairs {} , ShowDesignatorRange { true } + , TabIndex { 1 } , UseWeeds { false } , UseWeeds_Amount { RulesClass::Instance->WeedCapacity } , UseWeeds_StorageTimer { false } diff --git a/src/Ext/SWType/Hooks.cpp b/src/Ext/SWType/Hooks.cpp index cb0369c5ef..b87982ab02 100644 --- a/src/Ext/SWType/Hooks.cpp +++ b/src/Ext/SWType/Hooks.cpp @@ -182,3 +182,67 @@ DEFINE_HOOK(0x6CC1E6, SuperClass_SetSWCharge_UseWeeds, 0x5) return 0; } + +#pragma region SW TabIndex +DEFINE_HOOK(0x6A5F6E, SidebarClass_6A5F20_TabIndex, 0x8) +{ + enum { ApplyTabIndex = 0x6A5FD3 }; + + GET(AbstractType const, absType, ESI); + GET(int const, typeIdx, EAX); + + R->EAX(SidebarClass::GetObjectTabIdx(absType, typeIdx, 0)); + return ApplyTabIndex; +} + +DEFINE_HOOK(0x6A614D, SidebarClass_6A6140_TabIndex, 0x5) +{ + enum { ApplyTabIndex = 0x6A61B1 }; + + GET(AbstractType const, absType, EDI); + GET(int const, typeIdx, EBP); + + R->EAX(SidebarClass::GetObjectTabIdx(absType, typeIdx, 0)); + return ApplyTabIndex; +} + +DEFINE_HOOK(0x6A633D, SidebarClass_AddCameo_TabIndex, 0x5) +{ + enum { ApplyTabIndex = 0x6A63B7 }; + + GET(AbstractType const, absType, ESI); + GET(int const, typeIdx, EBP); + + R->Stack(STACK_OFFSET(0x14, 0x4), SidebarClass::GetObjectTabIdx(absType, typeIdx, 0)); + return ApplyTabIndex; +} + +DEFINE_HOOK(0x6ABC9D, SidebarClass_GetObjectTabIndex_Super, 0x5) +{ + enum { ApplyTabIndex = 0x6ABCA2 }; + + GET(int const, typeIdx, EDX); + + if (typeIdx < 0 || typeIdx >= SuperWeaponTypeClass::Array->Count) + return 0; + + const auto pSWType = SuperWeaponTypeClass::Array->Items[typeIdx]; + const auto pSWTypExt = SWTypeExt::ExtMap.Find(pSWType); + + R->EAX(pSWTypExt->TabIndex); + return ApplyTabIndex; +} + +DEFINE_HOOK(0x6AC67A, SidebarClass_6AC5F0_TabIndex, 0x5) +{ + enum { ApplyTabIndex = 0x6AC6D9 }; + + GET(AbstractType const, absType, EAX); + GET(int const, typeIdx, ESI); + + R->EAX(SidebarClass::GetObjectTabIdx(absType, typeIdx, 0)); + return ApplyTabIndex; +} + +DEFINE_JUMP(LJMP, 0x6A8D07, 0x6A8D17) // Skip tabIndex check +#pragma endregion