Decompiled source of LCUndefeatableNutcrackerMod v1.0.0

LCUndefeatableNutcrackerMod.dll

Decompiled a day ago
using System;
using System.Collections;
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 Unity.Netcode;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LCUndefeatableNutcrackerMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replace the Nutcracker's music with Undefeatable from Sonic Frontiers!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LCUndefeatableNutcrackerMod")]
[assembly: AssemblyTitle("LCUndefeatableNutcrackerMod")]
[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 LCUndefeatableNutcrackerMod
{
	[BepInPlugin("local.SimonTendo.LCUndefeatableNutcrackerMod", "LCUndefeatableNutcrackerMod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class Delayer : MonoBehaviour
		{
			public IEnumerator SetPitchAtFrameEnd(AudioSource audio)
			{
				yield return (object)new WaitForEndOfFrame();
				audio.pitch = 1f;
				Logger.LogDebug((object)"successfully reached end of coroutine");
			}
		}

		[HarmonyPatch]
		public class NutcrackerPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch(typeof(NutcrackerEnemyAI), "Start")]
			public static void StartPostfix(NutcrackerEnemyAI __instance)
			{
				if (loadSong)
				{
					Logger.LogDebug((object)$"setting Undefeatable audio variables on {((Object)__instance).name} #{((NetworkBehaviour)__instance).NetworkObjectId}");
					((EnemyAI)__instance).creatureVoice.clip = undefeatableSong;
					((EnemyAI)__instance).creatureVoice.dopplerLevel = 0f;
					((EnemyAI)__instance).creatureVoice.maxDistance = 25f;
					((EnemyAI)__instance).creatureVoice.time = 28f;
					((Component)__instance).gameObject.AddComponent<Delayer>();
				}
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(AudioSource), "Play")]
			public static bool PlayPrefix(AudioSource __instance)
			{
				if (loadSong && ((Object)((Component)__instance).gameObject).name == "CreatureVoice" && (Object)(object)((Component)__instance).transform.parent != (Object)null && ((Object)((Component)__instance).transform.parent).name == "NutcrackerEnemy(Clone)")
				{
					Delayer componentInParent = ((Component)__instance).GetComponentInParent<Delayer>();
					if ((Object)(object)componentInParent != (Object)null)
					{
						Logger.LogDebug((object)$"StartCoroutine on {componentInParent}");
						((MonoBehaviour)componentInParent).StartCoroutine(componentInParent.SetPitchAtFrameEnd(__instance));
					}
					if (__instance.isPlaying)
					{
						Logger.LogDebug((object)("not restarting song on " + ((Object)((Component)__instance).transform.parent).name));
						return false;
					}
				}
				return true;
			}
		}

		internal static ManualLogSource Logger;

		public static AudioClip undefeatableSong;

		public static bool loadSong = true;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Invalid comparison between Unknown and I4
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCUndefeatableNutcrackerMod is loaded!");
			Harmony val = new Harmony("LCUndefeatableNutcrackerMod");
			val.Patch((MethodBase)typeof(NutcrackerEnemyAI).GetMethod("Start"), (HarmonyMethod)null, new HarmonyMethod(typeof(NutcrackerPatch).GetMethod("StartPostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)(from x in typeof(AudioSource).GetMethods()
				where x.Name == "Play"
				select x).FirstOrDefault(), new HarmonyMethod(typeof(NutcrackerPatch).GetMethod("PlayPrefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			string text = ((BaseUnityPlugin)this).Info.Location.TrimEnd("LCUndefeatableNutcrackerMod.dll".ToCharArray());
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("File://" + text + "Undefeatable.ogg", (AudioType)14);
			audioClip.SendWebRequest();
			while (!audioClip.isDone)
			{
			}
			if ((int)audioClip.result == 1)
			{
				undefeatableSong = DownloadHandlerAudioClip.GetContent(audioClip);
				Logger.LogInfo((object)"Successfully loaded song");
			}
			else
			{
				loadSong = false;
				Logger.LogError((object)"Failed to load song");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCUndefeatableNutcrackerMod";

		public const string PLUGIN_NAME = "LCUndefeatableNutcrackerMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}