using System; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using FMOD; using FMOD.Studio; using FMODUnity; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("CustomHurryUp")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("CustomHurryUp")] [assembly: AssemblyTitle("CustomHurryUp")] [assembly: AssemblyVersion("1.0.0.0")] [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 CustomHurryUp { [BepInPlugin("sbg.stevecheese.hurryupmusic", "CustomHurryUp", "0.0.1")] public class CustomHurryUpPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(CourseManager), "HurryUpHoleMusic")] internal static class Patch_CourseManager_HurryUpHoleMusic { private static bool Prefix(CourseManager __instance, bool instant) { ManualLogSource log = Log; if (log != null) { log.LogInfo((object)$"HurryUpHoleMusic patch fired. instant={instant}, soundReady={_soundReady}"); } if (!_soundReady) { return true; } StopVanillaHoleMusic(__instance); PlayCustomHurryUpMusic(); return false; } } [HarmonyPatch(typeof(CourseManager), "EndCourseInternal")] internal static class Patch_CourseManager_EndCourseInternal { private static void Prefix() { StopCustomHurryUpMusic(); } } public const string ModGuid = "sbg.stevecheese.hurryupmusic"; public const string ModName = "CustomHurryUp"; public const string ModVersion = "0.0.1"; private const string AudioFileName = "Tenebre_Rosso_Sangue.wav"; internal static ManualLogSource Log; private static Sound _hurryUpSound; private static Channel _hurryUpChannel; private static bool _soundReady; private static readonly FieldInfo HoleMusicInstanceField = AccessTools.Field(typeof(CourseManager), "holeMusicInstance"); private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; new Harmony("sbg.stevecheese.hurryupmusic").PatchAll(); SceneManager.activeSceneChanged += OnActiveSceneChanged; Log.LogInfo((object)"CustomHurryUp v0.0.1 loaded."); } private void OnDestroy() { SceneManager.activeSceneChanged -= OnActiveSceneChanged; StopCustomHurryUpMusic(); } private static void OnActiveSceneChanged(Scene oldScene, Scene newScene) { StopCustomHurryUpMusic(); } private void Start() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Invalid comparison between Unknown and I4 //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) try { string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "Tenebre_Rosso_Sangue.wav"); if (!File.Exists(text)) { Log.LogError((object)("Audio file missing: " + text)); return; } System coreSystem = RuntimeManager.CoreSystem; RESULT val = ((System)(ref coreSystem)).createSound(text, (MODE)130, ref _hurryUpSound); if ((int)val > 0) { Log.LogError((object)$"FMOD createSound failed: {val}"); return; } ((Sound)(ref _hurryUpSound)).setMode((MODE)2); ((Sound)(ref _hurryUpSound)).setLoopCount(-1); uint num = default(uint); ((Sound)(ref _hurryUpSound)).getLength(ref num, (TIMEUNIT)1); _soundReady = true; Log.LogInfo((object)$"FMOD hurry-up music loaded ({num} ms): {text}"); } catch (Exception arg) { Log.LogError((object)$"Start failed: {arg}"); } } private static void StopCustomHurryUpMusic() { //IL_0016: Unknown result type (might be due to invalid IL or missing references) try { if (((Channel)(ref _hurryUpChannel)).hasHandle()) { ((Channel)(ref _hurryUpChannel)).stop(); ((Channel)(ref _hurryUpChannel)).clearHandle(); } } catch (Exception arg) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)$"StopCustomHurryUpMusic failed: {arg}"); } } } private static void PlayCustomHurryUpMusic() { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Invalid comparison between Unknown and I4 //IL_006e: Unknown result type (might be due to invalid IL or missing references) if (!_soundReady) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)"Tried to play hurry-up music, but sound is not ready."); } return; } try { StopCustomHurryUpMusic(); System coreSystem = RuntimeManager.CoreSystem; RESULT val = ((System)(ref coreSystem)).playSound(_hurryUpSound, default(ChannelGroup), false, ref _hurryUpChannel); if ((int)val > 0) { ManualLogSource log2 = Log; if (log2 != null) { log2.LogWarning((object)$"playSound hurry-up music failed: {val}"); } } else { ManualLogSource log3 = Log; if (log3 != null) { log3.LogInfo((object)"Custom hurry-up music started."); } } } catch (Exception arg) { ManualLogSource log4 = Log; if (log4 != null) { log4.LogError((object)$"PlayCustomHurryUpMusic failed: {arg}"); } } } private static void StopVanillaHoleMusic(CourseManager courseManager) { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) try { if (HoleMusicInstanceField == null) { ManualLogSource log = Log; if (log != null) { log.LogWarning((object)"Could not find CourseManager.holeMusicInstance field."); } } else if (HoleMusicInstanceField.GetValue(courseManager) is EventInstance val) { ((EventInstance)(ref val)).stop((STOP_MODE)0); ManualLogSource log2 = Log; if (log2 != null) { log2.LogInfo((object)"Vanilla hole music stop requested."); } } else { ManualLogSource log3 = Log; if (log3 != null) { log3.LogWarning((object)"holeMusicInstance was not an FMOD.Studio.EventInstance."); } } } catch (Exception arg) { ManualLogSource log4 = Log; if (log4 != null) { log4.LogWarning((object)$"StopVanillaHoleMusic failed: {arg}"); } } } } }