Decompiled source of TeleportFromAnywhere v0.1.1

TeleportFromAnywhere.dll

Decompiled 4 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("TeleportFromAnywhere")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A Nine Sols mod that allows the player to use the \"Teleport\" menu from anywhere in the game, not just the Pavilion root node.")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+6c69ec0434948828831ec821bb0b7c11c9d97365")]
[assembly: AssemblyProduct("TeleportFromAnywhere")]
[assembly: AssemblyTitle("TeleportFromAnywhere")]
[assembly: AssemblyVersion("0.1.1.0")]
[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 TeleportFromAnywhere
{
	internal static class Log
	{
		private static ManualLogSource? logSource;

		internal static void Init(ManualLogSource logSource)
		{
			Log.logSource = logSource;
		}

		internal static void Debug(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogError(data);
			}
		}

		internal static void Fatal(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogFatal(data);
			}
		}

		internal static void Info(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogInfo(data);
			}
		}

		internal static void Message(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogMessage(data);
			}
		}

		internal static void Warning(object data)
		{
			ManualLogSource? obj = logSource;
			if (obj != null)
			{
				obj.LogWarning(data);
			}
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("TeleportFromAnywhere", "TeleportFromAnywhere", "0.1.1")]
	[HarmonyPatch]
	public class TeleportFromAnywhere : BaseUnityPlugin
	{
		private Harmony harmony;

		private void Awake()
		{
			Log.Init(((BaseUnityPlugin)this).Logger);
			RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
			harmony = Harmony.CreateAndPatchAll(typeof(TeleportFromAnywhere).Assembly, (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TeleportFromAnywhere is loaded!");
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TabsUI), "PrepareValidTab")]
		public static void TabsUI_PrepareValidTab_Postfix(TabsUI __instance)
		{
			List<UITabsItem> list = AccessTools.FieldRefAccess<TabsUI, List<UITabsItem>>("items").Invoke(__instance);
			Log.Debug(string.Format("TabsUI_PrepareValidTab_Postfix {0} {1}", list, string.Join("|", list.Select((UITabsItem i) => ((Object)((Component)i).gameObject).name))));
			if (!(((Object)list[0]).name != "TeleportPanel Tab") && !list[0].IsAllValid)
			{
				Log.Debug("TabsUI_PrepareValidTab_Postfix forcing TeleportTab into the list of 'valid' menu tabs");
				AccessTools.FieldRefAccess<TabsUI, List<UITabsItem>>("validItems").Invoke(__instance).Add(list[0]);
				((Component)list[0]).gameObject.SetActive(true);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TeleportPointButton), "SubmitImplementation")]
		public static bool TeleportPointButton_SubmitImplementation(TeleportPointButton __instance)
		{
			Log.Info("TeleportPointButton_SubmitImplementation called for button '" + ((__instance != null) ? ((Object)__instance).name : null) + "'");
			GameCore instance = SingletonBehaviour<GameCore>.Instance;
			object obj;
			if (instance == null)
			{
				obj = null;
			}
			else
			{
				SavePanel savePanelUiController = instance.savePanelUiController;
				obj = ((savePanelUiController != null) ? savePanelUiController.CurrentSavePointGameObjectOnScene : null);
			}
			if ((Object)obj != (Object)null)
			{
				return true;
			}
			Log.Info("Yi is not sitting at the Pavilion root node. Using mod impl of teleportation to avoid errors.");
			SingletonBehaviour<GameCore>.Instance.savePanelUiController.ToMenu = false;
			SingletonBehaviour<ApplicationUIGroupManager>.Instance.PopAll();
			SingletonBehaviour<GameCore>.Instance.savePanelUiController.ClearCurrentSavePoint();
			SingletonBehaviour<GameCore>.Instance.SetReviveSavePoint(__instance?.teleportPoint);
			SingletonBehaviour<GameCore>.Instance.TeleportToSavePoint(__instance?.teleportPoint, false, 0f);
			return false;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TeleportFromAnywhere";

		public const string PLUGIN_NAME = "TeleportFromAnywhere";

		public const string PLUGIN_VERSION = "0.1.1";
	}
}