Decompiled source of RespawnInShop v1.2.0

RespawnInShop.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
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("onecoolsnowman.RespawnInShop")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+a50ee467004a65279efafcb6fa465a79b2e0f0a8")]
[assembly: AssemblyProduct("RespawnInShop")]
[assembly: AssemblyTitle("onecoolsnowman.RespawnInShop")]
[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 RespawnInShop
{
	public class DelayedRevive : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <ReviveAfterDelay>d__3 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public DelayedRevive <>4__this;

			private Vector3 <spawnPos>5__1;

			private Quaternion <spawnRot>5__2;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ReviveAfterDelay>d__3(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Expected O, but got Unknown
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0165: Unknown result type (might be due to invalid IL or missing references)
				//IL_0180: Unknown result type (might be due to invalid IL or missing references)
				//IL_0185: Unknown result type (might be due to invalid IL or missing references)
				//IL_0196: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					RespawnInShop.Logger.LogInfo((object)("Reviving player " + <>4__this.player.playerName + " in " + RespawnInShop.configManager.respawnDelay.Value + " seconds..."));
					<>2__current = (object)new WaitForSeconds((float)RespawnInShop.configManager.respawnDelay.Value);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (object.Equals(LevelGenerator.Instance, null))
					{
						RespawnInShop.Logger.LogWarning((object)"LevelGenerator instance not found");
					}
					else if (object.Equals(RunManager.instance.levelCurrent, RunManager.instance.levelShop))
					{
						<>4__this.player.Revive(false);
						<>4__this.player.playerHealth.health = 1;
						RespawnInShop.Logger.LogInfo((object)("Revived player " + <>4__this.player.playerName));
						if (RespawnInShop.configManager.spawnInTruck.Value)
						{
							<spawnPos>5__1 = ((Component)Object.FindObjectsOfType<SpawnPoint>()[0]).transform.position;
							<spawnRot>5__2 = ((Component)<>4__this.player.playerDeathHead).transform.rotation;
							<>4__this.player.Spawn(<spawnPos>5__1, <spawnRot>5__2);
						}
					}
					else
					{
						RespawnInShop.Logger.LogWarning((object)"Not currently in shop");
					}
					Object.Destroy((Object)(object)((Component)<>4__this).gameObject);
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		public PlayerAvatar player;

		public DelayedRevive(PlayerAvatar player)
		{
			this.player = player;
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(ReviveAfterDelay());
		}

		[IteratorStateMachine(typeof(<ReviveAfterDelay>d__3))]
		private IEnumerator ReviveAfterDelay()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReviveAfterDelay>d__3(0)
			{
				<>4__this = this
			};
		}
	}
	public class ConfigManager
	{
		internal ConfigEntry<bool> spawnInTruck = null;

		internal ConfigEntry<int> respawnDelay = null;

		internal void Setup(ConfigFile configFile)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			spawnInTruck = configFile.Bind<bool>("General", "Spawn in truck", false, new ConfigDescription("Spawn in truck (otherwise, players will spawn where their head is.)", (AcceptableValueBase)null, Array.Empty<object>()));
			respawnDelay = configFile.Bind<int>("General", "Respawn delay (Seconds)", 5, new ConfigDescription("How long before respawning players at the shop.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
		}
	}
	[BepInPlugin("onecoolsnowman.RespawnInShop", "RespawnInShop", "1.0.0")]
	public class RespawnInShop : BaseUnityPlugin
	{
		internal static ConfigManager configManager;

		internal static ConfigFile Conf;

		public static RespawnInShop Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			configManager = new ConfigManager();
			Conf = ((BaseUnityPlugin)this).Config;
			configManager.Setup(((BaseUnityPlugin)this).Config);
			Patch();
			Logger.LogInfo((object)"onecoolsnowman.RespawnInShop has loaded!");
		}

		internal static void Patch()
		{
			//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("onecoolsnowman.RespawnInShop");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "onecoolsnowman.RespawnInShop";

		public const string PLUGIN_NAME = "RespawnInShop";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace RespawnInShop.Patches
{
	[HarmonyPatch(typeof(PlayerAvatar))]
	public class PlayerDeathPatch
	{
		[HarmonyPatch("PlayerDeathRPC")]
		[HarmonyPostfix]
		public static void Postfix(PlayerAvatar __instance)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			if (object.Equals(RunManager.instance.levelCurrent, RunManager.instance.levelShop) && (!GameManager.Multiplayer() || PhotonNetwork.IsMasterClient))
			{
				DelayedRevive delayedRevive = new GameObject("DelayedRevive").AddComponent<DelayedRevive>();
				delayedRevive.player = __instance;
			}
		}
	}
}