Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
zkxs committed Jan 7, 2022
2 parents d48d06d + d615364 commit bfa5a59
Show file tree
Hide file tree
Showing 18 changed files with 1,160 additions and 49 deletions.
27 changes: 27 additions & 0 deletions NeosModLoader/ConfigurationChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace NeosModLoader
{
public class ConfigurationChangedEvent
{
/// <summary>
/// The configuration the change occurred in
/// </summary>
public ModConfiguration Config { get; private set; }

/// <summary>
/// The specific key who's value changed
/// </summary>
public ModConfigurationKey Key { get; private set; }

/// <summary>
/// A custom label that may be set by whoever changed the configuration
/// </summary>
public string Label { get; private set; }

internal ConfigurationChangedEvent(ModConfiguration config, ModConfigurationKey key, string label)
{
Config = config;
Key = key;
Label = label;
}
}
}
21 changes: 21 additions & 0 deletions NeosModLoader/DebugInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;

namespace NeosModLoader
{
internal class DebugInfo
{
internal static void Log()
{
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(ModLoaderConfiguration.get().Debug ? " Debug logs will be shown." : "")}");
Logger.MsgInternal($"Using Harmony v{GetAssemblyVersion(typeof(HarmonyLib.Harmony))}");
Logger.MsgInternal($"Using BaseX v{GetAssemblyVersion(typeof(BaseX.floatQ))}");
Logger.MsgInternal($"Using FrooxEngine v{GetAssemblyVersion(typeof(FrooxEngine.IComponent))}");
Logger.MsgInternal($"Using Json.NET v{GetAssemblyVersion(typeof(Newtonsoft.Json.JsonSerializer))}");
}

private static string GetAssemblyVersion(Type typeFromAssembly)
{
return typeFromAssembly.Assembly.GetName()?.Version?.ToString();
}
}
}
31 changes: 31 additions & 0 deletions NeosModLoader/DelegateExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace NeosModLoader
{
internal static class DelegateExtensions
{
internal static void SafeInvoke(this Delegate del, params object[] args)
{
var exceptions = new List<Exception>();

foreach (var handler in del.GetInvocationList())
{
try
{
handler.Method.Invoke(handler.Target, args);
}
catch (Exception ex)
{
exceptions.Add(ex);
}
}

if (exceptions.Any())
{
throw new AggregateException(exceptions);
}
}
}
}
2 changes: 1 addition & 1 deletion NeosModLoader/ExecutionHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ static ExecutionHook()
{
try
{
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(Configuration.get().Debug ? " Debug logs will be shown." : "")}");
DebugInfo.Log();
NeosVersionReset.Initialize();
ModLoader.LoadMods();
}
Expand Down
16 changes: 16 additions & 0 deletions NeosModLoader/LoadedNeosMod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace NeosModLoader
{
internal class LoadedNeosMod
{
internal LoadedNeosMod(NeosMod neosMod, ModAssembly modAssembly)
{
NeosMod = neosMod;
ModAssembly = modAssembly;
}

internal NeosMod NeosMod { get; private set; }
internal ModAssembly ModAssembly { get; private set; }
internal ModConfiguration ModConfiguration { get; set; }
internal bool AllowSavingConfiguration = true;
}
}
17 changes: 7 additions & 10 deletions NeosModLoader/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using BaseX;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;

Expand All @@ -10,15 +8,15 @@ internal class Logger
{
internal static void DebugExternal(string message)
{
if (Configuration.get().Debug)
if (ModLoaderConfiguration.get().Debug)
{
LogInternal(LogType.DEBUG, message, SourceFromStackTrace());
}
}

internal static void DebugInternal(string message)
{
if (Configuration.get().Debug)
if (ModLoaderConfiguration.get().Debug)
{
LogInternal(LogType.DEBUG, message);
}
Expand Down Expand Up @@ -104,14 +102,13 @@ private static void LogInternal(string logTypePrefix, string message, string sou

private static string SourceFromStackTrace()
{
Dictionary<Assembly, NeosMod> 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))
if (ModLoader.AssemblyLookupMap.TryGetValue(assembly, out mod))
{
return mod.Name;
}
Expand All @@ -121,10 +118,10 @@ private static string SourceFromStackTrace()

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]";
internal readonly static string DEBUG = "[DEBUG]";
internal readonly static string INFO = "[INFO] ";
internal readonly static string WARN = "[WARN] ";
internal readonly static string ERROR = "[ERROR]";
}
}
}
14 changes: 14 additions & 0 deletions NeosModLoader/ModAssembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;

namespace NeosModLoader
{
internal class ModAssembly
{
internal string File { get; }
internal Assembly Assembly { get; set; }
internal ModAssembly(string file)
{
File = file;
}
}
}
Loading

0 comments on commit bfa5a59

Please sign in to comment.