using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using Barotrauma; using HarmonyLib; using Microsoft.Xna.Framework; namespace QICrabUI { public class ModStorage { private static Dictionary GetOrCreateRepo() { if (GUI.Canvas.GUIComponent is not GUIButton) { GUI.Canvas.GUIComponent = new GUIButton(new RectTransform(new Point(0, 0))); } if (GUI.Canvas.GUIComponent.UserData is not Dictionary) { GUI.Canvas.GUIComponent.UserData = new Dictionary(); } return (Dictionary)GUI.Canvas.GUIComponent.UserData; } public static object Get(string key) => (TValue)Get(key); public static object Get(string key) { Dictionary repo = GetOrCreateRepo(); return repo.GetValueOrDefault(key); } public static void Set(string key, object value) { Dictionary repo = GetOrCreateRepo(); repo[key] = value; } public static bool Has(string key) { Dictionary repo = GetOrCreateRepo(); return repo.ContainsKey(key); } } }