Skip to content
This repository has been archived by the owner on Dec 21, 2022. It is now read-only.

Commit

Permalink
first attempt at hostile players
Browse files Browse the repository at this point in the history
  • Loading branch information
joffreybesos committed Jun 13, 2022
1 parent 0e608df commit 402f856
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/memory/readGameMemory.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ readGameMemory(ByRef d2rprocess, ByRef settings, ByRef gameMemoryData) {

; get party
if (Mod(ticktock, 3)) {
ReadParty(d2rprocess, partyList)
ReadParty(d2rprocess, partyList, unitId)
}


Expand Down
36 changes: 24 additions & 12 deletions src/memory/readParty.ahk
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@


ReadParty(ByRef d2rprocess, ByRef partyList) {
ReadParty(ByRef d2rprocess, ByRef partyList, ByRef playerUnitId) {
partyList := []
SetFormat Integer, D
rosterOffset := offsets["rosterOffset"]
, baseAddress := d2rprocess.BaseAddress + rosterOffset
, playerUnit := d2rprocess.read(baseAddress, "Int64")
while (playerUnit > 0) { ; keep following the next pointer
name := d2rprocess.readString(playerUnit, length := 16)
, unitId := d2rprocess.read(playerUnit + 0x48, "UInt")
, area := d2rprocess.read(playerUnit + 0x5C, "UInt")
, plevel := d2rprocess.read(playerUnit + 0x58, "UShort")
, partyId := d2rprocess.read(playerUnit + 0x5A, "UShort")
, xPos := d2rprocess.read(playerUnit + 0x60, "UInt")
, yPos := d2rprocess.read(playerUnit + 0x64, "UInt")
player := { "name": name, "unitId": unitId, "area": area, "partyId": partyId, "plevel": plevel, "xPos": xPos, "yPos": yPos }
, partyStruct := d2rprocess.read(baseAddress, "Int64")
while (partyStruct > 0) { ; keep following the next pointer
name := d2rprocess.readString(partyStruct, length := 16)
, unitId := d2rprocess.read(partyStruct + 0x48, "UInt")
, area := d2rprocess.read(partyStruct + 0x5C, "UInt")
, plevel := d2rprocess.read(partyStruct + 0x58, "UShort")
, partyId := d2rprocess.read(partyStruct + 0x5A, "UShort")
, xPos := d2rprocess.read(partyStruct + 0x60, "UInt")
, yPos := d2rprocess.read(partyStruct + 0x64, "UInt")
, hostilePtr := d2rprocess.read(partyStruct + 0x70, "Int64")
, isHostileToPlayer := false
while (hostilePtr) {
hostileUnitId := d2rprocess.read(hostilePtr, "UInt")
hostileFlag := d2rprocess.read(hostilePtr + 0x04, "UInt")
hostilePtr := d2rprocess.read(hostilePtr + 0x08, "Int64")
if (playerUnitId == hostileUnitId) {
if (hostileFlag > 0) {
isHostileToPlayer := true
}
}
}
player := { "name": name, "unitId": unitId, "area": area, "partyId": partyId, "plevel": plevel, "xPos": xPos, "yPos": yPos, "isHostileToPlayer": isHostileToPlayer }
partyList.push(player)
playerUnit := d2rprocess.read(playerUnit + 0x148, "Int64") ; get next player
partyStruct := d2rprocess.read(partyStruct + 0x148, "Int64") ; get next player
}
}
8 changes: 8 additions & 0 deletions src/ui/gdip/GameInfoLayer.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class GameInfoLayer {
}
this.numplayers := 0
this.numinparty := 1
; this.hostilePlayers := 0

for k,v in gameMemoryData["partyList"]
{
Expand All @@ -167,11 +168,18 @@ class GameInfoLayer {
if (v.partyId == playerPartyId) { ; only if in same party
this.numinparty++
}
; if (v.isHostileToPlayer) {
; this.hostilePlayers++
; }
}
}
if (this.numplayers > 1) {
textList := textList "Players: " this.numplayers "`n"
textList := textList "In Party: " this.numinparty "`n"
; if (this.hostilePlayers) {
; textList := textList "Hostile: " this.hostilePlayers "`n"
; }

}
}

Expand Down

0 comments on commit 402f856

Please sign in to comment.