From e6c4a10e5727eca02976b69cada58af01a095d2e Mon Sep 17 00:00:00 2001 From: KlaasWhite Date: Tue, 15 Sep 2026 19:20:20 +0200 Subject: [PATCH] Update KSA ref, fix restart popup and dependency loading --- StarMap.API/StarMap.API.csproj | 4 ++-- StarMap.Core/ModRepository/RuntimeMod.cs | 13 ++++++----- StarMap.Core/StarMap.Core.csproj | 4 ++-- .../UI/ConfirmRestart/ConfirmRestart.cs | 2 +- .../UI/ConfirmRestart/ConfirmRestartPopup.cs | 22 ++++++++++--------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/StarMap.API/StarMap.API.csproj b/StarMap.API/StarMap.API.csproj index 62c4121..70c3f45 100644 --- a/StarMap.API/StarMap.API.csproj +++ b/StarMap.API/StarMap.API.csproj @@ -20,14 +20,14 @@ - + compile; build; analyzers all - + compile; build; analyzers all diff --git a/StarMap.Core/ModRepository/RuntimeMod.cs b/StarMap.Core/ModRepository/RuntimeMod.cs index 1cb09b8..ae242ce 100644 --- a/StarMap.Core/ModRepository/RuntimeMod.cs +++ b/StarMap.Core/ModRepository/RuntimeMod.cs @@ -18,10 +18,11 @@ internal class RuntimeMod public required string ModId { get; init; } public required ModAssemblyLoadContext ModAssemblyLoadContext { get; init; } - public required Type ModType { get; init; } public required StarMapConfig Config { get; init; } + public required Assembly ModAssembly { get; init; } public bool Initialized { get; set; } = false; + public Type? ModType { get; set; } public object? ModInstance { get; set; } = null; public HashSet ExportedAssemblies { get; set; } = []; @@ -61,14 +62,11 @@ public static bool TryCreateMod(ModEntry manifestEntry, AssemblyLoadContext core var modLoadContext = new ModAssemblyLoadContext(manifestEntry.Id, modAssemblyFile, coreALC); var modAssembly = modLoadContext.LoadFromAssemblyName(new AssemblyName() { Name = starMapConfig.EntryAssembly }); - var modClass = modAssembly.GetTypes().FirstOrDefault(type => type.GetCustomAttributes().Any(attr => attr.GetType().Name == typeof(StarMapModAttribute).Name)); - if (modClass is null) return false; - runtimeMod = new RuntimeMod { ModId = manifestEntry.Id, ModAssemblyLoadContext = modLoadContext, - ModType = modClass, + ModAssembly = modAssembly, Config = starMapConfig, }; @@ -130,6 +128,11 @@ private static IEnumerable CalculateUseableAssemblies(RuntimeMod depende public bool InitializeMod(ModRegistry modRegistry) { + var modClass = ModAssembly.GetTypes().FirstOrDefault(type => type.GetCustomAttributes().Any(attr => attr.GetType().Name == typeof(StarMapModAttribute).Name)); + if (modClass is null) return false; + + ModType = modClass; + var modObject = Activator.CreateInstance(ModType); if (modObject is null) return false; ModInstance = modObject; diff --git a/StarMap.Core/StarMap.Core.csproj b/StarMap.Core/StarMap.Core.csproj index 7abfbb0..1ec9d02 100644 --- a/StarMap.Core/StarMap.Core.csproj +++ b/StarMap.Core/StarMap.Core.csproj @@ -25,13 +25,13 @@ - + runtime - + runtime diff --git a/StarMap.Core/UI/ConfirmRestart/ConfirmRestart.cs b/StarMap.Core/UI/ConfirmRestart/ConfirmRestart.cs index 339f8c1..17cadde 100644 --- a/StarMap.Core/UI/ConfirmRestart/ConfirmRestart.cs +++ b/StarMap.Core/UI/ConfirmRestart/ConfirmRestart.cs @@ -32,7 +32,7 @@ public void DrawUi() { if (!Show) return; - ImGuiHelper.BlankBackground(); + ImGuiHelper.BlankBackground(ImGuiHelper.GetMainOverlayDrawList()); Popup.DrawAll(); } diff --git a/StarMap.Core/UI/ConfirmRestart/ConfirmRestartPopup.cs b/StarMap.Core/UI/ConfirmRestart/ConfirmRestartPopup.cs index 03b22eb..a21a8e7 100644 --- a/StarMap.Core/UI/ConfirmRestart/ConfirmRestartPopup.cs +++ b/StarMap.Core/UI/ConfirmRestart/ConfirmRestartPopup.cs @@ -1,10 +1,13 @@ using Brutal.ImGuiApi; +using Brutal.Numerics; using KSA; namespace StarMap.Core.UI.ConfirmRestart { internal class ConfirmRestartPopup : Popup { + private static readonly float2 SIZE_UV = new float2(0.32f, 0.213333f); + private readonly string _title; public ConfirmRestart UI { get; } private static readonly PopupButton PopupButtonContinue = CreateButton("Continue", (Action)(popup => @@ -20,7 +23,7 @@ internal class ConfirmRestartPopup : Popup popup.UI.Show = false; })); - private static readonly IPopupWidget[] ButtonMatrix = [ + private static readonly PopupButton[] ButtonMatrix = [ PopupButtonContinue, PopupButtonRestart ]; @@ -35,15 +38,14 @@ private ConfirmRestartPopup(ConfirmRestart ui) protected override void OnDrawUi() { - ImGui.OpenPopup((ImString)_title); - ImGui.BeginPopup((ImString)_title, ImGuiWindowFlags.NoMove | ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.Popup); - ImGuiHelper.SetCurrentWindowToCenter(); - var text1 = new ImString(60, 1); - text1.AppendLiteral("New mods have been enabled after starting KSA.\nThe game needs to be restarted for these mods to be loaded in StarMap.".AsSpan()); - ImGui.TextWrapped(text1); - ImGui.Separator(); - DrawUi(this, ButtonMatrix); - ImGui.EndPopup(); + if (!BeginConsoleModal(WindowId.AsSpan(), _title.AsSpan(), SIZE_UV)) + return; + ConsoleStyle.BeginBody(); + ConsoleStyle.PushWidgetStyle(); + CenteredWrappedText("New mods have been enabled after starting KSA.\nThe game needs to be restarted for these mods to be loaded in StarMap.".AsSpan()); + EndConsoleBody(); + DrawConsoleButtonRow(this, ButtonMatrix); + EndConsoleModal(); } } }