using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using HarmonyLib; using Microsoft.CodeAnalysis; using P1.Sound; using P1.System.Sound; using P2.Media.Lrt; using P2.Sound; using P2.System.Sound; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("PataponAudioFixes")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PataponAudioFixes")] [assembly: AssemblyTitle("PataponAudioFixes")] [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.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; } } [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 PataponAudioFix { [BepInPlugin("juras.patapon.audiofix", "Patapon Audio Fix", "1.0.0")] public class Plugin : BasePlugin { internal static ManualLogSource L; internal static ConfigEntry AudioFix_ThemeLoopFix; internal static ConfigEntry AudioFix_HelperMute; internal const bool DebugLog = false; internal static bool ThemeLoopFixEnabled => AudioFix_ThemeLoopFix.Value != 0; internal static bool HelperMuteEnabled => AudioFix_HelperMute.Value != 0; internal static void D(string message) { } internal static void DW(string message) { } public override void Load() { //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00d9: Unknown result type (might be due to invalid IL or missing references) L = ((BasePlugin)this).Log; AudioFix_ThemeLoopFix = ((BasePlugin)this).Config.Bind("AudioFix", "AudioFix_ThemeLoopFix", 1u, "Set to 1 to enable the rhythm/theme loop playCount fix. Set to 0 to disable it."); AudioFix_HelperMute = ((BasePlugin)this).Config.Bind("AudioFix", "AudioFix_HelperMute", 1u, "Set to 1 to enable helper mute behavior. Set to 0 to disable it."); L.LogInfo((object)"Patapon Audio Fix 1.0.0 loaded"); ManualLogSource l = L; bool flag = default(bool); BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AudioFix_ThemeLoopFix: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ThemeLoopFixEnabled ? "enabled" : "disabled"); } l.LogInfo(val); ManualLogSource l2 = L; val = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("AudioFix_HelperMute: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(HelperMuteEnabled ? "enabled" : "disabled"); } l2.LogInfo(val); new Harmony("juras.patapon.audiofix").PatchAll(); } } internal sealed class PlayCountFixState { public bool Applied; public uint OriginalPlayCount; public uint VirtualPlayCount; } [HarmonyPatch(typeof(Rhythm), "playRhythm")] internal static class P1RhythmPlayCountVirtualWrapFix { private static void Prefix(Rhythm __instance, PlayRequest rhythmPlayRequest, out PlayCountFixState __state) { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Invalid comparison between Unknown and I4 __state = new PlayCountFixState(); if (!Plugin.ThemeLoopFixEnabled) { return; } try { if (__instance != null && rhythmPlayRequest != null && (int)rhythmPlayRequest.rhythmMood == 2 && (int)__instance.lastMood_ == 2) { uint playCount_ = __instance.playCount_; if (playCount_ > 16) { uint num = (playCount_ - 1) % 16 + 1; __state.Applied = true; __state.OriginalPlayCount = playCount_; __state.VirtualPlayCount = num; __instance.playCount_ = num; } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 FIX] Prefix failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } private static void Postfix(Rhythm __instance, bool __result, PlayCountFixState __state) { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown try { if (__instance != null && __state != null && __state.Applied) { __instance.playCount_ = (__result ? (__state.OriginalPlayCount + 1) : __state.OriginalPlayCount); Plugin.D($"[P1 FIX] Virtualized Mood_High playCount {__state.OriginalPlayCount} -> {__state.VirtualPlayCount}, restored to {__instance.playCount_}"); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 FIX] Postfix failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } [HarmonyPatch(typeof(Rhythm), "playRhythm")] internal static class P2RhythmPlayCountVirtualWrapFix { private static void Prefix(Rhythm __instance, out PlayCountFixState __state) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Expected O, but got Unknown //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Invalid comparison between Unknown and I4 __state = new PlayCountFixState(); if (!Plugin.ThemeLoopFixEnabled) { return; } try { if (__instance != null && (int)__instance.lastMood_ == 2) { uint playCount_ = __instance.playCount_; if (playCount_ > 16) { uint num = (playCount_ - 1) % 16 + 1; __state.Applied = true; __state.OriginalPlayCount = playCount_; __state.VirtualPlayCount = num; __instance.playCount_ = num; } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 FIX] Prefix failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } private static void Postfix(Rhythm __instance, bool __result, PlayCountFixState __state) { //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown try { if (__instance != null && __state != null && __state.Applied) { __instance.playCount_ = (__result ? (__state.OriginalPlayCount + 1) : __state.OriginalPlayCount); Plugin.D($"[P2 FIX] Virtualized Mood_High playCount {__state.OriginalPlayCount} -> {__state.VirtualPlayCount}, restored to {__instance.playCount_}"); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 FIX] Postfix failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } internal static class P1HelperMidiState { public static BgmPlayer? HelperPlayer; public static bool SequenceActive; public static bool HelperMuted; private static bool HasLastRhythmState; private static Mood LastMood; private static uint LastPlayCount; private static bool LastIsPlay; public const uint HelperMuteMask = uint.MaxValue; public static void Reset(string source) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) try { if (HelperMuted && HelperPlayer != null) { HelperPlayer.setMute(0u); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 HELPER MIDI] reset unmute failed from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } SequenceActive = false; HelperMuted = false; HelperPlayer = null; HasLastRhythmState = false; LastMood = (Mood)0; LastPlayCount = 0u; LastIsPlay = false; Plugin.D("[P1 HELPER MIDI] reset from " + source); } public static void SetHelperMuted(bool muted, string source, bool force = false) { //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown bool flag = default(bool); try { if (!force && HelperMuted == muted) { return; } BgmPlayer helperPlayer = HelperPlayer; if (helperPlayer == null) { ManualLogSource l = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(62, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 HELPER MIDI] wanted muted="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(muted); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", but helperPlayer is null"); } l.LogWarning(val); HelperMuted = muted; } else { helperPlayer.setMute(muted ? uint.MaxValue : 0u); HelperMuted = muted; Plugin.D($"[P1 HELPER MIDI] {(muted ? "MUTED" : "UNMUTED")} helper from {source}, playId={helperPlayer.playId_}, rid={helperPlayer.getRID()}, isPlay={helperPlayer.isPlay()}"); } } catch (Exception ex) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(48, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 HELPER MIDI] SetHelperMuted("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(muted); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") failed from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l2.LogWarning(val); } } public static void ResetProgress(string source) { SequenceActive = false; SetHelperMuted(muted: false, source, force: true); Plugin.D("[P1 HELPER MIDI] progress reset from " + source); } public static void OnSuccessfulRhythm(Rhythm rhythm, PlayRequest request) { //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) try { if (!SequenceActive) { SequenceActive = true; SetHelperMuted(muted: true, $"first successful command mood={request.rhythmMood}, playCount={rhythm.playCount_}"); Plugin.D($"[P1 HELPER MIDI] sequence started; helper muted immediately: mood={request.rhythmMood}, playCount={rhythm.playCount_}, playSEIndex={rhythm.playSEIndex_}"); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 HELPER MIDI] OnSuccessfulRhythm failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } public static void WatchRhythmState(Rhythm rhythm) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Expected O, but got Unknown //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Invalid comparison between Unknown and I4 try { Mood lastMood_ = rhythm.lastMood_; uint playCount_ = rhythm.playCount_; bool isPlay_ = rhythm.isPlay_; if (!HasLastRhythmState) { HasLastRhythmState = true; LastMood = lastMood_; LastPlayCount = playCount_; LastIsPlay = isPlay_; return; } if (SequenceActive && LastPlayCount != 0 && playCount_ == 0 && !isPlay_) { Plugin.D($"[P1 HELPER MIDI] rhythm loss detected: mood {LastMood}->{lastMood_}, playCount {LastPlayCount}->0, isPlay {LastIsPlay}->{isPlay_}"); ResetProgress("rhythm loss"); } else if (!HelperMuted && (int)lastMood_ == 2 && playCount_ != 0 && !isPlay_) { SetHelperMuted(muted: true, $"after Mood_High transition finished, playCount={playCount_}"); } LastMood = lastMood_; LastPlayCount = playCount_; LastIsPlay = isPlay_; } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(42, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 HELPER MIDI] WatchRhythmState failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } [HarmonyPatch(typeof(Director), "playMidi")] internal static class P1CaptureHelperMidiPlayer { private static void Postfix(Director __instance, int midiIndex, MixingCategory cate, float fadeTime) { //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_018f: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Invalid comparison between Unknown and I4 //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Invalid comparison between Unknown and I4 if (!Plugin.HelperMuteEnabled) { return; } try { if (!P1HelperMidiState.SequenceActive && midiIndex == 0 && (int)cate == 3) { P1HelperMidiState.Reset("playMidi(0, BGM)"); } else { if (midiIndex != 0 || (int)cate != 4) { return; } BgmPlayer curPlayer_ = __instance.curPlayer_; if (curPlayer_ == null) { Plugin.L.LogWarning((object)"[P1 HELPER MIDI] wanted to capture helper player, but curPlayer_ is null"); return; } bool value = P1HelperMidiState.HelperPlayer != null; P1HelperMidiState.HelperPlayer = curPlayer_; Plugin.D($"[P1 HELPER MIDI] CAPTURED helper player from playMidi(0, Rhythm), hadCachedPlayer={value}, playId={curPlayer_.playId_}, rid={curPlayer_.getRID()}, vol={curPlayer_.getVolumeValue()}, targetVol={curPlayer_.getTargetVolume()}, isPlay={curPlayer_.isPlay()}, sequenceActive={P1HelperMidiState.SequenceActive}, "); if (P1HelperMidiState.SequenceActive && P1HelperMidiState.HelperMuted) { P1HelperMidiState.SetHelperMuted(muted: true, "re-applied mute after playMidi(0, Rhythm) recapture", force: true); } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P1 HELPER MIDI] capture failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } [HarmonyPatch(typeof(Rhythm), "playRhythm")] internal static class P1HelperOnSuccessfulRhythm { private static void Postfix(Rhythm __instance, PlayRequest rhythmPlayRequest, bool __result) { if (Plugin.HelperMuteEnabled && __result && __instance != null && rhythmPlayRequest != null) { P1HelperMidiState.OnSuccessfulRhythm(__instance, rhythmPlayRequest); } } } [HarmonyPatch(typeof(Rhythm), "update")] internal static class P1HelperWatchRhythmState { private static void Postfix(Rhythm __instance) { if (Plugin.HelperMuteEnabled && __instance != null) { P1HelperMidiState.WatchRhythmState(__instance); } } } [HarmonyPatch(typeof(Rhythm), "clearPlayCount")] internal static class P1HelperResetOnClearPlayCount { private static void Postfix() { if (Plugin.HelperMuteEnabled && (P1HelperMidiState.SequenceActive || P1HelperMidiState.HelperMuted)) { P1HelperMidiState.ResetProgress("Rhythm.clearPlayCount"); } } } [HarmonyPatch(typeof(Rhythm), "resetPlayCount")] internal static class P1HelperResetOnResetPlayCount { private static void Postfix() { if (Plugin.HelperMuteEnabled && (P1HelperMidiState.SequenceActive || P1HelperMidiState.HelperMuted)) { P1HelperMidiState.ResetProgress("Rhythm.clearPlayCount"); } } } [HarmonyPatch(typeof(Director), "moodDown")] internal static class P1HelperResetOnMoodDown { private static void Postfix() { if (Plugin.HelperMuteEnabled && (P1HelperMidiState.SequenceActive || P1HelperMidiState.HelperMuted)) { P1HelperMidiState.ResetProgress("Rhythm.clearPlayCount"); } } } [HarmonyPatch(typeof(Director), "startPlayGame")] internal static class P1HelperResetOnStartPlayGame { private static void Prefix() { if (Plugin.HelperMuteEnabled) { P1HelperMidiState.Reset("Director.startPlayGame"); } } } [HarmonyPatch(typeof(Director), "exitPlayGame")] internal static class P1HelperResetOnExitPlayGame { private static void Prefix() { if (Plugin.HelperMuteEnabled) { P1HelperMidiState.Reset("Director.exitPlayGame"); } } } internal static class P2HelperMidiState { public static bool CommandsStarted; public static bool HelperMuted; public static RhythmBgmPlayer? HelperPlayer; public static Rhythm? RhythmInstance; private static bool HasLastRhythmState; private static Mood LastMood; private static uint LastPlayCount; public const uint HelperMuteMask = uint.MaxValue; public static bool BattleActive; public static void Reset(string source, bool forceLog = false) { //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_00bb: Unknown result type (might be due to invalid IL or missing references) if (!BattleActive && !CommandsStarted && !HelperMuted && HelperPlayer == null && !HasLastRhythmState && !forceLog) { return; } try { if (HelperMuted && HelperPlayer != null) { ((BgmPlayer)HelperPlayer).setMute(0u); Plugin.D("[P2 HELPER MIDI] UNMUTED helper during reset from " + source); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] reset unmute failed from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } BattleActive = false; CommandsStarted = false; HelperMuted = false; HelperPlayer = null; RhythmInstance = null; HasLastRhythmState = false; LastMood = (Mood)0; LastPlayCount = 0u; Plugin.D("[P2 HELPER MIDI] reset from " + source); } public static void CaptureHelperCandidate(RhythmBgmPlayer player, string source, BgmType type, MixingCategory cate, SubGameType subGameType, string detail) { //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0268: Expected O, but got Unknown //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0189: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Invalid comparison between Unknown and I4 //IL_018d: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Invalid comparison between Unknown and I4 //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_0195: Invalid comparison between Unknown and I4 //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_0199: Invalid comparison between Unknown and I4 //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) try { if (player == null) { return; } Plugin.D($"[P2 HELPER MIDI] addMidi candidate from {source}: type={type}, cate={cate}, subGameType={subGameType}, {detail}, playId={((BgmPlayer)player).playId_}, rid={((BgmPlayer)player).getRID()}, vol={((BgmPlayer)player).getVolumeValue()}, targetVol={((BgmPlayer)player).getTargetVolume()}, isPlay={((BgmPlayer)player).isPlay()}, isLoop={((BgmPlayer)player).isLoop()}, commandsStarted={CommandsStarted}, helperMuted={HelperMuted}"); bool num = (int)type == 1; bool flag = (int)subGameType == 0; bool flag2 = (int)cate == 3 || (int)cate == 4; if (num && flag && flag2) { HelperPlayer = player; Plugin.D($"[P2 HELPER MIDI] CAPTURED helper candidate from {source}, type={type}, cate={cate}, subGameType={subGameType}, {detail}"); if (CommandsStarted && !HelperMuted) { SetHelperMuted(muted: true, "late helper capture after commands already started"); } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag3 = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(54, 2, ref flag3); if (flag3) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] CaptureHelperCandidate failed from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } public static void ResetProgress(string source) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) SetHelperMuted(muted: false, source, force: true); CommandsStarted = false; HasLastRhythmState = false; LastMood = (Mood)0; LastPlayCount = 0u; Plugin.D("[P2 HELPER MIDI] progress reset from " + source); } public static void SetHelperMuted(bool muted, string source, bool force = false) { //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0149: Expected O, but got Unknown //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown bool flag = default(bool); try { if (!force && HelperMuted == muted) { return; } RhythmBgmPlayer helperPlayer = HelperPlayer; if (helperPlayer == null) { ManualLogSource l = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(62, 2, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] wanted muted="); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(muted); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", but helperPlayer is null"); } l.LogWarning(val); if (muted) { CommandsStarted = false; } else { HelperMuted = false; } return; } ((BgmPlayer)helperPlayer).setMute(muted ? uint.MaxValue : 0u); HelperMuted = muted; if (!muted) { CommandsStarted = false; } Plugin.D($"[P2 HELPER MIDI] {(muted ? "MUTED" : "UNMUTED")} helper from {source}, playId={((BgmPlayer)helperPlayer).playId_}, rid={((BgmPlayer)helperPlayer).getRID()}, isPlay={((BgmPlayer)helperPlayer).isPlay()}"); } catch (Exception ex) { ManualLogSource l2 = Plugin.L; BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(48, 3, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] SetHelperMuted("); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(muted); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") failed from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l2.LogWarning(val); } } public static void OnSuccessfulRhythm(Rhythm rhythm) { //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) try { if (rhythm != null) { RhythmInstance = rhythm; if (rhythm.playCount_ == 0 || rhythm.playSEIndex_ == 0) { Plugin.D($"[P2 HELPER MIDI] ignored early/empty playRhythm: mood={rhythm.lastMood_}, playCount={rhythm.playCount_}, playSEIndex={rhythm.playSEIndex_}"); } else if (!CommandsStarted) { CommandsStarted = true; Plugin.D($"[P2 HELPER MIDI] Commands started at mood={rhythm.lastMood_}, playCount={rhythm.playCount_}, playSEIndex={rhythm.playSEIndex_}, helperPlayer={((HelperPlayer == null) ? "null" : "cached")}"); SetHelperMuted(muted: true, "first successful playRhythm"); } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] OnSuccessfulRhythm failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } public static void CheckForRhythmLoss(Rhythm rhythm) { //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Expected O, but got Unknown //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: 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_008a: Unknown result type (might be due to invalid IL or missing references) try { if (rhythm == null) { return; } Mood lastMood_ = rhythm.lastMood_; uint playCount_ = rhythm.playCount_; if (!HasLastRhythmState) { HasLastRhythmState = true; LastMood = lastMood_; LastPlayCount = playCount_; return; } if (CommandsStarted && LastPlayCount != 0 && playCount_ == 0) { Plugin.D($"[P2 HELPER MIDI] rhythm loss detected by Rhythm.update: mood {LastMood}->{lastMood_}, playCount {LastPlayCount}->0, helperMuted={HelperMuted}"); ResetProgress("Rhythm.update loss"); } LastMood = lastMood_; LastPlayCount = playCount_; } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] CheckForRhythmLoss failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } public static void CheckLowLowMoodLoss(string source, int commandPoint, float commandBeatCount) { //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_0165: Unknown result type (might be due to invalid IL or missing references) try { if (!CommandsStarted && !HelperMuted) { return; } Rhythm rhythmInstance = RhythmInstance; if (rhythmInstance == null) { Plugin.D($"[P2 HELPER MIDI] low->low mood pulse, but RhythmInstance is null, commandPoint={commandPoint}, commandBeatCount={commandBeatCount}"); return; } Mood lastMood_ = rhythmInstance.lastMood_; uint playCount_ = rhythmInstance.playCount_; uint playSEIndex_ = rhythmInstance.playSEIndex_; bool flag = playCount_ == 0; Plugin.D($"[P2 HELPER MIDI] low->low mood pulse while active: rhythmMood={lastMood_}, playCount={playCount_}, playSEIndex={playSEIndex_}, commandPoint={commandPoint}, commandBeatCount={commandBeatCount}, looksLikeLoss={flag}"); if (flag) { ResetProgress($"{source}, rhythmMood={lastMood_}, playCount={playCount_}, commandPoint={commandPoint}, commandBeatCount={commandBeatCount}"); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag2 = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(51, 2, ref flag2); if (flag2) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] CheckLowLowMoodLoss failed from "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(source); ((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } [HarmonyPatch(typeof(Director), "playMidi")] internal static class P2TraceHelperMidiPlayMidi { private static void Postfix(Director __instance, int midiIndex, MixingCategory cate, float fadeTime) { //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Expected O, but got Unknown //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Invalid comparison between Unknown and I4 //IL_0155: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.HelperMuteEnabled) { return; } try { Plugin.D($"[P2 PLAYERTRACE] after playMidi argIndex={midiIndex}, argCate={cate}, curMIDIIndex={__instance.curMIDIIndex_}, curCate={__instance.curMidiCategory_}, bgmPlayers={((__instance.bgmPlayer_ == null) ? "null" : "not-null")}, commandsStarted={P2HelperMidiState.CommandsStarted}, helperMuted={P2HelperMidiState.HelperMuted}, helperPlayer={((P2HelperMidiState.HelperPlayer == null) ? "null" : "cached")}"); if (!P2HelperMidiState.BattleActive && !P2HelperMidiState.CommandsStarted && midiIndex == 0 && (int)cate == 11) { P2HelperMidiState.Reset($"playMidi(0, {cate})"); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(25, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 PLAYERTRACE] failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } [HarmonyPatch(typeof(Rhythm), "playRhythm")] internal static class P2HelperOnSuccessfulRhythm { private static void Postfix(Rhythm __instance, bool __result) { if (Plugin.HelperMuteEnabled && __result && __instance != null) { P2HelperMidiState.OnSuccessfulRhythm(__instance); } } } [HarmonyPatch(typeof(Rhythm), "update")] internal static class P2HelperWatchRhythmState { private static void Postfix(Rhythm __instance) { if (Plugin.HelperMuteEnabled && __instance != null) { P2HelperMidiState.CheckForRhythmLoss(__instance); } } } [HarmonyPatch(typeof(Rhythm), "clearPlayCount")] internal static class P2HelperResetOnClearPlayCount { private static void Postfix() { if (Plugin.HelperMuteEnabled && (P2HelperMidiState.CommandsStarted || P2HelperMidiState.HelperMuted)) { P2HelperMidiState.ResetProgress("Rhythm.clearPlayCount"); } } } [HarmonyPatch(typeof(Rhythm), "resetPlayCount")] internal static class P2HelperResetOnResetPlayCount { private static void Postfix() { if (Plugin.HelperMuteEnabled && (P2HelperMidiState.CommandsStarted || P2HelperMidiState.HelperMuted)) { P2HelperMidiState.ResetProgress("Rhythm.resetPlayCount"); } } } [HarmonyPatch] internal static class P2CaptureHelperFromAddMidi_MidiId { private static MethodBase TargetMethod() { return AccessTools.DeclaredMethod(typeof(BgmPlayers), "addMidi", new Type[4] { typeof(BgmType), typeof(MidiId), typeof(MixingCategory), typeof(SubGameType) }, (Type[])null); } private static void Postfix(RhythmBgmPlayer __result, BgmType type, MidiId id, MixingCategory cate, SubGameType subGameType) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (Plugin.HelperMuteEnabled) { P2HelperMidiState.CaptureHelperCandidate(__result, "BgmPlayers.addMidi(MidiId)", type, cate, subGameType, $"id={id}"); } } } [HarmonyPatch] internal static class P2CaptureHelperFromAddMidi_BankRid { private static MethodBase TargetMethod() { return AccessTools.DeclaredMethod(typeof(BgmPlayers), "addMidi", new Type[6] { typeof(BgmType), typeof(BankRIDHandle), typeof(RhythmParam), typeof(string), typeof(MixingCategory), typeof(SubGameType) }, (Type[])null); } private static void Postfix(RhythmBgmPlayer __result, BgmType type, BankRIDHandle rid, RhythmParam rhythmParam, string filename, MixingCategory cate, SubGameType subGameType) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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) if (Plugin.HelperMuteEnabled) { P2HelperMidiState.CaptureHelperCandidate(__result, "BgmPlayers.addMidi(BankRIDHandle)", type, cate, subGameType, "filename=" + filename); } } } [HarmonyPatch(typeof(Director), "startBattle")] internal static class P2HelperResetOnStartBattle { private static void Prefix(uint index) { if (Plugin.HelperMuteEnabled) { P2HelperMidiState.Reset($"Director.startBattle pre-reset index={index}"); P2HelperMidiState.BattleActive = true; Plugin.D($"[P2 HELPER MIDI] battle active from Director.startBattle index={index}"); } } } [HarmonyPatch(typeof(Director), "exitBattle")] internal static class P2HelperResetOnExitBattle { private static void Prefix() { if (Plugin.HelperMuteEnabled) { P2HelperMidiState.Reset("Director.exitBattle"); } } } [HarmonyPatch(typeof(Director), "failedBattle")] internal static class P2HelperResetOnFailedBattle { private static void Prefix() { if (Plugin.HelperMuteEnabled) { P2HelperMidiState.Reset("Director.failedBattle"); } } } [HarmonyPatch(typeof(Director), "goalBattle")] internal static class P2HelperResetOnGoalBattle { private static void Prefix() { if (Plugin.HelperMuteEnabled) { P2HelperMidiState.Reset("Director.goalBattle"); } } } [HarmonyPatch(typeof(Director), "onChangeMood")] internal static class P2HelperResetOnChangeMood { private static void Postfix(Director __instance, int newMood, int oldMood) { //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019b: Expected O, but got Unknown //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_006e: 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_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Invalid comparison between Unknown and I4 //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_0171: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Invalid comparison between Unknown and I4 if (!Plugin.HelperMuteEnabled) { return; } try { if (P2HelperMidiState.CommandsStarted || P2HelperMidiState.HelperMuted) { Mood val = (Mood)oldMood; Mood val2 = (Mood)newMood; int num = -999; float num2 = -1f; try { num = __instance.getCommandPoint(); num2 = __instance.getCommandBeatCount(); } catch { } Plugin.D($"[P2 HELPER MIDI] onChangeMood fired oldMood={val}, newMood={val2}, commandPoint={num}, commandBeatCount={num2}, commandsStarted={P2HelperMidiState.CommandsStarted}, helperMuted={P2HelperMidiState.HelperMuted}, helperPlayer={((P2HelperMidiState.HelperPlayer == null) ? "null" : "cached")}"); if ((int)val != 0 && (int)val2 == 0) { P2HelperMidiState.ResetProgress($"Director.onChangeMood {val}->{val2}"); } else if ((int)val == 0 && (int)val2 == 0) { P2HelperMidiState.CheckLowLowMoodLoss("Director.onChangeMood Mood_Low->Mood_Low", num, num2); } } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(43, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[P2 HELPER MIDI] onChangeMood hook failed: "); ((BepInExLogInterpolatedStringHandler)val3).AppendFormatted(ex); } l.LogWarning(val3); } } } [HarmonyPatch(typeof(Rhythm), "playRhythm")] internal static class P2HelperResetOnFailedPlayRhythm { private static void Postfix(Rhythm __instance, bool __result) { //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Expected O, but got Unknown //IL_0050: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.HelperMuteEnabled) { return; } try { if (__instance != null && !__result && (P2HelperMidiState.CommandsStarted || P2HelperMidiState.HelperMuted)) { Plugin.D($"[P2 HELPER MIDI] failed playRhythm detected: mood={__instance.lastMood_}, playCount={__instance.playCount_}, playSEIndex={__instance.playSEIndex_}, helperMuted={P2HelperMidiState.HelperMuted}"); P2HelperMidiState.ResetProgress("failed playRhythm"); } } catch (Exception ex) { ManualLogSource l = Plugin.L; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(48, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[P2 HELPER MIDI] failed playRhythm hook failed: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(ex); } l.LogWarning(val); } } } }