From 754ff2c64fce5db3c64b6db0310727a056e600d1 Mon Sep 17 00:00:00 2001 From: EIA485 <17285570+EIA485@users.noreply.github.com> Date: Fri, 15 Oct 2021 10:44:09 -0700 Subject: [PATCH 1/3] add suport for objects and multiple objects to logger --- NeosModLoader/Logger.cs | 215 ++++++++++++++++++++++----------------- NeosModLoader/NeosMod.cs | 38 ++++--- 2 files changed, 147 insertions(+), 106 deletions(-) diff --git a/NeosModLoader/Logger.cs b/NeosModLoader/Logger.cs index cdfd7d7..d919e6f 100644 --- a/NeosModLoader/Logger.cs +++ b/NeosModLoader/Logger.cs @@ -1,94 +1,127 @@ -using BaseX; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Reflection; - -namespace NeosModLoader -{ - internal class Logger - { - internal static void DebugExternal(string message) +using BaseX; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Reflection; + +namespace NeosModLoader +{ + internal class Logger + { + internal static void DebugExternal(string message) + { + if (Configuration.get().Debug) + { + LogInternal(LogType.DEBUG, message, SourceFromStackTrace()); + } + } + + internal static void DebugInternal(string message) + { + if (Configuration.get().Debug) + { + LogInternal(LogType.DEBUG, message); + } + } + internal static void DebugList(object[] messages) { - if (Configuration.get().Debug) - { - LogInternal(LogType.DEBUG, message, SourceFromStackTrace()); - } - } - - internal static void DebugInternal(string message) + string Source = SourceFromStackTrace(); + foreach (object element in messages) + { + LogInternal(LogType.DEBUG, element.ToString(), Source); + } + } + + internal static void MsgExternal(string message) + { + LogInternal(LogType.INFO, message, SourceFromStackTrace()); + } + + internal static void MsgInternal(string message) + { + LogInternal(LogType.INFO, message); + } + internal static void MsgList(object[] messages) { - if (Configuration.get().Debug) - { - LogInternal(LogType.DEBUG, message); - } - } - - internal static void MsgExternal(string message) + string Source = SourceFromStackTrace(); + foreach (object element in messages) + { + LogInternal(LogType.INFO, element.ToString(), Source); + } + } + + internal static void WarnExternal(string message) + { + LogInternal(LogType.WARN, message, SourceFromStackTrace()); + } + + internal static void WarnInternal(string message) + { + LogInternal(LogType.WARN, message); + } + internal static void WarnList(object[] messages) { - LogInternal(LogType.INFO, message, SourceFromStackTrace()); - } - - internal static void MsgInternal(string message) - { - LogInternal(LogType.INFO, message); - } - - internal static void WarnExternal(string message) - { - LogInternal(LogType.WARN, message, SourceFromStackTrace()); - } - - internal static void WarnInternal(string message) - { - LogInternal(LogType.WARN, message); - } - - internal static void ErrorExternal(string message) - { - LogInternal(LogType.ERROR, message, SourceFromStackTrace()); - } - - internal static void ErrorInternal(string message) - { - LogInternal(LogType.ERROR, message); - } - - private static void LogInternal(string logTypePrefix, string message, string source = null) - { - if (source == null) - { - UniLog.Log($"{logTypePrefix}[NeosModLoader] {message}"); - } - else - { - UniLog.Log($"{logTypePrefix}[NeosModLoader/{source}] {message}"); - } - } - - private static string SourceFromStackTrace() - { - Dictionary loadedMods = ModLoader.LoadedMods; - // skip three frames: SourceFromStackTrace(), MsgExternal(), Msg() - StackTrace stackTrace = new StackTrace(3); - for (int i = 0; i < stackTrace.FrameCount; i++) - { - Assembly assembly = stackTrace.GetFrame(i).GetMethod().DeclaringType.Assembly; - NeosMod mod; - if (loadedMods.TryGetValue(assembly, out mod)) - { - return mod.Name; - } - } - return null; - } - - private sealed class LogType - { - public readonly static string DEBUG = "[DEBUG]"; - public readonly static string INFO = "[INFO] "; - public readonly static string WARN = "[WARN] "; - public readonly static string ERROR = "[ERROR]"; - } - } -} + string Source = SourceFromStackTrace(); + foreach (object element in messages) + { + LogInternal(LogType.WARN, element.ToString(), Source); + } + } + + internal static void ErrorExternal(string message) + { + LogInternal(LogType.ERROR, message, SourceFromStackTrace()); + } + + internal static void ErrorInternal(string message) + { + LogInternal(LogType.ERROR, message); + } + + internal static void ErrorList(object[] messages) + { + string Source = SourceFromStackTrace(); + foreach (object element in messages) + { + LogInternal(LogType.ERROR, element.ToString(), Source); + } + } + + private static void LogInternal(string logTypePrefix, string message, string source = null) + { + if (source == null) + { + UniLog.Log($"{logTypePrefix}[NeosModLoader] {message}"); + } + else + { + UniLog.Log($"{logTypePrefix}[NeosModLoader/{source}] {message}"); + } + } + + private static string SourceFromStackTrace() + { + Dictionary loadedMods = ModLoader.LoadedMods; + // skip three frames: SourceFromStackTrace(), MsgExternal(), Msg() + StackTrace stackTrace = new StackTrace(3); + for (int i = 0; i < stackTrace.FrameCount; i++) + { + Assembly assembly = stackTrace.GetFrame(i).GetMethod().DeclaringType.Assembly; + NeosMod mod; + if (loadedMods.TryGetValue(assembly, out mod)) + { + return mod.Name; + } + } + return null; + } + + private sealed class LogType + { + public readonly static string DEBUG = "[DEBUG]"; + public readonly static string INFO = "[INFO] "; + public readonly static string WARN = "[WARN] "; + public readonly static string ERROR = "[ERROR]"; + } + } +} diff --git a/NeosModLoader/NeosMod.cs b/NeosModLoader/NeosMod.cs index d58300c..72ff977 100644 --- a/NeosModLoader/NeosMod.cs +++ b/NeosModLoader/NeosMod.cs @@ -1,15 +1,23 @@ -namespace NeosModLoader -{ - public abstract class NeosMod - { - public static void Debug(string message) => Logger.DebugExternal(message); - public static void Msg(string message) => Logger.MsgExternal(message); - public static void Warn(string message) => Logger.WarnExternal(message); - public static void Error(string message) => Logger.ErrorExternal(message); - public virtual void OnEngineInit() { } - public abstract string Name { get; } - public abstract string Author { get; } - public abstract string Version { get; } - public virtual string Link { get; } - } -} +namespace NeosModLoader +{ + public abstract class NeosMod + { + public static void Debug(string message) => Logger.DebugExternal(message); + public static void Debug(object message) => Logger.DebugExternal(message.ToString()); + public static void Debug(params object[] messages) => Logger.DebugList(messages); + public static void Msg(string message) => Logger.MsgExternal(message); + public static void Msg(object message) => Logger.MsgExternal(message.ToString()); + public static void Msg(params object[] messages) => Logger.MsgList(messages); + public static void Warn(string message) => Logger.WarnExternal(message); + public static void Warn(object message) => Logger.WarnExternal(message.ToString()); + public static void Warn(params object[] messages) => Logger.WarnList(messages); + public static void Error(string message) => Logger.ErrorExternal(message); + public static void Error(object message) => Logger.ErrorExternal(message.ToString()); + public static void Error(params object[] messages) => Logger.ErrorList(messages); + public virtual void OnEngineInit() { } + public abstract string Name { get; } + public abstract string Author { get; } + public abstract string Version { get; } + public virtual string Link { get; } + } +} From b0a8c19e4da3201fc14bf496313490189e478671 Mon Sep 17 00:00:00 2001 From: EIA485 <17285570+EIA485@users.noreply.github.com> Date: Fri, 15 Oct 2021 10:45:33 -0700 Subject: [PATCH 2/3] use lf line endings --- NeosModLoader/Logger.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NeosModLoader/Logger.cs b/NeosModLoader/Logger.cs index d919e6f..db58fa1 100644 --- a/NeosModLoader/Logger.cs +++ b/NeosModLoader/Logger.cs @@ -24,7 +24,7 @@ internal static void DebugInternal(string message) } } internal static void DebugList(object[] messages) - { + { string Source = SourceFromStackTrace(); foreach (object element in messages) { @@ -42,7 +42,7 @@ internal static void MsgInternal(string message) LogInternal(LogType.INFO, message); } internal static void MsgList(object[] messages) - { + { string Source = SourceFromStackTrace(); foreach (object element in messages) { @@ -60,7 +60,7 @@ internal static void WarnInternal(string message) LogInternal(LogType.WARN, message); } internal static void WarnList(object[] messages) - { + { string Source = SourceFromStackTrace(); foreach (object element in messages) { From 134c0be3f269586c1ee990beec040e7e9557b5a1 Mon Sep 17 00:00:00 2001 From: EIA485 <17285570+EIA485@users.noreply.github.com> Date: Sun, 17 Oct 2021 16:10:38 -0700 Subject: [PATCH 3/3] fix for neos version 2021.10.17.1326 --- NeosModLoader/ExecutionHook.cs | 91 ++++++++++++------------ NeosModLoader/Properties/AssemblyInfo.cs | 70 +++++++++--------- 2 files changed, 81 insertions(+), 80 deletions(-) diff --git a/NeosModLoader/ExecutionHook.cs b/NeosModLoader/ExecutionHook.cs index a645485..5334b85 100644 --- a/NeosModLoader/ExecutionHook.cs +++ b/NeosModLoader/ExecutionHook.cs @@ -1,45 +1,46 @@ -using FrooxEngine; -using System; - -namespace NeosModLoader -{ - [ImplementableClass(true)] - class ExecutionHook - { -#pragma warning disable CS0169 - // field must exist due to reflective access - private static Type __connectorType; -#pragma warning restore CS0169 - - static ExecutionHook() - { - try - { - Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(Configuration.get().Debug ? " Debug logs will be shown." : "")}"); - NeosVersionReset.Initialize(); - ModLoader.LoadMods(); - } - catch (Exception e) // it's important that this doesn't send exceptions back to Neos - { - Logger.ErrorInternal($"Exception in execution hook!\n{e}"); - } - } - - // implementation not strictly required, but method must exist due to reflective access - private static DummyConnector InstantiateConnector() - { - return new DummyConnector(); - } - - // type must match return type of InstantiateConnector() - private class DummyConnector : IConnector - { - public IImplementable Owner { get; private set; } - public void ApplyChanges() { } - public void AssignOwner(IImplementable owner) => Owner = owner; - public void Destroy(bool destroyingWorld) { } - public void Initialize() { } - public void RemoveOwner() => Owner = null; - } - } -} +using FrooxEngine; +using System; + +namespace NeosModLoader +{ + [ImplementableClass(true)] + class ExecutionHook + { +#pragma warning disable CS0169 + // field must exist due to reflective access + private static Type __connectorType; + private static Type __connectorTypes; +#pragma warning restore CS0169 + + static ExecutionHook() + { + try + { + Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(Configuration.get().Debug ? " Debug logs will be shown." : "")}"); + NeosVersionReset.Initialize(); + ModLoader.LoadMods(); + } + catch (Exception e) // it's important that this doesn't send exceptions back to Neos + { + Logger.ErrorInternal($"Exception in execution hook!\n{e}"); + } + } + + // implementation not strictly required, but method must exist due to reflective access + private static DummyConnector InstantiateConnector() + { + return new DummyConnector(); + } + + // type must match return type of InstantiateConnector() + private class DummyConnector : IConnector + { + public IImplementable Owner { get; private set; } + public void ApplyChanges() { } + public void AssignOwner(IImplementable owner) => Owner = owner; + public void Destroy(bool destroyingWorld) { } + public void Initialize() { } + public void RemoveOwner() => Owner = null; + } + } +} diff --git a/NeosModLoader/Properties/AssemblyInfo.cs b/NeosModLoader/Properties/AssemblyInfo.cs index e67f11c..ff2f80e 100644 --- a/NeosModLoader/Properties/AssemblyInfo.cs +++ b/NeosModLoader/Properties/AssemblyInfo.cs @@ -1,35 +1,35 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("NeosModLoader")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("NeosModLoader")] -[assembly: AssemblyCopyright("Copyright © 2021")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("d4627c7f-8091-477a-abdc-f1465d94d8d9")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.1.0")] -[assembly: AssemblyFileVersion("1.3.1.0")] +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("NeosModLoader")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("NeosModLoader")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d4627c7f-8091-477a-abdc-f1465d94d8d9")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.4.0.0")] +[assembly: AssemblyFileVersion("1.4.0.0")]