final fixes for warfare 2

This commit is contained in:
z__
2022-02-04 12:09:17 +07:00
parent ba5b611994
commit 1f7e4e869d
2 changed files with 23 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
@@ -8,6 +9,7 @@ using NLog;
using Sandbox; using Sandbox;
using Torch.Managers.PatchManager; using Torch.Managers.PatchManager;
using Torch.Managers.PatchManager.MSIL; using Torch.Managers.PatchManager.MSIL;
using Torch.Utils;
namespace Torch.Patches namespace Torch.Patches
{ {
@@ -17,12 +19,14 @@ namespace Torch.Patches
[PatchShim] [PatchShim]
public static class WorldLoadExceptionPatch public static class WorldLoadExceptionPatch
{ {
private static readonly ILogger _log = LogManager.GetCurrentClassLogger(); private static readonly ILogger Log = LogManager.GetCurrentClassLogger();
[ReflectedMethodInfo(typeof(MySandboxGame), "InitQuickLaunch")]
private static MethodInfo _quickLaunchMethod = null!;
public static void Patch(PatchContext ctx) public static void Patch(PatchContext ctx)
{ {
ctx.GetPattern(typeof(MySandboxGame).GetMethod("InitQuickLaunch", BindingFlags.Instance | BindingFlags.NonPublic)) ctx.GetPattern(_quickLaunchMethod).AddTranspiler(nameof(Transpile));
.Transpilers.Add(typeof(WorldLoadExceptionPatch).GetMethod(nameof(Transpile), BindingFlags.Static | BindingFlags.NonPublic));
} }
private static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> method) private static IEnumerable<MsilInstruction> Transpile(IEnumerable<MsilInstruction> method)
@@ -30,19 +34,19 @@ namespace Torch.Patches
var msil = method.ToList(); var msil = method.ToList();
for (var i = 0; i < msil.Count; i++) for (var i = 0; i < msil.Count; i++)
{ {
if (msil[i].TryCatchOperations.All(x => x.Type != MsilTryCatchOperationType.BeginClauseBlock)) var instruction = msil[i];
continue; if (instruction.IsLocalStore() && instruction.Operand is MsilOperandInline.MsilOperandLocal {Value.Index: 19} operand)
for (; i < msil.Count; i++)
{ {
if (msil[i].OpCode != OpCodes.Leave) msil.InsertRange(i + 1, new []
continue; {
operand.Instruction.CopyWith(OpCodes.Ldloc_S),
msil[i] = new MsilInstruction(OpCodes.Rethrow); new MsilInstruction(OpCodes.Call).InlineValue(new Action<Exception>(LogFatal).Method)
break; });
} }
} }
return msil; return msil;
} }
private static void LogFatal(Exception e) => Log.Fatal(e.ToStringDemystified());
} }
} }

View File

@@ -1,7 +1,9 @@
using System; using System;
using System.Collections;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@@ -43,11 +45,14 @@ namespace Torch.Patches
private static void WhitelistCtorPrefix(MyScriptCompiler scriptCompiler) private static void WhitelistCtorPrefix(MyScriptCompiler scriptCompiler)
{ {
scriptCompiler.AddReferencedAssemblies( scriptCompiler.AddReferencedAssemblies(
typeof(ValueType).Assembly.Location,
typeof(LinkedList<>).Assembly.Location,
typeof(Regex).Assembly.Location, typeof(Regex).Assembly.Location,
typeof(Enumerable).Assembly.Location, typeof(Enumerable).Assembly.Location,
typeof(ConcurrentBag<>).Assembly.Location, typeof(ConcurrentBag<>).Assembly.Location,
typeof(ImmutableArray).Assembly.Location, typeof(ImmutableArray).Assembly.Location,
typeof(System.ComponentModel.TypeConverter).Assembly.Location, typeof(PropertyChangedEventArgs).Assembly.Location,
typeof(TypeConverter).Assembly.Location,
typeof(System.Diagnostics.TraceSource).Assembly.Location, typeof(System.Diagnostics.TraceSource).Assembly.Location,
typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location, typeof(ProtoBuf.Meta.RuntimeTypeModel).Assembly.Location,
Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"), Path.Combine(MyFileSystem.ExePath, "Sandbox.Game.dll"),