Fix specialbot not working with [Enable/Disable]HamForward natives

This commit is contained in:
Arkshine 2014-10-25 20:44:17 +02:00
parent d8fc093fd8
commit b451fbd1c8
3 changed files with 15 additions and 16 deletions

View File

@ -582,10 +582,12 @@ static cell AMX_NATIVE_CALL RegisterHam(AMX *amx, cell *params)
enableSpecialBot = params[5] > 0; enableSpecialBot = params[5] > 0;
} }
Forward *pfwd = new Forward(fwd);
// We've passed all tests... // We've passed all tests...
if (strcmp(classname, "player") == 0 && enableSpecialBot) if (strcmp(classname, "player") == 0 && enableSpecialBot)
{ {
SpecialbotHandler.RegisterHamSpecialBot(amx, func, function, post, fwd); SpecialbotHandler.RegisterHamSpecialBot(amx, func, function, post, pfwd);
} }
int **ivtable=(int **)vtable; int **ivtable=(int **)vtable;
@ -599,7 +601,6 @@ static cell AMX_NATIVE_CALL RegisterHam(AMX *amx, cell *params)
if (hooks[func].at(i)->tramp == vfunction) if (hooks[func].at(i)->tramp == vfunction)
{ {
// Yes, this function is hooked // Yes, this function is hooked
Forward *pfwd=new Forward(fwd);
if (post) if (post)
{ {
hooks[func].at(i)->post.append(pfwd); hooks[func].at(i)->post.append(pfwd);
@ -616,7 +617,6 @@ static cell AMX_NATIVE_CALL RegisterHam(AMX *amx, cell *params)
Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname); Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname);
hooks[func].append(hook); hooks[func].append(hook);
Forward *pfwd=new Forward(fwd);
if (post) if (post)
{ {
hook->post.append(pfwd); hook->post.append(pfwd);

View File

@ -19,14 +19,14 @@ extern ke::Vector<Hook*> hooks[HAM_LAST_ENTRY_DONT_USE_ME_LOL];
extern hook_t hooklist[]; extern hook_t hooklist[];
CRegisterHamParams::CRegisterHamParams(AMX *arg_amx, int &arg_func, const char *arg_function, int &arg_post, int &arg_fwd) CRegisterHamParams::CRegisterHamParams(AMX *arg_amx, int &arg_func, const char *arg_function, int &arg_post, Forward *arg_pfwd)
{ {
amx = arg_amx; amx = arg_amx;
func = arg_func; func = arg_func;
function = new char[strlen(arg_function)+1]; function = new char[strlen(arg_function)+1];
strcpy(function, arg_function); strcpy(function, arg_function);
post = arg_post; post = arg_post;
fwd = arg_fwd; pfwd = arg_pfwd;
} }
CRegisterHamParams::~CRegisterHamParams() CRegisterHamParams::~CRegisterHamParams()
@ -64,25 +64,25 @@ void CHamSpecialBotHandler::CheckClientKeyValue(int &clientIndex, char *infobuff
for (size_t i = 0; i < m_RHP_list.length(); ++i) for (size_t i = 0; i < m_RHP_list.length(); ++i)
{ {
CRegisterHamParams *item = m_RHP_list.at(i); CRegisterHamParams *item = m_RHP_list.at(i);
RegisterChecked(item->amx, item->func, item->function, item->post, item->fwd); RegisterChecked(item->amx, item->func, item->function, item->post, item->pfwd);
delete item; delete item;
} }
m_RHP_list.clear(); m_RHP_list.clear();
} }
void CHamSpecialBotHandler::RegisterHamSpecialBot(AMX *amx, int &func, const char *function, int &post, int &fwd) void CHamSpecialBotHandler::RegisterHamSpecialBot(AMX *amx, int &func, const char *function, int &post, Forward *pfwd)
{ {
if(m_specialbot_vtable == NULL) if(m_specialbot_vtable == NULL)
{ {
m_RHP_list.append( new CRegisterHamParams(amx, func, function, post, fwd) ); m_RHP_list.append(new CRegisterHamParams(amx, func, function, post, pfwd));
return; return;
} }
RegisterChecked(amx, func, function, post, fwd); RegisterChecked(amx, func, function, post, pfwd);
} }
void CHamSpecialBotHandler::RegisterChecked(AMX *amx, int &func, const char *function, int &post, int &fwd) void CHamSpecialBotHandler::RegisterChecked(AMX *amx, int &func, const char *function, int &post, Forward *pfwd)
{ {
void **vtable = m_specialbot_vtable; void **vtable = m_specialbot_vtable;
int **ivtable=(int **)vtable; int **ivtable=(int **)vtable;
@ -94,7 +94,6 @@ void CHamSpecialBotHandler::RegisterChecked(AMX *amx, int &func, const char *fun
if (hooks[func].at(i)->tramp == vfunction) if (hooks[func].at(i)->tramp == vfunction)
{ {
// Yes, this function is hooked // Yes, this function is hooked
Forward *pfwd = new Forward(fwd);
if (post) if (post)
{ {
hooks[func].at(i)->post.append(pfwd); hooks[func].at(i)->post.append(pfwd);
@ -113,7 +112,6 @@ void CHamSpecialBotHandler::RegisterChecked(AMX *amx, int &func, const char *fun
Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname); Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname);
hooks[func].append(hook); hooks[func].append(hook);
Forward *pfwd=new Forward(fwd);
if (post) if (post)
{ {
hook->post.append(pfwd); hook->post.append(pfwd);

View File

@ -16,6 +16,7 @@
#include "ham_utils.h" #include "ham_utils.h"
#include <am-vector.h> #include <am-vector.h>
#include "forward.h"
class CRegisterHamParams class CRegisterHamParams
{ {
@ -24,9 +25,9 @@ public:
int func; int func;
char *function; char *function;
int post; int post;
int fwd; Forward *pfwd;
CRegisterHamParams(AMX *arg_amx, int &arg_func, const char *arg_function, int &arg_post, int &arg_fwd); CRegisterHamParams(AMX *arg_amx, int &arg_func, const char *arg_function, int &arg_post, Forward *arg_pfwd);
~CRegisterHamParams(); ~CRegisterHamParams();
private: private:
CRegisterHamParams(){} CRegisterHamParams(){}
@ -37,10 +38,10 @@ class CHamSpecialBotHandler
public: public:
CHamSpecialBotHandler(); CHamSpecialBotHandler();
void CheckClientKeyValue(int &clientIndex, char *infobuffer, const char *key, const char *value); void CheckClientKeyValue(int &clientIndex, char *infobuffer, const char *key, const char *value);
void RegisterHamSpecialBot(AMX *amx, int &func, const char *function, int &post, int &fwd); void RegisterHamSpecialBot(AMX *amx, int &func, const char *function, int &post, Forward *pfwd);
private: private:
void RegisterChecked(AMX *amx, int &func, const char *function, int &post, int &fwd); void RegisterChecked(AMX *amx, int &func, const char *function, int &post, Forward *pfwd);
ke::Vector<CRegisterHamParams*> m_RHP_list; ke::Vector<CRegisterHamParams*> m_RHP_list;
void **m_specialbot_vtable; void **m_specialbot_vtable;