From 6cea286d204eb3754d3b8363a5a1fd6640164a49 Mon Sep 17 00:00:00 2001 From: MenShiyun Date: Fri, 16 Oct 2026 18:41:59 +0800 Subject: [PATCH] Fix GameDataPath exception in non-Unity3D games (#1416) When `GameDataPath` is invalid, do not throw an exception; instead, set both `GameDataPath` and `ManagedPath` to `null`. --- BepInEx.Core/Paths.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/BepInEx.Core/Paths.cs b/BepInEx.Core/Paths.cs index a1a44eb..5fbbc98 100644 --- a/BepInEx.Core/Paths.cs +++ b/BepInEx.Core/Paths.cs @@ -125,11 +125,11 @@ public static class Paths if (!Directory.Exists(GameDataPath)) GameDataPath = Path.Combine(GameRootPath, "Data"); } - - if (string.IsNullOrEmpty(GameDataPath) || !Directory.Exists(GameDataPath)) - throw new DirectoryNotFoundException("Failed to extract valid GameDataPath from executablePath: " + executablePath); - ManagedPath = managedPath ?? Path.Combine(GameDataPath, "Managed"); + if (string.IsNullOrEmpty(GameDataPath) || !Directory.Exists(GameDataPath)) + GameDataPath = null; + + ManagedPath = managedPath ?? (GameDataPath != null ? Path.Combine(GameDataPath, "Managed") : null); BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx"); ConfigPath = Path.Combine(BepInExRootPath, "config"); BepInExConfigPath = Path.Combine(ConfigPath, "BepInEx.cfg"); @@ -139,7 +139,7 @@ public static class Paths BepInExAssemblyPath = Path.Combine(BepInExAssemblyDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.dll"); CachePath = Path.Combine(BepInExRootPath, "cache"); - DllSearchPaths = (dllSearchPath ?? new string[0]).Concat(new[] { ManagedPath }).Distinct().ToArray(); + DllSearchPaths = (dllSearchPath ?? new string[0]).Concat(new[] { ManagedPath }).Where(p => p != null).Distinct().ToArray(); } internal static void SetPluginPath(string pluginPath) =>