Switch to amtl vectors. Change how hooks are checked for removal on frame action.
This commit is contained in:
		
							parent
							
								
									98fcde86c1
								
							
						
					
					
						commit
						9d09a52e99
					
				| @ -42,7 +42,6 @@ | |||||||
| #include <ISDKHooks.h> | #include <ISDKHooks.h> | ||||||
| #include <IBinTools.h> | #include <IBinTools.h> | ||||||
| #include <ISDKTools.h> | #include <ISDKTools.h> | ||||||
| #include <sh_vector.h> |  | ||||||
| #include "sdk-hacks.h" | #include "sdk-hacks.h" | ||||||
| 
 | 
 | ||||||
| /**
 | /**
 | ||||||
|  | |||||||
| @ -3,42 +3,39 @@ | |||||||
| 
 | 
 | ||||||
| using namespace SourceHook; | using namespace SourceHook; | ||||||
| 
 | 
 | ||||||
| SourceHook::CVector<EntityListener> g_EntityListeners; | ke::Vector<EntityListener> g_EntityListeners; | ||||||
| 
 | ke::Vector<DHooksManager *>g_pRemoveList; | ||||||
| 
 | 
 | ||||||
| void FrameCleanupHooks(void *data) | void FrameCleanupHooks(void *data) | ||||||
| { | { | ||||||
| 	for (int i = g_pHooks.size() - 1; i >= 0; i--) | 	for (int i = g_pRemoveList.length() - 1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pRemoveList.at(i); | ||||||
| 		if (manager->bDelete) | 		delete manager; | ||||||
| 		{ | 		g_pRemoveList.remove(i); | ||||||
| 			delete manager; |  | ||||||
| 			g_pHooks.erase(g_pHooks.iterAt(i)); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void DHooks::OnCoreMapEnd() | void DHooks::OnCoreMapEnd() | ||||||
| { | { | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 		if(manager->callback->hookType == HookType_GameRules) | 		if(manager->callback->hookType == HookType_GameRules) | ||||||
| 		{ | 		{ | ||||||
| 			delete manager; | 			delete manager; | ||||||
| 			g_pHooks.erase(g_pHooks.iterAt(i)); | 			g_pHooks.remove(i); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void DHooksEntityListener::CleanupListeners(IPluginContext *pContext) | void DHooksEntityListener::CleanupListeners(IPluginContext *pContext) | ||||||
| { | { | ||||||
| 	for(int i = g_EntityListeners.size() -1; i >= 0; i--) | 	for(int i = g_EntityListeners.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		if(pContext == NULL || pContext == g_EntityListeners.at(i).callback->GetParentRuntime()->GetDefaultContext()) | 		if(pContext == NULL || pContext == g_EntityListeners.at(i).callback->GetParentRuntime()->GetDefaultContext()) | ||||||
| 		{ | 		{ | ||||||
| 			g_EntityListeners.erase(g_EntityListeners.iterAt(i)); | 			g_EntityListeners.remove(i); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| @ -47,7 +44,7 @@ void DHooksEntityListener::OnEntityCreated(CBaseEntity *pEntity, const char *cla | |||||||
| { | { | ||||||
| 	int entity = gamehelpers->EntityToBCompatRef(pEntity); | 	int entity = gamehelpers->EntityToBCompatRef(pEntity); | ||||||
| 
 | 
 | ||||||
| 	for(int i = g_EntityListeners.size() -1; i >= 0; i--) | 	for(int i = g_EntityListeners.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		EntityListener listerner = g_EntityListeners.at(i); | 		EntityListener listerner = g_EntityListeners.at(i); | ||||||
| 		if(listerner.type == ListenType_Created) | 		if(listerner.type == ListenType_Created) | ||||||
| @ -64,7 +61,7 @@ void DHooksEntityListener::OnEntityDestroyed(CBaseEntity *pEntity) | |||||||
| { | { | ||||||
| 	int entity = gamehelpers->EntityToBCompatRef(pEntity); | 	int entity = gamehelpers->EntityToBCompatRef(pEntity); | ||||||
| 
 | 
 | ||||||
| 	for(int i = g_EntityListeners.size() -1; i >= 0; i--) | 	for(int i = g_EntityListeners.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		EntityListener listerner = g_EntityListeners.at(i); | 		EntityListener listerner = g_EntityListeners.at(i); | ||||||
| 		if(listerner.type == ListenType_Deleted) | 		if(listerner.type == ListenType_Deleted) | ||||||
| @ -75,25 +72,24 @@ void DHooksEntityListener::OnEntityDestroyed(CBaseEntity *pEntity) | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	bool bDeleting = false; | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 
 |  | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) |  | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 		if(manager->callback->entity == entity) | 		if(manager->callback->entity == entity) | ||||||
| 		{ | 		{ | ||||||
| 			manager->bDelete = true; | 			if(g_pRemoveList.length() == 0) | ||||||
| 			if (!bDeleting) |  | ||||||
| 			{ | 			{ | ||||||
| 				smutils->AddFrameAction(&FrameCleanupHooks, NULL); | 				smutils->AddFrameAction(&FrameCleanupHooks, NULL); | ||||||
| 				bDeleting = true; |  | ||||||
| 			} | 			} | ||||||
|  | 
 | ||||||
|  | 			g_pRemoveList.append(manager); | ||||||
|  | 			g_pHooks.remove(i); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| bool DHooksEntityListener::AddPluginEntityListener(ListenType type, IPluginFunction *callback) | bool DHooksEntityListener::AddPluginEntityListener(ListenType type, IPluginFunction *callback) | ||||||
| { | { | ||||||
| 	for(int i = g_EntityListeners.size() -1; i >= 0; i--) | 	for(int i = g_EntityListeners.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		EntityListener listerner = g_EntityListeners.at(i); | 		EntityListener listerner = g_EntityListeners.at(i); | ||||||
| 		if(listerner.callback == callback && listerner.type == type) | 		if(listerner.callback == callback && listerner.type == type) | ||||||
| @ -104,17 +100,17 @@ bool DHooksEntityListener::AddPluginEntityListener(ListenType type, IPluginFunct | |||||||
| 	EntityListener listener; | 	EntityListener listener; | ||||||
| 	listener.callback = callback; | 	listener.callback = callback; | ||||||
| 	listener.type = type; | 	listener.type = type; | ||||||
| 	g_EntityListeners.push_back(listener); | 	g_EntityListeners.append(listener); | ||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
| bool DHooksEntityListener::RemovePluginEntityListener(ListenType type, IPluginFunction *callback) | bool DHooksEntityListener::RemovePluginEntityListener(ListenType type, IPluginFunction *callback) | ||||||
| { | { | ||||||
| 	for(int i = g_EntityListeners.size() -1; i >= 0; i--) | 	for(int i = g_EntityListeners.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		EntityListener listerner = g_EntityListeners.at(i); | 		EntityListener listerner = g_EntityListeners.at(i); | ||||||
| 		if(listerner.callback == callback && listerner.type == type) | 		if(listerner.callback == callback && listerner.type == type) | ||||||
| 		{ | 		{ | ||||||
| 			g_EntityListeners.erase(g_EntityListeners.iterAt(i)); | 			g_EntityListeners.remove(i); | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -27,5 +27,5 @@ struct EntityListener | |||||||
| 	IPluginFunction *callback; | 	IPluginFunction *callback; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| extern SourceHook::CVector<DHooksManager *> g_pHooks; | extern ke::Vector<DHooksManager *> g_pHooks; | ||||||
| #endif | #endif | ||||||
|  | |||||||
							
								
								
									
										16
									
								
								natives.cpp
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								natives.cpp
									
									
									
									
									
								
							| @ -109,7 +109,7 @@ cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params) | |||||||
| 	} | 	} | ||||||
| 	bool post = params[2] != 0; | 	bool post = params[2] != 0; | ||||||
| 
 | 
 | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 		if(manager->callback->hookType == HookType_Entity && manager->callback->entity == gamehelpers->ReferenceToBCompatRef(params[3]) && manager->callback->offset == setup->offset && manager->callback->post == post && manager->remove_callback == pContext->GetFunctionById(params[4]) && manager->callback->plugin_callback == setup->callback) | 		if(manager->callback->hookType == HookType_Entity && manager->callback->entity == gamehelpers->ReferenceToBCompatRef(params[3]) && manager->callback->offset == setup->offset && manager->callback->post == post && manager->remove_callback == pContext->GetFunctionById(params[4]) && manager->callback->plugin_callback == setup->callback) | ||||||
| @ -132,7 +132,7 @@ cell_t Native_HookEntity(IPluginContext *pContext, const cell_t *params) | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	g_pHooks.push_back(manager); | 	g_pHooks.append(manager); | ||||||
| 
 | 
 | ||||||
| 	return manager->hookid; | 	return manager->hookid; | ||||||
| } | } | ||||||
| @ -153,7 +153,7 @@ cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params) | |||||||
| 
 | 
 | ||||||
| 	bool post = params[2] != 0; | 	bool post = params[2] != 0; | ||||||
| 
 | 
 | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 		if(manager->callback->hookType == HookType_GameRules && manager->callback->offset == setup->offset && manager->callback->post == post && manager->remove_callback == pContext->GetFunctionById(params[3]) && manager->callback->plugin_callback == setup->callback) | 		if(manager->callback->hookType == HookType_GameRules && manager->callback->offset == setup->offset && manager->callback->post == post && manager->remove_callback == pContext->GetFunctionById(params[3]) && manager->callback->plugin_callback == setup->callback) | ||||||
| @ -177,7 +177,7 @@ cell_t Native_HookGamerules(IPluginContext *pContext, const cell_t *params) | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	g_pHooks.push_back(manager); | 	g_pHooks.append(manager); | ||||||
| 
 | 
 | ||||||
| 	return manager->hookid; | 	return manager->hookid; | ||||||
| } | } | ||||||
| @ -199,7 +199,7 @@ cell_t Native_HookRaw(IPluginContext *pContext, const cell_t *params) | |||||||
| 	bool post = params[2] != 0; | 	bool post = params[2] != 0; | ||||||
| 	void *iface = (void *)(params[3]); | 	void *iface = (void *)(params[3]); | ||||||
| 
 | 
 | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 		if(manager->callback->hookType == HookType_Raw && manager->addr == (intptr_t)iface && manager->callback->offset == setup->offset && manager->callback->post == post && manager->remove_callback == pContext->GetFunctionById(params[4]) && manager->callback->plugin_callback == setup->callback) | 		if(manager->callback->hookType == HookType_Raw && manager->addr == (intptr_t)iface && manager->callback->offset == setup->offset && manager->callback->post == post && manager->remove_callback == pContext->GetFunctionById(params[4]) && manager->callback->plugin_callback == setup->callback) | ||||||
| @ -221,20 +221,20 @@ cell_t Native_HookRaw(IPluginContext *pContext, const cell_t *params) | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	g_pHooks.push_back(manager); | 	g_pHooks.append(manager); | ||||||
| 
 | 
 | ||||||
| 	return manager->hookid; | 	return manager->hookid; | ||||||
| } | } | ||||||
| // native bool:DHookRemoveHookID(hookid);
 | // native bool:DHookRemoveHookID(hookid);
 | ||||||
| cell_t Native_RemoveHookID(IPluginContext *pContext, const cell_t *params) | cell_t Native_RemoveHookID(IPluginContext *pContext, const cell_t *params) | ||||||
| { | { | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 		if(manager->hookid == params[1] && manager->callback->plugin_callback->GetParentRuntime()->GetDefaultContext() == pContext) | 		if(manager->hookid == params[1] && manager->callback->plugin_callback->GetParentRuntime()->GetDefaultContext() == pContext) | ||||||
| 		{ | 		{ | ||||||
| 			delete manager; | 			delete manager; | ||||||
| 			g_pHooks.erase(g_pHooks.iterAt(i)); | 			g_pHooks.remove(i); | ||||||
| 			return 1; | 			return 1; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -10,5 +10,5 @@ extern ISDKTools *g_pSDKTools; | |||||||
| extern HandleType_t g_HookSetupHandle; | extern HandleType_t g_HookSetupHandle; | ||||||
| extern HandleType_t g_HookParamsHandle; | extern HandleType_t g_HookParamsHandle; | ||||||
| extern HandleType_t g_HookReturnHandle; | extern HandleType_t g_HookReturnHandle; | ||||||
| extern SourceHook::CVector<DHooksManager *> g_pHooks; | extern ke::Vector<DHooksManager *> g_pHooks; | ||||||
| #endif | #endif | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ | |||||||
| 
 | 
 | ||||||
| SourceHook::IHookManagerAutoGen *g_pHookManager = NULL; | SourceHook::IHookManagerAutoGen *g_pHookManager = NULL; | ||||||
| 
 | 
 | ||||||
| SourceHook::CVector<DHooksManager *> g_pHooks; | ke::Vector<DHooksManager *> g_pHooks; | ||||||
| 
 | 
 | ||||||
| using namespace SourceHook; | using namespace SourceHook; | ||||||
| 
 | 
 | ||||||
| @ -26,7 +26,6 @@ DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *rem | |||||||
| 	this->callback->params = setup->params; | 	this->callback->params = setup->params; | ||||||
| 
 | 
 | ||||||
| 	this->addr = 0; | 	this->addr = 0; | ||||||
| 	this->bDelete = false; |  | ||||||
| 
 | 
 | ||||||
| 	if(this->callback->hookType == HookType_Entity) | 	if(this->callback->hookType == HookType_Entity) | ||||||
| 	{ | 	{ | ||||||
| @ -75,14 +74,14 @@ DHooksManager::DHooksManager(HookSetup *setup, void *iface, IPluginFunction *rem | |||||||
| 
 | 
 | ||||||
| void CleanupHooks(IPluginContext *pContext) | void CleanupHooks(IPluginContext *pContext) | ||||||
| { | { | ||||||
| 	for(int i = g_pHooks.size() -1; i >= 0; i--) | 	for(int i = g_pHooks.length() -1; i >= 0; i--) | ||||||
| 	{ | 	{ | ||||||
| 		DHooksManager *manager = g_pHooks.at(i); | 		DHooksManager *manager = g_pHooks.at(i); | ||||||
| 
 | 
 | ||||||
| 		if(pContext == NULL || pContext == manager->callback->plugin_callback->GetParentRuntime()->GetDefaultContext()) | 		if(pContext == NULL || pContext == manager->callback->plugin_callback->GetParentRuntime()->GetDefaultContext()) | ||||||
| 		{ | 		{ | ||||||
| 			delete manager; | 			delete manager; | ||||||
| 			g_pHooks.erase(g_pHooks.iterAt(i)); | 			g_pHooks.remove(i); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										1
									
								
								vhook.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								vhook.h
									
									
									
									
									
								
							| @ -364,7 +364,6 @@ public: | |||||||
| 	DHooksCallback *callback; | 	DHooksCallback *callback; | ||||||
| 	IPluginFunction *remove_callback; | 	IPluginFunction *remove_callback; | ||||||
| 	SourceHook::HookManagerPubFunc pManager; | 	SourceHook::HookManagerPubFunc pManager; | ||||||
| 	bool bDelete; |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| size_t GetStackArgsSize(DHooksCallback *dg); | size_t GetStackArgsSize(DHooksCallback *dg); | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user