mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-28 22:48:05 +03:00
Added safety checks for hookchains impl
This commit is contained in:
parent
b172d20227
commit
212e9638d6
@ -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/"
|
||||
|
@ -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])
|
||||
{
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user