Skip to content

Add StarMapAfterSave and StarMapAfterLoad hooks - #85

Open
LaurensDeV wants to merge 2 commits into
StarMapLoader:feature/external/pr-85-feature-save-and-load-hooksfrom
LaurensDeV:feature/save-and-load-hooks
Open

Add StarMapAfterSave and StarMapAfterLoad hooks#85
LaurensDeV wants to merge 2 commits into
StarMapLoader:feature/external/pr-85-feature-save-and-load-hooksfrom
LaurensDeV:feature/save-and-load-hooks

Conversation

@LaurensDeV

@LaurensDeV LaurensDeV commented Aug 6, 2026

Copy link
Copy Markdown

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, Program nor GameSaves raises an event, so the only signal available is polling the timestamp of universe.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:

[StarMapAfterSave]
public void OnSaved(DirectoryInfo saveDirectory);

[StarMapAfterLoad]
public void OnLoaded(DirectoryInfo saveDirectory);

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) and UniverseData.LoadFrom, both public. WriteTo is overloaded, so the patch names the argument type.

What I could not verify

The repository pins RocketWerkz.KSA.Ref 2026.7.6.4939, which is not on nuget.org, so I could not restore it. I compiled StarMap.API cleanly and type-checked StarMap.Core against KSA 2026.8.5.5168 from a local install — with that build, the pre-existing ConfirmRestart* files do not compile (PopupButton/IPopupWidget and DrawUi have 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/LoadFrom differ in 2026.7.6.4939, the patch targets need adjusting.

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
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
LaurensDeV marked this pull request as ready for review August 6, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant