using System; using System.Collections.Generic; using System.Globalization; using System.IO; using System.Text; using UltraParadise.Shared; using UnityEngine; namespace UltraParadise { internal struct KeyBind { public KeyCode Key; public bool Ctrl, Shift, Alt; public static bool TryParse(string s, out KeyBind b) { b = new KeyBind(); if (string.IsNullOrEmpty(s) || s == "none") return false; string[] parts = s.Split('+'); for (int i = 0; i < parts.Length - 1; i++) { if (parts[i] == "Ctrl") b.Ctrl = true; else if (parts[i] == "Shift") b.Shift = true; else if (parts[i] == "Alt") b.Alt = true; } try { b.Key = (KeyCode)Enum.Parse(typeof(KeyCode), parts[parts.Length - 1], true); } catch (Exception) { return false; } return b.Key != KeyCode.None; } } public class LinuxHost : MonoBehaviour { public const string Version = "0.5.0"; private static LinuxHost I; private static readonly object gate = new object(); private static Dictionary info; private static readonly List toastQ = new List(); private static string blockedWhy; internal static string Home { get { return Path.Combine(Path.GetDirectoryName(Application.dataPath), "UltraParadise"); } } internal static string LinkFile { get { return Path.Combine(Home, "link.txt"); } } private static string CfgFile { get { string f = Path.Combine(Home, "settings.cfg"); try { string old = Path.Combine(Path.Combine(Path.Combine(Path.GetDirectoryName(Application.dataPath), "BepInEx"), "config"), "UltraParadise.CUTrainer.cfg"); if (!File.Exists(f) && File.Exists(old)) { Directory.CreateDirectory(Home); File.Copy(old, f); } } catch (Exception) { } return f; } } private List tabs; private readonly Dictionary byId = new Dictionary(); private readonly Dictionary defaults = new Dictionary(); private readonly Dictionary binds = new Dictionary(); private readonly Dictionary extra = new Dictionary(); private readonly List ovExtra = new List(); private int ovSize = 100; private readonly Dictionary parsed = new Dictionary(); private readonly Dictionary last = new Dictionary(); private readonly Dictionary saved = new Dictionary(); private readonly List> toasts = new List>(); private bool overlayOn = true, remember = true, pauseInMenu = true, menuOpen, restored; private string ovCorner = "top-left", accentHex = "ff7a18"; private int ovAlpha = 93; private int tab; private Vector2 scroll; private string binding; private float nextDiff, saveAt = -1f, savedScale = 1f; private bool wePaused, oldCursorVisible; private CursorLockMode oldLock; private void Awake() { I = this; tabs = Cheats.Build(); foreach (CTab t in tabs) foreach (CSection s in t.Sections) foreach (COpt o in s.Rows) { byId[o.Id] = o; if (o.Kind == CKind.Toggle || o.Kind == CKind.Action) defaults[o.Id] = o.Key; } defaults["menu"] = Cheats.MenuKey; defaults["overlay"] = Cheats.OverlayKey; foreach (KeyValuePair kv in defaults) binds[kv.Key] = kv.Value; Load(); Reparse(); try { Directory.CreateDirectory(Path.GetDirectoryName(LinkFile)); } catch (Exception) { } } private void Start() { if (restored) return; restored = true; if (!remember) return; foreach (KeyValuePair kv in saved) { COpt o; if (!byId.TryGetValue(kv.Key, out o)) continue; if (o.Kind == CKind.Toggle && kv.Value == "1") Link.Inject("SET " + o.Id + " 1"); else if (o.Kind == CKind.Slider) Link.Inject("VAL " + o.Id + " " + kv.Value); } } internal static void Sent(string s) { if (s.StartsWith("MSG ", StringComparison.Ordinal)) Toast(s.Substring(4)); else if (s.StartsWith("INFO ", StringComparison.Ordinal)) { Dictionary d = new Dictionary(); foreach (string part in s.Substring(5).Split('|')) { int eq = part.IndexOf('='); if (eq > 0) d[part.Substring(0, eq)] = part.Substring(eq + 1); } lock (gate) info = d; } else if (s.StartsWith("BLOCKED ", StringComparison.Ordinal)) blockedWhy = s.Substring(8); } internal static void Toast(string s) { lock (gate) { if (toastQ.Count < 8) toastQ.Add(s); } } internal static void OnConnected() { if (I != null) I.SendAll(); } internal static bool Handle(string cmd, string[] p) { if (I == null) return false; if (cmd == "BIND" && p.Length >= 3) { if (!I.binds.ContainsKey(p[1])) return true; string k = p[2].Trim(); KeyBind b; if (k != "none" && !KeyBind.TryParse(k, out b)) return true; I.binds[p[1]] = k; I.Reparse(); I.Dirty(); return true; } if (cmd == "OPT" && p.Length >= 3) { bool on = p[2] == "1"; if (p[1] == "overlay") I.overlayOn = on; else if (p[1] == "remember") I.remember = on; else if (p[1] == "pause") I.pauseInMenu = on; I.Dirty(); I.SendOpts(); return true; } if (cmd == "THEME" && p.Length >= 2) { I.ApplyTheme(string.Join(" ", p, 1, p.Length - 1)); I.Dirty(); return true; } if (cmd == "STATEREQ") { I.SendAll(); return true; } if (cmd == "TOAST" && p.Length >= 2) { Toast(string.Join(" ", p, 1, p.Length - 1)); return true; } if (cmd == "XBINDS") { I.extra.Clear(); if (p.Length >= 2) foreach (string part in string.Join(" ", p, 1, p.Length - 1).Split(',')) { int eq = part.IndexOf('='); KeyBind b; if (eq > 0 && KeyBind.TryParse(part.Substring(eq + 1), out b)) I.extra[part.Substring(0, eq)] = b; } return true; } if (cmd == "OVEXTRA") { I.ovExtra.Clear(); if (p.Length >= 2) foreach (string l in string.Join(" ", p, 1, p.Length - 1).Split('\u001c')) if (l.Length > 0 && I.ovExtra.Count < 12) I.ovExtra.Add(l); return true; } if (cmd == "ACT" && p.Length >= 2) { if (p[1] == "speedcycle") { I.CycleSpeed(); return true; } if (p[1] == "alloff") { Plugin.AllOff(); Toast("Everything is off"); return true; } } return false; } private void CycleSpeed() { float[] steps = { 1f, 1.5f, 2f, 0.5f }; int at = 0; for (int i = 0; i < steps.Length; i++) if (Mathf.Abs(Plugin.GameSpeed - steps[i]) < 0.01f) { at = i; break; } float v = steps[(at + 1) % steps.Length]; Link.Inject("VAL GameSpeed " + v.ToString(CultureInfo.InvariantCulture)); Toast("Game speed x" + v.ToString("0.0", CultureInfo.InvariantCulture)); } private void SendAll() { last.Clear(); foreach (COpt o in byId.Values) { if (o.Kind != CKind.Toggle && o.Kind != CKind.Slider) continue; string v = Value(o); last[o.Id] = v; Link.Send("STATE " + o.Id + " " + v); } foreach (KeyValuePair kv in binds) Link.Send("BIND " + kv.Key + " " + (string.IsNullOrEmpty(kv.Value) ? "none" : kv.Value)); SendOpts(); Link.Send("PLUGIN " + Version); } private void ApplyTheme(string s) { foreach (string part in s.Split('|')) { int eq = part.IndexOf('='); if (eq <= 0) continue; string k = part.Substring(0, eq).Trim(), v = part.Substring(eq + 1).Trim().ToLowerInvariant(); int n; if (k == "corner" && (v == "top-left" || v == "top-right" || v == "bottom-left" || v == "bottom-right")) ovCorner = v; else if (k == "alpha" && int.TryParse(v, NumberStyles.Integer, CultureInfo.InvariantCulture, out n)) ovAlpha = Mathf.Clamp(n, 30, 100); else if (k == "size" && int.TryParse(v, NumberStyles.Integer, CultureInfo.InvariantCulture, out n)) ovSize = Mathf.Clamp(n, 60, 160); else if (k == "accent" && v.Length == 6 && int.TryParse(v, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out n)) { accentHex = v; panel = null; } } } private Color Accent(float a) { int n; if (!int.TryParse(accentHex, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out n)) n = 0xff7a18; return C((n >> 16) & 255, (n >> 8) & 255, n & 255, a); } private void SendOpts() { if (!Link.Connected) return; Link.Send("OPTS overlay=" + (overlayOn ? 1 : 0) + "|remember=" + (remember ? 1 : 0) + "|pause=" + (pauseInMenu ? 1 : 0)); } private static float Num(string id) { if (id == "GameSpeed") return Plugin.GameSpeed; if (id == "CameraZoom") return Plugin.CameraZoom; Num n = Plugin.FindNum(id); return n != null ? n.Value : 0f; } private static bool On(string id) { Flag f = Plugin.FindFlag(id); return f != null && f.Value; } private static string Value(COpt o) { if (o.Kind == CKind.Toggle) return On(o.Id) ? "1" : "0"; return Num(o.Id).ToString("0.###", CultureInfo.InvariantCulture); } private void Diff() { bool changed = false; foreach (COpt o in byId.Values) { if (o.Kind != CKind.Toggle && o.Kind != CKind.Slider) continue; string v = Value(o); string was; if (last.TryGetValue(o.Id, out was) && was == v) continue; bool first = was == null; last[o.Id] = v; if (!first) changed = true; if (Link.Connected && !first) Link.Send("STATE " + o.Id + " " + v); } if (changed) Dirty(); } private void Dirty() { saveAt = Time.unscaledTime + 1f; } private void Reparse() { parsed.Clear(); foreach (KeyValuePair kv in binds) { KeyBind b; if (KeyBind.TryParse(kv.Value, out b)) parsed[kv.Key] = b; } if (Link.Connected) foreach (KeyValuePair kv in binds) Link.Send("BIND " + kv.Key + " " + (string.IsNullOrEmpty(kv.Value) ? "none" : kv.Value)); } private void Load() { try { if (!File.Exists(CfgFile)) return; foreach (string line in File.ReadAllLines(CfgFile)) { int eq = line.IndexOf('='); if (eq <= 0) continue; string k = line.Substring(0, eq).Trim(), v = line.Substring(eq + 1).Trim(); if (k.StartsWith("bind.", StringComparison.Ordinal)) { string id = k.Substring(5); if (binds.ContainsKey(id)) binds[id] = v; } else if (k.StartsWith("cheat.", StringComparison.Ordinal)) saved[k.Substring(6)] = v; else if (k == "overlay") overlayOn = v == "1"; else if (k == "remember") remember = v == "1"; else if (k == "pause") pauseInMenu = v == "1"; else if (k == "theme.corner" || k == "theme.alpha" || k == "theme.accent") ApplyTheme(k.Substring(6) + "=" + v); } } catch (Exception e) { Plugin.Log.LogWarning("Couldn't read settings: " + e.Message); } } private void Save() { saveAt = -1f; try { List lines = new List(); lines.Add("# Ultra Paradise CU:Trainer (in-game settings). The menu and the Linux app change these for you."); lines.Add("overlay=" + (overlayOn ? 1 : 0)); lines.Add("remember=" + (remember ? 1 : 0)); lines.Add("pause=" + (pauseInMenu ? 1 : 0)); lines.Add("theme.corner=" + ovCorner); lines.Add("theme.alpha=" + ovAlpha); lines.Add("theme.accent=" + accentHex); foreach (KeyValuePair kv in binds) lines.Add("bind." + kv.Key + "=" + (string.IsNullOrEmpty(kv.Value) ? "none" : kv.Value)); if (remember) foreach (COpt o in byId.Values) { if (o.Kind == CKind.Toggle && On(o.Id)) lines.Add("cheat." + o.Id + "=1"); else if (o.Kind == CKind.Slider) lines.Add("cheat." + o.Id + "=" + Value(o)); } Directory.CreateDirectory(Path.GetDirectoryName(CfgFile)); File.WriteAllLines(CfgFile, lines.ToArray()); } catch (Exception e) { Plugin.Log.LogWarning("Couldn't save settings: " + e.Message); } } private void OnApplicationQuit() { Save(); if (wePaused && Time.timeScale == 0f) Time.timeScale = savedScale; } private void Update() { lock (gate) { foreach (string t in toastQ) toasts.Add(new KeyValuePair(t, Time.unscaledTime + 3.5f)); toastQ.Clear(); } toasts.RemoveAll(delegate (KeyValuePair t) { return t.Value < Time.unscaledTime; }); while (toasts.Count > 4) toasts.RemoveAt(0); if (binding == null) Keys(); if (Time.unscaledTime >= nextDiff) { nextDiff = Time.unscaledTime + 0.25f; try { Diff(); } catch (Exception) { } } if (saveAt > 0f && Time.unscaledTime >= saveAt) Save(); if (menuOpen) { Cursor.visible = true; if (Cursor.lockState != CursorLockMode.None) Cursor.lockState = CursorLockMode.None; if (wePaused && Time.timeScale != 0f) wePaused = false; } } private void Keys() { bool sticks = (Input.GetKey(KeyCode.JoystickButton8) && Input.GetKeyDown(KeyCode.JoystickButton9)) || (Input.GetKey(KeyCode.JoystickButton9) && Input.GetKeyDown(KeyCode.JoystickButton8)); if (sticks) { ToggleMenu(); return; } bool ctrl = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); bool shift = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); bool alt = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); string hit = null; foreach (KeyValuePair kv in parsed) { KeyBind b = kv.Value; if (b.Ctrl != ctrl || b.Shift != shift || b.Alt != alt) continue; if (Input.GetKeyDown(b.Key)) { hit = kv.Key; break; } } if (hit != null) { Trigger(hit); return; } if (menuOpen) return; foreach (KeyValuePair kv in extra) { KeyBind b = kv.Value; if (b.Ctrl != ctrl || b.Shift != shift || b.Alt != alt) continue; if (Input.GetKeyDown(b.Key)) { if (Link.Connected) Link.Send("HOTKEY " + kv.Key); return; } } } private void Trigger(string id) { if (id == "menu") { ToggleMenu(); return; } if (id == "overlay") { overlayOn = !overlayOn; Toast("Overlay " + (overlayOn ? "on" : "off")); Dirty(); SendOpts(); return; } if (menuOpen) return; COpt o; if (!byId.TryGetValue(id, out o)) return; if (o.Kind == CKind.Toggle) { bool on = On(id); Link.Inject("SET " + id + (on ? " 0" : " 1")); if (blockedWhy == null) Toast(o.Name + (on ? " off" : " on")); } else if (o.Kind == CKind.Action) Link.Inject("ACT " + id); } private void ToggleMenu() { menuOpen = !menuOpen; binding = null; if (menuOpen) { oldCursorVisible = Cursor.visible; oldLock = Cursor.lockState; if (pauseInMenu && Time.timeScale > 0f) { savedScale = Time.timeScale; Time.timeScale = 0f; wePaused = true; } } else { Cursor.visible = oldCursorVisible; Cursor.lockState = oldLock; if (wePaused && Time.timeScale == 0f) Time.timeScale = savedScale; wePaused = false; } } private GUIStyle panel, rowOff, rowOn, btn, key, keyOn, tabOff, tabOn, title, section, label, dim, note, ovTitle, ovLine, toast; private static Texture2D Tex(Color c) { Texture2D t = new Texture2D(1, 1, TextureFormat.RGBA32, false); t.hideFlags = HideFlags.HideAndDontSave; t.SetPixel(0, 0, c); t.Apply(); return t; } private static Color C(int r, int g, int b, float a) { return new Color(r / 255f, g / 255f, b / 255f, a); } private static GUIStyle Box(Color bg, Color hover, Color text, int size, TextAnchor align, bool bold) { GUIStyle s = new GUIStyle(GUI.skin.label); s.normal.background = Tex(bg); s.hover.background = Tex(hover); s.active.background = Tex(hover); s.normal.textColor = text; s.hover.textColor = text; s.active.textColor = text; s.border = new RectOffset(0, 0, 0, 0); s.padding = new RectOffset(10, 10, 4, 4); s.margin = new RectOffset(2, 2, 2, 2); s.fontSize = size; s.alignment = align; s.fontStyle = bold ? FontStyle.Bold : FontStyle.Normal; s.wordWrap = false; return s; } private static GUIStyle Text(Color c, int size, bool bold, bool wrap) { GUIStyle s = new GUIStyle(GUI.skin.label); s.normal.textColor = c; s.fontSize = size; s.fontStyle = bold ? FontStyle.Bold : FontStyle.Normal; s.wordWrap = wrap; s.richText = false; return s; } private void Styles() { Color orange = Accent(1f), light = C(236, 236, 239, 1f), dark = (orange.r * 0.2126f + orange.g * 0.7152f + orange.b * 0.0722f) > 0.45f ? C(20, 20, 22, 1f) : C(250, 250, 250, 1f); Color hover = Color.Lerp(orange, Color.white, 0.15f), keyBg = Color.Lerp(C(26, 26, 30, 1f), orange, 0.3f); panel = Box(C(18, 18, 20, 0.97f), C(18, 18, 20, 0.97f), light, 14, TextAnchor.UpperLeft, false); rowOff = Box(C(34, 34, 38, 1f), C(48, 48, 54, 1f), light, 14, TextAnchor.MiddleLeft, false); rowOn = Box(orange, hover, dark, 14, TextAnchor.MiddleLeft, true); btn = Box(C(48, 48, 54, 1f), C(66, 66, 74, 1f), light, 13, TextAnchor.MiddleCenter, false); key = Box(C(26, 26, 30, 1f), C(40, 40, 46, 1f), C(170, 170, 180, 1f), 12, TextAnchor.MiddleCenter, false); keyOn = Box(keyBg, keyBg, orange, 12, TextAnchor.MiddleCenter, true); tabOff = Box(C(30, 30, 34, 1f), C(46, 46, 52, 1f), light, 14, TextAnchor.MiddleCenter, false); tabOn = Box(orange, orange, dark, 14, TextAnchor.MiddleCenter, true); title = Text(orange, 20, true, false); section = Text(orange, 12, true, false); label = Text(light, 14, false, false); dim = Text(C(150, 150, 160, 1f), 12, false, true); note = Text(C(200, 200, 206, 1f), 13, false, true); ovTitle = Text(orange, 13, true, false); ovLine = Text(light, 12, false, false); toast = Box(C(18, 18, 20, 0.92f), C(18, 18, 20, 0.92f), light, 14, TextAnchor.MiddleCenter, false); } private void OnGUI() { if (panel == null || panel.normal.background == null) Styles(); float s = Mathf.Clamp(Screen.height / 760f, 1f, 3f); Matrix4x4 old = GUI.matrix; GUI.matrix = Matrix4x4.Scale(new Vector3(s, s, 1f)); float w = Screen.width / s, h = Screen.height / s; if (binding != null) CaptureKey(Event.current); if (menuOpen) DrawMenu(w, h); else if (overlayOn) { Matrix4x4 m2 = GUI.matrix; GUI.matrix = Matrix4x4.Scale(new Vector3(s * ovSize / 100f, s * ovSize / 100f, 1f)); DrawOverlay(); GUI.matrix = m2; } DrawToasts(w, h); GUI.matrix = old; } private void CaptureKey(Event e) { if (e == null || e.type != EventType.KeyDown || e.keyCode == KeyCode.None) return; KeyCode k = e.keyCode; if (k == KeyCode.LeftControl || k == KeyCode.RightControl || k == KeyCode.LeftShift || k == KeyCode.RightShift || k == KeyCode.LeftAlt || k == KeyCode.RightAlt) return; e.Use(); if (k == KeyCode.Escape) { binding = null; return; } string v; if (k == KeyCode.Delete || k == KeyCode.Backspace) v = "none"; else v = (e.control ? "Ctrl+" : "") + (e.shift ? "Shift+" : "") + (e.alt ? "Alt+" : "") + k.ToString(); if (v != "none" && binding == "menu" && (e.control || e.shift || e.alt)) v = k.ToString(); binds[binding] = v; binding = null; Reparse(); Dirty(); } private string KeyOf(string id) { string k; return binds.TryGetValue(id, out k) ? Cheats.KeyLabel(k) : "-"; } private void DrawOverlay() { List lines = new List(); foreach (CTab t in tabs) foreach (CSection sec in t.Sections) foreach (COpt o in sec.Rows) { if (o.Kind != CKind.Toggle || !On(o.Id)) continue; string k = KeyOf(o.Id); lines.Add(o.Name + (k != "-" ? " " + k : "")); } if (Mathf.Abs(Plugin.GameSpeed - 1f) > 0.01f) lines.Add("Game speed x" + Plugin.GameSpeed.ToString("0.##", CultureInfo.InvariantCulture)); int more = 0; if (lines.Count > 14) { more = lines.Count - 13; lines.RemoveRange(13, lines.Count - 13); lines.Add("+" + more + " more"); } string head = blockedWhy != null ? "Cheats are off: multiplayer mod" : KeyOf("menu") + " opens the menu"; if (ovExtra.Count > 0) { lines.Add(""); lines.AddRange(ovExtra); } float hgt = 44f + lines.Count * 17f; float sc = Mathf.Clamp(Screen.height / 760f, 1f, 3f) * ovSize / 100f; float x = ovCorner.EndsWith("right", StringComparison.Ordinal) ? Screen.width / sc - 270f : 10f; float y = ovCorner.StartsWith("bottom", StringComparison.Ordinal) ? Screen.height / sc - hgt - 10f : 10f; Color oldC = GUI.color; GUI.color = new Color(1f, 1f, 1f, ovAlpha / 100f); GUI.Box(new Rect(x, y, 260f, hgt), GUIContent.none, panel); GUI.Label(new Rect(x + 10f, y + 4f, 240f, 20f), "ULTRA PARADISE", ovTitle); GUI.Label(new Rect(x + 10f, y + 20f, 240f, 18f), head, dim); for (int i = 0; i < lines.Count; i++) GUI.Label(new Rect(x + 10f, y + 38f + i * 17f, 240f, 18f), lines[i], ovLine); GUI.color = oldC; } private void DrawToasts(float w, float h) { for (int i = 0; i < toasts.Count; i++) { Rect r = new Rect((w - 420f) / 2f, h - 70f - (toasts.Count - 1 - i) * 38f, 420f, 32f); GUI.Box(r, toasts[i].Key, toast); } } private Dictionary Info() { lock (gate) return info; } private void DrawMenu(float sw, float sh) { float w = Mathf.Min(1000f, sw - 30f), h = Mathf.Min(620f, sh - 30f); Rect r = new Rect((sw - w) / 2f, (sh - h) / 2f, w, h); GUI.Box(r, GUIContent.none, panel); GUILayout.BeginArea(new Rect(r.x + 16f, r.y + 10f, w - 32f, h - 20f)); GUILayout.BeginHorizontal(); GUILayout.Label("ULTRA PARADISE", title); string status = blockedWhy != null ? "Cheats are off: " + blockedWhy : Link.Connected ? "Linked to the Linux app" : "In-game menu"; GUILayout.Label(" " + status, dim, GUILayout.ExpandWidth(true)); if (GUILayout.Button("Close", btn, GUILayout.Width(90f), GUILayout.Height(28f))) ToggleMenu(); GUILayout.EndHorizontal(); GUILayout.Space(6f); GUILayout.BeginHorizontal(); for (int i = 0; i <= tabs.Count; i++) { string name = i < tabs.Count ? tabs[i].Name : "Settings"; if (GUILayout.Button(name, i == tab ? tabOn : tabOff, GUILayout.Height(30f))) { tab = i; scroll = Vector2.zero; binding = null; } } GUILayout.EndHorizontal(); GUILayout.Space(8f); scroll = GUILayout.BeginScrollView(scroll, false, false); float colW = (w - 32f - 40f) / 2f; GUILayout.BeginHorizontal(); if (tab < tabs.Count) { Dictionary d = Info(); GUILayout.BeginVertical(GUILayout.Width(colW)); foreach (CSection sec in tabs[tab].Sections) if (sec.Col == 0) DrawSection(sec, d); GUILayout.EndVertical(); GUILayout.Space(16f); GUILayout.BeginVertical(GUILayout.Width(colW)); foreach (CSection sec in tabs[tab].Sections) if (sec.Col != 0) DrawSection(sec, d); GUILayout.EndVertical(); } else DrawSettings(colW); GUILayout.EndHorizontal(); GUILayout.EndScrollView(); string tip = GUI.tooltip; GUILayout.Label(string.IsNullOrEmpty(tip) ? (binding != null ? "Press a key. Esc cancels, Delete clears it." : "Click a cheat to switch it. Click its key box to pick a new key. " + KeyOf("menu") + " (or both sticks on a controller) closes this menu.") : tip, dim); GUILayout.EndArea(); } private void DrawSection(CSection sec, Dictionary d) { GUILayout.Label(sec.Title, section); foreach (COpt o in sec.Rows) DrawRow(o, d); GUILayout.Space(10f); } private void KeyBox(string id) { bool waiting = binding == id; if (GUILayout.Button(waiting ? "press a key" : KeyOf(id), waiting ? keyOn : key, GUILayout.Width(104f), GUILayout.Height(30f))) binding = waiting ? null : id; } private void DrawRow(COpt o, Dictionary d) { switch (o.Kind) { case CKind.Toggle: { bool on = On(o.Id); GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent((on ? "ON " : "OFF ") + o.Name, o.Hint ?? ""), on ? rowOn : rowOff, GUILayout.Height(30f))) Link.Inject("SET " + o.Id + (on ? " 0" : " 1")); KeyBox(o.Id); GUILayout.EndHorizontal(); break; } case CKind.Action: GUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent(o.Name, o.Hint ?? ""), btn, GUILayout.Height(30f))) Link.Inject("ACT " + o.Id); KeyBox(o.Id); GUILayout.EndHorizontal(); break; case CKind.Slider: { float v = Num(o.Id); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent(o.Name + " " + string.Format(CultureInfo.InvariantCulture, o.Format, v), o.Hint ?? ""), label, GUILayout.Width(190f)); float nv = GUILayout.HorizontalSlider(v, o.Min, o.Max, GUILayout.ExpandWidth(true), GUILayout.Height(24f)); if (GUILayout.Button("Reset", btn, GUILayout.Width(60f), GUILayout.Height(24f))) nv = o.Default; GUILayout.EndHorizontal(); nv = Mathf.Clamp(Mathf.Round(nv / o.Step) * o.Step, o.Min, o.Max); if (Mathf.Abs(nv - v) > 0.0001f) Link.Inject("VAL " + o.Id + " " + nv.ToString("0.###", CultureInfo.InvariantCulture)); break; } case CKind.Buttons: { GUILayout.BeginHorizontal(); string text = o.Text != null ? o.Text(d) : o.Name; GUILayout.Label(new GUIContent(text ?? "", o.Hint ?? ""), label, GUILayout.Width(150f)); foreach (CBtn b in o.Buttons) if (GUILayout.Button(b.Label, btn, GUILayout.Height(28f))) Link.Inject("ACT " + b.Act + (b.Arg != null ? " " + b.Arg : "")); GUILayout.EndHorizontal(); break; } case CKind.Info: { string text = o.Text != null ? o.Text(d) : ""; if (!string.IsNullOrEmpty(text)) GUILayout.Label(text, label); break; } case CKind.Note: GUILayout.Label(o.Name, note); break; } } private bool Switch(string name, bool on, string hint) { return GUILayout.Button(new GUIContent((on ? "ON " : "OFF ") + name, hint), on ? rowOn : rowOff, GUILayout.Height(30f)); } private void DrawSettings(float colW) { GUILayout.BeginVertical(GUILayout.Width(colW)); GUILayout.Label("IN GAME", section); GUILayout.BeginHorizontal(); if (Switch("In-Game Overlay", overlayOn, "Shows what's on in the top-left corner.")) { overlayOn = !overlayOn; Dirty(); SendOpts(); } KeyBox("overlay"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(new GUIContent("Open This Menu", "Pressing both sticks (L3 + R3) on a controller also opens it."), label, GUILayout.ExpandWidth(true), GUILayout.Height(30f)); KeyBox("menu"); GUILayout.EndHorizontal(); if (Switch("Pause the Game While This Menu Is Open", pauseInMenu, "Stops time while you pick cheats.")) { pauseInMenu = !pauseInMenu; Dirty(); SendOpts(); } if (Switch("Remember My Cheats", remember, "The cheats you had on switch back on the next time you start the game.")) { remember = !remember; Dirty(); SendOpts(); } GUILayout.Space(6f); if (GUILayout.Button("Switch Everything Off", btn, GUILayout.Height(30f))) Link.Inject("ACT alloff"); if (GUILayout.Button("Reset All Keys", btn, GUILayout.Height(30f))) { foreach (KeyValuePair kv in defaults) binds[kv.Key] = kv.Value; Reparse(); Dirty(); Toast("Keys reset"); } GUILayout.EndVertical(); GUILayout.Space(16f); GUILayout.BeginVertical(GUILayout.Width(colW)); GUILayout.Label("STEAM DECK", section); GUILayout.Label("Press both sticks (L3 + R3) to open or close this menu. Tap the screen or use the trackpad to click. You can also map " + KeyOf("menu") + " to a back button in Steam Input.", note); GUILayout.Space(10f); GUILayout.Label("ABOUT", section); GUILayout.Label("Ultra Paradise CU:Trainer v" + Version + " (Linux)\nCopyright (c) casualexpie. All rights reserved.\n\nThis is closed-source software. Don't decompile, modify or reupload it.\n\nSingle player only. Cheats stay off while a multiplayer mod is loaded.", note); GUILayout.EndVertical(); } } }