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