diff --git a/Torch/Patches/DarkTardMissingNamespacePatch.cs b/Torch/Patches/DarkTardMissingNamespacePatch.cs new file mode 100644 index 0000000..2ad241c --- /dev/null +++ b/Torch/Patches/DarkTardMissingNamespacePatch.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Sandbox.Game.World; +using Torch.Managers.PatchManager; +using Torch.Utils; + +namespace Torch.Patches; + +[PatchShim] +internal static class DarkTardMissingNamespacePatch +{ + public static void Patch(PatchContext ctx) + { + ctx.GetPattern(Info.OfMethod(nameof(MyScriptManager.Init))).AddPrefix(); + } + + private static void Prefix(Dictionary ___m_compatibilityChanges) + { + ___m_compatibilityChanges["using System.Runtime.Remoting.Metadata.W3cXsd2001;"] = ""; + ___m_compatibilityChanges["using System.IO.Ports;"] = ""; + ___m_compatibilityChanges["using System.Runtime.Remoting;"] = ""; + ___m_compatibilityChanges["using System.Runtime.Remoting.Messaging;"] = ""; + ___m_compatibilityChanges["using System.Numerics;"] = ""; + ___m_compatibilityChanges["using System.Runtime.Remoting.Lifetime;"] = ""; + } +} \ No newline at end of file diff --git a/Torch/Patches/ScriptCompilerPatch.cs b/Torch/Patches/ScriptCompilerPatch.cs index 6ab2a13..ffdcae2 100644 --- a/Torch/Patches/ScriptCompilerPatch.cs +++ b/Torch/Patches/ScriptCompilerPatch.cs @@ -22,20 +22,22 @@ namespace Torch.Patches [PatchShim] public static class ScriptCompilerPatch { - [ReflectedMethodInfo(typeof(MyScriptWhitelist), "Register", Parameters = new[] {typeof(MyWhitelistTarget), typeof(INamespaceSymbol), typeof(Type)})] + [ReflectedMethodInfo(typeof(MyScriptWhitelist), "Register", Parameters = [typeof(MyWhitelistTarget), typeof(INamespaceSymbol), typeof(Type)])] private static MethodInfo _register1Method; - [ReflectedMethodInfo(typeof(MyScriptWhitelist), "Register", Parameters = new[] {typeof(MyWhitelistTarget), typeof(ITypeSymbol), typeof(Type)})] + [ReflectedMethodInfo(typeof(MyScriptWhitelist), "Register", Parameters = [typeof(MyWhitelistTarget), typeof(ITypeSymbol), typeof(Type)])] private static MethodInfo _register2Method; + + [ReflectedMethodInfo(null, "AllowMembers", TypeName = "VRage.Scripting.MyScriptWhitelist+MyWhitelistBatch, VRage.Scripting")] + private static MethodInfo _allowMembersMethod; public static void Patch(PatchContext context) { context.GetPattern(typeof(MyScriptWhitelist).GetConstructor(new[] {typeof(MyScriptCompiler)})) .AddPrefix(nameof(WhitelistCtorPrefix)); - context.GetPattern(Type.GetType("VRage.Scripting.MyVRageScriptingInternal, VRage.Scripting", true).GetMethod("Initialize")) + context.GetPattern(Info.OfMethod("VRage.Scripting", "VRage.Scripting.MyVRageScriptingInternal", "Initialize")) .AddPrefix(nameof(InitializePrefix)); - context.GetPattern(typeof(MyScriptWhitelist).GetNestedType("MyWhitelistBatch", BindingFlags.NonPublic)! - .GetMethod("AllowMembers")).AddPrefix(nameof(AllowMembersPrefix)); + context.GetPattern(_allowMembersMethod).AddPrefix(nameof(AllowMembersPrefix)); context.GetPattern(_register1Method).AddTranspiler(nameof(RegisterTranspiler)); context.GetPattern(_register2Method).AddTranspiler(nameof(RegisterTranspiler)); } @@ -56,9 +58,10 @@ namespace Torch.Patches typeof(System.Diagnostics.TraceSource).Assembly.Location, typeof(System.Security.Policy.Evidence).Assembly.Location, Path.Combine(baseDir, "System.Xml.ReaderWriter.dll"), + Path.Combine(MyFileSystem.ExePath, "ProtoBuf.Net.dll"), + Path.Combine(MyFileSystem.ExePath, "ProtoBuf.Net.Core.dll"), Path.Combine(baseDir, "netstandard.dll"), Path.Combine(baseDir, "System.Runtime.dll"), - Path.Combine(MyFileSystem.ExePath, "ProtoBuf.Net.Core.dll"), Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"), Path.Combine(MyFileSystem.ExePath, "Sandbox.Common.dll"), Path.Combine(MyFileSystem.ExePath, "Sandbox.Graphics.dll"), @@ -80,6 +83,7 @@ namespace Torch.Patches using var batch = MyScriptCompiler.Static.Whitelist.OpenBatch(); batch.AllowTypes(MyWhitelistTarget.ModApi, typeof(ConcurrentQueue<>)); + batch.AllowNamespaceOfTypes(MyWhitelistTarget.Both, typeof(ImmutableArray)); return false; } diff --git a/Torch/Patches/TypeTableRegisterPatch.cs b/Torch/Patches/TypeTableRegisterPatch.cs new file mode 100644 index 0000000..99b2075 --- /dev/null +++ b/Torch/Patches/TypeTableRegisterPatch.cs @@ -0,0 +1,21 @@ +using System; +using Torch.Managers.PatchManager; +using Torch.Utils; +using VRage.Network; + +namespace Torch.Patches; + +[PatchShim] +internal static class TypeTableRegisterPatch +{ + public static void Patch(PatchContext context) + { + context.GetPattern(Info.OfMethod("IsSerializableClass")).AddSuffix(); + } + + private static void Suffix(Type type, ref bool __result) + { + if (type == typeof(Delegate) || type == typeof(MulticastDelegate)) + __result = true; + } +} \ No newline at end of file