Fixed Critical hits being permanently disabled (bug 2674, r=dvander)
This commit is contained in:
parent
8541040bb9
commit
407e58604f
@ -39,6 +39,13 @@ CDetour *calcIsAttackCriticalKnifeDetour = NULL;
|
|||||||
|
|
||||||
IForward *g_critForward = NULL;
|
IForward *g_critForward = NULL;
|
||||||
|
|
||||||
|
enum DetourResult
|
||||||
|
{
|
||||||
|
Result_Ignore,
|
||||||
|
Result_NoCrit,
|
||||||
|
Result_Crit,
|
||||||
|
};
|
||||||
|
|
||||||
int CheckBaseHandle(CBaseHandle &hndl)
|
int CheckBaseHandle(CBaseHandle &hndl)
|
||||||
{
|
{
|
||||||
if (!hndl.IsValid())
|
if (!hndl.IsValid())
|
||||||
@ -72,14 +79,14 @@ int CheckBaseHandle(CBaseHandle &hndl)
|
|||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelper, bool)
|
DetourResult DetourCallback(CBaseEntity *pEnt)
|
||||||
{
|
{
|
||||||
edict_t *pEdict = gameents->BaseEntityToEdict((CBaseEntity *)this);
|
edict_t *pEdict = gameents->BaseEntityToEdict((CBaseEntity *)pEnt);
|
||||||
|
|
||||||
if (!pEdict)
|
if (!pEdict)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Entity Error");
|
g_pSM->LogMessage(myself, "Entity Error");
|
||||||
return false;
|
return Result_Ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
sm_sendprop_info_t info;
|
sm_sendprop_info_t info;
|
||||||
@ -87,18 +94,18 @@ DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelper, bool)
|
|||||||
if (!gamehelpers->FindSendPropInfo(pEdict->GetNetworkable()->GetServerClass()->GetName(), "m_hOwnerEntity", &info))
|
if (!gamehelpers->FindSendPropInfo(pEdict->GetNetworkable()->GetServerClass()->GetName(), "m_hOwnerEntity", &info))
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Offset Error");
|
g_pSM->LogMessage(myself, "Offset Error");
|
||||||
return false;
|
return Result_Ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!g_critForward)
|
if (!g_critForward)
|
||||||
{
|
{
|
||||||
g_pSM->LogMessage(myself, "Invalid Forward");
|
g_pSM->LogMessage(myself, "Invalid Forward");
|
||||||
return false;
|
return Result_Ignore;
|
||||||
}
|
}
|
||||||
|
|
||||||
int returnValue=0;
|
int returnValue=0;
|
||||||
|
|
||||||
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)this + info.actual_offset);
|
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEnt + info.actual_offset);
|
||||||
int index = CheckBaseHandle(hndl);
|
int index = CheckBaseHandle(hndl);
|
||||||
|
|
||||||
g_critForward->PushCell(index); //Client index
|
g_critForward->PushCell(index); //Client index
|
||||||
@ -112,20 +119,80 @@ DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelper, bool)
|
|||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
return !!returnValue;
|
if (returnValue)
|
||||||
|
{
|
||||||
|
return Result_Crit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Result_NoCrit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
return Result_Ignore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelperMelee, bool)
|
||||||
|
{
|
||||||
|
DetourResult result = DetourCallback((CBaseEntity *)this);
|
||||||
|
|
||||||
|
if (result == Result_Ignore)
|
||||||
|
{
|
||||||
|
return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelperMelee)();
|
||||||
|
}
|
||||||
|
else if (result == Result_NoCrit)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelperKnife, bool)
|
||||||
|
{
|
||||||
|
DetourResult result = DetourCallback((CBaseEntity *)this);
|
||||||
|
|
||||||
|
if (result == Result_Ignore)
|
||||||
|
{
|
||||||
|
return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelperKnife)();
|
||||||
|
}
|
||||||
|
else if (result == Result_NoCrit)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelper, bool)
|
||||||
|
{
|
||||||
|
DetourResult result = DetourCallback((CBaseEntity *)this);
|
||||||
|
|
||||||
|
if (result == Result_Ignore)
|
||||||
{
|
{
|
||||||
return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelper)();
|
return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelper)();
|
||||||
}
|
}
|
||||||
|
else if (result == Result_NoCrit)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitialiseDetours()
|
void InitialiseDetours()
|
||||||
{
|
{
|
||||||
calcIsAttackCriticalDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCritical");
|
calcIsAttackCriticalDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCritical");
|
||||||
calcIsAttackCriticalMeleeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCriticalMelee");
|
calcIsAttackCriticalMeleeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelperMelee, "CalcCriticalMelee");
|
||||||
calcIsAttackCriticalKnifeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCriticalKnife");
|
calcIsAttackCriticalKnifeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelperKnife, "CalcCriticalKnife");
|
||||||
|
|
||||||
bool HookCreated = false;
|
bool HookCreated = false;
|
||||||
|
|
||||||
|
@ -102,12 +102,16 @@ bool TF2Tools::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
|||||||
sharesys->AddNatives(myself, g_TFNatives);
|
sharesys->AddNatives(myself, g_TFNatives);
|
||||||
sharesys->RegisterLibrary(myself, "tf2");
|
sharesys->RegisterLibrary(myself, "tf2");
|
||||||
|
|
||||||
|
plsys->AddPluginsListener(this);
|
||||||
|
|
||||||
playerhelpers->RegisterCommandTargetProcessor(this);
|
playerhelpers->RegisterCommandTargetProcessor(this);
|
||||||
|
|
||||||
g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef);
|
g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef);
|
||||||
|
|
||||||
g_pCVar = icvar;
|
g_pCVar = icvar;
|
||||||
|
|
||||||
|
m_DetoursEnabled = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,16 +141,14 @@ void TF2Tools::SDK_OnUnload()
|
|||||||
gameconfs->CloseGameConfigFile(g_pGameConf);
|
gameconfs->CloseGameConfigFile(g_pGameConf);
|
||||||
playerhelpers->UnregisterCommandTargetProcessor(this);
|
playerhelpers->UnregisterCommandTargetProcessor(this);
|
||||||
|
|
||||||
forwards->ReleaseForward(g_critForward);
|
plsys->RemovePluginsListener(this);
|
||||||
|
|
||||||
RemoveDetours();
|
forwards->ReleaseForward(g_critForward);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TF2Tools::SDK_OnAllLoaded()
|
void TF2Tools::SDK_OnAllLoaded()
|
||||||
{
|
{
|
||||||
SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
|
SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
|
||||||
|
|
||||||
InitialiseDetours();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TF2Tools::RegisterConCommandBase(ConCommandBase *pVar)
|
bool TF2Tools::RegisterConCommandBase(ConCommandBase *pVar)
|
||||||
@ -187,7 +189,6 @@ void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
|
|||||||
g_resourceEntity = FindResourceEntity();
|
g_resourceEntity = FindResourceEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool TF2Tools::ProcessCommandTarget(cmd_target_info_t *info)
|
bool TF2Tools::ProcessCommandTarget(cmd_target_info_t *info)
|
||||||
{
|
{
|
||||||
int max_clients;
|
int max_clients;
|
||||||
@ -283,6 +284,23 @@ bool TF2Tools::ProcessCommandTarget(cmd_target_info_t *info)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TF2Tools::OnPluginLoaded(IPlugin *plugin)
|
||||||
|
{
|
||||||
|
if (!m_DetoursEnabled && g_critForward->GetFunctionCount())
|
||||||
|
{
|
||||||
|
InitialiseDetours();
|
||||||
|
m_DetoursEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
|
||||||
|
{
|
||||||
|
if (m_DetoursEnabled && !g_critForward->GetFunctionCount())
|
||||||
|
{
|
||||||
|
RemoveDetours();
|
||||||
|
m_DetoursEnabled = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
int FindResourceEntity()
|
int FindResourceEntity()
|
||||||
{
|
{
|
||||||
return FindEntityByNetClass(-1, "CTFPlayerResource");
|
return FindEntityByNetClass(-1, "CTFPlayerResource");
|
||||||
|
@ -50,9 +50,10 @@ class TF2Tools :
|
|||||||
public SDKExtension,
|
public SDKExtension,
|
||||||
public ICommandTargetProcessor,
|
public ICommandTargetProcessor,
|
||||||
public IConCommandBaseAccessor,
|
public IConCommandBaseAccessor,
|
||||||
public IGameEventListener2
|
public IGameEventListener2,
|
||||||
|
public IPluginsListener
|
||||||
{
|
{
|
||||||
public:
|
public: //SDKExtension
|
||||||
/**
|
/**
|
||||||
* @brief This is called after the initial loading sequence has been processed.
|
* @brief This is called after the initial loading sequence has been processed.
|
||||||
*
|
*
|
||||||
@ -74,11 +75,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void SDK_OnAllLoaded();
|
virtual void SDK_OnAllLoaded();
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Called when the pause state is changed.
|
|
||||||
*/
|
|
||||||
//virtual void SDK_OnPauseChange(bool paused);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief this is called when Core wants to know if your extension is working.
|
* @brief this is called when Core wants to know if your extension is working.
|
||||||
*
|
*
|
||||||
@ -90,12 +86,16 @@ public:
|
|||||||
|
|
||||||
void NotifyInterfaceDrop(SMInterface *pInterface);
|
void NotifyInterfaceDrop(SMInterface *pInterface);
|
||||||
bool QueryInterfaceDrop(SMInterface *pInterface);
|
bool QueryInterfaceDrop(SMInterface *pInterface);
|
||||||
public:
|
public: //ICommandTargetProcessor
|
||||||
bool ProcessCommandTarget(cmd_target_info_t *info);
|
bool ProcessCommandTarget(cmd_target_info_t *info);
|
||||||
|
public: //IConCommandBaseAccessor
|
||||||
bool RegisterConCommandBase(ConCommandBase *pVar);
|
bool RegisterConCommandBase(ConCommandBase *pVar);
|
||||||
|
public: //IGameEventManager
|
||||||
IGameEventManager2 *m_GameEventManager;
|
IGameEventManager2 *m_GameEventManager;
|
||||||
void FireGameEvent( IGameEvent *event );
|
void FireGameEvent( IGameEvent *event );
|
||||||
|
public: //IPluginsListener
|
||||||
|
void OnPluginLoaded(IPlugin *plugin);
|
||||||
|
void OnPluginUnloaded(IPlugin *plugin);
|
||||||
public:
|
public:
|
||||||
#if defined SMEXT_CONF_METAMOD
|
#if defined SMEXT_CONF_METAMOD
|
||||||
/**
|
/**
|
||||||
@ -107,28 +107,9 @@ public:
|
|||||||
* @return True to succeed, false to fail.
|
* @return True to succeed, false to fail.
|
||||||
*/
|
*/
|
||||||
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
|
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Called when Metamod is detaching, after the extension version is called.
|
|
||||||
* NOTE: By default this is blocked unless sent from SourceMod.
|
|
||||||
*
|
|
||||||
* @param error Error buffer.
|
|
||||||
* @param maxlength Maximum size of error buffer.
|
|
||||||
* @return True to succeed, false to fail.
|
|
||||||
*/
|
|
||||||
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Called when Metamod's pause state is changing.
|
|
||||||
* NOTE: By default this is blocked unless sent from SourceMod.
|
|
||||||
*
|
|
||||||
* @param paused Pause state being set.
|
|
||||||
* @param error Error buffer.
|
|
||||||
* @param maxlength Maximum size of error buffer.
|
|
||||||
* @return True to succeed, false to fail.
|
|
||||||
*/
|
|
||||||
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength);
|
|
||||||
#endif
|
#endif
|
||||||
|
private:
|
||||||
|
bool m_DetoursEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TFClassType
|
enum TFClassType
|
||||||
|
@ -72,5 +72,6 @@
|
|||||||
//#define SMEXT_ENABLE_THREADER
|
//#define SMEXT_ENABLE_THREADER
|
||||||
//#define SMEXT_ENABLE_LIBSYS
|
//#define SMEXT_ENABLE_LIBSYS
|
||||||
//#define SMEXT_ENABLE_USERMSGS
|
//#define SMEXT_ENABLE_USERMSGS
|
||||||
|
#define SMEXT_ENABLE_PLUGINSYS
|
||||||
|
|
||||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
|
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
|
||||||
|
@ -76,6 +76,9 @@
|
|||||||
#if defined SMEXT_ENABLE_USERMSGS
|
#if defined SMEXT_ENABLE_USERMSGS
|
||||||
#include <IUserMessages.h>
|
#include <IUserMessages.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if defined SMEXT_ENABLE_PLUGINSYS
|
||||||
|
#include <IPluginSys.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined SMEXT_CONF_METAMOD
|
#if defined SMEXT_CONF_METAMOD
|
||||||
#include <ISmmPlugin.h>
|
#include <ISmmPlugin.h>
|
||||||
@ -266,6 +269,9 @@ extern ILibrarySys *libsys;
|
|||||||
#if defined SMEXT_ENABLE_USERMSGS
|
#if defined SMEXT_ENABLE_USERMSGS
|
||||||
extern IUserMessages *usermsgs;
|
extern IUserMessages *usermsgs;
|
||||||
#endif
|
#endif
|
||||||
|
#if defined SMEXT_ENABLE_PLUGINSYS
|
||||||
|
extern IPluginManager *plsys;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined SMEXT_CONF_METAMOD
|
#if defined SMEXT_CONF_METAMOD
|
||||||
PLUGIN_GLOBALVARS();
|
PLUGIN_GLOBALVARS();
|
||||||
|
Loading…
Reference in New Issue
Block a user