From 0b8285bd700f7e9df117d86445d7a0b5ed90ae43 Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Tue, 22 Dec 2020 16:14:40 +0100 Subject: [PATCH 1/4] debug mode, writes everything to console if enabled --- src/OWML.Common/Interfaces/IOwmlConfig.cs | 2 ++ src/OWML.Common/MessageType.cs | 4 ++- src/OWML.Common/OwmlConfig.cs | 3 ++ src/OWML.Launcher/OWML.DefaultConfig.json | 1 + src/OWML.Launcher/Program.cs | 2 +- src/OWML.Logging/ConsoleUtils.cs | 1 + src/OWML.Logging/ModLogger.cs | 2 ++ src/OWML.Logging/ModSocketOutput.cs | 22 ++++++------ src/OWML.Logging/OutputWriter.cs | 18 +++++++--- src/OWML.Logging/UnityLogger.cs | 39 ++++++++++----------- src/OWML.ModHelper.Events/HarmonyHelper.cs | 10 +++--- src/OWML.ModHelper.Events/ModEvents.cs | 11 +++--- src/OWML.ModHelper.Input/ModInputHandler.cs | 16 +++++---- src/OWML.ModHelper.Menus/OwmlConfigMenu.cs | 7 +++- src/OWML.ModLoader/Owo.cs | 15 ++++---- src/OWML.Patcher/VRPatcher.cs | 16 ++++----- 16 files changed, 95 insertions(+), 74 deletions(-) diff --git a/src/OWML.Common/Interfaces/IOwmlConfig.cs b/src/OWML.Common/Interfaces/IOwmlConfig.cs index bec1d5b3..0e7ffed9 100644 --- a/src/OWML.Common/Interfaces/IOwmlConfig.cs +++ b/src/OWML.Common/Interfaces/IOwmlConfig.cs @@ -20,6 +20,8 @@ public interface IOwmlConfig bool BlockInput { get; set; } + bool DebugMode { get; set; } + int SocketPort { get; set; } } } diff --git a/src/OWML.Common/MessageType.cs b/src/OWML.Common/MessageType.cs index d7794bf1..7c2f48c0 100644 --- a/src/OWML.Common/MessageType.cs +++ b/src/OWML.Common/MessageType.cs @@ -14,6 +14,8 @@ public enum MessageType Quit = 5, - Fatal = 6 + Fatal = 6, + + Debug = 7 } } diff --git a/src/OWML.Common/OwmlConfig.cs b/src/OWML.Common/OwmlConfig.cs index 4a8f921d..31f6c7f9 100644 --- a/src/OWML.Common/OwmlConfig.cs +++ b/src/OWML.Common/OwmlConfig.cs @@ -10,6 +10,9 @@ public class OwmlConfig : IOwmlConfig [JsonProperty("combinationsBlockInput")] public bool BlockInput { get; set; } + [JsonProperty("debugMode")] + public bool DebugMode { get; set; } + [JsonIgnore] public string DataPath => $"{GamePath}/OuterWilds_Data"; diff --git a/src/OWML.Launcher/OWML.DefaultConfig.json b/src/OWML.Launcher/OWML.DefaultConfig.json index b7d54c10..7cf849a3 100644 --- a/src/OWML.Launcher/OWML.DefaultConfig.json +++ b/src/OWML.Launcher/OWML.DefaultConfig.json @@ -1,5 +1,6 @@ { "gamePath": "C:/Program Files/Epic Games/OuterWilds", + "debugMode": false, "combinationsBlockInput": false, "socketPort": 0 } diff --git a/src/OWML.Launcher/Program.cs b/src/OWML.Launcher/Program.cs index 0a25b765..f8c5dacc 100644 --- a/src/OWML.Launcher/Program.cs +++ b/src/OWML.Launcher/Program.cs @@ -87,6 +87,6 @@ private static IModManifest GetOwmlManifest() => private static IModConsole CreateConsoleWriter(IOwmlConfig owmlConfig, IModManifest owmlManifest, bool hasConsolePort) => hasConsolePort ? new ModSocketOutput(owmlConfig, owmlManifest, null, new ModSocket(owmlConfig), new ProcessHelper()) - : (IModConsole)new OutputWriter(); + : (IModConsole)new OutputWriter(owmlConfig); } } diff --git a/src/OWML.Logging/ConsoleUtils.cs b/src/OWML.Logging/ConsoleUtils.cs index 126c757c..996879ab 100644 --- a/src/OWML.Logging/ConsoleUtils.cs +++ b/src/OWML.Logging/ConsoleUtils.cs @@ -20,6 +20,7 @@ public static void WriteByType(MessageType type, string line) MessageType.Message => ConsoleColor.Gray, MessageType.Info => ConsoleColor.Cyan, MessageType.Fatal => ConsoleColor.Magenta, + MessageType.Debug => ConsoleColor.Blue, _ => ConsoleColor.Gray }; diff --git a/src/OWML.Logging/ModLogger.cs b/src/OWML.Logging/ModLogger.cs index 2335f250..cd5b3c54 100644 --- a/src/OWML.Logging/ModLogger.cs +++ b/src/OWML.Logging/ModLogger.cs @@ -21,9 +21,11 @@ public ModLogger(IOwmlConfig config, IModManifest manifest) } } + [Obsolete("Use ModHelper.Console.WriteLine with messageType = Debug instead.")] public void Log(string s) => LogInternal($"[{_manifest.Name}]: {s}"); + [Obsolete("Use ModHelper.Console.WriteLine with messageType = Debug instead.")] public void Log(params object[] objects) => Log(string.Join(" ", objects.Select(o => o.ToString()).ToArray())); diff --git a/src/OWML.Logging/ModSocketOutput.cs b/src/OWML.Logging/ModSocketOutput.cs index 8fbff580..d18f87a0 100644 --- a/src/OWML.Logging/ModSocketOutput.cs +++ b/src/OWML.Logging/ModSocketOutput.cs @@ -24,24 +24,26 @@ public override void WriteLine(params object[] objects) WriteLine(line, MessageType.Message, GetCallingType(new StackTrace())); } - public override void WriteLine(string line) => + public override void WriteLine(string line) => WriteLine(line, MessageType.Message, GetCallingType(new StackTrace())); - public override void WriteLine(string line, MessageType type) => + public override void WriteLine(string line, MessageType type) => WriteLine(line, type, GetCallingType(new StackTrace())); public override void WriteLine(string line, MessageType type, string senderType) { Logger?.Log($"{type}: {line}"); - var message = new ModSocketMessage + if (type != MessageType.Debug || OwmlConfig.DebugMode) { - SenderName = Manifest.Name, - SenderType = senderType, - Type = type, - Message = line - }; - _socket.WriteToSocket(message); + _socket.WriteToSocket(new ModSocketMessage + { + SenderName = Manifest.Name, + SenderType = senderType, + Type = type, + Message = line + }); + } if (type == MessageType.Fatal) { @@ -50,7 +52,7 @@ public override void WriteLine(string line, MessageType type, string senderType) } private void WriteLine(MessageType type, string line, string senderType) => WriteLine(line, type, senderType); - + private void KillProcess() { _socket.Close(); diff --git a/src/OWML.Logging/OutputWriter.cs b/src/OWML.Logging/OutputWriter.cs index aaad0277..a3b5edf8 100644 --- a/src/OWML.Logging/OutputWriter.cs +++ b/src/OWML.Logging/OutputWriter.cs @@ -6,6 +6,11 @@ namespace OWML.Logging { public class OutputWriter : IModConsole { + private readonly IOwmlConfig _config; + + public OutputWriter(IOwmlConfig config) => + _config = config; + [Obsolete("Use WriteLine(string) or WriteLine(string, MessageType) instead.")] public void WriteLine(params object[] objects) => WriteLine(string.Join(" ", objects.Select(o => o.ToString()).ToArray())); @@ -13,10 +18,15 @@ public void WriteLine(params object[] objects) => public void WriteLine(string line) => WriteLine(line, MessageType.Message); - public void WriteLine(string line, MessageType type) => - ConsoleUtils.WriteByType(type, line); + public void WriteLine(string line, MessageType type, string senderType) => + WriteLine($"{senderType}: {line}", type); - public void WriteLine(string line, MessageType type, string senderType) => - ConsoleUtils.WriteByType(type, $"{senderType}: {line}"); + public void WriteLine(string line, MessageType type) + { + if (type != MessageType.Debug || _config.DebugMode) + { + ConsoleUtils.WriteByType(type, line); + } + } } } diff --git a/src/OWML.Logging/UnityLogger.cs b/src/OWML.Logging/UnityLogger.cs index f0731d46..c4806a4a 100644 --- a/src/OWML.Logging/UnityLogger.cs +++ b/src/OWML.Logging/UnityLogger.cs @@ -1,46 +1,43 @@ -using System.Linq; -using OWML.Common; +using OWML.Common; using UnityEngine; namespace OWML.Logging { public class UnityLogger : IUnityLogger { - private readonly LogType[] _relevantTypes = { - LogType.Error, - LogType.Exception - }; - - private readonly IModSocket _socket; private readonly IApplicationHelper _appHelper; - private readonly IModLogger _logger; + private readonly IModConsole _console; + private readonly IOwmlConfig _config; - public UnityLogger(IModSocket socket, IApplicationHelper appHelper, IModLogger logger) + public UnityLogger(IApplicationHelper appHelper, IModConsole console, IOwmlConfig config) { - _socket = socket; _appHelper = appHelper; - _logger = logger; + _console = console; + _config = config; } - public void Start() => + public void Start() => _appHelper.AddLogCallback(OnLogMessageReceived); private void OnLogMessageReceived(string message, string stackTrace, LogType type) { - if (!_relevantTypes.Contains(type)) + if (type != LogType.Error + && type != LogType.Exception + && !_config.DebugMode) { return; } var line = $"{message}. Stack trace: {stackTrace?.Trim()}"; - _logger.Log(line); - _socket.WriteToSocket(new ModSocketMessage + + var messageType = type switch { - Type = MessageType.Error, - Message = line, - SenderName = "Unity", - SenderType = type.ToString() - }); + LogType.Error => MessageType.Error, + LogType.Exception => MessageType.Error, + _ => MessageType.Debug + }; + + _console.WriteLine(line, messageType, "Unity"); } } } diff --git a/src/OWML.ModHelper.Events/HarmonyHelper.cs b/src/OWML.ModHelper.Events/HarmonyHelper.cs index 23426dbd..6f9dfa67 100644 --- a/src/OWML.ModHelper.Events/HarmonyHelper.cs +++ b/src/OWML.ModHelper.Events/HarmonyHelper.cs @@ -7,15 +7,13 @@ namespace OWML.ModHelper.Events { public class HarmonyHelper : IHarmonyHelper { - private readonly IModLogger _logger; private readonly IModConsole _console; private readonly IModManifest _manifest; private readonly IOwmlConfig _owmlConfig; private readonly HarmonyInstance _harmony; - public HarmonyHelper(IModLogger logger, IModConsole console, IModManifest manifest, IOwmlConfig owmlConfig) + public HarmonyHelper(IModConsole console, IModManifest manifest, IOwmlConfig owmlConfig) { - _logger = logger; _console = console; _manifest = manifest; _owmlConfig = owmlConfig; @@ -28,7 +26,7 @@ private HarmonyInstance CreateInstance() HarmonyInstance harmony; try { - _logger.Log($"Creating harmony instance: {_manifest.UniqueName}"); + _console.WriteLine($"Creating harmony instance: {_manifest.UniqueName}", MessageType.Debug); HarmonyInstance.DEBUG = true; FileLog.logPath = $"{_owmlConfig.LogsPath}/harmony.log.txt"; harmony = HarmonyInstance.Create(_manifest.UniqueName); @@ -51,7 +49,7 @@ private MethodInfo GetMethod(string methodName) MethodInfo result = null; try { - _logger.Log($"Getting method {methodName} of {targetType.Name}"); + _console.WriteLine($"Getting method {methodName} of {targetType.Name}", MessageType.Debug); result = Utils.TypeExtensions.GetAnyMethod(targetType, methodName); } catch (Exception ex) @@ -129,7 +127,7 @@ private void Patch(MethodBase original, MethodInfo prefix, MethodInfo postfix, M try { _harmony.Patch(original, prefixMethod, postfixMethod, transpilerMethod); - _logger.Log($"Patched {fullName}!"); + _console.WriteLine($"Patched {fullName}!", MessageType.Debug); } catch (Exception ex) { diff --git a/src/OWML.ModHelper.Events/ModEvents.cs b/src/OWML.ModHelper.Events/ModEvents.cs index e55203cf..16135037 100644 --- a/src/OWML.ModHelper.Events/ModEvents.cs +++ b/src/OWML.ModHelper.Events/ModEvents.cs @@ -24,17 +24,14 @@ public class ModEvents : IModEvents private readonly IHarmonyHelper _harmonyHelper; private readonly IModConsole _console; - private readonly IModLogger _logger; public ModEvents( - IModLogger logger, IModConsole console, IHarmonyHelper harmonyHelper, IModPlayerEvents playerEvents, IModSceneEvents sceneEvents, IModUnityEvents unityEvents) { - _logger = logger; _console = console; _harmonyHelper = harmonyHelper; Player = playerEvents; @@ -50,13 +47,13 @@ private void OnPatchEvent(MonoBehaviour behaviour, Common.Events ev) var type = behaviour.GetType(); if (IsSubscribedTo(type, ev)) { - _logger.Log($"Got subscribed event: {ev} of {type.Name}"); + _console.WriteLine($"Got subscribed event: {ev} of {type.Name}", MessageType.Debug); OnEvent?.Invoke(behaviour, ev); Event?.Invoke(behaviour, ev); } else { - _logger.Log($"Not subscribed to: {ev} of {type.Name}"); + _console.WriteLine($"Not subscribed to: {ev} of {type.Name}", MessageType.Debug); } } @@ -71,7 +68,7 @@ private void SubscribeToEvent(Common.Events ev) var type = typeof(T); if (IsSubscribedTo(type, ev)) { - _logger.Log($"Already subscribed to {ev} of {type.Name}"); + _console.WriteLine($"Already subscribed to {ev} of {type.Name}", MessageType.Debug); return; } AddToEventList(_subscribedEvents, type, ev); @@ -82,7 +79,7 @@ private void PatchEvent(Common.Events ev) var type = typeof(T); if (InEventList(PatchedEvents, type, ev)) { - _logger.Log($"Event is already patched: {ev} of {type.Name}"); + _console.WriteLine($"Event is already patched: {ev} of {type.Name}", MessageType.Debug); return; } AddToEventList(PatchedEvents, type, ev); diff --git a/src/OWML.ModHelper.Input/ModInputHandler.cs b/src/OWML.ModHelper.Input/ModInputHandler.cs index ad21c87a..175fcc07 100644 --- a/src/OWML.ModHelper.Input/ModInputHandler.cs +++ b/src/OWML.ModHelper.Input/ModInputHandler.cs @@ -17,24 +17,28 @@ public class ModInputHandler : IModInputHandler private const float Cooldown = 0.05f; private const float TapDuration = 0.1f; private const BindingFlags NonPublic = BindingFlags.NonPublic | BindingFlags.Instance; - + private readonly HashSet _singlesPressed = new(); private readonly Dictionary> _comboRegistry = new(); private readonly HashSet _toResetOnNextFrame = new(); private readonly int[] _blockedFrame = new int[ModInputLibrary.MaxUsefulKey]; private readonly int[] _gameBindingCounter = new int[ModInputLibrary.MaxUsefulKey]; - private readonly IModLogger _logger; private readonly IModConsole _console; private HashSet _currentCombinations = new(); private int _lastSingleUpdate; private int _lastCombinationUpdate; - - public ModInputHandler(IModLogger logger, IModConsole console, IHarmonyHelper patcher, IOwmlConfig owmlConfig, IModEvents events, IModInputTextures inputTextures, IBindingChangeListener listener) + + public ModInputHandler( + IModConsole console, + IHarmonyHelper patcher, + IOwmlConfig owmlConfig, + IModEvents events, + IModInputTextures inputTextures, + IBindingChangeListener listener) { Instance = this; _console = console; - _logger = logger; Textures = inputTextures; listener.Initialize(this, events); @@ -364,7 +368,7 @@ public void UnregisterCombination(IModInputCombination combination) _console.WriteLine($"Failed to unregister \"{combination.FullName}\": Too long!", MessageType.Error); return; case RegistrationCode.AllNormal: - _logger.Log($"Successfully unregistered \"{combination.FullName}\"", MessageType.Success); + _console.WriteLine($"Successfully unregistered \"{combination.FullName}\"", MessageType.Debug); return; } } diff --git a/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs b/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs index ef6ae489..588de93f 100644 --- a/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs +++ b/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs @@ -5,6 +5,7 @@ namespace OWML.ModHelper.Menus { public class OwmlConfigMenu : ModConfigMenuBase { + private const string DebugModeTitle = "Debug mode"; private const string BlockInputTitle = "Mod inputs can block game actions"; private readonly IOwmlConfig _config; @@ -24,18 +25,21 @@ public OwmlConfigMenu( protected override void AddInputs() { - AddConfigInput(BlockInputTitle, _config.BlockInput, 2); + AddConfigInput(DebugModeTitle, _config.DebugMode, 2); + AddConfigInput(BlockInputTitle, _config.BlockInput, 3); UpdateNavigation(); SelectFirst(); } protected override void UpdateUIValues() { + GetToggleInput(DebugModeTitle).Value = _config.DebugMode; GetToggleInput(BlockInputTitle).Value = _config.BlockInput; } protected override void OnSave() { + _config.DebugMode = (bool)GetInputValue(DebugModeTitle); // todo generic _config.BlockInput = (bool)GetInputValue(BlockInputTitle); Storage.Save(_config, Constants.OwmlConfigFileName); Close(); @@ -44,6 +48,7 @@ protected override void OnSave() protected override void OnReset() { _config.GamePath = _defaultConfig.GamePath; + _config.DebugMode = _defaultConfig.DebugMode; _config.BlockInput = _defaultConfig.BlockInput; UpdateUIValues(); } diff --git a/src/OWML.ModLoader/Owo.cs b/src/OWML.ModLoader/Owo.cs index fa25cf49..6737e9a5 100644 --- a/src/OWML.ModLoader/Owo.cs +++ b/src/OWML.ModLoader/Owo.cs @@ -16,7 +16,6 @@ namespace OWML.ModLoader public class Owo { private readonly IModFinder _modFinder; - private readonly IModLogger _logger; private readonly IModConsole _console; private readonly IOwmlConfig _owmlConfig; private readonly IModMenus _menus; @@ -33,7 +32,6 @@ public class Owo public Owo( IModFinder modFinder, - IModLogger logger, IModConsole console, IOwmlConfig owmlConfig, IModMenus menus, @@ -48,7 +46,6 @@ public Owo( IModUnityEvents unityEvents) { _modFinder = modFinder; - _logger = logger; _console = console; _owmlConfig = owmlConfig; _menus = menus; @@ -120,13 +117,13 @@ private Type LoadMod(IModData modData) { if (!modData.Config.Enabled) { - _logger.Log($"{modData.Manifest.UniqueName} is disabled"); + _console.WriteLine($"{modData.Manifest.UniqueName} is disabled", MessageType.Debug); return null; } - _logger.Log($"Loading assembly: {modData.Manifest.AssemblyPath}"); + _console.WriteLine($"Loading assembly: {modData.Manifest.AssemblyPath}", MessageType.Debug); var assembly = Assembly.LoadFile(modData.Manifest.AssemblyPath); - _logger.Log($"Loaded {assembly.FullName}"); + _console.WriteLine($"Loaded {assembly.FullName}", MessageType.Debug); try { @@ -166,12 +163,12 @@ private IModHelper CreateModHelper(IModData modData) => private IModBehaviour InitializeMod(Type modType, IModHelper helper) { - _logger.Log($"Initializing {helper.Manifest.UniqueName} ({helper.Manifest.Version})..."); - _logger.Log("Adding mod behaviour..."); + _console.WriteLine($"Initializing {helper.Manifest.UniqueName} ({helper.Manifest.Version})...", MessageType.Debug); + _console.WriteLine("Adding mod behaviour...", MessageType.Debug); try { var mod = _goHelper.CreateAndAdd(modType, helper.Manifest.UniqueName); - _logger.Log("Added! Initializing..."); + _console.WriteLine("Added! Initializing...", MessageType.Debug); mod.Init(helper); return mod; } diff --git a/src/OWML.Patcher/VRPatcher.cs b/src/OWML.Patcher/VRPatcher.cs index 7e049219..aaa8325c 100644 --- a/src/OWML.Patcher/VRPatcher.cs +++ b/src/OWML.Patcher/VRPatcher.cs @@ -8,7 +8,7 @@ public class VRPatcher : IVRPatcher private readonly IOwmlConfig _owmlConfig; private readonly IBinaryPatcher _binaryPatcher; private readonly IVRFilePatcher _vrFilePatcher; - private readonly IModLogger _logger; + private readonly IModConsole _console; private static readonly string[] PluginFilenames = { @@ -16,25 +16,25 @@ public class VRPatcher : IVRPatcher "OVRPlugin.dll" }; - public VRPatcher(IOwmlConfig owmlConfig, IBinaryPatcher binaryPatcher, IVRFilePatcher vrFilePatcher, IModLogger logger) + public VRPatcher(IOwmlConfig owmlConfig, IBinaryPatcher binaryPatcher, IVRFilePatcher vrFilePatcher, IModConsole console) { _owmlConfig = owmlConfig; _binaryPatcher = binaryPatcher; _vrFilePatcher = vrFilePatcher; - _logger = logger; + _console = console; } public void PatchVR(bool enableVR) { if (enableVR) { - _logger.Log("Patching globalgamemanagers for VR and adding VR plugins"); + _console.WriteLine("Patching globalgamemanagers for VR and adding VR plugins", MessageType.Debug); _vrFilePatcher.Patch(); AddPluginFiles(); } else { - _logger.Log("Restoring globalgamemanagers and removing VR plugins"); + _console.WriteLine("Restoring globalgamemanagers and removing VR plugins", MessageType.Debug); _binaryPatcher.RestoreFromBackup(); RemovePluginFiles(); } @@ -46,7 +46,7 @@ private void AddPluginFiles() { var from = $"{_owmlConfig.OWMLPath}lib/{filename}"; var to = $"{_owmlConfig.PluginsPath}/{filename}"; - _logger.Log($"Copying {from} to {to}"); + _console.WriteLine($"Copying {from} to {to}", MessageType.Debug); File.Copy(from, to, true); } } @@ -58,12 +58,12 @@ private void RemovePluginFiles() var path = $"{_owmlConfig.PluginsPath}/{filename}"; if (File.Exists(path)) { - _logger.Log($"Deleting {path}"); + _console.WriteLine($"Deleting {path}", MessageType.Debug); File.Delete(path); } else { - _logger.Log($"{path} doesn't exist, nothing to delete."); + _console.WriteLine($"{path} doesn't exist, nothing to delete.", MessageType.Debug); } } } From 43d3aad14441f7a67283e031abcb2e9f30d3021e Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Tue, 22 Dec 2020 16:24:27 +0100 Subject: [PATCH 2/4] generic GetInputValue --- src/OWML.Common/Interfaces/Menus/IModMenu.cs | 3 + src/OWML.ModHelper.Menus/ModConfigMenu.cs | 2 +- src/OWML.ModHelper.Menus/ModMenu.cs | 132 +++++++------------ src/OWML.ModHelper.Menus/OwmlConfigMenu.cs | 4 +- 4 files changed, 51 insertions(+), 90 deletions(-) diff --git a/src/OWML.Common/Interfaces/Menus/IModMenu.cs b/src/OWML.Common/Interfaces/Menus/IModMenu.cs index de16ebd0..2e6f1adc 100644 --- a/src/OWML.Common/Interfaces/Menus/IModMenu.cs +++ b/src/OWML.Common/Interfaces/Menus/IModMenu.cs @@ -79,10 +79,13 @@ public interface IModMenu IModSeparator AddSeparator(IModSeparator separator); IModSeparator AddSeparator(IModSeparator separator, int index); + IModSeparator GetSeparator(string title); object GetInputValue(string key); + T GetInputValue(string key); + void SetInputValue(string key, object value); void SelectFirst(); diff --git a/src/OWML.ModHelper.Menus/ModConfigMenu.cs b/src/OWML.ModHelper.Menus/ModConfigMenu.cs index 002747c0..06a58563 100644 --- a/src/OWML.ModHelper.Menus/ModConfigMenu.cs +++ b/src/OWML.ModHelper.Menus/ModConfigMenu.cs @@ -41,7 +41,7 @@ protected override void UpdateUIValues() protected override void OnSave() { - ModData.Config.Enabled = (bool)GetInputValue(EnabledTitle); + ModData.Config.Enabled = GetInputValue(EnabledTitle); var keys = ModData.Config.Settings.Select(x => x.Key).ToList(); foreach (var key in keys) { diff --git a/src/OWML.ModHelper.Menus/ModMenu.cs b/src/OWML.ModHelper.Menus/ModMenu.cs index d16ac1e1..1f596234 100644 --- a/src/OWML.ModHelper.Menus/ModMenu.cs +++ b/src/OWML.ModHelper.Menus/ModMenu.cs @@ -41,10 +41,8 @@ public class ModMenu : IModMenu protected LayoutGroup Layout; protected IModConsole Console; - public ModMenu(IModConsole console) - { + public ModMenu(IModConsole console) => Console = console; - } public virtual void Initialize(Menu menu) { @@ -81,20 +79,14 @@ public virtual void Initialize(Menu menu, LayoutGroup layoutGroup) } [Obsolete("Use GetTitleButton instead")] - public IModButton GetButton(string title) - { - return GetTitleButton(title); - } + public IModButton GetButton(string title) => + GetTitleButton(title); - public IModButton GetTitleButton(string title) - { - return GetTitleButton(title, Buttons); - } + public IModButton GetTitleButton(string title) => + GetTitleButton(title, Buttons); - public IModPromptButton GetPromptButton(string title) - { - return GetTitleButton(title, PromptButtons); - } + public IModPromptButton GetPromptButton(string title) => + GetTitleButton(title, PromptButtons); private T GetTitleButton(string title, List buttons) where T : IModButton { @@ -107,21 +99,15 @@ private T GetTitleButton(string title, List buttons) where T : IModButton } [Obsolete("Use AddButton(IModButtonBase) instead.")] - public IModButton AddButton(IModButton button) - { - return AddButton(button, button.Index); - } + public IModButton AddButton(IModButton button) => + AddButton(button, button.Index); [Obsolete("Use AddButton(IModButtonBase, int) instead.")] - public virtual IModButton AddButton(IModButton button, int index) - { - return (IModButton)AddButton((IModButtonBase)button, index); - } + public virtual IModButton AddButton(IModButton button, int index) => + (IModButton)AddButton((IModButtonBase)button, index); - public IModButtonBase AddButton(IModButtonBase button) - { - return AddButton(button, button.Index); - } + public IModButtonBase AddButton(IModButtonBase button) => + AddButton(button, button.Index); public virtual IModButtonBase AddButton(IModButtonBase button, int index) { @@ -135,15 +121,11 @@ public virtual IModButtonBase AddButton(IModButtonBase button, int index) return button; } - public IModToggleInput GetToggleInput(string title) - { - return ToggleInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModToggleInput GetToggleInput(string title) => + ToggleInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - public IModToggleInput AddToggleInput(IModToggleInput input) - { - return AddToggleInput(input, input.Index); - } + public IModToggleInput AddToggleInput(IModToggleInput input) => + AddToggleInput(input, input.Index); public IModToggleInput AddToggleInput(IModToggleInput input, int index) { @@ -152,15 +134,11 @@ public IModToggleInput AddToggleInput(IModToggleInput input, int index) return input; } - public IModSliderInput GetSliderInput(string title) - { - return SliderInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModSliderInput GetSliderInput(string title) => + SliderInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - public IModSliderInput AddSliderInput(IModSliderInput input) - { - return AddSliderInput(input, input.Index); - } + public IModSliderInput AddSliderInput(IModSliderInput input) => + AddSliderInput(input, input.Index); public IModSliderInput AddSliderInput(IModSliderInput input, int index) { @@ -169,15 +147,11 @@ public IModSliderInput AddSliderInput(IModSliderInput input, int index) return input; } - public IModSelectorInput GetSelectorInput(string title) - { - return SelectorInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModSelectorInput GetSelectorInput(string title) => + SelectorInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - public IModSelectorInput AddSelectorInput(IModSelectorInput input) - { - return AddSelectorInput(input, input.Index); - } + public IModSelectorInput AddSelectorInput(IModSelectorInput input) => + AddSelectorInput(input, input.Index); public IModSelectorInput AddSelectorInput(IModSelectorInput input, int index) { @@ -186,15 +160,11 @@ public IModSelectorInput AddSelectorInput(IModSelectorInput input, int index) return input; } - public IModTextInput GetTextInput(string title) - { - return TextInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModTextInput GetTextInput(string title) => + TextInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - public IModTextInput AddTextInput(IModTextInput input) - { - return AddTextInput(input, input.Index); - } + public IModTextInput AddTextInput(IModTextInput input) => + AddTextInput(input, input.Index); public IModTextInput AddTextInput(IModTextInput input, int index) { @@ -203,15 +173,11 @@ public IModTextInput AddTextInput(IModTextInput input, int index) return input; } - public IModComboInput GetComboInput(string title) - { - return ComboInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModComboInput GetComboInput(string title) => + ComboInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - public IModComboInput AddComboInput(IModComboInput input) - { - return AddComboInput(input, input.Index); - } + public IModComboInput AddComboInput(IModComboInput input) => + AddComboInput(input, input.Index); public IModComboInput AddComboInput(IModComboInput input, int index) { @@ -220,15 +186,11 @@ public IModComboInput AddComboInput(IModComboInput input, int index) return input; } - public IModNumberInput GetNumberInput(string title) - { - return NumberInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModNumberInput GetNumberInput(string title) => + NumberInputs.FirstOrDefault(x => x.Title == title || x.Element.name == title); - public IModNumberInput AddNumberInput(IModNumberInput input) - { - return AddNumberInput(input, input.Index); - } + public IModNumberInput AddNumberInput(IModNumberInput input) => + AddNumberInput(input, input.Index); public IModNumberInput AddNumberInput(IModNumberInput input, int index) { @@ -247,10 +209,8 @@ private void AddInput(IModInput input, int index) input.Element.transform.localScale = scale; } - public IModSeparator AddSeparator(IModSeparator separator) - { - return AddSeparator(separator, separator.Index); - } + public IModSeparator AddSeparator(IModSeparator separator) => + AddSeparator(separator, separator.Index); public IModSeparator AddSeparator(IModSeparator separator, int index) { @@ -264,10 +224,11 @@ public IModSeparator AddSeparator(IModSeparator separator, int index) return separator; } - public IModSeparator GetSeparator(string title) - { - return Separators.FirstOrDefault(x => x.Title == title || x.Element.name == title); - } + public IModSeparator GetSeparator(string title) => + Separators.FirstOrDefault(x => x.Title == title || x.Element.name == title); + + public T GetInputValue(string key) => + (T)GetInputValue(key); public object GetInputValue(string key) { @@ -352,10 +313,8 @@ public void SetInputValue(string key, object value) Console.WriteLine("Error - No input found with name " + key, MessageType.Error); } - protected void InvokeOnInit() - { + protected void InvokeOnInit() => OnInit?.Invoke(); - } public virtual void SelectFirst() { @@ -384,6 +343,5 @@ public virtual void UpdateNavigation() .Where(x => x != null).ToList(); UpdateNavigation(selectables); } - } } diff --git a/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs b/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs index 588de93f..1bb03db3 100644 --- a/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs +++ b/src/OWML.ModHelper.Menus/OwmlConfigMenu.cs @@ -39,8 +39,8 @@ protected override void UpdateUIValues() protected override void OnSave() { - _config.DebugMode = (bool)GetInputValue(DebugModeTitle); // todo generic - _config.BlockInput = (bool)GetInputValue(BlockInputTitle); + _config.DebugMode = GetInputValue(DebugModeTitle); + _config.BlockInput = GetInputValue(BlockInputTitle); Storage.Save(_config, Constants.OwmlConfigFileName); Close(); } From b4adf3cd8f183434597ea56742d03f41608ee3aa Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Tue, 22 Dec 2020 16:25:06 +0100 Subject: [PATCH 3/4] version --- src/OWML.Launcher/OWML.Manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OWML.Launcher/OWML.Manifest.json b/src/OWML.Launcher/OWML.Manifest.json index 4ffec1b8..e1d70d2a 100644 --- a/src/OWML.Launcher/OWML.Manifest.json +++ b/src/OWML.Launcher/OWML.Manifest.json @@ -2,7 +2,7 @@ "author": "Alek", "name": "OWML", "uniqueName": "Alek.OWML", - "version": "1.1.2", + "version": "1.1.3", "description": "The mod loader and mod framework for Outer Wilds", "minGameVersion": "1.0.7.0", "maxGameVersion": "1.0.7.481" From 55507f7aa4960c9b2056773ef814f2e5fc862b36 Mon Sep 17 00:00:00 2001 From: Aleksander Waage Date: Tue, 22 Dec 2020 18:59:45 +0100 Subject: [PATCH 4/4] deprecated ModConsole.OwmlConsole and added Debug output test to LoadCustomAssets --- src/OWML.Logging/ModConsole.cs | 1 + src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/OWML.Logging/ModConsole.cs b/src/OWML.Logging/ModConsole.cs index e329272f..6d7f22c5 100644 --- a/src/OWML.Logging/ModConsole.cs +++ b/src/OWML.Logging/ModConsole.cs @@ -5,6 +5,7 @@ namespace OWML.Logging { public abstract class ModConsole : IModConsole { + [Obsolete("Use ModHelper.Console instead.")] public static ModConsole OwmlConsole { get; private set; } protected readonly IModLogger Logger; diff --git a/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs b/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs index 914bbb22..ea078ae6 100644 --- a/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs +++ b/src/SampleMods/OWML.LoadCustomAssets/LoadCustomAssets.cs @@ -74,6 +74,7 @@ public void TestLogging() ModHelper.Console.WriteLine("Test Message", MessageType.Message); ModHelper.Console.WriteLine("Test Success", MessageType.Success); ModHelper.Console.WriteLine("Test Info", MessageType.Info); + ModHelper.Console.WriteLine("Test Debug", MessageType.Debug); } private void OnMusicLoaded(AudioSource audio)