using EFT;
using HarmonyLib;
using SPT.Reflection.Patching;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics;
namespace SPT.SinglePlayer.Patches.Performance
{
///
/// Transpiler used to stop the allocation of a new every frame for all active AI
/// To update transpiler, look for:
/// - New allocation of
/// - and
/// - Unnecessary run of
///
public class RemoveStopwatchAllocationsEveryBotFramePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotOwner), nameof(BotOwner.UpdateManual));
}
[PatchTranspiler]
public static IEnumerable Transpile(IEnumerable instructions)
{
List codeList = instructions.ToList();
// These 3 lines remove BotUnityEditorRunChecker.ManualLateUpdate()
codeList[112] = new CodeInstruction(OpCodes.Nop);
codeList[111] = new CodeInstruction(OpCodes.Nop);
codeList[110].opcode = OpCodes.Nop;
// These 4 remove the allocation of the Stopwatch and the Start() and Stop()
codeList[18] = new CodeInstruction(OpCodes.Nop);
codeList[14] = new CodeInstruction(OpCodes.Nop);
codeList[13] = new CodeInstruction(OpCodes.Nop);
codeList[12] = new CodeInstruction(OpCodes.Nop);
return codeList;
}
}
}