-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathdebugger.lua
68 lines (59 loc) · 1.62 KB
/
debugger.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
local function getInnerDebugger()
local path
pcall(function ()
path = require 'log.debugger_path'
end)
return path
end
local function dofile(filename)
local f = assert(io.open(filename))
local str = f:read "*a"
f:close()
return assert(load(str, "=(debugger.lua)"))(filename)
end
local function isDebuggerValid()
if arg['lua_multi_mode'] == 'true' then
local id = GameAPI.get_client_role():get_role_id_num()
for i in arg['lua_multi_debug_players']:gmatch('%d+') do
if tonumber(i) == id then
return true
end
end
return false
end
return true
end
local function getDebuggerPort()
if arg['lua_multi_mode'] == 'true' then
local id = GameAPI.get_client_role():get_role_id_num()
return 12399 - id
else
return 12399
end
end
local function waitDebugger(forceWait)
if arg['lua_wait_debugger'] == 'true'
or arg['lua_multi_wait_debugger'] == 'true'
or forceWait then
do
local _ <close> = io.open(script_path:match('^(.-)%?') .. '/.log/wait_debugger', 'w')
end
LDBG:event 'wait'
end
end
pcall(function ()
if not isDebuggerValid() then
return
end
local path = getInnerDebugger()
local dbg = dofile(path .. "/script/debugger.lua")
local port = getDebuggerPort()
LDBG = dbg:start("127.0.0.1:" .. tostring(port))
if not LDBG then
return
end
-- 关闭调试器的自动更新,之后每帧手动更新一次
LDBG:event('autoUpdate', false)
-- 等待调试器连接
waitDebugger(false)
end)