2025-01-01 01:19:14 -08:00
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Transpiler used to stop the allocation of a new <see cref="Stopwatch"/> every frame for all active AI <br/>
|
|
|
|
|
/// To update transpiler, look for: <br/>
|
|
|
|
|
/// - New allocation of <see cref="Stopwatch"/> <br/>
|
|
|
|
|
/// - <see cref="Stopwatch.Start"/> and <see cref="Stopwatch.Stop"/> <br/>
|
|
|
|
|
/// - Unnecessary run of <see cref="BotUnityEditorRunChecker.ManualLateUpdate"/>
|
|
|
|
|
/// </summary>
|
2025-01-01 09:29:32 +00:00
|
|
|
|
public class RemoveStopwatchAllocationsEveryBotFramePatch : ModulePatch
|
2025-01-01 01:19:14 -08:00
|
|
|
|
{
|
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
|
{
|
|
|
|
|
return AccessTools.Method(typeof(BotOwner), nameof(BotOwner.UpdateManual));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[PatchTranspiler]
|
|
|
|
|
public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction> instructions)
|
|
|
|
|
{
|
|
|
|
|
List<CodeInstruction> codeList = instructions.ToList();
|
|
|
|
|
|
|
|
|
|
// These 3 lines remove BotUnityEditorRunChecker.ManualLateUpdate()
|
2025-01-02 02:11:27 -08:00
|
|
|
|
codeList[112] = new CodeInstruction(OpCodes.Nop);
|
|
|
|
|
codeList[111] = new CodeInstruction(OpCodes.Nop);
|
|
|
|
|
codeList[110].opcode = OpCodes.Nop;
|
2025-01-01 01:19:14 -08:00
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|