Decompiled source of OverworkedUI v1.1.2

OverworkedUI.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OverworkedUI.Core;
using OverworkedUI.Core.Modules.Data;
using OverworkedUI.Core.Modules.Host;
using OverworkedUI.Core.Patches;
using OverworkedUi;
using Steamworks;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OverworkedUI")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("OverworkedUI")]
[assembly: AssemblyTitle("OverworkedUI")]
[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.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;
		}
	}
}
public class OwButton : Selectable, IPointerClickHandler, IEventSystemHandler
{
	public UnityEvent<bool> onClick = new UnityEvent<bool>();

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Invalid comparison between Unknown and I4
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		bool flag = (int)eventData.button == 0;
		if ((int)eventData.button == 0 || (int)eventData.button == 1)
		{
			onClick.Invoke(flag);
		}
	}
}
public class OwHostHandler : MonoBehaviour
{
	public GameObject Title;

	public GameObject LobbyName;

	public GameObject Confirm;

	public GameObject Back;

	public GameObject Saves;

	public GameObject Config;

	public GameObject SavesHolder;

	public GameObject ConfigHolder;

	public GameObject Public;

	public GameObject Private;

	public GameObject OwUi;

	public GameObject SelectSaveButtonPrefab;

	public GameObject ConfigHolderPrefab;

	public GameObject ConfigTextPrefab;

	public GameObject ConfigButtonPrefab;

	public int creditsAmount = 60;

	private int _saveCount = 0;

	private Dictionary<string, ConfigCategory> TerminalConfig = new Dictionary<string, ConfigCategory>();

	public int SelectedSaveFileIndex { get; private set; } = -1;


	public bool IsNewSave { get; private set; } = false;


	public bool IsModded { get; private set; } = true;


	public bool IsPublic { get; private set; } = true;


	public void SetOwUiRoast(string roast)
	{
		((TMP_Text)OwUi.GetComponent<TextMeshProUGUI>()).text = roast;
	}

