From f03ebb887a6cffcc2fd62e2af1aec020a8fb3986 Mon Sep 17 00:00:00 2001 From: Ismoh <12631485+Ismoh@users.noreply.github.com> Date: Mon, 9 Oct 2023 00:29:17 +0200 Subject: [PATCH] Trying to get `local-lua-debugger` running --- .vscode/launch.json | 60 ++++--------- .vscode/settings.json | 1 + mods/noita-mp/files/scripts/Gui.lua | 45 ++++++---- .../files/scripts/NoitaMpSettings.lua | 4 +- mods/noita-mp/files/scripts/bin/profiler.lua | 24 +++-- mods/noita-mp/files/scripts/net/Client.lua | 88 +++++++++++-------- .../scripts/noita-components/nuid_debug.lua | 1 - mods/noita-mp/files/scripts/util/Utils.lua | 2 +- mods/noita-mp/init.lua | 19 +++- 9 files changed, 128 insertions(+), 116 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1b0846bd2..760b55423 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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 } ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 13c720d85..bcf4732cc 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -76,4 +76,5 @@ ], "prettier.printWidth": 110, "lua.debug.settings.luaVersion": "jit", + "lua-local.interpreter": "LuaJIT", } diff --git a/mods/noita-mp/files/scripts/Gui.lua b/mods/noita-mp/files/scripts/Gui.lua index 1c8187b0d..3802af583 100644 --- a/mods/noita-mp/files/scripts/Gui.lua +++ b/mods/noita-mp/files/scripts/Gui.lua @@ -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) @@ -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 @@ -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 @@ -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() @@ -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() @@ -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 @@ -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 @@ -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") diff --git a/mods/noita-mp/files/scripts/NoitaMpSettings.lua b/mods/noita-mp/files/scripts/NoitaMpSettings.lua index ff46f1a65..9b54d6540 100644 --- a/mods/noita-mp/files/scripts/NoitaMpSettings.lua +++ b/mods/noita-mp/files/scripts/NoitaMpSettings.lua @@ -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)) diff --git a/mods/noita-mp/files/scripts/bin/profiler.lua b/mods/noita-mp/files/scripts/bin/profiler.lua index 0e3f214cb..7c3c77864 100644 --- a/mods/noita-mp/files/scripts/bin/profiler.lua +++ b/mods/noita-mp/files/scripts/bin/profiler.lua @@ -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] = {} @@ -482,7 +494,7 @@ local run = function() --report() end - print(utils:pformat(cache)) + --print(utils:pformat(cache)) end --[[ Just some memory double checking! ]] diff --git a/mods/noita-mp/files/scripts/net/Client.lua b/mods/noita-mp/files/scripts/net/Client.lua index f0963693b..939c2fada 100644 --- a/mods/noita-mp/files/scripts/net/Client.lua +++ b/mods/noita-mp/files/scripts/net/Client.lua @@ -31,7 +31,7 @@ end ---@param data table data = { "networkMessageId", "event", "status", "ackedAt" } local onAcknowledgement = function(self, data) local cpc = self.customProfiler:start("Client.onAcknowledgement") - self.logger:debug(self.logger.channels.network, "onAcknowledgement: Acknowledgement received.", self.utils:pformat(data)) + self.logger:debug(self.logger.channels.network, ("onAcknowledgement: Acknowledgement received. %s"):format(self.utils:pformat(data))) if self.utils:isEmpty(data.networkMessageId) then error(("onAcknowledgement data.networkMessageId is empty: %s"):format(data.networkMessageId), 2) @@ -55,21 +55,21 @@ local onAcknowledgement = function(self, data) end if not self.clientCacheId then - self.clientCacheId = self.guidUtils.toNumber(self.guid) + self.clientCacheId = self.guidUtils:toNumber(self.guid) end - local cachedData = self.networkCacheUtils.get(self.guid, data.networkMessageId, data.event) + local cachedData = self.networkCacheUtils:get(self.guid, data.networkMessageId, data.event) if self.utils:isEmpty(cachedData) then - self.networkCacheUtils.logAll() + self.networkCacheUtils:logAll() error(("Unable to get cached data, because it is nil '%s'"):format(cachedData), 2) end if self.utils:isEmpty(cachedData.dataChecksum) or type(cachedData.dataChecksum) ~= "string" then - self.networkCacheUtils.logAll() + self.networkCacheUtils:logAll() error(("Unable to get cachedData.dataChecksum, because it is nil '%s' or checksum is not of type string, type: %s") :format(cachedData.dataChecksum, type(cachedData.dataChecksum)), 2) end -- update previous cached network message - self.networkCacheUtils.ack(self.guid, data.networkMessageId, data.event, + self.networkCacheUtils:ack(self.guid, data.networkMessageId, data.event, data.status, os.clock(), cachedData.sendAt, cachedData.dataChecksum) if self.networkCache.size() > self.acknowledgeMaxSize then @@ -134,19 +134,19 @@ end ---@param data number data(.code) = 0 local onDisconnect = function(self, data) local cpc = self.customProfiler:start("Client.onDisconnect") - self.logger.debug(self.logger.channels.network, "Disconnected from server!", self.utils:pformat(data)) + self.logger:debug(self.logger.channels.network, "Disconnected from server!", self.utils:pformat(data)) if self.utils:isEmpty(data) then error(("onDisconnect data is empty: %s"):format(data), 3) end if self.serverInfo.nuid then - self.entityUtils.destroyByNuid(self, self.serverInfo.nuid) + self.entityUtils:destroyByNuid(self, self.serverInfo.nuid) end -- TODO remove all NUIDS from entities. I now need a nuid-entityId-cache. - local nuid, entityId = self.globalsUtils.getNuidEntityPair(self.nuid) - self.networkVscUtils.addOrUpdateAllVscs(entityId, self.name, self.guid, nil) + local nuid, entityId = self.globalsUtils:getNuidEntityPair(self.nuid) + self.networkVscUtils:addOrUpdateAllVscs(entityId, self.name, self.guid, nil) self.nuid = nil self.otherClients = {} @@ -163,7 +163,7 @@ end ---@param data table data { "name", "guid" } @see self.networkUtils.events.disconnect2.schema local onDisconnect2 = function(self, data) local cpc = self.customProfiler:start("Client.onDisconnect2") - self.logger.debug(self.logger.channels.network, "onDisconnect2: Another client disconnected.", self.utils:pformat(data)) + self.logger:debug(self.logger.channels.network, "onDisconnect2: Another client disconnected.", self.utils:pformat(data)) if self.utils:isEmpty(data.networkMessageId) then error(("onDisconnect2 data.networkMessageId is empty: %s"):format(data.networkMessageId), 3) @@ -196,7 +196,7 @@ end ---@param data table data @see self.networkUtils.events.minaInformation.schema local onMinaInformation = function(self, data) local cpc = self.customProfiler:start("Client.onMinaInformation") - self.logger.debug(self.logger.channels.network, "onMinaInformation: Player info received.", self.utils:pformat(data)) + self.logger:debug(self.logger.channels.network, "onMinaInformation: Player info received.", self.utils:pformat(data)) if self.utils:isEmpty(data.networkMessageId) then error(("onMinaInformation data.networkMessageId is empty: %s"):format(data.networkMessageId), 2) @@ -232,13 +232,13 @@ local onMinaInformation = function(self, data) if data.guid == self.guid then - self.logger.warn(self.logger.channels.network, + self.logger:warn(self.logger.channels.network, ("onMinaInformation: Clients GUID %s isn't unique! Server will fix this!"):format(self.guid)) end - if FileUtils.GetVersionByFile() ~= tostring(data.version) then + if self.fileUtils:GetVersionByFile() ~= tostring(data.version) then error(("Version mismatch: NoitaMP version of Server: %s and your version: %s") - :format(data.version, FileUtils.GetVersionByFile()), 3) + :format(data.version, self.fileUtils:GetVersionByFile()), 3) self.disconnect() end @@ -262,7 +262,7 @@ end ---@param data table data { "networkMessageId", "oldGuid", "newGuid" } local onNewGuid = function(self, data) local cpc = self.customProfiler:start("Client.onNewGuid") - self.logger.debug(self.logger.channels.network, ("onNewGuid: New GUID from server received."):format(self.utils:pformat(data))) + self.logger:debug(self.logger.channels.network, ("onNewGuid: New GUID from server received."):format(self.utils:pformat(data))) if self.utils:isEmpty(data.networkMessageId) then error(("onNewGuid data.networkMessageId is empty: %s"):format(data.networkMessageId), 2) @@ -302,7 +302,7 @@ end ---@param data table data { networkMessageId, seed } local onSeed = function(self, data) local cpc = self.customProfiler:start("Client.onSeed") - self.logger.debug(self.logger.channels.network, "onSeed: Seed from server received.", self.utils:pformat(data)) + self.logger:debug(self.logger.channels.network, "onSeed: Seed from server received.", self.utils:pformat(data)) if self.utils:isEmpty(data.networkMessageId) then error(("onSeed data.networkMessageId is empty: %s"):format(data.networkMessageId), 3) @@ -313,7 +313,7 @@ local onSeed = function(self, data) end local serversSeed = tonumber(data.seed) - self.logger.info(self.logger.channels.network, + self.logger:info(self.logger.channels.network, ("Client received servers seed (%s) and stored it. Reloading map with that seed!") :format(serversSeed)) @@ -345,7 +345,7 @@ end -- ---@param data table data { networkMessageId, owner { name, guid }, localEntityId, newNuid, x, y, rotation, velocity { x, y }, filename } -- local onNewNuid = function(self, data) -- local cpc = self.customProfiler:start("Client.onNewNuid") --- self.logger.debug(self.logger.channels.network, ("Received a new nuid! data = %s"):format(self.utils:pformat(data))) +-- self.logger:debug(self.logger.channels.network, ("Received a new nuid! data = %s"):format(self.utils:pformat(data))) -- if self.utils:isEmpty(data.networkMessageId) then -- error(("onNewNuid data.networkMessageId is empty: %s"):format(data.networkMessageId), 3) @@ -420,7 +420,7 @@ end ---@param data table data { networkMessageId, ownerName, ownerGuid, entityId, serializedEntityString, nuid, x, y, initialSerializedEntityString } local onNewNuid = function(self, data) local cpc = self.customProfiler:start("Client.onNewNuid") - self.logger.debug(self.logger.channels.network, + self.logger:debug(self.logger.channels.network, ("Received a new nuid onNewNuid! data = %s"):format(self.utils:pformat(data))) if self.utils:isEmpty(data.networkMessageId) then @@ -518,7 +518,7 @@ end ---@param data table data { networkMessageId, owner { name, guid }, localEntityId, nuid, x, y, rotation, velocity { x, y }, health } local onEntityData = function(self, data) local cpc = self.customProfiler:start("Client.onEntityData") - self.logger.debug(self.logger.channels.network, ("Received entityData for nuid = %s! data = %s") + self.logger:debug(self.logger.channels.network, ("Received entityData for nuid = %s! data = %s") :format(data.nuid, self.utils:pformat(data))) if self.utils:isEmpty(data.networkMessageId) then @@ -569,7 +569,7 @@ local onEntityData = function(self, data) if self.nuid ~= nuid then self.noitaComponentUtils.setEntityData(localEntityId, x, y, rotation, velocity, health) else - self.logger.warn(self.logger.channels.network, ("Received entityData for self.nuid = %s! data = %s") + self.logger:warn(self.logger.channels.network, ("Received entityData for self.nuid = %s! data = %s") :format(data.nuid, self.utils:pformat(data))) end @@ -629,7 +629,7 @@ local onNeedModList = function(self, data) -- Display a prompt if mod conflicts are detected if #conflicts > 0 then self.missingMods = conflicts - self.logger.info("Mod conflicts detected: Missing " .. table.concat(conflicts, ", ")) + self.logger:info("Mod conflicts detected: Missing " .. table.concat(conflicts, ", ")) end self.customProfiler:stop("Client.onNeedModList", cpc) end @@ -644,19 +644,19 @@ local onNeedModContent = function(self, data) local modID = v.workshopID local modData = v.data if modID == "0" then - if not FileUtils.IsDirectory((FileUtils.GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) then + if not self.fileUtils:IsDirectory((self.fileUtils:GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) then local fileName = ("%s_%s_mod_sync.7z"):format(tostring(os.date("!")), modName) - FileUtils.WriteBinaryFile(FileUtils.GetAbsoluteDirectoryPathOfNoitaMP() .. "/" .. fileName, modData) - FileUtils.Extract7zipArchive(FileUtils.GetAbsoluteDirectoryPathOfNoitaMP(), fileName, - (FileUtils.GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) + self.fileUtils:WriteBinaryFile(self.fileUtils:GetAbsoluteDirectoryPathOfNoitaMP() .. "/" .. fileName, modData) + self.fileUtils:Extract7zipArchive(self.fileUtils:GetAbsoluteDirectoryPathOfNoitaMP(), fileName, + (self.fileUtils:GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) end else - if not FileUtils.IsDirectory(("C:/Program Files (x86)/Steam/steamapps/workshop/content/881100/%s/"):format(modID)) then - if not FileUtils.IsDirectory((FileUtils.GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) then + if not self.fileUtils:IsDirectory(("C:/Program Files (x86)/Steam/steamapps/workshop/content/881100/%s/"):format(modID)) then + if not self.fileUtils:IsDirectory((self.fileUtils:GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) then local fileName = ("%s_%s_mod_sync.7z"):format(tostring(os.date("!")), modName) - FileUtils.WriteBinaryFile(FileUtils.GetAbsoluteDirectoryPathOfNoitaMP() .. "/" .. fileName, modData) - FileUtils.Extract7zipArchive(FileUtils.GetAbsoluteDirectoryPathOfNoitaMP(), fileName, - (FileUtils.GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) + self.fileUtils:WriteBinaryFile(self.fileUtils:GetAbsoluteDirectoryPathOfNoitaMP() .. "/" .. fileName, modData) + self.fileUtils:Extract7zipArchive(self.fileUtils:GetAbsoluteDirectoryPathOfNoitaMP(), fileName, + (self.fileUtils:GetAbsolutePathOfNoitaRootDirectory() .. "/mods/%s/"):format(modName)) end end end @@ -765,7 +765,7 @@ function Client:disconnect() -- Inheritance: https://ozzypig.com/2018/05/10/object-oriented-programming-in-lua-part-5-inheritance self.sock.disconnect(self) --sockClientDisconnect(self) else - self.logger.info(self.logger.channels.network, "Client isn't connected, no need to disconnect!") + self.logger:info(self.logger.channels.network, "Client isn't connected, no need to disconnect!") end self.customProfiler:stop("Client.disconnect", cpc) end @@ -821,7 +821,7 @@ function Client:send(event, data) end if self.networkUtils.alreadySent(self, event, data) then - self.logger.debug(self.logger.channels.network, ("Network message for %s for data %s already was acknowledged.") + self.logger:debug(self.logger.channels.network, ("Network message for %s for data %s already was acknowledged.") :format(event, self.utils:pformat(data))) self.customProfiler:stop("Client.send", cpc) return false @@ -903,8 +903,8 @@ function Client:sendEntityData(entityId) if self.utils:isEmpty(compNuid) then -- this can happen, when entity spawned on client and network is slow - self.logger.debug(self.logger.channels.network, "Unable to send entity data, because nuid is empty.") - self.sendNeedNuid(compOwnerName, compOwnerGuid, entityId) + self.logger:debug(self.logger.channels.network, "Unable to send entity data, because nuid is empty.") + self:sendNeedNuid(compOwnerName, compOwnerGuid, entityId) return end @@ -923,7 +923,7 @@ function Client:sendDeadNuids(deadNuids) self.networkUtils.getNextNetworkMessageId(), deadNuids } local sent = self:send(self.networkUtils.events.deadNuids.name, data) - onDeadNuids(deadNuids) + onDeadNuids(self, deadNuids) self.customProfiler:stop("Client.sendDeadNuids", cpc) return sent end @@ -940,7 +940,7 @@ function Client:sendMinaInformation() local transform = minaInfo.transform local health = minaInfo.health local data = { - self.networkUtils.getNextNetworkMessageId(), FileUtils.GetVersionByFile(), name, guid, entityId, nuid, transform, health + self.networkUtils.getNextNetworkMessageId(), self.fileUtils:GetVersionByFile(), name, guid, entityId, nuid, transform, health } local sent = self:send(self.networkUtils.events.minaInformation.name, data) self.customProfiler:stop("Client.sendMinaInformation", cpc) @@ -1041,6 +1041,18 @@ function Client:new(clientObject, serverOrAddress, port, maxChannels, server, np clientObject.noitaComponentUtils = server.noitaComponentUtils or error("Client:new requires a server object!", 2) end + if not clientObject.fileUtils then + clientObject.fileUtils = server.fileUtils or error("Client:new requires a server object!", 2) + end + + if not clientObject.globalsUtils then + clientObject.globalsUtils = server.globalsUtils or error("Client:new requires a server object!", 2) + end + + if not clientObject.networkVscUtils then + clientObject.networkVscUtils = server.networkVscUtils or error("Client:new requires a server object!", 2) + end + --[[ Attributes ]] clientObject.acknowledgeMaxSize = 500 diff --git a/mods/noita-mp/files/scripts/noita-components/nuid_debug.lua b/mods/noita-mp/files/scripts/noita-components/nuid_debug.lua index 802e5ce75..368ed25a5 100644 --- a/mods/noita-mp/files/scripts/noita-components/nuid_debug.lua +++ b/mods/noita-mp/files/scripts/noita-components/nuid_debug.lua @@ -62,7 +62,6 @@ if ModSettingGet("noita-mp.toggle_debug") then y = y } - table.setNoitaMpDefaultMetaMethods(data, "kv") local i = 0 for name, value in pairs(data) do diff --git a/mods/noita-mp/files/scripts/util/Utils.lua b/mods/noita-mp/files/scripts/util/Utils.lua index 8db857f93..06e1a23c5 100644 --- a/mods/noita-mp/files/scripts/util/Utils.lua +++ b/mods/noita-mp/files/scripts/util/Utils.lua @@ -37,7 +37,7 @@ function Utils:sleep(s) end ---Checks if a variable is empty. ----@param var number|string|table variable to check +---@param var number|string|table|nil variable to check ---@return boolean true if empty, false otherwise function Utils:isEmpty(var) -- if you change this also change NetworkVscUtils.lua diff --git a/mods/noita-mp/init.lua b/mods/noita-mp/init.lua index 08476067a..1ab00de74 100644 --- a/mods/noita-mp/init.lua +++ b/mods/noita-mp/init.lua @@ -9,6 +9,19 @@ dofile("mods/noita-mp/files/scripts/init/init_.lua") -- Need to be initialized before everything else, otherwise Noita will crash local np = require("noitapatcher") +-- Check if we wan't to debug the mod +--if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then + local args = table.pack(...) + for i = 1, args.n do + local found = string.find(args[i], "debug_lua", 1, true) + if found then + local lldebugger = loadfile(os.getenv("LOCAL_LUA_DEBUGGER_FILEPATH"))() + lldebugger.start() + break + end + end +--end + -- Initialize default server local server = require("Server") :new(nil, nil, nil, nil, nil, nil, nil, np) @@ -260,14 +273,12 @@ function OnWorldPreUpdate() client:update(startFrameTime) local cpc1 = customProfiler:start("init.OnWorldPreUpdate.collectgarbage.count") - if collectgarbage("count") >= 250000 then + if collectgarbage("count") >= 16414586.467743 then local cpc2 = customProfiler:start("init.OnWorldPreUpdate.collectgarbage.collect") - -- if memory usage is above 250MB, force a garbage collection - GamePrintImportant("Memory Usage", "Forcing garbage collection because memory usage is above 250MB.") + GamePrintImportant("Memory Usage", ("Forcing garbage collection because memory usage is above %sMB."):format(collectgarbage("count") / 1024)) collectgarbage("collect") customProfiler:stop("init.OnWorldPreUpdate.collectgarbage.collect", cpc2) end - customProfiler:stop("init.OnWorldPreUpdate.collectgarbage.count", cpc1) customProfiler:stop("init.OnWorldPreUpdate", cpc)