Decompiled source of ICanHazMoreGlowsticks v0.999999.1

ICanHazMoreGlowsticks.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using Player;

[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("ICanHazMoreGlowsticks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ICanHazMoreGlowsticks")]
[assembly: AssemblyTitle("ICanHazMoreGlowsticks")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace ICanHazMoreGlowsticks
{
	internal static class ConfigMgr
	{
		public static ConfigFile conf;

		public static ConfigEntry<int> _GlowStickCount;

		public static ConfigEntry<bool> _ICanHazMoreGlowsticks;

		public static int GlowStickCount => _GlowStickCount.Value;

		public static bool CanHazMoreGlowsticks => _ICanHazMoreGlowsticks.Value;

		static ConfigMgr()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "ICanHazMoreGlowsticks.cfg");
			Logger.Debug("cfgPath = " + text);
			conf = new ConfigFile(text, true);
			int num = 1;
			string text2 = $"({num++}) HazMoreGlowsticks";
			_GlowStickCount = conf.Bind<int>(text2, "Glow Stick Count", 256, "Number of glow sticks given upon pickup");
			_ICanHazMoreGlowsticks = conf.Bind<bool>(text2, "I Can Haz More Glowsticks", true, "I Can Haz More Glowsticks - Enable this to never run out.");
		}
	}
	public class ConsumableUtils
	{
		public static readonly uint[] GlowStickItemIds = new uint[4] { 114u, 130u, 167u, 174u };

		public static readonly uint FogRepellerItemId = 117u;

		public static bool IsGlowstick(uint itemId)
		{
			uint[] glowStickItemIds = GlowStickItemIds;
			foreach (uint num in glowStickItemIds)
			{
				if (num == itemId)
				{
					return true;
				}
			}
			return false;
		}
	}
	internal static class Logger
	{
		private static ManualLogSource m_LogSource;

		public static void SetupFromInit(ManualLogSource logSource)
		{
			m_LogSource = logSource;
		}

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

		public static void Debug(object msg)
		{
			bool flag = false;
		}

		public static void Info(object msg)
		{
			m_LogSource.LogInfo((object)Format(msg));
		}

		public static void Warn(object msg)
		{
			m_LogSource.LogWarning((object)Format(msg));
		}

		public static void Error(object msg)
		{
			m_LogSource.LogError((object)Format(msg));
		}

		public static void Fatal(object msg)
		{
			m_LogSource.LogFatal((object)Format(msg));
		}
	}
	[HarmonyPatch]
	internal class Patch
	{
		[HarmonyPatch(typeof(PlayerAmmoStorage), "PickupAmmo")]
		[HarmonyPrefix]
		public static bool PickupAmmo(PlayerAmmoStorage __instance, ref AmmoType ammoType, ref float ammoAmount)
		{
			return true;
		}

		[HarmonyPatch(typeof(PlayerBackpack), "AddBackpackItem")]
		[HarmonyPrefix]
		public static bool AddBackpackItem(PlayerBackpack __instance, ref InventorySlot slot, ref BackpackItem item)
		{
			return true;
		}

		[HarmonyPatch(typeof(PlayerAmmoStorage), "UpdateBulletsInPack")]
		[HarmonyPrefix]
		public static bool UpdateBulletsInPack(PlayerAmmoStorage __instance, AmmoType ammoType, ref int bulletCount)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Invalid comparison between Unknown and I4
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if ((int)ammoType != 5)
			{
				Logger.Debug($"UpdateBulletsInPack -> !Consumable ammoType = {ammoType} bulletCount = {bulletCount}");
				return true;
			}
			uint itemID = ((Il2CppArrayBase<BackpackItem>)(object)__instance.m_playerBackpack.Slots)[5].ItemID;
			Logger.Debug($"UpdateBulletsInPack -> Consumable ItemID = {itemID} ammoType = {ammoType} bulletCount = {bulletCount} IsHazMoreGlowsticks = {ConfigMgr.CanHazMoreGlowsticks}");
			if ((int)ammoType == 5 && ConsumableUtils.IsGlowstick(itemID) && ConfigMgr.CanHazMoreGlowsticks)
			{
				bulletCount = 0;
			}
			return true;
		}
	}
	[BepInPlugin("io.takina.gtfo.ICanHazMoreGlowsticks", "ICanHazMoreGlowsticks", "0.999999.1")]
	public class Plugin : BasePlugin
	{
		public const string NAME = "ICanHazMoreGlowsticks";

		public const string GUID = "io.takina.gtfo.ICanHazMoreGlowsticks";

		public const string VERSION = "0.999999.1";

		public override void Load()
		{
			Logger.SetupFromInit(((BasePlugin)this).Log);
			Logger.Info("ICanHazMoreGlowsticks io.takina.gtfo.ICanHazMoreGlowsticks 0.999999.1");
			Logger.Info("Patching...");
			Logger.Info($"ConfigMgr Count = {ConfigMgr.GlowStickCount} Infinite = {ConfigMgr.CanHazMoreGlowsticks}");
			Harmony.CreateAndPatchAll(typeof(Patch), "io.takina.gtfo.ICanHazMoreGlowsticks");
			Logger.Info("Finished Patching");
		}
	}
}