Skip to content

Commit

Permalink
Trying to get local-lua-debugger running
Browse files Browse the repository at this point in the history
  • Loading branch information
Ismoh committed Oct 8, 2023
1 parent 24f3a23 commit f03ebb8
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 116 deletions.
60 changes: 15 additions & 45 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,22 @@
"version": "0.2.0",
"configurations": [
{
"name": "launch-lua",
"type": "lua",
"name": "Launch Noita with debugger",
"type": "lua-local",
"request": "launch",
"workingDirectory": "${workspaceRoot}",
"sourceBasePath": "${workspaceRoot}",
"executable": "${workspaceRoot}/mods/noita-mp/lua.bat",
"arguments": "main.lua",
"listenPublicly": false,
"listenPort": 56789,
"encoding": "UTF-8",
"env": {}
},
{
"name": "launch-gideros",
"type": "lua",
"request": "launch",
"workingDirectory": "${workspaceRoot}",
"giderosPath": "C:/Program Files (x86)/Gideros",
"gprojPath": "${workspaceRoot}/GPROJ.gproj",
"jumpToGiderosErrorPosition": false,
"stopGiderosWhenDebuggerStops": true,
"listenPublicly": false,
"listenPort": 56789,
"encoding": "UTF-8"
},
{
"name": "wait",
"type": "lua",
"request": "attach",
"workingDirectory": "${workspaceRoot}",
"sourceBasePath": "${workspaceRoot}",
"listenPublicly": false,
"listenPort": 56789,
"encoding": "UTF-8"
},
{
"name": "LAUNCH debug profiler.lua",
"type": "lua",
"request": "launch",
"workingDirectory": "C:/Program Files (x86)/Steam/steamapps/common/Noita",
"program": "C:/Program Files (x86)/Steam/steamapps/common/Noita/mods/noita-mp/files/scripts/bin/profiler.lua",
"listenPublicly": false,
"listenPort": 0,
"luaVersion": "jit",
"encoding": "UTF-8",
"luaexe": "${workspaceRoot}/LuaJIT-2.0.4/bin/luajit.exe",
"program": {
"lua": "C:/Program Files (x86)/Steam/steamapps/common/Noita/noita_dev_log.exe",
"file": "C:/Program Files (x86)/Steam/steamapps/common/Noita/noita_dev_log.exe",
//"command": "C:/Program Files (x86)/Steam/steamapps/common/Noita/noita_dev_log.exe",
"communication": "stdio"
},
"args": ["-debug_lua", "-no-console", "-luadebugger"],
"stopOnEntry": true,
"cwd": "C:/Program Files (x86)/Steam/steamapps/common/Noita",
"env": {
"LOCAL_LUA_DEBUGGER_VSCODE": "1"
},
"verbose": true
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,5 @@
],
"prettier.printWidth": 110,
"lua.debug.settings.luaVersion": "jit",
"lua-local.interpreter": "LuaJIT",
}
45 changes: 26 additions & 19 deletions mods/noita-mp/files/scripts/Gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function Gui:drawPlayMenu()
local isCollapsed
isCollapsed, self.showPlayMenu = self.imGui.Begin(self.playLabel, self.showPlayMenu, windowFlags)
if isCollapsed then
if self.utils:isEmpty(self.minaUtils.getLocalMinaName()) then
if self.utils:isEmpty(self.minaUtils:getLocalMinaName()) then
self.imGui.Text(("Please set your name in the settings first! Simply press '%s'!"):format(self.shortcuts.settings))
self.imGui.End()
self.customProfiler:stop("Gui.drawPlayMenu", cpc)
Expand Down Expand Up @@ -338,17 +338,17 @@ function Gui:drawPlayMenu()

local isPortChanged, port = self.imGui.InputTextWithHint("Server Port", "Type from 1 to max of 65535!", tostring(self.server:getPort()))
if isPortChanged then
self.server.port = port
self.server.port = tonumber(port) or 14017
end

