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.

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