	public void UpdateVisibility(bool isLobbyPublic)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//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_0031: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		Image component = Public.GetComponent<Image>();
		Image component2 = Private.GetComponent<Image>();
		if (isLobbyPublic)
		{
			((Graphic)component).color = Color32.op_Implicit(new Color32((byte)253, (byte)148, (byte)69, byte.MaxValue));
			((Graphic)component2).color = Color32.op_Implicit(new Color32((byte)118, (byte)47, (byte)47, byte.MaxValue));
		}
		else
		{
			((Graphic)component2).color = Color32.op_Implicit(new Color32((byte)253, (byte)148, (byte)69, byte.MaxValue));
			((Graphic)component).color = Color32.op_Implicit(new Color32((byte)118, (byte)47, (byte)47, byte.MaxValue));
		}
		IsPublic = isLobbyPublic;
	}

	public void InitializeVisibility(Action<bool> callback)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		((UnityEvent)Public.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			UpdateVisibility(isLobbyPublic: true);
			callback?.Invoke(obj: true);
		});
		((UnityEvent)Private.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			UpdateVisibility(isLobbyPublic: false);
			callback?.Invoke(obj: false);
		});
	}

	public void InitializeNewSave()
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		GameObject NewSaveButton = ((Component)SavesHolder.transform.Find("OW_CreateSave")).gameObject;
		Button componentInChildren = NewSaveButton.GetComponentInChildren<Button>();
		Hide();
		HideTerminalConfig();
		TMP_InputField textBox = LobbyName.GetComponent<TMP_InputField>();
		((UnityEvent)componentInChildren.onClick).AddListener((UnityAction)delegate
		{
			ShowTerminalConfig();
			HighlightSaveButton(((Component)NewSaveButton.transform.Find("Button")).gameObject);
			SelectedSaveFileIndex = _saveCount + 1;
			IsNewSave = true;
			((UnityEventBase)textBox.onSubmit).RemoveAllListeners();
		});
	}

	public void CreateSaveFile(int index, string filepath, string filename, Action deleteCallback, Action<string> renameCallback)
	{
		//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_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Expected O, but got Unknown
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		GameObject saveButton = Object.Instantiate<GameObject>(SelectSaveButtonPrefab, Vector3.zero, Quaternion.identity);
		saveButton.transform.SetParent(SavesHolder.transform, false);
		GameObject selectButton = ((Component)saveButton.transform.Find("Button")).gameObject;
		GameObject gameObject = ((Component)saveButton.transform.Find("Delete")).gameObject;
		((TMP_Text)selectButton.GetComponentInChildren<TextMeshProUGUI>()).text = filename;
		TMP_InputField textBox = LobbyName.GetComponent<TMP_InputField>();
		((UnityEvent)selectButton.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			HighlightSaveButton(selectButton);
			SetLobbyName(filename);
			HideTerminalConfig();
			SelectedSaveFileIndex = index;
			IsNewSave = false;
			((UnityEventBase)textBox.onSubmit).RemoveAllListeners();
			((UnityEvent<string>)(object)textBox.onSubmit).AddListener((UnityAction<string>)delegate(string text)
			{
				filename = text;
				((TMP_Text)selectButton.GetComponentInChildren<TextMeshProUGUI>()).text = text;
				renameCallback?.Invoke(text);
			});
		});
		((UnityEvent)gameObject.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			Object.Destroy((Object)(object)saveButton);
			deleteCallback?.Invoke();
		});
		_saveCount++;
	}

	public void ClearSaves()
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		HighlightSaveButton(null);
		SelectedSaveFileIndex = -1;
		_saveCount = 0;
		foreach (Transform item in SavesHolder.transform)
		{
			Transform val = item;
			if (((Object)val).name != "OW_CreateSave")
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}
	}

	public void HighlightSaveButton(GameObject? target)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		//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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		foreach (Transform item in SavesHolder.transform)
		{
			Transform val = item;
			if (((Object)val).name != "OW_CreateSave")
			{
				((Graphic)((Component)val.Find("Button")).GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)118, (byte)47, (byte)76, (byte)100));
			}
			else
			{
				((Graphic)((Component)val.Find("Button")).GetComponent<Image>()).color = Color32.op_Implicit(new Color32((byte)118, (byte)47, (byte)47, (byte)100));
			}
		}
		if ((Object)(object)target != (Object)null)
		{
			((Graphic)target.GetComponentInChildren<Image>()).color = Color32.op_Implicit(new Color32((byte)238, (byte)115, (byte)86, (byte)100));
			((Graphic)Confirm.GetComponentInChildren<TextMeshProUGUI>()).color = Color32.op_Implicit(new Color32((byte)252, (byte)180, (byte)103, byte.MaxValue));
		}
		else
		{
			((Graphic)Confirm.GetComponentInChildren<TextMeshProUGUI>()).color = Color32.op_Implicit(new Color32((byte)222, (byte)49, (byte)5, byte.MaxValue));
		}
	}

	public void SetLobbyName(string name)
	{
		LobbyName.GetComponent<TMP_InputField>().text = name;
	}

	public string GetLobbyName()
	{
		return LobbyName.GetComponent<TMP_InputField>().text;
	}

	public void Show()
	{
		((Component)((Component)this).gameObject.transform.parent).gameObject.SetActive(true);
	}

	public void Hide()
	{
		((Component)((Component)this).gameObject.transform.parent).gameObject.SetActive(false);
	}

	public void BindContext(Action CloseRequest, Action ConfirmRequest)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		((UnityEvent)Back.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			CloseRequest();
		});
		((UnityEvent)Confirm.GetComponent<Button>().onClick).AddListener((UnityAction)delegate
		{
			ConfirmRequest();
		});
	}

	public void ShowTerminalConfig()
	{
		//IL_0016: 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_003b: Unknown result type (might be due to invalid IL or missing references)
		Saves.GetComponent<RectTransform>().sizeDelta = new Vector2(813.2242f, 670.676f);
		Saves.GetComponent<RectTransform>().anchoredPosition = Vector2.op_Implicit(new Vector3(-491.1299f, -56.33801f));
		Config.SetActive(true);
	}

	public void HideTerminalConfig()
	{
		//IL_0016: 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_003b: Unknown result type (might be due to invalid IL or missing references)
		Saves.GetComponent<RectTransform>().sizeDelta = new Vector2(1772.9f, 670.676f);
		Saves.GetComponent<RectTransform>().anchoredPosition = Vector2.op_Implicit(new Vector3(-11.323f, -56.33801f));
		Config.SetActive(false);
	}

	public void BuildCategory(ConfigCategory newCategory)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		foreach (Transform item in newCategory.TargetObject.transform)
		{
			Transform val = item;
			Object.Destroy((Object)(object)((Component)val).gameObject);
		}
		foreach (ConfigElement element in newCategory.Elements)
		{
			GameObject uiElement = element.GetUiElement(this, newCategory);
			if ((Object)(object)uiElement != (Object)null)
			{
				uiElement.transform.SetParent(newCategory.TargetObject.transform, false);
			}
		}
	}

	public void AddTerminalCategory(string name, ConfigCategory newCategory)
	{
		GameObject val = Object.Instantiate<GameObject>(ConfigHolderPrefab);
		val.transform.SetParent(ConfigHolder.transform, false);
		newCategory.TargetObject = val;
		BuildCategory(newCategory);
		TerminalConfig[name] = newCategory;
	}

	public ConfigCategory? GetTerminalCategory(string name)
	{
		return TerminalConfig[name];
	}

	public void UpdateCredits()
	{
		TextMeshProUGUI component = ((Component)Config.transform.Find("Panel/Credits")).GetComponent<TextMeshProUGUI>();
		((TMP_Text)component).text = $"▪{creditsAmount}";
	}

	public void InitializeTerminal()
	{
		ConfigCategory configCategory = new ConfigCategory();
		configCategory.AddElement(new TextConfigElement(("id", "hint0"), ("text", ">Terminal"))).AddElement(new TextConfigElement(("id", "hint1"), ("text", "Left-click to interact with a node."))).AddElement(new TextConfigElement(("id", "hint2"), ("text", "Right-click to cancel the interaction.")))
			.AddElement(new SpacingConfigElement());
		AddTerminalCategory("Hint", configCategory);
	}
}
namespace OverworkedUi
{
	[BepInPlugin("dev.timmywastor.overworkedUI", "OverworkedUI", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "dev.timmywastor.overworkedUI";

		public const string ModName = "OverworkedUI";

		public const string ModVersion = "1.0.0";

		public static Harmony Harmony = new Harmony("dev.timmywastor.overworkedUI");

		public static ManualLogSource OverworkedLogger;

		public static string PluginFolder;

		private void Awake()
		{
			string location = ((BaseUnityPlugin)this).Info.Location;
			PluginFolder = Path.GetDirectoryName(location);
			OverworkedLogger = ((BaseUnityPlugin)this).Logger;
			OverworkedCore.InitialPatches();
		}
	}
}
namespace OverworkedUI
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "OverworkedUI";

		public const string PLUGIN_NAME = "OverworkedUI";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace OverworkedUI.Core
{
	internal class OverworkedCore
	{
		public const string BundleName = "ow_assets";

		public const string NameProperty = "OW_Name";

		public const string BetterSaveProperty = "Alias_BetterSaves";

		public const string LcGeneral = "LCGeneralSaveData";

		public const string LcSaveFile = "LCSaveFile";

		public const string VisibilityProperty = "OW_Vis";

		public static readonly Vector3 PurchasePosition = new Vector3(1.2093f, 0.0084f, -6.7502f);

		public static OverworkedSaveConfig SaveConfig;

		private static bool _alreadyPatched = false;

		private static bool _bundleLoaded = false;

		private static AssetBundle _bundle;

		public static int Version { get; private set; } = -1;


		public static void SetVersion(int version)
		{
			if (Version < 0)
			{
				Version = version;
			}
		}

		public static void InitialPatches()
		{
			Plugin.OverworkedLogger.LogInfo((object)"OverworkedCore: Loading initial patches");
			Plugin.Harmony.PatchAll(typeof(V0Patches.MenuManagerPatches));
		}

		public static void PatchAll()
		{
			if (!_alreadyPatched)
			{
				_alreadyPatched = true;
				Plugin.OverworkedLogger.LogInfo((object)"OverworkedCore: Loading late patches");
				Plugin.Harmony.PatchAll(typeof(V0Patches.GameNetworkManagerPatches));
				Plugin.Harmony.PatchAll(typeof(V0Patches.StartOfRoundPatch));
				Plugin.Harmony.PatchAll(typeof(V0Patches.TerminalPatch));
				if (Version >= 80)
				{
					Plugin.Harmony.PatchAll(typeof(V80Patches.StartOfRoundPatch));
				}
			}
		}

		public static void LoadSavesFor(OwHostHandler handler)
		{
			handler.ClearSaves();
			string[] array = (from f in ES3.GetFiles()
				where ES3.FileExists(f) && Regex.IsMatch(f, "^LCSaveFile\\d+$")
				select f).OrderBy(delegate(string f)
			{
				string s = new string(f.Where(char.IsDigit).ToArray());
				int result;
				return int.TryParse(s, out result) ? result : int.MaxValue;
			}).ToArray();
			int num = 1;
			string[] array2 = array;
			foreach (string text in array2)
			{
				string newFileName = string.Format("{0}{1}", "LCSaveFile", num);
				if (text != newFileName)
				{
					ES3.RenameFile(text, newFileName);
				}
				string text2 = ES3.Load<string>("OW_Name", newFileName, "");
				string text3 = ES3.Load<string>("Alias_BetterSaves", newFileName, "");
				string filename = ((!string.IsNullOrEmpty(text2)) ? text2 : ((!string.IsNullOrEmpty(text3)) ? text3 : "Unnamed save file"));
				handler.CreateSaveFile(num, newFileName, filename, delegate
				{
					DeleteSave(newFileName);
					LoadSavesFor(handler);
				}, delegate(string name)
				{
					RenameSave(newFileName, name);
				});
				num++;
			}
		}

		private static void DeleteSave(string file)
		{
			if (ES3.FileExists(file) && Regex.IsMatch(file, "^LCSaveFile\\d+$"))
			{
				ES3.DeleteFile(file);
			}
		}

		public static void RenameSave(string path, string name)
		{
			ES3.Save<string>("OW_Name", name, path);
		}

		public static AssetBundle LoadBundle()
		{
			if (!_bundleLoaded)
			{
				_bundle = AssetBundle.LoadFromFile(Plugin.PluginFolder + "/Assets/ow_assets");
				if ((Object)(object)_bundle != (Object)null)
				{
					_bundleLoaded = true;
				}
			}
			return _bundle;
		}

		public static void RebuildRefs(Component target, Dictionary<string, (GameObject root, string path)> lookUp, Dictionary<string, GameObject> prefabs)
		{
			Type type = ((object)target).GetType();
			if (prefabs != null)
			{
				foreach (KeyValuePair<string, GameObject> prefab in prefabs)
				{
					string key = prefab.Key;
					GameObject value = prefab.Value;
					FieldInfo field = type.GetField(key, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field == null)
					{
						Debug.LogWarning((object)("Field '" + key + "' not found on " + type.Name));
					}
					else
					{
						field.SetValue(target, value);
					}
				}
			}
			foreach (KeyValuePair<string, (GameObject, string)> item3 in lookUp)
			{
				string key2 = item3.Key;
				GameObject item = item3.Value.Item1;
				string item2 = item3.Value.Item2;
				FieldInfo field2 = type.GetField(key2, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field2 == null)
				{
					Debug.LogWarning((object)("Field '" + key2 + "' not found on " + type.Name));
					continue;
				}
				Transform val = item.transform.Find(item2);
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogWarning((object)("Path '" + item2 + "' not found under '" + ((Object)item).name + "'"));
				}
				else
				{
					field2.SetValue(target, ((Component)val).gameObject);
				}
			}
		}

		public static void TrySetDefaultPlanet(StartOfRound s, string p)
		{
			for (int i = 0; i < s.levels.Length; i++)
			{
				SelectableLevel val = s.levels[i];
				if (val.PlanetName == p)
				{
					s.defaultPlanet = i;
					break;
				}
			}
		}

		public static void InstantiatePurchases(StartOfRound s, Dictionary<string, int> d)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			foreach (Item items in s.allItemsList.itemsList)
			{
				if (d.ContainsKey(items.itemName))
				{
					Plugin.OverworkedLogger.LogInfo((object)items.itemName);
					for (int i = 0; i < d[items.itemName]; i++)
					{
						GrabbableObject component = Object.Instantiate<GameObject>(items.spawnPrefab, Vector3.zero, Quaternion.identity, s.elevatorTransform).GetComponent<GrabbableObject>();
						((Component)component).gameObject.transform.localPosition = PurchasePosition;
						component.fallTime = 0f;
						component.scrapPersistedThroughRounds = true;
						component.isInElevator = true;
						component.isInShipRoom = true;
						((NetworkBehaviour)component).NetworkObject.Spawn(false);
					}
				}
			}
		}

		public static void AttemptUpdateCredits(Terminal t, int c)
		{
			t.groupCredits = c;
			t.startingCreditsAmount = c;
		}
	}
	internal class OverworkedSaveConfig
	{
		public string SaveFileName = "Unnamed";

		public int StartCredits = -1;

		public string DefaultPlanet = "56 Vow";

		public Dictionary<string, int> InitialPurchases = new Dictionary<string, int>();

		public bool IsPublic = true;

		public int Seed = -1;

		public bool IsNewSave = false;
	}
}
namespace OverworkedUI.Core.Patches
{
	internal class References
	{
		public static MenuManager CurrentMenuManager;
	}
	internal class V0Patches
	{
		[HarmonyPatch(typeof(MenuManager))]
		internal class MenuManagerPatches
		{
			[HarmonyPatch("Awake")]
			[HarmonyPostfix]
			private static void Awake_PostFix(MenuManager __instance)
			{
				if (!__instance.isInitScene)
				{
					References.CurrentMenuManager = __instance;
					OverworkedCore.SetVersion(GameNetworkManager.Instance.gameVersionNum);
					OverworkedCore.PatchAll();
					OverworkedHostHandler.LoadHostModule();
				}
			}

			[HarmonyPatch("ClickHostButton")]
			[HarmonyPostfix]
			private static void ClickHostButton_PostFix(MenuManager __instance)
			{
				__instance.HostSettingsScreen.SetActive(false);
			}
		}

		[HarmonyPatch(typeof(GameNetworkManager))]
		internal class GameNetworkManagerPatches
		{
			[HarmonyPatch("SaveGame")]
			[HarmonyPostfix]
			private static void SaveGame_PostFix(GameNetworkManager __instance)
			{
				if (OverworkedCore.SaveConfig.IsNewSave)
				{
					OverworkedCore.RenameSave(__instance.currentSaveFileName, OverworkedCore.SaveConfig.SaveFileName);
				}
			}
		}

		[HarmonyPatch(typeof(StartOfRound))]
		internal class StartOfRoundPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPrefix]
			private static void Start_PreFix(StartOfRound __instance)
			{
				if (OverworkedCore.SaveConfig.IsNewSave)
				{
					OverworkedCore.TrySetDefaultPlanet(__instance, OverworkedCore.SaveConfig.DefaultPlanet);
				}
			}

			[HarmonyPatch("LoadShipGrabbableItems")]
			[HarmonyPrefix]
			private static void LoadShipGrabbableItems_PreFix(StartOfRound __instance)
			{
				if (OverworkedCore.SaveConfig.IsNewSave)
				{
					OverworkedCore.InstantiatePurchases(__instance, OverworkedCore.SaveConfig.InitialPurchases);
				}
			}
		}

		[HarmonyPatch(typeof(Terminal))]
		internal class TerminalPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPostfix]
			private static void Awake_PostFix(Terminal __instance)
			{
				if (OverworkedCore.SaveConfig.IsNewSave)
				{
					OverworkedCore.AttemptUpdateCredits(__instance, OverworkedCore.SaveConfig.StartCredits);
				}
			}
		}
	}
	internal class V80Patches
	{
		[HarmonyPatch(typeof(StartOfRound))]
		internal class StartOfRoundPatch
		{
			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

				private IEnumerable<CodeInstruction> instructions;

				public IEnumerable<CodeInstruction> <>3__instructions;

				private MethodInfo <target>5__1;

				private MethodInfo <replacement>5__2;

				private IEnumerator<CodeInstruction> <>s__3;

				private CodeInstruction <instr>5__4;

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

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

				[DebuggerHidden]
				public <Transpiler>d__0(int <>1__state)
				{
					this.<>1__state = <>1__state;
					<>l__initialThreadId = Environment.CurrentManagedThreadId;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					int num = <>1__state;
					if (num == -3 || (uint)(num - 1) <= 1u)
					{
						try
						{
						}
						finally
						{
							<>m__Finally1();
						}
					}
					<target>5__1 = null;
					<replacement>5__2 = null;
					<>s__3 = null;
					<instr>5__4 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0104: Unknown result type (might be due to invalid IL or missing references)
					//IL_010e: Expected O, but got Unknown
					try
					{
						switch (<>1__state)
						{
						default:
							return false;
						case 0:
							<>1__state = -1;
							<target>5__1 = AccessTools.Method(typeof(Random), "Range", new Type[2]
							{
								typeof(int),
								typeof(int)
							}, (Type[])null);
							<replacement>5__2 = AccessTools.Method(typeof(StartOfRoundPatch), "GetSeed", (Type[])null, (Type[])null);
							<>s__3 = instructions.GetEnumerator();
							<>1__state = -3;
							break;
						case 1:
							<>1__state = -3;
							goto IL_0145;
						case 2:
							{
								<>1__state = -3;
								goto IL_0145;
							}
							IL_0145:
							<instr>5__4 = null;
							break;
						}
						if (<>s__3.MoveNext())
						{
							<instr>5__4 = <>s__3.Current;
							if (<instr>5__4.opcode == OpCodes.Call && <instr>5__4.operand as MethodInfo == <target>5__1)
							{
								<>2__current = new CodeInstruction(OpCodes.Call, (object)<replacement>5__2);
								<>1__state = 1;
								return true;
							}
							<>2__current = <instr>5__4;
							<>1__state = 2;
							return true;
						}
						<>m__Finally1();
						<>s__3 = null;
						return false;
					}
					catch
					{
						//try-fault
						((IDisposable)this).Dispose();
						throw;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				private void <>m__Finally1()
				{
					<>1__state = -1;
					if (<>s__3 != null)
					{
						<>s__3.Dispose();
					}
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}

				[DebuggerHidden]
				IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
				{
					<Transpiler>d__0 <Transpiler>d__;
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						<Transpiler>d__ = this;
					}
					else
					{
						<Transpiler>d__ = new <Transpiler>d__0(0);
					}
					<Transpiler>d__.instructions = <>3__instructions;
					return <Transpiler>d__;
				}

				[DebuggerHidden]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
				}
			}

			[IteratorStateMachine(typeof(<Transpiler>d__0))]
			[HarmonyPatch("SetTimeAndPlanetToSavedSettings")]
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <Transpiler>d__0(-2)
				{
					<>3__instructions = instructions
				};
			}

			public static int GetSeed(int min, int max)
			{
				if (OverworkedCore.SaveConfig.Seed != -1)
				{
					return OverworkedCore.SaveConfig.Seed;
				}
				return Random.Range(min, max);
			}
		}
	}
}
namespace OverworkedUI.Core.Modules.Host
{
	internal class OverworkedHostHandler
	{
		private static void CreateMoonCategoryFor(OwHostHandler currentHandler)
		{
			ConfigCategory configCategory = new ConfigCategory();
			configCategory.AddElement(new TextConfigElement(("id", "title"), ("text", ">Default Moon")));
			Action<ConfigElementActor, bool> callback = delegate(ConfigElementActor a, bool i)
			{
				a.SetHighlighted();
				a.Rebuild();
			};
			int num = 0;
			foreach (string key in VanillaData.DefaultMoons.Keys)
			{
				if (!VanillaData.DefaultMoons[key].IsPaid)
				{
					ButtonConfigElement buttonConfigElement = new ButtonConfigElement(callback, ("id", key), ("text", "* " + key));
					if (num == 0)
					{
						buttonConfigElement.Set("highlighted", true);
					}
					configCategory.AddElement(buttonConfigElement);
					num++;
				}
			}
			configCategory.AddElement(new SpacingConfigElement());
			currentHandler.AddTerminalCategory("DefaultMoon", configCategory);
		}

