From 8ae0eb55c201e3cbcd082a922d449512f205b1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Gim=C3=A9nez?= Date: Tue, 24 Oct 2023 22:29:49 +0900 Subject: [PATCH] handle act 1/3/5 mercs (#5) --- pkg/data/npc.go | 2 +- pkg/memory/monsters.go | 43 +++++++++++++++++++------------------- pkg/utils/map_seed_hash.go | 2 ++ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pkg/data/npc.go b/pkg/data/npc.go index d33eeeb..998e2de 100644 --- a/pkg/data/npc.go +++ b/pkg/data/npc.go @@ -119,7 +119,7 @@ func (m Monster) IsImmune(resist stat.Resist) bool { } func (m Monster) IsMerc() bool { - if m.Name == npc.Guard { + if m.Name == npc.Guard || m.Name == npc.Act5Hireling1Hand || m.Name == npc.Act5Hireling2Hand || m.Name == npc.IronWolf || m.Name == npc.Rogue2 { return true } diff --git a/pkg/memory/monsters.go b/pkg/memory/monsters.go index 7b11a75..8e109a4 100644 --- a/pkg/memory/monsters.go +++ b/pkg/memory/monsters.go @@ -22,34 +22,35 @@ func (gd *GameReader) Monsters(playerPosition data.Position, hover data.HoverDat //monsterType := ReadUIntFromBuffer(monsterDataBuffer, 0x00, Uint32) txtFileNo := ReadUIntFromBuffer(monsterDataBuffer, 0x04, Uint32) - if !gd.shouldBeIgnored(txtFileNo) { - unitID := ReadUIntFromBuffer(monsterDataBuffer, 0x08, Uint32) + unitID := ReadUIntFromBuffer(monsterDataBuffer, 0x08, Uint32) - //mode := ReadUIntFromBuffer(monsterDataBuffer, 0x0C, Uint32) + //mode := ReadUIntFromBuffer(monsterDataBuffer, 0x0C, Uint32) - unitDataPtr := uintptr(ReadUIntFromBuffer(monsterDataBuffer, 0x10, Uint64)) - //isUnique := gd.Process.ReadUInt(unitDataPtr+0x18, Uint16) - flag := gd.Process.ReadBytesFromMemory(unitDataPtr+0x1A, Uint8)[0] - isCorpse := gd.Process.ReadUInt(monsterUnitPtr+0x1A6, Uint8) + unitDataPtr := uintptr(ReadUIntFromBuffer(monsterDataBuffer, 0x10, Uint64)) + //isUnique := gd.Process.ReadUInt(unitDataPtr+0x18, Uint16) + flag := gd.Process.ReadBytesFromMemory(unitDataPtr+0x1A, Uint8)[0] + isCorpse := gd.Process.ReadUInt(monsterUnitPtr+0x1A6, Uint8) - //unitDataBuffer := gd.Process.ReadBytesFromMemory(unitDataPtr, 144) + //unitDataBuffer := gd.Process.ReadBytesFromMemory(unitDataPtr, 144) - // Coordinates (X, Y) - pathPtr := uintptr(gd.Process.ReadUInt(monsterUnitPtr+0x38, Uint64)) - posX := gd.Process.ReadUInt(pathPtr+0x02, Uint16) - posY := gd.Process.ReadUInt(pathPtr+0x06, Uint16) + // Coordinates (X, Y) + pathPtr := uintptr(gd.Process.ReadUInt(monsterUnitPtr+0x38, Uint64)) + posX := gd.Process.ReadUInt(pathPtr+0x02, Uint16) + posY := gd.Process.ReadUInt(pathPtr+0x06, Uint16) - hovered := false - if hover.IsHovered && hover.UnitType == 1 && hover.UnitID == data.UnitID(unitID) { - hovered = true - } + hovered := false + if hover.IsHovered && hover.UnitType == 1 && hover.UnitID == data.UnitID(unitID) { + hovered = true + } - statsListExPtr := uintptr(ReadUIntFromBuffer(monsterDataBuffer, 0x88, Uint64)) - statPtr := uintptr(gd.Process.ReadUInt(statsListExPtr+0x30, Uint64)) - statCount := gd.Process.ReadUInt(statsListExPtr+0x38, Uint64) + 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) + stats := gd.getMonsterStats(statCount, statPtr) + // This excludes good NPCs but includes Mercs + if !gd.shouldBeIgnored(txtFileNo) || stats[stat.Experience] > 0 { m := data.Monster{ UnitID: data.UnitID(unitID), Name: npc.ID(int(txtFileNo)), @@ -156,7 +157,7 @@ func (gd *GameReader) shouldBeIgnored(txtNo uint) bool { npc.PoisonCloudTrap, npc.LightningTrap, npc.InvisoSpawner, - //338, //Guard + npc.Guard, npc.MiniSper, npc.BoneWall, npc.Hydra, diff --git a/pkg/utils/map_seed_hash.go b/pkg/utils/map_seed_hash.go index 7c980cc..fb01581 100644 --- a/pkg/utils/map_seed_hash.go +++ b/pkg/utils/map_seed_hash.go @@ -4,6 +4,8 @@ import "math" const mapHashDivisor = 1 << 16 +// Logic stolen from MapAssist, credits to them + func GetMapSeed(initHashSeed, endHashSeed uint) (uint, bool) { var gameSeedXor uint = 0 seed, found := reverseMapSeedHash(endHashSeed)