Decompiled source of CoordinateForEasterEggsFix v1.0.0

CFEELowVersionFix.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CFEELowVersionFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Low-version compatibility fix for CoordinateForEasterEggs.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+8dc079a6e01835fdf42f254d7f6af108b1baa7e5")]
[assembly: AssemblyProduct("CFEELowVersionFix")]
[assembly: AssemblyTitle("CFEELowVersionFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 Asta.CfeeLowVersionFix
{
	[BepInPlugin("asta.cfee.lowverfix", "CFEE Low Version Fix", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class CfeeLowVersionFixPlugin : BaseUnityPlugin
	{
		internal const string PluginGuid = "asta.cfee.lowverfix";

		internal const string PluginName = "CFEE Low Version Fix";

		internal const string PluginVersion = "0.1.0";

		internal static ManualLogSource Log;

		internal static Harmony HarmonyInstance;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			HarmonyInstance = new Harmony("asta.cfee.lowverfix");
			HarmonyInstance.PatchAll();
			OriginalCfeeHooks.Install(HarmonyInstance);
			Log.LogInfo((object)"CFEE Low Version Fix loaded.");
		}

		private void Start()
		{
			OriginalCfeeHooks.Install(HarmonyInstance);
		}
	}
	internal static class OriginalCfeeHooks
	{
		private const BindingFlags AnyMethod = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly HashSet<string> InstalledTargets = new HashSet<string>(StringComparer.Ordinal);

		private static MethodInfo? _generateEggLineMethod;

		private static bool _loggedGenerateEggLineFailure;

		internal static void Install(Harmony harmony)
		{
			TryInstallBypassPatch(harmony, "testModLethalCompany.Patches.CoordinateForEasterEggs", "CoordinateForEasterEggs", "SetExplodeOnThrowClinetRPCExtension", "SkipOriginalSetExplodeExtension");
			TryInstallBypassPatch(harmony, "testModLethalCompany.EggLineSync", "EggLineSync", "EggLinesClientRpc", "SkipEggLinesClientRpc");
		}

		internal static bool TryGenerateEggLine(Vector3 position, bool explodeOnThrow)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			MethodInfo methodInfo = ResolveGenerateEggLineMethod();
			if ((object)methodInfo == null)
			{
				return false;
			}
			try
			{
				methodInfo.Invoke(null, new object[2] { position, explodeOnThrow });
				return true;
			}
			catch (Exception arg)
			{
				CfeeLowVersionFixPlugin.Log.LogError((object)$"Failed to invoke CoordinateForEasterEggs.GenerateEggLine: {arg}");
				return false;
			}
		}

		private static bool SkipOriginalSetExplodeExtension()
		{
			return false;
		}

		private static bool SkipEggLinesClientRpc()
		{
			return false;
		}

		private static void TryInstallBypassPatch(Harmony harmony, string fullTypeName, string fallbackTypeName, string methodName, string prefixName)
		{
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			string methodName2 = methodName;
			Type type = FindType(fullTypeName, fallbackTypeName);
			if ((object)type == null)
			{
				return;
			}
			MethodInfo methodInfo = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo method) => string.Equals(method.Name, methodName2, StringComparison.Ordinal));
			if ((object)methodInfo == null)
			{
				return;
			}
			string text = methodInfo.DeclaringType?.FullName + "." + methodInfo.Name;
			if (InstalledTargets.Add(text))
			{
				MethodInfo method2 = typeof(OriginalCfeeHooks).GetMethod(prefixName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if ((object)method2 == null)
				{
					CfeeLowVersionFixPlugin.Log.LogWarning((object)("Bypass prefix '" + prefixName + "' could not be found."));
					return;
				}
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				CfeeLowVersionFixPlugin.Log.LogInfo((object)("Installed bypass for " + text + "."));
			}
		}

		private static MethodInfo? ResolveGenerateEggLineMethod()
		{
			if ((object)_generateEggLineMethod != null)
			{
				return _generateEggLineMethod;
			}
			Type type = FindType("testModLethalCompany.Patches.CoordinateForEasterEggs", "CoordinateForEasterEggs");
			if ((object)type == null)
			{
				LogMissingGenerateEggLine("CoordinateForEasterEggs type was not found.");
				return null;
			}
			_generateEggLineMethod = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(delegate(MethodInfo method)
			{
				if (!string.Equals(method.Name, "GenerateEggLine", StringComparison.Ordinal))
				{
					return false;
				}
				ParameterInfo[] parameters = method.GetParameters();
				return parameters.Length == 2 && parameters[0].ParameterType == typeof(Vector3) && parameters[1].ParameterType == typeof(bool);
			});
			if ((object)_generateEggLineMethod == null)
			{
				LogMissingGenerateEggLine("CoordinateForEasterEggs.GenerateEggLine(Vector3, bool) was not found.");
			}
			return _generateEggLineMethod;
		}

		private static Type? FindType(string fullName, string fallbackName)
		{
			string fallbackName2 = fallbackName;
			string fullName2 = fullName;
			Type type = AccessTools.TypeByName(fullName2);
			if ((object)type != null)
			{
				return type;
			}
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				try
				{
					type = assembly.GetType(fullName2, throwOnError: false);
					if ((object)type != null)
					{
						return type;
					}
					type = assembly.GetTypes().FirstOrDefault((Type candidate) => string.Equals(candidate.Name, fallbackName2, StringComparison.Ordinal));
					if ((object)type != null)
					{
						return type;
					}
				}
				catch (ReflectionTypeLoadException ex)
				{
					type = ex.Types.FirstOrDefault((Type candidate) => (object)candidate != null && (string.Equals(candidate.FullName, fullName2, StringComparison.Ordinal) || string.Equals(candidate.Name, fallbackName2, StringComparison.Ordinal)));
					if ((object)type != null)
					{
						return type;
					}
				}
			}
			return null;
		}

		private static void LogMissingGenerateEggLine(string message)
		{
			if (!_loggedGenerateEggLineFailure)
			{
				_loggedGenerateEggLineFailure = true;
				CfeeLowVersionFixPlugin.Log.LogWarning((object)message);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CFEELowVersionFix";

		public const string PLUGIN_NAME = "CFEELowVersionFix";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace Asta.CfeeLowVersionFix.Patches
{
	[HarmonyPatch(typeof(StunGrenadeItem), "SetExplodeOnThrowClientRpc")]
	internal static class StunGrenadeItemSetExplodeOnThrowClientRpcPatch
	{
		private static void Postfix(StunGrenadeItem __instance)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (__instance != null)
			{
				bool explodeOnThrow = __instance.explodeOnThrow;
				if (!OriginalCfeeHooks.TryGenerateEggLine(((Component)__instance).transform.position, explodeOnThrow))
				{
					CfeeLowVersionFixPlugin.Log.LogDebug((object)"Skipped local egg line generation because the original method could not be resolved.");
				}
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}