		private static void UpdateBuyableElement(ConfigElement e)
		{
			string text = e.Get<string>("id");
			int num = e.Get<int>("price");
			int num2 = e.Get<int>("bought");
			int num3 = e.Get<int>("currentSale");
			string text2 = e.Get<string>("type");
			int num4 = num - num * num3 / 100;
			string text3 = text2;
			string text4 = text3;
			if (!(text4 == "item"))
			{
				if (text4 == "vehicle")
				{
					e.Set("text", string.Format("* {0} // Price: ■{1} {2}", text, num4, (num3 > 0) ? $"({num3}% off)" : ""));
				}
			}
			else
			{
				e.Set("text", string.Format("* x{0} // {1} // Price: ■{2} {3}", num2, text, num4, (num3 > 0) ? $"({num3}% off)" : ""));
			}
		}

		private static void CreateShopCategoryFor(OwHostHandler currentHandler)
		{
			ConfigCategory configCategory = new ConfigCategory();
			configCategory.AddElement(new TextConfigElement(("id", "title"), ("text", ">Shop")));
			Action<ConfigElementActor, bool> callback = delegate(ConfigElementActor a, bool i)
			{
				string text = a.TargetElement.Get<string>("id");
				int num = a.TargetElement.Get<int>("price");
				int num2 = a.TargetElement.Get<int>("bought");
				int num3 = a.TargetElement.Get<int>("currentSale");
				int num4 = num - num * num3 / 100;
				if (i)
				{
					if (currentHandler.creditsAmount - num4 >= 0)
					{
						currentHandler.creditsAmount -= num4;
						a.TargetElement.Set("bought", num2 + 1);
					}
				}
				else if (num2 > 0)
				{
					currentHandler.creditsAmount += num4;
					a.TargetElement.Set("bought", num2 - 1);
				}
				UpdateBuyableElement(a.TargetElement);
				currentHandler.UpdateCredits();
				a.Blink();
				a.Rebuild();
			};
			Item[] array = Resources.FindObjectsOfTypeAll<Item>();
			Item[] array2 = array;
			foreach (Item val in array2)
			{
				bool flag = val.creditsWorth > 5 && val.creditsWorth <= currentHandler.creditsAmount && val.minValue == 0;
				configCategory.AddElement(new ButtonConfigElement(callback, ("id", val.itemName), ("text", $"* x0 // {val.itemName} // Price: ■{val.creditsWorth}"), ("hidden", !flag), ("price", val.creditsWorth), ("bought", 0), ("highestSalePercentage", val.highestSalePercentage), ("currentSale", 0), ("type", "item")));
			}
			if (OverworkedCore.Version >= 80)
			{
				configCategory.AddElement(new SpacingConfigElement());
				foreach (KeyValuePair<string, int> vehicles in VanillaData.VehiclesList)
				{
					configCategory.AddElement(new ButtonConfigElement(delegate
					{
					}, ("id", vehicles.Key), ("text", $"* {vehicles.Key} // Price: ■{vehicles.Value}"), ("price", vehicles.Value), ("bought", 0), ("highestSalePercentage", 80), ("currentSale", 0), ("type", "vehicle")));
				}
			}
			configCategory.AddElement(new SpacingConfigElement());
			currentHandler.AddTerminalCategory("Shop", configCategory);
		}

		private static bool StartHosting(string lobbyName, bool isPublic, int saveFileIndex)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			if (!string.IsNullOrEmpty(lobbyName) && saveFileIndex > 0)
			{
				GameNetworkManager instance = GameNetworkManager.Instance;
				instance.currentSaveFileName = string.Format("{0}{1}", "LCSaveFile", saveFileIndex);
				instance.saveFileNum = saveFileIndex;
				instance.lobbyHostSettings = new HostSettings(lobbyName, isPublic, "");
				instance.StartHost();
				return true;
			}
			return false;
		}

		private static void BuildConfigFromHandler(OwHostHandler handler)
		{
			OverworkedCore.SaveConfig.SaveFileName = handler.GetLobbyName();
			OverworkedCore.SaveConfig.StartCredits = handler.creditsAmount;
			OverworkedCore.SaveConfig.IsNewSave = handler.IsNewSave;
			ConfigCategory terminalCategory = handler.GetTerminalCategory("DefaultMoon");
			ConfigElement highlightedElement = terminalCategory.GetHighlightedElement();
			OverworkedCore.SaveConfig.DefaultPlanet = highlightedElement.Get<string>("id");
			ConfigCategory terminalCategory2 = handler.GetTerminalCategory("Shop");
			foreach (ConfigElement element in terminalCategory2.Elements)
			{
				int num = element.Get<int>("bought");
				string key = element.Get<string>("id");
				if (num > 0)
				{
					OverworkedCore.SaveConfig.InitialPurchases[key] = num;
				}
			}
			if (OverworkedCore.Version >= 80)
			{
				ConfigCategory terminalCategory3 = handler.GetTerminalCategory("Seed");
				int seed = terminalCategory3.GetElementFromId("reroll").Get<int>("currentSeed");
				OverworkedCore.SaveConfig.Seed = seed;
			}
		}

		private static void BuildPreConfigFromHandler(OwHostHandler handler)
		{
			OverworkedCore.SaveConfig.IsPublic = handler.IsPublic;
		}

