From ebb123f242a9649316e5c795cff54b8de1709215 Mon Sep 17 00:00:00 2001 From: hazre <37149950+hazre@users.noreply.github.com> Date: Fri, 26 Sep 2025 00:01:54 +0200 Subject: [PATCH 1/2] Fix relative paths --- BepInExResoniteShim.cs | 1 + RelativePathFixer.cs | 82 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 RelativePathFixer.cs diff --git a/BepInExResoniteShim.cs b/BepInExResoniteShim.cs index 7735e3b..96bdb78 100644 --- a/BepInExResoniteShim.cs +++ b/BepInExResoniteShim.cs @@ -70,6 +70,7 @@ void RunPatches() HarmonyInstance.SafePatchCategory(nameof(GraphicalClientPatch)); HarmonyInstance.SafePatchCategory(nameof(WindowTitlePatcher)); HarmonyInstance.SafePatchCategory(nameof(LogAlerter)); + HarmonyInstance.SafePatchCategory(nameof(RelativePathFixer)); } [HarmonyPatch] diff --git a/RelativePathFixer.cs b/RelativePathFixer.cs new file mode 100644 index 0000000..cea7fbd --- /dev/null +++ b/RelativePathFixer.cs @@ -0,0 +1,82 @@ +using BepInEx; +using FrooxEngine; +using HarmonyLib; +using System.Diagnostics; + +namespace BepInExResoniteShim; + +class RelativePathFixer +{ + [HarmonyPatchCategory(nameof(RelativePathFixer))] + [HarmonyPatch(typeof(LaunchOptions))] + class LaunchOptionsPathPatcher + { + [HarmonyPostfix] + [HarmonyPatch(nameof(LaunchOptions.LogsDirectory), MethodType.Getter)] + public static void LogsDirectory_Postfix(ref string __result) + { + if (string.IsNullOrWhiteSpace(__result)) + { + __result = "Logs"; + } + + if (!string.IsNullOrWhiteSpace(__result) && !Path.IsPathRooted(__result)) + { + var absolutePath = Path.Combine(Paths.GameRootPath, __result); + BepInExResoniteShim.Log.LogDebug($"Patched LogsDirectory from '{__result}' to '{absolutePath}'"); + __result = absolutePath; + } + } + + [HarmonyPostfix] + [HarmonyPatch(nameof(LaunchOptions.OverrideRendererIcon), MethodType.Getter)] + public static void OverrideRendererIcon_Postfix(ref string __result) + { + if (!string.IsNullOrWhiteSpace(__result) && !Path.IsPathRooted(__result)) + { + var absolutePath = Path.Combine(Paths.GameRootPath, __result); + BepInExResoniteShim.Log.LogDebug($"Patched OverrideRendererIcon from '{__result}' to '{absolutePath}'"); + __result = absolutePath; + } + } + } + + [HarmonyPatchCategory(nameof(RelativePathFixer))] + [HarmonyPatch(typeof(Process), nameof(Process.Start), typeof(ProcessStartInfo))] + class StartRendererPatch + { + public static void Prefix(ProcessStartInfo startInfo) + { + if (startInfo == null) return; + + if (startInfo.FileName != null && startInfo.FileName.Contains("Renderite.Renderer.exe")) + { + if (startInfo.WorkingDirectory == "Renderer" || string.IsNullOrEmpty(startInfo.WorkingDirectory)) + { + var originalWorkingDir = startInfo.WorkingDirectory; + var correctWorkingDir = Path.GetDirectoryName(startInfo.FileName); + startInfo.WorkingDirectory = correctWorkingDir; + BepInExResoniteShim.Log.LogDebug($"Patched renderer WorkingDirectory from '{originalWorkingDir}' to '{correctWorkingDir}'"); + } + } + } + } + + [HarmonyPatchCategory(nameof(RelativePathFixer))] + [HarmonyPatch(typeof(File), nameof(File.WriteAllText), typeof(string), typeof(string))] + class CrashLogPathFixer + { + public static void Prefix(ref string path, string contents) + { + if (path != null && path.Contains("Renderite.Host.Crash")) + { + if (!Path.IsPathRooted(path)) + { + var absolutePath = Path.Combine(Paths.GameRootPath, path); + BepInExResoniteShim.Log.LogDebug($"Patched crash log path from '{path}' to '{absolutePath}'"); + path = absolutePath; + } + } + } + } +} From 0a7e976b36e22c6cbcf2d10c34a46e646f1d122a Mon Sep 17 00:00:00 2001 From: art0007i Date: Fri, 26 Sep 2025 05:22:52 +0200 Subject: [PATCH 2/2] refactor fixes to use transpiler instead --- .gitignore | 5 ++- BepInExResoniteShim.csproj | 48 ++++++++++++--------- RelativePathFixer.cs | 87 +++++++++++++++----------------------- 3 files changed, 67 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index 9491a2f..dc0b9a9 100644 --- a/.gitignore +++ b/.gitignore @@ -360,4 +360,7 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd + +# Thunderstore CLI builds +/build \ No newline at end of file diff --git a/BepInExResoniteShim.csproj b/BepInExResoniteShim.csproj index d04ac7b..62a57a9 100644 --- a/BepInExResoniteShim.csproj +++ b/BepInExResoniteShim.csproj @@ -15,14 +15,14 @@ enable true false - true + false true true embedded - $(ResonitePath)/ - $(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\ - $(HOME)/.steam/steam/steamapps/common/Resonite/ - $(GamePath)BepInEx\plugins\$(AssemblyName) + $(ResonitePath)/ + $(MSBuildProgramFiles32)\Steam\steamapps\common\Resonite\ + $(HOME)/.steam/steam/steamapps/common/Resonite/ + $(GamePath)BepInEx\plugins\$(AssemblyName) $(AssemblyName) https://nuget-modding.resonite.net/v3/index.json @@ -30,18 +30,22 @@ - - - - - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + - - + + + + + + + $(GamePath)FrooxEngine.dll False @@ -50,15 +54,19 @@ $(GamePath)Elements.Core.dll False - - $(GamePath)Renderite.Host.dll - False - + + $(GamePath)Renderite.Host.dll + False + $(GamePath)Renderite.Shared.dll False + + + + diff --git a/RelativePathFixer.cs b/RelativePathFixer.cs index cea7fbd..726877a 100644 --- a/RelativePathFixer.cs +++ b/RelativePathFixer.cs @@ -1,81 +1,64 @@ using BepInEx; using FrooxEngine; using HarmonyLib; -using System.Diagnostics; +using System.Reflection; +using System.Reflection.Emit; namespace BepInExResoniteShim; class RelativePathFixer { [HarmonyPatchCategory(nameof(RelativePathFixer))] - [HarmonyPatch(typeof(LaunchOptions))] - class LaunchOptionsPathPatcher + [HarmonyPatch(typeof(Program), "
$", MethodType.Async)] + class RenderiteHostPathFixes { - [HarmonyPostfix] - [HarmonyPatch(nameof(LaunchOptions.LogsDirectory), MethodType.Getter)] - public static void LogsDirectory_Postfix(ref string __result) + public static IEnumerable Transpiler(IEnumerable codes) { - if (string.IsNullOrWhiteSpace(__result)) + foreach (var code in codes) { - __result = "Logs"; - } - - if (!string.IsNullOrWhiteSpace(__result) && !Path.IsPathRooted(__result)) - { - var absolutePath = Path.Combine(Paths.GameRootPath, __result); - BepInExResoniteShim.Log.LogDebug($"Patched LogsDirectory from '{__result}' to '{absolutePath}'"); - __result = absolutePath; - } - } - - [HarmonyPostfix] - [HarmonyPatch(nameof(LaunchOptions.OverrideRendererIcon), MethodType.Getter)] - public static void OverrideRendererIcon_Postfix(ref string __result) - { - if (!string.IsNullOrWhiteSpace(__result) && !Path.IsPathRooted(__result)) - { - var absolutePath = Path.Combine(Paths.GameRootPath, __result); - BepInExResoniteShim.Log.LogDebug($"Patched OverrideRendererIcon from '{__result}' to '{absolutePath}'"); - __result = absolutePath; + if (code.Is(OpCodes.Ldstr, "Logs")) + { + yield return new(OpCodes.Ldstr, Path.Combine(Paths.GameRootPath, "Logs")); + continue; + } + if (code.Is(OpCodes.Ldstr, "Icon.png")) + { + yield return new(OpCodes.Ldstr, Path.Combine(Paths.GameRootPath, "Icon.png")); + continue; + } + if(code.operand is MethodInfo mf && mf.Name == nameof(File.WriteAllText)) + { + yield return new(OpCodes.Call, AccessTools.Method(typeof(RenderiteHostPathFixes), nameof(FileWriteInjected))); + continue; + } + yield return code; } } - } - [HarmonyPatchCategory(nameof(RelativePathFixer))] - [HarmonyPatch(typeof(Process), nameof(Process.Start), typeof(ProcessStartInfo))] - class StartRendererPatch - { - public static void Prefix(ProcessStartInfo startInfo) + public static void FileWriteInjected(string path, string? contents) { - if (startInfo == null) return; - - if (startInfo.FileName != null && startInfo.FileName.Contains("Renderite.Renderer.exe")) + if (!Path.IsPathRooted(path)) { - if (startInfo.WorkingDirectory == "Renderer" || string.IsNullOrEmpty(startInfo.WorkingDirectory)) - { - var originalWorkingDir = startInfo.WorkingDirectory; - var correctWorkingDir = Path.GetDirectoryName(startInfo.FileName); - startInfo.WorkingDirectory = correctWorkingDir; - BepInExResoniteShim.Log.LogDebug($"Patched renderer WorkingDirectory from '{originalWorkingDir}' to '{correctWorkingDir}'"); - } + path = Path.Combine(Paths.GameRootPath, path); } + File.WriteAllText(path, contents); } } [HarmonyPatchCategory(nameof(RelativePathFixer))] - [HarmonyPatch(typeof(File), nameof(File.WriteAllText), typeof(string), typeof(string))] - class CrashLogPathFixer + [HarmonyPatch(typeof(RenderSystem), "StartRenderer", MethodType.Async)] + public class RenderiteWorkingDirectoryFix { - public static void Prefix(ref string path, string contents) - { - if (path != null && path.Contains("Renderite.Host.Crash")) + public static IEnumerable Transpiler(IEnumerable codes) + { + foreach (var code in codes) { - if (!Path.IsPathRooted(path)) + if(code.Is(OpCodes.Ldstr, "Renderer")) { - var absolutePath = Path.Combine(Paths.GameRootPath, path); - BepInExResoniteShim.Log.LogDebug($"Patched crash log path from '{path}' to '{absolutePath}'"); - path = absolutePath; + yield return new(OpCodes.Ldstr, Path.Combine(Paths.GameRootPath, "Renderer")); + continue; } + yield return code; } } }