mirror of
https://github.com/roflmuffin/CounterStrikeSharp.git
synced 2025-12-07 08:26:34 -08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cba5144bbf | ||
|
|
0de951cb6f |
@@ -457,6 +457,12 @@
|
||||
<Left>.\ApiCompat\v151.dll</Left>
|
||||
<Right>obj\Debug\net7.0\CounterStrikeSharp.API.dll</Right>
|
||||
</Suppression>
|
||||
<Suppression>
|
||||
<DiagnosticId>CP0002</DiagnosticId>
|
||||
<Target>M:CounterStrikeSharp.API.Core.Translations.JsonStringLocalizerFactory.#ctor(CounterStrikeSharp.API.Core.Plugin.IPluginContext)</Target>
|
||||
<Left>.\ApiCompat\v151.dll</Left>
|
||||
<Right>obj\Debug\net7.0\CounterStrikeSharp.API.dll</Right>
|
||||
</Suppression>
|
||||
<Suppression>
|
||||
<DiagnosticId>CP0006</DiagnosticId>
|
||||
<Target>M:CounterStrikeSharp.API.Core.IPlugin.OnAllPluginsLoaded(System.Boolean)</Target>
|
||||
|
||||
@@ -749,6 +749,16 @@ namespace CounterStrikeSharp.API.Core
|
||||
}
|
||||
}
|
||||
|
||||
public static void FreeEvent(IntPtr gameevent){
|
||||
lock (ScriptContext.GlobalScriptContext.Lock) {
|
||||
ScriptContext.GlobalScriptContext.Reset();
|
||||
ScriptContext.GlobalScriptContext.Push(gameevent);
|
||||
ScriptContext.GlobalScriptContext.SetIdentifier(0x7E8B60C2);
|
||||
ScriptContext.GlobalScriptContext.Invoke();
|
||||
ScriptContext.GlobalScriptContext.CheckErrors();
|
||||
}
|
||||
}
|
||||
|
||||
public static void FireEvent(IntPtr gameevent, bool dontbroadcast){
|
||||
lock (ScriptContext.GlobalScriptContext.Lock) {
|
||||
ScriptContext.GlobalScriptContext.Reset();
|
||||
|
||||
@@ -75,6 +75,7 @@ public partial class CCSPlayerController
|
||||
Userid = this
|
||||
};
|
||||
@event.FireEventToClient(this);
|
||||
@event.Free();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -32,12 +32,16 @@ namespace CounterStrikeSharp.API.Modules.Events
|
||||
|
||||
public class GameEvent : NativeObject
|
||||
{
|
||||
// Used to track freeable state for manually created events.
|
||||
private bool _freeable = false;
|
||||
|
||||
public GameEvent(IntPtr pointer) : base(pointer)
|
||||
{
|
||||
}
|
||||
|
||||
public GameEvent(string name, bool force) : this(NativeAPI.CreateEvent(name, force))
|
||||
{
|
||||
_freeable = true;
|
||||
}
|
||||
|
||||
public string EventName => NativeAPI.GetEventName(Handle);
|
||||
@@ -121,8 +125,28 @@ namespace CounterStrikeSharp.API.Modules.Events
|
||||
|
||||
protected void SetEntityIndex(string name, int value) => NativeAPI.SetEventEntityIndex(Handle, name, value);
|
||||
|
||||
public void FireEvent(bool dontBroadcast) => NativeAPI.FireEvent(Handle, dontBroadcast);
|
||||
|
||||
public void FireEvent(bool dontBroadcast)
|
||||
{
|
||||
NativeAPI.FireEvent(Handle, dontBroadcast);
|
||||
_freeable = false;
|
||||
}
|
||||
|
||||
public void FireEventToClient(CCSPlayerController player) => NativeAPI.FireEventToClient(Handle, (int)player.Index);
|
||||
|
||||
/// <summary>
|
||||
/// Used to manually free the event.
|
||||
/// <remarks>If <see cref="FireEvent"/> is called, Free will be called automatically.</remarks>
|
||||
/// </summary>
|
||||
public void Free()
|
||||
{
|
||||
if (!_freeable)
|
||||
{
|
||||
throw new InvalidOperationException("Event is not able to be freed.");
|
||||
}
|
||||
|
||||
NativeAPI.FreeEvent(Handle);
|
||||
|
||||
_freeable = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ public class DynamicHook : NativeObject
|
||||
return NativeAPI.DynamicHookGetParam<T>(Handle, (int)typeof(T).ToValidDataType(), index);
|
||||
}
|
||||
|
||||
public T GetReturn<T>(int index)
|
||||
public T GetReturn<T>()
|
||||
{
|
||||
return NativeAPI.DynamicHookGetReturn<T>(Handle, (int)typeof(T).ToValidDataType());
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ static void FireEvent(ScriptContext &script_context) {
|
||||
}
|
||||
|
||||
|
||||
static void FireEventToClient(ScriptContext& script_context) {
|
||||
static void FireEventToClient(ScriptContext& script_context) {
|
||||
auto game_event = script_context.GetArgument<IGameEvent*>(0);
|
||||
int entityIndex = script_context.GetArgument<int>(1);
|
||||
if (!game_event) {
|
||||
@@ -76,7 +76,17 @@ static void FireEvent(ScriptContext &script_context) {
|
||||
}
|
||||
|
||||
pListener->FireGameEvent(game_event);
|
||||
}
|
||||
}
|
||||
|
||||
static void FreeEvent(ScriptContext& script_context) {
|
||||
auto game_event = script_context.GetArgument<IGameEvent*>(0);
|
||||
if (!game_event) {
|
||||
script_context.ThrowNativeError("Invalid game event");
|
||||
}
|
||||
|
||||
globals::gameEventManager->FreeEvent(game_event);
|
||||
managed_game_events.erase(std::remove(managed_game_events.begin(), managed_game_events.end(), game_event), managed_game_events.end());
|
||||
}
|
||||
|
||||
static const char *GetEventName(ScriptContext &script_context) {
|
||||
IGameEvent *game_event = script_context.GetArgument<IGameEvent *>(0);
|
||||
@@ -263,6 +273,7 @@ REGISTER_NATIVES(events, {
|
||||
ScriptEngine::RegisterNativeHandler("HOOK_EVENT", HookEvent);
|
||||
ScriptEngine::RegisterNativeHandler("UNHOOK_EVENT", UnhookEvent);
|
||||
ScriptEngine::RegisterNativeHandler("CREATE_EVENT", CreateEvent);
|
||||
ScriptEngine::RegisterNativeHandler("FREE_EVENT", FreeEvent);
|
||||
ScriptEngine::RegisterNativeHandler("FIRE_EVENT", FireEvent);
|
||||
ScriptEngine::RegisterNativeHandler("FIRE_EVENT_TO_CLIENT", FireEventToClient);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
HOOK_EVENT: name:string, callback:func, isPost:bool -> void
|
||||
UNHOOK_EVENT: name:string, callback:func, isPost:bool -> void
|
||||
CREATE_EVENT: name:string, force:bool -> pointer
|
||||
FREE_EVENT: gameEvent:pointer -> void
|
||||
FIRE_EVENT: gameEvent:pointer, dontBroadcast:bool -> void
|
||||
FIRE_EVENT_TO_CLIENT: gameEvent:pointer, clientIndex:int -> void
|
||||
GET_EVENT_NAME: gameEvent:pointer -> string
|
||||
|
||||
Reference in New Issue
Block a user