Decompiled source of SailwindModdingHelper v2.0.3

SailwindModdingHelper.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SailwindModdingHelper;

public static class Extensions
{
	public static object GetPrivateField(this object obj, string field)
	{
		return Traverse.Create(obj).Field(field).GetValue();
	}

	public static object GetPrivateField(Type type, string field)
	{
		return Traverse.Create(type).Field(field).GetValue();
	}

	public static T GetPrivateField<T>(Type type, string field)
	{
		return (T)GetPrivateField(type, field);
	}

	public static T GetPrivateField<T>(this object obj, string field)
	{
		return (T)obj.GetPrivateField(field);
	}

	public static object GetPrivateField<T>(string field)
	{
		return Traverse.Create(typeof(T)).Field(field).GetValue();
	}

	public static T GetPrivateField<T, E>(string field)
	{
		return (T)GetPrivateField<E>(field);
	}

	public static void SetPrivateField(this object obj, string field, object value)
	{
		Traverse.Create(obj).Field(field).SetValue(value);
	}

	public static void SetPrivateField<T>(string field, object value)
	{
		Traverse.Create(typeof(T)).Field(field).SetValue(value);
	}

	public static object InvokePrivateMethod(this object obj, string method, params object[] parameters)
	{
		return AccessTools.Method(obj.GetType(), method, (Type[])null, (Type[])null).Invoke(obj, parameters);
	}

	public static T InvokePrivateMethod<T>(this object obj, string method, params object[] parameters)
	{
		return (T)obj.InvokePrivateMethod(method, parameters);
	}

	public static object InvokePrivateMethod<T>(string method, params object[] parameters)
	{
		return AccessTools.Method(typeof(T), method, (Type[])null, (Type[])null).Invoke(null, parameters);
	}

	public static T InvokePrivateMethod<T, E>(string method, params object[] parameters)
	{
		return (T)InvokePrivateMethod<E>(method, parameters);
	}

	public static T GetCopyOf<T>(this Component comp, T other) where T : Component
	{
		Type type = ((object)comp).GetType();
		if (type != ((object)other).GetType())
		{
			return default(T);
		}
		BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
		PropertyInfo[] properties = type.GetProperties(bindingAttr);
		foreach (PropertyInfo propertyInfo in properties)
		{
			if (propertyInfo.CanWrite)
			{
				try
				{
					propertyInfo.SetValue(comp, propertyInfo.GetValue(other, null), null);
				}
				catch
				{
				}
			}
		}
		FieldInfo[] fields = type.GetFields(bindingAttr);
		foreach (FieldInfo fieldInfo in fields)
		{
			fieldInfo.SetValue(comp, fieldInfo.GetValue(other));
		}
		return (T)(object)((comp is T) ? comp : null);
	}

	public static T AddComponent<T>(this GameObject go, T toAdd) where T : Component
	{
		return ((Component)(object)go.AddComponent<T>()).GetCopyOf(toAdd);
	}

	public static Transform GetChildByName(this Transform transform, string childName)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		foreach (Transform item in transform)
		{
			Transform val = item;
			if (((Object)val).name == childName)
			{
				return val;
			}
		}
		return null;
	}

	public static string GetFolderLocation(this PluginInfo pluginInfo)
	{
		return Directory.GetParent(pluginInfo.Location).FullName;
	}
}
public sealed class RegionData
{
	public Vector3 globePosition;

	public Vector3 globeSize;

	public Bounds globeBounds => new Bounds(globePosition, globeSize);

	public RegionData(Vector3 globePosition, Vector3 globeSize)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: 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)
		this.globePosition = globePosition;
		this.globeSize = globeSize;
	}
}
public static class GameAssets
{
	public static Font ArealFont { get; internal set; }

	public static Region AlAnkhRegion { get; internal set; }

	public static Region EmeraldRegion { get; internal set; }

	public static Region MediRegion { get; internal set; }

