-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Feature: "DisplaySentryArchetypeName"
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
TheArchive.IL2CPP/Features/Hud/DisplaySentryArchetypeName.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using GameData; | ||
using Gear; | ||
using Player; | ||
using System.Runtime.CompilerServices; | ||
using TheArchive.Core.Attributes; | ||
using TheArchive.Core.FeaturesAPI; | ||
using TheArchive.Utilities; | ||
|
||
#if IL2CPP | ||
using ColGen = Il2CppSystem.Collections.Generic; | ||
#else | ||
using ColGen = System.Collections.Generic; | ||
#endif | ||
|
||
namespace TheArchive.Features.Hud | ||
{ | ||
public class DisplaySentryArchetypeName : Feature | ||
{ | ||
public override string Name => "Display Sentry Type"; | ||
|
||
public override string Group => FeatureGroups.Hud; | ||
|
||
public override string Description => "Display the Sentry Type (<color=orange>Sniper</color>, <color=orange>Burst</color>, <color=orange>Auto</color>, <color=orange>Shotgun</color>) for remote players instead of the nondescript \"<color=orange>Sentry Gun</color>\" on the map screen."; | ||
|
||
|
||
private static readonly IValueAccessor<ArchetypeDataBlock, string> _ArchetypeDataBlock_PublicName = AccessorBase.GetValueAccessor<ArchetypeDataBlock, string>(nameof(ArchetypeDataBlock.PublicName)); | ||
|
||
|
||
[ArchivePatch(typeof(PUI_Inventory), nameof(PUI_Inventory.UpdateInfoForItem))] | ||
internal static class PUI_Inventory_UpdateInfoForItem_Patch | ||
{ | ||
private static IValueAccessor<PUI_Inventory, ColGen.Dictionary<InventorySlot, PUI_InventoryItem>> _m_inventorySlots; | ||
private static IValueAccessor<Item, ItemDataBlock> _Item_ItemDataBlock; | ||
|
||
public static void Init() | ||
{ | ||
_m_inventorySlots = AccessorBase.GetValueAccessor<PUI_Inventory, ColGen.Dictionary<InventorySlot, PUI_InventoryItem>>("m_inventorySlots"); | ||
|
||
_Item_ItemDataBlock = AccessorBase.GetValueAccessor<Item, ItemDataBlock>("ItemDataBlock") | ||
.OrAlternative(() => AccessorBase.GetValueAccessor<Item, ItemDataBlock>("ItemData")); // <-- R1 | ||
} | ||
|
||
public static void Postfix(PUI_Inventory __instance, BackpackItem bpItem) | ||
{ | ||
if (bpItem?.Instance == null || bpItem?.GearIDRange == null) | ||
return; | ||
|
||
bool isSentryGun = bpItem.GearIDRange.GetCompID(eGearComponent.Category) == 12; // => PersistentID of the Sentry Gun Category | ||
if (!isSentryGun) | ||
return; | ||
|
||
Item item = bpItem.Instance; | ||
InventorySlot inventorySlot = _Item_ItemDataBlock.Get(item).inventorySlot; | ||
|
||
eWeaponFireMode weaponFireMode = (eWeaponFireMode)bpItem.GearIDRange.GetCompID(eGearComponent.FireMode); | ||
ArchetypeDataBlock archetypeDataBlock = SentryGunInstance_Firing_Bullets.GetArchetypeDataForFireMode(weaponFireMode); | ||
|
||
if (_m_inventorySlots.Get(__instance).ContainsKey(inventorySlot)) | ||
{ | ||
PUI_InventoryItem pui_InventoryItem = _m_inventorySlots.Get(__instance)[inventorySlot]; | ||
|
||
var prefix = string.Empty; | ||
if(pui_InventoryItem.IsDeployed) | ||
{ | ||
prefix = $"<COLOR=red>{SharedUtils.GetLocalizedTextSafe(2505980868, overrideText: "DEPLOYED")}</color> "; | ||
} | ||
|
||
pui_InventoryItem.SetArchetypeName(prefix + GetPublicName(archetypeDataBlock)); | ||
} | ||
} | ||
} | ||
|
||
public static string GetPublicName(ArchetypeDataBlock archetypeDataBlock) | ||
{ | ||
if (archetypeDataBlock == null) | ||
return string.Empty; | ||
|
||
if (Is.R6OrLater) | ||
return GetPublicNameR6(archetypeDataBlock); | ||
|
||
return _ArchetypeDataBlock_PublicName.Get(archetypeDataBlock); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static string GetPublicNameR6(ArchetypeDataBlock archetypeDataBlock) | ||
{ | ||
return archetypeDataBlock.PublicName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters