using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using MegalovaniaItemDrop.Patches;
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.0.0")]
public class MegalovaniaItemDrop : BaseUnityPlugin
{
private const string modGUID = "Prometheus121.MegalovaniaBellDrop";
private const string modName = "Megalovania Bell Drop";
private const string modVersion = "1.0.0";
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(typeof(MegalovaniaItemDropPatch));
harmony.PatchAll(typeof(MegalovaniaResetNotesPatch));
}
}
}
namespace MegalovaniaItemDrop.Patches
{
[HarmonyPatch(typeof(EventWhenDroppedItem), "PlayDropSFX")]
internal class MegalovaniaItemDropPatch
{
private 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)
};
public static int currentNote = 0;
[HarmonyPrefix]
public static bool MegalovaniaDropItemPatch(ref EventWhenDroppedItem __instance)
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)((GrabbableObject)__instance).itemProperties.dropSFX != (Object)null)
{
FieldInfo fieldInfo = AccessTools.Field(((object)__instance).GetType(), "timesPlayedInSameSpot");
int num = (int)fieldInfo.GetValue(__instance);
FieldInfo fieldInfo2 = AccessTools.Field(((object)__instance).GetType(), "lastPositionDropped");
Vector3 val = (Vector3)fieldInfo2.GetValue(__instance);
__instance.itemAudio.pitch = megalovania[currentNote];
currentNote++;
if (currentNote >= megalovania.Length)
{
currentNote = 0;
}
__instance.itemAudio.PlayOneShot(((GrabbableObject)__instance).itemProperties.dropSFX);
WalkieTalkie.TransmitOneShotAudio(__instance.itemAudio, ((GrabbableObject)__instance).itemProperties.dropSFX, 1f);
RoundManager.Instance.PlayAudibleNoise(((Component)__instance).transform.position, __instance.noiseRange, __instance.noiseLoudness, num, ((GrabbableObject)__instance).isInElevator && StartOfRound.Instance.hangarDoorsClosed, 941);
if (Vector3.Distance(((Component)__instance).transform.position, val) < __instance.lastPositionDroppedThresholdDistance)
{
num += __instance.effectWearOffMultiplier;
}
else
{
num = 0;
}
((GrabbableObject)__instance).hasHitGround = true;
return false;
}
((GrabbableObject)__instance).hasHitGround = true;
return true;
}
}
[HarmonyPatch(typeof(StartOfRound), "WritePlayerNotes")]
internal class MegalovaniaResetNotesPatch
{
[HarmonyPrefix]
private static void MegalovaniaResetNotes()
{
MegalovaniaItemDropPatch.currentNote = 0;
}
}
}