Decompiled source of QuickWarp v1.1.1

QuickWarp.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 GlobalEnums;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;

[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("QuickWarp")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+03ddb8180813a5a792af62b2207e3c77308d84f2")]
[assembly: AssemblyProduct("QuickWarp")]
[assembly: AssemblyTitle("QuickWarp")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/hk-speedrunning/QuickWarp")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	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")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace QuickWarp
{
	public static class JsonUtil
	{
		public static readonly JsonSerializer _js;

		public static T Deserialize<T>(string embeddedResourcePath)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			using StreamReader streamReader = new StreamReader(typeof(JsonUtil).Assembly.GetManifestResourceStream(embeddedResourcePath));
			JsonTextReader val = new JsonTextReader((TextReader)streamReader);
			try
			{
				return _js.Deserialize<T>((JsonReader)(object)val);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}

		static JsonUtil()
		{
			//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)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			_js = new JsonSerializer
			{
				DefaultValueHandling = (DefaultValueHandling)1,
				Formatting = (Formatting)1,
				TypeNameHandling = (TypeNameHandling)4
			};
		}
	}
	public class QuickWarpGUI : MonoBehaviour
	{
		public bool Enabled;

		private Vector2 _mapScrollVector = Vector2.zero;

		private Vector2 _sceneScrollVector = Vector2.zero;

		private Vector2 _transitionScrollVector = Vector2.zero;

		private int _areaSelection;

		private int _sceneSelection;

		private int _transitionSelection;

		private string[] _areaNames = Array.Empty<string>();

		private string[] _sceneNames = Array.Empty<string>();

		private string[] _transitionNames = Array.Empty<string>();

		public void Awake()
		{
			_areaNames = Warp.GetAreaNames();
			ResetSceneNames();
			ResetTransitionNames();
		}

		public void Update()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(QuickWarpPlugin.quickWarpKey))
			{
				Enabled = !Enabled;
			}
		}

		public void OnGUI()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			GameManager instance = GameManager.instance;
			if ((instance == null || !instance.IsNonGameplayScene()) && Enabled)
			{
				GUILayout.BeginArea(new Rect(550f, 25f, 520f, 800f));
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) });
				_mapScrollVector = GUILayout.BeginScrollView(_mapScrollVector, Array.Empty<GUILayoutOption>());
				int num = GUILayout.SelectionGrid(_areaSelection, _areaNames, 1, Array.Empty<GUILayoutOption>());
				GUILayout.EndScrollView();
				GUILayout.EndVertical();
				GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[4]
				{
					GUILayout.MaxHeight(400f),
					GUILayout.MinWidth(150f),
					GUILayout.MaxWidth(230f),
					GUILayout.ExpandWidth(false)
				});
				_sceneScrollVector = GUILayout.BeginScrollView(_sceneScrollVector, Array.Empty<GUILayoutOption>());
				int num2 = GUILayout.SelectionGrid(_sceneSelection, _sceneNames, 1, Array.Empty<GUILayoutOption>());
				GUILayout.EndScrollView();
				GUILayout.EndVertical();
				GUILayout.BeginVertical((GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.MaxHeight(400f) });
				_transitionScrollVector = GUILayout.BeginScrollView(_transitionScrollVector, Array.Empty<GUILayoutOption>());
				_transitionSelection = GUILayout.SelectionGrid(_transitionSelection, _transitionNames, 1, Array.Empty<GUILayoutOption>());
				GUILayout.EndScrollView();
				GUILayout.EndVertical();
				GUILayout.EndHorizontal();
				GUILayout.EndArea();
				if (_transitionSelection != 0)
				{
					Enabled = false;
					Warp.TryWarp(_sceneNames[num2], _transitionNames[_transitionSelection]);
					_transitionSelection = 0;
				}
				if (_sceneSelection != num2)
				{
					_sceneSelection = num2;
					ResetTransitionNames();
				}
				if (num != _areaSelection)
				{
					_areaSelection = num;
					ResetSceneNames();
					ResetTransitionNames();
				}
			}
		}

		private void ResetSceneNames()
		{
			_sceneNames = Warp.GetSceneNames(_areaNames[_areaSelection]);
			_sceneSelection = 0;
		}

		private void ResetTransitionNames()
		{
			string text = "Select";
			string[] transitionNames = Warp.GetTransitionNames(_sceneNames[_sceneSelection]);
			int num = 0;
			string[] array = new string[1 + transitionNames.Length];
			array[num] = text;
			num++;
			ReadOnlySpan<string> readOnlySpan = new ReadOnlySpan<string>(transitionNames);
			readOnlySpan.CopyTo(new Span<string>(array).Slice(num, readOnlySpan.Length));
			num += readOnlySpan.Length;
			_transitionNames = array;
			_transitionSelection = 0;
		}
	}
	[BepInPlugin("io.github.hk-speedrunning.quickwarp", "QuickWarp", "1.1.1")]
	public class QuickWarpPlugin : BaseUnityPlugin
	{
		private ConfigEntry<string> quickWarpKeyName;

		public static KeyCode quickWarpKey = (KeyCode)286;

		public static QuickWarpPlugin Instance;

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

		internal static ManualLogSource? Log { get; private set; }

		public static string Name => "QuickWarp";

		public static string Version => "1.1.1";

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			quickWarpKeyName = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Toggle QuickWarp menu", "F5", (ConfigDescription)null);
		}

		private void Start()
		{
			//IL_000a: 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_0015: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Warp.BuildRefs();
			GameObject val = new GameObject("QuickWarp");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<QuickWarpGUI>();
			if (!Enum.TryParse<KeyCode>(quickWarpKeyName.Value, ignoreCase: true, out quickWarpKey))
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Failed to parse QuickWarp key value " + quickWarpKeyName.Value + ", defaulting to F5"));
				quickWarpKey = (KeyCode)286;
			}
		}
	}
	public static class Warp
	{
		[CompilerGenerated]
		private sealed class <TryWarpCoroutine>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public string sceneName;

			public string transitionName;

			private IEnumerator <pauseGameIterator>5__2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: 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_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Expected O, but got Unknown
				int num = <>1__state;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
				}
				else
				{
					<>1__state = -1;
					if (!GameManager.instance.IsGamePaused())
					{
						goto IL_006a;
					}
					<pauseGameIterator>5__2 = GameManager.instance.PauseGameToggleByMenu();
				}
				if (<pauseGameIterator>5__2.MoveNext())
				{
					<>2__current = <pauseGameIterator>5__2.Current;
					<>1__state = 1;
					return true;
				}
				<pauseGameIterator>5__2 = null;
				goto IL_006a;
				IL_006a:
				SceneLoadInfo val = new SceneLoadInfo
				{
					SceneName = sceneName,
					EntryGateName = transitionName,
					PreventCameraFadeOut = true,
					WaitForSceneTransitionCameraFade = false,
					Visualization = (SceneLoadVisualizations)0,
					AlwaysUnloadUnusedAssets = true,
					IsFirstLevelForPlayer = false
				};
				GameManager.UnsafeInstance.BeginSceneTransition(val);
				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 Dictionary<string, SceneInfo> _scenes;

		private static Dictionary<string, List<string>> _scenes_by_area = new Dictionary<string, List<string>>();

		private static Dictionary<string, List<string>> _transitions_by_scene = new Dictionary<string, List<string>>();

		private static Dictionary<string, List<string>> _respawns_by_scene = new Dictionary<string, List<string>>();

		private static MapZone _mapZone;

		private static string _sceneName;

		private static string _transitionName;

		public static string[] GetAreaNames()
		{
			return _scenes_by_area.Keys.ToArray();
		}

		public static string[] GetSceneNames(string areaName)
		{
			return _scenes_by_area[areaName].OrderBy((string x) => x).ToArray();
		}

		public static string[] GetTransitionNames(string sceneName)
		{
			return _transitions_by_scene[sceneName].OrderBy((string x) => x).ToArray();
		}

		public static void BuildRefs()
		{
			_scenes = ((SerializableNamedList<SceneInfo, SerializableSceneInfo>)(object)SceneTeleportMap.Instance.sceneList).RuntimeData;
			_scenes_by_area = JsonUtil.Deserialize<Dictionary<string, List<string>>>("QuickWarp.Resources.scenes_by_area.json");
			_transitions_by_scene.Clear();
			_respawns_by_scene.Clear();
			foreach (var (key, val2) in _scenes)
			{
				_transitions_by_scene[key] = val2.TransitionGates;
				_respawns_by_scene[key] = val2.RespawnPoints;
			}
		}

		public static void TryWarp(string sceneName, string transitionName)
		{
			((MonoBehaviour)QuickWarpPlugin.Instance).StartCoroutine(TryWarpCoroutine(sceneName, transitionName));
		}

		[IteratorStateMachine(typeof(<TryWarpCoroutine>d__12))]
		public static IEnumerator TryWarpCoroutine(string sceneName, string transitionName)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TryWarpCoroutine>d__12(0)
			{
				sceneName = sceneName,
				transitionName = transitionName
			};
		}
	}
}