zz
This commit is contained in:
31
GlobalShared/Patches/TerminalSystemPatch.cs
Normal file
31
GlobalShared/Patches/TerminalSystemPatch.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user