31 lines
1007 B
C#
31 lines
1007 B
C#
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<long> OwnerCache = new UintCache<long>(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;
|
|
}
|
|
}
|
|
} |