Cstrike: cs_set_no_knives - pfnCreateNamedEntity is now hooked only when needed
This commit is contained in:
parent
2de1f9a33b
commit
71c6ac8c2e
@ -14,8 +14,8 @@
|
||||
#include "CstrikeDatas.h"
|
||||
#include "CstrikeUtils.h"
|
||||
#include "CstrikeHacks.h"
|
||||
#include <sm_stringhashmap.h>
|
||||
#include "CstrikeHLTypeConversion.h"
|
||||
#include <sm_stringhashmap.h>
|
||||
|
||||
void CtrlDetours_ClientCommand(bool set);
|
||||
void CtrlDetours_BuyCommands(bool set);
|
||||
@ -174,6 +174,35 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
|
||||
DETOUR_STATIC_CALL(C_ClientCommand)(pEdict);
|
||||
}
|
||||
|
||||
edict_s* OnCreateNamedEntity(int classname)
|
||||
{
|
||||
if (NoKifesMode)
|
||||
{
|
||||
if (!strcmp(STRING(classname), "weapon_knife"))
|
||||
{
|
||||
RETURN_META_VALUE(MRES_SUPERCEDE, nullptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_pengfuncsTable->pfnCreateNamedEntity = nullptr;
|
||||
}
|
||||
|
||||
RETURN_META_VALUE(MRES_IGNORED, 0);
|
||||
}
|
||||
|
||||
DETOUR_DECL_MEMBER0(GiveDefaultItems, void) // void CBasePlayer::GiveDefaultItems(void)
|
||||
{
|
||||
if (NoKifesMode)
|
||||
{
|
||||
g_pengfuncsTable->pfnCreateNamedEntity = OnCreateNamedEntity;
|
||||
}
|
||||
|
||||
DETOUR_MEMBER_CALL(GiveDefaultItems)();
|
||||
|
||||
g_pengfuncsTable->pfnCreateNamedEntity = nullptr;
|
||||
}
|
||||
|
||||
DETOUR_DECL_MEMBER1(GiveNamedItem, void, const char*, pszName) // void CBasePlayer::GiveNamedItem(const char *pszName)
|
||||
{
|
||||
// If the current item id is not null, this means player has triggers a buy command.
|
||||
@ -458,5 +487,22 @@ void CtrlDetours_Natives(bool set)
|
||||
{
|
||||
MF_Log("UTIL_FindEntByString is not available - native cs_find_ent_by_class() has been disabled");
|
||||
}
|
||||
|
||||
if (MainConfig->GetMemSig("GiveDefaultItems", &address))
|
||||
{
|
||||
GiveDefaultItemsDetour = DETOUR_CREATE_MEMBER_FIXED(GiveDefaultItems, address);
|
||||
}
|
||||
|
||||
if (!GiveDefaultItemsDetour)
|
||||
{
|
||||
MF_Log("GiveDefaultItems is not available - native cs_set_no_knives has been disabled");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (GiveDefaultItemsDetour)
|
||||
{
|
||||
GiveDefaultItemsDetour->Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
CCstrikePlayer g_players[33];
|
||||
int g_zooming[33] = {0};
|
||||
bool g_precachedknife = false;
|
||||
bool g_noknives = false;
|
||||
|
||||
bool NoKifesMode = false;
|
||||
|
||||
@ -946,8 +944,23 @@ static cell AMX_NATIVE_CALL cs_get_no_knives(AMX *amx, cell *params)
|
||||
// native cs_set_no_knives(noknives = 0);
|
||||
static cell AMX_NATIVE_CALL cs_set_no_knives(AMX *amx, cell *params)
|
||||
{
|
||||
if (!GiveDefaultItemsDetour)
|
||||
{
|
||||
MF_LogError(amx, AMX_ERR_NATIVE, "Native cs_set_no_knives() is disabled");
|
||||
return 0;
|
||||
}
|
||||
|
||||
NoKifesMode = params[1] != 0;
|
||||
|
||||
if (NoKifesMode)
|
||||
{
|
||||
GiveDefaultItemsDetour->EnableDetour();
|
||||
}
|
||||
else
|
||||
{
|
||||
GiveDefaultItemsDetour->DisableDetour();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1623,29 +1636,6 @@ AMX_NATIVE_INFO CstrikeNatives[] =
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
||||
edict_s* FN_CreateNamedEntity(int classname)
|
||||
{
|
||||
if (g_noknives && !strcmp(STRING(classname), "weapon_knife"))
|
||||
{
|
||||
if (g_precachedknife)
|
||||
{
|
||||
// Knife is creating
|
||||
RETURN_META_VALUE(MRES_SUPERCEDE, NULL);
|
||||
}
|
||||
// Let it create a knife first time; this seems to keep it precached properly in case anyone give_items a knife later.
|
||||
g_precachedknife = true;
|
||||
}
|
||||
|
||||
RETURN_META_VALUE(MRES_IGNORED, 0);
|
||||
}
|
||||
|
||||
void FN_ServerDeactivate()
|
||||
{
|
||||
g_precachedknife = false;
|
||||
|
||||
RETURN_META(MRES_IGNORED);
|
||||
}
|
||||
|
||||
void MessageBegin(int msg_dest, int msg_type, const float *pOrigin, edict_t *ed)
|
||||
{
|
||||
// Reset player model a short while (MODELRESETTIME) after this if they are using an edited model.
|
||||
|
@ -124,7 +124,7 @@
|
||||
// #define FN_ClientCommand ClientCommand /* pfnClientCommand() (wd) Player has sent a command (typed or from a bind) */
|
||||
#define FN_ClientUserInfoChanged ClientUserInfoChanged /* pfnClientUserInfoChanged() (wd) Client has updated their setinfo structure */
|
||||
// #define FN_ServerActivate ServerActivate /* pfnServerActivate() (wd) Server is starting a new map */
|
||||
#define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */
|
||||
// #define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */
|
||||
#define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */
|
||||
#define FN_PlayerPostThink PlayerPostThink /* pfnPlayerPostThink() */
|
||||
// #define FN_StartFrame StartFrame /* pfnStartFrame() */
|
||||
@ -229,7 +229,7 @@
|
||||
// #define FN_AngleVectors AngleVectors
|
||||
// #define FN_CreateEntity CreateEntity
|
||||
// #define FN_RemoveEntity RemoveEntity
|
||||
#define FN_CreateNamedEntity CreateNamedEntity
|
||||
// #define FN_CreateNamedEntity CreateNamedEntity
|
||||
// #define FN_MakeStatic MakeStatic
|
||||
// #define FN_EntIsOnFloor EntIsOnFloor
|
||||
// #define FN_DropToFloor DropToFloor
|
||||
|
Loading…
Reference in New Issue
Block a user