Decompiled source of GlitchDebug v0.2.0

plugins/GlitchDebug.dll

Decompiled a day ago
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 DebugMod;
using DebugMod.Hitbox;
using DebugMod.SaveStates;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.ResourceManagement.ResourceProviders;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GlitchDebug")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+c6684a6757d5f3f40f98dd4a6f549542e350e1a0")]
[assembly: AssemblyProduct("GlitchDebug")]
[assembly: AssemblyTitle("GlitchDebug")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/hk-speedrunning/Silksong.GlitchDebug")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace GlitchDebug
{
	[BepInDependency("io.github.hk-speedrunning.debugmod", "1.0.3")]
	[BepInDependency("org.silksong-modding.modlist", "0.2.0")]
	[BepInPlugin("io.github.hk-speedrunning.glitchdebug", "GlitchDebug", "0.2.0")]
	public class GlitchDebugPlugin : BaseUnityPlugin
	{
		private static GlitchDebugPlugin? _instance;

		internal ConfigEntry<bool> SaveDupedStates;

		internal ConfigEntry<bool> LegacyForceDuped;

		public const string Id = "io.github.hk-speedrunning.glitchdebug";

		internal static GlitchDebugPlugin Instance => _instance;

		public static string Name => "GlitchDebug";

		public static string Version => "0.2.0";

		private void Start()
		{
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = this;
			}
			SaveDupedStates = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SaveDupedStates", false, "Whether to save states as duped; mirrors the corresponding keybind.");
			LegacyForceDuped = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LegacyForceDuped", false, "Forces duped loading for savestates made prior to v0.2. Will be removed in future; recreate duped states!");
			DebugMod.AddToKeyBindList(typeof(Keybinds));
			DebugMod.AddTextToInfoPanel("INFOPANEL_ALLSCENES", (Func<string>)(() => GeneralExtensions.Join<LoadedSceneInfo>((IEnumerable<LoadedSceneInfo>)SceneWatcher.LoadedScenes, (Func<LoadedSceneInfo, string>)((LoadedSceneInfo lsi) => lsi.name), ", ")), (InfoPanelColumn)0);
			DebugMod.AddTranslationSheet("Mods.io.github.hk-speedrunning.glitchdebug");
			SaveState.BeforeLoad += Savestates.BeforeLoad;
			SaveState.AfterLoad += Savestates.AfterLoad;
			SaveState.OnSave += Savestates.OnSave;
		}

		public static void Log(string message)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)message);
		}
	}
	public class Keybinds
	{
		[CompilerGenerated]
		private sealed class <DupeToTut_01>d__2 : IEnumerator<object>, IEnumerator, IDisposable
		{
			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 <DupeToTut_01>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_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: 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)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					Addressables.LoadSceneAsync((object)"Scenes/Tut_01", (LoadSceneMode)0, true, 100, (SceneReleaseMode)0);
					<>2__current = (object)new WaitUntil((Func<bool>)delegate
					{
						//IL_0000: Unknown result type (might be due to invalid IL or missing references)
						//IL_0005: Unknown result type (might be due to invalid IL or missing references)
						Scene activeScene = SceneManager.GetActiveScene();
						return ((Scene)(ref activeScene)).name == "Tut_01";
					});
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					AsyncOperationHandle<SceneInstance> val = Addressables.LoadSceneAsync((object)"Scenes/Tut_01", (LoadSceneMode)1, true, 100, (SceneReleaseMode)0);
					<>2__current = val;
					<>1__state = 2;
					return true;
				}
				case 2:
					<>1__state = -1;
					GameManager.instance.ReadyForRespawn(false);
					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();
			}
		}

		[CompilerGenerated]
		private sealed class <LoadRoom>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string sceneName;

			private Settings <settings>5__2;

			private int <cs>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <LoadRoom>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<settings>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
				{
					<>1__state = -1;
					AsyncOperation val = SceneManager.LoadSceneAsync(sceneName, (LoadSceneMode)1);
					val.allowSceneActivation = true;
					<>2__current = val;
					<>1__state = 1;
					return true;
				}
				case 1:
					<>1__state = -1;
					GameManager.instance.RefreshTilemapInfo(sceneName);
					<settings>5__2 = DebugMod.settings;
					if (<settings>5__2.ShowHitBoxes > 0)
					{
						<cs>5__3 = <settings>5__2.ShowHitBoxes;
						<settings>5__2.ShowHitBoxes = 0;
						<>2__current = (object)new WaitUntil((Func<bool>)(() => HitboxViewer.State == 0));
						<>1__state = 2;
						return true;
					}
					break;
				case 2:
					<>1__state = -1;
					<settings>5__2.ShowHitBoxes = <cs>5__3;
					break;
				}
				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();
			}
		}

		[BindableMethod(name = "GLITCHES_TOGGLEDUPEDSTATES", category = "CATEGORY_GLITCHES")]
		public static void ToggleDupedStates()
		{
			ConfigEntry<bool> saveDupedStates = GlitchDebugPlugin.Instance.SaveDupedStates;
			saveDupedStates.Value = !saveDupedStates.Value;
			DebugMod.LogConsole("Duped states " + (GlitchDebugPlugin.Instance.SaveDupedStates.Value ? "enabled" : "disabled"));
		}

		[BindableMethod(name = "GLITCHES_MMSDUPETOBENCH", category = "CATEGORY_GLITCHES")]
		public static void MMS_Dupe()
		{
			((MonoBehaviour)GameManager.instance).StartCoroutine(DupeToTut_01());
		}

		[IteratorStateMachine(typeof(<DupeToTut_01>d__2))]
		private static IEnumerator DupeToTut_01()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DupeToTut_01>d__2(0);
		}

		[BindableMethod(name = "GLITCHES_TOGGLENOCLIP", category = "CATEGORY_GLITCHES")]
		public static void ToggleNoclip()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody2D component = ((Component)HeroController.instance).GetComponent<Rigidbody2D>();
			component.bodyType = (RigidbodyType2D)(((int)component.bodyType == 0) ? 1 : 0);
		}

		[BindableMethod(name = "GLITCHES_TOGGLEBENCHSTORAGE", category = "CATEGORY_GLITCHES")]
		public static void ToggleBenchStorage()
		{
			PlayerData.instance.atBench = !PlayerData.instance.atBench;
			DebugMod.LogConsole((PlayerData.instance.atBench ? "Given" : "Taken away") + " bench storage");
		}

		[BindableMethod(name = "GLITCHES_TOGGLEPOGOSTORAGE", category = "CATEGORY_GLITCHES")]
		public static void TogglePogoStorage()
		{
			if (Object.op_Implicit((Object)(object)HeroController.instance.currentDownspike) && !((NailAttackBase)HeroController.instance.currentDownspike).EnemyDamager.endedDamage)
			{
				HeroController.instance.currentDownspike.CancelAttack();
				return;
			}
			HeroController.instance.currentDownspike = HeroController.instance.downSpike;
			HeroController.instance.currentDownspike.StartSlash();
		}

		[BindableMethod(name = "GLITCHES_DUPEACTIVEROOM", category = "CATEGORY_GLITCHES")]
		public static void DupeActiveRoom()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameManager instance = GameManager.instance;
			Scene activeScene = SceneManager.GetActiveScene();
			((MonoBehaviour)instance).StartCoroutine(LoadRoom(((Scene)(ref activeScene)).name));
		}

		[IteratorStateMachine(typeof(<LoadRoom>d__7))]
		private static IEnumerator LoadRoom(string sceneName)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadRoom>d__7(0)
			{
				sceneName = sceneName
			};
		}

		[BindableMethod(name = "GLITCHES_UNDUPEACTIVEROOM", category = "CATEGORY_GLITCHES")]
		public static void UndupeActiveRoom()
		{
			Savestates.UndupeThisState = true;
			SaveState val = SaveStateManager.SaveNewState();
			((MonoBehaviour)GameManager.instance).StartCoroutine(val.Load());
		}

		[BindableMethod(name = "GLITCHES_RESETALLSCENEDATA", category = "CATEGORY_GLITCHES")]
		public static void ResetAllSceneData()
		{
			SceneData.instance.Reset();
			BindableFunctions.ResetCurrentScene();
			DebugMod.LogConsole("All Scene Data reset.");
		}
	}
	internal static class Savestates
	{
		internal static bool UndupeThisState;

		private static bool StateFlagEnabled(SaveState state, string flagName)
		{
			state.data.customData.TryGetValue(flagName, out var value);
			return value == "true";
		}

		internal static void OnSave(SaveState state)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Invalid comparison between Unknown and I4
			if (GlitchDebugPlugin.Instance.SaveDupedStates.Value && !UndupeThisState && state.data.loadedScenes.Length > 1)
			{
				state.data.customData["GlitchDebug.Duped"] = "true";
			}
			UndupeThisState = false;
			if ((int)((Component)HeroController.instance).GetComponent<Rigidbody2D>().bodyType == 1)
			{
				state.data.customData["GlitchDebug.Noclip"] = "true";
			}
			if (PlayerData.instance.atBench)
			{
				state.data.customData["GlitchDebug.BenchStorage"] = "true";
			}
			if (Object.op_Implicit((Object)(object)HeroController.instance.currentDownspike) && !((NailAttackBase)HeroController.instance.currentDownspike).EnemyDamager.endedDamage)
			{
				state.data.customData["GlitchDebug.PogoStorage"] = "true";
			}
		}

		internal static void BeforeLoad(SaveState state)
		{
			if (StateFlagEnabled(state, "GlitchDebug.Duped") || GlitchDebugPlugin.Instance.LegacyForceDuped.Value)
			{
				SaveState.LoadDuped = true;
			}
		}

		internal static void AfterLoad(SaveState state)
		{
			SaveState.LoadDuped = false;
			if (StateFlagEnabled(state, "GlitchDebug.Noclip"))
			{
				((Component)HeroController.instance).GetComponent<Rigidbody2D>().bodyType = (RigidbodyType2D)1;
			}
			if (StateFlagEnabled(state, "GlitchDebug.BenchStorage"))
			{
				GameManager.instance.SetPlayerDataBool("atBench", true);
			}
			if (StateFlagEnabled(state, "GlitchDebug.Invulnerable"))
			{
				HeroController.instance.cState.invulnerable = true;
			}
			if (StateFlagEnabled(state, "GlitchDebug.PogoStorage"))
			{
				HeroController.instance.currentDownspike = HeroController.instance.downSpike;
				HeroController.instance.currentDownspike.StartSlash();
			}
		}
	}
}