	public static Region MediEastRegion { get; internal set; }

	public static Region LagoonRegion { get; internal set; }

	public static RegionData AlAnkhRegionData { get; internal set; }

	public static RegionData EmeraldRegionData { get; internal set; }

	public static RegionData MediRegionData { get; internal set; }

	public static RegionData OceanRegionData { get; internal set; }

	public static StartMenu StartMenu { get; internal set; }

	public static Font ImmortalFont { get; internal set; }

	public static IReadOnlyList<string> AlcoholNames { get; } = new List<string> { "rum", "wine", "coconut wine", "honey beer", "mead", "rice beer" };


	public static IReadOnlyList<SailwindPrefab> Prefabs { get; private set; }

	public static bool IsAlcohol(string liquidName)
	{
		return AlcoholNames.Contains(liquidName.ToLower());
	}

	public static bool IsAlcohol(float liquidIndexAsAmount)
	{
		return IsAlcohol(Liquids.GetLiquidName(liquidIndexAsAmount));
	}

	internal static void LoadPrefabs()
	{
		List<SailwindPrefab> list = new List<SailwindPrefab>();
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		foreach (GameObject val in array)
		{
			List<string> list2 = new List<string>(((Object)val).name.Split(new char[1] { ' ' }));
			if (int.TryParse(list2[0], out var _))
			{
				list2.RemoveAt(0);
			}
			string prefabName = string.Join(" ", list2);
			list.Add(new SailwindPrefab(((Object)val).name, prefabName, val));
		}
		Prefabs = list;
	}

	public static GameObject GetPrefabGameObject(string prefabName)
	{
		return GetPrefab(prefabName).PrefabGameObject;
	}

	public static SailwindPrefab GetPrefab(string prefabName)
	{
		string text = prefabName.ToLower();
		foreach (SailwindPrefab prefab in Prefabs)
		{
			if (prefab.PrefabName.ToLower() == text || prefab.FullPrefabName.ToLower() == text)
			{
				return prefab;
			}
		}
		return new SailwindPrefab("", "", null);
	}
}
public struct SailwindPrefab
{
	public string FullPrefabName { get; }

	public string PrefabName { get; }

	public GameObject PrefabGameObject { get; }

	internal SailwindPrefab(string fullPrefabName, string prefabName, GameObject prefabGameObject)
	{
		FullPrefabName = fullPrefabName;
		PrefabName = prefabName;
		PrefabGameObject = prefabGameObject;
	}
}
public static class GameCanvas
{
	public static GameObject GameObject { get; private set; }

	public static Transform Transform { get; private set; }

	internal static void InitializeCanvas()
	{
		GameObject = ((Component)((Component)Object.FindObjectOfType<NotificationUi>()).transform.parent).gameObject;
		Transform = GameObject.transform;
	}

	public static void AddToCanvas(GameObject gameObject)
	{
		gameObject.transform.SetParent(Transform, false);
	}
}
public static class GameEvents
{
	public delegate void SaveSlotEventHandler(object sender, SaveSlotEventArgs e);

	public delegate void GameSaveEventHandler(object sender, SaveSlotEventArgs e);

	public delegate void GameQuitEventHandler(object sender, GameQuitEventArgs e);

