From 218fb9c794c0aca226250de961e428d97e6de1d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Gr=C3=BCnbacher?= Date: Sun, 10 May 2015 23:40:22 +0200 Subject: [PATCH] Engine: Add unregister_[touch|think|impulse]() --- modules/engine/engine.cpp | 67 +++++++++++++++++++++++++++++++++++++- plugins/include/engine.inc | 33 +++++++++++++++++-- 2 files changed, 96 insertions(+), 4 deletions(-) diff --git a/modules/engine/engine.cpp b/modules/engine/engine.cpp index 8c8b6f34..a635fd4b 100644 --- a/modules/engine/engine.cpp +++ b/modules/engine/engine.cpp @@ -55,6 +55,27 @@ static cell AMX_NATIVE_CALL register_think(AMX *amx, cell *params) return p->Forward; } +static cell AMX_NATIVE_CALL unregister_think(AMX *amx, cell *params) +{ + int fwd = params[1]; + for (size_t i = 0; i < Thinks.length(); ++i) + { + EntClass *p = Thinks.at(i); + if (p->Forward == fwd) + { + Thinks.remove(i); + delete p; + + if (!Thinks.length()) + g_pFunctionTable->pfnThink = NULL; + + return 1; + } + } + + return 0; +} + static cell AMX_NATIVE_CALL register_impulse(AMX *amx, cell *params) { int len; @@ -72,6 +93,27 @@ static cell AMX_NATIVE_CALL register_impulse(AMX *amx, cell *params) return p->Forward; } +static cell AMX_NATIVE_CALL unregister_impulse(AMX *amx, cell *params) +{ + int fwd = params[1]; + for (size_t i = 0; i < Impulses.length(); ++i) + { + Impulse *p = Impulses.at(i); + if (p->Forward == fwd) + { + Impulses.remove(i); + delete p; + + if (!Impulses.length()) + g_pFunctionTable->pfnCmdStart = NULL; + + return 1; + } + } + + return 0; +} + static cell AMX_NATIVE_CALL register_touch(AMX *amx, cell *params) { int len; @@ -102,6 +144,27 @@ static cell AMX_NATIVE_CALL register_touch(AMX *amx, cell *params) return p->Forward; } +static cell AMX_NATIVE_CALL unregister_touch(AMX *amx, cell *params) +{ + int fwd = params[1]; + for (size_t i = 0; i < Touches.length(); ++i) + { + Touch *p = Touches.at(i); + if (p->Forward == fwd) + { + Touches.remove(i); + delete p; + + if (!Touches.length()) + g_pFunctionTable->pfnTouch = NULL; + + return 1; + } + } + + return 0; +} + static cell AMX_NATIVE_CALL halflife_time(AMX *amx, cell *params) { REAL fVal = gpGlobals->time; @@ -983,10 +1046,12 @@ AMX_NATIVE_INFO engine_Natives[] = { {"get_usercmd", get_usercmd}, {"set_usercmd", set_usercmd}, - {"register_impulse", register_impulse}, {"register_think", register_think}, {"register_touch", register_touch}, + {"unregister_impulse", unregister_impulse}, + {"unregister_think", unregister_think}, + {"unregister_touch", unregister_touch}, {"eng_get_string", get_string}, {"is_in_viewcone", in_view_cone}, diff --git a/plugins/include/engine.inc b/plugins/include/engine.inc index cd0b5e5f..9d9bcdbd 100755 --- a/plugins/include/engine.inc +++ b/plugins/include/engine.inc @@ -70,7 +70,7 @@ native traceresult(type, any:...); * @param impulse Impulse to hook * @param function Name of callback function * - * @noreturn + * @return Impulse forward id */ native register_impulse(impulse, const function[]); @@ -96,7 +96,7 @@ native register_impulse(impulse, const function[]); * @param Toucher Entity classname touching, "*" or "" for any class * @param function Name of callback function * - * @noreturn + * @return Touch forward id */ native register_touch(const Touched[], const Toucher[], const function[]); @@ -120,10 +120,37 @@ native register_touch(const Touched[], const Toucher[], const function[]); * @param Touched Entity classname to hook * @param function Name of callback function * - * @noreturn + * @return Think forward id */ native register_think(const Classname[], const function[]); +/** + * Removes a previously registered impulse hook. + * + * @param registerid Impulse forward id + * + * @return 1 on success, 0 if nothing was removed + */ +native unregister_impulse(registerid); + +/** + * Removes a previously registered touch hook. + * + * @param registerid Touch forward id + * + * @return 1 on success, 0 if nothing was removed + */ +native unregister_touch(registerid); + +/** + * Removes a previously registered think hook. + * + * @param registerid Think forward id + * + * @return 1 on success, 0 if nothing was removed + */ +native unregister_think(registerid); + /** * Precaches an event file. *