Decompiled source of ThirdGunSlot v1.0.0

ThirdGunSlot.dll

Decompiled 9 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using ClassWeaponSlot.Patches;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ThirdGunSlot")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+01d52404a812f386735a05a43d4398bdf77e06d7")]
[assembly: AssemblyProduct("ThirdGunSlot")]
[assembly: AssemblyTitle("ThirdGunSlot")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ThirdGunSlot
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ThirdGunSlot";

		public const string PLUGIN_NAME = "ThirdGunSlot";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ClassWeaponSlot
{
	internal static class Logger
	{
		private static readonly ManualLogSource _Logger;

		static Logger()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			_Logger = new ManualLogSource("cactus.ClassWeaponSlot");
			Logger.Sources.Add((ILogSource)(object)_Logger);
		}

		private static string Format(object msg)
		{
			return msg.ToString();
		}

		public static void Info(BepInExInfoLogInterpolatedStringHandler handler)
		{
			_Logger.LogInfo(handler);
		}

		public static void Info(string str)
		{
			_Logger.LogMessage((object)str);
		}

		public static void Info(object data)
		{
			_Logger.LogMessage((object)Format(data));
		}

		public static void Debug(BepInExDebugLogInterpolatedStringHandler handler)
		{
			_Logger.LogDebug(handler);
		}

		public static void Debug(string str)
		{
			_Logger.LogDebug((object)str);
		}

		public static void Debug(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}

		public static void Error(BepInExErrorLogInterpolatedStringHandler handler)
		{
			_Logger.LogError(handler);
		}

		public static void Error(string str)
		{
			_Logger.LogError((object)str);
		}

		public static void Error(object data)
		{
			_Logger.LogError((object)Format(data));
		}

		public static void Fatal(BepInExFatalLogInterpolatedStringHandler handler)
		{
			_Logger.LogFatal(handler);
		}

		public static void Fatal(string str)
		{
			_Logger.LogFatal((object)str);
		}

		public static void Fatal(object data)
		{
			_Logger.LogFatal((object)Format(data));
		}

		public static void Warn(BepInExWarningLogInterpolatedStringHandler handler)
		{
			_Logger.LogWarning(handler);
		}

		public static void Warn(string str)
		{
			_Logger.LogWarning((object)str);
		}

		public static void Warn(object data)
		{
			_Logger.LogWarning((object)Format(data));
		}

		[Conditional("DEBUG")]
		public static void DebugOnly(object data)
		{
			_Logger.LogDebug((object)Format(data));
		}
	}
	[BepInPlugin("cactus.ClassWeaponSlot", "ClassWeaponSlot", "1.0.0")]
	public class Plugin : BasePlugin
	{
		public Harmony m_Harmony;

		public static ConfigFile configFile;

		public static ConfigEntry<string> configEntry;

		public override void Load()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(17, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin is loaded!");
			}
			log.LogInfo(val);
			GetSettings();
			m_Harmony = new Harmony("cactus.ClassWeaponSlot");
			m_Harmony.PatchAll();
		}

		public static void GetSettings()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "cactus.ClassWeaponSlot.cfg"), true);
			configEntry = configFile.Bind<string>("General", "ArchetypeDB persistendIDs", "", "List desired persistentIDs from ArchetypeDB: xx,xx,xx,etc");
			string[] array = configEntry.Value.Split(',');
			uint[] array2 = new uint[array.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array2[i] = Convert.ToUInt32(array[i]);
				Logger.Warn("persistentID saved to array");
			}
			WeaponManager.configUIntArray = array2;
		}
	}
}
namespace ClassWeaponSlot.Patches
{
	[HarmonyPatch]
	internal class ClassWeaponSlot_Patches
	{
		[HarmonyPatch(typeof(PlayerAmmoStorage), "FillAllClips")]
		[HarmonyPostfix]
		public static void FillClips__PostFix(PlayerAmmoStorage __instance)
		{
			__instance.SetClipAmmoInSlot((InventorySlot)3, (AmmoType)2, __instance.ClassAmmo);
		}

