Corpses (#29)
* Update data.go Added corpses check * Update game_reader.go Added corpse finder function * Update monsters.go added corpse finder function
This commit is contained in:
@@ -49,6 +49,7 @@ func (gd *GameReader) GetData() data.Data {
|
||||
Position: corpseUnit.Position,
|
||||
},
|
||||
Monsters: gd.Monsters(pu.Position, hover),
|
||||
Corpses: gd.Corpses(pu.Position, hover),
|
||||
PlayerUnit: pu,
|
||||
Inventory: gd.Inventory(rawPlayerUnits, hover),
|
||||
Objects: gd.Objects(pu.Position, hover),
|
||||
|
||||
@@ -113,6 +113,71 @@ func (gd *GameReader) getMonsterStats(statCount uint, statPtr uintptr) map[stat.
|
||||
return stats
|
||||
}
|
||||
|
||||
func (gd *GameReader) Corpses(playerPosition data.Position, hover data.HoverData) data.Monsters {
|
||||
baseAddr := gd.Process.moduleBaseAddressPtr + gd.offset.UnitTable + 1024
|
||||
unitTableBuffer := gd.Process.ReadBytesFromMemory(baseAddr, 128*8)
|
||||
|
||||
corpses := data.Monsters{}
|
||||
|
||||
for i := 0; i < 128; i++ {
|
||||
monsterOffset := 8 * i
|
||||
monsterUnitPtr := uintptr(ReadUIntFromBuffer(unitTableBuffer, uint(monsterOffset), Uint64))
|
||||
for monsterUnitPtr > 0 {
|
||||
monsterDataBuffer := gd.Process.ReadBytesFromMemory(monsterUnitPtr, 144)
|
||||
|
||||
txtFileNo := ReadUIntFromBuffer(monsterDataBuffer, 0x04, Uint32)
|
||||
unitID := ReadUIntFromBuffer(monsterDataBuffer, 0x08, Uint32)
|
||||
|
||||
unitDataPtr := uintptr(ReadUIntFromBuffer(monsterDataBuffer, 0x10, Uint64))
|
||||
flag := gd.Process.ReadBytesFromMemory(unitDataPtr+0x1A, Uint8)[0]
|
||||
isCorpse := gd.Process.ReadUInt(monsterUnitPtr+0x1A6, Uint8)
|
||||
|
||||
if isCorpse == 0 {
|
||||
monsterUnitPtr = uintptr(gd.Process.ReadUInt(monsterUnitPtr+0x150, Uint64))
|
||||
continue
|
||||
}
|
||||
|
||||
pathPtr := uintptr(gd.Process.ReadUInt(monsterUnitPtr+0x38, Uint64))
|
||||
posX := gd.Process.ReadUInt(pathPtr+0x02, Uint16)
|
||||
posY := gd.Process.ReadUInt(pathPtr+0x06, Uint16)
|
||||
|
||||
statsListExPtr := uintptr(ReadUIntFromBuffer(monsterDataBuffer, 0x88, Uint64))
|
||||
statPtr := uintptr(gd.Process.ReadUInt(statsListExPtr+0x30, Uint64))
|
||||
statCount := gd.Process.ReadUInt(statsListExPtr+0x38, Uint64)
|
||||
|
||||
stats := gd.getMonsterStats(statCount, statPtr)
|
||||
|
||||
hovered := hover.IsHovered && hover.UnitType == 1 && hover.UnitID == data.UnitID(unitID)
|
||||
|
||||
if (!gd.shouldBeIgnored(txtFileNo) || stats[stat.Experience] > 0) && isCorpse != 0 {
|
||||
m := data.Monster{
|
||||
UnitID: data.UnitID(unitID),
|
||||
Name: npc.ID(int(txtFileNo)),
|
||||
IsHovered: hovered,
|
||||
Position: data.Position{
|
||||
X: int(posX),
|
||||
Y: int(posY),
|
||||
},
|
||||
Stats: stats,
|
||||
Type: getMonsterType(flag),
|
||||
}
|
||||
|
||||
corpses = append(corpses, m)
|
||||
}
|
||||
|
||||
monsterUnitPtr = uintptr(gd.Process.ReadUInt(monsterUnitPtr+0x150, Uint64))
|
||||
}
|
||||
}
|
||||
|
||||
sort.SliceStable(corpses, func(i, j int) bool {
|
||||
distanceI := utils.DistanceFromPoint(playerPosition, corpses[i].Position)
|
||||
distanceJ := utils.DistanceFromPoint(playerPosition, corpses[j].Position)
|
||||
return distanceI < distanceJ
|
||||
})
|
||||
|
||||
return corpses
|
||||
}
|
||||
|
||||
func (gd *GameReader) shouldBeIgnored(txtNo uint) bool {
|
||||
switch npc.ID(txtNo) {
|
||||
case npc.Chicken,
|
||||
|
||||
Reference in New Issue
Block a user