using System;
using System.Collections;
using System.Collections.Generic;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("REPOJP")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("zabuMod")]
[assembly: AssemblyTitle("zabuMod")]
[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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace REPOJP.AutoMuteOn
{
[BepInPlugin("REPOJP.AutoMuteOn", "AutoMuteOn", "4.0.0")]
public sealed class AutoMuteOnPlugin : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <CoApplyAfterLevelGenerated>d__16 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public string reason;
public AutoMuteOnPlugin <>4__this;
private float <delay>5__1;
private int <retryCount>5__2;
private float <retryInterval>5__3;
private int <i>5__4;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <CoApplyAfterLevelGenerated>d__16(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Expected O, but got Unknown
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Expected O, but got Unknown
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<delay>5__1 = 1f;
try
{
<delay>5__1 = Mathf.Clamp(ApplyDelaySeconds.Value, 0f, 10f);
}
catch
{
<delay>5__1 = 1f;
}
if (<delay>5__1 > 0f)
{
<>2__current = (object)new WaitForSeconds(<delay>5__1);
<>1__state = 1;
return true;
}
<>2__current = null;
<>1__state = 2;
return true;
case 1:
<>1__state = -1;
goto IL_00d0;
case 2:
<>1__state = -1;
goto IL_00d0;
case 3:
<>1__state = -1;
goto IL_01f5;
case 4:
{
<>1__state = -1;
goto IL_01f5;
}
IL_01f5:
<i>5__4++;
break;
IL_00d0:
<retryCount>5__2 = 20;
<retryInterval>5__3 = 0.5f;
try
{
<retryCount>5__2 = Mathf.Clamp(ApplyRetryCount.Value, 1, 120);
}
catch
{
<retryCount>5__2 = 20;
}
try
{
<retryInterval>5__3 = Mathf.Clamp(ApplyRetryIntervalSeconds.Value, 0.1f, 5f);
}
catch
{
<retryInterval>5__3 = 0.5f;
}
<i>5__4 = 0;
break;
}
if (<i>5__4 < <retryCount>5__2 && ModEnabled != null && ModEnabled.Value)
{
if (!IsReadyForMainProcess())
{
<>2__current = (object)new WaitForSeconds(<retryInterval>5__3);
<>1__state = 3;
return true;
}
if (!TrySetToggleMute(value: true))
{
<>2__current = (object)new WaitForSeconds(<retryInterval>5__3);
<>1__state = 4;
return true;
}
WriteInfo("Auto mute applied reason=" + reason + " retry=" + <i>5__4);
}
<>4__this.applyCoroutine = null;
return false;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
public const string PluginGuid = "REPOJP.AutoMuteOn";
public const string PluginName = "AutoMuteOn";
public const string PluginVersion = "4.0.0";
internal static AutoMuteOnPlugin Instance;
internal static ManualLogSource Log;
internal static ConfigEntry<bool> ModEnabled;
internal static ConfigEntry<float> ApplyDelaySeconds;
internal static ConfigEntry<int> ApplyRetryCount;
internal static ConfigEntry<float> ApplyRetryIntervalSeconds;
internal static ConfigEntry<bool> EnableLog;
private Harmony harmony;
private Coroutine applyCoroutine;
private static FieldInfo toggleMuteField;
private void Awake()
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Expected O, but got Unknown
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
//IL_0158: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Instance = this;
try
{
((Component)this).transform.parent = null;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Failure: Persist setup\n" + ex));
}
ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod. このMODを有効化");
ApplyDelaySeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ApplyDelaySeconds", 1f, new ConfigDescription("Delay after level generation before applying toggle mute. レベル生成後にトグルミュートを適用するまでの待機秒数", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
ApplyRetryCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ApplyRetryCount", 20, new ConfigDescription("Retry count after level generation. レベル生成後の再試行回数", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 120), Array.Empty<object>()));
ApplyRetryIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ApplyRetryIntervalSeconds", 0.5f, new ConfigDescription("Retry interval seconds after level generation. レベル生成後の再試行間隔秒数", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.1f, 5f), Array.Empty<object>()));
EnableLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableLog", true, "Enable log output. ログ出力有効化");
harmony = new Harmony("REPOJP.AutoMuteOn");
harmony.PatchAll();
WriteInfo("Loaded AutoMuteOn v4.0.0 safe mode");
}
private void OnDestroy()
{
if (applyCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(applyCoroutine);
applyCoroutine = null;
}
try
{
if (harmony != null)
{
harmony.UnpatchSelf();
harmony = null;
}
}
catch
{
}
if ((Object)(object)Instance == (Object)(object)this)
{
Instance = null;
}
}
internal void ScheduleApplyAfterLevelGenerated(string reason)
{
if (ModEnabled != null && ModEnabled.Value)
{
if (applyCoroutine != null)
{
((MonoBehaviour)this).StopCoroutine(applyCoroutine);
applyCoroutine = null;
}
applyCoroutine = ((MonoBehaviour)this).StartCoroutine(CoApplyAfterLevelGenerated(reason));
}
}
[IteratorStateMachine(typeof(<CoApplyAfterLevelGenerated>d__16))]
private IEnumerator CoApplyAfterLevelGenerated(string reason)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <CoApplyAfterLevelGenerated>d__16(0)
{
<>4__this = this,
reason = reason
};
}
private static bool IsReadyForMainProcess()
{
try
{
if ((Object)(object)LevelGenerator.Instance == (Object)null)
{
return false;
}
if (!LevelGenerator.Instance.Generated)
{
return false;
}
}
catch
{
return false;
}
try
{
if ((Object)(object)RunManager.instance == (Object)null)
{
return false;
}
if ((Object)(object)StatsManager.instance == (Object)null)
{
return false;
}
if ((Object)(object)PunManager.instance == (Object)null)
{
return false;
}
}
catch
{
return false;
}
try
{
if (SemiFunc.RunIsShop())
{
return false;
}
}
catch
{
}
try
{
if (SemiFunc.RunIsLevel() || SemiFunc.RunIsArena() || SemiFunc.RunIsTutorial())
{
return true;
}
}
catch
{
return false;
}
return false;
}
private static bool TrySetToggleMute(bool value)
{
DataDirector val = null;
try
{
val = DataDirector.instance;
}
catch
{
val = null;
}
if ((Object)(object)val == (Object)null)
{
return false;
}
FieldInfo fieldInfo = GetToggleMuteField();
if (fieldInfo == null)
{
WriteWarning("DataDirector.toggleMute field not found");
return false;
}
try
{
object value2 = fieldInfo.GetValue(val);
bool flag = false;
if (value2 is bool)
{
flag = (bool)value2;
}
if (flag != value)
{
fieldInfo.SetValue(val, value);
}
return true;
}
catch (Exception ex)
{
WriteError("Failure: Set toggleMute\n" + ex);
return false;
}
}
private static FieldInfo GetToggleMuteField()
{
if (toggleMuteField != null)
{
return toggleMuteField;
}
try
{
toggleMuteField = AccessTools.Field(typeof(DataDirector), "toggleMute");
}
catch
{
toggleMuteField = null;
}
return toggleMuteField;
}
internal static void WriteInfo(string message)
{
if (Log != null && (EnableLog == null || EnableLog.Value))
{
Log.LogInfo((object)message);
}
}
internal static void WriteWarning(string message)
{
if (Log != null && (EnableLog == null || EnableLog.Value))
{
Log.LogWarning((object)message);
}
}
internal static void WriteError(string message)
{
if (Log != null && (EnableLog == null || EnableLog.Value))
{
Log.LogError((object)message);
}
}
}
[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
internal static class LevelGenerator_GenerateDone_Patch
{
private static void Postfix()
{
try
{
if ((Object)(object)AutoMuteOnPlugin.Instance != (Object)null)
{
AutoMuteOnPlugin.Instance.ScheduleApplyAfterLevelGenerated("LevelGenerator.GenerateDone");
}
}
catch (Exception ex)
{
AutoMuteOnPlugin.WriteError("Failure: GenerateDone patch\n" + ex);
}
}
}
}