Skip to content

Commit

Permalink
Removed references to System.Drawing from ModHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
slxdy committed Jun 10, 2024
1 parent 7effaf6 commit 11db972
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 37 deletions.
2 changes: 1 addition & 1 deletion TweaksLauncher.Game/Il2CppHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void LoadModHandler()

modHandler.GetType("TweaksLauncher.ModHandler", true)!
.InvokeMember("Start", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static, null, null,
[Program.baseDir, Program.gameName, Program.gamePath, new Action<string?, Color, string?, Color>(Logger.Log)]);
[Program.baseDir, Program.gameName, Program.gamePath, new Action<string?, byte, byte, byte, string?, byte, byte, byte>(Logger.Log)]);
}

private static nint OnIl2CppInit(nint domainName)
Expand Down
11 changes: 8 additions & 3 deletions TweaksLauncher.Game/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ static Logger()
}
}

public static void Log(string? message, byte baseColorR, byte baseColorG, byte baseColorB, string? moduleName, byte moduleColorR, byte moduleColorG, byte moduleColorB)
{
Log(message, Color.FromArgb(baseColorR, baseColorG, baseColorB), moduleName, Color.FromArgb(moduleColorR, moduleColorG, moduleColorB));
}

public static void Log(string? message, Color baseColor = default, string? moduleName = null, Color moduleColor = default)
{
if (message == null && moduleName == null)
Expand Down Expand Up @@ -54,7 +59,7 @@ public static void Log(string? message, Color baseColor = default, string? modul

if (message != string.Empty)
{
if (baseColor.A == 0)
if (baseColor.R == 0 && baseColor.G == 0 && baseColor.B == 0)
baseColor = Color.LightCyan;

message = message.Pastel(baseColor);
Expand All @@ -63,7 +68,7 @@ public static void Log(string? message, Color baseColor = default, string? modul
var consoleLog = $"[{time.Pastel(Color.DarkGray)}]";
if (moduleName != null)
{
if (moduleColor.A == 0)
if (moduleColor.R == 0 && moduleColor.G == 0 && moduleColor.B == 0)
moduleColor = Color.Magenta;

consoleLog += $"[{moduleName.Pastel(moduleColor)}]";
Expand All @@ -87,4 +92,4 @@ private static void OnProcessLog(object sender, DataReceivedEventArgs e)

Log(e.Data, moduleName: (sender as Process)?.ProcessName);
}
}
}
6 changes: 3 additions & 3 deletions TweaksLauncher.Game/MonoHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ private static void LoadModHandler(nint domain)
Mono.mono_runtime_invoke(startMethod, 0, args, null);
}

private static void LogImpl(nint monoMessage, int baseColor, nint monoModuleName, int moduleColor)
private static void LogImpl(nint monoMessage, byte baseColorR, byte baseColorG, byte baseColorB, nint monoModuleName, byte moduleColorR, byte moduleColorG, byte moduleColorB)
{
Logger.Log(monoMessage == 0 ? null : Mono.mono_string_to_utf16(monoMessage), Color.FromArgb(baseColor), monoModuleName == 0 ? null : Mono.mono_string_to_utf16(monoModuleName), Color.FromArgb(moduleColor));
Logger.Log(monoMessage == 0 ? null : Mono.mono_string_to_utf16(monoMessage), baseColorR, baseColorG, baseColorB, monoModuleName == 0 ? null : Mono.mono_string_to_utf16(monoModuleName), moduleColorR, moduleColorG, moduleColorB);
}

private static nint OnDomainInit(nint domainName, nint a)
Expand All @@ -80,5 +80,5 @@ private static nint OnDomainInit(nint domainName, nint a)
}

internal delegate nint MonoJitInitSig(nint domainName, nint a);
private delegate void LogImplSig(nint monoMessage, int baseColor, nint monoModuleName, int moduleColor);
private delegate void LogImplSig(nint monoMessage, byte baseColorR, byte baseColorG, byte baseColorB, nint monoModuleName, byte moduleColorR, byte moduleColorG, byte moduleColorB);
}
3 changes: 1 addition & 2 deletions TweaksLauncher.ModHandler/Il2Cpp/Il2CppEnumeratorWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Il2CppInterop.Runtime.Injection;
using System;
using System.Collections;
using System.Drawing;

namespace TweaksLauncher.Il2Cpp;

Expand Down Expand Up @@ -45,7 +44,7 @@ public bool MoveNext()
}
catch (Exception e)
{
ModHandler.Log(e.ToString(), Color.Red);
ModHandler.Log(e.ToString(), LogColor.Red);

return false;
}
Expand Down
6 changes: 3 additions & 3 deletions TweaksLauncher.ModHandler/LoadedMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public void Init()
}
catch (MissingMethodException)
{
ModHandler.Log($"Mod interface doesn't implement an 'Initialize' method: '{iMod.InterfaceType.FullName}'", System.Drawing.Color.Red);
ModHandler.Log($"Mod interface doesn't implement an 'Initialize' method: '{iMod.InterfaceType.FullName}'", LogColor.Red);
}
catch (Exception ex)
{
ModHandler.Log($"Mod interface failed to initialize: '{iMod.InterfaceType.FullName}'", System.Drawing.Color.Red);
ModHandler.Log(ex.ToString(), System.Drawing.Color.Red);
ModHandler.Log($"Mod interface failed to initialize: '{iMod.InterfaceType.FullName}'", LogColor.Red);
ModHandler.Log(ex.ToString(), LogColor.Red);
}
}
}
Expand Down
Loading

0 comments on commit 11db972

Please sign in to comment.