From fd5d308a7e0aa265aee7ffba3753f7fe5e098f7b Mon Sep 17 00:00:00 2001 From: art0007i Date: Tue, 23 Sep 2025 16:49:38 +0200 Subject: [PATCH 1/5] Revert "Fix direct launches" This reverts commit 84182a877cf2a89629265029ebb87a08d05ddef2. --- Runtimes/NET/BepisLoader/BepisLoader.cs | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/Runtimes/NET/BepisLoader/BepisLoader.cs b/Runtimes/NET/BepisLoader/BepisLoader.cs index 9e83cbb1..f1367737 100644 --- a/Runtimes/NET/BepisLoader/BepisLoader.cs +++ b/Runtimes/NET/BepisLoader/BepisLoader.cs @@ -1,4 +1,3 @@ -using System.Diagnostics; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Loader; @@ -31,20 +30,6 @@ static void Main(string[] args) var asm = alc.LoadFromAssemblyPath(Path.Combine(bepinPath, "core", "BepInEx.NET.CoreCLR.dll")); - // Check if we're launching from outside the game directory - var exePath = Process.GetCurrentProcess().MainModule?.FileName; - if (exePath != null) - { - var exeDir = Path.GetDirectoryName(exePath); - if (exeDir != resoDir) - { - // Change working directory to the game directory for direct launches - Log($"Changing working directory from {resoDir} to {exeDir}"); - Directory.SetCurrentDirectory(exeDir); - resoDir = exeDir; - } - } - var resoDllPath = Path.Combine(resoDir, "Renderite.Host.dll"); if (!File.Exists(resoDllPath)) resoDllPath = Path.Combine(resoDir, "Resonite.dll"); @@ -53,8 +38,8 @@ static void Main(string[] args) m.Invoke(null, [resoDllPath, bepinPath, alc]); // Find and load Resonite - var resoAsm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == "Renderite.Host"); - if (resoAsm == null && File.Exists(resoDllPath)) + var resoAsm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == "Resonite"); + if (resoAsm == null) { resoAsm = alc.LoadFromAssemblyPath(resoDllPath); } From 6c71cc9fe22be7e79dccb6300ba0e8f8375c6388 Mon Sep 17 00:00:00 2001 From: art0007i Date: Tue, 23 Sep 2025 21:01:18 +0200 Subject: [PATCH 2/5] Stop relying on working directory --- Runtimes/NET/BepisLoader/BepisLoader.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Runtimes/NET/BepisLoader/BepisLoader.cs b/Runtimes/NET/BepisLoader/BepisLoader.cs index f1367737..a243b9d7 100644 --- a/Runtimes/NET/BepisLoader/BepisLoader.cs +++ b/Runtimes/NET/BepisLoader/BepisLoader.cs @@ -10,10 +10,11 @@ public class BepisLoader internal static AssemblyLoadContext alc = null!; static void Main(string[] args) { + resoDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); #if DEBUG - File.WriteAllText("BepisLoader.log", "BepisLoader started\n"); + logPath = Path.Combine(resoDir, "BepisLoader.log"); + File.WriteAllText(logPath, "BepisLoader started\n"); #endif - resoDir = Directory.GetCurrentDirectory(); alc = new BepisLoadContext(); @@ -38,19 +39,20 @@ static void Main(string[] args) m.Invoke(null, [resoDllPath, bepinPath, alc]); // Find and load Resonite - var resoAsm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == "Resonite"); - if (resoAsm == null) - { - resoAsm = alc.LoadFromAssemblyPath(resoDllPath); - } + var resoAsm = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name == "Renderite.Host"); + try { + if (resoAsm == null) + { + resoAsm = alc.LoadFromAssemblyPath(resoDllPath); + } var result = resoAsm.EntryPoint!.Invoke(null, [args]); if (result is Task task) task.Wait(); } catch (Exception e) { - File.WriteAllLines("BepisCrash.log", [DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " - Resonite crashed", e.ToString()]); + File.WriteAllLines(Path.Combine(resoDir, "BepisCrash.log"), [DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " - Resonite crashed", e.ToString()]); } } @@ -152,6 +154,7 @@ private static string GetUnmanagedLibraryName(string name) } #if DEBUG + private static string logPath; private static object _lock = new object(); #endif public static void Log(string message) @@ -159,7 +162,7 @@ public static void Log(string message) #if DEBUG lock (_lock) { - File.AppendAllLines("BepisLoader.log", [message]); + File.AppendAllLines(logPath, [message]); } #endif } From b4c30d68a953f702eb06577705747d3aba9a9aed Mon Sep 17 00:00:00 2001 From: art0007i Date: Wed, 24 Sep 2025 23:07:32 +0200 Subject: [PATCH 3/5] chmod +x LinuxBootstrap.sh --- Runtimes/NET/BepisLoader/LinuxBootstrap.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 Runtimes/NET/BepisLoader/LinuxBootstrap.sh diff --git a/Runtimes/NET/BepisLoader/LinuxBootstrap.sh b/Runtimes/NET/BepisLoader/LinuxBootstrap.sh old mode 100644 new mode 100755 From 7f0789de1eda1dad5bd91080dc74644d7afe8fe2 Mon Sep 17 00:00:00 2001 From: art0007i Date: Wed, 24 Sep 2025 23:44:33 +0200 Subject: [PATCH 4/5] Workaround for cake-build/cake#2592 --- build/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build/Program.cs b/build/Program.cs index 9dfad98a..1d6a0668 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -587,9 +587,9 @@ public override void Run(BuildContext ctx) { var targetZipName = $"BepInEx-{dist.Target}-{ctx.BuildPackageVersion}.zip"; ctx.Log.Information($"Packing {targetZipName}"); - ctx.Zip(ctx.DistributionDirectory.Combine(dist.Target), - ctx.DistributionDirectory - .CombineWithFilePath(targetZipName)); + // https://github.com/cake-build/cake/issues/2592 + System.IO.Compression.ZipFile.CreateFromDirectory(ctx.DistributionDirectory.Combine(dist.Target).FullPath, + ctx.DistributionDirectory.CombineWithFilePath(targetZipName).FullPath); } From f4c1f86f994109612ceb7bf62431827af313fbee Mon Sep 17 00:00:00 2001 From: haz <37149950+hazre@users.noreply.github.com> Date: Thu, 25 Sep 2025 02:48:13 +0200 Subject: [PATCH 5/5] Add FixThunderstoreLinuxPermissions Task to build project (#24) * Add FixThunderstoreLinuxPermissions Task to build project * Remove BepisLoader.dll from FixThunderstoreLinuxPermissions and Fix temp directory path --- build/Program.cs | 67 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/build/Program.cs b/build/Program.cs index 1d6a0668..21f51bcb 100644 --- a/build/Program.cs +++ b/build/Program.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.Versioning; using System.Text; using Cake.Common; using Cake.Common.IO; @@ -573,10 +574,74 @@ public override void Run(BuildContext ctx) } } +[TaskName("FixThunderstoreLinuxPermissions")] +[IsDependentOn(typeof(BuildThunderstorePackageTask))] +[SupportedOSPlatform("linux")] +public sealed class FixThunderstoreLinuxPermissionsTask : FrostingTask +{ + public override bool ShouldRun(BuildContext ctx) => + ctx.Distributions.Any(d => d.Runtime == "BepisLoader") && + System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); + + [SupportedOSPlatform("linux")] + public override void Run(BuildContext ctx) + { + ctx.Log.Information("Fixing Linux permissions in Thunderstore package..."); + + var thunderstorePackageDir = ctx.DistributionDirectory.Combine("thunderstore-package"); + var packageFiles = ctx.GetFiles(thunderstorePackageDir.Combine("*.zip").FullPath); + + foreach (var packageFile in packageFiles) + { + ctx.Log.Information($"Fixing Linux permissions in {packageFile.GetFilename()}..."); + + var tempDir = ctx.DistributionDirectory.Combine("temp-thunderstore-fix"); + if (ctx.DirectoryExists(tempDir)) + { + ctx.CleanDirectory(tempDir); + } + else + { + ctx.CreateDirectory(tempDir); + } + + System.IO.Compression.ZipFile.ExtractToDirectory(packageFile.FullPath, tempDir.FullPath); + + var executablePermissions = System.IO.UnixFileMode.UserExecute | + System.IO.UnixFileMode.GroupExecute | + System.IO.UnixFileMode.OtherExecute; + + var executableFiles = new[] { "LinuxBootstrap.sh" }; + + foreach (var fileName in executableFiles) + { + var filePath = tempDir.CombineWithFilePath($"BepInExPack/{fileName}"); + if (ctx.FileExists(filePath)) + { + var fileInfo = new System.IO.FileInfo(filePath.FullPath); + var originalMode = fileInfo.UnixFileMode; + ctx.Log.Information($"Original permissions for {fileName}: {Convert.ToString((int)originalMode, 8).PadLeft(3, '0')} ({originalMode})"); + + fileInfo.UnixFileMode |= executablePermissions; + + var newMode = fileInfo.UnixFileMode; + ctx.Log.Information($"New permissions for {fileName}: {Convert.ToString((int)newMode, 8).PadLeft(3, '0')} ({newMode})"); + } + } + + ctx.DeleteFile(packageFile); + + System.IO.Compression.ZipFile.CreateFromDirectory(tempDir.FullPath, packageFile.FullPath); + + ctx.Log.Information($"Fixed Linux permissions in {packageFile.GetFilename()}"); + } + } +} + [TaskName("Publish")] [IsDependentOn(typeof(MakeDistTask))] [IsDependentOn(typeof(PushNuGetTask))] -[IsDependentOn(typeof(BuildThunderstorePackageTask))] +[IsDependentOn(typeof(FixThunderstoreLinuxPermissionsTask))] public sealed class PublishTask : FrostingTask { public override void Run(BuildContext ctx)