2008-04-10 06:49:17 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
2008-04-11 19:16:36 +02:00
|
|
|
* SourceMod Team Fortress 2 Extension
|
2008-04-10 06:49:17 +02:00
|
|
|
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program 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
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "criticals.h"
|
|
|
|
|
|
|
|
IServerGameEnts *gameents = NULL;
|
|
|
|
|
2008-07-01 11:04:00 +02:00
|
|
|
CDetour *calcIsAttackCriticalDetour = NULL;
|
|
|
|
CDetour *calcIsAttackCriticalMeleeDetour = NULL;
|
|
|
|
CDetour *calcIsAttackCriticalKnifeDetour = NULL;
|
2008-04-10 06:49:17 +02:00
|
|
|
|
2008-07-01 11:04:00 +02:00
|
|
|
IForward *g_critForward = NULL;
|
2008-04-10 06:49:17 +02:00
|
|
|
|
|
|
|
int CheckBaseHandle(CBaseHandle &hndl)
|
|
|
|
{
|
|
|
|
if (!hndl.IsValid())
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int index = hndl.GetEntryIndex();
|
|
|
|
|
|
|
|
edict_t *pStoredEdict;
|
|
|
|
|
|
|
|
pStoredEdict = engine->PEntityOfEntIndex(index);
|
|
|
|
|
|
|
|
if (pStoredEdict == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerEntity *pSE = pStoredEdict->GetIServerEntity();
|
|
|
|
|
|
|
|
if (pSE == NULL)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pSE->GetRefEHandle() != hndl)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2009-02-26 00:42:13 +01:00
|
|
|
DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelper, bool)
|
2008-04-10 06:49:17 +02:00
|
|
|
{
|
2009-02-26 00:42:13 +01:00
|
|
|
edict_t *pEdict = gameents->BaseEntityToEdict((CBaseEntity *)this);
|
2008-04-10 06:49:17 +02:00
|
|
|
|
|
|
|
if (!pEdict)
|
|
|
|
{
|
|
|
|
g_pSM->LogMessage(myself, "Entity Error");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
sm_sendprop_info_t info;
|
|
|
|
|
|
|
|
if (!gamehelpers->FindSendPropInfo(pEdict->GetNetworkable()->GetServerClass()->GetName(), "m_hOwnerEntity", &info))
|
|
|
|
{
|
|
|
|
g_pSM->LogMessage(myself, "Offset Error");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-01 11:04:00 +02:00
|
|
|
if (!g_critForward)
|
2008-04-10 06:49:17 +02:00
|
|
|
{
|
|
|
|
g_pSM->LogMessage(myself, "Invalid Forward");
|
|
|
|
return false;
|
|
|
|
}
|
2008-07-01 11:04:00 +02:00
|
|
|
|
|
|
|
int returnValue=0;
|
2008-04-10 06:49:17 +02:00
|
|
|
|
2009-02-26 00:42:13 +01:00
|
|
|
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)this + info.actual_offset);
|
2008-04-10 06:49:17 +02:00
|
|
|
int index = CheckBaseHandle(hndl);
|
|
|
|
|
2008-07-01 11:04:00 +02:00
|
|
|
g_critForward->PushCell(index); //Client index
|
|
|
|
g_critForward->PushCell(engine->IndexOfEdict(pEdict)); // Weapon index
|
|
|
|
g_critForward->PushString(pEdict->GetClassName()); //Weapon classname
|
|
|
|
g_critForward->PushCellByRef(&returnValue); //return value
|
2008-04-10 06:49:17 +02:00
|
|
|
|
|
|
|
cell_t result = 0;
|
|
|
|
|
2008-07-01 11:04:00 +02:00
|
|
|
g_critForward->Execute(&result);
|
|
|
|
|
|
|
|
if (result)
|
|
|
|
{
|
2009-02-26 00:42:13 +01:00
|
|
|
return !!returnValue;
|
2008-07-01 11:04:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-26 00:42:13 +01:00
|
|
|
return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelper)();
|
2008-07-01 11:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2008-04-10 06:49:17 +02:00
|
|
|
|
2009-02-26 00:42:13 +01:00
|
|
|
void InitialiseDetours()
|
|
|
|
{
|
|
|
|
calcIsAttackCriticalDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCritical");
|
|
|
|
calcIsAttackCriticalMeleeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCriticalMelee");
|
|
|
|
calcIsAttackCriticalKnifeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCriticalKnife");
|
|
|
|
|
|
|
|
bool HookCreated = false;
|
|
|
|
|
|
|
|
if (calcIsAttackCriticalDetour != NULL)
|
|
|
|
{
|
|
|
|
calcIsAttackCriticalDetour->EnableDetour();
|
|
|
|
HookCreated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calcIsAttackCriticalMeleeDetour != NULL)
|
|
|
|
{
|
|
|
|
calcIsAttackCriticalMeleeDetour->EnableDetour();
|
|
|
|
HookCreated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (calcIsAttackCriticalKnifeDetour != NULL)
|
|
|
|
{
|
|
|
|
calcIsAttackCriticalKnifeDetour->EnableDetour();
|
|
|
|
HookCreated = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HookCreated)
|
|
|
|
{
|
|
|
|
g_pSM->LogError(myself, "No critical hit forwards could be initialized - Disabled critical hit hooks");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-07-01 11:04:00 +02:00
|
|
|
void RemoveDetours()
|
|
|
|
{
|
2009-02-26 00:42:13 +01:00
|
|
|
calcIsAttackCriticalDetour->Destroy();
|
|
|
|
calcIsAttackCriticalMeleeDetour->Destroy();
|
|
|
|
calcIsAttackCriticalKnifeDetour->Destroy();
|
2008-04-10 06:49:17 +02:00
|
|
|
}
|