Decompiled source of MimicFinalAscentPatch v1.0.0

plugins/com.github.MiiMii1205.MimicFinalAscentPatch.dll

Decompiled 2 weeks ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mimic;
using MimicFinalAscentPatch.Patchers;
using Photon.Pun;
using Photon.Voice.Unity;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.MiiMii1205.MimicFinalAscentPatch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("com.github.MiiMii1205.MimicFinalAscentPatch")]
[assembly: AssemblyTitle("MimicFinalAscentPatch")]
[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace MimicFinalAscentPatch
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.github.MiiMii1205.MimicFinalAscentPatch", "MimicFinalAscentPatch", "1.0.0")]
	public class MimicFinalAscentPatchPlugin : BaseUnityPlugin
	{
		public const string Id = "com.github.MiiMii1205.MimicFinalAscentPatch";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "MimicFinalAscentPatch";

		public static string Version => "1.0.0";

		private static bool IsMimicPatchedTranspiler(MethodBase? met, string mimicPatchClassName)
		{
			if (met == null)
			{
				Log.LogInfo((object)("No patches exists. " + mimicPatchClassName + " was NOT patch."));
				return false;
			}
			Patches patchInfo = Harmony.GetPatchInfo(met);
			if (patchInfo != null)
			{
				foreach (Patch transpiler in patchInfo.Transpilers)
				{
					if (!(transpiler.PatchMethod.DeclaringType == null) && transpiler.PatchMethod.DeclaringType.Name == mimicPatchClassName)
					{
						Log.LogInfo((object)("Has " + mimicPatchClassName + " patch."));
						return true;
					}
				}
				Log.LogInfo((object)("Patch " + mimicPatchClassName + " was NOT found."));
			}
			else
			{
				Log.LogInfo((object)("No patches exists. " + mimicPatchClassName + " was NOT patch."));
			}
			return false;
		}

		private static bool IsMimicPatchedPrefix(MethodBase? met, string mimicPatchClassName)
		{
			if (met == null)
			{
				Log.LogInfo((object)("No patches exists. " + mimicPatchClassName + " was NOT patch."));
				return false;
			}
			Patches patchInfo = Harmony.GetPatchInfo(met);
			if (patchInfo != null)
			{
				foreach (Patch prefix in patchInfo.Prefixes)
				{
					if (!(prefix.PatchMethod.DeclaringType == null) && prefix.PatchMethod.DeclaringType.Name == mimicPatchClassName)
					{
						Log.LogInfo((object)("Has " + mimicPatchClassName + " patch."));
						return true;
					}
				}
				Log.LogInfo((object)("Patch " + mimicPatchClassName + " was NOT found."));
			}
			else
			{
				Log.LogInfo((object)("No patches exists. " + mimicPatchClassName + " was NOT patch."));
			}
			return false;
		}

		private static bool IsMimicPatchedPostfix(MethodBase? met, string mimicPatchClassName)
		{
			if (met == null)
			{
				Log.LogInfo((object)("No patches exists. " + mimicPatchClassName + " was NOT patch."));
				return false;
			}
			Patches patchInfo = Harmony.GetPatchInfo(met);
			if (patchInfo != null)
			{
				foreach (Patch postfix in patchInfo.Postfixes)
				{
					if (!(postfix.PatchMethod.DeclaringType == null) && postfix.PatchMethod.DeclaringType.Name == mimicPatchClassName)
					{
						Log.LogInfo((object)("Has " + mimicPatchClassName + " patch."));
						return true;
					}
				}
				Log.LogInfo((object)("Patch " + mimicPatchClassName + " was NOT found."));
			}
			else
			{
				Log.LogInfo((object)("No patches exists. " + mimicPatchClassName + " was NOT patch."));
			}
			return false;
		}

		private static void DoPatch()
		{
			if (!IsMimicPatchedTranspiler(AccessTools.Method(typeof(Character), "RPCA_Fall", (Type[])null, (Type[])null), "No_Mimic_Fall_Shake"))
			{
				Log.LogInfo((object)"Patching RPCA_Fall with MimicFallShakeFinalAscent");
				Harmony.CreateAndPatchAll(typeof(MimicFallShakeFinalAscent), (string)null);
			}
			else
			{
				Log.LogWarning((object)"No_Mimic_Fall_Shake already applied. Skipping...");
			}
			CheckAndPatchMimic(AccessTools.Method(typeof(UIPlayerNames), "UpdateName", (Type[])null, (Type[])null), (HarmonyPatchType)1, typeof(Global_Hide_Names_Patch));
			CheckAndPatchMimic(AccessTools.Method(typeof(MushroomZombie), "Awake", (Type[])null, (Type[])null), (HarmonyPatchType)2, typeof(Global_Zombie_Override));
			CheckAndPatchMimic(AccessTools.Method(typeof(MicWrapper), "Read", (Type[])null, (Type[])null), (HarmonyPatchType)3, typeof(Mic_Hook));
			CheckAndPatchMimic(AccessTools.Method(typeof(CharacterClimbing), "Update", (Type[])null, (Type[])null), (HarmonyPatchType)3, typeof(No_Mimic_Climb_Shake));
			CheckAndPatchMimic(AccessTools.Method(typeof(CharacterMovement), "RaycastGroundCheck", (Type[])null, (Type[])null), (HarmonyPatchType)3, typeof(No_Mimic_Landing_Shake));
			CheckAndPatchMimic(AccessTools.Method(typeof(RunManager), "StartRun", (Type[])null, (Type[])null), (HarmonyPatchType)2, typeof(Run_Start_Patch));
			CheckAndPatchMimic(AccessTools.Method(typeof(MushroomZombie), "RPC_PlaySFX", (Type[])null, (Type[])null), (HarmonyPatchType)1, typeof(Silence_Disguised_Zombie));
			CheckAndPatchMimic(AccessTools.Method(typeof(CharacterVoiceHandler), "Start", (Type[])null, (Type[])null), (HarmonyPatchType)2, typeof(Voice_Injection_Patch));
			Log.LogInfo((object)"Mimic 1.0.0 - Final Release [FINAL ASCENT PATCH].");
			PhotonNetwork.MaxResendsBeforeDisconnect = 20;
			PhotonNetwork.SerializationRate = 20;
		}

		private static void CheckAndPatchMimic(MethodInfo? met, HarmonyPatchType? ptype, Type patchClassType)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected I4, but got Unknown
			if (met == null)
			{
				throw new ArgumentNullException("met", "Method couldn't be found");
			}
			if (ptype switch
			{
				(HarmonyPatchType)0L => IsMimicPatchedPrefix(met, patchClassType.Name) ? 1 : 0, 
				(HarmonyPatchType)1L => IsMimicPatchedPostfix(met, patchClassType.Name) ? 1 : 0, 
				(HarmonyPatchType)2L => IsMimicPatchedTranspiler(met, patchClassType.Name) ? 1 : 0, 
				_ => throw new ArgumentOutOfRangeException("ptype", ptype, null), 
			} == 0)
			{
				Log.LogInfo((object)("Patching " + met.Name + " with " + patchClassType.Name));
				Harmony.CreateAndPatchAll(patchClassType, (string)null);
			}
			else
			{
				Log.LogWarning((object)(patchClassType.Name + " already applied. Skipping..."));
			}
		}

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			DoPatch();
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}
	}
}
namespace MimicFinalAscentPatch.Patchers
{
	[HarmonyPatch(typeof(Character), "RPCA_Fall")]
	public static class MimicFallShakeFinalAscent
	{
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			return No_Mimic_Fall_Shake.Transpiler(instructions);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}