Decompiled source of GeoSaver v1.0.1

plugins/GeoSaver.dll

Decompiled 5 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using CommonAPI;
using CommonAPI.Phone;
using GeoSaver.Apps;
using GeoSaver.Patches;
using HarmonyLib;
using MapStation.API;
using Reptile;
using Reptile.Phone;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BRC_HarmonyTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BRC_HarmonyTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("32955761-5b97-4968-9c6d-aca3855af53e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace GeoSaver
{
	public class LocationApp : CustomApp
	{
		private static Sprite IconSprite;

		public static void Init()
		{
			string text = Path.Combine(GeoSaverPlugin.Instance.Dir, "GeoSaver_Icon.png");
			try
			{
				IconSprite = TextureUtility.LoadSprite(text);
				PhoneAPI.RegisterApp<LocationApp>("GeoSaver", IconSprite);
			}
			catch (Exception ex)
			{
				Console.WriteLine("Error loading icon sprite: " + ex.Message);
				PhoneAPI.RegisterApp<LocationApp>("GeoSaver", (Sprite)null);
			}
		}

		public override void OnAppInit()
		{
			((CustomApp)this).OnAppInit();
			((CustomApp)this).CreateIconlessTitleBar("GeoSaver", 80f);
			base.ScrollView = PhoneScrollView.Create((CustomApp)(object)this, 275f, 1600f);
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("Save Location");
			SimplePhoneButton obj = val;
			((PhoneButton)obj).OnConfirm = (Action)Delegate.Combine(((PhoneButton)obj).OnConfirm, (Action)delegate
			{
				((App)this).MyPhone.OpenApp(typeof(SaveApp));
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
			val = PhoneUIUtility.CreateSimpleButton("Load Location");
			SimplePhoneButton obj2 = val;
			((PhoneButton)obj2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)obj2).OnConfirm, (Action)delegate
			{
				((App)this).MyPhone.OpenApp(typeof(LoadApp));
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
			val = PhoneUIUtility.CreateSimpleButton("Save Temp Location");
			SimplePhoneButton obj3 = val;
			((PhoneButton)obj3).OnConfirm = (Action)Delegate.Combine(((PhoneButton)obj3).OnConfirm, (Action)delegate
			{
				GeoSaverPlugin.TempSaveButton();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
			val = PhoneUIUtility.CreateSimpleButton("Load Last Location");
			SimplePhoneButton obj4 = val;
			((PhoneButton)obj4).OnConfirm = (Action)Delegate.Combine(((PhoneButton)obj4).OnConfirm, (Action)delegate
			{
				GeoSaverPlugin.TempLoadButton();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val);
		}
	}
	internal class LocationFileManager
	{
		private static string configFolderPath = Path.GetDirectoryName(((BaseUnityPlugin)GeoSaverPlugin.Instance).Config.ConfigFilePath);

		private static string locationsFolderPath = Path.Combine(configFolderPath, "Locations");

		public static void SaveLocation(string customFolderPath = null)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			Player player = GeoSaverPlugin.player;
			Vector3 position = player.tf.position;
			Quaternion rotation = player.tf.rotation;
			Stage currentStage = Core.instance.baseModule.stageManager.baseModule.currentStage;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(Mathf.Round(position.x), Mathf.Round(position.y), Mathf.Round(position.z));
			string contents = $"{position.x},{position.y},{position.z}|{rotation.x},{rotation.y},{rotation.z},{rotation.w}|{currentStage}";
			string text = customFolderPath ?? locationsFolderPath;
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string text2 = $"{currentStage}_{val.x}_{val.y}_{val.z}.txt";
			text2 = string.Join("_", text2.Split(Path.GetInvalidFileNameChars()));
			string path = Path.Combine(text, text2);
			int num = 1;
			while (File.Exists(path))
			{
				path = Path.Combine(text, $"{currentStage}_{val.x}_{val.y}_{val.z}_{num}.txt");
				num++;
			}
			File.WriteAllText(path, contents);
		}

		public static bool LoadLocation(string name)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(locationsFolderPath, name + ".txt");
			if (!File.Exists(text))
			{
				Debug.LogWarning((object)("Save file not found at " + text));
				return false;
			}
			try
			{
				string[] array = File.ReadAllText(text).Split(new char[1] { '|' });
				if (array.Length != 3)
				{
					Debug.LogError((object)"Invalid save data format");
					return false;
				}
				Vector3 val = ParseVector3(array[0]);
				Quaternion val2 = ParseQuaternion(array[1]);
				string text2 = array[2];
				Player player = GeoSaverPlugin.player;
				if ((Object)(object)player == (Object)null)
				{
					Debug.LogError((object)"Player reference is null");
					return false;
				}
				if (text2.StartsWith("mapstation/"))
				{
					GeoSaverPlugin.desLoc = val;
					GeoSaverPlugin.desRot = val2;
					GeoSaverPlugin.desStg = text2;
					if (text2 != ((object)(Stage)(ref Core.instance.baseModule.stageManager.baseModule.currentStage)).ToString())
					{
						GeoSaverPlugin.moveMe = true;
						string text3 = text2.Remove(0, "mapstation/".Length);
						if (APIManager.API.GetCustomStageByID(APIManager.API.GetStageID(text3)) != null)
						{
							Stage val3 = (Stage)APIManager.API.GetStageID(text3);
							Core.instance.baseModule.stageManager.ExitCurrentStage(val3, (Stage)(-1));
						}
						else
						{
							Debug.LogError((object)"Stage not found");
						}
					}
					else
					{
						GeoSaverPlugin.PlacePlayer(val, val2, velSave: true);
					}
				}
				else
				{
					GeoSaverPlugin.desLoc = val;
					GeoSaverPlugin.desRot = val2;
					GeoSaverPlugin.desStg = text2;
					Stage val4 = StringToStage(text2);
					if (val4 != Core.instance.baseModule.stageManager.baseModule.currentStage)
					{
						Core.instance.baseModule.stageManager.ExitCurrentStage(val4, (Stage)(-1));
						GeoSaverPlugin.moveMe = true;
					}
					else
					{
						GeoSaverPlugin.PlacePlayer(val, val2, velSave: true);
					}
				}
				return true;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Error loading location: " + ex.Message));
				return false;
			}
		}

		public static Stage StringToStage(string stageName)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return (Stage)Enum.Parse(typeof(Stage), stageName, ignoreCase: true);
		}

		private static Vector3 ParseVector3(string vectorString)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			string[] array = vectorString.Split(new char[1] { ',' });
			return new Vector3(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]));
		}

		private static Quaternion ParseQuaternion(string quaternionString)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			string[] array = quaternionString.Split(new char[1] { ',' });
			return new Quaternion(float.Parse(array[0]), float.Parse(array[1]), float.Parse(array[2]), float.Parse(array[3]));
		}
	}
	[BepInPlugin("com.Yuri.GeoSaver", "GeoSaver", "1.0.0")]
	public class GeoSaverPlugin : BaseUnityPlugin
	{
		public const string MyGUID = "com.Yuri.GeoSaver";

		private const string PluginName = "GeoSaver";

		private const string VersionString = "1.0.0";

		private Harmony harmony;

		public static Player player;

		public static ConfigEntry<bool> EnableVelSave;

		public static ConfigEntry<bool> EnableVelForward;

		public static ConfigEntry<bool> EnableUnground;

		public static ConfigEntry<KeyboardShortcut> LoadKey;

		public static ConfigEntry<KeyboardShortcut> SaveKey;

		public static bool moveMe;

		public static Vector3 desLoc;

		public static Quaternion desRot;

		public static string desStg;

		public static GeoSaverPlugin Instance { get; private set; }

		public string Dir => Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmony = new Harmony("com.Yuri.GeoSaver");
			harmony.PatchAll(typeof(PlayerPatch));
			Instance = this;
			InitConfig();
			LocationApp.Init();
			LoadApp.Init();
			SaveApp.Init();
		}

		private void InitConfig()
		{
			//IL_0078: 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)
			EnableVelSave = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Velocity Retention", false, "Retains current velocity when loading a state in the same stage.");
			EnableVelForward = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Forward Velocity Correction", true, "When velocity is retained adjust the returned velocity to the players new forward direction.");
			EnableUnground = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Force Unground", false, "Will force the player to be airborne for a moment when loading a position, this will often make storage goons trigger automatically.");
			LoadKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "Load last Location Key", new KeyboardShortcut((KeyCode)120, Array.Empty<KeyCode>()), "Hotkey to load the last loaded location, this only applies if the location is in the current stage.");
			SaveKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "Temp Save Location Key", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), "Hotkey to make a temporary save, this does not make a file but can be loaded with the load last location button.");
		}

		private void Update()
		{
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			if (!((Object)(object)player != (Object)null))
			{
				return;
			}
			KeyboardShortcut value;
			if (desStg == ((object)(Stage)(ref Core.instance.baseModule.stageManager.baseModule.currentStage)).ToString())
			{
				value = LoadKey.Value;
				if (((KeyboardShortcut)(ref value)).IsDown())
				{
					TempLoadButton();
				}
				if (moveMe)
				{
					PlacePlayer(desLoc, desRot, velSave: false);
					moveMe = false;
				}
			}
			value = SaveKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				TempSaveButton();
			}
		}

		public static void TempSaveButton()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			desLoc = player.tf.position;
			desRot = player.tf.rotation;
			desStg = ((object)(Stage)(ref Core.instance.baseModule.stageManager.baseModule.currentStage)).ToString();
		}

		public static void TempLoadButton()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			PlacePlayer(desLoc, desRot, velSave: true);
		}

		public static void PlacePlayer(Vector3 loc, Quaternion rot, bool velSave)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			Vector3 velocity = player.GetVelocity();
			WorldHandler.instance.PlacePlayerAt(player, loc, rot, true);
			if (EnableUnground.Value)
			{
				player.ForceUnground(true);
			}
			if (EnableVelSave.Value && velSave)
			{
				Vector3 val = (EnableVelForward.Value ? AlignVelocityWithForward(velocity, ((Component)player).transform.forward) : velocity);
				if (val.y > 0f || EnableUnground.Value)
				{
					player.ForceUnground(true);
				}
				player.SetVelocity(val);
			}
		}

		private static Vector3 AlignVelocityWithForward(Vector3 velocity, Vector3 forward)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.up * velocity.y;
			Vector3 val2 = Vector3.ProjectOnPlane(velocity, Vector3.up);
			float magnitude = ((Vector3)(ref val2)).magnitude;
			return forward * magnitude + val;
		}
	}
}
namespace GeoSaver.Patches
{
	internal static class PlayerPatch
	{
		[HarmonyPatch(typeof(Player), "Init")]
		[HarmonyPostfix]
		private static void Player_Init_Postfix(Player __instance)
		{
			if (!__instance.isAI)
			{
				GeoSaverPlugin.player = __instance;
			}
		}
	}
}
namespace GeoSaver.Apps
{
	public class SaveApp : CustomApp
	{
		public static List<string> currentPath = new List<string>();

