Decompiled source of InfiniteShotgunWithReload v1.0.3

EnoPM.InfiniteShotgunWithReload.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CSync.Extensions;
using CSync.Lib;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("EnoPM")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Lethal Company mod that allows you to reload the shotgun without having any shells")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+3b9cfd85d16e14fdb8d50b25fefb007273b1da06")]
[assembly: AssemblyProduct("InfiniteShotgunWithReload")]
[assembly: AssemblyTitle("EnoPM.InfiniteShotgunWithReload")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 EnoPM.InfiniteShotgunWithReload
{
	public sealed class HostConfig : SyncedConfig2<HostConfig>
	{
		private static bool SyncedState { get; set; }

		[field: SyncedEntryField]
		public SyncedEntry<bool> Enabled { get; }

		public static bool IsSynced()
		{
			if (!Object.op_Implicit((Object)(object)NetworkManager.Singleton))
			{
				return false;
			}
			if (NetworkManager.Singleton.IsServer)
			{
				return true;
			}
			if (!SyncedState)
			{
				Plugin.Log.LogError((object)"(HostConfig) Client joined without synced state");
			}
			return SyncedState;
		}

		public HostConfig(ConfigFile configFile)
			: base("infiniteshotgunwithreload.lc.eno.pm")
		{
			Enabled = SyncedBindingExtensions.BindSyncedEntry<bool>(configFile, "infiniteshotgunwithreload.lc.eno.pm", "Enabled", true, "Globally enable/disable the plugin");
			ConfigManager.Register<HostConfig>((SyncedConfig2<HostConfig>)this);
		}

		internal static void OnInitialSyncCompleted(object _0, EventArgs _1)
		{
			Plugin.Log.LogInfo((object)"HostConfig synced");
			SyncedState = true;
		}
	}
	[BepInPlugin("infiniteshotgunwithreload.lc.eno.pm", "InfiniteShotgunWithReload", "1.0.3")]
	[BepInDependency("com.sigurd.csync", "5.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private static readonly Harmony HarmonyPatcher = new Harmony("infiniteshotgunwithreload.lc.eno.pm");

		public static HostConfig HostConfig { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			HostConfig = new HostConfig(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Config.Save();
			HarmonyPatcher.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin infiniteshotgunwithreload.lc.eno.pm is loaded!");
			((SyncedConfig2<HostConfig>)HostConfig).InitialSyncCompleted += HostConfig.OnInitialSyncCompleted;
		}
	}
	internal static class ProjectInfos
	{
		internal const string Guid = "infiniteshotgunwithreload.lc.eno.pm";

		internal const string Name = "InfiniteShotgunWithReload";

		internal const string Version = "1.0.3";
	}
}
namespace EnoPM.InfiniteShotgunWithReload.Patches
{
	[HarmonyPatch(typeof(ShotgunItem))]
	internal static class ShotgunItemPatches
	{
		private static readonly int Reloading = Animator.StringToHash("Reloading");

		private static readonly int ReloadShotgun = Animator.StringToHash("ReloadShotgun");

		private static readonly int ReloadShotgun2 = Animator.StringToHash("ReloadShotgun2");

		[HarmonyPostfix]
		[HarmonyPatch("ReloadedGun")]
		private static void ReloadedGunPostfix(ref bool __result)
		{
			if (HostConfig.IsSynced() && SyncedEntry<bool>.op_Implicit(Plugin.HostConfig.Enabled))
			{
				__result = true;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("StartReloadGun")]
		private static bool StartReloadGunPrefix(ShotgunItem __instance)
		{
			if (!HostConfig.IsSynced() || !SyncedEntry<bool>.op_Implicit(Plugin.HostConfig.Enabled))
			{
				return true;
			}
			if (__instance.ReloadedGun())
			{
				if (!((NetworkBehaviour)__instance).IsOwner)
				{
					return false;
				}
				if (__instance.gunCoroutine != null)
				{
					((MonoBehaviour)__instance).StopCoroutine(__instance.gunCoroutine);
				}
				__instance.gunCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.CoReloadGunAnimation());
			}
			else
			{
				__instance.gunAudio.PlayOneShot(__instance.noAmmoSFX);
			}
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("reloadGunAnimation")]
		private static bool ReloadGunAnimationPrefix(ShotgunItem __instance)
		{
			__instance.gunCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.CoReloadGunAnimation());
			return false;
		}

		private static IEnumerator CoReloadGunAnimation(this ShotgunItem shotgunItem)
		{
			shotgunItem.isReloading = true;
			if (shotgunItem.shellsLoaded <= 0)
			{
				((GrabbableObject)shotgunItem).playerHeldBy.playerBodyAnimator.SetBool(ReloadShotgun, true);
				((Renderer)shotgunItem.shotgunShellLeft).enabled = false;
				((Renderer)shotgunItem.shotgunShellRight).enabled = false;
			}
			else
			{
				((GrabbableObject)shotgunItem).playerHeldBy.playerBodyAnimator.SetBool(ReloadShotgun2, true);
				((Renderer)shotgunItem.shotgunShellRight).enabled = false;
			}
			yield return (object)new WaitForSeconds(0.3f);
			shotgunItem.gunAudio.PlayOneShot(shotgunItem.gunReloadSFX);
			shotgunItem.gunAnimator.SetBool(Reloading, true);
			shotgunItem.ReloadGunEffectsServerRpc(true);
			yield return (object)new WaitForSeconds(0.95f);
			((Renderer)shotgunItem.shotgunShellInHand).enabled = true;
			shotgunItem.shotgunShellInHandTransform.SetParent(((GrabbableObject)shotgunItem).playerHeldBy.leftHandItemTarget);
			shotgunItem.shotgunShellInHandTransform.localPosition = new Vector3(-0.0555f, 0.1469f, -0.0655f);
			shotgunItem.shotgunShellInHandTransform.localEulerAngles = new Vector3(-1.956f, 143.856f, -16.427f);
			yield return (object)new WaitForSeconds(0.95f);
			if (shotgunItem.ammoSlotToUse != -1)
			{
				((GrabbableObject)shotgunItem).playerHeldBy.DestroyItemInSlotAndSync(shotgunItem.ammoSlotToUse);
				shotgunItem.ammoSlotToUse = -1;
			}
			shotgunItem.shellsLoaded = Mathf.Clamp(shotgunItem.shellsLoaded + 1, 0, 2);
			((Renderer)shotgunItem.shotgunShellLeft).enabled = true;
			if (shotgunItem.shellsLoaded == 2)
			{
				((Renderer)shotgunItem.shotgunShellRight).enabled = true;
			}
			((Renderer)shotgunItem.shotgunShellInHand).enabled = false;
			shotgunItem.shotgunShellInHandTransform.SetParent(((Component)shotgunItem).transform);
			yield return (object)new WaitForSeconds(0.45f);
			shotgunItem.gunAudio.PlayOneShot(shotgunItem.gunReloadFinishSFX);
			shotgunItem.gunAnimator.SetBool(Reloading, false);
			((GrabbableObject)shotgunItem).playerHeldBy.playerBodyAnimator.SetBool(ReloadShotgun, false);
			((GrabbableObject)shotgunItem).playerHeldBy.playerBodyAnimator.SetBool(ReloadShotgun2, false);
			shotgunItem.isReloading = false;
			shotgunItem.ReloadGunEffectsServerRpc(false);
		}
	}
}