From e8a41dc79c9a4b69d48d12fc4120b0abd95ba169 Mon Sep 17 00:00:00 2001 From: vietdungdev Date: Sun, 24 May 2026 22:37:32 +0700 Subject: [PATCH] update item owner --- pkg/data/items.go | 7 ++----- pkg/memory/game_reader.go | 11 ++++------- pkg/memory/item.go | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/data/items.go b/pkg/data/items.go index bc195b2..b0eeb7d 100644 --- a/pkg/data/items.go +++ b/pkg/data/items.go @@ -14,18 +14,15 @@ type Inventory struct { StashedGold [6]int // [0]=personal, [1..5]=shared stash pages SharedStashPages int // Number of shared stash units detected (3=non-DLC, 5+=DLC) PlayerID UnitID // Number of shared stash units detected (3=non-DLC, 5+=DLC) - MercID UnitID } func (i Inventory) isMatchOwner(it Item) bool { if it.Location.LocationType == item.LocationUnknown || - it.Location.LocationType == item.LocationGround || it.Location.LocationType == item.LocationVendor { + it.Location.LocationType == item.LocationGround || + it.Location.LocationType == item.LocationMercenary || it.Location.LocationType == item.LocationVendor { return true } - if it.Location.LocationType == item.LocationMercenary { - return i.MercID != 0 && it.Owner == i.MercID - } return it.Owner == i.PlayerID } diff --git a/pkg/memory/game_reader.go b/pkg/memory/game_reader.go index 9a18750..abdaaad 100644 --- a/pkg/memory/game_reader.go +++ b/pkg/memory/game_reader.go @@ -82,15 +82,12 @@ func (gd *GameReader) GetData() data.Data { gd.monstersLastUpdate = now } - merc, foundMerc := gd.OwnMercenary() - merc.Found = foundMerc - // Conditionally update inventory 500ms // Except when hovering over an item inventory := gd.cachedInventory if now.Sub(gd.inventoryLastUpdate) > 250*time.Millisecond || (hover.IsHovered && hover.UnitType == 4) { // 4 = Item type - inventory = gd.Inventory(rawPlayerUnits, merc, hover) + inventory = gd.Inventory(rawPlayerUnits, hover) gd.cachedInventory = inventory gd.inventoryLastUpdate = now } @@ -150,6 +147,8 @@ func (gd *GameReader) GetData() data.Data { ActiveWeaponSlot: gd.GetActiveWeaponSlot(), } + merc, foundMerc := gd.OwnMercenary() + merc.Found = foundMerc d.Mercenary = data.OwnMercenary(merc) return d } @@ -157,9 +156,7 @@ func (gd *GameReader) GetData() data.Data { func (gd *GameReader) GetInventory() data.Inventory { rawPlayerUnits := gd.GetRawPlayerUnits() hover := gd.HoveredData() - merc, foundMerc := gd.OwnMercenary() - merc.Found = foundMerc - return gd.Inventory(rawPlayerUnits, merc, hover) + return gd.Inventory(rawPlayerUnits, hover) } func (gd *GameReader) InGame() bool { diff --git a/pkg/memory/item.go b/pkg/memory/item.go index 584a322..bc36a1b 100644 --- a/pkg/memory/item.go +++ b/pkg/memory/item.go @@ -13,7 +13,7 @@ import ( "github.com/hectorgimenez/d2go/pkg/utils" ) -func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, merc OwnMercenary, hover data.HoverData) data.Inventory { +func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, hover data.HoverData) data.Inventory { mainPlayer := rawPlayerUnits.GetMainPlayer() baseAddr := gd.Process.moduleBaseAddressPtr + gd.offset.UnitTable + (4 * 1024) unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8) @@ -55,7 +55,6 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, merc OwnMercenary StashedGold: stashedGold, SharedStashPages: len(stashPlayerUnitOrder), PlayerID: mainPlayer.UnitID, - MercID: merc.UnitID, } belt := data.Belt{} @@ -268,15 +267,26 @@ func (gd *GameReader) Inventory(rawPlayerUnits RawPlayerUnits, merc OwnMercenary if page, ok := stashUnitIDToPage[itemOwnerNPC]; ok { location = item.LocationSharedStash invPage = page + + // In party mode / current memory layout: + // shared stash page 1 belongs to the current character. + // Other pages are other shared stash containers and should keep raw owner. + if page == 1 { + itm.Owner = mainPlayer.UnitID + } + } else if itemOwnerNPC == 2 && len(stashUnitIDToPage) == 0 { location = item.LocationSharedStash invPage = 1 + itm.Owner = mainPlayer.UnitID } else if itemOwnerNPC == 3 && len(stashUnitIDToPage) == 0 { location = item.LocationSharedStash invPage = 2 + itm.Owner = mainPlayer.UnitID } else if itemOwnerNPC == 4 && len(stashUnitIDToPage) == 0 { location = item.LocationSharedStash invPage = 3 + itm.Owner = mainPlayer.UnitID } else if itemOwnerNPC == 4294967295 { if 0x00002000&flags != 0 { location = item.LocationVendor