You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
7.1 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. // BEGIN: section ignore
  2. #nullable enable
  3. using IPA.Logging;
  4. using IPA.Config.Stores;
  5. using IPA.Config.Stores.Attributes;
  6. using IPA.Config.Stores.Converters;
  7. // END: section ignore
  8. using Newtonsoft.Json;
  9. using System.Collections.Generic;
  10. namespace IPA.Config
  11. {
  12. internal class SelfConfig
  13. {
  14. // This is to allow the doc generation to parse this file and use Newtonsoft to generate a JSON schema
  15. // BEGIN: section ignore
  16. public static Config LoaderConfig { get; set; } = null!; // this is set before used
  17. public static SelfConfig Instance = new();
  18. public static void Load()
  19. {
  20. LoaderConfig = Config.GetConfigFor(IPAName, "json");
  21. Instance = LoaderConfig.Generated<SelfConfig>();
  22. Instance.OnReload();
  23. }
  24. protected virtual void CopyFrom(SelfConfig cfg) { }
  25. protected internal virtual void OnReload()
  26. {
  27. if (Regenerate)
  28. CopyFrom(new SelfConfig { Regenerate = false });
  29. StandardLogger.Configure();
  30. }
  31. protected internal virtual void Changed()
  32. {
  33. Logger.log.Debug("SelfConfig Changed called");
  34. }
  35. public static void ReadCommandLine(string[] args)
  36. {
  37. foreach (var arg in args)
  38. {
  39. switch (arg)
  40. {
  41. case "--debug":
  42. case "--mono-debug":
  43. CommandLineValues.Debug.ShowDebug = true;
  44. CommandLineValues.Debug.ShowCallSource = true;
  45. break;
  46. case "--no-yeet":
  47. CommandLineValues.YeetMods = false;
  48. break;
  49. case "--condense-logs":
  50. CommandLineValues.Debug.CondenseModLogs = true;
  51. break;
  52. #if false
  53. case "--no-updates":
  54. CommandLineValues.Updates.AutoCheckUpdates = false;
  55. CommandLineValues.Updates.AutoUpdate = false;
  56. break;
  57. #endif
  58. case "--trace":
  59. CommandLineValues.Debug.ShowTrace = true;
  60. break;
  61. }
  62. }
  63. }
  64. internal const string IPAName = "Beat Saber IPA";
  65. internal const string IPAVersion = "4.1.6.0";
  66. // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug,
  67. // Debug.CondenseModLogs
  68. internal static SelfConfig CommandLineValues = new();
  69. // END: section ignore
  70. public virtual bool Regenerate { get; set; } = true;
  71. #if false
  72. public class Updates_
  73. {
  74. public virtual bool AutoUpdate { get; set; } = true;
  75. // LINE: ignore 2
  76. public static bool AutoUpdate_ => (Instance?.Updates?.AutoUpdate ?? true)
  77. && CommandLineValues.Updates.AutoUpdate;
  78. public virtual bool AutoCheckUpdates { get; set; } = true;
  79. // LINE: ignore 2
  80. public static bool AutoCheckUpdates_ => (Instance?.Updates?.AutoCheckUpdates ?? true)
  81. && CommandLineValues.Updates.AutoCheckUpdates;
  82. }
  83. // LINE: ignore
  84. [NonNullable]
  85. public virtual Updates_ Updates { get; set; } = new Updates_();
  86. #endif
  87. public class Debug_
  88. {
  89. public virtual bool ShowCallSource { get; set; } = false;
  90. // LINE: ignore 2
  91. public static bool ShowCallSource_ => (Instance?.Debug?.ShowCallSource ?? false)
  92. || CommandLineValues.Debug.ShowCallSource;
  93. public virtual bool ShowDebug { get; set; } = false;
  94. // LINE: ignore 2
  95. public static bool ShowDebug_ => (Instance?.Debug?.ShowDebug ?? false)
  96. || CommandLineValues.Debug.ShowDebug;
  97. // This option only takes effect after a full game restart, unless new logs are created again
  98. public virtual bool CondenseModLogs { get; set; } = false;
  99. // LINE: ignore 2
  100. public static bool CondenseModLogs_ => (Instance?.Debug?.CondenseModLogs ?? false)
  101. || CommandLineValues.Debug.CondenseModLogs;
  102. public virtual bool ShowHandledErrorStackTraces { get; set; } = false;
  103. // LINE: ignore
  104. public static bool ShowHandledErrorStackTraces_ => Instance?.Debug?.ShowHandledErrorStackTraces ?? false;
  105. public virtual bool HideMessagesForPerformance { get; set; } = true;
  106. // LINE: ignore
  107. public static bool HideMessagesForPerformance_ => Instance?.Debug?.HideMessagesForPerformance ?? true;
  108. public virtual int HideLogThreshold { get; set; } = 512;
  109. // LINE: ignore
  110. public static int HideLogThreshold_ => Instance?.Debug?.HideLogThreshold ?? 512;
  111. public virtual bool ShowTrace { get; set; } = false;
  112. // LINE: ignore 2
  113. public static bool ShowTrace_ => (Instance?.Debug?.ShowTrace ?? false)
  114. || CommandLineValues.Debug.ShowTrace;
  115. public virtual bool SyncLogging { get; set; } = false;
  116. // LINE: ignore
  117. public static bool SyncLogging_ => Instance?.Debug?.SyncLogging ?? false;
  118. }
  119. // LINE: ignore
  120. [NonNullable]
  121. public virtual Debug_ Debug { get; set; } = new Debug_();
  122. public virtual bool YeetMods { get; set; } = true;
  123. // LINE: ignore 2
  124. public static bool YeetMods_ => (Instance?.YeetMods ?? true)
  125. && CommandLineValues.YeetMods;
  126. // LINE: ignore
  127. [NonNullable, UseConverter(typeof(CollectionConverter<string, HashSet<string>>))]
  128. public virtual HashSet<string> GameAssemblies { get; set; } = new HashSet<string>
  129. {
  130. // LINE: ignore 5
  131. #if BeatSaber // provide these defaults only for Beat Saber builds
  132. "Main.dll", "Core.dll", "HMLib.dll", "HMUI.dll", "HMRendering.dll", "VRUI.dll",
  133. "BeatmapCore.dll", "GameplayCore.dll","HMLibAttributes.dll",
  134. #else // otherwise specify Assembly-CSharp.dll
  135. "Assembly-CSharp.dll"
  136. // LINE: ignore
  137. #endif
  138. };
  139. // LINE: ignore
  140. public static HashSet<string> GameAssemblies_ => Instance?.GameAssemblies ?? new HashSet<string> { "Assembly-CSharp.dll" };
  141. [JsonProperty(Required = Required.DisallowNull)] // Used for documentation schema generation
  142. // LINE: ignore
  143. #if false
  144. public virtual string LastGameVersion { get; set; } = null;
  145. // LINE: ignore 2
  146. #endif
  147. public virtual string? LastGameVersion { get; set; } = null;
  148. // LINE: ignore
  149. public static string? LastGameVersion_ => Instance?.LastGameVersion;
  150. }
  151. }