2007-05-16 03:57:18 +00:00
|
|
|
/* Ham Sandwich
|
|
|
|
* Copyright 2007
|
|
|
|
* By the AMX Mod X Development Team
|
|
|
|
*
|
|
|
|
* Ham Sandwich is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* Ham Sandwich is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Ham Sandwich; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the author gives permission to
|
|
|
|
* link the code of Ham Sandwich with the Half-Life Game Engine ("HL
|
|
|
|
* Engine") and Modified Game Libraries ("MODs") developed by Valve,
|
|
|
|
* L.L.C ("Valve"). You must obey the GNU General Public License in all
|
|
|
|
* respects for all of the code used other than the HL Engine and MODs
|
|
|
|
* from Valve. If you modify this file, you may extend this exception
|
|
|
|
* to your version of the file, but you are not obligated to do so. If
|
|
|
|
* you do not wish to do so, delete this exception statement from your
|
|
|
|
* version.
|
|
|
|
*/
|
|
|
|
|
2008-08-16 09:48:39 +00:00
|
|
|
#include "amxxmodule.h"
|
2007-05-04 12:51:13 +00:00
|
|
|
#include <extdll.h>
|
2007-05-04 14:56:57 +00:00
|
|
|
|
2007-05-04 12:51:13 +00:00
|
|
|
#include "NEW_Util.h"
|
2007-05-04 14:56:57 +00:00
|
|
|
#include "CVector.h"
|
|
|
|
#include "forward.h"
|
|
|
|
#include "hook.h"
|
|
|
|
#include "ham_const.h"
|
2007-05-10 16:08:02 +00:00
|
|
|
#include "hooklist.h"
|
2007-05-12 17:33:58 +00:00
|
|
|
#include "offsets.h"
|
2007-05-10 16:08:02 +00:00
|
|
|
#include <assert.h>
|
2007-05-04 12:51:13 +00:00
|
|
|
|
|
|
|
edict_t *NEW_FirstEdict;
|
|
|
|
bool NEW_Initialized;
|
|
|
|
|
2007-05-04 14:56:57 +00:00
|
|
|
extern CVector<Hook*> hooks[HAM_LAST_ENTRY_DONT_USE_ME_LOL];
|
2007-05-04 12:51:13 +00:00
|
|
|
|
|
|
|
extern AMX_NATIVE_INFO RegisterNatives[];
|
2007-05-08 17:26:51 +00:00
|
|
|
extern AMX_NATIVE_INFO ReturnNatives[];
|
2007-05-13 13:59:54 +00:00
|
|
|
extern AMX_NATIVE_INFO pdata_natives[];
|
|
|
|
extern AMX_NATIVE_INFO pdata_natives_safe[];
|
|
|
|
|
2007-05-04 12:51:13 +00:00
|
|
|
|
2007-05-10 16:08:02 +00:00
|
|
|
extern hook_t hooklist[];
|
|
|
|
|
2007-05-04 12:51:13 +00:00
|
|
|
int ReadConfig(void);
|
|
|
|
|
|
|
|
void OnAmxxAttach(void)
|
|
|
|
{
|
2007-05-10 16:08:02 +00:00
|
|
|
// Assert that the enum is aligned properly with the table
|
2007-05-16 03:57:18 +00:00
|
|
|
|
|
|
|
assert(strcmp(hooklist[Ham_FVecVisible].name, "fvecvisible")==0);
|
|
|
|
assert(strcmp(hooklist[Ham_Player_UpdateClientData].name, "player_updateclientdata")==0);
|
|
|
|
assert(strcmp(hooklist[Ham_Item_AddToPlayer].name, "item_addtoplayer")==0);
|
|
|
|
assert(strcmp(hooklist[Ham_Weapon_ExtractAmmo].name, "weapon_extractammo")==0);
|
|
|
|
assert(strcmp(hooklist[Ham_TS_BreakableRespawn].name, "ts_breakablerespawn")==0);
|
2007-05-10 16:08:02 +00:00
|
|
|
assert(strcmp(hooklist[Ham_NS_UpdateOnRemove].name, "ns_updateonremove")==0);
|
2007-07-19 18:43:27 +00:00
|
|
|
assert(strcmp(hooklist[Ham_TS_ShouldCollide].name, "ts_shouldcollide")==0);
|
2007-05-10 16:08:02 +00:00
|
|
|
|
2007-05-13 13:59:54 +00:00
|
|
|
MF_AddNatives(pdata_natives_safe);
|
2007-05-04 12:51:13 +00:00
|
|
|
if (ReadConfig() > 0)
|
|
|
|
{
|
2007-05-12 17:33:58 +00:00
|
|
|
if (Offsets.IsValid())
|
|
|
|
{
|
|
|
|
MF_AddNatives(RegisterNatives);
|
|
|
|
MF_AddNatives(ReturnNatives);
|
2007-05-13 13:59:54 +00:00
|
|
|
MF_AddNatives(pdata_natives);
|
2007-05-12 17:33:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
MF_Log("Error: pev and base not set for section \"%s windows\", cannot register natives.", MF_GetModname());
|
|
|
|
#elif defined __linux__
|
|
|
|
MF_Log("Error: pev and base not set for section \"%s linux\", cannot register natives.", MF_GetModname());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MF_Log("Error: Cannot read config file, natives not registered!");
|
2007-05-04 12:51:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HamCommand(void);
|
|
|
|
|
2007-05-04 14:56:57 +00:00
|
|
|
void OnPluginsUnloaded(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
CVector <Hook *>::iterator end;
|
|
|
|
for (int i = 0; i < HAM_LAST_ENTRY_DONT_USE_ME_LOL; i++)
|
|
|
|
{
|
|
|
|
end=hooks[i].end();
|
|
|
|
|
|
|
|
for (CVector<Hook*>::iterator j=hooks[i].begin();
|
|
|
|
j!=end;
|
|
|
|
++j)
|
|
|
|
{
|
|
|
|
delete (*j);
|
|
|
|
}
|
|
|
|
hooks[i].clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-04 12:51:13 +00:00
|
|
|
void OnPluginsLoaded(void)
|
|
|
|
{
|
|
|
|
NEW_Initialize(INDEXENT(0));
|
|
|
|
}
|
|
|
|
void OnMetaAttach(void)
|
|
|
|
{
|
|
|
|
REG_SVR_COMMAND("ham", HamCommand);
|
|
|
|
}
|