0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00

Update performance patches (#14)

* Add new transpilers

* Cleanup

---------

Co-authored-by: Chomp <27521899+chompDev@users.noreply.github.com>
This commit is contained in:
Lacyway 2025-01-01 01:19:14 -08:00 committed by GitHub
parent 050ab8daf8
commit 8260ad4d6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 154 additions and 150 deletions

View File

@ -0,0 +1,45 @@
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>
public class BotOwner_ManualUpdate_Transpiler : ModulePatch
{
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()
codeList[109] = new CodeInstruction(OpCodes.Nop);
codeList[108] = new CodeInstruction(OpCodes.Nop);
codeList[107].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;
}
}
}

View File

@ -0,0 +1,38 @@
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>
internal class CoverPointMaster_method_0_Transpiler : 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 stops the allocation and Start() of the Stopwatch
codeList[12].opcode = OpCodes.Nop;
codeList[11].opcode = OpCodes.Nop;
codeList[10].opcode = OpCodes.Nop;
return codeList;
}
}
}

View File

@ -1,81 +0,0 @@
using EFT;
using EFT.Game.Spawning;
using SPT.Reflection.Patching;
using System.Reflection;
using UnityEngine;
using UnityEngine.AI;
namespace SPT.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// Patch used to stop the allocation of a new <see cref="System.Diagnostics.Stopwatch"/> every frame for all active AI
/// </summary>
public class BotOwnerManualUpdatePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return typeof(BotOwner).GetMethod(nameof(BotOwner.UpdateManual));
}
[PatchPrefix]
public static bool Prefix(BotOwner __instance, float ____nextGetGoalTime, ref float ____nextTimeCheckBorn)
{
if (__instance.BotState == EBotState.Active && __instance.GetPlayer.HealthController.IsAlive)
{
__instance.StandBy.Update();
__instance.LookSensor.ManualUpdate();
if (__instance.StandBy.StandByType != BotStandByType.paused)
{
if (____nextGetGoalTime < Time.time)
{
__instance.CalcGoal();
}
__instance.SuppressShoot.ManualUpdate();
__instance.HeadData.ManualUpdate();
__instance.ShootData.ManualUpdate();
__instance.Tilt.ManualUpdate();
__instance.NightVision.ManualUpdate();
__instance.NearDoorData.Update();
__instance.DogFight.ManualUpdate();
__instance.FriendChecker.ManualUpdate();
__instance.RecoilData.LosingRecoil();
__instance.Mover.ManualUpdate();
__instance.AimingManager.ManualUpdate();
__instance.Medecine.ManualUpdate();
__instance.Boss.ManualUpdate();
__instance.BotTalk.ManualUpdate();
__instance.WeaponManager.ManualUpdate();
__instance.BotRequestController.Update();
__instance.GrenadeToPortal.ManualUpdate();
__instance.Tactic.UpdateChangeTactics();
__instance.Memory.ManualUpdate(Time.deltaTime);
__instance.Settings.UpdateManual();
__instance.BotRequestController.TryToFind();
__instance.ArtilleryDangerPlace.ManualUpdate();
if (__instance.GetPlayer.UpdateQueue == EUpdateQueue.Update)
{
__instance.Mover.ManualFixedUpdate();
__instance.Steering.ManualFixedUpdate();
}
__instance.UnityEditorRunChecker.ManualLateUpdate();
}
return false;
}
if (__instance.BotState == EBotState.PreActive && __instance.WeaponManager.IsReady)
{
if (NavMesh.SamplePosition(__instance.GetPlayer.Position, out _, 0.6f, -1))
{
__instance.method_10();
return false;
}
if (____nextTimeCheckBorn < Time.time)
{
____nextTimeCheckBorn = Time.time + 1f;
__instance.Transform.position = __instance.BotsGroup.BotZone.SpawnPoints.RandomElement<ISpawnPoint>().Position + Vector3.up * 0.5f;
__instance.method_10();
}
}
return false;
}
}
}

View File

@ -1,11 +1,12 @@
using System; using BepInEx;
using SPT.Common; using SPT.Common;
using SPT.SinglePlayer.Patches.MainMenu; using SPT.SinglePlayer.Patches.MainMenu;
using SPT.SinglePlayer.Patches.Performance;
using SPT.SinglePlayer.Patches.Progression; using SPT.SinglePlayer.Patches.Progression;
using SPT.SinglePlayer.Patches.RaidFix; using SPT.SinglePlayer.Patches.RaidFix;
using SPT.SinglePlayer.Patches.ScavMode; using SPT.SinglePlayer.Patches.ScavMode;
using BepInEx;
using SPT.SinglePlayer.Utils.MainMenu; using SPT.SinglePlayer.Utils.MainMenu;
using System;
namespace SPT.SinglePlayer namespace SPT.SinglePlayer
{ {
@ -62,13 +63,14 @@ namespace SPT.SinglePlayer
new RemoveClothingItemExternalObtainLabelPatch().Enable(); new RemoveClothingItemExternalObtainLabelPatch().Enable();
new ForceRaidModeToLocalPatch().Enable(); new ForceRaidModeToLocalPatch().Enable();
new ScavIsPlayerEnemyPatch().Enable(); new ScavIsPlayerEnemyPatch().Enable();
new BotOwnerManualUpdatePatch().Enable();
new FirearmControllerShowIncompatibleNotificationClass().Enable(); new FirearmControllerShowIncompatibleNotificationClass().Enable();
new FixKeyAlreadyExistsErrorOnAchievementPatch().Enable(); new FixKeyAlreadyExistsErrorOnAchievementPatch().Enable();
// 4.0.0 // 4.0.0
new ScavPrestigeFixPatch().Enable(); new ScavPrestigeFixPatch().Enable();
new DisableDevMaskCheckPatch().Enable(); new DisableDevMaskCheckPatch().Enable();
new BotOwner_ManualUpdate_Transpiler().Enable();
new CoverPointMaster_method_0_Transpiler().Enable();
} }
catch (Exception ex) catch (Exception ex)
{ {