using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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 Newtonsoft.Json;
using UnityEngine;
using loaforcsSoundAPI.Core.JSON;
using loaforcsSoundAPI.SoundPacks;
using loaforcsSoundAPI.SoundPacks.Data;
using loaforcsSoundAPI.SoundPacks.Data.Conditions;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("me.loaforc.soundapi")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("me.loaforc.balatroquotasounds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BalatroQuotaSounds")]
[assembly: AssemblyTitle("me.loaforc.balatroquotasounds")]
[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 BalatroQuotaSounds
{
[BepInPlugin("me.loaforc.balatroquotasounds", "BalatroQuotaSounds", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BalatroQuotaSounds : BaseUnityPlugin
{
internal static Coroutine currentSoundCoroutine;
internal static Coroutine fireCoroutine;
internal static SoundEscalationSettings settings;
internal static FireSettings fireSettings;
internal static AudioSource source;
internal static AudioSource fireSource;
public static BalatroQuotaSounds Instance { get; private set; }
internal static ManualLogSource Logger { get; private set; }
private void Awake()
{
Logger = Logger.CreateLogSource("me.loaforc.balatroquotasounds");
Instance = this;
Logger.LogInfo((object)"patching");
Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "me.loaforc.soundapi");
Reload();
Logger.LogInfo((object)"done :3");
}
private static void Reload()
{
Logger.LogInfo((object)"loading misc settings");
settings = JSONDataLoader.LoadFromFile<SoundEscalationSettings>(GetRelativePath("escalation_settings.json"));
fireSettings = JSONDataLoader.LoadFromFile<FireSettings>(GetRelativePath("fire_settings.json"));
Logger.LogDebug((object)JsonConvert.SerializeObject((object)settings));
Logger.LogDebug((object)JsonConvert.SerializeObject((object)fireSettings));
}
private static string GetRelativePath(string path)
{
return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path);
}
}
public class FireSettings
{
public float InitialDelay { get; private set; }
public float BaseVolume { get; private set; }
public float TargetVolume { get; private set; }
public float RampUpTime { get; private set; }
public float CalculateSlope()
{
return (TargetVolume - BaseVolume) / RampUpTime;
}
public float CalculateAt(float x)
{
return CalculateSlope() * x + BaseVolume;
}
}
public class SoundEscalationSettings
{
public float BasePitch { get; private set; } = 1f;
public float PitchStep { get; private set; }
public float MaxPitch { get; private set; } = 1f;
public bool ResetPitchAtMax { get; private set; }
public float BaseDelay { get; private set; } = 0.2f;
public float DelayStep { get; private set; }
public float MinDelay { get; private set; } = 0.2f;
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "me.loaforc.balatroquotasounds";
public const string PLUGIN_NAME = "BalatroQuotaSounds";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace BalatroQuotaSounds.Patches
{
[HarmonyPatch(typeof(HUDManager))]
internal static class HUDManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void AddAudioSource(HUDManager __instance)
{
BalatroQuotaSounds.source = ((Component)__instance).gameObject.AddComponent<AudioSource>();
BalatroQuotaSounds.source.outputAudioMixerGroup = __instance.UIAudio.outputAudioMixerGroup;
BalatroQuotaSounds.fireSource = ((Component)__instance).gameObject.AddComponent<AudioSource>();
BalatroQuotaSounds.fireSource.outputAudioMixerGroup = __instance.UIAudio.outputAudioMixerGroup;
BalatroQuotaSounds.Logger.LogInfo((object)"created audio sources");
}
[HarmonyPatch("DisplayNewDeadline")]
[HarmonyPostfix]
private static void StartBalatroSounds(HUDManager __instance)
{
BalatroQuotaSounds.currentSoundCoroutine = ((MonoBehaviour)__instance).StartCoroutine(balatroSounds());
BalatroQuotaSounds.fireCoroutine = ((MonoBehaviour)__instance).StartCoroutine(FireHandler());
}
private static bool TryGetSound(string sound, out AudioClip clip)
{
SoundReplacementGroup val = default(SoundReplacementGroup);
return SoundReplacementHandler.TryGetReplacementClip(new string[3] { "*", "BalatroQuotaSounds", sound }, ref val, ref clip, (IContext)(object)SoundReplacementHandler.DEFAULT_CONTEXT);
}
private static IEnumerator balatroSounds()
{
BalatroQuotaSounds.source.pitch = BalatroQuotaSounds.settings.BasePitch;
yield return (object)new WaitForSeconds(3.5f);
if (!TryGetSound("basehit", out var basehit))
{
BalatroQuotaSounds.Logger.LogDebug((object)"no basehit sound");
yield break;
}
BalatroQuotaSounds.Logger.LogInfo((object)"beginning quota scoring sounds!");
float time = 0f;
float delay = BalatroQuotaSounds.settings.BaseDelay;
while (HUDManager.Instance.displayingNewQuota)
{
time += Time.deltaTime;
AudioSource source = BalatroQuotaSounds.source;
source.pitch += BalatroQuotaSounds.settings.PitchStep;
if (BalatroQuotaSounds.source.pitch > BalatroQuotaSounds.settings.MaxPitch)
{
if (BalatroQuotaSounds.settings.ResetPitchAtMax)
{
BalatroQuotaSounds.Logger.LogDebug((object)"reset pitch at max!");
BalatroQuotaSounds.source.pitch = BalatroQuotaSounds.settings.BasePitch;
}
else
{
BalatroQuotaSounds.source.pitch = BalatroQuotaSounds.settings.MaxPitch;
}
}
delay = Mathf.Max(delay + BalatroQuotaSounds.settings.DelayStep, BalatroQuotaSounds.settings.MinDelay);
BalatroQuotaSounds.source.PlayOneShot(basehit);
yield return (object)new WaitForSeconds(delay);
}
}
private static IEnumerator FireHandler()
{
yield return (object)new WaitForSeconds(3.5f);
if (!TryGetSound("fire", out var fire))
{
BalatroQuotaSounds.Logger.LogDebug((object)"no fire sound");
yield break;
}
BalatroQuotaSounds.Logger.LogInfo((object)$"fire starting in: {BalatroQuotaSounds.fireSettings.InitialDelay}");
yield return (object)new WaitForSeconds(BalatroQuotaSounds.fireSettings.InitialDelay);
BalatroQuotaSounds.Logger.LogInfo((object)"playing fire sound effect!!");
BalatroQuotaSounds.fireSource.volume = BalatroQuotaSounds.fireSettings.CalculateAt(0f);
BalatroQuotaSounds.fireSource.clip = fire;
while (HUDManager.Instance.displayingNewQuota)
{
BalatroQuotaSounds.fireSource.Play();
float time = 0f;
while (time < BalatroQuotaSounds.fireSettings.RampUpTime)
{
time += Time.deltaTime;
BalatroQuotaSounds.fireSource.volume = BalatroQuotaSounds.fireSettings.CalculateAt(time);
yield return null;
}
BalatroQuotaSounds.Logger.LogDebug((object)"reached target volume!!");
yield return (object)new WaitUntil((Func<bool>)(() => !BalatroQuotaSounds.fireSource.isPlaying));
BalatroQuotaSounds.Logger.LogDebug((object)"fire sound effect ended but we are still going.. looping sound");
}
}
}
[HarmonyPatch(typeof(SoundReplacementHandler))]
internal static class SoundReplacementHandlerPatch
{
[HarmonyPatch("TryReplaceAudio")]
[HarmonyPrefix]
[HarmonyWrapSafe]
private static bool LobotomizeSoundReplacementSometimes(ref AudioSource source, ref bool __result)
{
if ((Object)(object)source != (Object)(object)BalatroQuotaSounds.source)
{
return true;
}
__result = false;
return false;
}
}
[HarmonyPatch(typeof(TimeOfDay))]
internal static class TimeOfDayPatch
{
[HarmonyPatch("UpdateProfitQuotaCurrentTime")]
[HarmonyPrefix]
[HarmonyWrapSafe]
private static void StopBalatroSounds()
{
if (BalatroQuotaSounds.currentSoundCoroutine != null)
{
((MonoBehaviour)HUDManager.Instance).StopCoroutine(BalatroQuotaSounds.currentSoundCoroutine);
((MonoBehaviour)HUDManager.Instance).StopCoroutine(BalatroQuotaSounds.fireCoroutine);
BalatroQuotaSounds.source.Stop(true);
BalatroQuotaSounds.fireSource.Stop(true);
BalatroQuotaSounds.currentSoundCoroutine = null;
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}