using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using CG.GameLoopStateMachine; using CG.GameLoopStateMachine.GameStates; using CG.Profile; using Client.Utils; using Gameplay.Hub; using Gameplay.Quests; using HarmonyLib; using Microsoft.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Photon.Pun; using PlatformAbstractionLayer; using ResourceAssets; using ToolClasses; using UI; using UI.Core.Audio; using UnityEngine; using UnityEngine.UIElements; using VoidManager; using VoidManager.CustomGUI; using VoidManager.MPModChecks; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Quickstart")] [assembly: AssemblyDescription("Adds a Quickstart option to the main menu that drops you straight into a solo pilgrimage on a chosen ship loadout, skipping the hub entirely.")] [assembly: AssemblyProduct("Quickstart")] [assembly: AssemblyCompany("Jack")] [assembly: AssemblyFileVersion("0.2.1.0")] [assembly: ComVisible(false)] [assembly: AssemblyMetadata("ModCategories", "Quality of Life, Client-Side")] [assembly: AssemblyMetadata("MPType", "Client")] [assembly: AssemblyMetadata("ProgressionFlag", "enabled")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("0.2.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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; } } } internal static class MenuKit { private static readonly Dictionary foldouts = new Dictionary(); private static readonly HashSet loggedFailures = new HashSet(); public static void Header(string text) { GUILayout.Space(10f); GUILayout.Label("" + text + "", Array.Empty()); } public static void Rule() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0042: 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) GUILayout.Space(6f); Rect rect = GUILayoutUtility.GetRect(1f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) }); Color color = GUI.color; GUI.color = new Color(1f, 1f, 1f, 0.25f); GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture); GUI.color = color; GUILayout.Space(6f); } public static bool Foldout(string id, string label) { foldouts.TryGetValue(id, out var value); if (GUILayout.Button((value ? "[-] " : "[+] ") + label, Array.Empty())) { value = !value; foldouts[id] = value; } return value; } public static void DevZone(string id, Action body) { if (!Configs.IsDebugMode) { return; } GUILayout.Space(12f); Rule(); if (!Foldout(id + ".dev", "Developer tools")) { return; } GUILayout.BeginVertical(GUI.skin.box, Array.Empty()); try { body(); } catch (Exception ex) { GUILayout.Label("Dev section failed: " + ex.Message + " (see log)", Array.Empty()); if (loggedFailures.Add(id)) { Debug.LogError((object)("[MenuKit] dev zone '" + id + "' threw: " + ex)); } } finally { GUILayout.EndVertical(); } } } internal static class ModFlagPolicy { internal const bool FlagsSession = true; internal const MultiplayerType MPType = (MultiplayerType)20; internal const SessionModificationEffect NetworkSpawnedEffect = (SessionModificationEffect)2; internal const SessionModificationEffect RequiredEffect = (SessionModificationEffect)94; internal const string BuildTag = "enabled"; } internal static class StatContrib { internal enum Kind { Additive, Multiplicative, Override } private const string SlotKey = "jack.voidcrew.statcontrib.v1"; internal static ManualLogSource Log; private static object[] Root() { object[] array = AppDomain.CurrentDomain.GetData("jack.voidcrew.statcontrib.v1") as object[]; if (array == null) { array = new object[2] { new object(), new Dictionary() }; AppDomain.CurrentDomain.SetData("jack.voidcrew.statcontrib.v1", array); } return array; } internal static bool Set(object target, string field, string ownerId, Func getter, Action setter, Kind kind, float value, Func alive = null) { if (target == null || string.IsNullOrEmpty(field) || string.IsNullOrEmpty(ownerId) || getter == null || setter == null) { Error("StatContrib.Set called with a null argument (field '" + field + "', owner '" + ownerId + "') - ignored."); return false; } if (float.IsNaN(value) || float.IsInfinity(value)) { Error("StatContrib.Set: owner '" + ownerId + "' offered a non-finite value for '" + field + "' - ignored."); return false; } try { object[] array = Root(); lock (array[0]) { Dictionary dictionary = (Dictionary)array[1]; object value2; Dictionary dictionary2 = (Dictionary)(dictionary.TryGetValue(target, out value2) ? ((Dictionary)value2) : (dictionary[target] = new Dictionary())); object[] array2; if (dictionary2.TryGetValue(field, out value2)) { array2 = (object[])value2; } else { array2 = (object[])(dictionary2[field] = new object[4] { getter(), getter, setter, new List() }); Info("captured base " + ((float)array2[0]).ToString("0.####") + " for " + Describe(target, field)); } List list = (List)array2[3]; object[] array3 = null; for (int i = 0; i < list.Count; i++) { if ((string)list[i][0] == ownerId) { array3 = list[i]; break; } } if (array3 == null) { array3 = new object[4] { ownerId, null, null, null }; list.Add(array3); } array3[1] = alive; array3[2] = (int)kind; array3[3] = value; Recompute(dictionary2, field, array2); SweepDeadOwners(dictionary, target, field); } return true; } catch (Exception ex) { Error("StatContrib.Set('" + field + "', '" + ownerId + "') threw: " + ex); return false; } } internal static void Remove(object target, string field, string ownerId) { if (target == null || string.IsNullOrEmpty(field) || string.IsNullOrEmpty(ownerId)) { return; } try { object[] array = Root(); lock (array[0]) { Dictionary dictionary = (Dictionary)array[1]; if (!dictionary.TryGetValue(target, out var value)) { return; } Dictionary dictionary2 = (Dictionary)value; if (!dictionary2.TryGetValue(field, out value)) { return; } object[] array2 = (object[])value; List list = (List)array2[3]; bool flag = false; for (int num = list.Count - 1; num >= 0; num--) { if ((string)list[num][0] == ownerId) { list.RemoveAt(num); flag = true; } } if (flag) { Recompute(dictionary2, field, array2); if (!dictionary2.ContainsKey(field) && dictionary2.Count == 0) { dictionary.Remove(target); } SweepDeadOwners(dictionary, target, field); } } } catch (Exception ex) { Error("StatContrib.Remove('" + field + "', '" + ownerId + "') threw: " + ex); } } internal static string DescribeField(object target, string field) { try { object[] array = Root(); lock (array[0]) { Dictionary dictionary = (Dictionary)array[1]; if (target == null || !dictionary.TryGetValue(target, out var value)) { return null; } if (!((Dictionary)value).TryGetValue(field, out value)) { return null; } object[] array2 = (object[])value; List list = (List)array2[3]; string text = field + ": base " + ((float)array2[0]).ToString("0.####"); for (int i = 0; i < list.Count; i++) { text = text + ", " + (string)list[i][0] + " " + ((Kind)(int)list[i][2]/*cast due to .constrained prefix*/).ToString() + " " + ((float)list[i][3]).ToString("0.####"); } return text; } } catch { return null; } } private static void Recompute(Dictionary byField, string field, object[] entry) { List list = (List)entry[3]; for (int num = list.Count - 1; num >= 0; num--) { Func func = list[num][1] as Func; bool flag = true; if (func != null) { try { flag = func(); } catch { flag = false; } } if (!flag) { Info("dropping contribution '" + (string)list[num][0] + "' to '" + field + "' - its owner is gone."); list.RemoveAt(num); } } float num2 = (float)entry[0]; Action setter = (Action)entry[2]; if (list.Count == 0) { byField.Remove(field); TryWrite(setter, num2, field, "base restore"); return; } float num3 = num2; float num4 = 1f; object[] array = null; for (int i = 0; i < list.Count; i++) { float num5 = (float)list[i][3]; switch ((Kind)(int)list[i][2]) { case Kind.Additive: num3 += num5; break; case Kind.Multiplicative: num4 *= num5; break; case Kind.Override: array = list[i]; break; } } float num6; if (array != null) { num6 = (float)array[3]; if (list.Count > 1) { Info("override '" + (string)array[0] + "' wins '" + field + "' over " + (list.Count - 1) + " other contribution(s)."); } } else { num6 = num3 * num4; } if (float.IsNaN(num6) || float.IsInfinity(num6)) { Error("composed value for '" + field + "' is non-finite; writing the base back instead. " + DescribeEntry(field, entry)); num6 = num2; } TryWrite(setter, num6, field, "recompute"); } private static void SweepDeadOwners(Dictionary entries, object exceptTarget, string exceptField) { List list = null; foreach (KeyValuePair entry in entries) { Dictionary dictionary = (Dictionary)entry.Value; List list2 = null; foreach (KeyValuePair item in dictionary) { if (entry.Key == exceptTarget && item.Key == exceptField) { continue; } List list3 = (List)((object[])item.Value)[3]; for (int i = 0; i < list3.Count; i++) { Func func = list3[i][1] as Func; bool flag = true; if (func != null) { try { flag = func(); } catch { flag = false; } } if (!flag) { List obj2 = list2 ?? new List(); list2 = obj2; obj2.Add(item.Key); break; } } } if (list2 != null) { for (int j = 0; j < list2.Count; j++) { Recompute(dictionary, list2[j], (object[])dictionary[list2[j]]); } } if (dictionary.Count == 0) { List obj3 = list ?? new List(); list = obj3; obj3.Add(entry.Key); } } if (list != null) { for (int k = 0; k < list.Count; k++) { entries.Remove(list[k]); } } } private static void TryWrite(Action setter, float value, string field, string why) { try { setter(value); } catch (Exception ex) { Info("write to '" + field + "' (" + why + ") failed: " + ex.Message); } } private static string Describe(object target, string field) { string text; try { text = target.GetType().Name; } catch { text = ""; } return text + "." + field; } private static string DescribeEntry(string field, object[] entry) { List list = (List)entry[3]; string text = "base " + ((float)entry[0]).ToString("0.####") + ";"; for (int i = 0; i < list.Count; i++) { text = text + " " + (string)list[i][0] + "=" + ((Kind)(int)list[i][2]/*cast due to .constrained prefix*/).ToString() + ":" + ((float)list[i][3]).ToString("0.####"); } return text; } private static void Info(string m) { if (Log != null) { Log.LogInfo((object)("StatContrib: " + m)); } } private static void Error(string m) { if (Log != null) { Log.LogError((object)("StatContrib: " + m)); } } } internal interface ITuningKnob { string Name { get; } string Help { get; } bool IsInert { get; } void WriteJson(JObject o); void ReadJson(JObject o); string Describe(); void DrawMenuRow(); string BakeSnippet(); } internal sealed class TuningFile { private readonly string _guid; private readonly string _tag; private readonly string _readme; private readonly ManualLogSource _log; private readonly List _order = new List(); private readonly Dictionary _byName = new Dictionary(StringComparer.OrdinalIgnoreCase); private readonly List _reloadHandlers = new List(); private DateTime _lastWrite = DateTime.MinValue; private JObject _baseline; private JObject _previousBaseline; internal string LastBakePath = ""; private string _menuSignature; internal string Status { get; private set; } = "not loaded"; internal string Path { get; private set; } internal string BaselinePath { get; private set; } internal IList Knobs => _order; internal bool AllInert { get { for (int i = 0; i < _order.Count; i++) { if (!_order[i].IsInert) { return false; } } return true; } } internal TuningFile(string pluginGuid, string logTag, string readme, ManualLogSource log) { _guid = pluginGuid; _tag = logTag; _readme = readme; _log = log; } internal T Add(T knob) where T : ITuningKnob { if (knob == null) { return default(T); } if (_byName.ContainsKey(knob.Name)) { Warn("duplicate tuning knob '" + knob.Name + "' ignored. Two declarations of one name means one of them is silently dead."); return knob; } _byName[knob.Name] = knob; _order.Add(knob); return knob; } internal ITuningKnob Find(string name) { if (!_byName.TryGetValue(name, out var value)) { return null; } return value; } internal void OnReload(Action handler) { if (handler != null && !_reloadHandlers.Contains(handler)) { _reloadHandlers.Add(handler); } } internal void Initialise(string configDir) { try { Path = System.IO.Path.Combine(configDir, _guid + ".tuning.json"); BaselinePath = System.IO.Path.Combine(configDir, _guid + ".tuning.baseline.json"); _baseline = BuildKnobObject(); _previousBaseline = ReadPreviousBaseline(); WriteBaseline(); if (!File.Exists(Path)) { Save("created at the declared defaults"); } else { Load(); } } catch (Exception e) { Status = "FAILED to initialise: " + Brief(e); Error(Status); } } internal bool PollForChanges() { if (string.IsNullOrEmpty(Path)) { return false; } try { if (!File.Exists(Path)) { return false; } if (File.GetLastWriteTimeUtc(Path) <= _lastWrite) { return false; } Load(); Info("tuning reloaded - " + Status); FireReloadHandlers(); return true; } catch (Exception e) { Warn("tuning poll threw: " + Brief(e)); return false; } } private void FireReloadHandlers() { for (int i = 0; i < _reloadHandlers.Count; i++) { try { _reloadHandlers[i](); } catch (Exception ex) { Error("a tuning re-apply handler threw: " + ex); } } } private void Load() { string text; try { text = File.ReadAllText(Path); } catch (Exception e) { Status = "could not read the file (" + Brief(e) + "); previous values stand"; Error(Status); return; } _lastWrite = File.GetLastWriteTimeUtc(Path); JObject val; try { val = JObject.Parse(text); } catch (Exception e2) { Status = "MALFORMED tuning file (" + Brief(e2) + "); previous values stand"; Error(Status + ". Fix " + Path + " - nothing was applied from it."); return; } JToken obj = val["knobs"]; JObject val2 = (JObject)(object)((obj is JObject) ? obj : null); if (val2 == null) { Status = "tuning file has no 'knobs' object; every knob left at its declared default"; Warn(Status); return; } int num = 0; int num2 = 0; int num3 = 0; int num4 = 0; foreach (KeyValuePair item in val2) { if (!_byName.TryGetValue(item.Key, out var value)) { num2++; Warn("tuning file names unknown knob '" + item.Key + "' - ignored. This is a typo or a rename, not a tuning value."); continue; } JToken value2 = item.Value; JObject val3 = (JObject)(object)((value2 is JObject) ? value2 : null); if (val3 == null) { continue; } if (FollowsNewDeclaration(item.Key, val3)) { num4++; num++; continue; } try { value.ReadJson(val3); } catch (Exception e3) { Warn("knob '" + item.Key + "' could not be read: " + Brief(e3)); } num++; if (!value.IsInert) { num3++; } } Status = num + " knob(s) read, " + num3 + " active" + ((num2 > 0) ? (", " + num2 + " unknown name(s) ignored") : "") + ((num4 > 0) ? (", " + num4 + " untouched knob(s) moved to this build's new declared value") : ""); if (num3 == 0) { Status += " - every knob inert"; } int count = DriftReport().Count; if (count > 0) { Status = Status + "; " + count + " differ(s) from source"; } if (num2 > 0 || num < _order.Count || num4 > 0) { string status = Status; Save("rewritten to match this version's knobs (" + (_order.Count - num) + " added, " + num2 + " stale name(s) dropped)"); Status = status + "; file rewritten to match this version's knobs"; } } private JObject ReadPreviousBaseline() { try { if (!File.Exists(BaselinePath)) { return null; } JToken obj = JObject.Parse(File.ReadAllText(BaselinePath))["knobs"]; return (JObject)(object)((obj is JObject) ? obj : null); } catch { return null; } } private bool FollowsNewDeclaration(string name, JObject fromFile) { if (_previousBaseline == null || _baseline == null) { return false; } JToken obj = _previousBaseline[name]; JObject val = (JObject)(object)((obj is JObject) ? obj : null); JToken obj2 = _baseline[name]; JObject val2 = (JObject)(object)((obj2 is JObject) ? obj2 : null); if (val == null || val2 == null) { return false; } if (JToken.DeepEquals((JToken)(object)val, (JToken)(object)val2)) { return false; } return JToken.DeepEquals((JToken)(object)val, (JToken)(object)fromFile); } internal void Save(string why) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown try { JObject val = new JObject(); val["_readme"] = JToken.op_Implicit(_readme + " The '_' field in each knob is a comment and is ignored. Saved changes are picked up within a second - no restart. This file is NOT shipped: values dialled in here reach nobody else until they are written back into the mod's source declarations."); val["knobs"] = (JToken)(object)BuildKnobObject(); EnsureDir(Path); File.WriteAllText(Path, ((JToken)val).ToString((Formatting)1, Array.Empty())); _lastWrite = File.GetLastWriteTimeUtc(Path); Status = why; Info("tuning file " + why + " -> " + Path); } catch (Exception e) { Status = "could not write the tuning file: " + Brief(e); Error(Status); } } private JObject BuildKnobObject() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Expected O, but got Unknown JObject val = new JObject(); for (int i = 0; i < _order.Count; i++) { ITuningKnob tuningKnob = _order[i]; JObject val2 = new JObject(); val2["_"] = JToken.op_Implicit(tuningKnob.Help); tuningKnob.WriteJson(val2); val[tuningKnob.Name] = (JToken)(object)val2; } return val; } private void WriteBaseline() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown try { JObject val = new JObject(); val["_readme"] = JToken.op_Implicit("Generated every launch. These are the knob values as DECLARED IN SOURCE, which is what a build handed to anyone else runs at. Diff the sibling .tuning.json against this to see which dialled-in numbers would be lost by shipping. Do not edit; edit the source declarations and relaunch."); val["knobs"] = (JToken)(object)_baseline; EnsureDir(BaselinePath); File.WriteAllText(BaselinePath, ((JToken)val).ToString((Formatting)1, Array.Empty())); } catch (Exception e) { Warn("could not write the tuning baseline (" + Brief(e) + "). The release drift check has nothing to compare against for this mod."); } } internal List DriftReport() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown List list = new List(); if (_baseline == null) { return list; } for (int i = 0; i < _order.Count; i++) { ITuningKnob tuningKnob = _order[i]; JObject val = new JObject(); tuningKnob.WriteJson(val); JToken obj = _baseline[tuningKnob.Name]; JObject val2 = (JObject)(object)((obj is JObject) ? obj : null); if (val2 == null) { continue; } foreach (KeyValuePair item in val) { JToken val3 = val2[item.Key]; if (val3 != null && !JToken.DeepEquals(val3, item.Value)) { list.Add(tuningKnob.Name + "." + item.Key + ": source " + ((object)val3)?.ToString() + " -> live " + (object)item.Value); } } } return list; } internal string WriteBakeSnippet(string outputDir) { try { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("// " + _tag + " - tuning bake, taken from the live tuning file."); stringBuilder.AppendLine("//"); stringBuilder.AppendLine("// Paste over the knob declarations. After this the declared defaults"); stringBuilder.AppendLine("// and the tuning file agree, the drift check is clean, and a build"); stringBuilder.AppendLine("// handed to anyone else plays at the numbers you dialled in."); stringBuilder.AppendLine("//"); stringBuilder.AppendLine("// Source : " + (Path ?? "")); stringBuilder.AppendLine("// State : " + Status); stringBuilder.AppendLine(); for (int i = 0; i < _order.Count; i++) { stringBuilder.AppendLine(_order[i].BakeSnippet()); } List list = DriftReport(); stringBuilder.AppendLine(); if (list.Count == 0) { stringBuilder.AppendLine("// Nothing has drifted - source already matches the tuning file."); } else { stringBuilder.AppendLine("// Differs from source (" + list.Count + "):"); for (int j = 0; j < list.Count; j++) { stringBuilder.AppendLine("// " + list[j]); } } string text = System.IO.Path.Combine(outputDir, _guid + ".tuning.bake.cs.txt"); EnsureDir(text); File.WriteAllText(text, stringBuilder.ToString()); Info("tuning bake snippet -> " + text); return text; } catch (Exception ex) { Error("tuning bake snippet threw: " + ex); return ""; } } internal void DrawMenu() { try { GUILayout.Label("Tuning : " + Status, Array.Empty()); GUILayout.Label(" " + (Path ?? ""), Array.Empty()); for (int i = 0; i < _order.Count; i++) { _order[i].DrawMenuRow(); } string text = MenuSignature(); if (_menuSignature == null) { _menuSignature = text; } else if (text != _menuSignature) { _menuSignature = text; FireReloadHandlers(); } List list = DriftReport(); GUILayout.Space(6f); if (list.Count == 0) { GUILayout.Label("Source and tuning file agree - safe to package.", Array.Empty()); } else { GUILayout.Label("NOT IN SOURCE (" + list.Count + ") - a build sent to anyone else", Array.Empty()); GUILayout.Label("would run at the source values, not these:", Array.Empty()); for (int j = 0; j < list.Count; j++) { GUILayout.Label(" " + list[j], Array.Empty()); } } GUILayout.Space(4f); if (GUILayout.Button("Save these values to the tuning file", Array.Empty())) { Save("saved from the F5 menu"); } if (GUILayout.Button("Reload the tuning file now", Array.Empty())) { _lastWrite = DateTime.MinValue; PollForChanges(); } if (GUILayout.Button("Write the bake snippet (the release step)", Array.Empty())) { LastBakePath = WriteBakeSnippet(Paths.ConfigPath); } GUILayout.Label(" " + LastBakePath, Array.Empty()); } catch (Exception e) { GUILayout.Label("Tuning menu failed to draw: " + Brief(e), Array.Empty()); } } private string MenuSignature() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < _order.Count; i++) { JObject val = new JObject(); _order[i].WriteJson(val); stringBuilder.Append(((JToken)val).ToString((Formatting)0, Array.Empty())); } return stringBuilder.ToString(); } private static void EnsureDir(string file) { string directoryName = System.IO.Path.GetDirectoryName(file); if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } } private static string Brief(Exception e) { if (e != null) { return e.GetType().Name + ": " + e.Message; } return ""; } private void Info(string m) { if (_log != null) { _log.LogInfo((object)(_tag + ": " + m)); } } private void Warn(string m) { if (_log != null) { _log.LogWarning((object)(_tag + ": " + m)); } } private void Error(string m) { if (_log != null) { _log.LogError((object)(_tag + ": " + m)); } } internal static string F(float v) { return v.ToString("0.####", CultureInfo.InvariantCulture); } } internal sealed class TuningScalar : ITuningKnob { public float Value; public readonly float Declared; public readonly float Min; public readonly float Max; public readonly float Sentinel; private readonly NumericField _field = new NumericField(); public string Name { get; private set; } public string Help { get; private set; } public bool IsInert { get { if (!float.IsNaN(Sentinel) && Nearly(Value, Sentinel)) { return true; } return Nearly(Value, Declared); } } public bool IsSentinel { get { if (!float.IsNaN(Sentinel)) { return Nearly(Value, Sentinel); } return false; } } internal TuningScalar(string name, string help, float declared, float min, float max, float sentinel = float.NaN) { Name = name; Help = help; Value = declared; Declared = declared; Min = min; Max = max; Sentinel = sentinel; } public void WriteJson(JObject o) { o["value"] = JToken.op_Implicit(Value); } public void ReadJson(JObject o) { JToken val = o["value"]; if (val == null) { return; } try { float num = Extensions.Value((IEnumerable)val); if (!float.IsNaN(num) && !float.IsInfinity(num)) { Value = num; } } catch { } } public string Describe() { if (!IsSentinel) { return TuningFile.F(Value); } return "keep the game's own value"; } public void DrawMenuRow() { GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label(Name + " " + Describe(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(280f) }); Value = _field.Draw(Value); Value = GUILayout.HorizontalSlider(Value, Min, Max, Array.Empty()); GUILayout.EndHorizontal(); } public string BakeSnippet() { string text = (float.IsNaN(Sentinel) ? "" : (", " + TuningFile.F(Sentinel) + "f")); return "Scalar(\"" + Name + "\", \"" + Help.Replace("\"", "\\\"") + "\", " + TuningFile.F(Value) + "f, " + TuningFile.F(Min) + "f, " + TuningFile.F(Max) + "f" + text + ");"; } private static bool Nearly(float a, float b) { return Math.Abs(a - b) < 0.0001f; } } internal sealed class TuningString : ITuningKnob { public string Value; public readonly string Declared; public string Name { get; private set; } public string Help { get; private set; } public bool HasValue => !string.IsNullOrEmpty(Value); public bool IsInert => string.Equals(Value, Declared, StringComparison.Ordinal); internal TuningString(string name, string help, string declared) { Name = name; Help = help; Value = declared ?? ""; Declared = declared ?? ""; } public void WriteJson(JObject o) { o["text"] = JToken.op_Implicit(Value ?? ""); } public void ReadJson(JObject o) { JToken val = o["text"]; if (val == null) { return; } try { string text = Extensions.Value((IEnumerable)val); Value = (text ?? "").Trim(); } catch { } } public string Describe() { if (!HasValue) { return "the game's own choice"; } return Value; } public void DrawMenuRow() { GUILayout.BeginHorizontal(Array.Empty()); GUILayout.Label(Name, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(280f) }); Value = GUILayout.TextField(Value ?? "", Array.Empty()) ?? ""; GUILayout.EndHorizontal(); } public string BakeSnippet() { return "Text(\"" + Name + "\", \"" + Help.Replace("\"", "\\\"") + "\", \"" + (Value ?? "").Replace("\\", "\\\\").Replace("\"", "\\\"") + "\");"; } } internal sealed class NumericField { private string _text; private float _synced = float.NaN; internal float Draw(float value, float width = 64f, bool integer = false) { if (_text == null || value != _synced) { _text = (integer ? ((int)Math.Round(value)).ToString(CultureInfo.InvariantCulture) : TuningFile.F(value)); _synced = value; } string text = GUILayout.TextField(_text, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(width) }); if (text == _text) { return value; } _text = text; if (!float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var result)) { return value; } if (float.IsNaN(result) || float.IsInfinity(result)) { return value; } if (integer) { result = (float)Math.Round(result); } _synced = result; return result; } } internal sealed class TuningToggle : ITuningKnob { public bool Value; public readonly bool Declared; public string Name { get; private set; } public string Help { get; private set; } public bool IsInert => Value == Declared; internal TuningToggle(string name, string help, bool declared) { Name = name; Help = help; Value = declared; Declared = declared; } public void WriteJson(JObject o) { o["on"] = JToken.op_Implicit(Value); } public void ReadJson(JObject o) { JToken val = o["on"]; if (val == null) { return; } try { Value = Extensions.Value((IEnumerable)val); } catch { } } public string Describe() { if (!Value) { return "off"; } return "on"; } public void DrawMenuRow() { Value = GUILayout.Toggle(Value, " " + Name + " - " + Help, Array.Empty()); } public string BakeSnippet() { return "Toggle(\"" + Name + "\", \"" + Help.Replace("\"", "\\\"") + "\", " + (Value ? "true" : "false") + ");"; } } namespace VoidCrewQuickstart { internal static class MenuInjection { [HarmonyPatch(typeof(MainMenu), "StartAsTitleMenu")] internal static class Patch_MainMenu_StartAsTitleMenu { [HarmonyPostfix] private static void Postfix(MainMenu __instance) { try { Inject(Traverse.Create((object)__instance).Field("_mainmenuRoot").GetValue()); } catch (Exception ex) { Plugin.Log.LogError((object)("Quickstart: injection at StartAsTitleMenu failed: " + ex)); } } } [HarmonyPatch(typeof(TitleMenu), "OnEnter")] internal static class Patch_TitleMenu_OnEnter { [HarmonyPostfix] private static void Postfix(TitleMenu __instance) { try { UIDocument value = Traverse.Create((object)__instance).Field("UIDoc").GetValue(); if (!((Object)(object)value == (Object)null)) { Inject(value.rootVisualElement); } } catch (Exception ex) { Plugin.Log.LogError((object)("Quickstart: injection at TitleMenu.OnEnter failed: " + ex)); } } } private const string PICKING_IGNORE = "picking-mode-setter-ignore"; private static bool _loggedInject; private static MethodInfo[] _gameReadyChecks; private static bool _loggedReadyFailure; public static void Inject(VisualElement root) { if (root == null || !QuickstartConfig.Enabled.Value) { return; } Button val = UQueryExtensions.Q