using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BaseNutcrackerMusicFix.Patches;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BaseNutcrackerMusicFix")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BaseNutcrackerMusicFix")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c884f0ec-15b3-4d46-8b5f-ef1d0049ee0a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BaseNutcrackerMusicFix
{
[BepInPlugin("HondaOdyssey.BaseNutcrackerMusicFix", "Base Nutcracker Music Fix", "1.0.0")]
public class BaseNutcrackerMusicFix : BaseUnityPlugin
{
private const string modGUID = "HondaOdyssey.BaseNutcrackerMusicFix";
private const string modName = "Base Nutcracker Music Fix";
private const string modVersion = "1.0.0";
private readonly Harmony harmony = new Harmony("HondaOdyssey.BaseNutcrackerMusicFix");
private static BaseNutcrackerMusicFix Instance;
internal ManualLogSource mls;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("HondaOdyssey.BaseNutcrackerMusicFix");
mls.LogInfo((object)"Patching NutcrackerAI...");
harmony.PatchAll(typeof(BaseNutcrackerMusicFix));
harmony.PatchAll(typeof(NutcrackerAIPatch));
mls.LogInfo((object)"Patched Nutcracker AI");
}
}
}
namespace BaseNutcrackerMusicFix.Patches
{
internal static class NutcrackerAIPatch
{
[HarmonyTranspiler]
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
CodeInstruction item = Transpilers.EmitDelegate<Action<AudioSource>>((Action<AudioSource>)delegate(AudioSource audio)
{
if (!audio.isPlaying)
{
audio.loop = true;
audio.Play();
}
});
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = -1;
for (int i = 0; i < list.Count - 1; i++)
{
if (list[i].opcode == OpCodes.Ldfld && ((FieldInfo)list[i].operand).Name == "creatureVoice")
{
num = i;
break;
}
}
if (num == -1)
{
throw new Exception("Unable to patch NutcrackerAI");
}
list.RemoveRange(num + 1, 7);
list.Insert(num + 1, item);
return list;
}
}
}