		public override bool Available => false;

		public static void Init()
		{
			PhoneAPI.RegisterApp<SaveApp>("Save Location", (Sprite)null);
		}

		public override void OnAppInit()
		{
			((CustomApp)this).OnAppInit();
			((CustomApp)this).CreateIconlessTitleBar("Save Location", 80f);
		}

		public override void OnAppEnable()
		{
			((App)this).OnAppEnable();
			if ((Object)(object)base.ScrollView == (Object)null)
			{
				base.ScrollView = PhoneScrollView.Create((CustomApp)(object)this, 275f, 1600f);
			}
			else
			{
				base.ScrollView.RemoveAllButtons();
			}
			PopulateList();
		}

		public override void OnAppDisable()
		{
			((App)this).OnAppDisable();
			currentPath.Clear();
		}

		private void PopulateList()
		{
			var (list, list2) = GetAvailableLocations(currentPath);
			if (currentPath.Count > 0)
			{
				SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("..");
				((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
				{
					currentPath.RemoveAt(currentPath.Count - 1);
					((App)this).OnAppEnable();
				});
				base.ScrollView.AddButton((PhoneButton)(object)val);
			}
			SimplePhoneButton val2 = PhoneUIUtility.CreateSimpleButton("Save Here");
			((PhoneButton)val2).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val2).OnConfirm, (Action)delegate
			{
				SaveLocation();
			});
			base.ScrollView.AddButton((PhoneButton)(object)val2);
			foreach (string item in list)
			{
				SimplePhoneButton val3 = CreateFolderButton(item);
				base.ScrollView.AddButton((PhoneButton)(object)val3);
			}
		}