	[HarmonyPatch(typeof(Sun), "Start")]
	private static class GameStartPatch
	{
		[HarmonyPostfix]
		public static void Postfix(Sun __instance)
		{
			GameEvents.OnGameStart?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(StartMenu), "ButtonClick", new Type[] { typeof(StartMenuButtonType) })]
	private static class GameQuit
	{
		[HarmonyPostfix]
		public static void Postfix(StartMenu __instance, StartMenuButtonType button)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)button == 4)
			{
				GameEvents.OnGameQuit?.Invoke(__instance, new GameQuitEventArgs(GameState.playing));
			}
		}
	}

	[HarmonyPatch(typeof(StartMenu), "GameToSettings")]
	private static class GamePausePatch
	{
		[HarmonyPrefix]
		public static void Prefix(StartMenu __instance)
		{
			GameEvents.OnGamePause?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(StartMenu), "SettingsToGame")]
	private static class GameUnpausePatch
	{
		[HarmonyPrefix]
		public static void Prefix(StartMenu __instance)
		{
			GameEvents.OnGameUnpause?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(StartMenu), "StartNewGame")]
	private static class SaveLoadNew
	{
		[HarmonyPostfix]
		public static void Postfix(StartMenu __instance)
		{
			GameEvents.OnNewGame?.Invoke(__instance, new SaveSlotEventArgs(SaveSlots.currentSlot));
		}
	}

	[HarmonyPatch(typeof(SaveLoadManager), "LoadGame")]
	private static class SaveLoad
	{
		[HarmonyPostfix]
		public static void Postfix(StartMenu __instance)
		{
			GameEvents.OnSaveLoad?.Invoke(__instance, new SaveSlotEventArgs(SaveSlots.currentSlot));
			GameEvents.OnSaveLoadPost?.Invoke(__instance, new SaveSlotEventArgs(SaveSlots.currentSlot));
		}
	}

	[HarmonyPatch(typeof(SaveLoadManager), "SaveModData")]
	private static class SaveSave
	{
		[HarmonyPostfix]
		public static void Postfix(SaveLoadManager __instance)
		{
			GameEvents.OnGameSave?.Invoke(__instance, new SaveSlotEventArgs(SaveSlots.currentSlot));
		}
	}

	[HarmonyPatch(typeof(Sleep), "FallAsleep")]
	private static class FallAsleep
	{
		[HarmonyPostfix]
		public static void Postfix(Sleep __instance)
		{
			GameEvents.OnSleep?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(Sleep), "WakeUp")]
	private static class WakeUp
	{
		[HarmonyPostfix]
		public static void Postfix(Sleep __instance)
		{
			GameEvents.OnWakeUp?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(Sleep), "EnterBed")]
	private static class EnterBed
	{
		[HarmonyPostfix]
		public static void Postfix(Sleep __instance)
		{
			GameEvents.OnBedEnter?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(Sleep), "LeaveBed")]
	private static class LeaveBed
	{
		[HarmonyPostfix]
		public static void Postfix(Sleep __instance)
		{
			GameEvents.OnBedLeave?.Invoke(__instance, new EventArgs());
		}
	}

	[HarmonyPatch(typeof(PlayerCrouching), "Update")]
	private static class PlayerInput
	{
		[HarmonyPostfix]
		public static void Postfix(PlayerCrouching __instance)
		{
			if (GameState.playing && !Utilities.GamePaused)
			{
				GameEvents.OnPlayerInput?.Invoke(__instance, new EventArgs());
			}
		}
	}

	public static event EventHandler OnGameStart;

	public static event GameQuitEventHandler OnGameQuit;

	public static event EventHandler OnGamePause;

	public static event EventHandler OnGameUnpause;

	public static event SaveSlotEventHandler OnSaveLoad;

	public static event SaveSlotEventHandler OnSaveLoadPost;

	public static event SaveSlotEventHandler OnNewGame;

	public static event GameSaveEventHandler OnGameSave;

	public static event EventHandler OnSleep;

	public static event EventHandler OnWakeUp;

	public static event EventHandler OnBedEnter;

	public static event EventHandler OnBedLeave;

	public static event EventHandler OnPlayerInput;

	public static event NewDay OnNewDay
	{
		add
		{
			Sun.OnNewDay += value;
		}
		remove
		{
			Sun.OnNewDay -= value;
		}
	}
}
public sealed class SaveSlotEventArgs
{
	public int SaveSlot { get; }

	public SaveSlotEventArgs(int saveSlot)
	{
		SaveSlot = saveSlot;
	}
}
public sealed class GameQuitEventArgs
{
	public bool QuitFromSave { get; }

