using System.Runtime.CompilerServices; using Global.Shared.Util; using HarmonyLib; using Sandbox.Game.GameSystems; namespace Global.Shared.Patches { [HarmonyPatch(typeof(MyGridTerminalSystem))] public class TerminalSystemPatch { public static readonly UintCache OwnerCache = new UintCache(337 * 60); [HarmonyPrefix] [HarmonyPatch(nameof(MyGridTerminalSystem.UpdateGridBlocksOwnership))] [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool UpdateGridBlocksOwnershipPrefix(MyGridTerminalSystem __instance, long ownerID) { var key = __instance.GetHashCode() ^ ownerID; if (OwnerCache.TryGetValue(key, out var value)) { if (value == (uint)ownerID) return false; OwnerCache.Forget(key); return true; } OwnerCache.Store(key, (uint)ownerID, 240 + ((uint)key & 63)); return true; } } }