		public static (List<string> folders, List<string> files) GetAvailableLocations(List<string> path)
		{
			GeoSaverPlugin instance = GeoSaverPlugin.Instance;
			string path2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Config.ConfigFilePath), "Locations");
			path2 = Path.Combine(path2, Path.Combine(path.ToArray()));
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			if (Directory.Exists(path2))
			{
				string[] directories = Directory.GetDirectories(path2);
				string[] array = directories;
				foreach (string path3 in array)
				{
					list.Add(Path.GetFileName(path3));
				}
				string[] files = Directory.GetFiles(path2, "*.txt");
				string[] array2 = files;
				foreach (string path4 in array2)
				{
					list2.Add(Path.GetFileNameWithoutExtension(path4));
				}
			}
			else
			{
				Directory.CreateDirectory(path2);
			}
			return (list, list2);
		}

		private SimplePhoneButton CreateFolderButton(string folderName)
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(folderName + "/");
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				currentPath.Add(folderName);
				((App)this).OnAppEnable();
			});
			return val;
		}

		private void SaveLocation()
		{
			GeoSaverPlugin instance = GeoSaverPlugin.Instance;
			string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Config.ConfigFilePath), "Locations");
			string customFolderPath = Path.Combine(path, Path.Combine(currentPath.ToArray()));
			LocationFileManager.SaveLocation(customFolderPath);
			((App)this).MyPhone.CloseCurrentApp();
		}
	}
	public class LoadApp : CustomApp
	{
		private static List<string> currentPath = new List<string>();

		private static string stage;

		public override bool Available => false;

		public static void Init()
		{
			PhoneAPI.RegisterApp<LoadApp>("Load Location", (Sprite)null);
		}

		public override void OnAppInit()
		{
			((CustomApp)this).OnAppInit();
			((CustomApp)this).CreateIconlessTitleBar("Load Location", 80f);
		}

		public override void OnAppEnable()
		{
			((App)this).OnAppEnable();
			if ((Object)(object)base.ScrollView == (Object)null)
			{
				base.ScrollView = PhoneScrollView.Create((CustomApp)(object)this, 275f, 1600f);
			}
			else
			{
				base.ScrollView.RemoveAllButtons();
			}
			if (stage != ((object)(Stage)(ref Core.instance.baseModule.stageManager.baseModule.currentStage)).ToString() && stage != null)
			{
				currentPath.Clear();
			}
			stage = ((object)(Stage)(ref Core.instance.baseModule.stageManager.baseModule.currentStage)).ToString();
			PopulateList();
		}

		private void PopulateList()
		{
			var (list, list2) = GetAvailableLocations(currentPath);
			if (currentPath.Count > 0)
			{
				SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton("..");
				((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
				{
					currentPath.RemoveAt(currentPath.Count - 1);
					((App)this).OnAppEnable();
				});
				base.ScrollView.AddButton((PhoneButton)(object)val);
			}
			foreach (string item in list)
			{
				SimplePhoneButton val2 = CreateFolderButton(item);
				base.ScrollView.AddButton((PhoneButton)(object)val2);
			}
			foreach (string item2 in list2)
			{
				SimplePhoneButton val3 = CreateLocationButton(item2);
				base.ScrollView.AddButton((PhoneButton)(object)val3);
			}
		}

		public static (List<string> folders, List<string> files) GetAvailableLocations(List<string> path)
		{
			GeoSaverPlugin instance = GeoSaverPlugin.Instance;
			string path2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)instance).Config.ConfigFilePath), "Locations");
			path2 = Path.Combine(path2, Path.Combine(path.ToArray()));
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			if (Directory.Exists(path2))
			{
				string[] directories = Directory.GetDirectories(path2);
				string[] array = directories;
				foreach (string path3 in array)
				{
					list.Add(Path.GetFileName(path3));
				}
				string[] files = Directory.GetFiles(path2, "*.txt");
				string[] array2 = files;
				foreach (string path4 in array2)
				{
					list2.Add(Path.GetFileNameWithoutExtension(path4));
				}
			}
			return (list, list2);
		}

		private SimplePhoneButton CreateFolderButton(string folderName)
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(folderName + "/");
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				currentPath.Add(folderName);
				((App)this).OnAppEnable();
			});
			return val;
		}

		private static SimplePhoneButton CreateLocationButton(string preset)
		{
			SimplePhoneButton val = PhoneUIUtility.CreateSimpleButton(preset);
			((PhoneButton)val).OnConfirm = (Action)Delegate.Combine(((PhoneButton)val).OnConfirm, (Action)delegate
			{
				LocationFileManager.LoadLocation(Path.Combine(Path.Combine(currentPath.ToArray()), preset));
			});
			return val;
		}
	}
}

plugins/MapStation.API.dll

Decompiled 5 hours ago
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyCompany("MapStation.API")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fcde2fd24791d3a1e0f0ffd87d453c788d9e8863")]
[assembly: AssemblyProduct("MapStation.API")]
[assembly: AssemblyTitle("MapStation.API")]
[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 MapStation.API
{
	public static class APIManager
	{
		public static IMapStationAPI API;

		public static bool Initialized;

		public static event Action OnInitialized;

		public static void Initialize(IMapStationAPI api)
		{
			API = api;
			Initialized = true;
			APIManager.OnInitialized?.Invoke();
		}
	}
	public interface ICustomStage
	{
		string DisplayName { get; }

		string InternalName { get; }

		string AuthorName { get; }

		int StageID { get; }
	}
	public interface IMapStationAPI
	{
		ReadOnlyCollection<ICustomStage> CustomStages { get; }

		ICustomStage GetCustomStageByID(int stageID);

		int GetStageID(string stageInternalName);
	}
}