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

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
- Hide debug logs by default
- Improve log readability
- Explicitly sort mods before loading
  • Loading branch information
zkxs committed Aug 16, 2021
1 parent 1a68a8c commit c8bdbd8
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
9 changes: 7 additions & 2 deletions NeosModLoader/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ internal static Configuration get()

if ("unsafe".Equals(key) && "true".Equals(value))
{
_configuration.UnsafeMode = true;
_configuration.Unsafe = true;
}
else if ("debug".Equals(key) && "true".Equals(value))
{
_configuration.Debug = true;
}
}
}
Expand Down Expand Up @@ -65,6 +69,7 @@ private static string GetAssemblyDirectory()
return Path.GetDirectoryName(path);
}

public bool UnsafeMode { get; private set; } = true;
public bool Unsafe { get; private set; } = false;
public bool Debug { get; private set; } = false;
}
}
2 changes: 1 addition & 1 deletion NeosModLoader/ExecutionHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static ExecutionHook()
{
try
{
Logger.DebugInternal($"NeosModLoader v{ModLoader.VERSION} starting up!");
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(Configuration.get().Debug ? " Debug logs will be shown." : "")}");
NeosVersionReset.Initialize();
ModLoader.LoadMods();
}
Expand Down
28 changes: 17 additions & 11 deletions NeosModLoader/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ internal class Logger
{
internal static void DebugExternal(string message)
{
LogInternal(LogType.DEBUG, message, SourceFromStackTrace());
if (Configuration.get().Debug)
{
LogInternal(LogType.DEBUG, message, SourceFromStackTrace());
}
}

internal static void DebugInternal(string message)
{
LogInternal(LogType.DEBUG, message);
if (Configuration.get().Debug)
{
LogInternal(LogType.DEBUG, message);
}
}

internal static void MsgExternal(string message)
Expand Down Expand Up @@ -52,11 +58,11 @@ private static void LogInternal(LogType logType, string message, string source =
{
if (source == null)
{
UniLog.Log($"[NeosModLoader][{LogTypeName(logType)}] {message}");
UniLog.Log($"{GetTagFromLogType(logType)}[NeosModLoader] {message}");
}
else
{
UniLog.Log($"[NeosModLoader/{source}][{LogTypeName(logType)}] {message}");
UniLog.Log($"{GetTagFromLogType(logType)}[NeosModLoader/{source}] {message}");
}
}

Expand Down Expand Up @@ -85,15 +91,15 @@ private enum LogType
ERROR,
}

private static string LogTypeName(LogType logType)
private static string GetTagFromLogType(LogType logType)
{
switch(logType)
switch (logType)
{
case LogType.DEBUG: return "DEBUG";
case LogType.INFO: return "INFO";
case LogType.WARN: return "WARN";
case LogType.ERROR: return "ERROR";
default: return Enum.GetName(typeof(LogType), logType);
case LogType.DEBUG: return "[DEBUG]";
case LogType.INFO: return "[INFO] ";
case LogType.WARN: return "[WARN] ";
case LogType.ERROR: return "[ERROR]";
default: return $"[{Enum.GetName(typeof(LogType), logType)}]"; // should never happen, but just in case...
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions NeosModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NeosModLoader
{
internal class ModLoader
{
public static readonly string VERSION = "1.1.0";
public static readonly string VERSION = "1.2.0";
private static readonly Type NEOS_MOD_TYPE = typeof(NeosMod);
internal static Dictionary<Assembly, NeosMod> LoadedMods { get; } = new Dictionary<Assembly, NeosMod>();

Expand All @@ -25,6 +25,8 @@ internal static void LoadMods()
modsToLoad = Directory.GetFiles(modDirectory, "*.dll")
.Select(file => new ModAssembly(file))
.ToArray();

Array.Sort(modsToLoad, (a, b) => string.CompareOrdinal(a.File, b.File));
}
catch (Exception e)
{
Expand Down Expand Up @@ -103,7 +105,8 @@ private static void HookMod(ModAssembly mod)
if (modClasses.Length == 0)
{
Logger.ErrorInternal($"no mods found in {mod.File}");
} else if (modClasses.Length != 1)
}
else if (modClasses.Length != 1)
{
Logger.ErrorInternal($"more than one mod found in {mod.File}. no mods will be loaded.");
}
Expand Down
5 changes: 2 additions & 3 deletions NeosModLoader/NeosVersionReset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;

namespace NeosModLoader
{
Expand All @@ -25,9 +24,9 @@ internal static void Initialize()
return;
}

if (Configuration.get().UnsafeMode)
if (Configuration.get().Unsafe)
{
Logger.WarnInternal("Unsafe mode is on! Beware of using plugin components in multiplayer!");
Logger.WarnInternal("Unsafe mode is on! Version will be reset even if other plugins are detected! Beware of using plugin components in multiplayer!");
extraAssemblies.Clear();
}
else if (extraAssemblies.Count != 0)
Expand Down
4 changes: 2 additions & 2 deletions NeosModLoader/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// 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.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]

0 comments on commit c8bdbd8

Please sign in to comment.