Decompiled source of SlipperyShotgun v1.0.8

SlipperyShotgun.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PiggyVarietyMod.Patches;
using SlipperyShotgun.Patches;
using Unity.Netcode;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SlipperyShotgun")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+faa44a042c76128f8819c744375d7d0e9f707cd7")]
[assembly: AssemblyProduct("SlipperyShotgun")]
[assembly: AssemblyTitle("SlipperyShotgun")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.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 SlipperyShotgun
{
	public enum LogLevel
	{
		None,
		Info,
		Debug
	}
	[BepInPlugin("com.itekso.SlipperyShotgun", "SlipperyShotgun", "1.0.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class SlipperyShotgun : BaseUnityPlugin
	{
		private const string modGUID = "com.itekso.SlipperyShotgun";

		private const string modName = "SlipperyShotgun";

		private const string modVersion = "1.0.8";

		public static SlipperyShotgun Instance { get; private set; }

		public static ManualLogSource Logger { get; private set; }

		private static Harmony? Harmony { get; set; }

		public static ConfigEntry<int> DropChance { get; private set; }

		public static ConfigEntry<int> M4DropChance { get; private set; }

		public static ConfigEntry<int> RevolverDropChance { get; private set; }

		public static ConfigEntry<LogLevel> LogLevelConfig { get; private set; }

		public static ConfigEntry<bool> ConfettiMode { get; private set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			DropChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "DropChance", 45, "Percent chance to drop the shotgun (0-100)");
			M4DropChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "M4DropChance", 25, "Percent chance to drop the M4 (0-100)");
			RevolverDropChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "RevolverDropChance", 35, "Percent chance to drop the Revolver (0-100)");
			LogLevelConfig = ((BaseUnityPlugin)this).Config.Bind<LogLevel>("General", "LogLevel", LogLevel.Info, "Log level (None, Info, Debug)");
			ConfettiMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ConfettiMode", false, "Enable confetti explosion on drop");
			PatchShotgun();
			ConfigEntry<LogLevel> logLevelConfig = LogLevelConfig;
			if (logLevelConfig == null || logLevelConfig.Value != 0)
			{
				Logger.LogInfo((object)"SlipperyShotgun v1.0.8 has loaded!");
			}
			Dictionary<string, PluginInfo> pluginInfos = Chainloader.PluginInfos;
			if (pluginInfos != null && pluginInfos.Keys.Any((string k) => k == "Piggy.PiggyVarietyMod"))
			{
				Logger.LogInfo((object)"Piggy's Variety Mod found. Applying patches for RevolverItem and M4Item.");
				Harmony? harmony = Harmony;
				if (harmony != null)
				{
					harmony.PatchAll(typeof(RevolverItemPatch));
				}
				Harmony? harmony2 = Harmony;
				if (harmony2 != null)
				{
					harmony2.PatchAll(typeof(M4ItemPatch));
				}
			}
			else
			{
				Logger.LogInfo((object)"Piggy's Variety Mod not found. RevolverItem and M4Item patches skipped.");
			}
		}

		private static void PatchShotgun()
		{
			//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)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("com.itekso.SlipperyShotgun");
			}
			if (LogLevelConfig.Value == LogLevel.Debug)
			{
				Logger.LogDebug((object)"Patching ShotgunItem...");
			}
			Harmony.PatchAll(typeof(ShotgunItemPatch));
			if (LogLevelConfig.Value == LogLevel.Debug)
			{
				Logger.LogDebug((object)"Finished patching ShotgunItem!");
			}
		}

		internal static void Unpatch()
		{
			if (LogLevelConfig.Value == LogLevel.Debug)
			{
				Logger.LogDebug((object)"Unpatching...");
			}
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if (LogLevelConfig.Value == LogLevel.Debug)
			{
				Logger.LogDebug((object)"Finished unpatching!");
			}
		}

		public static GameObject FindPrefabByName(string prefabName)
		{
			string prefabName2 = prefabName;
			GameObject val = ((IEnumerable<GameObject>)Resources.FindObjectsOfTypeAll<GameObject>()).FirstOrDefault((Func<GameObject, bool>)((GameObject obj) => ((Object)obj).name == prefabName2));
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogError((object)("Prefab '" + prefabName2 + "' not found."));
			}
			return val;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SlipperyShotgun";

		public const string PLUGIN_NAME = "SlipperyShotgun";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SlipperyShotgun.Patches
{
	[HarmonyPatch(typeof(M4Item))]
	public static class M4ItemPatch
	{
		private static readonly Random random = new Random();

		[HarmonyPatch("ShootGun")]
		[HarmonyPostfix]
		public static void PostfixShootGun(M4Item __instance, Vector3 gunPosition, Vector3 gunForward)
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: 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)
			if (!((Object)(object)((GrabbableObject)(__instance?)).playerHeldBy != (Object)null) || !((Object)(object)((GrabbableObject)__instance).playerHeldBy.currentlyHeldObjectServer != (Object)null))
			{
				return;
			}
			int num = random.Next(1, 101);
			ConfigEntry<LogLevel> logLevelConfig = SlipperyShotgun.LogLevelConfig;
			if (logLevelConfig != null && logLevelConfig.Value == LogLevel.Debug)
			{
				ManualLogSource logger = SlipperyShotgun.Logger;
				if (logger != null)
				{
					logger.LogDebug((object)$"Generated random number: {num}");
				}
			}
			if (num <= SlipperyShotgun.M4DropChance?.Value)
			{
				__instance.isFiring = false;
				__instance.isReloading = false;
				__instance.isInspecting = false;
				__instance.cantFire = false;
				((GrabbableObject)__instance).playerHeldBy.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
				ConfigEntry<bool> confettiMode = SlipperyShotgun.ConfettiMode;
				if (confettiMode != null && confettiMode.Value)
				{
					GameObject val = SlipperyShotgun.FindPrefabByName("EasterEggExplosionParticle");
					if ((Object)(object)val != (Object)null)
					{
						Object.Instantiate<GameObject>(val, ((Component)__instance).transform.position, Quaternion.identity);
					}
					else
					{
						ManualLogSource logger2 = SlipperyShotgun.Logger;
						if (logger2 != null)
						{
							logger2.LogError((object)"EasterEggExplosionParticle prefab is null.");
						}
					}
				}
				ConfigEntry<LogLevel> logLevelConfig2 = SlipperyShotgun.LogLevelConfig;
				if (logLevelConfig2 == null || logLevelConfig2.Value != 0)
				{
					ManualLogSource logger3 = SlipperyShotgun.Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)"You call yourself a Scavenger?!");
					}
				}
			}
			ConfigEntry<LogLevel> logLevelConfig3 = SlipperyShotgun.LogLevelConfig;
			if (logLevelConfig3 != null && logLevelConfig3.Value == LogLevel.Debug)
			{
				ManualLogSource logger4 = SlipperyShotgun.Logger;
				if (logger4 != null)
				{
					logger4.LogDebug((object)$"Configured drop chance: {SlipperyShotgun.M4DropChance?.Value}");
				}
			}
		}
	}
	[HarmonyPatch(typeof(RevolverItem))]
	public static class RevolverItemPatch
	{
		private static readonly Random random = new Random();

		[HarmonyPatch("ShootGun")]
		[HarmonyPostfix]
		public static void PostfixShootGun(RevolverItem __instance, Vector3 revolverPosition, Vector3 revolverForward)
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((GrabbableObject)(__instance?)).playerHeldBy != (Object)null) || !((Object)(object)((GrabbableObject)__instance).playerHeldBy.currentlyHeldObjectServer != (Object)null))
			{
				return;
			}
			int num = random.Next(1, 101);
			ConfigEntry<LogLevel> logLevelConfig = SlipperyShotgun.LogLevelConfig;
			if (logLevelConfig != null && logLevelConfig.Value == LogLevel.Debug)
			{
				ManualLogSource logger = SlipperyShotgun.Logger;
				if (logger != null)
				{
					logger.LogDebug((object)$"Generated random number: {num}");
				}
			}
			if (num <= SlipperyShotgun.RevolverDropChance?.Value)
			{
				__instance.isReloading = false;
				__instance.cantFire = false;
				__instance.isCylinderMoving = false;
				((GrabbableObject)__instance).playerHeldBy.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
				ConfigEntry<bool> confettiMode = SlipperyShotgun.ConfettiMode;
				if (confettiMode != null && confettiMode.Value)
				{
					GameObject val = SlipperyShotgun.FindPrefabByName("EasterEggExplosionParticle");
					if ((Object)(object)val != (Object)null)
					{
						Object.Instantiate<GameObject>(val, ((Component)__instance).transform.position, Quaternion.identity);
					}
					else
					{
						ManualLogSource logger2 = SlipperyShotgun.Logger;
						if (logger2 != null)
						{
							logger2.LogError((object)"EasterEggExplosionParticle prefab is null.");
						}
					}
				}
				ConfigEntry<LogLevel> logLevelConfig2 = SlipperyShotgun.LogLevelConfig;
				if (logLevelConfig2 == null || logLevelConfig2.Value != 0)
				{
					ManualLogSource logger3 = SlipperyShotgun.Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)"This town ain't big enough for the two of us!");
					}
				}
			}
			ConfigEntry<LogLevel> logLevelConfig3 = SlipperyShotgun.LogLevelConfig;
			if (logLevelConfig3 != null && logLevelConfig3.Value == LogLevel.Debug)
			{
				ManualLogSource logger4 = SlipperyShotgun.Logger;
				if (logger4 != null)
				{
					logger4.LogDebug((object)$"Configured drop chance: {SlipperyShotgun.RevolverDropChance?.Value}");
				}
			}
		}
	}
	[HarmonyPatch(typeof(ShotgunItem))]
	public static class ShotgunItemPatch
	{
		private static readonly Random random = new Random();

		[HarmonyPatch("ShootGunClientRpc")]
		[HarmonyPostfix]
		public static void PostfixShootGunClientRpc(ShotgunItem __instance)
		{
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((GrabbableObject)(__instance?)).playerHeldBy != (Object)null) || !((Object)(object)((GrabbableObject)__instance).playerHeldBy.currentlyHeldObjectServer != (Object)null))
			{
				return;
			}
			int num = random.Next(1, 101);
			ConfigEntry<LogLevel> logLevelConfig = SlipperyShotgun.LogLevelConfig;
			if (logLevelConfig != null && logLevelConfig.Value == LogLevel.Debug)
			{
				ManualLogSource logger = SlipperyShotgun.Logger;
				if (logger != null)
				{
					logger.LogDebug((object)$"Generated random number: {num}");
				}
			}
			if (num <= SlipperyShotgun.DropChance?.Value)
			{
				((GrabbableObject)__instance).playerHeldBy.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
				ConfigEntry<bool> confettiMode = SlipperyShotgun.ConfettiMode;
				if (confettiMode != null && confettiMode.Value)
				{
					GameObject val = SlipperyShotgun.FindPrefabByName("EasterEggExplosionParticle");
					if ((Object)(object)val != (Object)null)
					{
						Object.Instantiate<GameObject>(val, ((Component)__instance).transform.position, Quaternion.identity);
					}
					else
					{
						ManualLogSource logger2 = SlipperyShotgun.Logger;
						if (logger2 != null)
						{
							logger2.LogError((object)"EasterEggExplosionParticle prefab is null.");
						}
					}
				}
				ConfigEntry<LogLevel> logLevelConfig2 = SlipperyShotgun.LogLevelConfig;
				if (logLevelConfig2 == null || logLevelConfig2.Value != 0)
				{
					ManualLogSource logger3 = SlipperyShotgun.Logger;
					if (logger3 != null)
					{
						logger3.LogInfo((object)"Try putting more stats in to handling!");
					}
				}
			}
			ConfigEntry<LogLevel> logLevelConfig3 = SlipperyShotgun.LogLevelConfig;
			if (logLevelConfig3 != null && logLevelConfig3.Value == LogLevel.Debug)
			{
				ManualLogSource logger4 = SlipperyShotgun.Logger;
				if (logger4 != null)
				{
					logger4.LogDebug((object)$"Configured drop chance: {SlipperyShotgun.DropChance?.Value}");
				}
			}
		}
	}
}