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

@@ -167,6 +167,7 @@ type PlayerUnit struct {
Class Class
LeftSkill 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 {

View File

@@ -132,3 +132,10 @@ func (gd *GameReader) getStatsData(statCount uint, statPtr uintptr) []stat.Data
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
import (
"encoding/binary"
"github.com/hectorgimenez/d2go/pkg/data"
"github.com/hectorgimenez/d2go/pkg/data/area"
"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))
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{
Name: name,
ID: data.UnitID(unitID),
@@ -150,6 +162,7 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
Class: class,
LeftSkill: skill.Skill(leftSkillId),
RightSkill: skill.Skill(rightSkillId),
AvailableWaypoints: availableWPs,
}
}