Skip to content

Commit

Permalink
Add support for D2SE
Browse files Browse the repository at this point in the history
  • Loading branch information
squeek502 committed Mar 2, 2018
1 parent 4073f7e commit ece4dce
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Currently, it provides the following information:
- Number of experience 'ticks' gained (pixels filled in the experience bar)
- Information about the current area, like monster level and % xp gain (unfinished, disabled by default; see `SHOW_AREA_INFORMATION` in the config)

Supports Diablo II verisons 1.13c, 1.13d, 1.14b, 1.14c, and 1.14d
Supports Diablo II versions 1.13c, 1.13d, 1.14b, 1.14c, and 1.14d (D2SE and/or PlugY are also supported)

## Installation

Expand Down
1 change: 1 addition & 0 deletions d2info/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ return {
},

exe = "Game.exe",
d2seExe = "D2SE.exe",
windowTitle = "Diablo II",

gui = {
Expand Down
45 changes: 31 additions & 14 deletions d2info/d2reader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function D2Reader.new()
self.d2ClientDLL = nil
self.d2GameDLL = nil
self.d2NetDLL = nil
self.isD2SE = nil
self:init()
return self
end
Expand All @@ -30,18 +31,30 @@ function D2Reader:init()
return
end

local versionInfo, err = self.process:version()
if not versionInfo then
self.status = "Error obtaining Game.exe version: " .. err
self.process = nil
return
end
self.isD2SE = self.process.name:lower() == constants.d2seExe:lower()

local version = utils.friendlyVersion(versionInfo.file)
local d2version = constants.versions[version]
if not d2version then
self.status = "Error: Unrecognized Game.exe version: " .. version
return
local d2version
local shouldHaveDLLs
if self.isD2SE then
d2version = assert(self.process:readrelative(offsetsTable["d2se"].d2version, 5))
d2version = binary.null_terminate(d2version)
shouldHaveDLLs = true
else
local versionInfo, err = self.process:version()
if not versionInfo then
self.status = "Error obtaining Game.exe version: " .. err
self.process = nil
return
end

local version = utils.friendlyVersion(versionInfo.file)
d2version = constants.versions[version]
shouldHaveDLLs = versionInfo.file.minor == 0

if not d2version then
self.status = "Error: Unrecognized Game.exe version: " .. version
return
end
end

self.isPlugY = false
Expand All @@ -62,7 +75,7 @@ function D2Reader:init()
end

local hasDLLs = self.d2ClientDLL and self.d2GameDLL and self.d2NetDLL
if versionInfo.file.minor == 0 and not hasDLLs then
if shouldHaveDLLs and not hasDLLs then
self.status = "Waiting for D2 dlls to be loaded"
return
end
Expand All @@ -79,21 +92,25 @@ function D2Reader:init()
self.status = nil
end

local function isValidExe(exe)
return constants.exe:lower() == exe:lower() or constants.d2seExe:lower() == exe:lower()
end

-- finding the process by window title is fast but can lead to false positives
-- or fail to find it if there are multiple windows with the same title
local function openProcessFast()
local window = memreader.findwindow(constants.windowTitle)
if window then
local process = memreader.openprocess(window.pid)
if process and process.name:lower() == constants.exe:lower() then
if process and isValidExe(process.name) then
return process
end
end
end

local function openProcess()
for pid, name in memreader.processes() do
if name:lower() == constants.exe:lower() then
if isValidExe(name) then
return assert(memreader.openprocess(pid))
end
end
Expand Down
3 changes: 3 additions & 0 deletions d2info/offsets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,7 @@ return {
worldGameBuffer=0x1C, -- relative to world address
worldGameMask=0x24, -- relative to world address
},
["d2se"] = {
d2version=0x1A049, -- relative to d2se.exe address
}
}

0 comments on commit ece4dce

Please sign in to comment.