	public GameQuitEventArgs(bool quitFromSave)
	{
		QuitFromSave = quitFromSave;
	}
}
[BepInPlugin("com.app24.sailwindmoddinghelper", "Sailwind Modding Helper", "2.0.3")]
public class SailwindModdingHelperMain : BaseUnityPlugin
{
	public const string GUID = "com.app24.sailwindmoddinghelper";

	public const string NAME = "Sailwind Modding Helper";

	public const string VERSION = "2.0.3";

	internal static ManualLogSource logSource;

	private void Awake()
	{
		logSource = ((BaseUnityPlugin)this).Logger;
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.app24.sailwindmoddinghelper");
		ModLoading.LoadMod();
	}
}
internal static class ModButton
{
	private static bool initialised;

	internal static void InitConsole()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		//IL_0022: 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)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: 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)
		if (!initialised)
		{
			GameObject val = new GameObject();
			GameCanvas.AddToCanvas(val);
			RectTransform obj = val.AddComponent<RectTransform>();
			val.AddComponent<Image>();
			((Transform)obj).localPosition = Vector3.zero;
			obj.sizeDelta = new Vector2(120f, 20f);
			GameObject val2 = new GameObject();
			val2.transform.SetParent(val.transform, false);
			Text obj2 = val2.AddComponent<Text>();
			obj2.text = "Test";
			obj2.fontSize = 32;
			((Graphic)obj2).color = Color.black;
			initialised = true;
		}
	}
}
internal static class ModLoading
{
	public static void LoadMod()
	{
		ModLogger.OnLog += delegate(LogLevel logLevel, PluginInfo mod, object message)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource val2 = Logger.CreateLogSource(mod.Metadata.Name);
			val2.Log(logLevel, message);
			Logger.Sources.Remove((ILogSource)(object)val2);
		};
		GameEvents.OnGameStart += delegate
		{
			Utilities.SetPlayerController(Refs.charController);
			Utilities.playerTransform = Sun.sun.GetPrivateField<Transform>("player");
		};
		GameEvents.OnGameStart += delegate
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			Object builtinResource = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf");
			GameAssets.ArealFont = (Font)(object)((builtinResource is Font) ? builtinResource : null);
			GameAssets.AlAnkhRegion = GameObject.Find("Region Al'ankh").GetComponent<Region>();
			GameAssets.EmeraldRegion = GameObject.Find("Region Emerald (new smaller)").GetComponent<Region>();
			GameAssets.LagoonRegion = GameObject.Find("Region Emerald Lagoon").GetComponent<Region>();
			GameAssets.MediRegion = GameObject.Find("Region Medi").GetComponent<Region>();
			GameAssets.MediEastRegion = GameObject.Find("Region Medi East").GetComponent<Region>();
			GameAssets.AlAnkhRegionData = new RegionData(new Vector3(-4.95f, 0f, 31.07f), new Vector3(1.1f, 0f, 0.94f));
			GameAssets.EmeraldRegionData = new RegionData(new Vector3(4.765f, 0f, 31.495f), new Vector3(1.37f, 0f, 1.31f));
			GameAssets.MediRegionData = new RegionData(new Vector3(0.72f, 0f, 40.395f), new Vector3(1.12f, 0f, 1.11f));
			GameAssets.OceanRegionData = new RegionData(new Vector3(0f, 0f, 36f), new Vector3(11.66f, 0f, 11.6f));
			GameAssets.StartMenu = Object.FindObjectOfType<StartMenu>();
			GameAssets.LoadPrefabs();
		};
		GameEvents.OnGameStart += delegate
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			GameObject privateField = GameAssets.StartMenu.GetPrivateField<GameObject>("settingsUI");
			if (Object.op_Implicit((Object)(object)privateField))
			{
				foreach (Transform item in privateField.transform)
				{
					Transform val = item;
					if (((Object)val).name == "button recover")
					{
						Transform childByName = val.GetChildByName("bg+trigger");
						UIManager.blueButtonMaterial = ((Renderer)((Component)childByName).GetComponent<MeshRenderer>()).sharedMaterial;
						UIManager.buttonMesh = ((Component)childByName).GetComponent<MeshFilter>().sharedMesh;
						GameAssets.ImmortalFont = ((Component)val.GetChildByName("text")).GetComponent<TextMesh>().font;
						UIManager.uiLayer = ((Component)val).gameObject.layer;
					}
					else if (((Object)val).name == "button back")
					{
						UIManager.whiteButtonMaterial = ((Renderer)((Component)val.GetChildByName("bg+trigger")).GetComponent<MeshRenderer>()).sharedMaterial;
					}
				}
			}
		};
		GameEvents.OnGamePause += delegate
		{
			Utilities.GamePaused = true;
		};
		GameEvents.OnGameUnpause += delegate
		{
			Utilities.GamePaused = false;
		};
		GameEvents.OnNewGame += delegate(object _, SaveSlotEventArgs e)
		{
			if (Directory.Exists(ModSave.GetSaveDirectory(e.SaveSlot)))
			{
				Directory.Delete(ModSave.GetSaveDirectory(e.SaveSlot), recursive: true);
			}
		};
		GameEvents.OnGameStart += delegate
		{
			GameCanvas.InitializeCanvas();
		};
	}
}
public static class ModLogger
{
	public delegate void LogEventHandler(LogLevel logType, PluginInfo pluginInfo, object message);

