using System.Collections.Generic; 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.Logging; using HarmonyLib; using LethalThings.MonoBehaviours; using ReturnByDeath.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("ReturnByDeath")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ReturnByDeath")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("04f7ab02-1427-4ec5-b84a-1917d3c59b27")] [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 ReturnByDeath { [BepInPlugin("quocnam612.ReturnByDeath", "Rezero Return By Death SFX", "1.0.0")] public class ReturnByDeathBase : BaseUnityPlugin { private const string modGUID = "quocnam612.ReturnByDeath"; private const string modName = "Rezero Return By Death SFX"; private const string modVersion = "1.0.0"; private readonly Harmony harmony = new Harmony("quocnam612.ReturnByDeath"); public static ReturnByDeathBase Instance; internal ManualLogSource mls; internal static List SoundFX; internal static AssetBundle Bundle; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("quocnam612.ReturnByDeath"); mls.LogInfo((object)"[Rezero Return By Death SFX] v1.0.0 is loaded!"); harmony.PatchAll(typeof(ReturnByDeathBase)); harmony.PatchAll(typeof(SoundManagerPatch)); harmony.PatchAll(typeof(ShipTeleporterPatch)); harmony.PatchAll(typeof(LethalThingsPatch)); mls = ((BaseUnityPlugin)this).Logger; SoundFX = new List(); string location = ((BaseUnityPlugin)Instance).Info.Location; location = location.TrimEnd("ReturnByDeath.dll".ToCharArray()); Bundle = AssetBundle.LoadFromFile(location + "rbd"); if ((Object)(object)Bundle != (Object)null) { mls.LogMessage((object)("[Rezero Return By Death SFX] Successfully loaded AssetBundle from " + location + "rbd")); SoundFX = Bundle.LoadAllAssets().ToList(); } else { mls.LogError((object)("[Rezero Return By Death SFX] Failed to load AssetBundle from " + location + "rbd")); } } } } namespace ReturnByDeath.Patches { [HarmonyPatch(typeof(TeleporterTrap))] internal class LethalThingsPatch { [HarmonyPatch("__initializeVariables")] [HarmonyPostfix] private static void OverrideAudio(TeleporterTrap __instance) { __instance.teleporterBeamUpSFX = ReturnByDeathBase.SoundFX[0]; } } [HarmonyPatch(typeof(ShipTeleporter))] internal class ShipTeleporterPatch { [HarmonyPatch("Awake")] [HarmonyPostfix] private static void OverrideAudio(ShipTeleporter __instance) { __instance.teleporterBeamUpSFX = ReturnByDeathBase.SoundFX[0]; } } [HarmonyPatch(typeof(SoundManager))] internal class SoundManagerPatch { private static AudioSource witchAudioSource; private static bool isFadingOut = false; private static int currentWitchTrack = -1; public static bool hasJustDiscoveredBody = false; [HarmonyPatch("Start")] [HarmonyPostfix] private static void CreateCustomWitchAudioSource(SoundManager __instance) { witchAudioSource = ((Component)__instance).gameObject.AddComponent(); witchAudioSource.playOnAwake = false; witchAudioSource.loop = true; witchAudioSource.volume = 0f; } public static void TriggerWitch2() { hasJustDiscoveredBody = true; } [HarmonyPatch("SetFearAudio")] [HarmonyPostfix] private static void UpdateWitchFearAudio(SoundManager __instance) { if ((Object)(object)witchAudioSource == (Object)null) { return; } if (GameNetworkManager.Instance.localPlayerController.isPlayerDead) { witchAudioSource.volume = 0f; witchAudioSource.Stop(); isFadingOut = false; currentWitchTrack = -1; hasJustDiscoveredBody = false; return; } float fearLevel = StartOfRound.Instance.fearLevel; int num = -1; if (hasJustDiscoveredBody) { num = 2; } else if (fearLevel > 0.4f) { num = 1; } if (num != -1) { isFadingOut = false; if (currentWitchTrack != num || !witchAudioSource.isPlaying) { currentWitchTrack = num; if (ReturnByDeathBase.SoundFX != null && ReturnByDeathBase.SoundFX.Count > num) { witchAudioSource.clip = ReturnByDeathBase.SoundFX[num]; witchAudioSource.time = 0f; witchAudioSource.Play(); } } float volume = ((num == 2) ? 1f : Mathf.Clamp(fearLevel - 0.2f, 0.1f, 1f)); witchAudioSource.volume = volume; } else if (witchAudioSource.isPlaying) { isFadingOut = true; witchAudioSource.volume = Mathf.Lerp(witchAudioSource.volume, 0f, 2f * Time.deltaTime); if (witchAudioSource.volume < 0.01f) { witchAudioSource.Stop(); witchAudioSource.volume = 0f; isFadingOut = false; currentWitchTrack = -1; hasJustDiscoveredBody = false; } } } } }