mirror of
https://github.com/BepInEx/BepInEx.git
synced 2026-10-19 15:51:45 +00:00
Fix failing to initialize if game's Data folder is just 'Data' (#975)
Any Unity game can have its _Data folder renamed to just Data and continue working just fine.
This commit is contained in:
1 parent
5a324246f1
commit
6b38cee127
2 files changed
+19
-6
No files matched your search
+18
-4
@@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MonoMod.Utils;
|
||||
@@ -106,9 +106,23 @@ public static class Paths
|
||||
? Utility.ParentDirectory(executablePath, 4)
|
||||
: Path.GetDirectoryName(executablePath);
|
||||
|
||||
GameDataPath = managedPath != null && gameDataRelativeToManaged
|
||||
? Path.GetDirectoryName(managedPath)
|
||||
: Path.Combine(GameRootPath, $"{ProcessName}_Data");
|
||||
if (managedPath != null && gameDataRelativeToManaged)
|
||||
{
|
||||
GameDataPath = Path.GetDirectoryName(managedPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// According to some experiments, Unity checks whether globalgamemanagers/data.unity3d exists in the data folder before picking it.
|
||||
// 'ProcessName_Data' folder is checked first, then if that fails 'Data' folder is checked. If neither is valid, the player crashes.
|
||||
// A simple Directory.Exists check is accurate enough while being less likely to break in case these conditions change.
|
||||
GameDataPath = Path.Combine(GameRootPath, $"{ProcessName}_Data");
|
||||
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");
|
||||
BepInExRootPath = bepinRootPath ?? Path.Combine(GameRootPath, "BepInEx");
|
||||
ConfigPath = Path.Combine(BepInExRootPath, "config");
|
||||
|
||||
@@ -281,8 +281,7 @@ internal static partial class Il2CppInteropManager
|
||||
{
|
||||
Logger.LogMessage("Running Cpp2IL to generate dummy assemblies");
|
||||
|
||||
var metadataPath = Path.Combine(Paths.GameRootPath,
|
||||
$"{Paths.ProcessName}_Data",
|
||||
var metadataPath = Path.Combine(Paths.GameDataPath,
|
||||
"il2cpp_data",
|
||||
"Metadata",
|
||||
"global-metadata.dat");
|
||||
|
||||
Reference in new issue
Block a user