	public static event LogEventHandler OnLog;

	public static void Log(LogLevel logLevel, PluginInfo pluginInfo, object message)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		ModLogger.OnLog?.Invoke(logLevel, pluginInfo, message);
	}

	public static void LogFatal(PluginInfo pluginInfo, object data)
	{
		Log((LogLevel)1, pluginInfo, data);
	}

	public static void LogError(PluginInfo pluginInfo, object data)
	{
		Log((LogLevel)2, pluginInfo, data);
	}

	public static void LogWarning(PluginInfo pluginInfo, object data)
	{
		Log((LogLevel)4, pluginInfo, data);
	}

	public static void LogMessage(PluginInfo pluginInfo, object data)
	{
		Log((LogLevel)8, pluginInfo, data);
	}

	public static void LogInfo(PluginInfo pluginInfo, object data)
	{
		Log((LogLevel)16, pluginInfo, data);
	}

	public static void LogDebug(PluginInfo pluginInfo, object data)
	{
		Log((LogLevel)32, pluginInfo, data);
	}
}
public static class ModSave
{
	public static void Save(PluginInfo pluginInfo, object data)
	{
		if (GameState.playing)
		{
			Directory.CreateDirectory(GetSaveDirectory(SaveSlots.currentSlot));
			FileStream fileStream = File.Create(GetSaveModFile(SaveSlots.currentSlot, pluginInfo));
			BinaryFormatter binaryFormatter = new BinaryFormatter();
			try
			{
				binaryFormatter.Serialize(fileStream, data);
			}
			catch (Exception ex)
			{
				ModLogger.LogError(pluginInfo, "Could not serialize data '" + pluginInfo.Metadata.GUID + "'");
				ModLogger.LogError(pluginInfo, ex.Message);
			}
			fileStream.Close();
		}
	}

