Skip to content

Commit

Permalink
Fixed CoreModule.PreLoad trying to read from GameData/Mods even when …
Browse files Browse the repository at this point in the history
…it doesn't exist
  • Loading branch information
jan-bures committed Dec 26, 2023
1 parent a28b841 commit 8d565a2
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions src/PatchManager.Core/CoreModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,62 @@ public override void Init()
/// <inheritdoc />
public override void PreLoad()
{
var gameDataModsExists = Directory.Exists(Path.Combine(Paths.GameRootPath, "GameData/Mods"));

// Go here instead so that the static constructor recognizes everything
var disabledPlugins = File.ReadAllText(Path.Combine(Paths.BepInExRootPath, "disabled_plugins.cfg"))
.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);

var modFolders = Directory.GetDirectories(Paths.PluginPath, "*", SearchOption.AllDirectories)
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x =>
(Folder: x,
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))))
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json")))
.Select(x => (
Folder: x,
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))
))
.ToList();
modFolders.AddRange(Directory
.GetDirectories(Path.Combine(Paths.GameRootPath, "GameData/Mods"), "*", SearchOption.AllDirectories)
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json"))).Select(x =>
(Folder: x,
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json"))))));

if (gameDataModsExists)
{
modFolders.AddRange(
Directory
.GetDirectories(Path.Combine(Paths.GameRootPath, "GameData/Mods"), "*", SearchOption.AllDirectories)
.Where(dir => ShouldLoad(disabledPlugins, Path.Combine(dir, "swinfo.json")))
.Select(x => (
Folder: x,
Info: JsonConvert.DeserializeObject<ModInfo>(File.ReadAllText(Path.Combine(x, "swinfo.json")))
)));
}

var gameRoot = new DirectoryInfo(Paths.GameRootPath);

var standalonePatches = Directory.EnumerateFiles(Path.Combine(Paths.GameRootPath, "GameData/Mods"), "*.patch",
SearchOption.AllDirectories)
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot)).Select(x => new FileInfo(x)).ToList();
standalonePatches.AddRange(Directory.EnumerateFiles(Paths.PluginPath, "*.patch", SearchOption.AllDirectories)
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot)).Select(x => new FileInfo(x)));
var standalonePatches = Directory.EnumerateFiles(
Paths.PluginPath,
"*.patch",
SearchOption.AllDirectories
)
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot))
.Select(x => new FileInfo(x))
.ToList();

if (gameDataModsExists)
{
standalonePatches.AddRange(
Directory.EnumerateFiles(
Path.Combine(Paths.GameRootPath, "GameData/Mods"),
"*.patch",
SearchOption.AllDirectories
)
.Where(x => NoSwinfo(new FileInfo(x).Directory, gameRoot))
.Select(x => new FileInfo(x))
);
}

PatchingManager.GenerateUniverse(standalonePatches.Select(x =>
x.Directory!.FullName
.MakeRelativePathTo(gameRoot.FullName)
.Replace("\\", "-")
).ToHashSet());

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

0 comments on commit 8d565a2

Please sign in to comment.