* Panel Manager Improvements - Now maps instead of slices for easy traverse - Function for easy and safe traverse of paths - Removed constant updates of Panel Manager to reduce usage. It will now be called on demand. - Updated some functions to use the new Panel Manager. * Remove unused struct members * Added IsDismissalModalPresent (error popup) * Correct function return for char select screen and dismissal modal * Add error checking to IsDismissableModalPresent
79 lines
2.7 KiB
Go
79 lines
2.7 KiB
Go
package memory
|
|
|
|
import (
|
|
"github.com/hectorgimenez/d2go/pkg/data"
|
|
)
|
|
|
|
func NewPanel(panelPtr uintptr, panelParent string, depth int, gd *GameReader) *data.Panel { //itemUnitPtr = uintptr(gd.Process.ReadUInt(itemUnitPtr+0x158, Uint64))
|
|
panel := &data.Panel{
|
|
PanelPtr: panelPtr,
|
|
PanelName: gd.Process.ReadStringFromMemory(uintptr(gd.Process.ReadUInt(panelPtr+0x08, Uint64)), 0),
|
|
PanelEnabled: gd.Process.ReadUInt(panelPtr+0x50, Uint8) != 0,
|
|
PanelVisible: gd.Process.ReadUInt(panelPtr+0x51, Uint8) != 0,
|
|
PtrChild: uintptr(gd.Process.ReadUInt(panelPtr+0x58, Uint64)),
|
|
NumChildren: int(gd.Process.ReadUInt(panelPtr+0x60, Uint8)),
|
|
ExtraText: gd.Process.ReadStringFromMemory(panelPtr+0xA0, 0),
|
|
ExtraText2: gd.Process.ReadStringFromMemory(uintptr(gd.Process.ReadUInt(panelPtr+0x290, Uint64)), 0),
|
|
ExtraText3: gd.Process.ReadStringFromMemory(uintptr(gd.Process.ReadUInt(panelPtr+0x88, Uint64)), 0),
|
|
PanelParent: panelParent,
|
|
PanelChildren: make(map[string]data.Panel),
|
|
Depth: depth,
|
|
}
|
|
if panel.NumChildren > 0 && panel.NumChildren < 50 {
|
|
readPanel(panel.PtrChild, panel.NumChildren, &panel.PanelChildren, panel.PanelName, depth+1, gd)
|
|
}
|
|
return panel
|
|
}
|
|
|
|
func GetText(p data.Panel) string {
|
|
text1 := cleanString(p.ExtraText)
|
|
text2 := cleanString(p.ExtraText2)
|
|
text3 := cleanString(p.ExtraText3)
|
|
|
|
if text3 != "" && isASCII(text3) {
|
|
return text3
|
|
}
|
|
if text2 != "" && isASCII(text2) {
|
|
return text2
|
|
}
|
|
if text1 != "" && isASCII(text1) {
|
|
return text1
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func cleanString(input string) string {
|
|
return input // Replace newlines and carriage returns as needed
|
|
}
|
|
|
|
func isASCII(s string) bool {
|
|
for _, r := range s {
|
|
if r < 32 || r > 126 {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
// ReadAllPanels reads all panels from the game memory
|
|
func (gd *GameReader) ReadAllPanels() map[string]data.Panel {
|
|
base := gd.Process.moduleBaseAddressPtr + gd.offset.PanelManagerContainerOffset
|
|
panelStructPtr := uintptr(gd.Process.ReadUInt(base, Uint64))
|
|
panelPtr := uintptr(gd.Process.ReadUInt(panelStructPtr+0x58, Uint64))
|
|
numChildren := int(gd.Process.ReadUInt(panelStructPtr+0x60, Uint8))
|
|
|
|
panels := make(map[string]data.Panel)
|
|
depth := 0
|
|
// recursively read all panels, starting with the Root panel
|
|
readPanel(panelPtr, numChildren, &panels, "Root", depth, gd)
|
|
return panels
|
|
}
|
|
|
|
func readPanel(panelPtr uintptr, numChildren int, panels *map[string]data.Panel, panelParent string, depth int, gd *GameReader) {
|
|
for i := 0; i < numChildren; i++ {
|
|
panelStructPtr := uintptr(gd.Process.ReadUInt(uintptr(uint64(panelPtr)+uint64(i*8)), Uint64))
|
|
thisPanel := NewPanel(panelStructPtr, panelParent, depth, gd)
|
|
(*panels)[thisPanel.PanelName] = *thisPanel
|
|
}
|
|
}
|