Add StarMapAfterSave and StarMapAfterLoad hooks - #85
Open
LaurensDeV wants to merge 2 commits into
Open
Conversation
A mod that keeps per-save state has no way to be told when a save happens. The only signal available today is polling the save file's timestamp, which leaves a window: save and load inside it and the mod writes nothing for that save, then writes over it once the poll finally fires. Shortening the interval narrows the window without closing it. Both hooks pass the save's DirectoryInfo, because a save is a directory and what a mod usually wants is to put a file beside universe.xml -- so it is deleted, copied and renamed along with the save it belongs to. Patched on UniverseData.WriteTo(DirectoryInfo) and UniverseData.LoadFrom, both public. WriteTo is overloaded, so the patch names the argument type. Verified against KSA 2026.8.5.5168; the repository pins 2026.7.6.4939 for its reference package, which I could not restore here, so the method shapes are worth a second look against that build.
github-actions
Bot
changed the base branch from
main
to
feature/external/pr-85-feature-save-and-load-hooks
August 6, 2026 16:39
The motivation for the hooks belongs in the pull request, not in the source.
LaurensDeV
marked this pull request as ready for review
August 6, 2026 16:42
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 happens. There is no save or load hook, and neither
Universe,ProgramnorGameSavesraises an event, so the only signal available is polling the timestamp ofuniverse.xml.Polling leaves a window. Save and load inside it and the mod writes nothing for that save, and then — when the poll finally fires and sees the stamp change — writes the freshly-defaulted state over the file. Shortening the interval narrows the window without closing it, and costs a file stat every frame to do so.
I hit this in a mod that stores per-craft settings inside the save folder, which is where they belong: deleting a save deletes them, copying copies them, renaming takes them along.
The change
Two attributes, following the existing ones:
Both pass the save's directory, because a save is a directory and what a mod usually wants is to put a file beside
universe.xml.Patched on
UniverseData.WriteTo(DirectoryInfo)andUniverseData.LoadFrom, both public.WriteTois overloaded, so the patch names the argument type.What I could not verify
The repository pins
RocketWerkz.KSA.Ref2026.7.6.4939, which is not on nuget.org, so I could not restore it. I compiledStarMap.APIcleanly and type-checkedStarMap.Coreagainst KSA 2026.8.5.5168 from a local install — with that build, the pre-existingConfirmRestart*files do not compile (PopupButton/IPopupWidgetandDrawUihave moved), which is unrelated to this change but did stop a full solution build here.So: the method shapes are worth a second look against the pinned build, and this is a draft rather than ready to merge for that reason. If
WriteTo/LoadFromdiffer in 2026.7.6.4939, the patch targets need adjusting.