From 9103a5674412b2d95210260b1c6423dd183911fe Mon Sep 17 00:00:00 2001 From: Lexi Date: Mon, 30 Oct 2023 09:11:17 -0400 Subject: [PATCH 1/4] Remove invalid parts from vessels --- .../UpdateSavedVesselPartDefinitions.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/PatchManager.Parts/Patchers/UpdateSavedVesselPartDefinitions.cs b/src/PatchManager.Parts/Patchers/UpdateSavedVesselPartDefinitions.cs index 456ef91..2737949 100644 --- a/src/PatchManager.Parts/Patchers/UpdateSavedVesselPartDefinitions.cs +++ b/src/PatchManager.Parts/Patchers/UpdateSavedVesselPartDefinitions.cs @@ -21,6 +21,8 @@ public override void DoAction(Action resolve, Action reject) resolve(); return; } + List toRemove = new(); + int idx = 0; foreach (var vessel in _loadGameData.SavedGame.Vessels) { // Lets change only a few things @@ -29,6 +31,12 @@ public override void DoAction(Action resolve, Action reject) { var name = part.partName; var def = GameManager.Instance.Game.Parts.Get(name); + if (def == null) + { + Logging.LogWarning($"Invalid part {name} found on vessel {vessel.AssemblyDefinition.assemblyName}, removing vessel from save file\n"); + toRemove.Add(idx); + break; + } for (var i = part.PartModulesState.Count - 1; i >= 0; i--) { var i2 = i; @@ -59,7 +67,16 @@ public override void DoAction(Action resolve, Action reject) } } } + idx += 1; + } + + toRemove.Reverse(); + var vesselList = _loadGameData.SavedGame.Vessels.ToList(); + foreach (var removal in toRemove) + { + vesselList.RemoveAt(removal); } + _loadGameData.SavedGame.Vessels = vesselList.ToArray(); resolve(); } } \ No newline at end of file From 64aa4c1f448298c142a0b4442eeb2e1f362d5599 Mon Sep 17 00:00:00 2001 From: Lexi Date: Wed, 8 Nov 2023 09:49:39 -0500 Subject: [PATCH 2/4] Make it so patch managers loading actions are always the first ones run (such that addressables loading actions always run after) --- src/PatchManager.Core/CoreModule.cs | 18 +++++++++--------- src/PatchManager.Core/PatchManager.Core.csproj | 3 ++- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/PatchManager.Core/CoreModule.cs b/src/PatchManager.Core/CoreModule.cs index f439212..dbb808a 100644 --- a/src/PatchManager.Core/CoreModule.cs +++ b/src/PatchManager.Core/CoreModule.cs @@ -72,24 +72,24 @@ public override void Preload() if (!isValid) { _wasCacheInvalidated = true; - SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction( - () => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets)); - SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction( - () => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache)); + SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0,() => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets)); + SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(1,() => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache)); + SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(2, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator)); + // SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction( + // () => new GenericFlowAction("Patch Manager: Creating New Assets", PatchingManager.CreateNewAssets)); + // SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction( + // () => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache)); } } - /// /// Registers the provider and locator for cached assets. /// - public override void Load() + private void RegisterResourceLocator(Action resolve, Action reject) { - - Logging.LogInfo("Registering resource locator"); Addressables.ResourceManager.ResourceProviders.Add(new ArchiveResourceProvider()); Locators.Register(new ArchiveResourceLocator()); + resolve(); } - /// public override VisualElement GetDetails() { diff --git a/src/PatchManager.Core/PatchManager.Core.csproj b/src/PatchManager.Core/PatchManager.Core.csproj index d4e8ed5..25f3fce 100644 --- a/src/PatchManager.Core/PatchManager.Core.csproj +++ b/src/PatchManager.Core/PatchManager.Core.csproj @@ -2,8 +2,9 @@ + - + From 704ad066b7ce27ce25da9991297b7d44a8e61401 Mon Sep 17 00:00:00 2001 From: Lexi Date: Wed, 8 Nov 2023 09:50:45 -0500 Subject: [PATCH 3/4] Bump to 0.3.2 --- plugin_template/swinfo.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_template/swinfo.json b/plugin_template/swinfo.json index 9161a7e..aecb632 100644 --- a/plugin_template/swinfo.json +++ b/plugin_template/swinfo.json @@ -5,7 +5,7 @@ "name": "Patch Manager", "description": "A mod for generic patching needs similar to KSP 1's Module Manager.", "source": "https://github.com/KSP2Community/PatchManager", - "version": "0.3.1", + "version": "0.3.2", "version_check": "https://raw.githubusercontent.com/KSP2Community/PatchManager/main/plugin_template/swinfo.json", "ksp2_version": { "min": "0.1.5", From 6c4630004d6f061972ddf40b2a1be05ce7c2d43f Mon Sep 17 00:00:00 2001 From: Lexi Date: Wed, 8 Nov 2023 09:53:00 -0500 Subject: [PATCH 4/4] Still register the resource locator if invalid --- src/PatchManager.Core/CoreModule.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PatchManager.Core/CoreModule.cs b/src/PatchManager.Core/CoreModule.cs index dbb808a..8f45474 100644 --- a/src/PatchManager.Core/CoreModule.cs +++ b/src/PatchManager.Core/CoreModule.cs @@ -80,6 +80,10 @@ public override void Preload() // SpaceWarp.API.Loading.Loading.AddGeneralLoadingAction( // () => new GenericFlowAction("Patch Manager: Rebuilding Cache", PatchingManager.RebuildAllCache)); } + else + { + SpaceWarp.API.Loading.Loading.GeneralLoadingActions.Insert(0, () => new GenericFlowAction("Patch Manager: Registering Resource Locator", RegisterResourceLocator)); + } } /// /// Registers the provider and locator for cached assets.