Repository navigation
Add StarMapAfterSave and StarMapAfterLoad hooks - #85
Open
LaurensDeV wants to merge 1 commit into
Open
LaurensDeV wants to merge 1 commit into
LaurensDeV wants to merge 1 commit into
Conversation
github-actions
Bot
changed the base branch from
main
to
feature/external/pr-85-feature-save-and-load-hooks
August 6, 2026 16:39
LaurensDeV
marked this pull request as ready for review
August 6, 2026 16:42
A mod that keeps per-save state has no way to be told when a save is written or loaded, so it has to poll universe.xml's timestamp, which misses a save and load inside the poll window. Both hooks pass the save's directory, because a save is a directory and what a mod usually wants is a file beside universe.xml. AfterSave is a postfix on UncompressedSave.Make, which every save, overwrite and save-as goes through; it is skipped when the write fails. AfterLoad fires after UncompressedSave.Load, but only when that load reached Program.OnGameLoaded. Load returns early when a save cannot be read, so a postfix on it alone would report loads that never happened. Registered once through the patch manager rather than per mod, so the hooks do not take a mod's own slot on these methods, and each mod's callback is isolated so one exception does not stop the rest or reach KSA's save path.
LaurensDeV
force-pushed
the
feature/save-and-load-hooks
branch
from
October 25, 2026 12:17
eacf529 to
16f248b
Compare
LaurensDeV
changed the base branch from
feature/external/pr-85-feature-save-and-load-hooks
to
main
October 25, 2026 12:17
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
A mod that keeps per-save state has no way to be told when a save is written or loaded. KSA raises no event for either, so the only signal is polling
universe.xml's timestamp, which misses a save and load that happen inside one poll.The change
Two lifecycle attributes, following the existing ones:
Both pass the save's directory, because a save is a directory and what a mod usually wants is a file beside
universe.xml.StarMapAfterSaveis a postfix onUncompressedSave.Make(string), which every save, overwrite and save-as goes through. It is not called when the write fails (Makereturns null).StarMapAfterLoadfires afterUncompressedSave.Load(), but only when that load reachedProgram.OnGameLoaded().Loadreturns early when a save cannot be read, so a postfix on it alone would report loads that never happened;OnGameLoadedis called only onceUniverse.DeserializeSavehas rebuilt the world.How it is wired
mainand moved onto the newPatchManager.SaveLoadPatchesregisters the patches once, owned by StarMap itself (modnull), like the menu and restart patches, and dispatches to every mod's attributed methods throughModRegistry. Registering per mod would take each mod's one slot on these methods, so a mod could not then patchLoaditself.docs/modding/lifecycle.mdlists both attributes.Verification
SaveHookandWorldReloadHook), checked against the decompiled 5638 source.Building note: the Debug configuration on
maindoes not referencePlanet.Core.dllorPlanet.Render.Core.dll, whichConfirmRestartneeds, so Debug does not compile against a plainImport/folder. I added those two references from outside the repository to build; this PR does not change the csproj.