using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; using System.IO.Compression; using System.Text; using System.Windows.Forms; namespace UltraParadise { internal class Profile { public string Name; public readonly HashSet On = new HashSet(); public readonly Dictionary Vals = new Dictionary(); public readonly Dictionary KeyMap = new Dictionary(); public Keys Hot; public bool Chaos; } internal class Macro { public string Name = "", Cond = "always", Mode = "on"; public Keys Key; public readonly List Ids = new List(); } internal class RunStat { public DateTime Start; public double Secs; public int Deepest; public bool Died; public float BloodLost, BloodGained; public int LimbsLost, Spawned, Actions; public readonly HashSet Cheats = new HashSet(); public float LastBlood = -1f; public int LastMissing = -1; public bool Cheated { get { return Cheats.Count > 0 || Spawned > 0 || Actions > 0; } } public string Line() { List c = new List(Cheats); return Start.Ticks.ToString(CultureInfo.InvariantCulture) + "|" + ((int)Secs).ToString(CultureInfo.InvariantCulture) + "|" + Deepest + "|" + (Died ? 1 : 0) + "|" + BloodLost.ToString("0.#", CultureInfo.InvariantCulture) + "|" + BloodGained.ToString("0.#", CultureInfo.InvariantCulture) + "|" + LimbsLost + "|" + Spawned + "|" + Actions + "|" + string.Join(";", c.ToArray()).Replace("|", "/"); } public static RunStat Parse(string s) { string[] p = s.Split('|'); if (p.Length < 10) return null; RunStat r = new RunStat(); long ticks; int i; float f; if (!long.TryParse(p[0], NumberStyles.Integer, CultureInfo.InvariantCulture, out ticks) || ticks <= 0 || ticks >= DateTime.MaxValue.Ticks) return null; r.Start = new DateTime(ticks); if (int.TryParse(p[1], NumberStyles.Integer, CultureInfo.InvariantCulture, out i)) r.Secs = i; if (int.TryParse(p[2], NumberStyles.Integer, CultureInfo.InvariantCulture, out i)) r.Deepest = i; r.Died = p[3] == "1"; if (float.TryParse(p[4], NumberStyles.Float, CultureInfo.InvariantCulture, out f)) r.BloodLost = f; if (float.TryParse(p[5], NumberStyles.Float, CultureInfo.InvariantCulture, out f)) r.BloodGained = f; if (int.TryParse(p[6], NumberStyles.Integer, CultureInfo.InvariantCulture, out i)) r.LimbsLost = i; if (int.TryParse(p[7], NumberStyles.Integer, CultureInfo.InvariantCulture, out i)) r.Spawned = i; if (int.TryParse(p[8], NumberStyles.Integer, CultureInfo.InvariantCulture, out i)) r.Actions = i; foreach (string c in p[9].Split(';')) if (c.Length > 0) r.Cheats.Add(c); return r; } } internal static class SaveCheck { public static string Line(Dictionary d) { string v; if (d == null || !d.TryGetValue("savecheat", out v)) return "Save file marked as cheated: unknown (update UltraPara.dll)"; switch (v) { case "cheated": return "Save file marked as cheated: TRUE"; case "clean": return "Save file marked as cheated: FALSE"; case "none": return "Save file marked as cheated: no save file right now"; case "error": return "Save file marked as cheated: couldn't read the save"; default: return "Save file marked as cheated: unknown"; } } public static string Ach(Dictionary d) { string v; if (d == null || !d.TryGetValue("achoff", out v)) return ""; return v == "1" ? "Achievements right now: OFF" : "Achievements right now: on"; } } internal class Bookmark { public string Name; public float X, Y; public int Depth; } internal static partial class Dialogs { public static Form Shell(string title, int w) { Form f = new Form(); f.Text = title; f.FormBorderStyle = FormBorderStyle.FixedDialog; f.MaximizeBox = false; f.MinimizeBox = false; f.ShowInTaskbar = false; f.StartPosition = FormStartPosition.CenterParent; f.BackColor = Theme.Back; f.ForeColor = Theme.Text; f.Font = Theme.F("Segoe UI", 9.5f); f.ClientSize = new Size(Theme.S(w), Theme.S(100)); return f; } public static Button MakeButton(string text, DialogResult r) { Button b = new Button(); b.Text = text; b.DialogResult = r; b.FlatStyle = FlatStyle.Flat; b.FlatAppearance.BorderColor = Theme.Line; b.BackColor = r == DialogResult.OK ? Theme.Orange : Theme.Panel; b.ForeColor = r == DialogResult.OK ? (Theme.Lum(Theme.Orange) > 0.55 ? Color.Black : Color.White) : Theme.Text; b.AutoSize = true; b.Padding = new Padding(Theme.S(8), Theme.S(2), Theme.S(8), Theme.S(2)); return b; } public static Label Text(string s, int w) { Label l = new Label(); l.Text = s; l.ForeColor = Theme.Text; l.MaximumSize = new Size(Theme.S(w), 0); l.AutoSize = true; return l; } private static void Finish(Form f, Control last, Button ok, Button cancel) { int y = last.Bottom + Theme.S(14); if (cancel != null) { cancel.Location = new Point(f.ClientSize.Width - Theme.S(16) - cancel.PreferredSize.Width, y); f.Controls.Add(cancel); f.CancelButton = cancel; } ok.Location = new Point((cancel != null ? cancel.Left - Theme.S(8) : f.ClientSize.Width - Theme.S(16)) - ok.PreferredSize.Width, y); f.Controls.Add(ok); f.AcceptButton = ok; f.ClientSize = new Size(f.ClientSize.Width, y + ok.PreferredSize.Height + Theme.S(14)); } public static string Ask(IWin32Window owner, string title, string prompt, string def) { using (Form f = Shell(title, 380)) { Label l = Text(prompt, 350); l.Location = new Point(Theme.S(16), Theme.S(14)); f.Controls.Add(l); TextBox t = new TextBox(); t.Text = def ?? ""; t.BackColor = Theme.Panel; t.ForeColor = Theme.Text; t.BorderStyle = BorderStyle.FixedSingle; t.Bounds = new Rectangle(Theme.S(16), l.Bottom + Theme.S(8), f.ClientSize.Width - Theme.S(32), t.PreferredHeight); t.MaxLength = 32; f.Controls.Add(t); Finish(f, t, MakeButton("OK", DialogResult.OK), MakeButton("Cancel", DialogResult.Cancel)); t.SelectAll(); return f.ShowDialog(owner) == DialogResult.OK ? t.Text.Trim() : null; } } public static bool Confirm(IWin32Window owner, string title, string text) { using (Form f = Shell(title, 380)) { Label l = Text(text, 350); l.Location = new Point(Theme.S(16), Theme.S(14)); f.Controls.Add(l); Finish(f, l, MakeButton("Yes", DialogResult.OK), MakeButton("Cancel", DialogResult.Cancel)); return f.ShowDialog(owner) == DialogResult.OK; } } private class KeyBox : Label { public Keys Value; public KeyBox() { SetStyle(ControlStyles.Selectable, true); TabStop = true; BorderStyle = BorderStyle.FixedSingle; BackColor = Theme.Panel; ForeColor = Theme.Text; TextAlign = ContentAlignment.MiddleCenter; } protected override bool IsInputKey(Keys k) { return true; } protected override void OnClick(EventArgs e) { Focus(); base.OnClick(e); } protected override void OnGotFocus(EventArgs e) { Text = "Press a key..."; base.OnGotFocus(e); } protected override void OnLostFocus(EventArgs e) { ShowKey(); base.OnLostFocus(e); } public void ShowKey() { Text = Value == Keys.None ? "No key (click to set)" : KeyText.Of(Value); } protected override void OnKeyDown(KeyEventArgs e) { Keys c = e.KeyCode; e.Handled = true; e.SuppressKeyPress = true; if (c == Keys.ControlKey || c == Keys.ShiftKey || c == Keys.Menu || c == Keys.LWin || c == Keys.RWin) return; if (c == Keys.Escape) { Parent.SelectNextControl(this, true, true, true, true); return; } Value = c == Keys.Delete || c == Keys.Back ? Keys.None : e.KeyData; ShowKey(); Parent.SelectNextControl(this, true, true, true, true); } } private static ComboBox Combo(string[] items, int sel) { ComboBox c = new ComboBox(); c.DropDownStyle = ComboBoxStyle.DropDownList; c.FlatStyle = FlatStyle.Flat; c.BackColor = Theme.Panel; c.ForeColor = Theme.Text; c.Items.AddRange(items); c.SelectedIndex = Math.Max(0, Math.Min(items.Length - 1, sel)); return c; } public static bool PickKey(IWin32Window owner, string title, string what, ref Keys key) { using (Form f = Shell(title, 340)) { Label l = Text(what + "\n\nClick the box, then press a key (with Ctrl, Shift or Alt if you like). Delete clears it.", 310); l.Location = new Point(Theme.S(16), Theme.S(14)); f.Controls.Add(l); KeyBox kb = new KeyBox(); kb.Value = key; kb.ShowKey(); kb.Bounds = new Rectangle(Theme.S(16), l.Bottom + Theme.S(10), f.ClientSize.Width - Theme.S(32), Theme.S(30)); f.Controls.Add(kb); Finish(f, kb, MakeButton("OK", DialogResult.OK), MakeButton("Cancel", DialogResult.Cancel)); if (f.ShowDialog(owner) != DialogResult.OK) return false; key = kb.Value; return true; } } public static readonly string[] CondIds = { "always", "run", "bleeding", "critical", "hurt", "hungry", "trader" }; public static readonly string[] CondNames = { "Always", "Only in a run", "Only when bleeding", "Only when dying or in cardiac arrest", "Only when hurt (pain, broken or dislocated)", "Only when hungry or thirsty", "Only next to a survivor" }; private static readonly string[] ModeIds = { "on", "off", "flip" }; private static readonly string[] ModeNames = { "Turn the cheats on", "Turn the cheats off", "Flip them (on to off, off to on)" }; public static bool EditMacro(IWin32Window owner, Macro m, List