Decompiled source of TruckAlwaysSpawn v1.0.0

TruckAlwaysSpawn.Core.dll

Decompiled 19 hours 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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RespawnInTruck")]
[assembly: AssemblyTitle("RespawnInTruck")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 RespawnInTruck
{
	public class RespawnInTruck : BaseUnityPlugin
	{
		internal static RespawnInTruck Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}
namespace Empress.Repo.RespawnInTruck
{
	[BepInPlugin("com.truckalwaysspawn.repo", "TruckAlwaysSpawn", "1.0.0")]
	public class RespawnInTruckPlugin : BaseUnityPlugin
	{
		public const string GUID = "com.truckalwaysspawn.repo";

		public const string Name = "TruckAlwaysSpawn";

		public const string Version = "1.0.0";

		internal static RespawnInTruckPlugin Instance;

		internal static Harmony Harmony;

		internal static ManualLogSource Log;

		private ConfigEntry<bool> _enabled;

		private ConfigEntry<float> _respawnDelay;

		internal static readonly HashSet<int> Scheduled = new HashSet<int>();

		private void Awake()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "If true, dead players are revived in the truck (master-controlled).");
			_respawnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RespawnDelay", 3f, "Real-time delay after death before reviving (seconds).");
			Harmony = new Harmony("com.truckalwaysspawn.repo");
			Harmony.PatchAll();
			Log.LogInfo((object)string.Format("[{0}] v{1} loaded. Enabled={2}, Delay={3:F2}s", "RespawnInTruck", "2.0.0", _enabled.Value, _respawnDelay.Value));
		}

		private void OnDestroy()
		{
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Scheduled.Clear();
		}

		internal bool FeatureEnabledForThisClient()
		{
			return _enabled.Value;
		}

		internal IEnumerator ReviveAfterDelay(PlayerAvatar avatar, int actorNr)
		{
			float wait = Mathf.Max(0f, _respawnDelay.Value);
			if (wait > 0f)
			{
				yield return (object)new WaitForSecondsRealtime(wait);
			}
			float t = 0f;
			while ((Object)(object)avatar != (Object)null && (Object)(object)avatar.playerDeathHead == (Object)null && t < 2f)
			{
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			if ((Object)(object)avatar == (Object)null)
			{
				Scheduled.Remove(actorNr);
				yield break;
			}
			if ((Object)(object)avatar.playerDeathHead == (Object)null)
			{
				Log.LogWarning((object)string.Format("[{0}] Death head missing for actor {1}; postponing revive by 0.25s", "RespawnInTruck", actorNr));
				yield return (object)new WaitForSecondsRealtime(0.25f);
			}
			try
			{
				avatar.Revive(true);
				Log.LogDebug((object)string.Format("[{0}] Revive(true) sent for actor {1} after {2:F2}s", "RespawnInTruck", actorNr, wait));
			}
			catch (Exception ex)
			{
				Exception ex2 = ex;
				Log.LogError((object)string.Format("[{0}] Revive call failed for actor {1}: {2}", "RespawnInTruck", actorNr, ex2));
			}
			finally
			{
				Scheduled.Remove(actorNr);
			}
		}

		internal static bool TryGetTruckSpawn(out Vector3 pos, out Quaternion rot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			rot = Quaternion.identity;
			if ((Object)(object)TruckSafetySpawnPoint.instance != (Object)null)
			{
				Transform transform = ((Component)TruckSafetySpawnPoint.instance).transform;
				SpawnPoint[] componentsInChildren = ((Component)transform).GetComponentsInChildren<SpawnPoint>(false);
				if (componentsInChildren != null && componentsInChildren.Length != 0)
				{
					pos = ((Component)componentsInChildren[0]).transform.position;
					rot = ((Component)componentsInChildren[0]).transform.rotation;
					return true;
				}
				pos = transform.position;
				rot = transform.rotation;
				return true;
			}
			if ((Object)(object)LevelGenerator.Instance != (Object)null && (Object)(object)LevelGenerator.Instance.LevelPathTruck != (Object)null)
			{
				Transform transform2 = ((Component)LevelGenerator.Instance.LevelPathTruck).transform;
				pos = transform2.position;
				rot = transform2.rotation;
				return true;
			}
			if ((Object)(object)TruckHealer.instance != (Object)null)
			{
				Transform transform3 = ((Component)TruckHealer.instance).transform;
				pos = transform3.position;
				rot = transform3.rotation;
				return true;
			}
			return false;
		}

		internal static bool GetTruckSpawnFor(PlayerAvatar avatar, out Vector3 pos, out Quaternion rot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			rot = Quaternion.identity;
			if ((Object)(object)TruckSafetySpawnPoint.instance != (Object)null)
			{
				Transform transform = ((Component)TruckSafetySpawnPoint.instance).transform;
				List<Transform> list = new List<Transform>();
				try
				{
					SpawnPoint[] componentsInChildren = ((Component)transform).GetComponentsInChildren<SpawnPoint>(false);
					if (componentsInChildren != null && componentsInChildren.Length != 0)
					{
						SpawnPoint[] array = componentsInChildren;
						foreach (SpawnPoint val in array)
						{
							if (Object.op_Implicit((Object)(object)val))
							{
								list.Add(((Component)val).transform);
							}
						}
					}
				}
				catch
				{
				}
				if (list.Count == 0)
				{
					list.Add(transform);
				}
				int num = 0;
				try
				{
					num = (((Object)(object)avatar?.photonView != (Object)null) ? avatar.photonView.OwnerActorNr : ((Object)avatar).GetInstanceID());
				}
				catch
				{
					num = (((Object)(object)avatar != (Object)null) ? ((Object)avatar).GetInstanceID() : 0);
				}
				int index = ((list.Count > 0) ? (Mathf.Abs(num) % list.Count) : 0);
				Transform val2 = list[index];
				if (Object.op_Implicit((Object)(object)val2))
				{
					pos = val2.position;
					rot = val2.rotation;
					return true;
				}
			}
			return TryGetTruckSpawn(out pos, out rot);
		}

		internal static Vector3 SpreadOffsetFor(PlayerAvatar avatar)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			try
			{
				num = (((Object)(object)avatar?.photonView != (Object)null) ? avatar.photonView.OwnerActorNr : ((Object)avatar).GetInstanceID());
			}
			catch
			{
				num = (((Object)(object)avatar != (Object)null) ? ((Object)avatar).GetInstanceID() : 0);
			}
			float num2 = 0.6f;
			float num3 = (float)(num % 8) * (MathF.PI / 4f);
			return new Vector3(Mathf.Cos(num3) * num2, 0f, Mathf.Sin(num3) * num2);
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar))]
	internal static class PlayerAvatar_TruckRespawn_Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch("PlayerDeathRPC")]
		private static void Post_PlayerDeathRPC(PlayerAvatar __instance, int enemyIndex, PhotonMessageInfo _info)
		{
			RespawnInTruckPlugin instance = RespawnInTruckPlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.FeatureEnabledForThisClient())
			{
				/*Error near IL_0020: Invalid branch target*/;
			}
			bool num = PhotonNetwork.IsMasterClient;
			if (!num)
			{
				num = !PhotonNetwork.InRoom;
			}
			if (num && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.photonView == (Object)null))
			{
				int num2 = __instance.photonView.OwnerActorNr;
				if (num2 <= 0)
				{
					num2 = 1;
				}
				if (num2 > 0 && RespawnInTruckPlugin.Scheduled.Add(num2))
				{
					((MonoBehaviour)instance).StartCoroutine(instance.ReviveAfterDelay(__instance, num2));
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("ReviveRPC")]
		private static void Post_ReviveRPC(PlayerAvatar __instance, bool _revivedByTruck, PhotonMessageInfo _info)
		{
			RespawnInTruckPlugin instance = RespawnInTruckPlugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.FeatureEnabledForThisClient() || !_revivedByTruck)
			{
				return;
			}
			try
			{
				if ((Object)(object)__instance.photonView != (Object)null && PhotonNetwork.InRoom && !__instance.photonView.IsMine)
				{
					return;
				}
			}
			catch
			{
			}
			((MonoBehaviour)instance).StartCoroutine(OwnerMoveAfterRevive(__instance));
		}

		private static IEnumerator OwnerMoveAfterRevive(PlayerAvatar avatar)
		{
			yield return null;
			yield return (object)new WaitForSeconds(0.05f);
			if (!RespawnInTruckPlugin.TryGetTruckSpawn(out var basePos, out var baseRot))
			{
				yield break;
			}
			if (!RespawnInTruckPlugin.GetTruckSpawnFor(avatar, out var finalPos, out var finalRot))
			{
				finalPos = basePos + RespawnInTruckPlugin.SpreadOffsetFor(avatar);
				finalRot = baseRot;
			}
			Vector3 probe = finalPos + Vector3.up * 2f;
			RaycastHit hit = default(RaycastHit);
			finalPos = ((!Physics.Raycast(probe, Vector3.down, ref hit, 5f)) ? (finalPos + Vector3.up * 0.1f) : (((RaycastHit)(ref hit)).point + Vector3.up * 0.05f));
			try
			{
				((Component)avatar).transform.SetPositionAndRotation(finalPos, finalRot);
				if ((Object)(object)avatar.playerTransform != (Object)null)
				{
					avatar.playerTransform.position = finalPos;
				}
				if ((Object)(object)avatar.playerAvatarVisuals != (Object)null)
				{
					((Component)avatar.playerAvatarVisuals).transform.position = finalPos;
				}
				try
				{
					avatar.FallDamageResetSet(2f);
				}
				catch
				{
				}
			}
			catch (Exception arg)
			{
				RespawnInTruckPlugin.Log.LogError((object)string.Format("[{0}] Owner teleport failed: {1}", "RespawnInTruck", arg));
			}
		}
	}
}

