From 6da4481c8327b3513b2d094d6806441a16ba6a09 Mon Sep 17 00:00:00 2001 From: Evil Factory <36804725+evilfactory@users.noreply.github.com> Date: Sun, 17 Apr 2022 13:03:24 -0300 Subject: [PATCH 1/2] fix names --- .../BarotraumaServer/ServerSource/DebugConsole.cs | 10 +++++----- .../BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs index 86be7a28f..4bcc8f624 100644 --- a/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/ServerSource/DebugConsole.cs @@ -1253,17 +1253,17 @@ namespace Barotrauma commands.Add(new Command("install_cl_lua", "Installs client-Side Lua into your client.", (string[] args) => { - ContentPackage luaPackage = LuaCsSetup.GetPackage(); + ContentPackage luaCsPackage = LuaCsSetup.GetPackage(); - if (luaPackage == null) + if (luaCsPackage == null) { - GameMain.Server.SendChatMessage("Couldn't find the LuaForBarotrauma package.", ChatMessageType.ServerMessageBox); + GameMain.Server.SendChatMessage("Couldn't find the LuaCsForBarotrauma package.", ChatMessageType.ServerMessageBox); return; } try { - string path = Path.GetDirectoryName(luaPackage.Path); + string path = Path.GetDirectoryName(luaCsPackage.Path); string[] filesToCopy = new string[] { @@ -1293,7 +1293,7 @@ namespace Barotrauma File.Copy(Path.Combine(path, "Binary", file), file, true); } - File.WriteAllText(LuaCsSetup.VERSION_FILE, luaPackage.ModVersion); + File.WriteAllText(LuaCsSetup.VERSION_FILE, luaCsPackage.ModVersion); } catch (UnauthorizedAccessException e) { diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs index 83fd7b6da..00e2057d2 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsSetup.cs @@ -43,7 +43,7 @@ namespace Barotrauma { foreach (ContentPackage package in ContentPackageManager.LocalPackages) { - if (package.NameMatches(new Identifier("LuaForBarotraumaUnstable"))) + if (package.NameMatches(new Identifier("LuaCsForBarotraumaUnstable"))) { return package; } @@ -51,7 +51,7 @@ namespace Barotrauma foreach (ContentPackage package in ContentPackageManager.AllPackages) { - if (package.NameMatches(new Identifier("LuaForBarotraumaUnstable"))) + if (package.NameMatches(new Identifier("LuaCsForBarotraumaUnstable"))) { return package; } @@ -373,7 +373,7 @@ namespace Barotrauma } - ContentPackage luaPackage = GetPackage(); + ContentPackage luaCsPackage = GetPackage(); if (File.Exists(LUASETUP_FILE)) { @@ -386,9 +386,9 @@ namespace Barotrauma HandleException(e); } } - else if (luaPackage != null) + else if (luaCsPackage != null) { - string path = Path.GetDirectoryName(luaPackage.Path); + string path = Path.GetDirectoryName(luaCsPackage.Path); try { From 22f82c7cb2f2f0fb157703a9ab477b71c156a31b Mon Sep 17 00:00:00 2001 From: Oiltanker Date: Sun, 17 Apr 2022 19:55:45 +0300 Subject: [PATCH 2/2] fix cs filter metadata bug --- .../SharedSource/LuaCs/Cs/CsScriptFilter.cs | 21 +++++++++++-------- .../SharedSource/LuaCs/LuaCsHook.cs | 13 ++++++++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptFilter.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptFilter.cs index f06e48083..895d4319d 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptFilter.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/Cs/CsScriptFilter.cs @@ -11,15 +11,7 @@ namespace Barotrauma { { private static readonly string[] typesPermitted = new string[] { // Basics - "System.Runtime.CompilerServices.CompilationRelaxationsAttribute", - "System.Runtime.CompilerServices.RuntimeCompatibilityAttribute", - "System.Diagnostics.DebuggableAttribute", - "System.Object", - "System.String", - "System.Collections", "System", - // Some roslyn magic - ".DebuggingModes", // Barotrauma "Barotrauma", // Lua @@ -76,7 +68,18 @@ namespace Barotrauma { reader.TypeReferences.ToList().ForEach(t => { var tRef = reader.GetTypeReference(t); - var typeName = $"{reader.GetString(tRef.Namespace)}.{reader.GetString(tRef.Name)}"; + + var typeName = $"{reader.GetString(tRef.Name)}"; + EntityHandle handle = tRef.ResolutionScope; + TypeReference tr = tRef; + while (!handle.IsNil && handle.Kind == HandleKind.TypeReference) + { + tr = reader.GetTypeReference((TypeReferenceHandle)handle); + handle = tr.ResolutionScope; + typeName = $"{reader.GetString(tr.Name)}.{typeName}"; + } + typeName = $"{reader.GetString(tr.Namespace)}.{typeName}"; + if (!IsTypeAllowed(typeName)) conflictingTypes.Add(typeName); }); diff --git a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs index ecaad266b..60059b925 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/LuaCs/LuaCsHook.cs @@ -6,6 +6,7 @@ using HarmonyLib; using System.Collections.Generic; using System.Text; using MoonSharp.Interpreter.Interop; +using static Barotrauma.LuaCsSetup; namespace Barotrauma { @@ -221,8 +222,16 @@ namespace Barotrauma }; public void HookMethod(string identifier, MethodInfo method, LuaCsPatch patch, HookMethodType hookType = HookMethodType.Before, ACsMod owner = null) { - if (identifier == null || method == null || patch == null) throw new ArgumentNullException("Identifier, Method and Patch arguments must not be null."); - if (prohibitedHooks.Any(h => method.DeclaringType.FullName.StartsWith(h))) throw new ArgumentException("Hooks into Modding Environment are prohibited."); + if (identifier == null || method == null || patch == null) + { + GameMain.LuaCs.HandleException(new ArgumentNullException("Identifier, Method and Patch arguments must not be null."), exceptionType: ExceptionType.Both); + return; + } + if (prohibitedHooks.Any(h => method.DeclaringType.FullName.StartsWith(h))) + { + GameMain.LuaCs.HandleException(new ArgumentException("Hooks into Modding Environment are prohibited."), exceptionType: ExceptionType.Both); + return; + } var funcAddr = ((long)method.MethodHandle.GetFunctionPointer()); var patches = Harmony.GetPatchInfo(method);