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.

237 lines
9.4 KiB

  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.Default.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 "--no-logs":
  50. CommandLineValues.WriteLogs = false;
  51. break;
  52. case "--darken-message":
  53. CommandLineValues.Debug.DarkenMessages = true;
  54. break;
  55. case "--condense-logs":
  56. CommandLineValues.Debug.CondenseModLogs = true;
  57. break;
  58. case "--plugin-logs":
  59. CommandLineValues.Debug.CreateModLogs = true;
  60. break;
  61. #if false
  62. case "--no-updates":
  63. CommandLineValues.Updates.AutoCheckUpdates = false;
  64. CommandLineValues.Updates.AutoUpdate = false;
  65. break;
  66. #endif
  67. case "--trace":
  68. CommandLineValues.Debug.ShowTrace = true;
  69. break;
  70. }
  71. }
  72. }
  73. public void CheckVersionBoundary()
  74. {
  75. if (ResetGameAssebliesOnVersionChange && Utilities.UnityGame.IsGameVersionBoundary)
  76. {
  77. GameAssemblies = GetDefaultGameAssemblies();
  78. }
  79. }
  80. internal const string IPAName = "Beat Saber IPA";
  81. internal const string IPAVersion = "4.3.1.0";
  82. // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug,
  83. // Debug.CondenseModLogs
  84. internal static SelfConfig CommandLineValues = new();
  85. // For readability's sake, I want the default values to be visible in source.
  86. #pragma warning disable CA1805 // Do not initialize unnecessarily
  87. // END: section ignore
  88. public virtual bool Regenerate { get; set; } = true;
  89. #if false
  90. public class Updates_
  91. {
  92. public virtual bool AutoUpdate { get; set; } = true;
  93. // LINE: ignore 2
  94. public static bool AutoUpdate_ => (Instance?.Updates?.AutoUpdate ?? true)
  95. && CommandLineValues.Updates.AutoUpdate;
  96. public virtual bool AutoCheckUpdates { get; set; } = true;
  97. // LINE: ignore 2
  98. public static bool AutoCheckUpdates_ => (Instance?.Updates?.AutoCheckUpdates ?? true)
  99. && CommandLineValues.Updates.AutoCheckUpdates;
  100. }
  101. // LINE: ignore
  102. [NonNullable]
  103. public virtual Updates_ Updates { get; set; } = new Updates_();
  104. #endif
  105. public class Debug_
  106. {
  107. public virtual bool ShowCallSource { get; set; } = false;
  108. // LINE: ignore 2
  109. public static bool ShowCallSource_ => (Instance?.Debug?.ShowCallSource ?? false)
  110. || CommandLineValues.Debug.ShowCallSource;
  111. public virtual bool ShowDebug { get; set; } = false;
  112. // LINE: ignore 2
  113. public static bool ShowDebug_ => (Instance?.Debug?.ShowDebug ?? false)
  114. || CommandLineValues.Debug.ShowDebug;
  115. // This option only takes effect after a full game restart, unless new logs are created again
  116. public virtual bool CondenseModLogs { get; set; } = false;
  117. // LINE: ignore 2
  118. public static bool CondenseModLogs_ => (Instance?.Debug?.CondenseModLogs ?? false)
  119. || CommandLineValues.Debug.CondenseModLogs;
  120. // This option only takes effect after a full game restart, unless new logs are created again
  121. public virtual bool CreateModLogs { get; set; } = false;
  122. // LINE: ignore 2
  123. public static bool CreateModLogs_ => (Instance?.Debug?.CreateModLogs ?? false)
  124. || CommandLineValues.Debug.CreateModLogs;
  125. public virtual bool ShowHandledErrorStackTraces { get; set; } = false;
  126. // LINE: ignore
  127. public static bool ShowHandledErrorStackTraces_ => Instance?.Debug?.ShowHandledErrorStackTraces ?? false;
  128. public virtual bool HideMessagesForPerformance { get; set; } = true;
  129. // LINE: ignore
  130. public static bool HideMessagesForPerformance_ => Instance?.Debug?.HideMessagesForPerformance ?? true;
  131. public virtual int HideLogThreshold { get; set; } = 512;
  132. // LINE: ignore
  133. public static int HideLogThreshold_ => Instance?.Debug?.HideLogThreshold ?? 512;
  134. public virtual bool ShowTrace { get; set; } = false;
  135. // LINE: ignore 2
  136. public static bool ShowTrace_ => (Instance?.Debug?.ShowTrace ?? false)
  137. || CommandLineValues.Debug.ShowTrace;
  138. public virtual bool SyncLogging { get; set; } = false;
  139. // LINE: ignore
  140. public static bool SyncLogging_ => Instance?.Debug?.SyncLogging ?? false;
  141. public virtual bool DarkenMessages { get; set; } = false;
  142. // LINE: ignore 2
  143. public static bool DarkenMessages_ => (Instance?.Debug?.DarkenMessages ?? false)
  144. || CommandLineValues.Debug.DarkenMessages;
  145. }
  146. // LINE: ignore
  147. [NonNullable]
  148. public virtual Debug_ Debug { get; set; } = new();
  149. public class AntiMalware_
  150. {
  151. public virtual bool UseIfAvailable { get; set; } = true;
  152. // LINE: ignore
  153. public static bool UseIfAvailable_ => Instance?.AntiMalware?.UseIfAvailable ?? true;
  154. public virtual bool RunPartialThreatCode { get; set; } = false;
  155. // LINE: ignore
  156. public static bool RunPartialThreatCode_ => Instance?.AntiMalware?.RunPartialThreatCode ?? true;
  157. }
  158. // LINE: ignore
  159. [NonNullable]
  160. public virtual AntiMalware_ AntiMalware { get; set; } = new();
  161. public virtual bool YeetMods { get; set; } = true;
  162. // LINE: ignore 2
  163. public static bool YeetMods_ => (Instance?.YeetMods ?? true)
  164. && CommandLineValues.YeetMods;
  165. [JsonIgnore]
  166. public bool WriteLogs { get; set; } = true;
  167. public virtual bool ResetGameAssebliesOnVersionChange { get; set; } = true;
  168. // LINE: ignore
  169. [NonNullable, UseConverter(typeof(CollectionConverter<string, HashSet<string?>>))]
  170. public virtual HashSet<string> GameAssemblies { get; set; } = GetDefaultGameAssemblies();
  171. // BEGIN: section ignore
  172. public static HashSet<string> GetDefaultGameAssemblies()
  173. => new()
  174. {
  175. #if BeatSaber // provide these defaults only for Beat Saber builds
  176. "Main.dll", "Core.dll", "HMLib.dll", "HMUI.dll", "HMRendering.dll", "VRUI.dll",
  177. "BeatmapCore.dll", "GameplayCore.dll", "HMLibAttributes.dll", "BeatmapEditor3D.dll"
  178. #else // otherwise specify Assembly-CSharp.dll
  179. "Assembly-CSharp.dll"
  180. #endif
  181. };
  182. // END: section ignore
  183. // LINE: ignore
  184. #if false // used to make schema gen happy
  185. private static HashSet<string> GetDefaultGameAssemblies() => null;
  186. // LINE: ignore
  187. #endif
  188. // LINE: ignore
  189. public static HashSet<string> GameAssemblies_ => Instance?.GameAssemblies ?? new HashSet<string> { "Assembly-CSharp.dll" };
  190. // LINE: ignore
  191. #if false // Used for documentation schema generation
  192. [JsonProperty(Required = Required.DisallowNull)]
  193. public virtual string LastGameVersion { get; set; } = null;
  194. // LINE: ignore 2
  195. #endif
  196. public virtual string? LastGameVersion { get; set; } = null;
  197. // LINE: ignore
  198. public static string? LastGameVersion_ => Instance?.LastGameVersion;
  199. }
  200. }