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.

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