Decompiled source of TeleportFromAnywhere v0.2.1

TeleportFromAnywhere.dll

Decompiled a month 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 RCGFSM.Items;
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.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+25c7c55d5a5fbe61cb20d572f5837eb889f498ac")]
[assembly: AssemblyProduct("TeleportFromAnywhere")]
[assembly: AssemblyTitle("TeleportFromAnywhere")]
[assembly: AssemblyVersion("0.1.2.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.2")]
	[HarmonyPatch]
	public class TeleportFromAnywhere : BaseUnityPlugin
	{
		private Harmony harmony;

		private static string NymphAbilitySaveFlagId = "be31937c6691a44d88d3d70ac2f62cc9PlayerAbilityData";

		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") && SingletonBehaviour<GameCore>.IsAvailable() && SingletonBehaviour<GameFlagManager>.IsAvailable())
			{
				if (SingletonBehaviour<GameCore>.Instance.CurrentSceneName == "A5_S2_Jail_Remake_Final" && !((FlagField<bool>)(object)((GameFlagDescriptable)SingletonBehaviour<GameFlagManager>.Instance.GetTeleportPointWithPath("28a1908d9e21d4136b8c903e2b92b0afTeleportPointData")).unlocked).CurrentValue)
				{
					Log.Info("TeleportFromAnywhere: Keeping Teleport menu hidden because we're in Prison and its node hasn't been activated yet. If the player teleported out now, they'd never be able to get back in.");
				}
				else if (!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) + "'");
			if (!SingletonBehaviour<GameCore>.IsAvailable() || !SingletonBehaviour<ApplicationUIGroupManager>.IsAvailable())
			{
				return true;
			}
			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;
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void TeleportPointButton_get_IsNotAcquired(TeleportPointButton __instance, ref bool __result)
		{
			if (__result)
			{
				Log.Info("TeleportPointButton_get_IsNotAcquired enabling '" + ((__instance != null) ? ((Object)__instance).name : null) + "' button, so the player can teleport there despite it being their 'current node'");
				__result = false;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(TeleportPointButton), "GetInstructionData")]
		public static bool TeleportPointButton_GetInstructionData(TeleportPointButton __instance, ref ButtonInstructionData __result)
		{
			__result = AccessTools.FieldRefAccess<UIControlButton, ButtonInstructionData>("InstructionData").Invoke((UIControlButton)(object)__instance);
			return false;
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void TreeGotMadCondition_get_isValid(TreeGotMadCondition __instance, ref bool __result)
		{
			if (__result)
			{
				Log.Info("forcing TreeGotMadCondition to pass so the Root Node menus will continue to display [Pavilion]/[Last Node] options");
				__result = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void PlayerInPrisionCondition_get_isValid(PlayerInPrisionCondition __instance, ref bool __result)
		{
			if (__result)
			{
				Log.Info("forcing PlayerInPrisionCondition_get_isValid to return true so the Root Node menus will continue to display [Pavilion]/[Last Node] options");
				__result = false;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static void TeleportPointMatchSavePanelCondition_get_isValid(TeleportPointMatchSavePanelCondition __instance, ref bool __result)
		{
			Transform parent = ((Component)__instance).transform.parent;
			if (((parent != null) ? ((Object)parent).name : null) == "Teleport 神遊" && !__result)
			{
				__result = true;
			}
		}

		public static string GetGOPath(GameObject go)
		{
			Transform val = go.transform;
			List<string> list = new List<string>();
			while ((Object)(object)val != (Object)null)
			{
				list.Add(((Object)val).name);
				val = val.parent;
			}
			list.Reverse();
			return string.Join("/", list);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(PickItemAction), "OnStateEnterImplement")]
		private static bool PickItemAction_OnStateEnterImplement(PickItemAction __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)__instance.scheme == 1 && ((GameFlagBase)__instance.pickItemData).FinalSaveID == NymphAbilitySaveFlagId && GetGOPath(((Component)__instance).gameObject) == "A2_Stage_Remake/Room/Prefab/FallingTeleportTrickBackgroundProvider/A7_HotSpring/溫泉場景Setting FSM Object/FSM Animator/LogicRoot/SectionA/[CutScene] Portal 第一次來到 A7/--[States]/FSM/[State] PlayCutSceneEnd/[Action] DisableButterfly")
			{
				Log.Info("PickItemAction_OnStateEnterImplement preventing Lady E's soulscape from disabling the nymph, so you can safely teleport out without losing it");
				return false;
			}
			return true;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TeleportFromAnywhere";

		public const string PLUGIN_NAME = "TeleportFromAnywhere";

		public const string PLUGIN_VERSION = "0.1.2";
	}
}