amxmodx/modules/hamsandwich/amxx_api.cpp

137 lines
4.2 KiB
C++
Raw Normal View History

// 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
//
#include "amxxmodule.h"
#include <extdll.h>
2015-09-30 17:08:39 +00:00
#include <amtl/am-vector.h>
#include "forward.h"
#include "hook.h"
#include "ham_const.h"
#include "hooklist.h"
#include "offsets.h"
#include <assert.h>
#include "DataHandler.h"
#include "hook_specialbot.h"
#include <HLTypeConversion.h>
HLTypeConversion TypeConversion;
extern ke::Vector<Hook*> hooks[HAM_LAST_ENTRY_DONT_USE_ME_LOL];
extern CHamSpecialBotHandler SpecialbotHandler;
extern AMX_NATIVE_INFO RegisterNatives[];
extern AMX_NATIVE_INFO ReturnNatives[];
extern AMX_NATIVE_INFO pdata_natives[];
extern AMX_NATIVE_INFO pdata_natives_safe[];
extern hook_t hooklist[];
int ReadConfig(void);
void OnAmxxAttach(void)
{
// Assert that the enum is aligned properly with the table
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);
assert(strcmp(hooklist[Ham_NS_UpdateOnRemove].name, "ns_updateonremove")==0);
assert(strcmp(hooklist[Ham_TS_ShouldCollide].name, "ts_shouldcollide")==0);
2015-03-10 15:51:45 +00:00
assert(strcmp(hooklist[Ham_GetDeathActivity].name, "getdeathactivity")==0);
assert(strcmp(hooklist[Ham_StopFollowing].name, "stopfollowing")==0);
assert(strcmp(hooklist[Ham_CS_Player_OnTouchingWeapon].name, "cstrike_player_ontouchingweapon")==0);
assert(strcmp(hooklist[Ham_DOD_Weapon_Special].name, "dod_weapon_special")==0);
assert(strcmp(hooklist[Ham_TFC_RadiusDamage2].name, "tfc_radiusdamage2")==0);
assert(strcmp(hooklist[Ham_ESF_Weapon_HolsterWhenMeleed].name, "esf_weapon_holsterwhenmeleed") == 0);
assert(strcmp(hooklist[Ham_NS_Weapon_GetDeployTime].name, "ns_weapon_getdeploytime")==0);
assert(strcmp(hooklist[Ham_SC_MedicCallSound].name, "sc_mediccallsound")==0);
assert(strcmp(hooklist[Ham_SC_Player_CanTouchPlayer].name, "sc_player_cantouchplayer")==0);
assert(strcmp(hooklist[Ham_SC_Weapon_ChangeWeaponSkin].name, "sc_weapon_changeweaponskin")==0);
assert(strcmp(hooklist[Ham_Item_GetItemInfo].name, "item_getiteminfo") == 0);
Update Hamsandwich for Sven Coop 5.17 (#452) * Remove dropped functions * Update existing offsets * Add some logic to prevent the use of removed functions. * Add Ham_SC_AddPoints and Ham_SC_AddPointsToTeam * Add Ham_SC_GiveAmmo * Add Ham_SC_FVisibleFromPos * Fix an old typos with CanPlaySentence for all mods * Add Ham_SC_CanPlaySequence * Add Ham_SC_PlayScriptSentence * Add Ham_SC_StartPlayerFollowing * Fix CanPlaySequence hamdata.ini (SC) * Add Ham_SC_StopPlayerFollowing * Fix handlers from previous commits * Add Ham_SC_PreSpawn * Add Ham_SC_PostSpawn * Add Ham_SC_OnKeyValueUpdate * Add Ham_SC_SetClassification * Add Ham_SC_MyCustomPointer and Ham_SC_MyItemPointer * Add Ham_SC_IsSneaking * Add Ham_SC_IsAlive * Add Ham_SC_IsBSPModel * Add Ham_SC_ReflectGauss * Add Ham_SC_HasTarget * Add Ham_SC_IsInWorld * Add Ham_SC_IsPlayer * Add Ham_SC_IsNetClient * Add Ham_SC_IsBreakable * Fix Ham_SC_IsMonster, Ham_SC_IsPointEntity, Ham_SC_IsMachine and Ham_SC_CriticakRemove handlers * Add Ham_SC_OnControls * Fix Ham_SC_TakeHealth and Ham_SC_TakeArmor handlers * Add Ham_SC_IsTriggered * Add Ham_SC_RemovePlayerItem * Fix typo * Fix Ham_SC_IsMoving handler * Add Ham_SC_SUB_UseTargets * Ham_SC_IsLockedByMaster * Add Ham_SC_FBecomeProne * Fix Ham_SC_FVisible handler * Add Ham_SC_FVecVisible * Fix Ham_SC_FVisibleFromPos handler * Fix Ham_SC_IsFacing handler * Add Ham_SC_SetPlayerAlly * Add Ham_SC_OnSetOriginByMap * Add Ham_SC_IsRevivable * Add Ham_SC_BeginRevive and Ham_SC_EndRevive * Update offsets based on SvenCoop v5.17 * Add Ham_SC_Item_CanCollect and Ham_SC_Item_Collect * Add Ham_SC_Item_AddToPlayer * Add Ham_SC_Item_AddDuplicate * Add Ham_SC_Item_AddAmmoFromItem * Add Ham_SC_Item_GetItemInfo * Add Ham_SC_Item_CanDeploy, Ham_SC_Item_Deploy and Ham_SC_Item_CanHolster * Add Ham_SC_Item_UpdateClientData * Add Ham_SC_Item_GetRespawnTime * Add Ham_SC_Item_CanHaveDuplicates * Add Ham_SC_Weapon_ExtractAmmoFromItem * Add Ham_SC_Weapon_GetAmmo1Drop and Ham_SC_Weapon_GetAmmo2Drop * Add Ham_SC_Weapon_FinishReload and Ham_SC_Weapon_ShouldReload * Fix Ham_SC_IsMultiplayer, Ham_SC_FRunfuncs and Ham_SC_FCanRun handlers * Add Ham_SC_Weapon_AddWeapon, _PlayEmptySound, _IsUsable, _ShouldWeaponIdle and _UseDecrement * Add Ham_SC_Item_GetPickupSound * Add Ham_SC_Item_InactiveItemPreFrame and Ham_SC_Item_InactiveItemPostFrame * Add Ham_SC_Item_DetachFromPlayer * Fix Ham_SC_Player_IsConnected handler * Add Ham_SC_Player_EnteredObserver, Ham_SC_Player_LeftObserver and Ham_SC_Player_IsObserver * Fix sc_postpawn typo (should be sc_postspawn) * Add few more assert
2018-09-06 15:09:10 +00:00
assert(strcmp(hooklist[Ham_SC_Item_AddToPlayer].name, "sc_item_addtoplayer") == 0);
assert(strcmp(hooklist[Ham_SC_Weapon_ExtractAmmoFromItem].name, "sc_weapon_extractammofromitem") == 0);
assert(strcmp(hooklist[Ham_SC_Player_EnteredObserver].name, "sc_player_enteredobserver") == 0);
MF_AddNatives(pdata_natives_safe);
if (ReadConfig() > 0)
{
if (Offsets.IsValid())
{
MF_AddNatives(RegisterNatives);
MF_AddNatives(ReturnNatives);
MF_AddNatives(pdata_natives);
}
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());
#elif defined(__APPLE__)
MF_Log("Error: pev and base not set for section \"%s mac\", cannot register natives.", MF_GetModname());
#endif
}
}
else
{
MF_Log("Error: Cannot read config file, natives not registered!");
}
}
2015-03-10 15:51:45 +00:00
extern CStack<ItemInfo *> g_FreeIIs;
void OnAmxxDetach()
{
while (!g_FreeIIs.empty())
{
delete g_FreeIIs.front();
g_FreeIIs.pop();
}
}
void HamCommand(void);
void OnPluginsUnloaded(void)
{
for (size_t i = 0; i < HAM_LAST_ENTRY_DONT_USE_ME_LOL; i++)
{
for (size_t j = 0; j < hooks[i].length(); ++j)
{
delete hooks[i].at(j);
}
hooks[i].clear();
}
}
void OnPluginsLoaded(void)
{
TypeConversion.init();
}
void OnMetaAttach(void)
{
REG_SVR_COMMAND("ham", HamCommand);
}
void SetClientKeyValue(int clientIndex, char *infobuffer, const char *key, const char *value)
{
SpecialbotHandler.CheckClientKeyValue(clientIndex, infobuffer, key, value);
RETURN_META(MRES_IGNORED);
}