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.

186 lines
7.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
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
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.1.6.0";
  69. // uses Updates.AutoUpdate, Updates.AutoCheckUpdates, YeetMods, Debug.ShowCallSource, Debug.ShowDebug,
  70. // Debug.CondenseModLogs
  71. internal static SelfConfig CommandLineValues = new();
  72. // END: section ignore
  73. public virtual bool Regenerate { get; set; } = true;
  74. #if false
  75. public class Updates_
  76. {
  77. public virtual bool AutoUpdate { get; set; } = true;
  78. // LINE: ignore 2
  79. public static bool AutoUpdate_ => (Instance?.Updates?.AutoUpdate ?? true)
  80. && CommandLineValues.Updates.AutoUpdate;
  81. public virtual bool AutoCheckUpdates { get; set; } = true;
  82. // LINE: ignore 2
  83. public static bool AutoCheckUpdates_ => (Instance?.Updates?.AutoCheckUpdates ?? true)
  84. && CommandLineValues.Updates.AutoCheckUpdates;
  85. }
  86. // LINE: ignore
  87. [NonNullable]
  88. public virtual Updates_ Updates { get; set; } = new Updates_();
  89. #endif
  90. public class Debug_
  91. {
  92. public virtual bool ShowCallSource { get; set; } = false;
  93. // LINE: ignore 2
  94. public static bool ShowCallSource_ => (Instance?.Debug?.ShowCallSource ?? false)
  95. || CommandLineValues.Debug.ShowCallSource;
  96. public virtual bool ShowDebug { get; set; } = false;
  97. // LINE: ignore 2
  98. public static bool ShowDebug_ => (Instance?.Debug?.ShowDebug ?? false)
  99. || CommandLineValues.Debug.ShowDebug;
  100. // This option only takes effect after a full game restart, unless new logs are created again
  101. public virtual bool CondenseModLogs { get; set; } = false;
  102. // LINE: ignore 2
  103. public static bool CondenseModLogs_ => (Instance?.Debug?.CondenseModLogs ?? false)
  104. || CommandLineValues.Debug.CondenseModLogs;
  105. // This option only takes effect after a full game restart, unless new logs are created again
  106. public virtual bool CreateModLogs { get; set; } = false;
  107. // LINE: ignore 2
  108. public static bool CreateModLogs_ => (Instance?.Debug?.CreateModLogs ?? false)
  109. || CommandLineValues.Debug.CreateModLogs;
  110. public virtual bool ShowHandledErrorStackTraces { get; set; } = false;
  111. // LINE: ignore
  112. public static bool ShowHandledErrorStackTraces_ => Instance?.Debug?.ShowHandledErrorStackTraces ?? false;
  113. public virtual bool HideMessagesForPerformance { get; set; } = true;
  114. // LINE: ignore
  115. public static bool HideMessagesForPerformance_ => Instance?.Debug?.HideMessagesForPerformance ?? true;
  116. public virtual int HideLogThreshold { get; set; } = 512;
  117. // LINE: ignore
  118. public static int HideLogThreshold_ => Instance?.Debug?.HideLogThreshold ?? 512;
  119. public virtual bool ShowTrace { get; set; } = false;
  120. // LINE: ignore 2
  121. public static bool ShowTrace_ => (Instance?.Debug?.ShowTrace ?? false)
  122. || CommandLineValues.Debug.ShowTrace;
  123. public virtual bool SyncLogging { get; set; } = false;
  124. // LINE: ignore
  125. public static bool SyncLogging_ => Instance?.Debug?.SyncLogging ?? false;
  126. }
  127. // LINE: ignore
  128. [NonNullable]
  129. public virtual Debug_ Debug { get; set; } = new Debug_();
  130. public virtual bool YeetMods { get; set; } = true;
  131. // LINE: ignore 2
  132. public static bool YeetMods_ => (Instance?.YeetMods ?? true)
  133. && CommandLineValues.YeetMods;
  134. // LINE: ignore
  135. [NonNullable, UseConverter(typeof(CollectionConverter<string, HashSet<string>>))]
  136. public virtual HashSet<string> GameAssemblies { get; set; } = new HashSet<string>
  137. {
  138. // LINE: ignore 5
  139. #if BeatSaber // provide these defaults only for Beat Saber builds
  140. "Main.dll", "Core.dll", "HMLib.dll", "HMUI.dll", "HMRendering.dll", "VRUI.dll",
  141. "BeatmapCore.dll", "GameplayCore.dll","HMLibAttributes.dll",
  142. #else // otherwise specify Assembly-CSharp.dll
  143. "Assembly-CSharp.dll"
  144. // LINE: ignore
  145. #endif
  146. };
  147. // LINE: ignore
  148. public static HashSet<string> GameAssemblies_ => Instance?.GameAssemblies ?? new HashSet<string> { "Assembly-CSharp.dll" };
  149. // LINE: ignore
  150. #if false // Used for documentation schema generation
  151. [JsonProperty(Required = Required.DisallowNull)]
  152. public virtual string LastGameVersion { get; set; } = null;
  153. // LINE: ignore 2
  154. #endif
  155. public virtual string? LastGameVersion { get; set; } = null;
  156. // LINE: ignore
  157. public static string? LastGameVersion_ => Instance?.LastGameVersion;
  158. }
  159. }