Skip to content

Commit 8d565a2

Browse files
committed
Fixed CoreModule.PreLoad trying to read from GameData/Mods even when it doesn't exist
1 parent a28b841 commit 8d565a2

1 file changed

Lines changed: 47 additions & 15 deletions

File tree

src/PatchManager.Core/CoreModule.cs

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,62 @@ public override void Init()
8787
/// <inheritdoc />
8888
public override void PreLoad()
8989
{
90+
var gameDataModsExists = Directory.Exists(Path.Combine(Paths.GameRootPath, "GameData/Mods"));
91+
9092
// Go here instead so that the static constructor recognizes everything
9193
var disabledPlugins = File.ReadAllText(Path.Combine(Paths.BepInExRootPath, "disabled_plugins.cfg"))
9294
.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
9395

9496
var modFolders = Directory.GetDirectories(Paths.PluginPath, "*", SearchOption.AllDirectories)
95-
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x =>
96-
(Folder: x,
97-
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))))
97+
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json")))
98+
.Select(x => (
99+
Folder: x,
100+
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))
101+
))
98102
.ToList();
99-
modFolders.AddRange(Directory
100-
.GetDirectories(Path.Combine(Paths.GameRootPath, "GameData/Mods"), "*", SearchOption.AllDirectories)
101-
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x =>
102-
(Folder: x,
103-
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json"))))));
103+
104+
if (gameDataModsExists)
105+
{
106+
modFolders.AddRange(
107+
Directory
108+
.GetDirectories(Path.Combine(Paths.GameRootPath, "GameData/Mods"), "*", SearchOption.AllDirectories)
109+
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json")))
110+
.Select(x => (
111+
Folder: x,
112+
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))
113+
)));
114+
}
115+
104116
var gameRoot = new DirectoryInfo(Paths.GameRootPath);
105117

106-
var standalonePatches = Directory.EnumerateFiles(Path.Combine(Paths.GameRootPath, "GameData/Mods"), "*.patch",
107-
SearchOption.AllDirectories)
108-
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot)).Select(x => new FileInfo(x)).ToList();
109-
standalonePatches.AddRange(Directory.EnumerateFiles(Paths.PluginPath, "*.patch", SearchOption.AllDirectories)
110-
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot)).Select(x => new FileInfo(x)));
118+
var standalonePatches = Directory.EnumerateFiles(
119+
Paths.PluginPath,
120+
"*.patch",
121+
SearchOption.AllDirectories
122+
)
123+
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot))
124+
.Select(x => new FileInfo(x))
125+
.ToList();
126+
127+
if (gameDataModsExists)
128+
{
129+
standalonePatches.AddRange(
130+
Directory.EnumerateFiles(
131+
Path.Combine(Paths.GameRootPath, "GameData/Mods"),
132+
"*.patch",
133+
SearchOption.AllDirectories
134+
)
135+
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot))
136+
.Select(x => new FileInfo(x))
137+
);
138+
}
139+
140+
PatchingManager.GenerateUniverse(standalonePatches.Select(x =>
141+
x.Directory!.FullName
142+
.MakeRelativePathTo(gameRoot.FullName)
143+
.Replace("\\", "-")
144+
).ToHashSet());
111145

112-
PatchingManager.GenerateUniverse(standalonePatches
113-
.Select(x => x.Directory!.FullName.MakeRelativePathTo(gameRoot.FullName).Replace("\\","-")).ToHashSet());
114146
foreach (var modFolder in modFolders)
115147
{
116148
Logging.LogInfo($"Loading patchers from {modFolder.Folder}");

0 commit comments

Comments
 (0)