0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.SinglePlayer/Patches/Performance/RemoveStopwatchAllocationsEveryCoverPointFramePatch.cs

39 lines
1.2 KiB
C#

using HarmonyLib;
using SPT.Reflection.Patching;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace SPT.SinglePlayer.Patches.Performance
{
/// <summary>
/// Transpiler used to stop the allocation of a new <see cref="Stopwatch"/> during <see cref="CoverPointMaster.method_0(CoverSearchData)"/> <br/>
/// To update transpiler, look for: <br/>
/// - New allocation of <see cref="Stopwatch"/> <br/>
/// - <see cref="Stopwatch.Start"/> and <see cref="Stopwatch.Stop"/> <br/>
/// </summary>
public class RemoveStopwatchAllocationsEveryCoverPointFramePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(CoverPointMaster), nameof(CoverPointMaster.method_0));
}
[PatchTranspiler]
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> codeList = instructions.ToList();
// This is the line that stops the Stopwatch
codeList[69].opcode = OpCodes.Nop;
// These lines stop the allocation and Start() of the Stopwatch
codeList[12].opcode = OpCodes.Nop;
codeList[11].opcode = OpCodes.Nop;
codeList[10].opcode = OpCodes.Nop;
return codeList;
}
}
}