mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 06:30:43 -05:00
Make the GC only run on show inventory screen, and only allow it to run for a maximum of 25 milliseconds at a time. Co-authored-by: Cj <161484149+CJ-SPT@users.noreply.github.com> Reviewed-on: SPT/Modules#178 Co-authored-by: Cj <cj@noreply.dev.sp-tarkov.com> Co-committed-by: Cj <cj@noreply.dev.sp-tarkov.com>
29 lines
787 B
C#
29 lines
787 B
C#
using System.Reflection;
|
|
using Comfort.Common;
|
|
using EFT;
|
|
using EFT.UI;
|
|
using EFT.UI.Screens;
|
|
using HarmonyLib;
|
|
using SPT.Reflection.Patching;
|
|
using UnityEngine.Scripting;
|
|
|
|
namespace SPT.Custom.Patches;
|
|
|
|
public class MemoryCollectionPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
return AccessTools.Method(typeof(MenuTaskBar), nameof(MenuTaskBar.OnScreenChanged));
|
|
}
|
|
|
|
[PatchPostfix]
|
|
public static void PatchPostfix(EEftScreenType eftScreenType)
|
|
{
|
|
if (eftScreenType != EEftScreenType.Inventory || !Singleton<GameWorld>.Instantiated) return;
|
|
|
|
GarbageCollector.GCMode = GarbageCollector.Mode.Enabled;
|
|
|
|
// 25000000 Nanoseconds is 25 Milliseconds.
|
|
GarbageCollector.CollectIncremental(25000000L);
|
|
}
|
|
} |