Add layers on stats and small refactor
This commit is contained in:
@@ -118,7 +118,7 @@ type PlayerUnit struct {
|
||||
Name string
|
||||
Area area.Area
|
||||
Position Position
|
||||
Stats map[stat.Stat]int
|
||||
Stats map[stat.ID]int
|
||||
Skills map[skill.Skill]int
|
||||
States state.States
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ type Item struct {
|
||||
Position Position
|
||||
Ethereal bool
|
||||
IsHovered bool
|
||||
Stats map[stat.Stat]int
|
||||
Stats map[stat.ID]stat.Data
|
||||
Identified bool
|
||||
IsVendor bool
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ type Monster struct {
|
||||
Name npc.ID
|
||||
IsHovered bool
|
||||
Position Position
|
||||
Stats map[stat.Stat]int
|
||||
Stats map[stat.ID]int
|
||||
Type MonsterType
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package stat
|
||||
|
||||
type Stat int16
|
||||
type ID int16
|
||||
|
||||
type Data struct {
|
||||
ID ID
|
||||
Value int
|
||||
Layer int
|
||||
}
|
||||
|
||||
const (
|
||||
Strength Stat = iota
|
||||
Strength ID = iota
|
||||
Energy
|
||||
Dexterity
|
||||
Vitality
|
||||
@@ -364,7 +370,7 @@ const (
|
||||
PassiveMagicPierce
|
||||
)
|
||||
|
||||
func (s Stat) String() string {
|
||||
func (s ID) String() string {
|
||||
switch s {
|
||||
case Strength:
|
||||
return "strength"
|
||||
|
||||
@@ -86,23 +86,38 @@ func (gd *GameReader) hoveredData() (hoveredUnitID uint, hoveredType uint, isHov
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
func getStatData(statEnum, statValue uint) (stat.Stat, int) {
|
||||
value := int(statValue)
|
||||
switch stat.Stat(statEnum) {
|
||||
case stat.Life,
|
||||
stat.MaxLife,
|
||||
stat.Mana,
|
||||
stat.MaxMana,
|
||||
stat.Stamina,
|
||||
stat.LifePerLevel,
|
||||
stat.ManaPerLevel:
|
||||
value = int(statValue >> 8)
|
||||
case stat.ColdLength,
|
||||
stat.PoisonLength:
|
||||
value = int(statValue / 25)
|
||||
func (gd *GameReader) getStatsData(statCount uint, statPtr uintptr) []stat.Data {
|
||||
var stats = make([]stat.Data, 0)
|
||||
statBuffer := gd.Process.ReadBytesFromMemory(statPtr, statCount*10)
|
||||
for i := 0; i < int(statCount); i++ {
|
||||
offset := uint(i * 8)
|
||||
statLayer := ReadUIntFromBuffer(statBuffer, offset, Uint16)
|
||||
statEnum := ReadUIntFromBuffer(statBuffer, offset+0x2, Uint16)
|
||||
statValue := ReadUIntFromBuffer(statBuffer, offset+0x4, Uint32)
|
||||
|
||||
value := int(statValue)
|
||||
switch stat.ID(statEnum) {
|
||||
case stat.Life,
|
||||
stat.MaxLife,
|
||||
stat.Mana,
|
||||
stat.MaxMana,
|
||||
stat.Stamina,
|
||||
stat.LifePerLevel,
|
||||
stat.ManaPerLevel:
|
||||
value = int(statValue >> 8)
|
||||
case stat.ColdLength,
|
||||
stat.PoisonLength:
|
||||
value = int(statValue / 25)
|
||||
}
|
||||
|
||||
stats = append(stats, stat.Data{
|
||||
ID: stat.ID(statEnum),
|
||||
Value: value,
|
||||
Layer: int(statLayer),
|
||||
})
|
||||
}
|
||||
|
||||
return stat.Stat(statEnum), value
|
||||
return stats
|
||||
}
|
||||
|
||||
func setProperties(item *data.Item, flags uint32) {
|
||||
|
||||
@@ -102,28 +102,19 @@ func (gd *GameReader) Items(playerPosition data.Position) data.Items {
|
||||
return items
|
||||
}
|
||||
|
||||
func (gd *GameReader) getItemStats(statCount uint, statPtr uintptr, statExCount uint, statExPtr uintptr) map[stat.Stat]int {
|
||||
stats := map[stat.Stat]int{}
|
||||
|
||||
func (gd *GameReader) getItemStats(statCount uint, statPtr uintptr, statExCount uint, statExPtr uintptr) map[stat.ID]stat.Data {
|
||||
stats := make(map[stat.ID]stat.Data, 0)
|
||||
if statCount < 20 && statCount > 0 {
|
||||
statBuffer := gd.Process.ReadBytesFromMemory(statPtr, statCount*10)
|
||||
for i := 0; i < int(statCount); i++ {
|
||||
offset := uint(i * 8)
|
||||
statEnum := ReadUIntFromBuffer(statBuffer, offset+0x2, Uint16)
|
||||
statValue := ReadUIntFromBuffer(statBuffer, offset+0x4, Uint32)
|
||||
st, value := getStatData(statEnum, statValue)
|
||||
stats[st] = value
|
||||
stats1 := gd.getStatsData(statCount, statPtr)
|
||||
for _, v := range stats1 {
|
||||
stats[v.ID] = v
|
||||
}
|
||||
}
|
||||
|
||||
if statExCount < 20 && statExCount > 0 {
|
||||
statBuffer := gd.Process.ReadBytesFromMemory(statExPtr, statExCount*10)
|
||||
for i := 0; i < int(statExCount); i++ {
|
||||
offset := uint(i * 8)
|
||||
statEnum := ReadUIntFromBuffer(statBuffer, offset+0x2, Uint16)
|
||||
statValue := ReadUIntFromBuffer(statBuffer, offset+0x4, Uint32)
|
||||
st, value := getStatData(statEnum, statValue)
|
||||
stats[st] = value
|
||||
stats2 := gd.getStatsData(statExCount, statExPtr)
|
||||
for _, v := range stats2 {
|
||||
stats[v.ID] = v
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,8 @@ func getMonsterType(typeFlag byte) data.MonsterType {
|
||||
return data.MonsterTypeNone
|
||||
}
|
||||
|
||||
func (gd *GameReader) getMonsterStats(statCount uint, statPtr uintptr) map[stat.Stat]int {
|
||||
stats := map[stat.Stat]int{}
|
||||
func (gd *GameReader) getMonsterStats(statCount uint, statPtr uintptr) map[stat.ID]int {
|
||||
stats := map[stat.ID]int{}
|
||||
|
||||
if statCount > 0 {
|
||||
statBuffer := gd.Process.ReadBytesFromMemory(statPtr+0x2, statCount*8)
|
||||
@@ -106,7 +106,7 @@ func (gd *GameReader) getMonsterStats(statCount uint, statPtr uintptr) map[stat.
|
||||
offset := uint(i * 8)
|
||||
statEnum := ReadUIntFromBuffer(statBuffer, offset, Uint16)
|
||||
statValue := ReadUIntFromBuffer(statBuffer, offset+0x2, Uint32)
|
||||
stats[stat.Stat(statEnum)] = int(statValue)
|
||||
stats[stat.ID(statEnum)] = int(statValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,20 +93,20 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
|
||||
statPtr := gd.Process.ReadUInt(statsListExPtr+0x30, Uint64)
|
||||
statCount := gd.Process.ReadUInt(statsListExPtr+0x38, Uint64)
|
||||
|
||||
stats := map[stat.Stat]int{}
|
||||
stats := map[stat.ID]int{}
|
||||
for j := 0; j < int(statCount); j++ {
|
||||
statOffset := uintptr(statPtr) + 0x2 + uintptr(j*8)
|
||||
statNumber := gd.Process.ReadUInt(statOffset, Uint16)
|
||||
statValue := gd.Process.ReadUInt(statOffset+0x02, Uint32)
|
||||
|
||||
switch stat.Stat(statNumber) {
|
||||
switch stat.ID(statNumber) {
|
||||
case stat.Life,
|
||||
stat.MaxLife,
|
||||
stat.Mana,
|
||||
stat.MaxMana:
|
||||
stats[stat.Stat(statNumber)] = int(uint32(statValue) >> 8)
|
||||
stats[stat.ID(statNumber)] = int(uint32(statValue) >> 8)
|
||||
default:
|
||||
stats[stat.Stat(statNumber)] = int(statValue)
|
||||
stats[stat.ID(statNumber)] = int(statValue)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user