From f198b102255c06db35bab86ba0fe9c21499ee341 Mon Sep 17 00:00:00 2001 From: KlaasWhite Date: Fri, 14 Nov 2025 14:32:03 +0100 Subject: [PATCH] Final changes so it can load mods for KSA --- StarMap.Core/ModLoaderPatcher.cs | 5 ----- StarMap.Core/ModManager.cs | 7 ++++++- StarMap.Core/StarMap.Core.csproj | 15 ++++++++++++--- StarMap/GameSurveyer.cs | 1 + 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/StarMap.Core/ModLoaderPatcher.cs b/StarMap.Core/ModLoaderPatcher.cs index ed20131..2bbb994 100644 --- a/StarMap.Core/ModLoaderPatcher.cs +++ b/StarMap.Core/ModLoaderPatcher.cs @@ -18,7 +18,6 @@ public static void Patch(ModManager modManager) public static void Unload() { _modManager = null; - //MainScreen.Screens = []; _harmony?.UnpatchAll(); } @@ -34,10 +33,6 @@ public static void OnLoadMod(this Mod __instance) public static void AfterLoad() { _modManager?.OnAllModsLoaded(); - /*var screens = MainScreen.Screens.ToList(); - screens.Insert(MainScreen.Screens.Length - 1, new ModManagerScreen(_modManager)); - - MainScreen.Screens = screens.ToArray();*/ _harmony?.UnpatchAll(_harmony.Id); } } diff --git a/StarMap.Core/ModManager.cs b/StarMap.Core/ModManager.cs index cddeb65..2f7ab31 100644 --- a/StarMap.Core/ModManager.cs +++ b/StarMap.Core/ModManager.cs @@ -43,7 +43,12 @@ public void DeInit() { public void LoadMod(Mod mod) { - if (!Directory.Exists(mod.DirectoryPath)) return; + var fullPath = Path.GetFullPath(mod.DirectoryPath); + var filePath = Path.Combine(fullPath, $"{mod.Name}.dll"); + var folderExists = Directory.Exists(fullPath); + var fileExists = File.Exists(filePath); + + if (!folderExists || !fileExists) return; var modLoadContext = new ModAssemblyLoadContext(mod, _coreAssemblyLoadContext); var modAssembly = modLoadContext.LoadFromAssemblyName(new AssemblyName() { Name = mod.Name }); diff --git a/StarMap.Core/StarMap.Core.csproj b/StarMap.Core/StarMap.Core.csproj index 1488325..4b8a98c 100644 --- a/StarMap.Core/StarMap.Core.csproj +++ b/StarMap.Core/StarMap.Core.csproj @@ -8,9 +8,6 @@ - - runtime - @@ -18,4 +15,16 @@ + + + runtime + + + + + + runtime + + + diff --git a/StarMap/GameSurveyer.cs b/StarMap/GameSurveyer.cs index 2e94dd8..07eaa6f 100644 --- a/StarMap/GameSurveyer.cs +++ b/StarMap/GameSurveyer.cs @@ -46,6 +46,7 @@ public void RunGame() Debug.Assert(_game is not null, "Load needs to be called before running game"); string[] args = []; + Directory.SetCurrentDirectory(Path.GetDirectoryName(_gameLocation)); _game.EntryPoint!.Invoke(null, [args]); }