		private static void HandleUiFor(OwHostHandler handler)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			Button component = GameObject.Find("Canvas/MenuContainer/MainButtons/HostButton").GetComponent<Button>();
			((UnityEvent)component.onClick).AddListener((UnityAction)delegate
			{
				handler.Show();
				OverworkedCore.LoadSavesFor(handler);
			});
			if (SteamClient.IsValid && SteamClient.IsLoggedOn)
			{
				handler.SetLobbyName(SteamClient.Name + "'s Lobby");
			}
			else
			{
				handler.SetLobbyName("My Lobby");
			}
			bool isLobbyPublic = ES3.Load<bool>("OW_Vis", "LCGeneralSaveData", true);
			handler.UpdateVisibility(isLobbyPublic);
			handler.InitializeVisibility(delegate(bool isPublic)
			{
				ES3.Save<bool>("OW_Vis", isPublic, "LCGeneralSaveData");
			});
			handler.InitializeTerminal();
			handler.InitializeNewSave();
			handler.HighlightSaveButton(null);
			handler.BindContext(delegate
			{
				handler.HideTerminalConfig();
				handler.HighlightSaveButton(null);
				handler.Hide();
			}, delegate
			{
				BuildPreConfigFromHandler(handler);
				if (StartHosting(handler.GetLobbyName(), handler.IsPublic, handler.SelectedSaveFileIndex))
				{
					handler.Hide();
					BuildConfigFromHandler(handler);
				}
			});
		}

		private static void SetRoastFor(OwHostHandler handler)
		{
			if (OverworkedCore.Version < 60)
			{
				handler.SetOwUiRoast("Baby mode");
			}
			else
			{
				handler.SetOwUiRoast("Goated version");
			}
		}

		private static void ClearWeathers(OwHostHandler currentHandler)
		{
			ConfigCategory terminalCategory = currentHandler.GetTerminalCategory("DefaultMoon");
			foreach (ConfigElement element in terminalCategory.Elements)
			{
				if (element is ButtonConfigElement buttonConfigElement)
				{
					string text = buttonConfigElement.Get<string>("id");
					buttonConfigElement.Set("text", "* " + text);
				}
			}
			currentHandler.BuildCategory(terminalCategory);
		}

		private static void SetWeathers(OwHostHandler currentHandler, int seed)
		{
			ConfigCategory terminalCategory = currentHandler.GetTerminalCategory("DefaultMoon");
			AnimationCurve weatherCurve = VanillaData.GetWeatherCurve();
			Random random = new Random(seed + 35);
			List<string> list = VanillaData.DefaultMoons.Keys.ToList();
			float num = Mathf.Clamp(weatherCurve.Evaluate((float)random.NextDouble()) * 1f, 0f, 1f);
			int num2 = Mathf.Clamp((int)(num * ((float)VanillaData.DefaultMoons.Keys.Count - 3f)), 0, VanillaData.DefaultMoons.Keys.Count);
			for (int i = 0; i < num2; i++)
			{
				int index = random.Next(0, list.Count);
				string text = list[index];
				string[] item = VanillaData.DefaultMoons[text].Weathers;
				if (text != "41 Experimentation")
				{
					if (item != null && item.Length != 0)
					{
						string text2 = item[random.Next(0, item.Length)];
						terminalCategory.GetElementFromId(text)?.Set("text", "* " + text + " (" + text2 + ")");
					}
					list.Remove(text);
				}
			}
			currentHandler.BuildCategory(terminalCategory);
		}

		private static void ClearSales(OwHostHandler currentHandler)
		{
			ConfigCategory terminalCategory = currentHandler.GetTerminalCategory("Shop");
			currentHandler.creditsAmount = 60;
			currentHandler.UpdateCredits();
			foreach (ConfigElement element in terminalCategory.Elements)
			{
				if (element is ButtonConfigElement)
				{
					element.Set("currentSale", 0);
					element.Set("bought", 0);
					UpdateBuyableElement(element);
				}
			}
			currentHandler.BuildCategory(terminalCategory);
		}

		private static void SetSales(OwHostHandler currentHandler, int seed)
		{
			ConfigCategory terminalCategory = currentHandler.GetTerminalCategory("Shop");
			Random random = new Random(seed + 90);
			int minValue = -10;
			int maxValue = 5;
			int num = Mathf.Max(random.Next(minValue, maxValue), 0);
			if (num <= 0)
			{
				return;
			}
			List<int> list = new List<int>();
			int[] array = new int[VanillaData.BuyableItemList.Length];
			for (int i = 0; i < VanillaData.BuyableItemList.Length; i++)
			{
				list.Add(i);
				array[i] = 100;
			}
			for (int j = 0; j < num; j++)
			{
				if (list.Count <= 0)
				{
					break;
				}
				int num2 = random.Next(0, list.Count);
				ConfigElement elementFromId = terminalCategory.GetElementFromId(VanillaData.BuyableItemList[num2]);
				if (elementFromId == null)
				{
					Plugin.OverworkedLogger.LogInfo((object)VanillaData.BuyableItemList[num2]);
					list.RemoveAt(num2);
					continue;
				}
				int num3 = elementFromId.Get<int>("highestSalePercentage");
				int maxValue2 = ((num2 < VanillaData.BuyableItemList.Length) ? Mathf.Clamp(num3, 0, 90) : 80);
				int num4 = 100 - random.Next(0, maxValue2);
				num4 = (int)Math.Round((double)num4 / 10.0) * 10;
				array[num2] = num4;
				list.RemoveAt(num2);
			}
			for (int k = 0; k < array.Length; k++)
			{
				ConfigElement elementFromId2 = terminalCategory.GetElementFromId(VanillaData.BuyableItemList[k]);
				if (elementFromId2 != null)
				{
					elementFromId2.Set("currentSale", 100 - array[k]);
					UpdateBuyableElement(elementFromId2);
				}
			}
			currentHandler.BuildCategory(terminalCategory);
		}

		private static void CreateSeedCategoryFor(OwHostHandler currentHandler)
		{
			ConfigCategory configCategory = new ConfigCategory();
			int seed = -1;
			Action rollSeed = delegate
			{
				seed = Random.Range(1, 100000000);
				ClearWeathers(currentHandler);
				SetWeathers(currentHandler, seed);
				ClearSales(currentHandler);
				SetSales(currentHandler, seed);
			};
			rollSeed();
			configCategory.AddElement(new TextConfigElement(("id", "title"), ("text", ">Seed (v80+)"))).AddElement(new ButtonConfigElement(delegate(ConfigElementActor a, bool isLeftClick)
			{
				a.Blink();
				a.Rebuild();
				rollSeed();
				a.TargetElement.Set("currentSeed", seed);
			}, ("id", "reroll"), ("text", "* Reroll seed"), ("currentSeed", seed)));
			configCategory.AddElement(new SpacingConfigElement());
			currentHandler.AddTerminalCategory("Seed", configCategory);
		}

		public static void LoadHostModule()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			AssetBundle val = OverworkedCore.LoadBundle();
			Object val2 = val.LoadAsset<Object>("assets/overworked/ui/ow_host.prefab");
			GameObject value = (GameObject)val.LoadAsset<Object>("assets/overworked/ui/ow_save.prefab");
			GameObject value2 = (GameObject)val.LoadAsset<Object>("assets/overworked/ui/ow_holder.prefab");
			GameObject value3 = (GameObject)val.LoadAsset<Object>("assets/overworked/ui/ow_text.prefab");
			GameObject value4 = (GameObject)val.LoadAsset<Object>("assets/overworked/ui/ow_button.prefab");
			OverworkedCore.SaveConfig = new OverworkedSaveConfig();
			GameObject val3 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
			if (val3 != null)
			{
				GameObject val4 = Object.Instantiate<GameObject>(val3);
				OwHostHandler owHostHandler = ((val4 != null) ? ((Component)val4.transform.Find("OW_Host")).gameObject.AddComponent<OwHostHandler>() : null);
				OverworkedCore.RebuildRefs((Component)(object)owHostHandler, new Dictionary<string, (GameObject, string)>
				{
					{
						"Title",
						(val4, "OW_Host/Foreground/Title")
					},
					{
						"LobbyName",
						(val4, "OW_Host/Foreground/LobbyName")
					},
					{
						"Confirm",
						(val4, "OW_Host/Foreground/Confirm")
					},
					{
						"Back",
						(val4, "OW_Host/Foreground/Back")
					},
					{
						"Saves",
						(val4, "OW_Host/Foreground/Saves")
					},
					{
						"Config",
						(val4, "OW_Host/Foreground/SaveConfig")
					},
					{
						"SavesHolder",
						(val4, "OW_Host/Foreground/Saves/Viewport/Content")
					},
					{
						"ConfigHolder",
						(val4, "OW_Host/Foreground/SaveConfig/Viewport/Content")
					},
					{
						"Public",
						(val4, "OW_Host/Foreground/Public")
					},
					{
						"Private",
						(val4, "OW_Host/Foreground/Private")
					},
					{
						"OwUi",
						(val4, "OW_Host/Foreground/OwUI_Elem")
					}
				}, new Dictionary<string, GameObject>
				{
					{ "SelectSaveButtonPrefab", value },
					{ "ConfigHolderPrefab", value2 },
					{ "ConfigTextPrefab", value3 },
					{ "ConfigButtonPrefab", value4 }
				});
				HandleUiFor(owHostHandler);
				CreateShopCategoryFor(owHostHandler);
				CreateMoonCategoryFor(owHostHandler);
				SetRoastFor(owHostHandler);
				if (OverworkedCore.Version >= 80)
				{
					CreateSeedCategoryFor(owHostHandler);
				}
			}
		}
	}
	public abstract class ConfigElement
	{
		private Dictionary<string, object> _data;

		public Dictionary<string, object> Data
		{
			get
			{
				return _data;
			}
			private set
			{
				_data = value;
			}
		}

		public ConfigElement(params (string key, object value)[] fields)
		{
			Data = fields.ToDictionary(((string key, object value) f) => f.key, ((string key, object value) f) => f.value);
		}

		public bool TryGet<T>(string key, out T result)
		{
			if (Data.TryGetValue(key, out var value) && value is T val)
			{
				result = val;
				return true;
			}
			result = default(T);
			return false;
		}

		public void Set(string key, object value)
		{
			Data[key] = value;
		}

		public T Get<T>(string key)
		{
			if (Data.TryGetValue(key, out var value) && value is T result)
			{
				return result;
			}
			return default(T);
		}

		public virtual GameObject GetUiElement(OwHostHandler handler, ConfigCategory category)
		{
			return null;
		}
	}
	public class TextConfigElement : ConfigElement
	{
		public TextConfigElement(params (string key, object value)[] fields)
			: base(fields)
		{
		}

		public override GameObject GetUiElement(OwHostHandler handler, ConfigCategory category)
		{
			GameObject val = Object.Instantiate<GameObject>(handler.ConfigTextPrefab);
			if (TryGet<string>("text", out var result))
			{
				((TMP_Text)val.GetComponent<TextMeshProUGUI>()).text = result;
			}
			return val;
		}
	}
	public class SpacingConfigElement : ConfigElement
	{
		public override GameObject GetUiElement(OwHostHandler handler, ConfigCategory category)
		{
			GameObject val = Object.Instantiate<GameObject>(handler.ConfigTextPrefab);
			((TMP_Text)val.GetComponent<TextMeshProUGUI>()).text = "";
			return val;
		}
	}
	public class ButtonConfigElement : ConfigElement
	{
		[CompilerGenerated]
		private sealed class <Blink>d__3 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Image image;

			public ButtonConfigElement <>4__this;

			private int <i>5__1;

			private byte <alpha>5__2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: 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_0070: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<i>5__1 = 10;
					break;
				case 1:
					<>1__state = -1;
					<i>5__1--;
					break;
				}
				if (<i>5__1 >= 0)
				{
					<alpha>5__2 = (byte)(<i>5__1 * 10);
					((Graphic)image).color = Color32.op_Implicit(new Color32((byte)48, (byte)148, (byte)55, <alpha>5__2));
					<>2__current = (object)new WaitForSeconds(0.05f);
					<>1__state = 1;
					return true;
				}
				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 Action<ConfigElementActor, bool> _callback;

		public ButtonConfigElement(Action<ConfigElementActor, bool> callback, params (string key, object value)[] fields)
			: base(fields)
		{
			_callback = callback;
		}

		public override GameObject GetUiElement(OwHostHandler handler, ConfigCategory category)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (TryGet<bool>("hidden", out var result) && result)
			{
				return null;
			}
			GameObject uiObject = Object.Instantiate<GameObject>(handler.ConfigButtonPrefab);
			TextMeshProUGUI componentInChildren = uiObject.GetComponentInChildren<TextMeshProUGUI>();
			Image component = uiObject.GetComponent<Image>();
			if (TryGet<string>("text", out var result2))
			{
				((TMP_Text)componentInChildren).text = result2;
			}
			if (TryGet<bool>("highlighted", out var result3) && result3)
			{
				((Graphic)component).color = Color32.op_Implicit(new Color32((byte)48, (byte)148, (byte)55, (byte)100));
				((Graphic)componentInChildren).color = Color32.op_Implicit(new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue));
			}
			if (TryGet<bool>("doBlink", out var result4) && result4)
			{
				((MonoBehaviour)component).StartCoroutine(Blink(component));
				Set("doBlink", false);
			}
			OwButton owButton = uiObject.AddComponent<OwButton>();
			owButton.onClick.AddListener((UnityAction<bool>)delegate(bool isLeftClick)
			{
				_callback(new ConfigElementActor(uiObject, this, category, handler), isLeftClick);
			});
			return uiObject;
		}

		[IteratorStateMachine(typeof(<Blink>d__3))]
		private IEnumerator Blink(Image image)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Blink>d__3(0)
			{
				<>4__this = this,
				image = image
			};
		}
	}
	public class ConfigElementActor
	{
		private ConfigCategory _targetCategory;

		private OwHostHandler _handler;

		public GameObject TargetObject { get; private set; }

		public ConfigElement TargetElement { get; private set; }

		public ConfigElementActor(GameObject targetObject, ConfigElement targetElement, ConfigCategory category, OwHostHandler handler)
		{
			TargetObject = targetObject;
			TargetElement = targetElement;
			_targetCategory = category;
			_handler = handler;
		}

		public void Blink()
		{
			TargetElement.Set("doBlink", true);
		}

		public void SetHighlighted()
		{
			foreach (ConfigElement element in _targetCategory.Elements)
			{
				element.Set("highlighted", false);
			}
			TargetElement.Set("highlighted", true);
		}

		public void Rebuild()
		{
			_handler.BuildCategory(_targetCategory);
		}
	}
	public class ConfigCategory
	{
		public List<ConfigElement> Elements { get; private set; } = new List<ConfigElement>();


		public GameObject TargetObject { get; set; }

		public ConfigCategory AddElement(ConfigElement element)
		{
			Elements.Add(element);
			return this;
		}

		public ConfigElement? GetElementFromId(string id)
		{
			foreach (ConfigElement element in Elements)
			{
				if (element.TryGet<string>("id", out var result) && result == id)
				{
					return element;
				}
			}
			return null;
		}

		public ConfigElement? GetHighlightedElement()
		{
			foreach (ConfigElement element in Elements)
			{
				if (element.TryGet<bool>("highlighted", out var result) && result)
				{
					return element;
				}
			}
			return null;
		}
	}
}
namespace OverworkedUI.Core.Modules.Data
{
	internal class VanillaData
	{
		public static readonly Dictionary<string, (string[] Weathers, bool IsPaid)> DefaultMoons = new Dictionary<string, (string[], bool)>
		{
			{
				"41 Experimentation",
				(new string[5] { "Rainy", "Stormy", "Foggy", "Flooded", "Eclipsed" }, false)
			},
			{
				"220 Assurance",
				(new string[5] { "Rainy", "Stormy", "Flooded", "Eclipsed", "Foggy" }, false)
			},
			{
				"56 Vow",
				(new string[4] { "Flooded", "Stormy", "Foggy", "Eclipsed" }, false)
			},
			{
				"71 Gordion",
				(new string[0], false)
			},
			{
				"61 March",
				(new string[3] { "Stormy", "Foggy", "Eclipsed" }, false)
			},
			{
				"20 Adamance",
				(new string[5] { "Stormy", "Eclipsed", "Rainy", "Flooded", "Foggy" }, false)
			},
			{
				"85 Rend",
				(new string[2] { "Stormy", "Eclipsed" }, true)
			},
			{
				"7 Dine",
				(new string[3] { "Flooded", "Eclipsed", "Rainy" }, true)
			},
			{
				"21 Offense",
				(new string[5] { "Rainy", "Stormy", "Eclipsed", "Flooded", "Foggy" }, false)
			},
			{
				"8 Titan",
				(new string[3] { "Stormy", "Foggy", "Eclipsed" }, true)
			},
			{
				"68 Artifice",
				(new string[5] { "Stormy", "Eclipsed", "Rainy", "Flooded", "Foggy" }, true)
			},
			{
				"44 Liquidation",
				(new string[4] { "Stormy", "Eclipsed", "Rainy", "Flooded" }, true)
			},
			{
				"5 Embrion",
				(new string[2] { "Foggy", "Eclipsed" }, true)
			}
		};

