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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MoskauNutcracker.Patches;
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: AssemblyTitle("MoskauNutcracker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoskauNutcracker")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("793e286b-ab6c-431e-922f-64a8cd0c800e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoskauNutcracker
{
public class Config
{
public static ConfigEntry<float> volume;
public Config(ConfigFile configFile)
{
volume = configFile.Bind<float>("General", "volume", 1f, "Volume multiplier of the song.");
}
}
[BepInPlugin("KamenVacuumCleaner.MoskauNutcracker", "MoskauNutcracker", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
private const string GUID = "KamenVacuumCleaner.MoskauNutcracker";
private const string NAME = "MoskauNutcracker";
private const string VERSION = "1.1.0";
internal ManualLogSource mls;
private Harmony harmony = new Harmony("MoskauNutcracker");
public static Plugin instance;
public AudioClip moskau;
public static Config config { get; internal set; }
private void Awake()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Invalid comparison between Unknown and I4
if ((Object)(object)instance == (Object)null)
{
instance = this;
}
config = new Config(((BaseUnityPlugin)this).Config);
mls = Logger.CreateLogSource("MoskauNutcracker");
mls.LogInfo((object)"Loading: MoskauNutcracker v1.1.0...");
string text = ((BaseUnityPlugin)this).Info.Location.TrimEnd("MoskauNutcracker.dll".ToCharArray());
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("File://" + text + "MoskauOffset.wav", (AudioType)20);
audioClip.SendWebRequest();
while (!audioClip.isDone)
{
}
if ((int)audioClip.result == 1)
{
moskau = DownloadHandlerAudioClip.GetContent(audioClip);
harmony.PatchAll(typeof(NutcrackerEnemyAIPatch));
mls.LogInfo((object)"MoskauNutcracker v1.1.0 has been loaded up successfully!");
}
else
{
mls.LogError((object)"An error occured while trying to load!");
}
}
}
}
namespace MoskauNutcracker.Patches
{
internal static class NutcrackerEnemyAIPatch
{
[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.clip = Plugin.instance.moskau;
audio.pitch = 1f;
audio.volume = Config.volume.Value;
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("Could not patch NutcrackerEnemyAI");
}
list.RemoveRange(num + 1, 7);
list.Insert(num + 1, item);
return list;
}
}
}