TruckAlwaysSpawn.Solo.dll

Decompiled 19 hours 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SinglePlayerRevive")]
[assembly: AssemblyTitle("SinglePlayerRevive")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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 SinglePlayerRevive
{
	public class SinglePlayerRevive : BaseUnityPlugin
	{
		internal static SinglePlayerRevive Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}
namespace Empress.SingleplayerRevive
{
	[BepInPlugin("com.truckalwaysspawn.repo.solo", "TruckAlwaysSpawn.Solo", "1.0.0")]
	public class SingleplayerRevivePlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.truckalwaysspawn.repo.solo";

		public const string PluginName = "TruckAlwaysSpawn.Solo";

		public const string PluginVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static Harmony Harmony;

		internal static ConfigEntry<bool> CEnabled;

		internal static ConfigEntry<float> CReviveDelay;

		internal static ConfigEntry<int> CReviveHealth;

		internal static ConfigEntry<bool> CRestrictToSoloInMP;

		internal static bool ReviveInProgress;

		private void Awake()
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			CEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master enable/disable.");
			CReviveDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ReviveDelaySeconds", 2f, "Delay before reviving the player.");
			CReviveHealth = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ReviveHealth", 50, "Health set after revive (clamped to [1..maxHealth]).");
			CRestrictToSoloInMP = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RestrictToSoloInMP", true, "Only revive in MP if room PlayerCount <= 1.");
			Harmony = new Harmony("com.truckalwaysspawn.repo.solo");
			Harmony.PatchAll(typeof(Patch_RunManager_ChangeLevel));
			Log.LogInfo((object)"Singleplayer_Revive 1.0.1 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static IEnumerator ReviveRoutine()
		{
			ReviveInProgress = true;
			float delay = Mathf.Max(0f, CReviveDelay.Value);
			if (delay > 0f)
			{
				yield return (object)new WaitForSeconds(delay);
			}
			Exception caught = null;
			try
			{
				PlayerController pc = PlayerController.instance;
				PlayerAvatar avatar = (((Object)(object)pc != (Object)null) ? pc.playerAvatarScript : null);
				if ((Object)(object)avatar == (Object)null)
				{
					Log.LogWarning((object)"No local PlayerAvatar found. Aborting revive.");
					ReviveInProgress = false;
					yield break;
				}
				if (!avatar.isDisabled && !avatar.deadSet)
				{
					ReviveInProgress = false;
					yield break;
				}
				avatar.Revive(true);
				PlayerHealth ph = avatar.playerHealth;
				if ((Object)(object)ph != (Object)null)
				{
					int target = Mathf.Clamp(CReviveHealth.Value, 1, Mathf.Max(1, ph.maxHealth));
					int delta = target - Mathf.Max(0, ph.health);
					if (delta > 0)
					{
						ph.Heal(delta, false);
					}
				}
			}
			catch (Exception ex)
			{
				caught = ex;
			}
			yield return null;
			ReviveInProgress = false;
			if (caught != null)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogError((object)caught);
				}
			}
		}
	}
	[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
	internal static class Patch_RunManager_ChangeLevel
	{
		[HarmonyPrefix]
		[HarmonyPriority(600)]
		private static bool Prefix(RunManager __instance, bool _completedLevel, bool _levelFailed, ChangeLevelType _changeLevelType)
		{
			try
			{
				if (!SingleplayerRevivePlugin.CEnabled.Value)
				{
					return true;
				}
				if (!_levelFailed)
				{
					return true;
				}
				if (!SemiFunc.RunIsLevel())
				{
					return true;
				}
				if (SingleplayerRevivePlugin.ReviveInProgress)
				{
					return false;
				}
				if (GameManager.Multiplayer() && SingleplayerRevivePlugin.CRestrictToSoloInMP.Value)
				{
					try
					{
						Room currentRoom = PhotonNetwork.CurrentRoom;
						int num = ((currentRoom != null) ? currentRoom.PlayerCount : 0);
						SingleplayerRevivePlugin.Log.LogDebug((object)$"Room player count = {num}");
						if (num > 1)
						{
							return true;
						}
					}
					catch (Exception ex)
					{
						SingleplayerRevivePlugin.Log.LogWarning((object)("PlayerCount check failed: " + ex.Message));
						return true;
					}
				}
				PlayerController instance = PlayerController.instance;
				PlayerAvatar val = (((Object)(object)instance != (Object)null) ? instance.playerAvatarScript : null);
				if ((Object)(object)val == (Object)null || !val.isDisabled)
				{
					return true;
				}
				__instance.allPlayersDead = false;
				((MonoBehaviour)__instance).StartCoroutine(SingleplayerRevivePlugin.ReviveRoutine());
				SingleplayerRevivePlugin.Log.LogInfo((object)"Suppressed run fail and revived local player (solo).");
				return false;
			}
			catch (Exception ex2)
			{
				ManualLogSource log = SingleplayerRevivePlugin.Log;
				if (log != null)
				{
					log.LogError((object)ex2);
				}
				return true;
			}
		}
	}
}