Decompiled source of KeroFixes v1.1.1

plugins\Keroppi-KeroFixes\KeroFixes.dll

Decompiled 7 months 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 BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.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 KeroFixes
{
	[BepInPlugin("KeroBeepBoop.KeroFixes", "KeroFixes", "1.1.1")]
	[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 Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private static Type _mrapiType;

		private static MethodInfo _registerMethod;

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("KeroBeepBoop.KeroFixes").PatchAll();
			RegisterSuits();
			Logger.LogInfo((object)"KeroFixes loaded.");
		}

		private static void RegisterSuits()
		{
			_mrapiType = AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
			{
				try
				{
					return a.GetTypes();
				}
				catch
				{
					return Array.Empty<Type>();
				}
			}).FirstOrDefault((Type t) => t.FullName == "ModelReplacement.ModelReplacementAPI");
			if (_mrapiType == null)
			{
				Logger.LogWarning((object)"[KeroSuitFix] ModelReplacementAPI not found — suit fixes skipped");
				return;
			}
			_registerMethod = _mrapiType.GetMethod("RegisterSuitModelReplacement", BindingFlags.Static | BindingFlags.Public, null, new Type[2]
			{
				typeof(string),
				typeof(Type)
			}, null);
			if (_registerMethod == null)
			{
				Logger.LogError((object)"[KeroSuitFix] RegisterSuitModelReplacement not found on ModelReplacementAPI");
				return;
			}
			RegisterSuit("ModelReplacement.MRBELLADONNAFUTA", "belladonnafuta");
			RegisterSuit("ModelReplacement.MRUNTITLEDCKC", "futamewtwo");
			RegisterSuit("MikuModel_NotDefault.MRMIKU", "hatsunemiku");
		}

		private static void RegisterSuit(string typeName, string suitName)
		{
			Type type = AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
			{
				try
				{
					return a.GetTypes();
				}
				catch
				{
					return Array.Empty<Type>();
				}
			}).FirstOrDefault((Type t) => t.FullName == typeName);
			if (type == null)
			{
				Logger.LogWarning((object)("[KeroSuitFix] Type " + typeName + " not found — " + suitName + " skipped"));
				return;
			}
			try
			{
				_registerMethod.Invoke(null, new object[2] { suitName, type });
				Logger.LogInfo((object)("[KeroSuitFix] Registered " + suitName + " → " + typeName));
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("[KeroSuitFix] Failed to register " + suitName + ": " + (ex.InnerException?.Message ?? ex.Message)));
			}
		}
	}
	[HarmonyPatch]
	internal static class BakushinFixPatches
	{
		private static readonly Dictionary<int, float> _endTimes = new Dictionary<int, float>();

		private static bool ShouldPlay(AudioSource source, AudioClip clip)
		{
			if ((Object)(object)clip == (Object)null || clip.length < 10f)
			{
				return true;
			}
			if ((Object)(object)((Component)source).GetComponentInParent<CrawlerAI>() == (Object)null)
			{
				return true;
			}
			int instanceID = ((Object)source).GetInstanceID();
			float time = Time.time;
			if (_endTimes.TryGetValue(instanceID, out var value) && time < value)
			{
				return false;
			}
			_endTimes[instanceID] = time + clip.length;
			return true;
		}

		[HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[] { typeof(AudioClip) })]
		[HarmonyPrefix]
		private static bool PatchPlayOneShot(AudioSource __instance, AudioClip clip)
		{
			return ShouldPlay(__instance, clip);
		}

		[HarmonyPatch(typeof(AudioSource), "PlayOneShot", new Type[]
		{
			typeof(AudioClip),
			typeof(float)
		})]
		[HarmonyPrefix]
		private static bool PatchPlayOneShotVolume(AudioSource __instance, AudioClip clip, float volumeScale)
		{
			return ShouldPlay(__instance, clip);
		}

		[HarmonyPatch(typeof(AudioSource), "Play", new Type[] { })]
		[HarmonyPrefix]
		private static bool PatchPlay(AudioSource __instance)
		{
			return ShouldPlay(__instance, __instance.clip);
		}

		[HarmonyPatch(typeof(AudioSource), "Play", new Type[] { typeof(ulong) })]
		[HarmonyPrefix]
		private static bool PatchPlayDelayed(AudioSource __instance, ulong delay)
		{
			return ShouldPlay(__instance, __instance.clip);
		}
	}
	[HarmonyPatch]
	internal static class NullRefSilencerPatches
	{
		[HarmonyPatch(typeof(TerminalAccessibleObject), "Update")]
		[HarmonyFinalizer]
		private static Exception SilenceTerminalAccessibleUpdate(Exception __exception)
		{
			if (!(__exception is NullReferenceException))
			{
				return __exception;
			}
			return null;
		}

		[HarmonyPatch(typeof(AudioReverbTrigger), "ChangeAudioReverbForPlayer")]
		[HarmonyFinalizer]
		private static Exception SilenceReverbTriggerNull(Exception __exception)
		{
			if (!(__exception is NullReferenceException))
			{
				return __exception;
			}
			return null;
		}
	}
	[HarmonyPatch]
	internal static class PossessedMasksFix
	{
		[HarmonyTargetMethod]
		private static MethodBase TargetMethod()
		{
			Type type = AccessTools.TypeByName("PossessedMasks.Utils");
			if (!(type == null))
			{
				return AccessTools.Method(type, "TweakSpawnChanceAndMoons", (Type[])null, (Type[])null);
			}
			return null;
		}

		[HarmonyFinalizer]
		private static Exception Finalizer(Exception __exception)
		{
			if (__exception is NullReferenceException)
			{
				Plugin.Logger.LogWarning((object)"[PossessedMasksFix] Swallowed NRE in TweakSpawnChanceAndMoons — Mirage should now initialize correctly.");
				return null;
			}
			return __exception;
		}
	}
}