port over script compiler patch changes

This commit is contained in:
zznty
2024-05-15 21:13:35 +07:00
parent 46ee2b61a5
commit 28e26dbf5e
3 changed files with 56 additions and 6 deletions

View File

@@ -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<MyScriptManager>(nameof(MyScriptManager.Init))).AddPrefix();
}
private static void Prefix(Dictionary<string, string> ___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;"] = "";
}
}

View File

@@ -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;
}

View File

@@ -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<MyTypeTable>("IsSerializableClass")).AddSuffix();
}
private static void Suffix(Type type, ref bool __result)
{
if (type == typeof(Delegate) || type == typeof(MulticastDelegate))
__result = true;
}
}