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.

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