Item refactor and more (#1)
This commit is contained in:
@@ -28,15 +28,17 @@ func (gd *GameReader) GetData() data.Data {
|
||||
playerUnitPtr, corpse := gd.GetPlayerUnitPtr(roster)
|
||||
|
||||
pu := gd.GetPlayerUnit(playerUnitPtr)
|
||||
hover := gd.hoveredData()
|
||||
|
||||
d := data.Data{
|
||||
Corpse: corpse,
|
||||
Monsters: gd.Monsters(pu.Position),
|
||||
Monsters: gd.Monsters(pu.Position, hover),
|
||||
PlayerUnit: pu,
|
||||
Items: gd.Items(pu.Position),
|
||||
Objects: gd.Objects(pu.Position),
|
||||
Items: gd.Items(pu, hover),
|
||||
Objects: gd.Objects(pu.Position, hover),
|
||||
OpenMenus: gd.openMenus(),
|
||||
Roster: roster,
|
||||
HoverData: hover,
|
||||
}
|
||||
|
||||
if playerUnitPtr == 0 {
|
||||
@@ -74,21 +76,26 @@ func (gd *GameReader) openMenus() data.OpenMenus {
|
||||
QuitMenu: buffer[0x09] != 0,
|
||||
Cube: buffer[0x19] != 0,
|
||||
SkillSelect: buffer[0x03] != 0,
|
||||
Anvil: buffer[0x0D] != 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (gd *GameReader) hoveredData() (hoveredUnitID uint, hoveredType uint, isHovered bool) {
|
||||
func (gd *GameReader) hoveredData() data.HoverData {
|
||||
hoverAddressPtr := gd.Process.moduleBaseAddressPtr + gd.offset.Hover
|
||||
hoverBuffer := gd.Process.ReadBytesFromMemory(hoverAddressPtr, 12)
|
||||
isUnitHovered := ReadUIntFromBuffer(hoverBuffer, 0, Uint16)
|
||||
if isUnitHovered > 0 {
|
||||
hoveredType = ReadUIntFromBuffer(hoverBuffer, 0x04, Uint32)
|
||||
hoveredUnitID = ReadUIntFromBuffer(hoverBuffer, 0x08, Uint32)
|
||||
hoveredType := ReadUIntFromBuffer(hoverBuffer, 0x04, Uint32)
|
||||
hoveredUnitID := ReadUIntFromBuffer(hoverBuffer, 0x08, Uint32)
|
||||
|
||||
return hoveredUnitID, hoveredType, true
|
||||
return data.HoverData{
|
||||
IsHovered: true,
|
||||
UnitID: data.UnitID(hoveredUnitID),
|
||||
UnitType: int(hoveredType),
|
||||
}
|
||||
}
|
||||
|
||||
return 0, 0, false
|
||||
return data.HoverData{}
|
||||
}
|
||||
|
||||
func (gd *GameReader) getStatsData(statCount uint, statPtr uintptr) []stat.Data {
|
||||
@@ -124,15 +131,3 @@ func (gd *GameReader) getStatsData(statCount uint, statPtr uintptr) []stat.Data
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
func setProperties(item *data.Item, flags uint32) {
|
||||
if 0x00400000&flags != 0 {
|
||||
item.Ethereal = true
|
||||
}
|
||||
if 0x00000010&flags != 0 {
|
||||
item.Identified = true
|
||||
}
|
||||
if 0x00002000&flags != 0 {
|
||||
item.IsVendor = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,7 @@ import (
|
||||
"github.com/hectorgimenez/d2go/pkg/utils"
|
||||
)
|
||||
|
||||
func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||
hoveredUnitID, hoveredType, isHovered := gd.hoveredData()
|
||||
|
||||
func (gd *GameReader) Items(pu data.PlayerUnit, hover data.HoverData) data.Items {
|
||||
baseAddr := gd.Process.moduleBaseAddressPtr + gd.offset.UnitTable + (4 * 1024)
|
||||
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
||||
|
||||
@@ -38,7 +36,7 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||
flags := ReadUIntFromBuffer(unitDataBuffer, 0x18, Uint32)
|
||||
invPage := ReadUIntFromBuffer(unitDataBuffer, 0x55, Uint8)
|
||||
itemQuality := ReadUIntFromBuffer(unitDataBuffer, 0x00, Uint32)
|
||||
//itemOwnerNPC := ReadUIntFromBuffer(unitDataBuffer, 0x0C, Uint32)
|
||||
itemOwnerNPC := ReadUIntFromBuffer(unitDataBuffer, 0x0C, Uint32)
|
||||
|
||||
// Item coordinates (X, Y)
|
||||
pathPtr := uintptr(ReadUIntFromBuffer(itemDataBuffer, 0x38, Uint64))
|
||||
@@ -58,7 +56,7 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||
|
||||
name := item.GetNameByEnum(txtFileNo)
|
||||
itemHovered := false
|
||||
if isHovered && hoveredType == 4 && hoveredUnitID == unitID {
|
||||
if hover.IsHovered && hover.UnitType == 4 && hover.UnitID == data.UnitID(unitID) {
|
||||
itemHovered = true
|
||||
}
|
||||
|
||||
@@ -75,22 +73,53 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||
}
|
||||
setProperties(&itm, uint32(flags))
|
||||
|
||||
location := item.LocationUnknown
|
||||
switch itemLoc {
|
||||
case 0:
|
||||
if itm.IsVendor {
|
||||
items.Shop = append(items.Shop, itm)
|
||||
if 0x00002000&flags != 0 {
|
||||
location = item.LocationVendor
|
||||
break
|
||||
} else if invPage == 0 {
|
||||
items.Inventory = append(items.Inventory, itm)
|
||||
location = item.LocationInventory
|
||||
break
|
||||
}
|
||||
if data.UnitID(itemOwnerNPC) == pu.ID || itemOwnerNPC == 1 {
|
||||
location = item.LocationStash
|
||||
break
|
||||
}
|
||||
|
||||
// Offline only
|
||||
if itemOwnerNPC == 2 {
|
||||
location = item.LocationSharedStash1
|
||||
break
|
||||
}
|
||||
if itemOwnerNPC == 3 {
|
||||
location = item.LocationSharedStash2
|
||||
break
|
||||
}
|
||||
if itemOwnerNPC == 4 {
|
||||
location = item.LocationSharedStash3
|
||||
break
|
||||
}
|
||||
case 1:
|
||||
items.Equipped = append(items.Equipped, itm)
|
||||
location = item.LocationEquipped
|
||||
if itm.Type() == "belt" {
|
||||
belt.Name = itm.Name
|
||||
}
|
||||
case 2:
|
||||
belt.Items = append(belt.Items, itm)
|
||||
location = item.LocationBelt
|
||||
case 3, 5:
|
||||
items.Ground = append(items.Ground, itm)
|
||||
location = item.LocationGround
|
||||
case 6:
|
||||
location = item.LocationSocket
|
||||
}
|
||||
|
||||
itm.Location = location
|
||||
|
||||
if location == item.LocationBelt {
|
||||
belt.Items = append(belt.Items, itm)
|
||||
} else {
|
||||
items.AllItems = append(items.AllItems, itm)
|
||||
}
|
||||
|
||||
itemUnitPtr = uintptr(gd.Process.ReadUInt(itemUnitPtr+0x150, Uint64))
|
||||
@@ -99,9 +128,9 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||
|
||||
items.Belt = belt
|
||||
|
||||
sort.SliceStable(items.Ground, func(i, j int) bool {
|
||||
distanceI := utils.DistanceFromPoint(playerPosition, items.Ground[i].Position)
|
||||
distanceJ := utils.DistanceFromPoint(playerPosition, items.Ground[j].Position)
|
||||
sort.SliceStable(items.AllItems, func(i, j int) bool {
|
||||
distanceI := utils.DistanceFromPoint(pu.Position, items.AllItems[i].Position)
|
||||
distanceJ := utils.DistanceFromPoint(pu.Position, items.AllItems[j].Position)
|
||||
|
||||
return distanceI < distanceJ
|
||||
})
|
||||
@@ -127,3 +156,12 @@ func (gd *GameReader) getItemStats(statCount uint, statPtr uintptr, statExCount
|
||||
|
||||
return stats
|
||||
}
|
||||
|
||||
func setProperties(item *data.Item, flags uint32) {
|
||||
if 0x00400000&flags != 0 {
|
||||
item.Ethereal = true
|
||||
}
|
||||
if 0x00000010&flags != 0 {
|
||||
item.Identified = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/hectorgimenez/d2go/pkg/data"
|
||||
"github.com/hectorgimenez/d2go/pkg/data/npc"
|
||||
"github.com/hectorgimenez/d2go/pkg/data/stat"
|
||||
"github.com/hectorgimenez/d2go/pkg/utils"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func (gd *GameReader) Monsters(playerPosition data.Position) data.Monsters {
|
||||
hoveredUnitID, hoveredType, isHovered := gd.hoveredData()
|
||||
|
||||
func (gd *GameReader) Monsters(playerPosition data.Position, hover data.HoverData) data.Monsters {
|
||||
baseAddr := gd.Process.moduleBaseAddressPtr + gd.offset.UnitTable + 1024
|
||||
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
||||
|
||||
@@ -41,7 +40,7 @@ func (gd *GameReader) Monsters(playerPosition data.Position) data.Monsters {
|
||||
posY := gd.Process.ReadUInt(pathPtr+0x06, Uint16)
|
||||
|
||||
hovered := false
|
||||
if isHovered && hoveredType == 1 && hoveredUnitID == unitID {
|
||||
if hover.IsHovered && hover.UnitType == 1 && hover.UnitID == data.UnitID(unitID) {
|
||||
hovered = true
|
||||
}
|
||||
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/hectorgimenez/d2go/pkg/data"
|
||||
"github.com/hectorgimenez/d2go/pkg/data/object"
|
||||
"github.com/hectorgimenez/d2go/pkg/utils"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func (gd *GameReader) Objects(playerPosition data.Position) []data.Object {
|
||||
hoveredUnitID, hoveredType, isHovered := gd.hoveredData()
|
||||
|
||||
func (gd *GameReader) Objects(playerPosition data.Position, hover data.HoverData) []data.Object {
|
||||
baseAddr := gd.Process.moduleBaseAddressPtr + gd.offset.UnitTable + (2 * 1024)
|
||||
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
||||
|
||||
@@ -34,7 +33,7 @@ func (gd *GameReader) Objects(playerPosition data.Position) []data.Object {
|
||||
|
||||
obj := data.Object{
|
||||
Name: object.Name(int(txtFileNo)),
|
||||
IsHovered: unitID == hoveredUnitID && hoveredType == 2 && isHovered,
|
||||
IsHovered: data.UnitID(unitID) == hover.UnitID && hover.UnitType == 2 && hover.IsHovered,
|
||||
InteractType: object.InteractType(interactType),
|
||||
Selectable: mode == 0,
|
||||
Position: data.Position{
|
||||
|
||||
@@ -34,10 +34,10 @@ func (gd *GameReader) GetPlayerUnitPtr(roster data.Roster) (playerUnitPtr uintpt
|
||||
isCorpse := gd.Process.ReadUInt(playerUnit+0x1A6, Uint8)
|
||||
if isCorpse == 1 {
|
||||
unitID := gd.Process.ReadUInt(playerUnit+0x08, Uint32)
|
||||
hoveredUnitID, hoveredType, isHovered := gd.hoveredData()
|
||||
hover := gd.hoveredData()
|
||||
corpse = data.Corpse{
|
||||
Found: true,
|
||||
IsHovered: isHovered && hoveredUnitID == unitID && hoveredType == 0,
|
||||
IsHovered: hover.IsHovered && hover.UnitID == data.UnitID(unitID) && hover.UnitType == 0,
|
||||
Position: data.Position{
|
||||
X: int(xPos),
|
||||
Y: int(yPos),
|
||||
@@ -76,6 +76,8 @@ func (gd *GameReader) GetPlayerUnitPtr(roster data.Roster) (playerUnitPtr uintpt
|
||||
}
|
||||
|
||||
func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
|
||||
unitID := gd.Process.ReadUInt(playerUnit+0x08, Uint32)
|
||||
|
||||
// Read X and Y Positions
|
||||
pPath := playerUnit + 0x38
|
||||
pathAddress := uintptr(gd.Process.ReadUInt(pPath, Uint64))
|
||||
@@ -127,6 +129,7 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
|
||||
|
||||
return data.PlayerUnit{
|
||||
Name: name,
|
||||
ID: data.UnitID(unitID),
|
||||
Area: area.Area(levelNo),
|
||||
Position: data.Position{
|
||||
X: int(xPos),
|
||||
|
||||
Reference in New Issue
Block a user