Skip to content

[BUG] Custom dealer inventories are cleared after save reload #259

Description

@ifBars

Summary

Custom dealers added by multiple NPC mods reportedly lose all inventory contents after quitting/reloading a save. The same behavior has been observed with three different custom-NPC mods, which points to a shared S1API persistence path rather than one mod's configuration.

This issue is intentionally limited to inventory persistence:

A similar inventory-loss bug was previously tracked in #61 and fixed by #69, so this may be a regression or a newer load-order variant.

Environment

  • Schedule I version: not yet supplied; report followed the recent large game update
  • S1API version at reproduction: not yet confirmed; retest on 3.1.14 is needed
  • MelonLoader version: not yet supplied
  • Runtime: not yet supplied (Mono vs IL2CPP)
  • Affected mods: three separate custom-NPC mods were reported, but names were not supplied

Steps to reproduce

  1. Install S1API and a mod that adds a custom dealer NPC.
  2. Unlock/recruit the dealer if required.
  3. Put items into the dealer's inventory and save the game.
  4. Quit to the menu or exit the game.
  5. Reload the save.
  6. Inspect the custom dealer's inventory.

Expected behavior

The custom dealer's saved inventory contents, quantities, and slot state are restored.

Actual behavior

The custom dealer's inventory is empty after reload. Other persisted state, including addiction level and unlocked status, remains intact.

Impact

Players lose all stock assigned to custom dealers whenever they reload, breaking the core dealer loop across multiple NPC mods.

Investigation notes

The current custom-NPC loader deserializes Inventory directly in NPCLoader_Load_Prefix. The dealer-specific load prefix also stores the same payload in _pendingInventoryLoads, which is consumed from the NPCInventory.Awake postfix. Please verify the actual lifecycle ordering after the current game update, particularly whether Awake has already completed before the dealer load queues the pending item set, whether a later initialization/default pass clears restored slots, and whether the affected inventory is NPCInventory, dealer overflow inventory, or both.

Relevant code:

  • S1API/Internal/Patches/NPCPatches.cs: NPCInventory_Awake_Postfix
  • S1API/Internal/Patches/NPCPatches.cs: NPCLoader_Load_Prefix
  • S1API/Internal/Patches/NPCPatches.cs: Dealer_Load_Prefix

Acceptance criteria

  • Custom dealer inventory survives save -> quit/menu -> reload with the same items, quantities, and slots.
  • Restored inventory is not overwritten by startup/default inventory initialization.
  • Dealer overflow inventory continues to restore correctly.
  • Base-game NPC/dealer inventory behavior is unchanged.
  • The fix is validated separately on Mono and IL2CPP.
  • Regression coverage exercises the relevant NPCInventory.Awake / NPC load / dealer load ordering.

Additional evidence requested

To narrow the regression, please add the exact Schedule I, S1API, MelonLoader, and runtime versions; the affected mod names; and a MelonLoader log from one save/reload cycle.

Metadata

Metadata

Assignees

No one assigned

    Labels

    HighAPI features not working, or minor gameplay hinderancebugSomething isn't workingnpcssaveables

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions