Decompiled source of SafeDisconnect v2.2.0

BepInEx/plugins/SafeDisconnect.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SafeDisconnect")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SafeDisconnect")]
[assembly: AssemblyTitle("SafeDisconnect")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 SafeDisconnect
{
	[BepInPlugin("com.scythlz.safedisconnect", "SafeDisconnect", "2.2.0")]
	public class SafeDisconnectPlugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("com.scythlz.safedisconnect");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SafeDisconnect fully loaded (CentralConfig, LethalMoonUnlocks, Cruiser+ patched).");
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	public class Patch_Disconnect
	{
		private static void Prefix()
		{
			Debug.Log((object)"[SafeDisconnect] Running Disconnect prefix...");
		}

		private static void Finalizer(Exception __exception)
		{
			if (__exception != null)
			{
				Debug.LogError((object)("[SafeDisconnect] Crash caught in Disconnect(): " + __exception));
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "OnApplicationQuit")]
	public class Patch_OnApplicationQuit
	{
		private static void Prefix()
		{
			Debug.Log((object)"[SafeDisconnect] Running OnApplicationQuit prefix...");
		}

		private static void Finalizer(Exception __exception)
		{
			if (__exception != null)
			{
				Debug.LogError((object)("[SafeDisconnect] Crash caught in OnApplicationQuit(): " + __exception));
			}
		}
	}
	[HarmonyPatch]
	public class Patch_ResetOnDisconnect
	{
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("CentralConfig.ResetChanger+ResetOnDisconnect");
			return (type != null) ? AccessTools.Method(type, "Prefix", (Type[])null, (Type[])null) : null;
		}

		private static bool Prefix()
		{
			Debug.Log((object)"[SafeDisconnect] Skipping crashy ResetOnDisconnect.Prefix.");
			return false;
		}
	}
	[HarmonyPatch]
	public class Patch_TranspileResetMoons
	{
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("impulse.CentralConfig");
			return (type != null) ? AccessTools.Method(type, "ResetMoons", (Type[])null, (Type[])null) : null;
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Debug.Log((object)"[SafeDisconnect] Transpiler: Stripping ResetMoons method body.");
			return new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ret, (object)null)
			};
		}
	}
	[HarmonyPatch]
	public class Patch_ForceWasHostLastGame
	{
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("impulse.CentralConfig");
			return (type != null) ? AccessTools.Method(type, "WasHostLastGame", (Type[])null, (Type[])null) : null;
		}

		private static bool Prefix(ref bool __result)
		{
			__result = true;
			Debug.Log((object)"[SafeDisconnect] Faking WasHostLastGame() = true.");
			return false;
		}
	}
	[HarmonyPatch]
	public class Patch_WasHostProperty
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.TypeByName("impulse.CentralConfig")?.GetProperty("WasHost", BindingFlags.Static | BindingFlags.Public)?.GetGetMethod();
		}

		private static bool Prefix(ref bool __result)
		{
			__result = true;
			Debug.Log((object)"[SafeDisconnect] Faking WasHost property = true.");
			return false;
		}
	}
	[HarmonyPatch]
	public class Patch_LethalMoonUnlocks_DisconnectLogic
	{
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("LethalMoonUnlocks.Plugin");
			return (type != null) ? AccessTools.Method(type, "OnApplicationQuit", (Type[])null, (Type[])null) : null;
		}

		private static bool Prefix()
		{
			Debug.Log((object)"[SafeDisconnect] Skipping LethalMoonUnlocks disconnect cleanup.");
			return false;
		}
	}
	[HarmonyPatch]
	public class Patch_Cruiser_DisconnectLogic
	{
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("CruiserPlus.Patches.GameNetworkManagerPatch");
			return (type != null) ? AccessTools.Method(type, "Disconnect_Postfix", (Type[])null, (Type[])null) : null;
		}

		private static bool Prefix()
		{
			Debug.Log((object)"[SafeDisconnect] Skipping Cruiser+ Disconnect_Postfix.");
			return false;
		}
	}
}