bunch of fixes that include fixing lua networking, script loading and client side lua installation

This commit is contained in:
Evil Factory
2022-04-09 21:44:18 -03:00
parent 454a0a22d1
commit dc7a7bd74d
7 changed files with 92 additions and 28 deletions
+57 -16
View File
@@ -23,46 +23,87 @@ require("DefaultHook")
-- Execute Mods
local allPackages = ContentPackageManager.AllPackages
local localPackages = ContentPackageManager.LocalPackages
local enabledPackages = ContentPackageManager.EnabledPackages.All
local function endsWith(str, suffix)
return str:sub(-string.len(suffix)) == suffix
end
local function executeProtected(s)
print(s)
dofile(s)
local function getFileName(file)
return file:match("^.+/(.+)$")
end
local function runFolder(folder)
local function getPath(str)
local sep = "/"
return str:match("(.*"..sep..")")
end
local function executeProtected(s, folder)
loadfile(s)(folder)
end
local function runFolder(folder, rootFolder, package)
local search = File.DirSearch(folder)
for i = 1, #search, 1 do
local s = search[i]:gsub("\\", "/")
if endsWith(s, ".lua") then
executeProtected(s)
executeProtected(s, rootFolder)
print(string.format("%s: Executing %s", package.Name, getFileName(s)))
end
end
end
if SERVER then
for package in enabledPackages do
if package then
local d = package.Path:gsub("\\", "/")
d = d:gsub("/filelist.xml", "")
table.insert(modulePaths, (d .. "/Lua/?.lua"))
for package in enabledPackages do
if package then
local d = package.Path:gsub("\\", "/")
d = d:gsub("/filelist.xml", "")
if File.DirectoryExists(d .. "/Lua/Autorun") then
runFolder(d .. "/Lua/Autorun")
end
table.insert(modulePaths, (d .. "/Lua/?.lua"))
if File.DirectoryExists(d .. "/Lua/Autorun") then
runFolder(d .. "/Lua/Autorun", d, package)
end
end
end
-- we don't want to execute workshop ForcedAutorun if we have a local Package
local executedLocalPackages = {}
for package in localPackages do
if package then
local d = package.Path:gsub("\\", "/")
d = d:gsub("/filelist.xml", "")
table.insert(modulePaths, (d .. "/Lua/?.lua"))
if File.DirectoryExists(d .. "/Lua/ForcedAutorun") then
runFolder(d .. "/Lua/ForcedAutorun", d, package)
executedLocalPackages[package.Name] = true
end
end
end
for package in allPackages do
if package and executedLocalPackages[package.Name] == nil then
local d = package.Path:gsub("\\", "/")
d = d:gsub("/filelist.xml", "")
table.insert(modulePaths, (d .. "/Lua/?.lua"))
if File.DirectoryExists(d .. "/Lua/ForcedAutorun") then
runFolder(d .. "/Lua/ForcedAutorun", d, package)
end
end
end
setmodulepaths(modulePaths)
Hook.Add("stop", "luaSetup.stop", function ()