		public static readonly Dictionary<string, int> VehiclesList = new Dictionary<string, int> { { "Cruiser", 370 } };

		public static readonly string[] BuyableItemList = new string[16]
		{
			"Walkie-talkie", "Flashlight", "Shovel", "Lockpicker", "Pro-flashlight", "Stun grenade", "Boombox", "TZP-Inhalant", "Zap gun", "Jetpack",
			"Extension ladder", "Radar-booster", "Spray paint", "Weed killer", "Belt bag", "Cruiser"
		};

		public static AnimationCurve GetWeatherCurve()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			Keyframe val = default(Keyframe);
			((Keyframe)(ref val))..ctor(0f, 0f, 3.9991f, 3.9991f);
			((Keyframe)(ref val)).weightedMode = (WeightedMode)3;
			((Keyframe)(ref val)).inWeight = 0f;
			((Keyframe)(ref val)).outWeight = 0.234f;
			Keyframe val2 = val;
			((Keyframe)(ref val))..ctor(0.4983f, 0.4932f, 0.4621f, 0.4621f);
			((Keyframe)(ref val)).weightedMode = (WeightedMode)3;
			((Keyframe)(ref val)).inWeight = 0.8088f;
			((Keyframe)(ref val)).outWeight = 0.6222f;
			Keyframe val3 = val;
			((Keyframe)(ref val))..ctor(1f, 1.0039f, 4.3878f, 4.3878f);
			((Keyframe)(ref val)).weightedMode = (WeightedMode)3;
			((Keyframe)(ref val)).inWeight = 0.1519f;
			((Keyframe)(ref val)).outWeight = 0f;
			Keyframe val4 = val;
			AnimationCurve val5 = new AnimationCurve((Keyframe[])(object)new Keyframe[3] { val2, val3, val4 });
			WrapMode preWrapMode = (WrapMode)8;
			val5.postWrapMode = (WrapMode)8;
			val5.preWrapMode = preWrapMode;
			return val5;
		}
	}
}