using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SupplyRaid;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("Dr_Dog_PhD")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Necessary scripts and hooks for the Ammo Pouch.")]
[assembly: AssemblyFileVersion("0.1.5.0")]
[assembly: AssemblyInformationalVersion("0.1.5+4b751bd2cfd8d06cf23d2ca9c09652856d6de1b7")]
[assembly: AssemblyProduct("Ammo_Pouch_Scripts")]
[assembly: AssemblyTitle("Ammo Pouch Scripts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string id = null, string name = null, string version = null)
{
}
}
}
namespace Ammo_Pouch
{
public class AmmoPouch : FVRFireArmMagazine
{
[HideInInspector]
public enum ContainerType
{
Round,
SpeedLoader,
Clip,
Magazine,
None
}
public enum PouchSorting
{
LIFO,
Fullest,
Emptiest,
Retention
}
[Header("Pouch Attributes")]
[HideInInspector]
public int currentCapacity;
[HideInInspector]
public int currentRoundCapacity;
[HideInInspector]
public int totalCapacity = 10;
[HideInInspector]
public int containerCapacity = 10;
[HideInInspector]
public int proxyCount = 1;
[HideInInspector]
public int proxyCap = 5;
[HideInInspector]
public bool lockID;
[HideInInspector]
public bool vaultLoaded;
public List<List<FireArmRoundClass>> roundClassData = new List<List<FireArmRoundClass>>();
public int speedLoaderCapacity = 10;
public int clipCapacity = 10;
public int magazineCapacity = 10;
public int roundCapacity = 40;
public string lastObjId;
public Dictionary<string, string> camoCodes = new Dictionary<string, string>();
public AmmoPouch_UI UI;
public AmmoPouch_Reception reception;
public Transform displayMagContainer;
[HideInInspector]
public FVRPhysicalObject displayMag;
[HideInInspector]
public FireArmRoundClass None = (FireArmRoundClass)(-1);
[HideInInspector]
public ContainerType container = ContainerType.None;
[HideInInspector]
public PouchSorting sortMethod = PouchSorting.Retention;
public void Awake()
{
((FVRFireArmMagazine)this).Awake();
sortMethod = PouchSorting.Retention;
}
public void Start()
{
((FVRInteractiveObject)this).Start();
UI.updateDisplay();
}
public int fullMags()
{
if (roundClassData.Count < 1)
{
return 0;
}
return (currentRoundCapacity + containerCapacity - 1) / containerCapacity;
}
public void resetPouch()
{
lastObjId = null;
camoCodes = new Dictionary<string, string>();
currentCapacity = 0;
currentRoundCapacity = 0;
container = ContainerType.None;
roundClassData = new List<List<FireArmRoundClass>>();
if (!object.Equals(displayMag, null))
{
Object.Destroy((Object)(object)((FVRInteractiveObject)displayMag).GameObject);
displayMag = null;
}
sortMethod = PouchSorting.Retention;
UI.updateDisplay();
}
public void convertToRetention()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < roundClassData.Count; i++)
{
string text = "";
for (int j = 0; j < roundClassData[i].Count; j++)
{
string text2 = text;
FireArmRoundClass val = roundClassData[i][j];
text = text2 + ((object)(FireArmRoundClass)(ref val)).ToString() + " ";
}
Console.WriteLine(text);
}
if (roundClassData.Count == 0)
{
roundClassData.Clear();
currentCapacity = 0;
currentRoundCapacity = 0;
return;
}
List<FireArmRoundClass> list = new List<FireArmRoundClass>();
for (int k = 0; k < roundClassData.Count; k++)
{
for (int l = 0; l < roundClassData[k].Count; l++)
{
if (roundClassData[k][l] != None)
{
list.Add(roundClassData[k][l]);
}
}
}
currentRoundCapacity = list.Count;
roundClassData.Clear();
int num = currentRoundCapacity / containerCapacity;
int num2 = currentRoundCapacity % containerCapacity;
int num3 = currentCapacity - (num + ((num2 > 0) ? 1 : 0));
for (int m = 0; m < num3; m++)
{
List<FireArmRoundClass> list2 = new List<FireArmRoundClass>();
if (container == ContainerType.SpeedLoader)
{
for (int n = 0; n < containerCapacity; n++)
{
list2.Add(None);
}
}
roundClassData.Add(list2);
}
if (num2 > 0)
{
List<FireArmRoundClass> list3 = new List<FireArmRoundClass>();
for (int num4 = 0; num4 < num2; num4++)
{
list3.Add(list[num4]);
}
if (container == ContainerType.SpeedLoader)
{
for (int num5 = num2; num5 < containerCapacity; num5++)
{
list3.Add(None);
}
}
roundClassData.Add(list3);
}
for (int num6 = 0; num6 < num; num6++)
{
List<FireArmRoundClass> list4 = new List<FireArmRoundClass>();
for (int num7 = 0; num7 < containerCapacity; num7++)
{
list4.Add(list[num6 * containerCapacity + num7 + num2]);
}
roundClassData.Add(list4);
}
}
public void convertToContainers()
{
if (roundClassData.Count > 0)
{
currentRoundCapacity = 0;
return;
}
currentCapacity = 0;
currentRoundCapacity = 0;
}
public void sortLIFO()
{
if (sortMethod != 0)
{
if (sortMethod == PouchSorting.Retention)
{
convertToContainers();
}
sortMethod = PouchSorting.LIFO;
updateDisplayMag();
UI.updateDisplay();
}
}
public void sortFullestFirst()
{
if (sortMethod != PouchSorting.Fullest)
{
if (sortMethod == PouchSorting.Retention)
{
convertToContainers();
}
roundClassData.Sort(AmmoPouch_Helpers.CompareMagContainersAscending);
sortMethod = PouchSorting.Fullest;
updateDisplayMag();
UI.updateDisplay();
}
}
public void sortEmptiestFirst()
{
if (sortMethod != PouchSorting.Emptiest)
{
if (sortMethod == PouchSorting.Retention)
{
convertToContainers();
}
roundClassData.Sort(AmmoPouch_Helpers.CompareMagContainersDescending);
sortMethod = PouchSorting.Emptiest;
updateDisplayMag();
UI.updateDisplay();
}
}
public void sortRetention()
{
sortMethod = PouchSorting.Retention;
convertToRetention();
updateDisplayMag();
UI.updateDisplay();
}
public bool attemptAddProxy()
{
if (proxyCount < proxyCap)
{
proxyCount++;
if (currentCapacity > 0)
{
putRoundsInDisplay();
}
return true;
}
return false;
}
public bool attemptSubProxy()
{
if (proxyCount > 1)
{
proxyCount--;
if (currentCapacity > 0)
{
putRoundsInDisplay();
}
return true;
}
return false;
}
public void updateDisplayMag()
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
if (currentCapacity != 0)
{
if (container == ContainerType.Round)
{
putRoundsInDisplay();
}
else if ((Object)(object)displayMag != (Object)null && displayMag.ObjectWrapper.ItemID.Equals(lastObjId))
{
AmmoPouch_Helpers.fillContainer(displayMag, getNewClassData(), container);
}
else
{
FVRPhysicalObject component = Object.Instantiate<GameObject>(((AnvilAsset)IM.OD[lastObjId]).GetGameObject(), ((Component)displayMagContainer).transform.position, ((Component)displayMagContainer).transform.rotation).GetComponent<FVRPhysicalObject>();
setDisplayMag(component);
}
if ((Object)(object)displayMag != (Object)null)
{
displayMag.ConfigureFromFlagDic(camoCodes);
}
}
}
public int getTotalCapacity()
{
return totalCapacity;
}
public int getCurrentCapacity()
{
return currentCapacity;
}
public void testCamoCodes(FVRPhysicalObject obj)
{
if (lockID)
{
return;
}
camoCodes.Clear();
Dictionary<string, string> flagDic = obj.GetFlagDic();
foreach (string item in flagDic.Keys.Where((string key) => key.StartsWith("nga_mc")).ToList())
{
camoCodes.Add(item, flagDic[item]);
}
}
public void addClassData(List<FireArmRoundClass> data)
{
switch (sortMethod)
{
case PouchSorting.LIFO:
roundClassData.Add(data);
currentCapacity = roundClassData.Count;
return;
case PouchSorting.Retention:
roundClassData.Add(data);
currentCapacity++;
convertToRetention();
return;
}
int count = data.Count;
for (int i = 0; i < currentCapacity; i++)
{
int count2 = roundClassData[i].Count;
if ((sortMethod != PouchSorting.Fullest || count <= count2) && (sortMethod != PouchSorting.Emptiest || count >= count2))
{
roundClassData.Insert(i, data);
currentCapacity++;
return;
}
}
roundClassData.Add(data);
currentCapacity++;
}
public void refillWithType(FireArmRoundClass rClass)
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
Console.WriteLine("Attempted to reload all with " + ((object)(FireArmRoundClass)(ref rClass)).ToString());
if (currentCapacity == 0)
{
return;
}
roundClassData.Clear();
if (container != 0)
{
for (int i = 0; i < currentCapacity; i++)
{
List<FireArmRoundClass> list = new List<FireArmRoundClass>();
for (int j = 0; j < containerCapacity; j++)
{
list.Add(rClass);
}
roundClassData.Add(list);
}
if (sortMethod == PouchSorting.Retention)
{
currentRoundCapacity = containerCapacity * currentCapacity;
}
}
else
{
roundClassData.Add(new List<FireArmRoundClass>());
for (int k = 0; k < totalCapacity; k++)
{
roundClassData[0].Add(rClass);
}
currentCapacity = totalCapacity;
}
updateDisplayMag();
UI.updateDisplay();
}
public void duplicateMag()
{
if (currentCapacity < totalCapacity)
{
currentCapacity++;
roundClassData.Insert(0, new List<FireArmRoundClass>());
updateDisplayMag();
UI.updateDisplay();
}
}
public void upgradeMag(FVRObject upgrade)
{
lastObjId = upgrade.ItemID;
containerCapacity = upgrade.MagazineCapacity;
if (sortMethod == PouchSorting.Retention)
{
convertToRetention();
}
updateDisplayMag();
UI.updateDisplay();
}
public void addSpeedLoader(Speedloader loader)
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
if (currentCapacity >= totalCapacity || (Object)(object)((Component)loader).gameObject == (Object)null || !((FVRPhysicalObject)loader).m_isVisible)
{
return;
}
int count = loader.Chambers.Count;
List<FireArmRoundClass> list = new List<FireArmRoundClass>();
for (int i = 0; i < count; i++)
{
if (loader.Chambers[i].IsLoaded)
{
list.Add(loader.Chambers[i].LoadedClass);
}
}
addClassData(list);
testCamoCodes((FVRPhysicalObject)(object)loader);
((FVRPhysicalObject)loader).m_isVisible = false;
Object.Destroy((Object)(object)((Component)loader).gameObject);
updateDisplayMag();
}
public void addClip(FVRFireArmClip clip)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (currentCapacity >= totalCapacity || (Object)(object)((Component)clip).gameObject == (Object)null || !((FVRPhysicalObject)clip).m_isVisible)
{
return;
}
int numRounds = clip.m_numRounds;
List<FireArmRoundClass> list = new List<FireArmRoundClass>();
for (int i = 0; i < numRounds; i++)
{
if (clip.LoadedRounds[i] != null)
{
list.Add(clip.LoadedRounds[i].LR_Class);
}
}
addClassData(list);
testCamoCodes((FVRPhysicalObject)(object)clip);
((FVRPhysicalObject)clip).m_isVisible = false;
Object.Destroy((Object)(object)((Component)clip).gameObject);
updateDisplayMag();
}
public void addMag(FVRFireArmMagazine mag)
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (currentCapacity >= totalCapacity || (Object)(object)((Component)mag).gameObject == (Object)null || !((FVRPhysicalObject)mag).m_isVisible)
{
return;
}
int numRounds = mag.m_numRounds;
List<FireArmRoundClass> list = new List<FireArmRoundClass>();
for (int i = 0; i < numRounds; i++)
{
if (mag.LoadedRounds[i] != null)
{
list.Add(mag.LoadedRounds[i].LR_Class);
}
}
addClassData(list);
testCamoCodes((FVRPhysicalObject)(object)mag);
((FVRPhysicalObject)mag).m_isVisible = false;
Object.Destroy((Object)(object)((Component)mag).gameObject);
updateDisplayMag();
}
public void addRound(FVRFireArmRound round)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)((Component)round).gameObject == (Object)null) && ((FVRPhysicalObject)round).m_isVisible && currentCapacity < totalCapacity && !round.IsSpent)
{
if (currentCapacity == 0)
{
roundClassData.Clear();
roundClassData.Add(new List<FireArmRoundClass>());
}
roundClassData[0].Add(round.RoundClass);
currentCapacity++;
testCamoCodes((FVRPhysicalObject)(object)round);
((FVRPhysicalObject)round).m_isVisible = false;
Object.Destroy((Object)(object)((Component)round).gameObject);
putRoundsInDisplay();
}
}
public void setDisplayMag(FVRPhysicalObject obj)
{
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01de: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
if (currentCapacity == 0)
{
Object.Destroy((Object)(object)((Component)obj).gameObject);
return;
}
if ((Object)(object)displayMag != (Object)null)
{
Object.Destroy((Object)(object)((Component)displayMag).gameObject);
}
if (!((Object)(object)obj == (Object)null))
{
AmmoPouch_Helpers.fillContainer(obj, getNewClassData(), container);
obj.ConfigureFromFlagDic(camoCodes);
Rigidbody component = ((FVRInteractiveObject)obj).GameObject.GetComponent<Rigidbody>();
component.isKinematic = true;
component.detectCollisions = false;
((FVRInteractiveObject)obj).GameObject.transform.SetParent(displayMagContainer);
if ((Object)(object)((FVRInteractiveObject)obj).QBPoseOverride != (Object)null)
{
((FVRInteractiveObject)obj).GameObject.transform.localPosition = -((FVRInteractiveObject)obj).QBPoseOverride.localPosition;
((FVRInteractiveObject)obj).GameObject.transform.localRotation = ((FVRInteractiveObject)obj).QBPoseOverride.localRotation;
}
else if ((Object)(object)((FVRInteractiveObject)obj).PoseOverride != (Object)null)
{
((FVRInteractiveObject)obj).GameObject.transform.localPosition = -((FVRInteractiveObject)obj).PoseOverride.localPosition;
((FVRInteractiveObject)obj).GameObject.transform.localRotation = ((FVRInteractiveObject)obj).PoseOverride.localRotation;
}
else
{
((FVRInteractiveObject)obj).GameObject.transform.localPosition = default(Vector3);
((FVRInteractiveObject)obj).GameObject.transform.localRotation = Quaternion.identity;
}
switch (container)
{
case ContainerType.Round:
{
Transform transform3 = ((FVRInteractiveObject)obj).GameObject.transform;
transform3.localPosition += new Vector3(0f, 0.045f, 0f);
break;
}
case ContainerType.SpeedLoader:
{
Transform transform2 = ((FVRInteractiveObject)obj).GameObject.transform;
transform2.localPosition += new Vector3(0f, 0.03f, 0f);
break;
}
default:
{
Transform transform = ((FVRInteractiveObject)obj).GameObject.transform;
transform.localPosition += new Vector3(0f, 0.015f, 0f);
break;
}
}
((FVRInteractiveObject)obj).GameObject.layer = LayerMask.NameToLayer("Default");
displayMag = obj;
}
}
public List<FireArmRoundClass> getNewClassData()
{
if (container == ContainerType.Round || currentCapacity == 0)
{
return new List<FireArmRoundClass>();
}
return roundClassData[currentCapacity - 1];
}
public List<FireArmRoundClass> removeRoundClassData()
{
List<FireArmRoundClass> newClassData = getNewClassData();
currentRoundCapacity = Math.Max(0, currentRoundCapacity - newClassData.Count);
roundClassData.RemoveAt(roundClassData.Count - 1);
currentCapacity--;
return newClassData;
}
public FVRPhysicalObject duplicateDisplayMag()
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
GameObject val = ((!((Object)(object)displayMag != (Object)null)) ? Object.Instantiate<GameObject>(((AnvilAsset)IM.OD[lastObjId]).GetGameObject(), displayMagContainer.position, displayMagContainer.rotation) : Object.Instantiate<GameObject>(((AnvilAsset)displayMag.ObjectWrapper).GetGameObject(), ((FVRInteractiveObject)displayMag).Transform.position, ((FVRInteractiveObject)displayMag).Transform.rotation));
return val.GetComponent<FVRPhysicalObject>();
}
public FVRPhysicalObject removeDisplayMag(FVRViveHand hand)
{
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)displayMag == (Object)null && currentCapacity > 0)
{
updateDisplayMag();
}
else if ((Object)(object)displayMag == (Object)null)
{
return null;
}
FVRPhysicalObject val = null;
if (container != 0)
{
val = duplicateDisplayMag();
}
FVRPhysicalObject val2 = displayMag;
displayMagContainer.DetachChildren();
displayMag = null;
Rigidbody component = ((FVRInteractiveObject)val2).GameObject.GetComponent<Rigidbody>();
component.isKinematic = false;
component.detectCollisions = true;
((FVRInteractiveObject)val2).GameObject.layer = LayerMask.NameToLayer("Interactable");
if (container == ContainerType.Round)
{
int num = Math.Min(val2: (!((FVRInteractiveObject)this).IsHeld) ? ((FVRFireArmRound)val2).GetNumRoundsPulled(hand) : proxyCount, val1: proxyCount);
List<FireArmRoundClass> list = roundClassData[0];
FVRFireArmRound component2 = Object.Instantiate<GameObject>(((AnvilAsset)AM.GetRoundSelfPrefab(base.RoundType, list[currentCapacity - 1])).GetGameObject(), ((Component)displayMagContainer).transform.position, ((Component)displayMagContainer).transform.rotation).GetComponent<FVRFireArmRound>();
for (int num2 = currentCapacity - 2; num2 >= Math.Max(0, currentCapacity - num); num2--)
{
component2.AddProxy(list[num2], AM.GetRoundSelfPrefab(base.RoundType, list[num2]));
}
component2.UpdateProxyDisplay();
((FVRPhysicalObject)component2).ConfigureFromFlagDic(camoCodes);
Object.Destroy((Object)(object)((FVRInteractiveObject)val2).GameObject);
val2 = (FVRPhysicalObject)(object)component2;
currentCapacity -= component2.ProxyRounds.Count + 1;
putRoundsInDisplay();
}
else
{
List<FireArmRoundClass> classData = removeRoundClassData();
AmmoPouch_Helpers.fillContainer(val, classData, container);
if (currentCapacity > 0)
{
setDisplayMag(val);
}
else
{
Object.Destroy((Object)(object)((Component)val).gameObject);
}
}
UI.updateDisplay();
return val2;
}
public void putRoundsInDisplay()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
if (currentCapacity != 0)
{
List<FireArmRoundClass> list = roundClassData[0];
FVRFireArmRound component = Object.Instantiate<GameObject>(((AnvilAsset)AM.GetRoundSelfPrefab(base.RoundType, list[currentCapacity - 1])).GetGameObject(), ((Component)displayMagContainer).transform.position, ((Component)displayMagContainer).transform.rotation).GetComponent<FVRFireArmRound>();
for (int num = currentCapacity - 2; num >= Math.Max(0, currentCapacity - proxyCount); num--)
{
component.AddProxy(list[num], AM.GetRoundSelfPrefab(base.RoundType, list[num]));
}
component.UpdateProxyDisplay();
setDisplayMag((FVRPhysicalObject)(object)component);
}
}
private bool basicChecks(FVRPhysicalObject mag)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
if (object.Equals(mag, null))
{
return false;
}
if ((Object)(object)mag != (Object)null && !((FVRInteractiveObject)mag).IsHeld && (int)mag.Size == 0 && object.Equals(mag.m_quickbeltSlot, null))
{
if (currentCapacity >= totalCapacity)
{
return currentCapacity == 0;
}
return true;
}
return false;
}
public void putDisplayMagInHand(FVRViveHand hand)
{
FVRPhysicalObject val = removeDisplayMag(hand);
if (!((Object)(object)val == (Object)null))
{
if ((Object)(object)hand != (Object)null)
{
hand.ForceSetInteractable((FVRInteractiveObject)(object)val);
}
val.SetQuickBeltSlot((FVRQuickBeltSlot)null);
if ((Object)(object)hand != (Object)null)
{
((FVRInteractiveObject)val).BeginInteraction(hand);
}
}
}
public override void BeginInteraction(FVRViveHand hand)
{
if (((FVRInteractiveObject)this).IsHeld && !((FVRPhysicalObject)this).m_isHardnessed)
{
if (currentCapacity > 0)
{
putDisplayMagInHand(hand);
return;
}
((FVRInteractiveObject)this).ForceBreakInteraction();
if ((Object)(object)hand != (Object)null)
{
hand.ForceSetInteractable((FVRInteractiveObject)(object)this);
((FVRInteractiveObject)this).BeginInteraction(hand);
}
}
else if (((FVRPhysicalObject)this).m_isHardnessed)
{
if (currentCapacity > 0)
{
putDisplayMagInHand(hand);
}
else
{
((FVRFireArmMagazine)this).BeginInteraction(hand);
}
}
else
{
((FVRFireArmMagazine)this).BeginInteraction(hand);
}
}
public void collisionTest(Collider col)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0316: Unknown result type (might be due to invalid IL or missing references)
//IL_031b: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
//IL_025a: Unknown result type (might be due to invalid IL or missing references)
//IL_025f: Unknown result type (might be due to invalid IL or missing references)
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_022d: Unknown result type (might be due to invalid IL or missing references)
Speedloader component = ((Component)col).gameObject.GetComponent<Speedloader>();
FVRFireArmClip component2 = ((Component)col).gameObject.GetComponent<FVRFireArmClip>();
FVRFireArmMagazine component3 = ((Component)col).gameObject.GetComponent<FVRFireArmMagazine>();
FVRFireArmRound component4 = ((Component)col).gameObject.GetComponent<FVRFireArmRound>();
ContainerType containerType;
FireArmRoundType val;
FVRPhysicalObject val2;
string itemID;
if (basicChecks((FVRPhysicalObject)(object)component))
{
containerType = ContainerType.SpeedLoader;
val = component.Chambers[0].Type;
val2 = (FVRPhysicalObject)(object)component;
itemID = ((FVRPhysicalObject)component).ObjectWrapper.ItemID;
}
else if (basicChecks((FVRPhysicalObject)(object)component2) && (Object)(object)component2.FireArm == (Object)null)
{
containerType = ContainerType.Clip;
val = component2.RoundType;
val2 = (FVRPhysicalObject)(object)component2;
itemID = ((FVRPhysicalObject)component2).ObjectWrapper.ItemID;
}
else if (basicChecks((FVRPhysicalObject)(object)component3) && (Object)(object)component3.FireArm == (Object)null && !(component3 is AmmoPouch))
{
containerType = ContainerType.Magazine;
val = component3.RoundType;
val2 = (FVRPhysicalObject)(object)component3;
itemID = ((FVRPhysicalObject)component3).ObjectWrapper.ItemID;
}
else
{
if (!basicChecks((FVRPhysicalObject)(object)component4))
{
return;
}
containerType = ContainerType.Round;
val = component4.RoundType;
val2 = (FVRPhysicalObject)(object)component4;
itemID = ((FVRPhysicalObject)component4).ObjectWrapper.ItemID;
}
if ((lockID && !lastObjId.Equals(itemID) && container != 0) || (lockID && container == ContainerType.Round && base.RoundType != val))
{
return;
}
if (currentCapacity == 0)
{
currentRoundCapacity = 0;
bool flag = true;
if ((Object)(object)component4 != (Object)null)
{
flag = base.RoundType != component4.RoundType;
}
lastObjId = val2.ObjectWrapper.ItemID;
switch (containerType)
{
case ContainerType.SpeedLoader:
container = ContainerType.SpeedLoader;
containerCapacity = component.Chambers.Count;
base.RoundType = component.Chambers[0].Type;
totalCapacity = speedLoaderCapacity;
addSpeedLoader(component);
break;
case ContainerType.Clip:
containerCapacity = component2.m_capacity;
container = ContainerType.Clip;
base.RoundType = component2.RoundType;
totalCapacity = clipCapacity;
addClip(component2);
break;
case ContainerType.Magazine:
containerCapacity = component3.m_capacity;
container = ContainerType.Magazine;
base.RoundType = component3.RoundType;
totalCapacity = magazineCapacity;
addMag(component3);
break;
case ContainerType.Round:
containerCapacity = 1;
container = ContainerType.Round;
base.RoundType = component4.RoundType;
totalCapacity = roundCapacity;
proxyCap = component4.MaxPalmedAmount;
addRound(component4);
if (flag)
{
proxyCount = 1;
}
break;
}
}
else if (container == ContainerType.Round && containerType == container && val == base.RoundType)
{
addRound(component4);
}
else if (lastObjId.Equals(itemID) && currentCapacity < totalCapacity)
{
switch (containerType)
{
case ContainerType.SpeedLoader:
addSpeedLoader(component);
break;
case ContainerType.Clip:
addClip(component2);
break;
case ContainerType.Magazine:
addMag(component3);
break;
case ContainerType.Round:
addRound(component4);
break;
}
}
else if (base.RoundType == val)
{
stealRounds(val2, containerType);
}
UI.updateDisplay();
}
public void stealRounds(FVRPhysicalObject obj, ContainerType type)
{
}
public override void ConfigureFromFlagDic(Dictionary<string, string> f)
{
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
((FVRPhysicalObject)this).ConfigureFromFlagDic(f);
string empty = string.Empty;
string empty2 = string.Empty;
empty = "currentCapacity";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
currentCapacity = Convert.ToInt32(empty2);
}
empty = "currentRoundCapacity";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
currentRoundCapacity = Convert.ToInt32(empty2);
}
empty = "containerCapacity";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
containerCapacity = Convert.ToInt32(empty2);
}
empty = "containerType";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
container = (ContainerType)Convert.ToInt32(empty2);
switch (container)
{
case ContainerType.Magazine:
totalCapacity = magazineCapacity;
break;
case ContainerType.Clip:
totalCapacity = clipCapacity;
break;
case ContainerType.SpeedLoader:
totalCapacity = speedLoaderCapacity;
break;
case ContainerType.Round:
totalCapacity = roundCapacity;
break;
}
}
empty = "sortMethod";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
sortMethod = (PouchSorting)Convert.ToInt32(empty2);
}
empty = "roundClassData";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
roundClassData = AmmoPouch_Helpers.roundClassConfigure(empty2);
}
empty = "lastObjID";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
lastObjId = empty2;
}
empty = "proxyCount";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
proxyCount = Convert.ToInt32(empty2);
}
empty = "proxyCap";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
proxyCap = Convert.ToInt32(empty2);
}
empty = "lockID";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
lockID = Convert.ToBoolean(empty2);
}
empty = "roundType";
if (f.ContainsKey(empty))
{
empty2 = f[empty];
base.RoundType = (FireArmRoundType)Convert.ToInt32(empty2);
}
foreach (string item in f.Keys.Where((string i) => i.StartsWith("item_nga_mc")).ToList())
{
camoCodes.Add(item.Substring(5), f[item]);
}
updateDisplayMag();
UI.updateDisplay();
UI.setContainerText(container);
}
public override Dictionary<string, string> GetFlagDic()
{
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Expected I4, but got Unknown
Dictionary<string, string> flagDic = ((FVRPhysicalObject)this).GetFlagDic();
flagDic.Add("currentCapacity", currentCapacity.ToString());
flagDic.Add("currentRoundCapacity", currentRoundCapacity.ToString());
flagDic.Add("containerCapacity", containerCapacity.ToString());
int num = (int)container;
flagDic.Add("containerType", num.ToString());
num = (int)sortMethod;
flagDic.Add("sortMethod", num.ToString());
flagDic.Add("roundClassData", AmmoPouch_Helpers.roundClassGet(roundClassData));
flagDic.Add("lastObjID", lastObjId);
flagDic.Add("proxyCount", proxyCount.ToString());
flagDic.Add("proxyCap", proxyCap.ToString());
flagDic.Add("lockID", lockID.ToString());
flagDic.Add("roundType", ((int)base.RoundType).ToString());
foreach (string key in camoCodes.Keys)
{
flagDic.Add("item_" + key, camoCodes[key]);
}
return flagDic;
}
}
public static class AmmoPouch_Helpers
{
private const char roundSeparator = ',';
private const char magSeparator = ';';
public static int CompareMagContainersAscending(List<FireArmRoundClass> x, List<FireArmRoundClass> y)
{
if (x.Count < y.Count)
{
return -1;
}
if (x.Count == y.Count)
{
return 0;
}
return 1;
}
public static int CompareMagContainersDescending(List<FireArmRoundClass> x, List<FireArmRoundClass> y)
{
if (x.Count < y.Count)
{
return 1;
}
if (x.Count == y.Count)
{
return 0;
}
return -1;
}
public static int CompareSLContainersAscending(List<FireArmRoundClass> x, List<FireArmRoundClass> y)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (x.Count != y.Count)
{
return CompareMagContainersAscending(x, y);
}
int num = 0;
int num2 = 0;
FireArmRoundClass val = (FireArmRoundClass)(-1);
for (int i = 0; i < x.Count; i++)
{
if (x[i] != val)
{
num++;
}
if (y[i] != val)
{
num2++;
}
}
if (num < num2)
{
return -1;
}
if (num == num2)
{
return 0;
}
return 1;
}
public static int CompareSLContainersDescending(List<FireArmRoundClass> x, List<FireArmRoundClass> y)
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
if (x.Count != y.Count)
{
return CompareMagContainersDescending(x, y);
}
int num = 0;
int num2 = 0;
FireArmRoundClass val = (FireArmRoundClass)(-1);
for (int i = 0; i < x.Count; i++)
{
if (x[i] != val)
{
num++;
}
if (y[i] != val)
{
num2++;
}
}
if (num < num2)
{
return 1;
}
if (num == num2)
{
return 0;
}
return -1;
}
public static void fillContainer(FVRPhysicalObject obj, List<FireArmRoundClass> classData, AmmoPouch.ContainerType container)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
switch (container)
{
case AmmoPouch.ContainerType.SpeedLoader:
fillSpeedLoader((Speedloader)obj, classData);
break;
case AmmoPouch.ContainerType.Clip:
fillClip((FVRFireArmClip)obj, classData);
break;
case AmmoPouch.ContainerType.Magazine:
fillMagazine((FVRFireArmMagazine)obj, classData);
break;
}
}
public static void fillClip(FVRFireArmClip clip, List<FireArmRoundClass> classData)
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
while (clip.m_numRounds > 0)
{
clip.LoadedRounds[clip.m_numRounds - 1] = null;
clip.m_numRounds--;
}
for (int num = Mathf.Min(clip.m_capacity, classData.Count) - 1; num >= 0; num--)
{
clip.AddRound(classData[num], false, false);
}
clip.UpdateBulletDisplay();
}
public static void fillMagazine(FVRFireArmMagazine mag, List<FireArmRoundClass> classData)
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
mag.m_numRounds = 0;
for (int num = Mathf.Min(classData.Count, mag.m_capacity) - 1; num >= 0; num--)
{
mag.AddRound(classData[num], false, false);
}
mag.UpdateBulletDisplay();
}
public static void fillSpeedLoader(Speedloader loader, List<FireArmRoundClass> classData)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Invalid comparison between Unknown and I4
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
for (int i = 0; i < loader.Chambers.Count; i++)
{
loader.Chambers[i].Unload();
}
for (int j = 0; j < classData.Count; j++)
{
if ((int)classData[j] != -1)
{
loader.Chambers[j].Load(classData[j], false);
}
}
}
public static void printRoundClassData(List<FireArmRoundClass> data)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
string text = "";
for (int i = 0; i < data.Count; i++)
{
string text2 = text;
FireArmRoundClass val = data[i];
text = text2 + ((object)(FireArmRoundClass)(ref val)).ToString() + " ";
}
Console.WriteLine(text);
}
public static List<List<FireArmRoundClass>> roundClassConfigure(string s)
{
Console.WriteLine("Configure from: " + s);
List<List<FireArmRoundClass>> list = new List<List<FireArmRoundClass>>();
if (string.IsNullOrEmpty(s))
{
return list;
}
string[] array = s.Split(new char[1] { ';' });
foreach (string text in array)
{
List<FireArmRoundClass> list2 = new List<FireArmRoundClass>();
string[] array2 = text.Split(new char[1] { ',' });
if (!string.IsNullOrEmpty(text))
{
string[] array3 = array2;
for (int j = 0; j < array3.Length; j++)
{
if (int.TryParse(array3[j], out var result))
{
list2.Add((FireArmRoundClass)result);
}
}
}
list.Add(list2);
}
return list;
}
public static string roundClassGet(List<List<FireArmRoundClass>> data)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected I4, but got Unknown
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < data.Count; i++)
{
for (int j = 0; j < data[i].Count; j++)
{
stringBuilder.Append(((int)data[i][j]).ToString());
if (j < data[i].Count - 1)
{
stringBuilder.Append(',');
}
}
if (i < data.Count - 1)
{
stringBuilder.Append(';');
}
}
return stringBuilder.ToString();
}
}
public class AmmoPouch_Hooks
{
public class AmmoReloader
{
[HarmonyPatch(typeof(FVRFireArmMagazine), "ReloadMagWithType")]
[HarmonyPrefix]
private static bool ReloadWithMagFix(FVRFireArmMagazine __instance, FireArmRoundClass rClass)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
if (__instance is AmmoPouch)
{
((AmmoPouch)(object)__instance).refillWithType(rClass);
return false;
}
return true;
}
}
public class PouchSpawning
{
[HarmonyPatch(typeof(TNH_ObjectConstructor), "ButtonClicked")]
[HarmonyPrefix]
private static void SpawnObjectFix(TNH_ObjectConstructor __instance, int i)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Invalid comparison between Unknown and I4
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Invalid comparison between Unknown and I4
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
if (i != 3 || (int)__instance.State != 2)
{
return;
}
Console.WriteLine("i = 3 and Confirm state");
if ((int)__instance.M.GetObjectTable(__instance.m_poolEntries[__instance.m_selectedEntry].TableDef).GetRandomObject().Category == 1 && Ammo_Pouch_Scripts.AmmoPouch_CanSpawnInTnH.Value)
{
Console.WriteLine("Is firearm and valid");
int num = __instance.m_poolEntries[__instance.m_selectedEntry].GetCost(__instance.M.EquipmentMode) + __instance.m_poolAddedCost[__instance.m_selectedEntry];
if (__instance.M.GetNumTokens() >= num)
{
Console.WriteLine("Enough cost, attempting to spawn");
GameObject val = Object.Instantiate<GameObject>(((AnvilAsset)IM.OD["small_ammo_pouch"]).GetGameObject(), __instance.SpawnPoint_Mag);
__instance.M.AddObjectToTrackedList(val);
}
}
}
[HarmonyPatch(typeof(TNH_SupplyPoint), "ConfigureAtBeginning")]
[HarmonyPostfix]
private static void SpawnInitPouch(TNH_SupplyPoint __instance)
{
if (Ammo_Pouch_Scripts.AmmoPouch_CanSpawnInTnH.Value)
{
GameObject val = Object.Instantiate<GameObject>(((AnvilAsset)IM.OD["small_ammo_pouch"]).GetGameObject(), __instance.SpawnPoints_SmallItem[0]);
__instance.M.AddObjectToTrackedList(val);
}
}
}
}
public class AmmoPouch_Reception : MonoBehaviour
{
public AmmoPouch pouch;
public void OnTriggerStay(Collider other)
{
pouch.collisionTest(other);
}
}
public class AmmoPouch_UI : MonoBehaviour
{
[HideInInspector]
public enum UIPage
{
Default,
Settings,
Cheats
}
public Text CapacityTxt;
public AudioEvent SortSound;
public AudioEvent BtnSound;
[Header("Default Page")]
public GameObject DefaultPage;
public Text ContainerTypeTxt;
public GameObject SettingsBtn;
public GameObject ResetBtn;
public GameObject ResetConfirmBtn;
public GameObject ResetCancelBtn;
public GameObject IDLockOffBtn;
public GameObject IDLockOnBtn;
[Header("Settings")]
public GameObject SettingsPage;
public Text SettingsContainerTxt;
public GameObject SortingTab;
public OptionsPanel_ButtonSet SortingSet;
public GameObject[] SortButtons;
public int _selectedSort = 1;
public GameObject ProxyTab;
public Text ProxyCount;
public GameObject AddProxyBtn;
public GameObject SubProxyBtn;
public GameObject ReturnBtn;
public AmmoPouch AmmoPouch;
[HideInInspector]
private UIPage currentPage;
[HideInInspector]
private const int LIFO = 0;
private const int RETENTION = 1;
private const int FULLEST = 2;
private const int EMPTIEST = 3;
public void resetCheck()
{
ResetBtn.SetActive(false);
ResetCancelBtn.SetActive(true);
ResetConfirmBtn.SetActive(true);
}
public void resetConfirm()
{
ResetBtn.SetActive(true);
ResetCancelBtn.SetActive(false);
ResetConfirmBtn.SetActive(false);
AmmoPouch.resetPouch();
}
public void resetCancel()
{
ResetBtn.SetActive(true);
ResetCancelBtn.SetActive(false);
ResetConfirmBtn.SetActive(false);
}
public void SetDefaultUI()
{
currentPage = UIPage.Default;
SettingsPage.SetActive(false);
DefaultPage.SetActive(true);
SettingsBtn.SetActive(true);
ResetBtn.SetActive(true);
ResetConfirmBtn.SetActive(false);
ResetCancelBtn.SetActive(false);
setLockIDColor();
}
public void SetSettingsUI()
{
currentPage = UIPage.Settings;
DefaultPage.SetActive(false);
SettingsPage.SetActive(true);
setContainerText(AmmoPouch.container);
switch (AmmoPouch.container)
{
case AmmoPouch.ContainerType.SpeedLoader:
case AmmoPouch.ContainerType.Clip:
case AmmoPouch.ContainerType.Magazine:
case AmmoPouch.ContainerType.None:
SortingTab.SetActive(true);
ProxyTab.SetActive(false);
setSortingButton(AmmoPouch.sortMethod);
break;
case AmmoPouch.ContainerType.Round:
SortingTab.SetActive(false);
ProxyTab.SetActive(true);
updateProxyText();
break;
}
ReturnBtn.SetActive(true);
}
public void updateDisplay()
{
switch (currentPage)
{
case UIPage.Default:
SetDefaultUI();
break;
case UIPage.Settings:
SetSettingsUI();
break;
}
setCapacityTxt();
setContainerText(AmmoPouch.container);
}
public void Start()
{
SetDefaultUI();
}
public void setLockIDColor()
{
IDLockOnBtn.SetActive(AmmoPouch.lockID);
IDLockOffBtn.SetActive(!AmmoPouch.lockID);
}
public void setCapacityTxt()
{
if (AmmoPouch.sortMethod != AmmoPouch.PouchSorting.Retention)
{
CapacityTxt.text = AmmoPouch.currentCapacity + " / " + AmmoPouch.totalCapacity;
return;
}
CapacityTxt.text = AmmoPouch.fullMags() + " (" + AmmoPouch.currentCapacity + ") / " + AmmoPouch.totalCapacity;
}
public void setSortingButton(AmmoPouch.PouchSorting sort)
{
switch (sort)
{
case AmmoPouch.PouchSorting.LIFO:
SortingSet.SetSelectedButton(0);
break;
case AmmoPouch.PouchSorting.Retention:
SortingSet.SetSelectedButton(1);
break;
case AmmoPouch.PouchSorting.Fullest:
SortingSet.SetSelectedButton(2);
break;
default:
SortingSet.SetSelectedButton(3);
break;
}
}
public void sortLIFO()
{
SortingSet.SetSelectedButton(0);
AmmoPouch.sortLIFO();
}
public void sortRetention()
{
SortingSet.SetSelectedButton(1);
AmmoPouch.sortRetention();
}
public void sortFullest()
{
SortingSet.SetSelectedButton(2);
AmmoPouch.sortFullestFirst();
}
public void sortEmptiest()
{
SortingSet.SetSelectedButton(3);
AmmoPouch.sortEmptiestFirst();
}
public void lockIDToggle()
{
AmmoPouch.lockID = !AmmoPouch.lockID;
setLockIDColor();
}
public void addProxy()
{
AmmoPouch.attemptAddProxy();
updateProxyText();
}
public void subProxy()
{
AmmoPouch.attemptSubProxy();
updateProxyText();
}
public void updateProxyText()
{
ProxyCount.text = AmmoPouch.proxyCount.ToString() ?? "";
}
public void setContainerText(AmmoPouch.ContainerType type)
{
switch (type)
{
case AmmoPouch.ContainerType.Magazine:
ContainerTypeTxt.text = "Magazines";
SettingsContainerTxt.text = "Container: \nMagazine";
break;
case AmmoPouch.ContainerType.SpeedLoader:
ContainerTypeTxt.text = "Speed loaders";
SettingsContainerTxt.text = "Container: \nSpeedloader";
break;
case AmmoPouch.ContainerType.Clip:
ContainerTypeTxt.text = "Clips";
SettingsContainerTxt.text = "Container: \nClip";
break;
case AmmoPouch.ContainerType.Round:
ContainerTypeTxt.text = "Rounds";
SettingsContainerTxt.text = "Container: \nRound";
break;
default:
ContainerTypeTxt.text = "Empty";
SettingsContainerTxt.text = "Container: \nEmpty";
break;
}
}
}
[BepInPlugin("h3vr.Ammo_Pouch_Scripts", "Ammo Pouch Scripts", "0.1.5")]
public class Ammo_Pouch_Scripts : BaseUnityPlugin
{
public static ConfigEntry<bool> AmmoPouch_CanSpawnInTnH;
public static ConfigEntry<bool> AmmoPouch_CanSpawnInSR;
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
AmmoPouch_CanSpawnInTnH = ((BaseUnityPlugin)this).Config.Bind<bool>("Ammo Pouch", "Can Spawn in TnH?", true, "If true, will spawn ammo pouches with firearms.");
AmmoPouch_CanSpawnInSR = ((BaseUnityPlugin)this).Config.Bind<bool>("Ammo Pouch", "Can Spawn in Supply Raid?", true, "If true, will spawn ammo pouches with firearms.");
Logger = ((BaseUnityPlugin)this).Logger;
Harmony.CreateAndPatchAll(typeof(AmmoPouch_Hooks.AmmoReloader), (string)null);
Harmony.CreateAndPatchAll(typeof(AmmoPouch_Hooks.PouchSpawning), (string)null);
try
{
Harmony.CreateAndPatchAll(typeof(SupplyRaidPatch), (string)null);
}
catch
{
Logger.LogInfo((object)"Supply raid not found.");
}
}
}
public class Grenade_Pouch : FVRPhysicalObject
{
[HideInInspector]
public bool isEmpty = true;
[HideInInspector]
public string itemID = "";
[HideInInspector]
public bool isRecharging;
public float rechargeTime = 45f;
[HideInInspector]
public float currentTimer;
[HideInInspector]
public FVRPhysicalObject grenade;
[HideInInspector]
public Dictionary<string, string> camoCodes = new Dictionary<string, string>();
public Grenade_Pouch_UI ui;
public Grenade_Pouch_Reception reception;
public Transform displayContainer;
public Material hologramMat;
public void clear()
{
isEmpty = true;
isRecharging = false;
if ((Object)(object)grenade != (Object)null)
{
Object.Destroy((Object)(object)((Component)grenade).gameObject);
}
reception.activate();
}
public void rechargeGrenade()
{
}
public void updateDisplay()
{
if (isEmpty)
{
if ((Object)(object)grenade != (Object)null)
{
Object.Destroy((Object)(object)((Component)grenade).gameObject);
}
return;
}
if ((Object)(object)grenade != (Object)null)
{
Object.Destroy((Object)(object)((Component)grenade).gameObject);
}
putObjInDisplay(generateGrenade());
if (isRecharging)
{
setHologram();
}
}
public FVRPhysicalObject generateGrenade()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
FVRPhysicalObject component = Object.Instantiate<GameObject>(((AnvilAsset)IM.OD[itemID]).GetGameObject(), displayContainer.position, displayContainer.rotation).GetComponent<FVRPhysicalObject>();
component.ConfigureFromFlagDic(camoCodes);
return component;
}
public void setHologram()
{
MeshRenderer[] componentsInChildren = ((Component)grenade).gameObject.GetComponentsInChildren<MeshRenderer>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
((Renderer)componentsInChildren[i]).material = hologramMat;
}
}
public void setGrenade(FVRPhysicalObject obj)
{
reception.deactivate();
itemID = obj.m_IDSpawnedFrom.ItemID;
isEmpty = false;
isRecharging = false;
camoCodes.Clear();
Dictionary<string, string> flagDic = obj.GetFlagDic();
foreach (string item in flagDic.Keys.Where((string key) => key.StartsWith("nga_mc")).ToList())
{
camoCodes.Add(item, flagDic[item]);
}
if ((Object)(object)grenade != (Object)null)
{
Object.Destroy((Object)(object)((Component)grenade).gameObject);
}
obj = generateGrenade();
putObjInDisplay(obj);
}
public void putObjInDisplay(FVRPhysicalObject obj)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
Rigidbody component = ((Component)obj).GetComponent<Rigidbody>();
component.isKinematic = true;
component.detectCollisions = false;
((FVRInteractiveObject)obj).GameObject.transform.SetParent(displayContainer);
grenade = obj;
if ((Object)(object)((FVRInteractiveObject)obj).QBPoseOverride != (Object)null)
{
((FVRInteractiveObject)obj).GameObject.transform.localPosition = -((FVRInteractiveObject)obj).QBPoseOverride.localPosition;
((FVRInteractiveObject)obj).GameObject.transform.localRotation = ((FVRInteractiveObject)obj).QBPoseOverride.localRotation;
}
else if ((Object)(object)((FVRInteractiveObject)obj).PoseOverride != (Object)null)
{
((FVRInteractiveObject)obj).GameObject.transform.localPosition = -((FVRInteractiveObject)obj).PoseOverride.localPosition;
((FVRInteractiveObject)obj).GameObject.transform.localRotation = ((FVRInteractiveObject)obj).PoseOverride.localRotation;
}
else
{
((FVRInteractiveObject)obj).GameObject.transform.localPosition = default(Vector3);
((FVRInteractiveObject)obj).GameObject.transform.localRotation = Quaternion.identity;
}
}
public void PutGrenadeInHand(FVRViveHand hand)
{
FVRPhysicalObject val = generateGrenade();
if ((Object)(object)hand != (Object)null)
{
hand.ForceSetInteractable((FVRInteractiveObject)(object)val);
val.SetQuickBeltSlot((FVRQuickBeltSlot)null);
((FVRInteractiveObject)val).BeginInteraction(hand);
}
isRecharging = true;
currentTimer = rechargeTime;
updateDisplay();
}
public void Start()
{
((FVRInteractiveObject)this).Start();
ui.updateUI();
ref Material reference = ref hologramMat;
Object obj = Resources.Load("Hologram", typeof(Material));
reference = (Material)(object)((obj is Material) ? obj : null);
}
public void Update()
{
if (!isEmpty && isRecharging)
{
currentTimer -= Time.deltaTime;
if (currentTimer < 0f)
{
rechargeGrenade();
}
ui.updateTimer();
}
}
public override void BeginInteraction(FVRViveHand hand)
{
if (((FVRInteractiveObject)this).IsHeld && !base.m_isHardnessed)
{
if (!isEmpty && !isRecharging)
{
PutGrenadeInHand(hand);
return;
}
((FVRInteractiveObject)this).ForceBreakInteraction();
if ((Object)(object)hand != (Object)null)
{
hand.ForceSetInteractable((FVRInteractiveObject)(object)this);
((FVRInteractiveObject)this).BeginInteraction(hand);
}
}
else if (base.m_isHardnessed)
{
if (!isEmpty && !isRecharging)
{
PutGrenadeInHand(hand);
}
else
{
((FVRPhysicalObject)this).BeginInteraction(hand);
}
}
else
{
((FVRPhysicalObject)this).BeginInteraction(hand);
}
}
public override Dictionary<string, string> GetFlagDic()
{
return ((FVRPhysicalObject)this).GetFlagDic();
}
public override void ConfigureFromFlagDic(Dictionary<string, string> f)
{
((FVRPhysicalObject)this).ConfigureFromFlagDic(f);
}
}
public class Grenade_Pouch_Reception : MonoBehaviour
{
public Grenade_Pouch pouch;
public static string[] grenadeTypes = new string[5]
{
typeof(PinnedGrenade).ToString(),
typeof(FVRFusedThrowable).ToString(),
typeof(Molotov).ToString(),
typeof(FVRGrenade).ToString(),
typeof(FVRCappedGrenade).ToString()
};
public void OnTriggerStay(Collider col)
{
if (!pouch.isEmpty)
{
deactivate();
}
FVRPhysicalObject component = (FVRPhysicalObject)(object)((Component)col).gameObject.GetComponent<PinnedGrenade>();
for (int i = 0; i < grenadeTypes.Length; i++)
{
Component component2 = ((Component)col).gameObject.GetComponent(grenadeTypes[i]);
component = (FVRPhysicalObject)(object)((component2 is FVRPhysicalObject) ? component2 : null);
if (testObj(component))
{
break;
}
}
}
public bool testObj(FVRPhysicalObject obj)
{
if ((Object)(object)obj != (Object)null)
{
pouch.setGrenade(obj);
return true;
}
return false;
}
public void deactivate()
{
((Component)this).gameObject.SetActive(false);
}
public void activate()
{
((Component)this).gameObject.SetActive(true);
}
}
public class Grenade_Pouch_UI : MonoBehaviour
{
public Grenade_Pouch pouch;
public FVRPointableButton clear;
public FVRPointableButton clearConfirm;
public FVRPointableButton clearCancel;
public Text timer;
public bool showConfirm;
public void Start()
{
showConfirm = false;
updateUI();
}
public void resetCheck()
{
showConfirm = true;
updateUI();
}
public void resetCancel()
{
showConfirm = false;
updateUI();
}
public void resetConfirm()
{
pouch.clear();
showConfirm = false;
updateUI();
}
public void updateUI()
{
if (showConfirm)
{
((Component)clearConfirm).gameObject.SetActive(true);
((Component)clearCancel).gameObject.SetActive(true);
((Component)clear).gameObject.SetActive(false);
}
else
{
((Component)clearConfirm).gameObject.SetActive(false);
((Component)clearCancel).gameObject.SetActive(false);
((Component)clear).gameObject.SetActive(true);
}
updateTimer();
}
public void updateTimer()
{
if (pouch.isEmpty || !pouch.isRecharging)
{
timer.text = "";
return;
}
int num = (int)Math.Ceiling(pouch.currentTimer);
if (num > 0)
{
timer.text = num.ToString();
}
else
{
timer.text = "";
}
}
}
public class SupplyRaidPatch
{
[HarmonyPatch(typeof(SR_MagazineDuplicator), "Button_Duplicate")]
[HarmonyPrefix]
private static bool pouchDuplicate(SR_MagazineDuplicator __instance, bool ___canDuplicate, FVRFireArmMagazine ___m_detectedMag, int ___costDuplicate)
{
if (___m_detectedMag is AmmoPouch && ___canDuplicate && (Object)(object)___m_detectedMag != (Object)null && (Object)(object)((Component)___m_detectedMag).gameObject != (Object)null && SR_Manager.EnoughPoints(___costDuplicate))
{
AmmoPouch ammoPouch = ___m_detectedMag as AmmoPouch;
if (ammoPouch.currentCapacity < ammoPouch.totalCapacity && ammoPouch.container != 0)
{
SR_Manager.PlayConfirmSFX();
SR_Manager.SpendPoints(___costDuplicate);
ammoPouch.duplicateMag();
}
else
{
SR_Manager.PlayFailSFX();
}
return false;
}
return true;
}
[HarmonyPatch(typeof(SR_Global), "SpawnLoot")]
[HarmonyPostfix]
private static void spawnPouch(SR_Global __instance, SR_ItemCategory itemCategory, Transform[] spawns)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
if ((int)itemCategory.type == 0 && Ammo_Pouch_Scripts.AmmoPouch_CanSpawnInSR.Value)
{
Object.Instantiate<GameObject>(((AnvilAsset)IM.OD["small_ammo_pouch"]).GetGameObject(), spawns[0]);
}
}
}
}