stop using global variables
This commit is contained in:
@@ -6,7 +6,8 @@ import (
|
||||
)
|
||||
|
||||
type GameReader struct {
|
||||
offset Offset
|
||||
offset Offset
|
||||
previousRead data.Data
|
||||
Process
|
||||
}
|
||||
|
||||
@@ -17,8 +18,6 @@ func NewGameReader(process Process) *GameReader {
|
||||
}
|
||||
}
|
||||
|
||||
var previousData *data.Data
|
||||
|
||||
func (gd *GameReader) GetData() data.Data {
|
||||
if gd.offset.UnitTable == 0 {
|
||||
gd.offset = calculateOffsets(gd.Process)
|
||||
@@ -27,7 +26,7 @@ func (gd *GameReader) GetData() data.Data {
|
||||
roster := gd.getRoster()
|
||||
playerUnitPtr, corpse := gd.GetPlayerUnitPtr(roster)
|
||||
|
||||
pu := gd.GetPlayerUnit(playerUnitPtr)
|
||||
pu := gd.GetPlayerUnit(playerUnitPtr, gd.previousRead.PlayerUnit.MaxHPValue, gd.previousRead.PlayerUnit.MaxMPValue)
|
||||
hover := gd.hoveredData()
|
||||
|
||||
// Quests
|
||||
@@ -51,10 +50,10 @@ func (gd *GameReader) GetData() data.Data {
|
||||
}
|
||||
|
||||
if playerUnitPtr == 0 {
|
||||
return *previousData
|
||||
return gd.previousRead
|
||||
}
|
||||
|
||||
previousData = &d
|
||||
gd.previousRead = d
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -76,7 +76,14 @@ func (gd *GameReader) GetPlayerUnitPtr(roster data.Roster) (playerUnitPtr uintpt
|
||||
return
|
||||
}
|
||||
|
||||
func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
|
||||
func (gd *GameReader) GetPlayerUnit(playerUnit uintptr, previousHP, previousMP *data.PointCounter) data.PlayerUnit {
|
||||
if previousHP == nil {
|
||||
previousHP = &data.PointCounter{}
|
||||
}
|
||||
if previousMP == nil {
|
||||
previousMP = &data.PointCounter{}
|
||||
}
|
||||
|
||||
unitID := gd.Process.ReadUInt(playerUnit+0x08, Uint32)
|
||||
|
||||
// Read X and Y Positions
|
||||
@@ -148,7 +155,7 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
|
||||
}
|
||||
}
|
||||
|
||||
return data.PlayerUnit{
|
||||
d := data.PlayerUnit{
|
||||
Name: name,
|
||||
ID: data.UnitID(unitID),
|
||||
Area: area.Area(levelNo),
|
||||
@@ -163,7 +170,15 @@ func (gd *GameReader) GetPlayerUnit(playerUnit uintptr) data.PlayerUnit {
|
||||
LeftSkill: skill.ID(leftSkillId),
|
||||
RightSkill: skill.ID(rightSkillId),
|
||||
AvailableWaypoints: availableWPs,
|
||||
MaxHPValue: previousHP,
|
||||
MaxMPValue: previousMP,
|
||||
}
|
||||
|
||||
// Recalculate max HP and MP
|
||||
d.HPPercent()
|
||||
d.MPPercent()
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func (gd *GameReader) getSkills(skillListPtr uintptr) map[skill.ID]skill.Points {
|
||||
|
||||
Reference in New Issue
Block a user