Skip to content

Fix torn notes not combining when moved into inventory#8504

Open
morfidon wants to merge 7 commits intodiasurgical:masterfrom
morfidon:fix/8487-combine-notes-after-inventory-insert
Open

Fix torn notes not combining when moved into inventory#8504
morfidon wants to merge 7 commits intodiasurgical:masterfrom
morfidon:fix/8487-combine-notes-after-inventory-insert

Conversation

@morfidon
Copy link

Fixes #8487

Torn notes were only combined when picked up from the ground. The
combination logic is currently triggered through CheckQuestItem(),
which runs during ground pickup (InvGetItem / AutoGetItem).

Because of that, when notes are moved into the inventory through
other flows (for example from stash transfers), the combine logic
never runs and the notes remain separate.

This change introduces a small helper that runs when an item is added
to the inventory. It checks whether all three torn notes are present
and performs the Na-Krul note combination there.

The helper is executed from the inventory insertion paths so the
behavior is consistent regardless of how the notes enter the
inventory.

Special care was taken to avoid referencing stale inventory entries,
since the combination removes items and compacts the inventory.

Scenarios to test (I don't have notes - @Ruler2112 could you test it out?)

  • picking up the notes from the ground (original behavior preserved)
  • moving notes from stash into inventory
  • transferring notes directly into inventory

@qndel
Copy link
Member

qndel commented Mar 11, 2026

I don't understand, you added a new function but never call it?

@morfidon
Copy link
Author

I don't understand, you added a new function but never call it?

Sorry I didn't push one local change got a bit weird behavior on Windows I'm trying to fight with ^^

Fixes diasurgical#8487

Torn notes were only combined when picked up from the ground via
CheckQuestItem(). When notes entered the inventory through other
paths (e.g. stash transfers, item swaps), the combine logic never
ran.

Add CheckSpecialInventoryItem() which checks whether all three torn
notes are present after an item is placed into InvList, and combines
them into the full note if so.

Called from:
- ChangeInvItem (empty slot path)
- ChangeInvItem (swap path)
- AutoPlaceItemInInventory (covers stash-to-inventory transfers)
@morfidon morfidon force-pushed the fix/8487-combine-notes-after-inventory-insert branch from 14c16ca to 0f62a8c Compare March 11, 2026 10:24
Keep Na-Krul note auto-combine limited to player-facing inventory inserts so internal inventory reflow does not trigger partial side effects.\n\nTrack the inserted note through inventory compaction when combining, and add inventory regression tests for duplicate notes and sort behavior.
@yuripourre
Copy link
Collaborator

@morfidon does this logic can be called without Hellfire installed?

@morfidon
Copy link
Author

@morfidon does this logic can be called without Hellfire installed?

Yes, the function can be reached from shared inventory insertion paths even without Hellfire, since ChangeInvItem() / AutoPlaceItemInInventory() are not Hellfire-only.

That said, it should be effectively a no-op there, because the helper returns immediately unless the inserted item is one of IDI_NOTE1/2/3 and all three torn notes are present.

So the current behavior is: callable in vanilla paths, but inert unless Hellfire torn-note items are actually involved.

If you prefer, I can add an explicit if (!gbIsHellfire) return ...; guard at the top to make that intent clearer.

@morfidon
Copy link
Author

Looks like this failed in the macOS packaging step, not in compilation.

The log shows CPack failing during DMG creation with:

hdiutil: create failed - Resource busy

So this seems more like a transient macOS runner / packaging issue than a failure caused by the code in this PR. A rerun of the job is probably worth trying first.

@Ruler2112
Copy link

I'm sorry @morfidon - I kept playing & also do not have the notes anymore. I'm starting the Crypts in Hell difficulty, but do not know if I'm going to make it through due to the spike in difficulty referenced in a closed idea I had. (Seems like each enemy hit started duplicating 3-6 times based on the number of armor tinks I hear for each attack animation when I entered the caves.) If I do manage to complete the crypts and obtain all 3 notes, I will test them combining when obtaining in different ways.

@yuripourre
Copy link
Collaborator

@morfidon does this logic can be called without Hellfire installed?

Yes, the function can be reached from shared inventory insertion paths even without Hellfire, since ChangeInvItem() / AutoPlaceItemInInventory() are not Hellfire-only.

That said, it should be effectively a no-op there, because the helper returns immediately unless the inserted item is one of IDI_NOTE1/2/3 and all three torn notes are present.

So the current behavior is: callable in vanilla paths, but inert unless Hellfire torn-note items are actually involved.

If you prefer, I can add an explicit if (!gbIsHellfire) return ...; guard at the top to make that intent clearer.

Okay, in that case they way you did is fine. I was just wondering what would happen if an enum was missing or the Hellfire mod was off.

Another point: at first sight seems that a lot was changed just to check for new items in inventory. I am planning to review later this week but feels like it could be simplified, I can be wrong.

@StephenCWills
Copy link
Member

Another point: at first sight seems that a lot was changed just to check for new items in inventory. I am planning to review later this week but feels like it could be simplified, I can be wrong.

This is a really good point. For instance, why do we need a whole new function called TryCombineInsertedNaKrulNote() when we already have TryCombineNaKrulNotes()? The functionality has to be similar between these two functions. Can they not be combined in some way?

@morfidon
Copy link
Author

Another point: at first sight seems that a lot was changed just to check for new items in inventory. I am planning to review later this week but feels like it could be simplified, I can be wrong.

This is a really good point. For instance, why do we need a whole new function called TryCombineInsertedNaKrulNote() when we already have TryCombineNaKrulNotes()? The functionality has to be similar between these two functions. Can they not be combined in some way?

I think the two call sites represent different semantics: TryCombineNaKrulNotes() handles the ground-pickup/world-item path, while TryCombineInsertedNaKrulNote() handles an item already inserted into InvList, where removals can compact inventory and shift indices. So I do think a separate entry point is justified.
That said, I agree there is shared combine logic here, and I can refactor it so both paths delegate to a smaller common helper while keeping the separate wrappers for their different contexts.

Do I have green light?

@StephenCWills
Copy link
Member

Yes, that's what I expected you might say.

@qndel
Copy link
Member

qndel commented Mar 12, 2026

what about a scenario where someone would want to keep multiple torn note fragments in stash? after this "fix" it will be impossible to keep all 3, I think having them merge only when picking up from the ground is enough

Extract the shared preserved-note mapping into GetOtherNaKrulNotes.
Keep the ground pickup and inserted-inventory entry points separate because they still have different item lifetime and inventory compaction semantics.
Rename the inventory-insert combine helper to clarify that it runs after an item is inserted into InvList.
This keeps the separate flow-specific entry point but makes its purpose clearer during review.
@morfidon
Copy link
Author

morfidon commented Mar 12, 2026

what about a scenario where someone would want to keep multiple torn note fragments in stash? after this "fix" it will be impossible to keep all 3, I think having them merge only when picking up from the ground is enough

not unless we want to consciously design stash as a way to bypass auto-combine? If not, combining in inventory-insert flow is more consistent than limiting it to ground pickup only.

"merge only on ground pickup" is, to me, semantically weaker than "merge on relevant player inventory insert flows." Because then the result depends on the random path to acquiring the item, not on the game rule itself.

@morfidon
Copy link
Author

morfidon commented Mar 12, 2026

Yes, that's what I expected you might say.

I extracted the shared "other two notes" rule into a helper while keeping the two entry points separate because they operate on different state. If you think it would still be better to unify this further, I can take another pass
commit b2ccedf

Rename the local Na-Krul note helpers to a more consistent naming scheme.
This keeps behavior unchanged while making the shared predicates and transformations easier to follow in review.
@Ruler2112
Copy link

I'm not familiar enough with github to know how to download the appimage snapshot for this change - sorry. 🙁 I'm attaching a save game for you - I slogged through the crypt and managed to get all 3 torn notes. They're in my stash.
RulerNotes.zip

@morfidon
Copy link
Author

I'm not familiar enough with github to know how to download the appimage snapshot for this change - sorry. 🙁 I'm attaching a save game for you - I slogged through the crypt and managed to get all 3 torn notes. They're in my stash. RulerNotes.zip

That's totally ok! Thank you man it helped a lot.

I can confim the fix is working properly. When I move notes from stash to inventory they are being combined now.

They do not combine when I move last note TO the storage.

Should we change it or keep it as is.

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.

Torn Notes not combining

5 participants