Added Md5Hash and made FIFO queue less cursed

Starting to run out of food.
This commit is contained in:
EvilFactory
2022-11-06 17:49:17 -03:00
parent f7b046e950
commit 217f7b63a2
3 changed files with 62 additions and 16 deletions

View File

@@ -106,6 +106,7 @@ defaultLib["AutoItemPlacer"] = CreateStatic("Barotrauma.AutoItemPlacer")
defaultLib["PropertyConditional"] = CreateStatic("Barotrauma.PropertyConditional", true)
defaultLib["StatusEffect"] = CreateStatic("Barotrauma.StatusEffect", true)
defaultLib["Md5Hash"] = CreateStatic("Barotrauma.Md5Hash", true)
defaultLib["ContentXElement"] = CreateStatic("Barotrauma.ContentXElement", true)
defaultLib["ContentPath"] = CreateStatic("Barotrauma.ContentPath", true)
defaultLib["XElement"] = CreateStatic("System.Xml.Linq.XElement", true)

View File

@@ -160,6 +160,7 @@ RegisterBarotrauma("ContentXElement")
RegisterBarotrauma("ContentPath")
RegisterBarotrauma("ContentPackageId")
RegisterBarotrauma("SteamWorkshopId")
RegisterBarotrauma("Md5Hash")
RegisterBarotrauma("SoundsFile")

View File

@@ -56,25 +56,27 @@ local function AssertTypes(expectedTypes, ...)
end
local function ExecutionQueue()
local queue = {}
local function processQueueFIFO()
while queue[1] ~= nil do
local folder, rootFolder, package = table.unpack(table.remove(queue, 1))
local executionQueue = {}
executionQueue.Queue = {}
executionQueue.Process = function()
while executionQueue.Queue[1] ~= nil do
local folder, rootFolder, package = table.unpack(table.remove(executionQueue.Queue, 1))
print(string.format("%s %s", package.Name, package.ModVersion))
RunFolder(folder, rootFolder, package)
end
end
local function queueExecutionFIFO(...)
executionQueue.Add = function(...)
AssertTypes({ 'string', 'string', 'userdata' }, ...)
table.insert(queue, table.pack(...))
table.insert(executionQueue.Queue, table.pack(...))
end
return queueExecutionFIFO, processQueueFIFO
return executionQueue
end
local QueueAutorun, ProcessAutorun = ExecutionQueue()
local QueueForcedAutorun, ProcessForcedAutorun = ExecutionQueue()
local QueueAutorun = ExecutionQueue()
local QueueForcedAutorun = ExecutionQueue()
local function ProcessPackages(packages, fn)
for pkg in packages do
@@ -93,7 +95,7 @@ ProcessPackages(
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
local autorunPath = pkgPath .. LUA_MOD_AUTORUN_PATH
if File.DirectoryExists(autorunPath) then
QueueAutorun(autorunPath, pkgPath, pkg)
QueueAutorun.Add(autorunPath, pkgPath, pkg)
end
end
)
@@ -107,7 +109,7 @@ ProcessPackages(
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
if File.DirectoryExists(forcedAutorunPath) then
QueueForcedAutorun(forcedAutorunPath, pkgPath, pkg)
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
executedLocalPackages[pkg.Name] = true
end
end
@@ -120,7 +122,7 @@ ProcessPackages(
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
if File.DirectoryExists(forcedAutorunPath) then
QueueForcedAutorun(forcedAutorunPath, pkgPath, pkg)
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
executedLocalPackages[pkg.Name] = true
end
end
@@ -134,7 +136,7 @@ ProcessPackages(
table.insert(package.path, pkgPath .. LUA_MOD_REQUIRE_PATH)
local forcedAutorunPath = pkgPath .. LUA_MOD_FORCEDAUTORUN_PATH
if File.DirectoryExists(forcedAutorunPath) then
QueueForcedAutorun(forcedAutorunPath, pkgPath, pkg)
QueueForcedAutorun.Add(forcedAutorunPath, pkgPath, pkg)
end
end
end
@@ -142,11 +144,53 @@ ProcessPackages(
setmodulepaths(package.path)
setmodulepaths = nil
ProcessAutorun()
ProcessForcedAutorun()
local allExecuted = {}
for key, value in pairs(QueueAutorun.Queue) do table.insert(allExecuted, value[3]) end
for key, value in pairs(QueueForcedAutorun.Queue) do table.insert(allExecuted, value[3]) end
if SERVER then
Networking.Receive("_luastart", function (message, client)
local num = message.ReadUInt16()
local packages = {}
for i = 1, num, 1 do
table.insert(packages, {
Name = message.ReadString(),
Version = message.ReadString(),
Id = message.ReadUInt64(),
Hash = message.ReadString()
})
end
Hook.Call("client.packages", client, packages)
end)
else
local message = Networking.Start("_luastart")
message.WriteUInt16(#allExecuted)
for key, package in pairs(allExecuted) do
local id = package.UgcId
local hash = package.Hash and package.Hash.StringRepresentation or ""
if id == none then id = 0 end
message.WriteString(package.Name)
message.WriteString(package.ModVersion)
message.WriteUInt64(UInt64(id))
message.WriteString(hash)
end
Networking.Send(message)
end
QueueAutorun.Process()
QueueForcedAutorun.Process()
Hook.Add("stop", "luaSetup.stop", function()
print("Stopping Lua...")
end)
Hook.Call("loaded")
Hook.Call("loaded")