psiberx / cp2077-codeware

Cyberpunk 2077 library and framework for creating script mods.
MIT License
71 stars 12 forks source link

GetFilteredInventoryItemsData list contains removed wardrobe items #10

Open MrSimbax opened 10 months ago

MrSimbax commented 10 months ago

After using wardrobeSystem.ForgetItemID on a specific item, the item is still on the list returned by wardrobeSystem.GetFilteredInventoryItemsData. GetStoredItemIDs and GetFilteredStoredItemIDs work correctly and don't have the item.

The consequences are visible to the user. Since WardrobeSetEditorUIController uses GetFilteredInventoryItemsData instead of GetFilteredStoredItemIDs, the removed item is still visible in the wardrobe outfit editor. It can even be equipped, but it isn't saved in the outfit.

The issue can be workarounded by saving the game after using ForgetItemID, and loading the new save.

Example CET snippet reproducing the issue:

local inventoryManager = Game.GetScriptableSystemsContainer():Get(CName.new('EquipmentSystem')):GetPlayerData(Game.GetPlayer()):GetInventoryManager()
local wardrobeSystem = Game.GetWardrobeSystem()

local function printFilteredStoredItemIds ()
    local itemIds = wardrobeSystem:GetFilteredStoredItemIDs(gamedataEquipmentArea.OuterChest)
    for _,itemId in pairs(itemIds) do
        print("GetFilteredStoredItemIDs: "..ItemID.GetTDBID(itemId).value)
    end
end

local function printFilteredInventoryItemsData ()
    local itemDatas = wardrobeSystem:GetFilteredInventoryItemsData(gamedataEquipmentArea.OuterChest, inventoryManager)
    for _,itemData in pairs(itemDatas) do
        print("GetFilteredInventoryItemsData: "..ItemID.GetTDBID(itemData:GetID()).value)
    end
end

local itemId = ItemID.FromTDBID("Items.MQ049_martinez_jacket")

printFilteredStoredItemIds() -- the item is not present
printFilteredInventoryItemsData() -- the item is not present

wardrobeSystem:StoreUniqueItemID(itemId)

printFilteredStoredItemIds() -- the added item is present [OK]
printFilteredInventoryItemsData() -- the added item is present [OK]

wardrobeSystem:ForgetItemID(itemId)

printFilteredStoredItemIds() -- the removed item is not present [OK]
printFilteredInventoryItemsData() -- the removed item is present [NOT OK]
psiberx commented 10 months ago

Yeah I know they use some cache for GetFilteredInventoryItemsData(), but I let it slide since Equipment-EX was the only the mod using this feature. If you need ForgetItemID() for your mod, I'll look into it.