Fix client.packages hook sending normal packages
This commit is contained in:
@@ -35,44 +35,4 @@ if not CSActive then
|
|||||||
end
|
end
|
||||||
end
|
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)
|
|
||||||
elseif Game.IsMultiplayer then
|
|
||||||
local message = Networking.Start("_luastart")
|
|
||||||
|
|
||||||
local packageCount = 0
|
|
||||||
for package in ContentPackageManager.EnabledPackages.All do packageCount = packageCount + 1 end
|
|
||||||
|
|
||||||
message.WriteUInt16(packageCount)
|
|
||||||
|
|
||||||
for package in ContentPackageManager.EnabledPackages.All do
|
|
||||||
local id = package.UgcId
|
|
||||||
local hash = package.Hash and package.Hash.StringRepresentation or ""
|
|
||||||
|
|
||||||
if id == nil then id = 0 end
|
|
||||||
|
|
||||||
message.WriteString(package.Name)
|
|
||||||
message.WriteString(package.ModVersion)
|
|
||||||
message.WriteUInt64(UInt64(id))
|
|
||||||
message.WriteString(hash)
|
|
||||||
end
|
|
||||||
|
|
||||||
Networking.Send(message)
|
|
||||||
end
|
|
||||||
|
|
||||||
LuaSetup = nil
|
LuaSetup = nil
|
||||||
+55
-8
@@ -1,27 +1,19 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
using Barotrauma.LuaCs;
|
|
||||||
using Barotrauma.LuaCs.Compatibility;
|
using Barotrauma.LuaCs.Compatibility;
|
||||||
using Barotrauma.LuaCs.Data;
|
using Barotrauma.LuaCs.Data;
|
||||||
using Barotrauma.LuaCs.Events;
|
using Barotrauma.LuaCs.Events;
|
||||||
using Barotrauma.Networking;
|
using Barotrauma.Networking;
|
||||||
using FluentResults;
|
using FluentResults;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|
||||||
using Microsoft.Toolkit.Diagnostics;
|
using Microsoft.Toolkit.Diagnostics;
|
||||||
using MonoMod.RuntimeDetour;
|
|
||||||
using MoonSharp.Interpreter;
|
using MoonSharp.Interpreter;
|
||||||
using MoonSharp.Interpreter.Interop;
|
using MoonSharp.Interpreter.Interop;
|
||||||
using MoonSharp.Interpreter.Loaders;
|
|
||||||
using RestSharp.Validation;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -522,6 +514,61 @@ class LuaScriptManagementService : ILuaScriptManagementService, ILuaDataService,
|
|||||||
Table package = (Table)_script.Globals["package"];
|
Table package = (Table)_script.Globals["package"];
|
||||||
package.Set("path", DynValue.FromObject(_script, packages));
|
package.Set("path", DynValue.FromObject(_script, packages));
|
||||||
|
|
||||||
|
#if CLIENT
|
||||||
|
if (GameMain.NetworkMember is { IsClient: true })
|
||||||
|
{
|
||||||
|
var startMessage = _networkingService.Start("_luastart");
|
||||||
|
|
||||||
|
var packagesToReport = ContentPackageManager.EnabledPackages.All
|
||||||
|
.Where(p => _packageManagementService.Value.PackageContainsAnyRunnableResource(p))
|
||||||
|
.Where(p => !p.NameMatches(LuaCsSetup.PackageName))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
startMessage.WriteUInt16((UInt16)packagesToReport.Count());
|
||||||
|
|
||||||
|
foreach (var enabledPackage in packagesToReport)
|
||||||
|
{
|
||||||
|
var id = enabledPackage.UgcId;
|
||||||
|
string hash = enabledPackage.Hash.StringRepresentation ?? "";
|
||||||
|
|
||||||
|
startMessage.WriteString(enabledPackage.Name);
|
||||||
|
startMessage.WriteString(enabledPackage.ModVersion);
|
||||||
|
if (id.TryUnwrap(out ContentPackageId? packageId) && packageId is SteamWorkshopId steamId)
|
||||||
|
{
|
||||||
|
startMessage.WriteUInt64(steamId.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startMessage.WriteUInt64(0);
|
||||||
|
}
|
||||||
|
startMessage.WriteString(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
_networkingService.Send(startMessage);
|
||||||
|
}
|
||||||
|
#elif SERVER
|
||||||
|
_networkingService.Receive("_luastart", (message, client) =>
|
||||||
|
{
|
||||||
|
var num = message.ReadUInt16();
|
||||||
|
List<Table> packages = new List<Table>();
|
||||||
|
|
||||||
|
for (int i = 0; i < num; i++)
|
||||||
|
{
|
||||||
|
Table table = new Table(_script);
|
||||||
|
|
||||||
|
table.Set("Name", DynValue.NewString(message.ReadString()));
|
||||||
|
table.Set("Version", DynValue.NewString(message.ReadString()));
|
||||||
|
table.Set("Id", DynValue.NewString(message.ReadUInt64().ToString()));
|
||||||
|
table.Set("Hash", DynValue.NewString(message.ReadString()));
|
||||||
|
|
||||||
|
packages.Add(table);
|
||||||
|
}
|
||||||
|
|
||||||
|
_eventService.Call("client.packages", client, packages);
|
||||||
|
});
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
foreach (ILuaScriptResourceInfo resource in executionOrder.Where(l => l.IsAutorun))
|
foreach (ILuaScriptResourceInfo resource in executionOrder.Where(l => l.IsAutorun))
|
||||||
{
|
{
|
||||||
foreach (ContentPath filePath in resource.FilePaths)
|
foreach (ContentPath filePath in resource.FilePaths)
|
||||||
|
|||||||
@@ -525,4 +525,34 @@ public sealed class PackageManagementService : IPackageManagementService
|
|||||||
.Where(cfg => !cfg.Assemblies.IsDefaultOrEmpty || cfg.LuaScripts.Any(scr => scr.RunUnrestricted))
|
.Where(cfg => !cfg.Assemblies.IsDefaultOrEmpty || cfg.LuaScripts.Any(scr => scr.RunUnrestricted))
|
||||||
.Select(cfg => cfg.Package)];
|
.Select(cfg => cfg.Package)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool PackageContainsAnyRunnableResource(ContentPackage package)
|
||||||
|
{
|
||||||
|
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
|
IService.CheckDisposed(this);
|
||||||
|
|
||||||
|
var result = GetModConfigForPackage(package);
|
||||||
|
|
||||||
|
if (result.IsSuccess)
|
||||||
|
{
|
||||||
|
return result.Value.Assemblies.Any() || result.Value.LuaScripts.Any();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result<IModConfigInfo> GetModConfigForPackage(ContentPackage package)
|
||||||
|
{
|
||||||
|
using var lck = _operationsLock.AcquireReaderLock().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||||
|
IService.CheckDisposed(this);
|
||||||
|
|
||||||
|
if (!_loadedPackages.TryGetValue(package, out var modConfig))
|
||||||
|
{
|
||||||
|
return FluentResults.Result.Fail($"Failed to find mod config for package {package.Name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new FluentResults.Result<IModConfigInfo>().WithValue(modConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
@@ -26,4 +26,6 @@ public interface IPackageManagementService : IReusableService
|
|||||||
public bool IsPackageRunning(ContentPackage package);
|
public bool IsPackageRunning(ContentPackage package);
|
||||||
public bool IsAnyPackageLoaded();
|
public bool IsAnyPackageLoaded();
|
||||||
public bool IsAnyPackageRunning();
|
public bool IsAnyPackageRunning();
|
||||||
|
public bool PackageContainsAnyRunnableResource(ContentPackage package);
|
||||||
|
public Result<IModConfigInfo> GetModConfigForPackage(ContentPackage package);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user