		[HarmonyPatch(typeof(PlayerBackpack), "SetupAmmoStorageForItem")]
		[HarmonyPostfix]
		internal static void Postfix(PlayerBackpack __instance, Item item, InventorySlot slot)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)item == (Object)null) && WeaponManager.IsWeaponInToolSlot(item))
			{
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("SetupAmmoStorageForItem::Postfix on: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(item.ArchetypeName ?? "null");
				}
				Logger.Info(val);
				ItemEquippable val2 = ((Il2CppObjectBase)item).TryCast<ItemEquippable>();
				if ((Object)(object)val2 == (Object)null)
				{
					Logger.Error("SetupAmmoStorageForItem::Postfix could not cast item to ItemEquippable.");
					return;
				}
				ArchetypeDataBlock archetypeData = val2.ArchetypeData;
				float num = ((archetypeData != null) ? archetypeData.CostOfBullet : 1f);
				AmmoType ammoTypeFromSlot = PlayerAmmoStorage.GetAmmoTypeFromSlot(slot);
				__instance.AmmoStorage.SetupAmmoType(ammoTypeFromSlot, num, val2.ClipSize, -1f);
			}
		}

		[HarmonyPatch("UpdateSlotAmmoUI")]
		[HarmonyPatch(typeof(PlayerAmmoStorage), new Type[]
		{
			typeof(InventorySlotAmmo),
			typeof(int)
		})]
		[HarmonyPrefix]
		internal static bool UpdateSlotAmmoUI__2Param__Prefix(PlayerAmmoStorage __instance, InventorySlotAmmo ammo, ref int clip)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			if ((int)ammo.AmmoType != 2 || clip != 0)
			{
				return true;
			}
			BackpackItem val = default(BackpackItem);
			if (!__instance.m_playerBackpack.TryGetBackpackItem((InventorySlot)3, ref val))
			{
				Logger.Warn("PlayerAmmoStorage::UpdateSlotAmmoUI__Prefix (#2) - Could not get gear class backpack item.");
				return true;
			}
			Item instance = val.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Logger.Warn("PlayerAmmoStorage::UpdateSlotAmmoUI__Prefix (#2) - Encountered a backpack item with null Instance.");
				return true;
			}
			if (!WeaponManager.IsWeaponInToolSlot(instance))
			{
				return true;
			}
			ItemEquippable val2 = ((Il2CppObjectBase)instance).TryCast<ItemEquippable>();
			if ((Object)(object)val2 == (Object)null)
			{
				Logger.Warn("PlayerAmmoStorage::UpdateSlotAmmoUI__Prefix (#2) - Encountered an item that has been marked as a weapon in the tool slot, but could not be cast to an ItemEquippable.");
				return true;
			}
			clip = val2.GetCurrentClip();
			Logger.Warn("PlayerAmmoStorage::UpdateSlotAmmoUI__Prefix (#2) - Applied clip fix to weapon in tool slot.");
			return true;
		}

		[HarmonyPatch(typeof(PlayerAmmoStorage), "GetStorageData")]
		[HarmonyPostfix]
		public static void GetStorageData__Postfix(PlayerAmmoStorage __instance, ref pAmmoStorageData __result)
		{
			BackpackItem val = default(BackpackItem);
			if (!__instance.m_playerBackpack.TryGetBackpackItem((InventorySlot)3, ref val))
			{
				Logger.Warn("PlayerAmmoStorage::GetStorageData__Postfix - Could not get gear class backpack item.");
				return;
			}
			Item instance = val.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Logger.Warn("PlayerAmmoStorage::GetStorageData__Postfix - Encountered a backpack item with null Instance.");
			}
			else if (WeaponManager.IsWeaponInToolSlot(instance))
			{
				float num = __instance.GetClipAmmoFromSlot((InventorySlot)3) * __instance.ClassAmmo.CostOfBullet;
				((DevFloat32)(ref __result.classAmmo)).Set(num + __instance.ClassAmmo.AmmoInPack, 500f);
			}
		}

		[HarmonyPatch(typeof(PlayerAmmoStorage), "GetStorageDataForCapture")]
		[HarmonyPostfix]
		public static void GetStorageDataForCapture__Postfix(PlayerAmmoStorage __instance, ref pAmmoStorageData __result)
		{
			BackpackItem val = default(BackpackItem);
			if (!__instance.m_playerBackpack.TryGetBackpackItem((InventorySlot)3, ref val))
			{
				Logger.Warn("PlayerAmmoStorage::GetStorageDataForCapture__Postfix - Could not get gear class backpack item.");
				return;
			}
			Item instance = val.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				Logger.Warn("PlayerAmmoStorage::GetStorageDataForCapture__Postfix - Encountered a backpack item with null Instance.");
			}
			else if (WeaponManager.IsWeaponInToolSlot(instance))
			{
				float num = __instance.GetClipAmmoFromSlot((InventorySlot)3) * __instance.ClassAmmo.CostOfBullet;
				((DevFloat32)(ref __result.classAmmo)).Set(num + __instance.ClassAmmo.AmmoInPack, 500f);
			}
		}
	}
	internal class WeaponManager
	{
		public static uint[] configUIntArray = new uint[0];

		internal static bool IsWeaponInToolSlot(Item item)
		{
			if ((Object)(object)item == (Object)null)
			{
				return false;
			}
			ItemEquippable val = ((Il2CppObjectBase)item).TryCast<ItemEquippable>();
			if ((Object)(object)val == (Object)null || val.ArchetypeData == null)
			{
				return false;
			}
			return configUIntArray.Contains(((GameDataBlockBase<ArchetypeDataBlock>)(object)val.ArchetypeData).persistentID);
		}
	}
}