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 "extension.h"
|
|
|
|
#include <jit/jit_helpers.h>
|
|
|
|
#include <jit/x86/x86_macros.h>
|
|
|
|
#include "detours.h"
|
|
|
|
|
|
|
|
class CriticalHitManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CriticalHitManager()
|
|
|
|
{
|
|
|
|
enabled = false;
|
|
|
|
detoured = false;
|
|
|
|
critical_address = NULL;
|
|
|
|
critical_callback = NULL;
|
|
|
|
|
|
|
|
melee_address = NULL;
|
|
|
|
melee_callback = NULL;
|
|
|
|
|
|
|
|
knife_address = NULL;
|
|
|
|
knife_callback = NULL;
|
|
|
|
|
|
|
|
forward = NULL;
|
2008-05-01 09:29:46 +02:00
|
|
|
|
|
|
|
normalcreated = false;
|
|
|
|
meleecreated = false;
|
|
|
|
knifecreated = false;
|
2008-04-10 06:49:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
~CriticalHitManager()
|
|
|
|
{
|
|
|
|
forwards->ReleaseForward(forward);
|
|
|
|
DeleteCriticalDetour();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Init()
|
|
|
|
{
|
2008-05-01 09:29:46 +02:00
|
|
|
normalcreated = CreateCriticalDetour();
|
|
|
|
meleecreated = CreateCriticalMeleeDetour();
|
|
|
|
knifecreated = CreateCriticalKnifeDetour();
|
|
|
|
|
|
|
|
if (!normalcreated && !meleecreated && !knifecreated)
|
2008-04-10 06:49:17 +02:00
|
|
|
{
|
|
|
|
enabled = false;
|
2008-05-01 09:29:46 +02:00
|
|
|
g_pSM->LogError(myself, "No critical hit forwards could be initialised - Disabled critical hit hooks");
|
2008-04-10 06:49:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
forward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef);
|
|
|
|
|
|
|
|
if (!forward)
|
|
|
|
{
|
|
|
|
g_pSM->LogError(myself, "Failed to create forward - Disabling critical hit hook");
|
|
|
|
enabled = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Only enable this once forwards exist. Requires IForwardListener functionality */
|
|
|
|
EnableCriticalDetour();
|
|
|
|
|
|
|
|
enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsEnabled()
|
|
|
|
{
|
|
|
|
return enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CriticalDetour(void *pWeapon);
|
|
|
|
|
|
|
|
private:
|
|
|
|
IForward *forward;
|
|
|
|
|
|
|
|
/* These create/delete the allocated memory */
|
|
|
|
bool CreateCriticalDetour();
|
|
|
|
bool CreateCriticalMeleeDetour();
|
|
|
|
bool CreateCriticalKnifeDetour();
|
|
|
|
void DeleteCriticalDetour();
|
|
|
|
|
2008-05-01 09:29:46 +02:00
|
|
|
bool normalcreated;
|
|
|
|
bool meleecreated;
|
|
|
|
bool knifecreated;
|
|
|
|
|
2008-04-10 06:49:17 +02:00
|
|
|
/* These patch/unpatch the server.dll */
|
|
|
|
void EnableCriticalDetour();
|
|
|
|
void DisableCriticalDetour();
|
|
|
|
|
|
|
|
bool enabled;
|
|
|
|
bool detoured;
|
|
|
|
|
|
|
|
patch_t critical_restore;
|
|
|
|
void *critical_address;
|
|
|
|
void *critical_callback;
|
|
|
|
|
|
|
|
patch_t melee_restore;
|
|
|
|
void *melee_address;
|
|
|
|
void *melee_callback;
|
|
|
|
|
|
|
|
patch_t knife_restore;
|
|
|
|
void *knife_address;
|
|
|
|
void *knife_callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TempDetour(void *pWeapon);
|
|
|
|
|
|
|
|
extern ISourcePawnEngine *spengine;
|
|
|
|
extern IServerGameEnts *gameents;
|
|
|
|
extern CriticalHitManager g_CriticalHitManager;
|