using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
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("MegalovaniaItemDrop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MegalovaniaItemDrop")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a378d9b3-feab-4685-8fc4-a53a28d88d72")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MegalovaniaItemDrop
{
[BepInPlugin("Prometheus121.MegalovaniaBellDrop", "Megalovania Bell Drop", "1.1.1")]
public class MegalovaniaItemDrop : BaseUnityPlugin
{
private const string modGUID = "Prometheus121.MegalovaniaBellDrop";
private const string modName = "Megalovania Bell Drop";
private const string modVersion = "1.1.1";
private readonly Harmony harmony = new Harmony("Prometheus121.MegalovaniaBellDrop");
private static MegalovaniaItemDrop instance;
internal static ManualLogSource mls;
private void Awake()
{
if ((Object)(object)instance == (Object)null)
{
instance = new MegalovaniaItemDrop();
}
mls = Logger.CreateLogSource("Prometheus121.MegalovaniaBellDrop");
mls.LogInfo((object)"Prepare for a reality check through the skull");
harmony.PatchAll();
}
}
}
namespace MegalovaniaItemDrop.Patches
{
[HarmonyPatch(typeof(EventWhenDroppedItem), "PlayDropSFX")]
internal static class MegalovaniaItemDropPatch
{
internal static readonly float[] megalovania = new float[40]
{
Mathf.Pow(2f, 1f / 6f),
Mathf.Pow(2f, 1f / 6f),
Mathf.Pow(2f, 1.1666666f),
Mathf.Pow(2f, 0.75f),
Mathf.Pow(2f, 2f / 3f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 1f / 6f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, 0f),
Mathf.Pow(2f, 0f),
Mathf.Pow(2f, 1.1666666f),
Mathf.Pow(2f, 0.75f),
Mathf.Pow(2f, 2f / 3f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 1f / 6f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, -1f / 12f),
Mathf.Pow(2f, -1f / 12f),
Mathf.Pow(2f, 1.1666666f),
Mathf.Pow(2f, 0.75f),
Mathf.Pow(2f, 2f / 3f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 1f / 6f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, -1f / 6f),
Mathf.Pow(2f, -1f / 6f),
Mathf.Pow(2f, 1.1666666f),
Mathf.Pow(2f, 0.75f),
Mathf.Pow(2f, 2f / 3f),
Mathf.Pow(2f, 7f / 12f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 1f / 6f),
Mathf.Pow(2f, 5f / 12f),
Mathf.Pow(2f, 7f / 12f)
};
internal static int currentNote = 0;
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Expected O, but got Unknown
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_0180: Expected O, but got Unknown
//IL_018f: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Expected O, but got Unknown
//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
//IL_01b2: Expected O, but got Unknown
//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Expected O, but got Unknown
//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Expected O, but got Unknown
//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
//IL_01fc: Expected O, but got Unknown
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Expected O, but got Unknown
//IL_0222: Unknown result type (might be due to invalid IL or missing references)
//IL_022c: Expected O, but got Unknown
//IL_023c: Unknown result type (might be due to invalid IL or missing references)
//IL_0246: Expected O, but got Unknown
bool flag = false;
int num = -4;
MethodInfo methodInfo = AccessTools.Method(typeof(AudioSource), "PlayOneShot", new Type[1] { typeof(AudioClip) }, (Type[])null);
int num2 = 0;
FieldInfo fieldInfo = AccessTools.Field(typeof(EventWhenDroppedItem), "itemAudio");
MethodInfo methodInfo2 = AccessTools.PropertySetter(typeof(AudioSource), "pitch");
if (methodInfo2 == null)
{
MegalovaniaItemDrop.mls.LogError((object)"Failed to retireve set_pitch");
return instructions;
}
if (fieldInfo == null)
{
MegalovaniaItemDrop.mls.LogError((object)"Failed to revtrieve itemAudio");
return instructions;
}
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Callvirt && list[i].operand == methodInfo)
{
if (flag)
{
MegalovaniaItemDrop.mls.LogError((object)"Multiple PlayOneShot calls found");
break;
}
num2 = i;
flag = true;
}
}
FieldInfo fieldInfo2 = AccessTools.Field(typeof(MegalovaniaItemDropPatch), "megalovania");
FieldInfo fieldInfo3 = AccessTools.Field(typeof(MegalovaniaItemDropPatch), "currentNote");
list.Insert(num2 + num, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
list.Insert(num2 + num + 1, new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo));
list.Insert(num2 + num + 2, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo2));
list.Insert(num2 + num + 3, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo3));
list.Insert(num2 + num + 4, new CodeInstruction(OpCodes.Ldelem_R4, (object)null));
list.Insert(num2 + num + 5, new CodeInstruction(OpCodes.Callvirt, (object)methodInfo2));
list.Insert(num2 + num + 6, new CodeInstruction(OpCodes.Ldsfld, (object)fieldInfo3));
list.Insert(num2 + num + 7, new CodeInstruction(OpCodes.Ldc_I4_1, (object)null));
list.Insert(num2 + num + 8, new CodeInstruction(OpCodes.Add, (object)null));
list.Insert(num2 + num + 9, new CodeInstruction(OpCodes.Stsfld, (object)fieldInfo3));
return list.AsEnumerable();
}
}
[HarmonyPatch]
internal class MegalovaniaResetPatch
{
[HarmonyPatch(typeof(StartOfRound), "WritePlayerNotes")]
[HarmonyPrefix]
private static void MegalovaniaResetNotes()
{
MegalovaniaItemDropPatch.currentNote = 0;
}
[HarmonyPatch(typeof(EventWhenDroppedItem), "PlayDropSFX")]
[HarmonyPrefix]
private static void MegalovaniaResetOOBNotes()
{
if (MegalovaniaItemDropPatch.currentNote > MegalovaniaItemDropPatch.megalovania.Length - 1)
{
MegalovaniaItemDropPatch.currentNote = 0;
}
}
}
}