shitty gc calls removal
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
|
||||
<PropertyChanged />
|
||||
<InfoOf />
|
||||
</Weavers>
|
@@ -53,6 +53,7 @@
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="InfoOf" minOccurs="0" maxOccurs="1" type="xs:anyType" />
|
||||
</xs:all>
|
||||
<xs:attribute name="VerifyAssembly" type="xs:boolean">
|
||||
<xs:annotation>
|
||||
|
@@ -221,6 +221,27 @@ namespace Torch.Managers.PatchManager.MSIL
|
||||
{
|
||||
return new MsilInstruction(argument.Position < 0xFF ? OpCodes.Ldarga_S : OpCodes.Ldarga).InlineValue(argument);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy Instruction with null operand and new opcode.
|
||||
/// </summary>
|
||||
/// <param name="instruction">Instruction to copy from.</param>
|
||||
/// <param name="opCode">New opCode to assign.</param>
|
||||
/// <returns>Copy of <see cref="instruction"/>.</returns>
|
||||
public static MsilInstruction CopyWithoutOperand(this MsilInstruction instruction, OpCode opCode)
|
||||
{
|
||||
var copied = new MsilInstruction(opCode);
|
||||
foreach (var label in instruction.Labels)
|
||||
{
|
||||
copied.Labels.Add(label);
|
||||
}
|
||||
foreach (var operation in instruction.TryCatchOperations)
|
||||
{
|
||||
copied.TryCatchOperations.Add(operation);
|
||||
}
|
||||
|
||||
return copied;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constant Utils
|
||||
|
52
Torch/Patches/GcCollectPatch.cs
Normal file
52
Torch/Patches/GcCollectPatch.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Reflection.Emit;
|
||||
using Havok;
|
||||
using Sandbox.Engine.Voxels.Planet;
|
||||
using Sandbox.Game.World;
|
||||
using Torch.Managers.PatchManager;
|
||||
using Torch.Managers.PatchManager.MSIL;
|
||||
using Torch.Utils;
|
||||
using VRage;
|
||||
|
||||
namespace Torch.Patches;
|
||||
|
||||
[PatchShim]
|
||||
internal static class GcCollectPatch
|
||||
{
|
||||
// FUCK YO KEEN
|
||||
// every call results in freeze for seconds
|
||||
private static readonly MethodBase[] _targets =
|
||||
{
|
||||
Info.OfMethod<MyPlanetTextureMapProvider>(nameof(MyPlanetTextureMapProvider.GetHeightmap)),
|
||||
Info.OfMethod<MyPlanetTextureMapProvider>(nameof(MyPlanetTextureMapProvider.GetDetailMap)),
|
||||
Info.OfMethod<MyPlanetTextureMapProvider>(nameof(MyPlanetTextureMapProvider.GetMaps)),
|
||||
Info.OfMethod<MySession>(nameof(MySession.Unload)),
|
||||
Info.OfMethod("HavokWrapper", "Havok.HkBaseSystem", nameof(HkBaseSystem.Quit)),
|
||||
Info.OfMethod<MySimpleProfiler>(nameof(MySimpleProfiler.LogPerformanceTestResults)),
|
||||
Info.OfConstructor<MySession>("MySyncLayer,Boolean")
|
||||
};
|
||||
|
||||
public static void Patch(PatchContext context)
|
||||
{
|
||||
foreach (var target in _targets)
|
||||
{
|
||||
context.GetPattern(target).AddTranspiler(nameof(CollectRemovalTranspiler));
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<MsilInstruction> CollectRemovalTranspiler(IEnumerable<MsilInstruction> instructions)
|
||||
{
|
||||
foreach (var instruction in instructions)
|
||||
{
|
||||
if (instruction.Operand is MsilOperandInline<MethodInfo> operand &&
|
||||
operand.Value.DeclaringType == typeof(GC))
|
||||
{
|
||||
yield return instruction.CopyWithoutOperand(OpCodes.Nop);
|
||||
continue;
|
||||
}
|
||||
yield return instruction;
|
||||
}
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@
|
||||
<!-- <Import Project="$(SolutionDir)\TransformOnBuild.targets" /> -->
|
||||
<ItemGroup>
|
||||
<PackageReference Include="ControlzEx" Version="5.0.1" />
|
||||
<PackageReference Include="InfoOf.Fody" Version="2.1.0" />
|
||||
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
|
||||
<PackageReference Include="MonoMod.RuntimeDetour" Version="22.1.4.3" />
|
||||
<PackageReference Include="NLog" Version="4.7.13" />
|
||||
|
Reference in New Issue
Block a user