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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Reptile;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ErrorHandler.Plugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ErrorHandler.Plugin")]
[assembly: AssemblyTitle("ErrorHandler.Plugin")]
[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 ErrorHandler.Plugin
{
public static class ErrorHandlerSettings
{
public static bool IgnoreErrorOverride;
private static ConfigEntry<bool> _ignoreErrors;
private static ConfigEntry<float> _ignoreErrorAskInterval;
private static ConfigEntry<int> _errorsInARowAskThresh;
public static bool IgnoreErrors => _ignoreErrors.Value;
public static float IgnoreErrorsOverrideAskInterval => _ignoreErrorAskInterval.Value;
public static int IgnoreErrorsAskInARow => _errorsInARowAskThresh.Value;
public static void Initialize(ConfigFile config)
{
_ignoreErrors = config.Bind<bool>("General", "Ignore Errors", false, "Whether to just write errors to the console when they happen and continue playing.");
_ignoreErrorAskInterval = config.Bind<float>("General", "Interval To Ask To Ignore", 10f, "How close together, in seconds, errors have to be ignored in a row for the handler to ask if you want to ignore future ones. 0 to disable, -1 to always ask.");
_errorsInARowAskThresh = config.Bind<int>("General", "Errors in a Row To Ask To Ignore", 10, "After how many errors in a row the handler will ask if you want to ignore future ones. 0 to disable.");
}
}
[BepInPlugin("ErrorHandler.Plugin", "ErrorHandler.Plugin", "1.0.0")]
internal class Plugin : BaseUnityPlugin
{
public static double LastExceptionTime = -500.0;
public static double CurrentExceptionTime = 0.0;
public static int CurrentErrorInARow = 0;
public static Plugin Instance { get; private set; }
private void Awake()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Expected O, but got Unknown
Instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Initializing ErrorHandler.Plugin 1.0.0");
try
{
new Harmony("ErrorHandler.Plugin").PatchAll();
ErrorHandlerSettings.Initialize(((BaseUnityPlugin)this).Config);
StageManager.OnStagePostInitialization += new OnStageInitializedDelegate(StageManager_OnStagePostInitialization);
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)string.Format("Failed to initialize {0} {1}!{2}{3}", "ErrorHandler.Plugin", "1.0.0", Environment.NewLine, ex));
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Initialized ErrorHandler.Plugin 1.0.0!");
}
private void StageManager_OnStagePostInitialization()
{
ErrorHandlerSettings.IgnoreErrorOverride = false;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ErrorHandler.Plugin";
public const string PLUGIN_NAME = "ErrorHandler.Plugin";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace ErrorHandler.Plugin.Patches
{
[HarmonyPatch(typeof(Core))]
internal static class CorePatch
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static OnPopupButtonCallback <>9__1_0;
public static OnPopupButtonCallback <>9__3_0;
public static OnPopupButtonCallback <>9__3_1;
internal void <HandleExceptionInGame_Prefix>b__1_0()
{
Plugin.CurrentErrorInARow++;
double num = Plugin.CurrentExceptionTime - Plugin.LastExceptionTime;
Plugin.LastExceptionTime = Time.realtimeSinceStartupAsDouble;
bool flag = false;
if (ErrorHandlerSettings.IgnoreErrorsOverrideAskInterval == -1f)
{
flag = true;
}
else if (ErrorHandlerSettings.IgnoreErrorsOverrideAskInterval == 0f)
{
flag = false;
}
else if (num <= (double)ErrorHandlerSettings.IgnoreErrorsOverrideAskInterval)
{
flag = true;
}
if (ErrorHandlerSettings.IgnoreErrorsAskInARow > 0 && Plugin.CurrentErrorInARow >= ErrorHandlerSettings.IgnoreErrorsAskInARow)
{
flag = true;
}
if (flag)
{
((MonoBehaviour)Plugin.Instance).StartCoroutine(DisplayIgnoreQuestionDelayed());
}
else
{
_displayingError = false;
}
}
internal void <DisplayIgnoreQuestion>b__3_0()
{
Plugin.LastExceptionTime = Time.realtimeSinceStartupAsDouble;
_displayingError = false;
ErrorHandlerSettings.IgnoreErrorOverride = true;
}
internal void <DisplayIgnoreQuestion>b__3_1()
{
Plugin.LastExceptionTime = Time.realtimeSinceStartupAsDouble;
_displayingError = false;
}
}
[CompilerGenerated]
private sealed class <DisplayIgnoreQuestionDelayed>d__2 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <DisplayIgnoreQuestionDelayed>d__2(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSecondsRealtime(0.1f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
<>2__current = (object)new WaitForEndOfFrame();
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
<>2__current = null;
<>1__state = 3;
return true;
case 3:
<>1__state = -1;
DisplayIgnoreQuestion();
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();
}
}
private static bool _displayingError;
[HarmonyPrefix]
[HarmonyPatch("HandleExceptionInGame")]
private static bool HandleExceptionInGame_Prefix(Core __instance, Exception exception)
{
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Expected O, but got Unknown
Debug.LogException(exception);
if (!ErrorHandlerSettings.IgnoreErrors && !ErrorHandlerSettings.IgnoreErrorOverride && !_displayingError)
{
_displayingError = true;
Plugin.CurrentExceptionTime = Time.realtimeSinceStartupAsDouble;
__instance.BaseModule.EnableUIControllerMaps();
Overlay overlay = __instance.UIManager.Overlay;
string text = "An error happened during gameplay and has been logged to the console." + Environment.NewLine + "You can ignore this and continue to play, but the game might be in a bugged state.";
object obj = <>c.<>9__1_0;
if (obj == null)
{
OnPopupButtonCallback val = delegate
{
Plugin.CurrentErrorInARow++;
double num = Plugin.CurrentExceptionTime - Plugin.LastExceptionTime;
Plugin.LastExceptionTime = Time.realtimeSinceStartupAsDouble;
bool flag = false;
if (ErrorHandlerSettings.IgnoreErrorsOverrideAskInterval == -1f)
{
flag = true;
}
else if (ErrorHandlerSettings.IgnoreErrorsOverrideAskInterval == 0f)
{
flag = false;
}
else if (num <= (double)ErrorHandlerSettings.IgnoreErrorsOverrideAskInterval)
{
flag = true;
}
if (ErrorHandlerSettings.IgnoreErrorsAskInARow > 0 && Plugin.CurrentErrorInARow >= ErrorHandlerSettings.IgnoreErrorsAskInARow)
{
flag = true;
}
if (flag)
{
((MonoBehaviour)Plugin.Instance).StartCoroutine(DisplayIgnoreQuestionDelayed());
}
else
{
_displayingError = false;
}
};
<>c.<>9__1_0 = val;
obj = (object)val;
}
overlay.ShowPopup(text, "Ignore", "Restart", (OnPopupButtonCallback)obj, (OnPopupButtonCallback)delegate
{
_displayingError = false;
__instance.BaseModule.GoBackToIntro();
}, Array.Empty<string>());
}
return false;
}
[IteratorStateMachine(typeof(<DisplayIgnoreQuestionDelayed>d__2))]
private static IEnumerator DisplayIgnoreQuestionDelayed()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <DisplayIgnoreQuestionDelayed>d__2(0);
}
private static void DisplayIgnoreQuestion()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
Overlay overlay = Core.Instance.UIManager.Overlay;
object obj = <>c.<>9__3_0;
if (obj == null)
{
OnPopupButtonCallback val = delegate
{
Plugin.LastExceptionTime = Time.realtimeSinceStartupAsDouble;
_displayingError = false;
ErrorHandlerSettings.IgnoreErrorOverride = true;
};
<>c.<>9__3_0 = val;
obj = (object)val;
}
object obj2 = <>c.<>9__3_1;
if (obj2 == null)
{
OnPopupButtonCallback val2 = delegate
{
Plugin.LastExceptionTime = Time.realtimeSinceStartupAsDouble;
_displayingError = false;
};
<>c.<>9__3_1 = val2;
obj2 = (object)val2;
}
overlay.ShowPopup("Would you like to automatically ignore errors for the rest of the current level?", "Yes", "No", (OnPopupButtonCallback)obj, (OnPopupButtonCallback)obj2, Array.Empty<string>());
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}