Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions BepInExResoniteShim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,38 @@ class BepInExResoniteShim : BasePlugin
internal static new ManualLogSource Log = null!;
static ConfigEntry<bool> ShowWatermark = null!;

internal static string? GetBepisLoaderVersion()
{
try
{
var bepisLoaderAssembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.GetName().Name == "BepisLoader");

if (bepisLoaderAssembly != null)
{
var version = bepisLoaderAssembly.GetName().Version;
if (version != null)
{
return $"v{version.Major}.{version.Minor}.{version.Build}";
}
}
}
catch (Exception e)
{
Log.LogWarning($"Failed to get BepisLoader version: {e.Message}");
}

return null;
}

public override void Load()
{
Log = base.Log;

var bepisLoaderVersion = GetBepisLoaderVersion();
Log.LogInfo(bepisLoaderVersion != null
? $"Loader: BepisLoader {bepisLoaderVersion}"
: "Loader: BepisLoader not found, version unknown");
ShowWatermark = Config.Bind("General", "ShowWatermark", true, "Shows 'BepisLoader' watermark in the window title");

Type? lastAttempted = null;
Expand All @@ -48,7 +77,7 @@ public override void Load()
ConvertToObject = (str, type) => typeof(Coder<>).MakeGenericType(type).GetMethod("DecodeFromString")!.Invoke(null, [str])!,
});
}

lastAttempted = typeof(dummy);
TomlTypeConverter.AddConverter(typeof(dummy), new TypeConverter
{
Expand Down Expand Up @@ -157,30 +186,6 @@ public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructio
[HarmonyPatch(typeof(RendererInitData), "Pack")]
class WindowTitlePatcher
{
private static string? GetBepisLoaderVersion()
{
try
{
var bepisLoaderAssembly = AppDomain.CurrentDomain.GetAssemblies()
.FirstOrDefault(a => a.GetName().Name == "BepisLoader");

if (bepisLoaderAssembly != null)
{
var version = bepisLoaderAssembly.GetName().Version;
if (version != null)
{
return $" v{version.Major}.{version.Minor}.{version.Build}";
}
}
}
catch (Exception e)
{
Log.LogWarning($"Failed to get BepisLoader version: {e.Message}");
}

return null;
}

public static void Prefix(RendererInitData __instance)
{
if (!ShowWatermark.Value)
Expand All @@ -191,7 +196,7 @@ public static void Prefix(RendererInitData __instance)
if (__instance.windowTitle == "Resonite")
{
var version = GetBepisLoaderVersion();
var newTitle = $"Resonite - BepisLoader{version ?? ""}";
var newTitle = $"Resonite - BepisLoader {version ?? ""}";
__instance.windowTitle = newTitle;
Log.LogInfo($"Successfully patched window title to: {newTitle}");
}
Expand All @@ -201,7 +206,7 @@ public static void Prefix(RendererInitData __instance)

static class HarmonyExtensions
{
public static bool AnyPatchFailed { get; private set; }
public static bool AnyPatchFailed { get; private set; }
public static void SafePatchCategory(this Harmony instance, string categoryName)
{
try
Expand Down
Loading