Cstrike: Enable/Disable detours whether CS_OnBuy and CS_InternalCommand are used in plugins + Add more check for safety.
This commit is contained in:
parent
f1e206fde6
commit
d2f2748e9e
@ -157,17 +157,25 @@ void CtrlDetours_ClientCommand(bool set)
|
||||
#endif
|
||||
g_ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target);
|
||||
|
||||
if (g_ClientCommandDetour != NULL)
|
||||
g_ClientCommandDetour->EnableDetour();
|
||||
else
|
||||
if (g_ClientCommandDetour == NULL)
|
||||
{
|
||||
MF_Log("No Client Commands detour could be initialized - Disabled Client Command forward.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_ClientCommandDetour)
|
||||
g_ClientCommandDetour->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleDetour_ClientCommands(bool enable)
|
||||
{
|
||||
if (g_ClientCommandDetour)
|
||||
(enable) ? g_ClientCommandDetour->EnableDetour() : g_ClientCommandDetour->DisableDetour();
|
||||
}
|
||||
|
||||
|
||||
void CtrlDetours_BuyCommands(bool set)
|
||||
{
|
||||
if (set)
|
||||
@ -180,21 +188,32 @@ void CtrlDetours_BuyCommands(bool set)
|
||||
g_BuyItemDetour = DETOUR_CREATE_STATIC_FIXED(BuyItem, buyItemAddress);
|
||||
g_BuyGunAmmoDetour = DETOUR_CREATE_STATIC_FIXED(BuyGunAmmo, buyGunAmmoAddress);
|
||||
|
||||
if (g_CanBuyThisDetour != NULL && g_BuyItemDetour != NULL && g_BuyGunAmmoDetour != NULL)
|
||||
{
|
||||
g_CanBuyThisDetour->EnableDetour();
|
||||
g_BuyItemDetour->EnableDetour();
|
||||
g_BuyGunAmmoDetour->EnableDetour();
|
||||
}
|
||||
else
|
||||
if (g_CanBuyThisDetour == NULL || g_BuyItemDetour == NULL || g_BuyGunAmmoDetour == NULL)
|
||||
{
|
||||
MF_Log("No Buy Commands detours could be initialized - Disabled Buy forward.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_CanBuyThisDetour)
|
||||
g_CanBuyThisDetour->Destroy();
|
||||
|
||||
if (g_BuyItemDetour)
|
||||
g_BuyItemDetour->Destroy();
|
||||
|
||||
if (g_BuyGunAmmoDetour)
|
||||
g_BuyGunAmmoDetour->Destroy();
|
||||
g_ClientCommandDetour->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
void ToggleDetour_BuyCommands(bool enable)
|
||||
{
|
||||
if (g_CanBuyThisDetour)
|
||||
(enable) ? g_CanBuyThisDetour->EnableDetour() : g_CanBuyThisDetour->DisableDetour();
|
||||
|
||||
if (g_BuyItemDetour)
|
||||
(enable) ? g_BuyItemDetour->EnableDetour() : g_BuyItemDetour->DisableDetour();
|
||||
|
||||
if (g_BuyGunAmmoDetour)
|
||||
(enable) ? g_BuyGunAmmoDetour->EnableDetour() : g_BuyGunAmmoDetour->DisableDetour();
|
||||
}
|
@ -120,3 +120,23 @@ void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden, const char *li
|
||||
|
||||
return finalAddress != NULL ? finalAddress : NULL;
|
||||
}
|
||||
|
||||
bool UTIL_CheckForPublic(const char *publicname)
|
||||
{
|
||||
AMX* amx;
|
||||
int iFunctionIndex;
|
||||
int i = 0;
|
||||
char blah[64];
|
||||
|
||||
strncpy(blah, publicname, sizeof(blah)- 1);
|
||||
|
||||
while ((amx = MF_GetScriptAmx(i++)) != NULL)
|
||||
{
|
||||
if (MF_AmxFindPublic(amx, blah, &iFunctionIndex) == AMX_ERR_NONE)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
@ -36,6 +36,7 @@
|
||||
bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer);
|
||||
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message);
|
||||
void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden = false, const char *library = "mod");
|
||||
bool UTIL_CheckForPublic(const char *publicname);
|
||||
|
||||
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
|
||||
|
@ -31,6 +31,7 @@
|
||||
* version.
|
||||
*/
|
||||
#include "amxxmodule.h"
|
||||
#include "CstrikeUtils.h"
|
||||
|
||||
extern AMX_NATIVE_INFO cstrikeNatives[];
|
||||
|
||||
@ -39,6 +40,9 @@ extern int g_CSBuyCmdFwd;
|
||||
|
||||
void InitializeHacks();
|
||||
void ShutdownHacks();
|
||||
void ToggleDetour_ClientCommands(bool enable);
|
||||
void ToggleDetour_BuyCommands(bool enable);
|
||||
|
||||
|
||||
int AmxxCheckGame(const char *game)
|
||||
{
|
||||
@ -60,6 +64,9 @@ void OnPluginsLoaded()
|
||||
{
|
||||
g_CSCliCmdFwd = MF_RegisterForward("CS_InternalCommand", ET_STOP, FP_CELL, FP_STRING, FP_DONE);
|
||||
g_CSBuyCmdFwd = MF_RegisterForward("CS_OnBuy", ET_STOP, FP_CELL, FP_CELL, FP_DONE);
|
||||
|
||||
ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand"));
|
||||
ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy"));
|
||||
}
|
||||
|
||||
void OnAmxxDetach()
|
||||
|
Loading…
Reference in New Issue
Block a user