	public static bool Load(PluginInfo pluginInfo, out object loadedObject)
	{
		loadedObject = null;
		if (!GameState.playing && !GameState.currentlyLoading)
		{
			ModLogger.LogError(pluginInfo, "Trying to load mod save while in main menu '" + pluginInfo.Metadata.GUID + "'");
			return false;
		}
		if (!File.Exists(GetSaveModFile(SaveSlots.currentSlot, pluginInfo)))
		{
			ModLogger.LogError(pluginInfo, "Could not find mod save file for '" + pluginInfo.Metadata.GUID + "'");
			return false;
		}
		FileStream fileStream = File.OpenRead(GetSaveModFile(SaveSlots.currentSlot, pluginInfo));
		if (fileStream.Length <= 0)
		{
			fileStream.Close();
			ModLogger.LogError(pluginInfo, "File stream length is 0 '" + pluginInfo.Metadata.GUID + "'");
			return false;
		}
		try
		{
			object obj = new BinaryFormatter().Deserialize(fileStream);
			fileStream.Close();
			loadedObject = obj;
			return true;
		}
		catch (Exception ex)
		{
			fileStream.Close();
			ModLogger.LogError(pluginInfo, "Could not deserialize mod save for '" + pluginInfo.Metadata.GUID + "'");
			ModLogger.LogError(pluginInfo, ex.Message);
			return false;
		}
	}

	public static bool Load<T>(PluginInfo pluginInfo, out T loadedObject)
	{
		loadedObject = default(T);
		object loadedObject2;
		bool num = Load(pluginInfo, out loadedObject2);
		if (num)
		{
			loadedObject = (T)loadedObject2;
		}
		return num;
	}

	internal static string GetSaveModFile(int slot, PluginInfo pluginInfo)
	{
		return Path.Combine(GetSaveDirectory(slot), pluginInfo.Metadata.GUID + ".save");
	}

	public static string GetSaveDirectory(int slot)
	{
		return Path.Combine(Application.persistentDataPath, $"slot{slot}");
	}
}
public enum ButtonSize
{
	Normal,
	Small
}
public enum ButtonColor
{
	White,
	Blue
}
public static class UIManager
{
	internal static Material blueButtonMaterial;

	internal static Material whiteButtonMaterial;

	internal static Mesh buttonMesh;

	internal static int uiLayer;

	public static GameObject CreateButton<T>(Transform parent, string name, string text, int fontSize, Vector2 position, ButtonSize buttonSize, ButtonColor buttonColor) where T : GoPointerButton
	{
		//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_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		Vector3 one = Vector3.one;
		switch (buttonSize)
		{
		case ButtonSize.Normal:
			((Vector3)(ref one))..ctor(0.8106962f, 0.3124738f, 0.8656517f);
			break;
		case ButtonSize.Small:
			((Vector3)(ref one))..ctor(0.4137929f, 0.2343553f, 0.6492388f);
			break;
		}
		Material buttonMaterial = whiteButtonMaterial;
		switch (buttonColor)
		{
		case ButtonColor.White:
			buttonMaterial = whiteButtonMaterial;
			break;
		case ButtonColor.Blue:
			buttonMaterial = blueButtonMaterial;
			break;
		}
		return CreateButton<T>(parent, name, text, fontSize, position, one, buttonMaterial);
	}