self.imGui.Separator()
if self.imGui.Button("Start Server!") then
self.server.start(self.server:getAddress(), self.server:getPort())
self.server:start(self.server:getAddress(), self.server:getPort())
self.showPlayMenu = false
end
else
local isServerIpChanged, serverIp = self.imGui.InputTextWithHint("Server IP", "Use '*', 'localhost' or 'whatismyip.com'!",
Server:getAddress())
self.server:getAddress())
if isServerIpChanged then
self.server.address = serverIp
end
Expand Down Expand Up @@ -409,7 +409,7 @@ function Gui:drawSettings()
self.imGui.Text("Mandatory:")

-- Player name
local isPlayerNameChanged, playerName = self.imGui.InputTextWithHint("Nickname", "Type in your Nickname!", self.minaUtils.getLocalMinaName())
local isPlayerNameChanged, playerName = self.imGui.InputTextWithHint("Nickname", "Type in your Nickname!", self.minaUtils:getLocalMinaName())
if isPlayerNameChanged then
self.minaUtils:setLocalMinaName(playerName)
end
Expand Down Expand Up @@ -499,8 +499,8 @@ function Gui:drawSettings()
-- Save settings
if self.imGui.Button("Save Settings") then
if self.noitaMpSettings:isMoreThanOneNoitaProcessRunning() then
local newGuid = self.guidUtils:generateNewGuid({ self.minaUtils.getLocalMinaGuid() })
self.minaUtils.setLocalMinaGuid(newGuid)
local newGuid = self.guidUtils:generateNewGuid({ self.minaUtils:getLocalMinaGuid() })
self.minaUtils:setLocalMinaGuid(newGuid)
end

self.noitaMpSettings:save()
Expand Down Expand Up @@ -531,10 +531,10 @@ function Gui:drawSettings()
end
end

self.networkVscUtils.addOrUpdateAllVscs(self.minaUtils:getLocalMinaEntityId(), self.minaUtils:getLocalMinaName(),
self.networkVscUtils:addOrUpdateAllVscs(self.minaUtils:getLocalMinaEntityId(), self.minaUtils:getLocalMinaName(),
self.minaUtils:getLocalMinaGuid(), self.minaUtils:getLocalMinaNuid())

self.globalsUtils.setUpdateGui(true)
self.globalsUtils:setUpdateGui(true)
end
if self.showSettingsSaved then
self.imGui.SameLine()
Expand Down Expand Up @@ -644,7 +644,7 @@ function Gui:drawPlayerList()
self.imGui.TableFlags.Borders
)

local minas = self.minaUtils:getAllMinas()
local minas = self.minaUtils:getAllMinas(self.client, self.server)
local columnCount = function()
local count = 0
for _ in pairs(minas[1]) do
Expand Down Expand Up @@ -761,16 +761,13 @@ function Gui:new(guiObject, server, client, customProfiler, guidUtils, minaUtils
if not guiObject.customProfiler then
---@type CustomProfiler
---@see CustomProfiler
guiObject.customProfiler = customProfiler or server.customProfiler or require("CustomProfiler")
:new(nil, nil, server.noitaMpSettings, nil, nil, nil, nil)
guiObject.customProfiler = customProfiler or server.customProfiler or error("Gui:new needs a CustomProfiler instance!", 2)
end

if not guiObject.guidUtils then
---@type GuidUtils
---@see GuidUtils
guiObject.guidUtils = guidUtils or require("GuidUtils")
:new(nil, guiObject.customProfiler, server.fileUtils, server.logger, nil, nil,
server.utils, nil)
guiObject.guidUtils = guidUtils or server.guidUtils or error("Gui:new needs a GuidUtils instance!", 2)
end

if not guiObject.imGui then
Expand All @@ -782,18 +779,28 @@ function Gui:new(guiObject, server, client, customProfiler, guidUtils, minaUtils
if not guiObject.minaUtils then
---@type MinaUtils
---@see MinaUtils
guiObject.minaUtils = minaUtils or require("MinaUtils")
:new(nil, guiObject.customProfiler, server.noitaComponentUtils.globalsUtils, noitaMpSettings.logger,
server.networkVscUtils, noitaMpSettings, noitaMpSettings.utils)
guiObject.minaUtils = minaUtils or server.minaUtils or error("Gui:new needs a MinaUtils instance!", 2)
end

if not guiObject.networkVscUtils then
guiObject.networkVscUtils = server.networkVscUtils or error("Gui:new needs a NetworkVscUtils instance!", 2)
end

if not guiObject.utils then
---@type Utils
---@see Utils
guiObject.utils = noitaMpSettings.utils or require("Utils")
guiObject.utils = server.utils or error("Gui:new needs a Utils instance!", 2)
--:new()
end

if not guiObject.globalsUtils then
guiObject.globalsUtils = server.globalsUtils or error("Gui:new needs a GlobalsUtils instance!", 2)
end

if not guiObject.fileUtils then
guiObject.fileUtils = server.fileUtils or error("Gui:new needs a FileUtils instance!", 2)
end

--[[ Attributes ]]
guiObject.entityDetectionRadius = guiObject.noitaMpSettings:get("noita-mp.entity-detection-radius", "number")
guiObject.playerListIsBorder = guiObject.noitaMpSettings:get("noita-mp.gui.player-list.border", "boolean")
Expand Down
4 changes: 2 additions & 2 deletions mods/noita-mp/files/scripts/NoitaMpSettings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ end
function NoitaMpSettings:save()
local settingsFilePath = getSettingsFilePath(self)

if self.utils:isEmpty(self.cachedSettings["pid"]) then
self.cachedSettings["pid"] = self.winapi.get_current_pid()
if self.utils:isEmpty(self.cachedSettings["noita-mp.pid"]) then
self.cachedSettings["noita-mp.pid"] = self.winapi.get_current_pid()
end

self.fileUtils:WriteFile(settingsFilePath, self.json.encode(self.cachedSettings))
Expand Down
24 changes: 18 additions & 6 deletions mods/noita-mp/files/scripts/bin/profiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -437,15 +437,27 @@ local run = function()
--[[ Recieve data from Noita.exe-Client ]]
local dataString = udp:receive() --local data, msgOrIp, portOrNil = udp:receivefrom()
if dataString then
local frame = tonumber(dataString:split(", ")[1])
local customProfilerCounter = tonumber(dataString:split(", ")[2])
local frame = dataString:split(", ")[1]
local customProfilerCounter = dataString:split(", ")[2]
local startOrStop = dataString:split(", ")[3]
local time = tonumber(dataString:split(", ")[4])
local time = dataString:split(", ")[4]
local functionName = dataString:split(", ")[5]
local noitaMemoryUsage = tonumber(dataString:split(", ")[6])
local noitaMemoryUsage = dataString:split(", ")[6]


print(("%s %s %s %s %s %s"):format(frame, customProfilerCounter, startOrStop, time, functionName, noitaMemoryUsage))
print(("Frame %s cpc %s %s time %s %s memoryUsage %s"):format(
string.ExtendOrCutStringToLength(frame, 8, " ", true),
string.ExtendOrCutStringToLength(customProfilerCounter, 8, " ", true),
string.ExtendOrCutStringToLength(startOrStop, 5, " ", true),
string.ExtendOrCutStringToLength(time, 12, " ", true),
string.ExtendOrCutStringToLength(functionName, 50, " ", true),
string.ExtendOrCutStringToLength(noitaMemoryUsage, 15, " ", true))
)

frame = tonumber(frame)
customProfilerCounter = tonumber(customProfilerCounter) or error("customProfilerCounter is nil!", 2)
time = tonumber(time)
noitaMemoryUsage = tonumber(noitaMemoryUsage)

if not cache[functionName] then
cache[functionName] = {}
Expand Down Expand Up @@ -482,7 +494,7 @@ local run = function()
--report()
end

print(utils:pformat(cache))
--print(utils:pformat(cache))
end

--[[ Just some memory double checking! ]]
Expand Down
Loading

0 comments on commit f03ebb8

Please sign in to comment.