using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ReverbTriggerFix.Components;
using ReverbTriggerFix.Core;
using ReverbTriggerFix.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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ReverbTriggerFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ReverbTriggerFix")]
[assembly: AssemblyTitle("ReverbTriggerFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace ReverbTriggerFix
{
[BepInPlugin("JacobG5.ReverbTriggerFix", "ReverbTriggerFix", "0.3.0")]
public class ReverbTriggerFixes : BaseUnityPlugin
{
private const string modGUID = "JacobG5.ReverbTriggerFix";
private const string modName = "ReverbTriggerFix";
private const string modVersion = "0.3.0";
private readonly Harmony harmony = new Harmony("JacobG5.ReverbTriggerFix");
public static ReverbTriggerFixes Instance;
internal ManualLogSource mls;
public static ConfigEntry<bool> disableMod;
public static ConfigEntry<bool> triggerOnEnter;
public static ConfigEntry<bool> extendedLogging;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
mls = Logger.CreateLogSource("JacobG5.ReverbTriggerFix");
disableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("Core", "disableMod", false, "Disables all reverb trigger modifications.\nRequires a lobby restart to apply.\nGame restart *not* required.");
triggerOnEnter = ((BaseUnityPlugin)this).Config.Bind<bool>("Experimental", "triggerOnEnter", false, "I'm not sure why reverb triggers run their calculations every frame when as far as I can tell they only need to run their changes when something enters their collider.\nI'm leaving this as an experimental toggle because it seems to be very buggy atm.\n\nFeel free to try it if you wish. If you're experiencing problems then turn it back off.");
extendedLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "extendedLogging", false, "Logs more info to the console when enabled.\n\n*THIS WILL SPAM YOUR CONSOLE DEPENDING ON YOUR OTHER SETTINGS*");
harmony.PatchAll(typeof(RoundManagerPatch));
harmony.PatchAll(typeof(AudioReverbTriggerPatch));
harmony.PatchAll(typeof(EntranceTeleportPatch));
harmony.PatchAll(typeof(JetpackItemPatch));
harmony.PatchAll(typeof(ShipTeleporterPatch));
}
}
}
namespace ReverbTriggerFix.Patches
{
[HarmonyPatch(typeof(AudioReverbTrigger))]
internal class AudioReverbTriggerPatch
{
[HarmonyPatch("OnTriggerStay")]
[HarmonyPrefix]
public static bool patchOnTriggerStay(Collider other, AudioReverbTrigger __instance)
{
if (!((Behaviour)__instance).enabled)
{
return false;
}
if (ReverbTriggerFixes.extendedLogging.Value)
{
ReverbTriggerFixes.Instance.mls.LogInfo((object)("Checking " + ((Object)other).name));
}
return true;
}
[HarmonyPatch("ChangeAudioReverbForPlayer")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return AudioReverbFixCore.FindObjectTranspiler(instructions);
}
}
[HarmonyPatch(typeof(EntranceTeleport))]
internal class EntranceTeleportPatch
{
[HarmonyPatch("SetAudioPreset")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return AudioReverbFixCore.FindObjectTranspiler(instructions);
}
}
[HarmonyPatch(typeof(JetpackItem))]
internal class JetpackItemPatch
{
[HarmonyPatch("ActivateJetpack")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return AudioReverbFixCore.FindObjectTranspiler(instructions);
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("SetSpectatedPlayerEffects")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
return AudioReverbFixCore.FindObjectTranspiler(instructions);
}
}
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPrefix]
public static void patchStart()
{
AudioReverbFixCore.PatchTriggers();
}
[HarmonyPatch("FinishGeneratingNewLevelClientRpc")]
[HarmonyPostfix]
public static void postLevelGeneration()
{
AudioReverbFixCore.PatchTriggers();
}
}
[HarmonyPatch(typeof(ShipTeleporter))]
internal class ShipTeleporterPatch
{
[HarmonyPatch("TeleportPlayerOutWithInverseTeleporter")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> InverseTpTranspiler(IEnumerable<CodeInstruction> instructions)
{
return AudioReverbFixCore.FindObjectTranspiler(instructions);
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> BeamUpTranspiler(IEnumerable<CodeInstruction> instructions)
{
return AudioReverbFixCore.FindObjectTranspiler(instructions);
}
}
}
namespace ReverbTriggerFix.Core
{
internal class AudioReverbFixCore
{
private static AudioReverbPresets levelPresets;
public static AudioReverbPresets GetAudioReverbPresets()
{
if (Object.op_Implicit((Object)(object)levelPresets))
{
return levelPresets;
}
ReverbTriggerFixes.Instance.mls.LogInfo((object)"Caching reverb presets.");
return levelPresets = Object.FindObjectOfType<AudioReverbPresets>();
}
public static void PatchTriggers()
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
if (ReverbTriggerFixes.disableMod.Value)
{
return;
}
bool value = ReverbTriggerFixes.triggerOnEnter.Value;
AudioReverbTrigger[] array = Object.FindObjectsOfType<AudioReverbTrigger>(true);
for (int i = 0; i < array.Length; i++)
{
Collider[] componentsInChildren = ((Component)array[i]).GetComponentsInChildren<Collider>();
if (componentsInChildren.Length == 0 || LayerMask.op_Implicit(componentsInChildren[0].excludeLayers) != 2145910775)
{
for (int j = 0; j < componentsInChildren.Length; j++)
{
componentsInChildren[j].excludeLayers = LayerMask.op_Implicit(2145910775);
componentsInChildren[j].layerOverridePriority = 100;
}
bool flag = false;
if (value)
{
((Component)array[i]).gameObject.AddComponent<AudioReverbTriggerFix>().trigger = array[i];
}
ReverbTriggerFixes.Instance.mls.LogInfo((object)$"Fixed {componentsInChildren.Length} colliders on {((Object)array[i]).name}. Experimental features enabled: {flag}");
}
}
}
public static IEnumerable<CodeInstruction> FindObjectTranspiler(IEnumerable<CodeInstruction> instructions)
{
MethodInfo FindObjectCall = SymbolExtensions.GetMethodInfo((Expression<Action>)(() => Object.FindObjectOfType<AudioReverbPresets>()));
MethodInfo ReplacementMethod = SymbolExtensions.GetMethodInfo((Expression<Action>)(() => GetAudioReverbPresets()));
bool found = false;
foreach (CodeInstruction instruction in instructions)
{
if (CodeInstructionExtensions.Calls(instruction, FindObjectCall))
{
found = true;
yield return new CodeInstruction(OpCodes.Call, (object)ReplacementMethod);
}
else
{
yield return instruction;
}
}
if (!found)
{
ReverbTriggerFixes.Instance.mls.LogInfo((object)"Couldn't find call to UnityEngine.Object.FindObjectOfType!");
}
}
}
}
namespace ReverbTriggerFix.Components
{
public class AudioReverbTriggerFix : MonoBehaviour
{
public AudioReverbTrigger trigger;
public void OnTriggerEnter(Collider other)
{
((MonoBehaviour)this).StartCoroutine(DisableReverbTrigger());
}
private IEnumerator DisableReverbTrigger()
{
((Behaviour)trigger).enabled = true;
yield return (object)new WaitForEndOfFrame();
((Behaviour)trigger).enabled = false;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}