diff --git a/publish.gradle b/publish.gradle index c3782eb..7252ebe 100644 --- a/publish.gradle +++ b/publish.gradle @@ -128,7 +128,7 @@ if (file('repo_creds.properties').exists()) { publishing { repositories { maven { - if (project.version.contains('SNAPSHOT')) { + if (project.version.contains('dev')) { url "http://nexus.rehlds.org/nexus/content/repositories/rehlds-snapshots/" } else { url "http://nexus.rehlds.org/nexus/content/repositories/rehlds-releases/" diff --git a/rehlds/rehlds/hookchains_impl.cpp b/rehlds/rehlds/hookchains_impl.cpp index 998572a..07c61c2 100644 --- a/rehlds/rehlds/hookchains_impl.cpp +++ b/rehlds/rehlds/hookchains_impl.cpp @@ -27,12 +27,28 @@ AbstractHookChainRegistry::AbstractHookChainRegistry() m_NumHooks = 0; } -void AbstractHookChainRegistry::addHook(void* hookFunc, int priority) { - for (int i = 0; i < MAX_HOOKS_IN_CHAIN; i++) - { +bool AbstractHookChainRegistry::findHook(void* hookFunc) const +{ + for (auto i = 0; i < m_NumHooks; i++) { if (m_Hooks[i] == hookFunc) - return; + return true; + } + return false; +} + +void AbstractHookChainRegistry::addHook(void* hookFunc, int priority) +{ + if (!hookFunc) { + Sys_Error(__FUNCTION__ " Parameter hookFunc can't be a nullptr"); + } + + if (findHook(hookFunc)) { + Sys_Error(__FUNCTION__ " The same handler can't be used twice on the hookchain."); + } + + for (auto i = 0; i < MAX_HOOKS_IN_CHAIN; i++) + { if (m_Hooks[i] && priority <= m_Priorities[i]) continue; @@ -47,7 +63,7 @@ void AbstractHookChainRegistry::addHook(void* hookFunc, int priority) { } if (m_NumHooks >= MAX_HOOKS_IN_CHAIN) { - rehlds_syserror("MAX_HOOKS_IN_CHAIN limit hit"); + Sys_Error(__FUNCTION__ " MAX_HOOKS_IN_CHAIN limit hit"); } m_NumHooks++; @@ -56,7 +72,7 @@ void AbstractHookChainRegistry::addHook(void* hookFunc, int priority) { void AbstractHookChainRegistry::removeHook(void* hookFunc) { // erase hook - for (int i = 0; i < m_NumHooks; i++) + for (auto i = 0; i < m_NumHooks; i++) { if (hookFunc == m_Hooks[i]) { diff --git a/rehlds/rehlds/hookchains_impl.h b/rehlds/rehlds/hookchains_impl.h index 51de16a..3b46150 100644 --- a/rehlds/rehlds/hookchains_impl.h +++ b/rehlds/rehlds/hookchains_impl.h @@ -92,7 +92,8 @@ public: } virtual void callOriginal(t_args... args) { - m_OriginalFunc(args...); + if (m_OriginalFunc) + m_OriginalFunc(args...); } private: @@ -108,6 +109,7 @@ protected: protected: void addHook(void* hookFunc, int priority); + bool findHook(void* hookFunc) const; void removeHook(void* hookFunc); public: