From 1f12234e627dd1663416e1930f68fcb4624c6b1d Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Wed, 6 Feb 2019 18:38:28 -0800 Subject: [PATCH] Make d2info work in multiplayer (LAN/private servers) --- README.md | 2 +- d2info/gamestate.lua | 13 +++++++++---- d2info/output.lua | 8 ++++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3f23011..adea0fa 100644 --- a/README.md +++ b/README.md @@ -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 versions 1.13c, 1.13d, 1.14b, 1.14c, and 1.14d (D2SE and/or PlugY are also supported) +Supports Diablo II versions 1.13c, 1.13d, 1.14b, 1.14c, and 1.14d (D2SE and/or PlugY are also supported). It can also be used on LAN and private multiplayer servers (if it's allowed), however **it is not recommended to use it on Battle.net**, as it will most likely be considered a cheat and could result in a ban. ## Installation diff --git a/d2info/gamestate.lua b/d2info/gamestate.lua index c0e2254..7abd3fc 100644 --- a/d2info/gamestate.lua +++ b/d2info/gamestate.lua @@ -15,8 +15,12 @@ function GameState.new(reader, config, output) return self end -function GameState:inValidGame() - return self.reader:getGamePointer() ~= nil and self.reader:getExperience() ~= nil +function GameState:inValidGame(multiplayer) + return (multiplayer or self.reader:getGamePointer() ~= nil) and self.reader:getExperience() ~= nil +end + +function GameState:inMultiplayerGame() + return self.reader:getGamePointer() == nil and self.reader:getExperience() ~= nil end function GameState:inTown() @@ -24,7 +28,7 @@ function GameState:inTown() end function GameState:isPaused() - return self.ingame and self.lastFrameNumber and self.lastFrameNumber == self.frameNumber + return not self.multiplayer and self.ingame and self.lastFrameNumber and self.lastFrameNumber == self.frameNumber end function GameState:setupCurrentSession() @@ -57,7 +61,8 @@ function GameState:getSessions() end function GameState:tick(ms) - self.ingame = self:inValidGame() + self.multiplayer = self:inMultiplayerGame() + self.ingame = self:inValidGame(self.multiplayer) if self.ingame then -- read current state self.player = self.reader:getPlayerName() diff --git a/d2info/output.lua b/d2info/output.lua index 8973a6d..c726cdc 100644 --- a/d2info/output.lua +++ b/d2info/output.lua @@ -1,6 +1,6 @@ local utils = require('d2info.utils') local lfs = require('lfs') -local printf, friendlyNumber, friendlyTime, toFile = utils.printf, utils.friendlyNumber, utils.friendlyTime, utils.toFile +local friendlyNumber, friendlyTime, toFile = utils.friendlyNumber, utils.friendlyTime, utils.toFile local expToPercentLeveled = utils.expToPercentLeveled local Output = {} @@ -26,7 +26,11 @@ function Output:toScreen(state) local sessions = state:getSessions() local total, current, last = sessions.total, sessions.current, sessions.last self:buffer("%s (level %d & %.2f%%)", state.player, state.level, expToPercentLeveled(state.exp, state.level)*100) - self:buffer("/players %d", state.playersX) + if state.multiplayer then + self:buffer("Multiplayer") + else + self:buffer("/players %d", state.playersX) + end if current then self:buffer("\nRun #%d:", total.runs+1)