mirror of
https://github.com/OTCv8/otclientv8.git
synced 2025-04-30 03:09:20 +02:00
Fixed high memory usage issue
This commit is contained in:
parent
26c347d2bc
commit
11ad766308
@ -133,6 +133,7 @@ function sendStats()
|
|||||||
cpu = g_platform.getCPUName(),
|
cpu = g_platform.getCPUName(),
|
||||||
mem = g_platform.getTotalSystemMemory(),
|
mem = g_platform.getTotalSystemMemory(),
|
||||||
mem_usage = g_platform.getMemoryUsage(),
|
mem_usage = g_platform.getMemoryUsage(),
|
||||||
|
lua_mem_usage = gcinfo(),
|
||||||
os_name = g_platform.getOSName(),
|
os_name = g_platform.getOSName(),
|
||||||
platform = g_window.getPlatformType(),
|
platform = g_window.getPlatformType(),
|
||||||
uptime = g_clock.seconds()
|
uptime = g_clock.seconds()
|
||||||
@ -170,6 +171,7 @@ function update()
|
|||||||
end
|
end
|
||||||
|
|
||||||
statsWindow.debugPanel.sleepTime:setText("Sleep: " .. math.round(g_stats.getSleepTime() / math.max(1, g_clock.micros() - lastSleepTimeReset), 2) .. "%")
|
statsWindow.debugPanel.sleepTime:setText("Sleep: " .. math.round(g_stats.getSleepTime() / math.max(1, g_clock.micros() - lastSleepTimeReset), 2) .. "%")
|
||||||
|
statsWindow.debugPanel.luaRamUsage:setText("Ram usage by lua: " .. gcinfo() .. " kb")
|
||||||
local adaptive = "Adaptive: " .. g_adaptiveRenderer.getLevel() .. " | " .. g_adaptiveRenderer.getDebugInfo()
|
local adaptive = "Adaptive: " .. g_adaptiveRenderer.getLevel() .. " | " .. g_adaptiveRenderer.getDebugInfo()
|
||||||
adaptiveRender:setText(adaptive)
|
adaptiveRender:setText(adaptive)
|
||||||
atlas:setText("Atlas: " .. g_atlas.getStats())
|
atlas:setText("Atlas: " .. g_atlas.getStats())
|
||||||
|
@ -38,6 +38,10 @@ MainWindow
|
|||||||
text: -
|
text: -
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
|
|
||||||
|
DebugText
|
||||||
|
id: luaRamUsage
|
||||||
|
text: -
|
||||||
|
|
||||||
DebugLabel
|
DebugLabel
|
||||||
!text: tr('Render')
|
!text: tr('Render')
|
||||||
|
|
||||||
@ -89,7 +93,7 @@ MainWindow
|
|||||||
text: -
|
text: -
|
||||||
|
|
||||||
DebugLabel
|
DebugLabel
|
||||||
!text: tr('Widgets')
|
!text: tr('Widgets & Objects')
|
||||||
|
|
||||||
DebugText
|
DebugText
|
||||||
id: widgetsInfo
|
id: widgetsInfo
|
||||||
|
@ -3,7 +3,6 @@ battleButton = nil
|
|||||||
battlePanel = nil
|
battlePanel = nil
|
||||||
filterPanel = nil
|
filterPanel = nil
|
||||||
toggleFilterButton = nil
|
toggleFilterButton = nil
|
||||||
creatureAgeList = {}
|
|
||||||
battleButtonsList = {}
|
battleButtonsList = {}
|
||||||
|
|
||||||
mouseWidget = nil
|
mouseWidget = nil
|
||||||
@ -233,12 +232,8 @@ function checkCreatures()
|
|||||||
local dimension = modules.game_interface.getMapPanel():getVisibleDimension()
|
local dimension = modules.game_interface.getMapPanel():getVisibleDimension()
|
||||||
local spectators = g_map.getSpectatorsInRangeEx(player:getPosition(), false, math.floor(dimension.width / 2), math.floor(dimension.width / 2), math.floor(dimension.height / 2), math.floor(dimension.height / 2))
|
local spectators = g_map.getSpectatorsInRangeEx(player:getPosition(), false, math.floor(dimension.width / 2), math.floor(dimension.width / 2), math.floor(dimension.height / 2), math.floor(dimension.height / 2))
|
||||||
|
|
||||||
creatures = {}
|
local creatures = {}
|
||||||
for _, creature in ipairs(spectators) do
|
for _, creature in ipairs(spectators) do
|
||||||
if creatureAgeList[creature] == nil then
|
|
||||||
creatureAgeList[creature] = creatureAgeCounter
|
|
||||||
creatureAgeCounter = creatureAgeCounter + 1
|
|
||||||
end
|
|
||||||
if doCreatureFitFilters(creature) then
|
if doCreatureFitFilters(creature) then
|
||||||
table.insert(creatures, creature)
|
table.insert(creatures, creature)
|
||||||
end
|
end
|
||||||
@ -335,23 +330,23 @@ function sortCreatures(creatures)
|
|||||||
local playerPos = player:getPosition()
|
local playerPos = player:getPosition()
|
||||||
table.sort(creatures, function(a, b)
|
table.sort(creatures, function(a, b)
|
||||||
if getDistanceBetween(playerPos, a:getPosition()) == getDistanceBetween(playerPos, b:getPosition()) then
|
if getDistanceBetween(playerPos, a:getPosition()) == getDistanceBetween(playerPos, b:getPosition()) then
|
||||||
return creatureAgeList[a] > creatureAgeList[b]
|
return a:getAge() > b:getAge()
|
||||||
end
|
end
|
||||||
return getDistanceBetween(playerPos, a:getPosition()) > getDistanceBetween(playerPos, b:getPosition())
|
return getDistanceBetween(playerPos, a:getPosition()) > getDistanceBetween(playerPos, b:getPosition())
|
||||||
end)
|
end)
|
||||||
elseif getSortType() == 'health' then
|
elseif getSortType() == 'health' then
|
||||||
table.sort(creatures, function(a, b)
|
table.sort(creatures, function(a, b)
|
||||||
if a:getHealthPercent() == b:getHealthPercent() then
|
if a:getHealthPercent() == b:getHealthPercent() then
|
||||||
return creatureAgeList[a] > creatureAgeList[b]
|
return a:getAge() > b:getAge()
|
||||||
end
|
end
|
||||||
return a:getHealthPercent() > b:getHealthPercent()
|
return a:getHealthPercent() > b:getHealthPercent()
|
||||||
end)
|
end)
|
||||||
elseif getSortType() == 'age' then
|
elseif getSortType() == 'age' then
|
||||||
table.sort(creatures, function(a, b) return creatureAgeList[a] > creatureAgeList[b] end)
|
table.sort(creatures, function(a, b) return a:getAge() > b:getAge() end)
|
||||||
else -- name
|
else -- name
|
||||||
table.sort(creatures, function(a, b)
|
table.sort(creatures, function(a, b)
|
||||||
if a:getName():lower() == b:getName():lower() then
|
if a:getName():lower() == b:getName():lower() then
|
||||||
return creatureAgeList[a] > creatureAgeList[b]
|
return a:getAge() > b:getAge()
|
||||||
end
|
end
|
||||||
return a:getName():lower() > b:getName():lower()
|
return a:getName():lower() > b:getName():lower()
|
||||||
end)
|
end)
|
||||||
|
@ -1,3 +1,23 @@
|
|||||||
|
BotTabBar < MoveableTabBar
|
||||||
|
tab-spacing: 1
|
||||||
|
margin-left: 1
|
||||||
|
margin-right: 1
|
||||||
|
movable: false
|
||||||
|
height: 20
|
||||||
|
|
||||||
|
$on:
|
||||||
|
visible: true
|
||||||
|
margin-top: 2
|
||||||
|
|
||||||
|
$!on:
|
||||||
|
visible: false
|
||||||
|
margin-top: -20
|
||||||
|
|
||||||
|
BotTabBarButton < MoveableTabBarButton
|
||||||
|
padding: 3
|
||||||
|
text-horizontal-auto-resize: true
|
||||||
|
|
||||||
|
|
||||||
MiniWindow
|
MiniWindow
|
||||||
id: botWindow
|
id: botWindow
|
||||||
!text: tr('Bot')
|
!text: tr('Bot')
|
||||||
@ -88,24 +108,12 @@ MiniWindow
|
|||||||
margin-left: 2
|
margin-left: 2
|
||||||
margin-right: 2
|
margin-right: 2
|
||||||
|
|
||||||
MoveableTabBar
|
BotTabBar
|
||||||
id: botTabs
|
id: botTabs
|
||||||
anchors.top: prev.bottom
|
anchors.top: prev.bottom
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
anchors.right: parent.right
|
anchors.right: parent.right
|
||||||
tab-spacing: 1
|
margin-right: -20
|
||||||
margin-left: 1
|
|
||||||
margin-right: 1
|
|
||||||
height: 20
|
|
||||||
movable: false
|
|
||||||
|
|
||||||
$on:
|
|
||||||
visible: true
|
|
||||||
margin-top: 2
|
|
||||||
|
|
||||||
$!on:
|
|
||||||
visible: false
|
|
||||||
margin-top: -20
|
|
||||||
|
|
||||||
Panel
|
Panel
|
||||||
id: botPanel
|
id: botPanel
|
||||||
|
@ -67,6 +67,12 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs
|
|||||||
context.table = table
|
context.table = table
|
||||||
context.string = string
|
context.string = string
|
||||||
context.tonumber = tonumber
|
context.tonumber = tonumber
|
||||||
|
context.type = type
|
||||||
|
context.pcall = pcall
|
||||||
|
context.load = function(str) return load(str, nil, nil, context) end
|
||||||
|
context.loadstring = context.load
|
||||||
|
context.assert = assert
|
||||||
|
context.gcinfo = gcinfo
|
||||||
context.tr = tr
|
context.tr = tr
|
||||||
context.json = json
|
context.json = json
|
||||||
context.regexMatch = regexMatch
|
context.regexMatch = regexMatch
|
||||||
@ -84,9 +90,16 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs
|
|||||||
context.g_window = g_window
|
context.g_window = g_window
|
||||||
context.g_mouse = g_mouse
|
context.g_mouse = g_mouse
|
||||||
|
|
||||||
|
context.Item = Item
|
||||||
|
context.Creature = Creature
|
||||||
|
context.ThingType = ThingType
|
||||||
|
context.Effect = Effect
|
||||||
|
context.Missile = Missile
|
||||||
|
context.Player = Player
|
||||||
|
context.Monster = Monster
|
||||||
context.StaticText = StaticText
|
context.StaticText = StaticText
|
||||||
context.Config = Config
|
|
||||||
context.HTTP = HTTP
|
context.HTTP = HTTP
|
||||||
|
context.OutputMessage = OutputMessage
|
||||||
context.modules = modules
|
context.modules = modules
|
||||||
|
|
||||||
-- log functions
|
-- log functions
|
||||||
@ -123,7 +136,7 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, webs
|
|||||||
context.time = g_clock.millis()
|
context.time = g_clock.millis()
|
||||||
|
|
||||||
for i, macro in ipairs(context._macros) do
|
for i, macro in ipairs(context._macros) do
|
||||||
if macro.lastExecution + macro.timeout <= context.now and (macro.name == nil or macro.name:len() < 1 or macro.enabled) then
|
if macro.lastExecution + macro.timeout <= context.now and macro.enabled then
|
||||||
local status, result = pcall(function()
|
local status, result = pcall(function()
|
||||||
if macro.callback(macro) then
|
if macro.callback(macro) then
|
||||||
macro.lastExecution = context.now
|
macro.lastExecution = context.now
|
||||||
|
8
modules/game_bot/functions/const.lua
Normal file
8
modules/game_bot/functions/const.lua
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
North = 0
|
||||||
|
East = 1
|
||||||
|
South = 2
|
||||||
|
West = 3
|
||||||
|
NorthEast = 4
|
||||||
|
SouthEast = 5
|
||||||
|
SouthWest = 6
|
||||||
|
NorthWest = 7
|
@ -10,8 +10,6 @@ context.addIcon = function(id, options, callback)
|
|||||||
text: string
|
text: string
|
||||||
x: float (0.0 - 1.0)
|
x: float (0.0 - 1.0)
|
||||||
y: float (0.0 - 1.0)
|
y: float (0.0 - 1.0)
|
||||||
width: number
|
|
||||||
height: number
|
|
||||||
hotkey: string
|
hotkey: string
|
||||||
switchable: true / false [default: true]
|
switchable: true / false [default: true]
|
||||||
movable: true / false [default: true]
|
movable: true / false [default: true]
|
||||||
@ -63,6 +61,9 @@ context.addIcon = function(id, options, callback)
|
|||||||
widget.status:hide()
|
widget.status:hide()
|
||||||
widget.status:setOn(true)
|
widget.status:setOn(true)
|
||||||
else
|
else
|
||||||
|
if config.enabled ~= true then
|
||||||
|
config.enabled = false
|
||||||
|
end
|
||||||
widget.status:setOn(config.enabled)
|
widget.status:setOn(config.enabled)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -95,6 +95,8 @@ context.macro = function(timeout, name, hotkey, callback, parent)
|
|||||||
if context.storage._macros[name] == true then
|
if context.storage._macros[name] == true then
|
||||||
macro.setOn()
|
macro.setOn()
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
macro.enabled = true -- unnamed macros are enabled by default
|
||||||
end
|
end
|
||||||
|
|
||||||
local desc = "lua"
|
local desc = "lua"
|
||||||
|
@ -16,16 +16,17 @@ context.NPC.isTrading = function()
|
|||||||
end
|
end
|
||||||
context.NPC.hasTrade = context.NPC.isTrading
|
context.NPC.hasTrade = context.NPC.isTrading
|
||||||
context.NPC.hasTradeWindow = context.NPC.isTrading
|
context.NPC.hasTradeWindow = context.NPC.isTrading
|
||||||
|
context.NPC.isTradeOpen = context.NPC.isTrading
|
||||||
|
|
||||||
context.NPC.getSellItems = function()
|
context.NPC.getSellItems = function()
|
||||||
if not context.NPC.isTrading() then return {} end
|
if not context.NPC.isTrading() then return {} end
|
||||||
local items = {}
|
local items = {}
|
||||||
for i, item in ipairs(modules.game_npctrade.tradeItems[modules.game_npctrade.SELL]) do
|
for i, item in ipairs(modules.game_npctrade.tradeItems[modules.game_npctrade.SELL]) do
|
||||||
table.insert(items, {
|
table.insert(items, {
|
||||||
|
item = item.ptr,
|
||||||
id = item.ptr:getId(),
|
id = item.ptr:getId(),
|
||||||
name = item.name,
|
|
||||||
count = item.ptr:getCount(),
|
count = item.ptr:getCount(),
|
||||||
|
name = item.name,
|
||||||
subType = item.ptr:getSubType(),
|
subType = item.ptr:getSubType(),
|
||||||
weight = item.weight / 100,
|
weight = item.weight / 100,
|
||||||
price = item.price
|
price = item.price
|
||||||
@ -36,11 +37,13 @@ end
|
|||||||
|
|
||||||
context.NPC.getBuyItems = function()
|
context.NPC.getBuyItems = function()
|
||||||
if not context.NPC.isTrading() then return {} end
|
if not context.NPC.isTrading() then return {} end
|
||||||
|
local items = {}
|
||||||
for i, item in ipairs(modules.game_npctrade.tradeItems[modules.game_npctrade.BUY]) do
|
for i, item in ipairs(modules.game_npctrade.tradeItems[modules.game_npctrade.BUY]) do
|
||||||
table.insert(items, {
|
table.insert(items, {
|
||||||
|
item = item.ptr,
|
||||||
id = item.ptr:getId(),
|
id = item.ptr:getId(),
|
||||||
name = item.name,
|
|
||||||
count = item.ptr:getCount(),
|
count = item.ptr:getCount(),
|
||||||
|
name = item.name,
|
||||||
subType = item.ptr:getSubType(),
|
subType = item.ptr:getSubType(),
|
||||||
weight = item.weight / 100,
|
weight = item.weight / 100,
|
||||||
price = item.price
|
price = item.price
|
||||||
@ -66,9 +69,17 @@ context.NPC.canTradeItem = function(item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
context.NPC.sell = function(item, count, ignoreEquipped)
|
context.NPC.sell = function(item, count, ignoreEquipped)
|
||||||
|
if type(item) == 'number' then
|
||||||
|
for i, entry in ipairs(context.NPC.getSellItems()) do
|
||||||
|
if entry.id == item then
|
||||||
|
item = entry.item
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
if type(item) == 'number' then
|
if type(item) == 'number' then
|
||||||
item = Item.create(item)
|
item = Item.create(item)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if count == 0 then
|
if count == 0 then
|
||||||
count = 1
|
count = 1
|
||||||
end
|
end
|
||||||
@ -82,9 +93,17 @@ context.NPC.sell = function(item, count, ignoreEquipped)
|
|||||||
end
|
end
|
||||||
|
|
||||||
context.NPC.buy = function(item, count, ignoreCapacity, withBackpack)
|
context.NPC.buy = function(item, count, ignoreCapacity, withBackpack)
|
||||||
|
if type(item) == 'number' then
|
||||||
|
for i, entry in ipairs(context.NPC.getBuyItems()) do
|
||||||
|
if entry.id == item then
|
||||||
|
item = entry.item
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
if type(item) == 'number' then
|
if type(item) == 'number' then
|
||||||
item = Item.create(item)
|
item = Item.create(item)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
if count == nil or count <= 0 then
|
if count == nil or count <= 0 then
|
||||||
count = 1
|
count = 1
|
||||||
end
|
end
|
||||||
|
@ -10,10 +10,25 @@ context.setupUI = function(otml, parent)
|
|||||||
end
|
end
|
||||||
|
|
||||||
context.addTab = function(name)
|
context.addTab = function(name)
|
||||||
context.tabs:setOn(true)
|
local tab = context.tabs:getTab(name)
|
||||||
return context.tabs:addTab(name, g_ui.createWidget('BotPanel')).tabPanel.content
|
if tab then -- return existing tab
|
||||||
|
return tab.tabPanel.content
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context.tabs:setOn(true)
|
||||||
|
local newTab = context.tabs:addTab(name, g_ui.createWidget('BotPanel')).tabPanel.content
|
||||||
|
print(#(context.tabs.tabs))
|
||||||
|
if #(context.tabs.tabs) > 5 then
|
||||||
|
for k,tab in pairs(context.tabs.tabs) do
|
||||||
|
tab:setPadding(3)
|
||||||
|
tab:setFont('cipsoftFont')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return newTab
|
||||||
|
end
|
||||||
|
context.getTab = context.addTab
|
||||||
|
|
||||||
context.addSwitch = function(id, text, onClickCallback, parent)
|
context.addSwitch = function(id, text, onClickCallback, parent)
|
||||||
if not parent then
|
if not parent then
|
||||||
parent = context.panel
|
parent = context.panel
|
||||||
|
@ -551,8 +551,10 @@ function sellAll()
|
|||||||
for itemid,item in pairs(playerItems) do
|
for itemid,item in pairs(playerItems) do
|
||||||
local item = Item.create(itemid)
|
local item = Item.create(itemid)
|
||||||
local amount = getSellQuantity(item)
|
local amount = getSellQuantity(item)
|
||||||
if amount > 0 then
|
while amount > 0 do
|
||||||
g_game.sellItem(item, amount, ignoreEquipped:isChecked())
|
local maxAmount = math.min(amount, getMaxAmount())
|
||||||
|
g_game.sellItem(item, maxAmount, ignoreEquipped:isChecked())
|
||||||
|
amount = amount - maxAmount
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -20,7 +20,8 @@ function init()
|
|||||||
onPositionChange = onPositionChange,
|
onPositionChange = onPositionChange,
|
||||||
onWalk = onWalk,
|
onWalk = onWalk,
|
||||||
onTeleport = onTeleport,
|
onTeleport = onTeleport,
|
||||||
onWalkFinish = onWalkFinish
|
onWalkFinish = onWalkFinish,
|
||||||
|
onCancelWalk = onCancelWalk
|
||||||
})
|
})
|
||||||
|
|
||||||
modules.game_interface.getRootPanel().onFocusChange = stopSmartWalk
|
modules.game_interface.getRootPanel().onFocusChange = stopSmartWalk
|
||||||
@ -255,6 +256,10 @@ function onWalkFinish(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function onCancelWalk(player)
|
||||||
|
player:lockWalk(50)
|
||||||
|
end
|
||||||
|
|
||||||
function walk(dir)
|
function walk(dir)
|
||||||
lastManualWalk = g_clock.millis()
|
lastManualWalk = g_clock.millis()
|
||||||
local player = g_game.getLocalPlayer()
|
local player = g_game.getLocalPlayer()
|
||||||
|
BIN
otclient_dx.exe
BIN
otclient_dx.exe
Binary file not shown.
BIN
otclient_gl.exe
BIN
otclient_gl.exe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user