using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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("REPOAudioFixer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("REPOAudioFixer")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6482652c-dcda-4c8e-842f-da186da2942c")]
[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")]
[BepInPlugin("com.supernova.audiorework", "Audio Rework", "1.0.0")]
public class AudioRework : BaseUnityPlugin
{
[HarmonyPatch(typeof(AudioSource))]
private class Patch_Play
{
[HarmonyPatch("Play", new Type[] { })]
[HarmonyPostfix]
private static void Postfix(AudioSource __instance)
{
TryAttach(__instance);
}
}
[HarmonyPatch(typeof(AudioSource))]
private class Patch_PlayOneShot
{
[HarmonyPatch("PlayOneShot", new Type[] { typeof(AudioClip) })]
[HarmonyPostfix]
private static void Postfix(AudioSource __instance)
{
TryAttach(__instance);
}
}
public static ConfigEntry<int> rayCount;
public static ConfigEntry<float> minVolume;
public static ConfigEntry<float> maxCutoff;
public static ConfigEntry<float> minCutoff;
public static ConfigEntry<float> smoothingSpeed;
public static ConfigEntry<float> directionStrength;
public static ConfigEntry<float> diffractionSoftness;
public static ConfigEntry<float> earResponsiveness;
private static readonly ManualLogSource Logger = Logger.CreateLogSource("REPOAudioFixer_Class2");
private void Awake()
{
//IL_0132: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Expected O, but got Unknown
Logger.LogInfo((object)"Audio Rework Loaded");
rayCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Ray Count", 7, "Number of rays used for occlusion");
minVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Min Volume", 0.25f, "Lowest volume when fully occluded");
maxCutoff = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Max Cutoff", 22000f, "Clear sound cutoff frequency");
minCutoff = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Min Cutoff", 1200f, "Muffled sound cutoff frequency");
smoothingSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Smoothing Speed", 5f, "How fast audio transitions");
directionStrength = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Direction Strength", 1.8f, "1.0 = weak\r\n2.0 = stronger muffling when sound is behind player");
diffractionSoftness = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Diffraction Softness", 0.2f, "Higher = sound wraps more around corners");
earResponsiveness = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Ear Responsiveness", 5f, "Higher = snappier left/right movement");
Harmony val = new Harmony("com.supernova.audiorework");
val.PatchAll();
Logger.LogInfo((object)"Harmony patches applied");
Logger.LogInfo((object)("Patches: " + val.GetPatchedMethods().Count()));
}
private static void TryAttach(AudioSource source)
{
if (!((Object)(object)source == (Object)null) && !(source.spatialBlend < 0.1f) && (Object)(object)((Component)source).GetComponent<AudioReworkTag>() == (Object)null)
{
((Component)source).gameObject.AddComponent<AudioReworkTag>();
}
}
}
public class AudioReworkTag : MonoBehaviour
{
private AudioSource source;
private AudioLowPassFilter filter;
private Camera playerCam;
private void Awake()
{
source = ((Component)this).GetComponent<AudioSource>();
filter = ((Component)this).GetComponent<AudioLowPassFilter>();
if ((Object)(object)filter == (Object)null)
{
filter = ((Component)this).gameObject.AddComponent<AudioLowPassFilter>();
}
}
private void ApplyOcclusion()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Unknown result type (might be due to invalid IL or missing references)
//IL_0186: Unknown result type (might be due to invalid IL or missing references)
//IL_0188: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01df: Unknown result type (might be due to invalid IL or missing references)
//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
Vector3 position = ((Component)playerCam).transform.position;
Vector3 position2 = ((Component)this).transform.position;
Vector3 val = position2 - position;
float magnitude = ((Vector3)(ref val)).magnitude;
if (magnitude <= 0.1f)
{
return;
}
int value = AudioRework.rayCount.Value;
int num = 0;
float num2 = 0f;
RaycastHit val4 = default(RaycastHit);
for (int i = 0; i < value; i++)
{
Vector3 val2 = Random.insideUnitSphere * 0.3f;
Vector3 val3 = val + val2;
Vector3 normalized = ((Vector3)(ref val3)).normalized;
if (Physics.Raycast(position, normalized, ref val4, magnitude))
{
num++;
num2 = ((Component)((RaycastHit)(ref val4)).collider).tag switch
{
"Glass" => num2 + 0.2f,
"Wood" => num2 + 0.5f,
"Metal" => num2 + 0.8f,
_ => num2 + 1f,
};
}
}
float num3 = (float)num / (float)value;
if (num > 0)
{
num3 *= num2 / (float)num;
}
float num4 = Mathf.Lerp(AudioRework.diffractionSoftness.Value, 0f, num3);
num3 = Mathf.Clamp01(num3 - num4);
Vector3 forward = ((Component)playerCam).transform.forward;
Vector3 normalized2 = ((Vector3)(ref val)).normalized;
float num5 = Vector3.Dot(forward, normalized2);
num5 = Mathf.Clamp01((num5 + 1f) * 0.5f);
num5 = Mathf.Pow(num5, AudioRework.directionStrength.Value);
float num6 = Mathf.Lerp(num3, 1f, 1f - num5);
Vector3 right = ((Component)playerCam).transform.right;
float num7 = Vector3.Dot(right, normalized2);
source.panStereo = Mathf.Lerp(source.panStereo, num7, Time.deltaTime * AudioRework.earResponsiveness.Value);
float num8 = num6;
float num9 = Mathf.Lerp(1f, AudioRework.minVolume.Value, num8);
source.volume = Mathf.Lerp(source.volume, num9, Time.deltaTime * AudioRework.smoothingSpeed.Value);
float num10 = Mathf.Lerp(AudioRework.maxCutoff.Value, AudioRework.minCutoff.Value, num8);
filter.cutoffFrequency = Mathf.Lerp(filter.cutoffFrequency, num10, Time.deltaTime * AudioRework.smoothingSpeed.Value);
}
}