Decompiled source of MultiplayerFixes v1.0.1

MultiplayerFixes.dll

Decompiled a week ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MultiplayerFixes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MultiplayerFixes")]
[assembly: AssemblyTitle("MultiplayerFixes")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MultiplayerFixes
{
	[BepInPlugin("com.certifried.MultiplayerFixes", "MultiplayerFixes", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MultiplayerFixesPlugin : BaseUnityPlugin
	{
		private const string MyGUID = "com.certifried.MultiplayerFixes";

		private const string PluginName = "MultiplayerFixes";

		private const string VersionString = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("com.certifried.MultiplayerFixes");

		public static ManualLogSource Log;

		private int patchCount;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MultiplayerFixes v1.0.0 is loading...");
			PatchVoidChests();
			PatchCreativeChests();
			PatchWormholeChests();
			PatchVirtualCores();
			PatchMorePlantmatter();
			PatchBlueprints();
			PatchSmartInserters();
			PatchCaspersLoaders();
			PatchCrusherCoreBoost();
			PatchEMUBuilder();
			((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} loaded. Applied {1} multiplayer safety patches.", "MultiplayerFixes", patchCount));
		}

		private void PatchVoidChests()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("VoidChests");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("VoidChests.VoidChestsPlugin");
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched VoidChests.FixedUpdate");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch VoidChests: " + ex.Message));
			}
		}

		private void PatchCreativeChests()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("CreativeChests");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("CreativeChests.CreativeChestsPlugin");
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched CreativeChests.FixedUpdate");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch CreativeChests: " + ex.Message));
			}
		}

		private void PatchWormholeChests()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("WormholeChests");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("WormholeChests.ChestInstancePatch");
				if (type != null)
				{
					MethodInfo method = type.GetMethod("GetWormholeInsteadOfInventory", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched WormholeChests.GetWormholeInsteadOfInventory");
						patchCount++;
					}
				}
				Type type2 = assembly.GetType("WormholeChests.ChestDefinitionPatch");
				if (type2 != null)
				{
					MethodInfo method2 = type2.GetMethod("UpdateChestMap", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method2 != null)
					{
						Harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched WormholeChests.UpdateChestMap");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch WormholeChests: " + ex.Message));
			}
		}

		private void PatchVirtualCores()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("VirtualCores");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("VirtualCores.Patches.MemoryTreeInstancePatch");
				if (type == null)
				{
					type = assembly.GetType("VirtualCores.MemoryTreeInstancePatch");
				}
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("AddVirtualCore", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched VirtualCores.AddVirtualCore");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch VirtualCores: " + ex.Message));
			}
		}

		private void PatchMorePlantmatter()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("MorePlantmatter");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("MorePlantmatter.HitDestructibleActionPatch");
				if (type == null)
				{
					type = assembly.GetType("MorePlantmatter.Patches.HitDestructibleActionPatch");
				}
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("AddMorePlantmatter", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched MorePlantmatter.AddMorePlantmatter");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch MorePlantmatter: " + ex.Message));
			}
		}

		private void PatchBlueprints()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("Blueprints");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("Blueprints.BlueprintsPlugin");
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched Blueprints.FixedUpdate");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch Blueprints: " + ex.Message));
			}
		}

		private void PatchSmartInserters()
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("SmartInserters");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("SmartInserters.Patches.InserterInstancePatch");
				if (type == null)
				{
					type = assembly.GetType("SmartInserters.InserterInstancePatch");
				}
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("ShouldGiveItems", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefixReturnTrue", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched SmartInserters.ShouldGiveItems");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch SmartInserters: " + ex.Message));
			}
		}

		private void PatchCaspersLoaders()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("caspersLoaders");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("caspersLoaders.LoaderPlugin");
				if (type != null)
				{
					MethodInfo method = type.GetMethod("FixedUpdate", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched caspersLoaders.FixedUpdate");
						patchCount++;
					}
				}
				Type type2 = assembly.GetType("caspersLoaders.Patches.BlockVisualsPatch");
				if (type2 != null)
				{
					MethodInfo method2 = type2.GetMethod("BlockVisuals", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method2 != null)
					{
						Harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched caspersLoaders.BlockVisuals");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch caspersLoaders: " + ex.Message));
			}
		}

		private void PatchCrusherCoreBoost()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("CrusherCoreBoost");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("CrusherCoreBoost.Patches.TechTreeStatePatches");
				if (type == null)
				{
					type = assembly.GetType("CrusherCoreBoost.TechTreeStatePatches");
				}
				if (!(type == null))
				{
					MethodInfo method = type.GetMethod("ResetAtStartOfFrame_Prefix", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						Harmony.Patch((MethodBase)method, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched CrusherCoreBoost.ResetAtStartOfFrame_Prefix");
						patchCount++;
					}
					MethodInfo method2 = type.GetMethod("HandleEndOfFrame_Postfix", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method2 != null)
					{
						Harmony.Patch((MethodBase)method2, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)"Patched CrusherCoreBoost.HandleEndOfFrame_Postfix");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch CrusherCoreBoost: " + ex.Message));
			}
		}

		private void PatchEMUBuilder()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			try
			{
				Assembly assembly = GetAssembly("EMUBuilder");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("EMUBuilder");
				if (type == null)
				{
					return;
				}
				MethodInfo[] methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.Name == "BuildMachine")
					{
						Harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(NetworkServerPrefixes), "ServerOnlyPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						Log.LogInfo((object)$"Patched EMUBuilder.BuildMachine ({methodInfo.GetParameters().Length} params)");
						patchCount++;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Failed to patch EMUBuilder: " + ex.Message));
			}
		}

		private Assembly GetAssembly(string name)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name == name)
				{
					return assembly;
				}
			}
			return null;
		}
	}
	public static class NetworkServerPrefixes
	{
		public static bool ServerOnlyPrefix()
		{
			return NetworkServer.active;
		}

		public static bool ServerOnlyPrefixReturnTrue(ref bool __result)
		{
			if (!NetworkServer.active)
			{
				__result = true;
				return false;
			}
			return true;
		}
	}
}