	public static GameObject CreateButton<T>(Transform parent, string name, string text, int fontSize, Vector2 position, Vector3 buttonSize, ButtonColor buttonColor) where T : GoPointerButton
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		Material buttonMaterial = whiteButtonMaterial;
		switch (buttonColor)
		{
		case ButtonColor.White:
			buttonMaterial = whiteButtonMaterial;
			break;
		case ButtonColor.Blue:
			buttonMaterial = blueButtonMaterial;
			break;
		}
		return CreateButton<T>(parent, name, text, fontSize, position, buttonSize, buttonMaterial);
	}

	public static GameObject CreateButton<T>(Transform parent, string name, string text, int fontSize, Vector2 position, ButtonSize buttonSize, Material buttonMaterial) where T : GoPointerButton
	{
		//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_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		Vector3 one = Vector3.one;
		switch (buttonSize)
		{
		case ButtonSize.Normal:
			((Vector3)(ref one))..ctor(0.8106962f, 0.3124738f, 0.8656517f);
			break;
		case ButtonSize.Small:
			((Vector3)(ref one))..ctor(0.4137929f, 0.2343553f, 0.6492388f);
			break;
		}
		return CreateButton<T>(parent, name, text, fontSize, position, one, buttonMaterial);
	}

	public static GameObject CreateButton<T>(Transform parent, string name, string text, int fontSize, Vector2 position, Vector3 buttonSize, Material buttonMaterial) where T : GoPointerButton
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: 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)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: 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)
		//IL_0182: 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_01a1: 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)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject();
		((Object)val).name = name;
		val.layer = uiLayer;
		val.transform.parent = parent;
		val.transform.localPosition = new Vector3(position.x, position.y, 0.038f);
		val.transform.localRotation = Quaternion.identity;
		val.transform.localScale = Vector3.one;
		GameObject val2 = new GameObject
		{
			name = "bg+trigger",
			layer = uiLayer
		};
		val2.transform.parent = val.transform;
		val2.transform.localPosition = new Vector3(0f, 0.02250695f, 0f);
		val2.transform.localRotation = Quaternion.Euler(-180f, 0f, 180f);
		val2.transform.localScale = buttonSize;
		val2.AddComponent<MeshFilter>().sharedMesh = buttonMesh;
		((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = buttonMaterial;
		BoxCollider obj = val2.AddComponent<BoxCollider>();
		((Collider)obj).isTrigger = true;
		obj.center = new Vector3(0f, 0f, -0.00390625f);
		obj.size = new Vector3(1f, 1f, 5.960464E-08f);
		val2.AddComponent<T>();
		GameObject val3 = new GameObject
		{
			name = "text",
			layer = uiLayer
		};
		val3.transform.parent = val.transform;
		val3.transform.localPosition = new Vector3(0f, 0.02250695f, 0.004f);
		val3.transform.localRotation = Quaternion.Euler(-180f, 0f, 180f);
		val3.transform.localScale = new Vector3(0.01731304f, 0.01731303f, 0.01731304f);
		TextMesh obj2 = val3.AddComponent<TextMesh>();
		obj2.font = GameAssets.ImmortalFont;
		obj2.text = text;
		obj2.alignment = (TextAlignment)1;
		obj2.anchor = (TextAnchor)4;
		obj2.fontSize = fontSize;
		obj2.richText = true;
		obj2.fontStyle = (FontStyle)1;
		obj2.color = Color.black;
		return val;
	}
}
public static class Utilities
{
	private static CharacterController characterController;

	internal static Transform playerTransform;

	public static CharacterController CharacterController => characterController;

	public static Transform PlayerTransform => playerTransform;

	public static bool GamePaused { get; internal set; }

	internal static void SetPlayerController(CharacterController characterController)
	{
		Utilities.characterController = characterController;
	}

	public static IslandSceneryScene GetNearestIslandSceneryScene(Vector3 position)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		float num = float.MaxValue;
		IslandSceneryScene result = null;
		IslandSceneryScene[] array = Object.FindObjectsOfType<IslandSceneryScene>();
		foreach (IslandSceneryScene val in array)
		{
			float num2 = Vector3.Distance(((Component)val).transform.position, position);
			if (num2 < num)
			{
				num = num2;
				result = val;
			}
		}
		return result;
	}

	public static Vector3 GetPlayerGlobeCoords()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		return FloatingOriginManager.instance.GetGlobeCoords(playerTransform);
	}

	public static Vector3 GetGlobeCoords(Vector3 position)
	{
		//IL_0000: 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_000b: 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)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		return (position - FloatingOriginManager.instance.outCurrentOffset - FloatingOriginManager.instance.GetPrivateField<Vector3>("globeOffset")) / 9000f;
	}

	public static T Next<T>(this T src) where T : Enum
	{
		if (!typeof(T).IsEnum)
		{
			throw new ArgumentException($"Argument {typeof(T).FullName} is not an Enum");
		}
		T[] array = (T[])Enum.GetValues(src.GetType());
		int num = Array.IndexOf(array, src) + 1;
		if (array.Length != num)
		{
			return array[num];
		}
		return array[0];
	}
}