Read WP data (#7)

This commit is contained in:
Héctor Giménez
2024-01-19 22:00:48 +09:00
committed by GitHub
parent c32e8d6ae1
commit f06c587c7a
3 changed files with 37 additions and 16 deletions

View File

@@ -157,16 +157,17 @@ type Position struct {
} }
type PlayerUnit struct { type PlayerUnit struct {
Name string Name string
ID UnitID ID UnitID
Area area.Area Area area.Area
Position Position Position Position
Stats map[stat.ID]int Stats map[stat.ID]int
Skills map[skill.Skill]int Skills map[skill.Skill]int
States state.States States state.States
Class Class Class Class
LeftSkill skill.Skill LeftSkill skill.Skill
RightSkill skill.Skill RightSkill skill.Skill
AvailableWaypoints []area.Area // Is only filled when WP menu is open and only for the specific selected tab
} }
func (pu PlayerUnit) MaxGold() int { func (pu PlayerUnit) MaxGold() int {

View File

@@ -132,3 +132,10 @@ func (gd *GameReader) getStatsData(statCount uint, statPtr uintptr) []stat.Data
return stats return stats
} }
// TODO: Take a look to better ways to get this data, now it's very flakky, is just a random memory position + not in game
func (gd *GameReader) InCharacterSelectionScreen() bool {
uiBase := gd.Process.moduleBaseAddressPtr + gd.offset.UI - 0xA
return gd.Process.ReadUInt(uiBase, Uint8) != 1 && gd.Process.ReadUInt(gd.moduleBaseAddressPtr+0x1EC5AA8, Uint64) == 0
}

View File

@@ -1,6 +1,7 @@
package memory package memory
import ( import (
"encoding/binary"
"github.com/hectorgimenez/d2go/pkg/data" "github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area" "github.com/hectorgimenez/d2go/pkg/data/area"
"github.com/hectorgimenez/d2go/pkg/data/skill" "github.com/hectorgimenez/d2go/pkg/data/skill"
@@ -136,6 +137,17 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
levelPtr := uintptr(gd.Process.ReadUInt(room2Ptr+0x90, Uint64)) levelPtr := uintptr(gd.Process.ReadUInt(room2Ptr+0x90, Uint64))
levelNo := gd.Process.ReadUInt(levelPtr+0x1F8, Uint32) levelNo := gd.Process.ReadUInt(levelPtr+0x1F8, Uint32)
availableWPs := make([]area.Area, 0)
// Probably there is a better place to pick up those values, since this seems to be very tied to the UI
wpList := gd.Process.ReadBytesFromMemory(gd.moduleBaseAddressPtr+0x21AD220, 0x48)
for i := 0; i < 0x48; i = i + 8 {
a := binary.LittleEndian.Uint32(wpList[i : i+4])
available := binary.LittleEndian.Uint32(wpList[i+4 : i+8])
if available == 1 || area.Area(levelNo) == area.Area(a) {
availableWPs = append(availableWPs, area.Area(a))
}
}
return data.PlayerUnit{ return data.PlayerUnit{
Name: name, Name: name,
ID: data.UnitID(unitID), ID: data.UnitID(unitID),
@@ -144,12 +156,13 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
X: int(xPos), X: int(xPos),
Y: int(yPos), Y: int(yPos),
}, },
Stats: stats, Stats: stats,
Skills: skills, Skills: skills,
States: states, States: states,
Class: class, Class: class,
LeftSkill: skill.Skill(leftSkillId), LeftSkill: skill.Skill(leftSkillId),
RightSkill: skill.Skill(rightSkillId), RightSkill: skill.Skill(rightSkillId),
AvailableWaypoints: availableWPs,
} }
} }