From 964b9b4af3f5c89e84d95f7b2e08d3e570c55d82 Mon Sep 17 00:00:00 2001 From: KillStr3aK Date: Tue, 12 Dec 2023 19:17:11 +0100 Subject: [PATCH] added `CreateMemoryPatch` --- .../CounterStrikeSharp.API/Core/BasePlugin.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/managed/CounterStrikeSharp.API/Core/BasePlugin.cs b/managed/CounterStrikeSharp.API/Core/BasePlugin.cs index 89405c05e..cf9eb785c 100644 --- a/managed/CounterStrikeSharp.API/Core/BasePlugin.cs +++ b/managed/CounterStrikeSharp.API/Core/BasePlugin.cs @@ -30,6 +30,7 @@ using CounterStrikeSharp.API.Modules.Entities; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; +using CounterStrikeSharp.API.Modules.Memory; namespace CounterStrikeSharp.API.Core { @@ -126,6 +127,9 @@ public void Dispose() internal readonly Dictionary EntitySingleOutputHooks = new Dictionary(); + internal readonly Dictionary MemoryPatches = + new Dictionary(); + public readonly List Timers = new List(); public delegate HookResult GameEventHandler(T @event, GameEventInfo info) where T : GameEvent; @@ -388,6 +392,18 @@ public Timer AddTimer(float interval, Action callback, TimerFlags? flags = null) return timer; } + public MemoryPatch? CreateMemoryPatch(string patchName, string patchSignature) + { + MemoryPatch patch = new MemoryPatch(patchName, patchSignature); + + if (patch.PerformPatch()) + { + MemoryPatches.Add(patchName, patch); + return patch; + } + + return null; + } public void RegisterAllAttributes(object instance) { @@ -585,6 +601,11 @@ protected virtual void Dispose(bool disposing) timer.Kill(); } + foreach (var patch in MemoryPatches) + { + patch.Value.UndoPatch(); + } + _disposed = true; } }