2014-08-04 10:21:40 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// Ham Sandwich Module
|
|
|
|
//
|
2014-05-01 08:21:46 +00:00
|
|
|
|
|
|
|
#include "hook_specialbot.h"
|
|
|
|
#include "hooklist.h"
|
|
|
|
#include "hook.h"
|
|
|
|
|
2014-08-10 09:48:06 +00:00
|
|
|
extern ke::Vector<Hook*> hooks[HAM_LAST_ENTRY_DONT_USE_ME_LOL];
|
2014-05-01 08:21:46 +00:00
|
|
|
extern hook_t hooklist[];
|
|
|
|
|
|
|
|
|
|
|
|
CRegisterHamParams::CRegisterHamParams(AMX *arg_amx, int &arg_func, const char *arg_function, int &arg_post, int &arg_fwd)
|
|
|
|
{
|
|
|
|
amx = arg_amx;
|
|
|
|
func = arg_func;
|
|
|
|
function = new char[strlen(arg_function)+1];
|
|
|
|
strcpy(function, arg_function);
|
|
|
|
post = arg_post;
|
|
|
|
fwd = arg_fwd;
|
|
|
|
}
|
|
|
|
|
|
|
|
CRegisterHamParams::~CRegisterHamParams()
|
|
|
|
{
|
|
|
|
delete[] function;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CHamSpecialBotHandler::CHamSpecialBotHandler()
|
|
|
|
{
|
|
|
|
m_specialbot_vtable = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHamSpecialBotHandler::CheckClientKeyValue(int &clientIndex, char *infobuffer, const char *key, const char *value)
|
|
|
|
{
|
|
|
|
if(m_specialbot_vtable != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
edict_t *pEdict = MF_GetPlayerEdict(clientIndex);
|
|
|
|
if((pEdict->v.flags & FL_FAKECLIENT) != FL_FAKECLIENT)
|
|
|
|
{
|
|
|
|
const char *auth = GETPLAYERAUTHID(pEdict);
|
|
|
|
if (auth && (strcmp(auth, "BOT") != 0))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(strcmp(key, "*bot") != 0 || strcmp(value, "1") != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_specialbot_vtable = GetVTable(pEdict->pvPrivateData, Offsets.GetBase());
|
|
|
|
|
|
|
|
if(m_RHP_list.empty())
|
|
|
|
return;
|
2014-08-10 09:48:06 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < m_RHP_list.length(); ++i)
|
2014-05-01 08:21:46 +00:00
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
CRegisterHamParams *item = m_RHP_list.at(i);
|
|
|
|
RegisterChecked(item->amx, item->func, item->function, item->post, item->fwd);
|
|
|
|
delete item;
|
2014-05-01 08:21:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_RHP_list.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHamSpecialBotHandler::RegisterHamSpecialBot(AMX *amx, int &func, const char *function, int &post, int &fwd)
|
|
|
|
{
|
|
|
|
if(m_specialbot_vtable == NULL)
|
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
m_RHP_list.append( new CRegisterHamParams(amx, func, function, post, fwd) );
|
2014-05-01 08:21:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterChecked(amx, func, function, post, fwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CHamSpecialBotHandler::RegisterChecked(AMX *amx, int &func, const char *function, int &post, int &fwd)
|
|
|
|
{
|
|
|
|
void **vtable = m_specialbot_vtable;
|
|
|
|
int **ivtable=(int **)vtable;
|
|
|
|
|
|
|
|
void *vfunction=(void *)ivtable[hooklist[func].vtid];
|
|
|
|
|
2014-08-10 09:48:06 +00:00
|
|
|
for (size_t i = 0; i < hooks[func].length(); ++i)
|
2014-05-01 08:21:46 +00:00
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
if (hooks[func].at(i)->tramp == vfunction)
|
2014-05-01 08:21:46 +00:00
|
|
|
{
|
|
|
|
// Yes, this function is hooked
|
2014-08-10 09:48:06 +00:00
|
|
|
Forward *pfwd = new Forward(fwd);
|
2014-05-01 08:21:46 +00:00
|
|
|
if (post)
|
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
hooks[func].at(i)->post.append(pfwd);
|
2014-05-01 08:21:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
hooks[func].at(i)->pre.append(pfwd);
|
2014-05-01 08:21:46 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char classname[] = "player";
|
|
|
|
|
|
|
|
// If we got here, the function is not hooked
|
|
|
|
Hook *hook = new Hook(vtable, hooklist[func].vtid, hooklist[func].targetfunc, hooklist[func].isvoid, hooklist[func].needsretbuf, hooklist[func].paramcount, classname);
|
2014-08-10 09:48:06 +00:00
|
|
|
hooks[func].append(hook);
|
2014-05-01 08:21:46 +00:00
|
|
|
|
|
|
|
Forward *pfwd=new Forward(fwd);
|
|
|
|
if (post)
|
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
hook->post.append(pfwd);
|
2014-05-01 08:21:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-10 09:48:06 +00:00
|
|
|
hook->pre.append(pfwd);
|
2014-05-01 08:21:46 +00:00
|
|
|
}
|
|
|
|
}
|