Skip to content

Switch lock type on BeforeBaseGame saveables#80

Merged
ifBars merged 3 commits into
ifBars:stablefrom
k073l:fix/saveable-before-lock
Jun 4, 2026
Merged

Switch lock type on BeforeBaseGame saveables#80
ifBars merged 3 commits into
ifBars:stablefrom
k073l:fix/saveable-before-lock

Conversation

@k073l
Copy link
Copy Markdown
Collaborator

@k073l k073l commented Jun 1, 2026

Switches the lock on BeforeBaseGame saveable loader from save path check to a flag-based system, where the lock is set on first load of all eligible saveables and released when game invokes onLoadComplete.

This allows for these saveables to be correctly reloaded on another load cycle (e.g. load save1 -> exit to menu -> load save1). Previous system blocked this exact example.

Tested on Mono with MoreNPCs and MultiDelivery (regression testing and testing the fix) and on IL2CPP with the same + BigWillyMod (regression testing for custom items).
Let me know if I missed anything.

Release Notes

  • Replace save-path-based lock mechanism with a flag-based lock for BeforeBaseGame saveables to allow correct reloads across load cycles
  • Introduce sameSession boolean flag to prevent repeated execution within the same load session
  • sameSession is cleared by an onLoadComplete listener so saveables can be reloaded after exiting to menu and reloading the same save
  • Keeps existing filtering for LoadOrder == BeforeBaseGame and missing-save initialization-on-load-complete behavior
  • Minor cleanup: updated docstrings and removal of an unused MelonLoader import; clarified before-base load cycle detection

Contributions by Author

Author Lines Added Lines Removed
k073l 24 9

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9dc5cbac-e499-492a-8ed3-a90ed664c783

📥 Commits

Reviewing files that changed from the base of the PR and between c3571c8 and 90a163b.

📒 Files selected for processing (1)
  • S1API/Internal/Patches/GenericSaveables.Patches.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • S1API/Internal/Patches/GenericSaveables.Patches.cs

📝 Walkthrough

Walkthrough

Refactors load-cycle tracking in GenericSaveables.Patches.cs: adds a static session-scoped sameSession flag, gates the BeforeBaseLoaders prefix on it, sets it after the BeforeBaseGame pass, and clears it via a registered lm.onLoadComplete handler when loading finishes.

Changes

Session-scoped Load-Once Lock

Layer / File(s) Summary
Session lock mechanism with load-complete reset
S1API/Internal/Patches/GenericSaveables.Patches.cs
Adds a static sameSession flag and updates comments (range_11b9c845b451); BeforeBaseLoaders prefix now returns early when sameSession is true (range_c0f6c2135f8c); after BeforeBaseGame work the code sets sameSession = true and registers a ClearLockOnLoadComplete listener on lm.onLoadComplete that clears the flag and removes itself, with exception logging (range_b282358b613d).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nudge the flag, a quiet hop,
One session's guard — I won't nonstop.
When loading ends I clear the way,
So next new load may dance and play. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 70.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: replacing a lock mechanism on BeforeBaseGame saveables from path-based to flag-based.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
S1API/Internal/Patches/GenericSaveables.Patches.cs (1)

77-81: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Docstring is outdated.

Line 81 states "Uses the LoadedGameFolderPath to detect new load cycles" but the implementation now uses a sameSession flag cleared by onLoadComplete. Update to reflect the new mechanism.

📝 Suggested docstring update
 		/// <summary>
 		/// Loads saveables marked with BeforeBaseGame load order BEFORE base game loaders run.
 		/// This runs as a prefix to LoadManager.QueueLoadRequest on the first LoadRequest creation,
 		/// which happens right before base game loaders start processing.
-		/// Uses the LoadedGameFolderPath to detect new load cycles.
+		/// Uses a session flag cleared by onLoadComplete to detect new load cycles.
 		/// </summary>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@S1API/Internal/Patches/GenericSaveables.Patches.cs` around lines 77 - 81,
Update the outdated XML docstring for the prefix that loads saveables (the
method patch that runs before LoadManager.QueueLoadRequest) to remove the
reference to LoadedGameFolderPath and instead state that it uses an internal
sameSession flag (cleared by onLoadComplete) to detect new load cycles; mention
that this runs on the first LoadRequest creation before base game loaders run
and that sameSession is reset by onLoadComplete to allow subsequent load cycle
detection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@S1API/Internal/Patches/GenericSaveables.Patches.cs`:
- Around line 77-81: Update the outdated XML docstring for the prefix that loads
saveables (the method patch that runs before LoadManager.QueueLoadRequest) to
remove the reference to LoadedGameFolderPath and instead state that it uses an
internal sameSession flag (cleared by onLoadComplete) to detect new load cycles;
mention that this runs on the first LoadRequest creation before base game
loaders run and that sameSession is reset by onLoadComplete to allow subsequent
load cycle detection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 666cc5a7-2076-49ea-a351-eaac9707a942

📥 Commits

Reviewing files that changed from the base of the PR and between 248d8fe and c3571c8.

📒 Files selected for processing (1)
  • S1API/Internal/Patches/GenericSaveables.Patches.cs

@ifBars ifBars merged commit 5a52606 into ifBars:stable Jun 4, 2026
5 checks passed
@ifBars ifBars deleted the fix/saveable-before-lock branch June 4, 2026 01:05
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.

2 participants