Skip to content

Commit

Permalink
added CreateMemoryPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
KillStr3aK committed Dec 12, 2023
1 parent 6138806 commit 964b9b4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions managed/CounterStrikeSharp.API/Core/BasePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -126,6 +127,9 @@ public void Dispose()
internal readonly Dictionary<Delegate, EntityIO.EntityOutputCallback> EntitySingleOutputHooks =
new Dictionary<Delegate, EntityIO.EntityOutputCallback>();

internal readonly Dictionary<string, MemoryPatch> MemoryPatches =
new Dictionary<string, MemoryPatch>();

public readonly List<Timer> Timers = new List<Timer>();

public delegate HookResult GameEventHandler<T>(T @event, GameEventInfo info) where T : GameEvent;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -585,6 +601,11 @@ protected virtual void Dispose(bool disposing)
timer.Kill();
}

foreach (var patch in MemoryPatches)
{
patch.Value.UndoPatch();
}

_disposed = true;
}
}
Expand Down

0 comments on commit 964b9b4

Please sign in to comment.