-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Drop support for versions < 1.13, as I don't want to install that many versions of d2 to get the offsets - Add config with a few options - Add support for ignoring time spent in town past a certain threshold, to allow for stash management without ruining xp/min (default is 20 seconds) - Time spent paused is now ignored for game-time xp/min calculations - Add run tracking and # runs till level - Reformat console output to be more readable/concise - Add /players x value to output - General improvements/bug fixes/refactoring - Add a bunch of stuff for calculating real xp gain (area level, player level pentalty, /players x), but don't have a good way of displaying it yet and its not quite done (relevant console output is disabled by default) - Now depends on luabitop
- Loading branch information
Showing
12 changed files
with
717 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
output | ||
d2info-config.lua | ||
d2info-config-default.lua | ||
|
||
# Created by https://www.gitignore.io/api/lua,linux,windows | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,18 @@ | ||
local memreader = require('memreader') | ||
local D2Reader = require('d2info.d2reader') | ||
local sleep = require('sleep') | ||
local Session = require('d2info.session') | ||
local D2Reader = require('d2info.d2reader') | ||
local Output = require('d2info.output') | ||
local Config = require('d2info.config') | ||
local GameState = require('d2info.gamestate') | ||
|
||
memreader.debugprivilege(true) | ||
local reader = D2Reader.new() | ||
local sessions = {} | ||
local output = Output.new() | ||
local lastInfo = {} | ||
local UPDATE_PERIOD = 1000 | ||
|
||
while true do | ||
local player = reader:getPlayerName() | ||
local exp, lvl = reader:getExperience() | ||
if player and exp then | ||
if not sessions[player] then | ||
sessions[player] = {} | ||
sessions[player].total = Session.new(exp, lvl) | ||
end | ||
if sessions[player].current == nil then | ||
sessions[player].current = Session.new(exp, lvl) | ||
end | ||
|
||
local current, total, last = sessions[player].current, sessions[player].total, sessions[player].last | ||
current:update(exp, lvl) | ||
total:update(exp, lvl) | ||
local reader, output, config = D2Reader.new(), Output.new(), Config.new() | ||
local state = GameState.new(reader, config, output) | ||
|
||
output:toScreen(player, lvl, total, current, last) | ||
output:toFile(player, lvl, total, current, last) | ||
local UPDATE_PERIOD = config:get("UPDATE_PERIOD") | ||
|
||
current:incrementDuration() | ||
total:incrementDuration() | ||
|
||
lastInfo.player = player | ||
lastInfo.level = lvl | ||
elseif reader.status ~= nil then | ||
os.execute('cls') | ||
print(reader.status) | ||
else | ||
os.execute('cls') | ||
print("No player") | ||
|
||
if lastInfo.player ~= nil and sessions[lastInfo.player].current ~= nil then | ||
sessions[lastInfo.player].last = sessions[lastInfo.player].current | ||
sessions[lastInfo.player].current = nil | ||
end | ||
|
||
-- need to update files here because otherwise they wouldn't update | ||
-- while at the menu screen during save+quit | ||
if lastInfo.player then | ||
output:toFile(lastInfo.player, lastInfo.level, sessions[lastInfo.player].total, sessions[lastInfo.player].current, sessions[lastInfo.player].last) | ||
end | ||
end | ||
while true do | ||
state:tick(UPDATE_PERIOD) | ||
sleep(UPDATE_PERIOD) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
local lfs = require('lfs') | ||
|
||
local DEFAULT_CONFIG_NOTE = [=[--[[ | ||
NOTE: This file is not used by d2info and will get overwritten on every run of d2info. | ||
Instead, it is intended to be used as a reference for updating your config | ||
file after updating to a new version of d2info (to see new config options, etc). | ||
]]-- | ||
]=] | ||
local DEFAULT_CONFIG = [[ | ||
return { | ||
-- time between updates, in milliseconds | ||
UPDATE_PERIOD = 1000, | ||
-- maximum duration spent in each town that will count towards exp/min calculations | ||
-- (e.g. with a value of 30, spending longer than 30 seconds in any given town will only | ||
-- count as 30 seconds when calculating exp/min using game time) | ||
-- this allows for doing things like stash management without affecting the stats too much | ||
MAX_TOWN_DURATION = 20, | ||
-- enable/disable outputting info to the console screen | ||
OUTPUT_TO_SCREEN = true, | ||
-- enable/disable outputting info to files | ||
OUTPUT_TO_FILE = true, | ||
-- show information about the area you are currently in, such as: area level, | ||
-- percentage xp gain from monsters/champions/uniques in that area, etc | ||
SHOW_AREA_INFORMATION = false, | ||
} | ||
]] | ||
|
||
local Config = {} | ||
Config.__index = Config | ||
|
||
function Config.new(file, defaultFile) | ||
local self = setmetatable({}, Config) | ||
self.default = assert(loadstring(DEFAULT_CONFIG))() | ||
self.config = {} | ||
self.file = file or "d2info-config.lua" | ||
self.defaultFile = defaultFile or "d2info-config-default.lua" | ||
self:load(file) | ||
self:write(self.defaultFile, DEFAULT_CONFIG_NOTE .. DEFAULT_CONFIG) | ||
return self | ||
end | ||
|
||
local function resolve(t, ...) | ||
local keys = {...} | ||
local key = table.remove(keys, 1) | ||
if #keys == 0 then | ||
return t[key] | ||
end | ||
if not t[key] then | ||
return nil | ||
end | ||
return resolve(t[key], keys) | ||
end | ||
|
||
-- Gets a config value by resolving its keys in order | ||
-- e.g. get('a', 'b') will return config['a']['b'] | ||
function Config:get(...) | ||
local v = resolve(self.config, ...) | ||
if v == nil then | ||
v = resolve(self.default, ...) | ||
end | ||
return v | ||
end | ||
|
||
function Config:load(file) | ||
if not file then file = self.file end | ||
if not self:exists(file) then | ||
self:write(file, DEFAULT_CONFIG) | ||
return | ||
end | ||
local f = assert(io.open(file)) | ||
local str = f:read("*all") | ||
local fn = assert(loadstring(str, file)) | ||
local loaded = fn() | ||
self.config = loaded | ||
end | ||
|
||
function Config:write(file, data) | ||
if not file then file = self.file end | ||
local f = assert(io.open(file, "w")) | ||
f:write(data) | ||
f:close() | ||
end | ||
|
||
function Config:exists(file) | ||
if not file then file = self.file end | ||
return lfs.attributes(file) ~= nil | ||
end | ||
|
||
return Config |
Oops, something went wrong.