Skip to content

fix(inventory): prevent phantom/ghost items in inventory#317

Open
olisikh wants to merge 2 commits intosven-n:mainfrom
olisikh:bug/phantom_items
Open

fix(inventory): prevent phantom/ghost items in inventory#317
olisikh wants to merge 2 commits intosven-n:mainfrom
olisikh:bug/phantom_items

Conversation

@olisikh
Copy link
Copy Markdown
Contributor

@olisikh olisikh commented Apr 5, 2026

Leaving this PR as a draft for now. I am running it myself and it works for now.

@olisikh olisikh changed the title bug(inventory): prevent phantom items from appearing fix(inventory): prevent phantom items in inventory Apr 5, 2026
@itayalroy
Copy link
Copy Markdown

Can you elaborate on the symptom?

@olisikh
Copy link
Copy Markdown
Contributor Author

olisikh commented Apr 6, 2026

Hi, sure. Sorry forgot to explain the problem in detail.

The problem:

  1. Sometimes character loots an item and it does not appear in the inventory. Item still takes squares, you can't place anything into those squares, which is as expected. Items appear only after you relogin. It has something to do with sync between client and server, i.e. item gets looted but client thinks it wasn't.
  2. Similar thing happens when items are moved around inventory spaces. Similar result, item is moved but does not get rendered until relogin.

Both of these happened to me quite often when I moved items between inventory - inv-extension - stash - stash-extension, or when MuHelper looted an item while on a long AFK session.

Running this PR currently on my fork and it works pretty well so far. I did not see this problem since.

Happy to change anything or close this PR if it makes no sense. I am not a C++ pro.

There's also a PR for the server that should catch 99% of such issues, while this PR catches another 1% of desynchronization, + self-healing through RefreshInventorySync: MUnique/OpenMU#747.

PS
Unrelated to this PR, but there is a similar issue that lives on the server. It happens purely due to item being misconfigured in OpenMU. Happens for a Daybreak item, it is configured as 2 x 2 squares on the OpenMU server, but 2 x 4 is expected on the client. When item is looted into 2 bottom-most squares it takes the squares, but client is unable to render those. Item won't appear even after relogin and squares would be still occupied. (fixed in another PR to OpenMU MUnique/OpenMU#748).

@olisikh
Copy link
Copy Markdown
Contributor Author

olisikh commented Apr 6, 2026

A slightly better-explained summary from Codex:

This PR hardens client inventory state handling to recover from desyncs that caused phantom items, disappearing items, and relog duplication symptoms. I.e. client stops trusting broken local inventory data.

What changed

  • Added self-healing slot validation in CNewUIInventoryCtrl:
    • FindItemFromSlotIndex(...) validates slot key -> item mapping.
    • ClearSlotKey(...) removes stale key references from grid cells.
    • RemoveItemAt(...) safely removes by slot index with validation.
    • RequestInventoryRefresh() triggers full inventory resync when corruption is detected.
  • Updated interaction/render paths to avoid trusting stale slot keys:
    • hover/pick/tooltips now resolve through validated FindItem(...).
    • render and slot checks clear phantom keys and request a server refresh.
  • Hardened packet handlers in WSclient.cpp:
    • ReceiveGetItem, ReceiveEquipmentItemExtended, and ReceiveModifyItemExtended now detect failed insert/move and request full inventory sync.
    • ReceiveModifyItemExtended now handles extension-slot delete/insert symmetry.
    • ReceiveDurability now also resolves items in inventory extension slots.
  • Fixed inventory extension plumbing:
    • CNewUIInventoryExtension::InsertItem now returns actual AddItem(...) result.
      extension/main delete flows now use RemoveItemAt(...) for stale-slot-safe removal.

Expected impact

  • Client recovers automatically when slot map and item list diverge.
  • Phantom slot occupancy is cleared proactively.
  • Failed packet application no longer leaves the client in silently corrupted state; it triggers authoritative server resync.

@olisikh olisikh changed the title fix(inventory): prevent phantom items in inventory fix(inventory): prevent phantom/ghost items in inventory Apr 9, 2026
@olisikh olisikh marked this pull request as ready for review April 9, 2026 11:53
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the inventory system's reliability by preventing and resolving 'phantom' or 'ghost' item issues. It introduces a set of new, robust item management utilities and integrates them throughout the inventory control, extension, and network communication layers. The changes ensure that the client-side inventory accurately reflects the server's state, enhancing user experience by eliminating visual discrepancies and unexpected item behaviors.

Highlights

  • New Inventory Management Functions: Introduced RemoveItemAt, FindItemFromSlotIndex, ClearSlotKey, and RequestInventoryRefresh functions in CNewUIInventoryCtrl to enhance item handling and state synchronization.
  • Phantom Item Recovery: The FindItemFromSlotIndex function now includes a recovery mechanism that clears invalid slot keys and requests an inventory refresh if an item is expected but not found, directly addressing phantom item issues.
  • Refactored Item Retrieval and Deletion: Existing FindItem and DeleteItem methods across CNewUIInventoryCtrl, CNewUIInventoryExtension, and CNewUIMyInventory have been updated to utilize the new, more robust item management functions.
  • Client-Server Synchronization: Added explicit inventory refresh requests in WSclient.cpp for various item-related network events (receiving, equipping, modifying items) to ensure the client's inventory state remains consistent with the server, especially when item insertion fails.
  • UI and Rendering Consistency: Updated UpdateMouseEvent, UpdateProcess, and Render methods in CNewUIInventoryCtrl to correctly identify and handle items, preventing UI elements like tooltips from appearing for non-existent items and visually clearing phantom items.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several new methods for inventory management, including RemoveItemAt, FindItemFromSlotIndex, ClearSlotKey, and RequestInventoryRefresh, and refactors existing code to utilize them. The changes aim to centralize item lookup and removal logic, improve inventory synchronization by requesting refreshes when item operations fail, and extend item finding capabilities to inventory extensions. Review feedback highlights potential issues where FindItemFromSlotIndex and CheckSlot might incorrectly handle reserved slots (key 1), leading to unintended clearing or unblocking. Additionally, it suggests implementing throttling for RequestInventoryRefresh to prevent excessive network calls and recommends moving state-modifying and network operations out of the Render function for better separation of concerns.

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