More Windows build fix.
3 * =============================================================================
4 * SourceMod Team Fortress 2 Extension
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #include "criticals.h"
34 IServerGameEnts *gameents = NULL;
36 CDetour *calcIsAttackCriticalDetour = NULL;
37 CDetour *calcIsAttackCriticalMeleeDetour = NULL;
38 CDetour *calcIsAttackCriticalBowDetour = NULL;
40 IForward *g_critForward = NULL;
49 int CheckBaseHandle(CBaseHandle &hndl)
56 int index = hndl.GetEntryIndex();
58 edict_t *pStoredEdict;
60 pStoredEdict = engine->PEntityOfEntIndex(index);
62 if (pStoredEdict == NULL)
67 IServerEntity *pSE = pStoredEdict->GetIServerEntity();
74 if (pSE->GetRefEHandle() != hndl)
82 DetourResult DetourCallback(CBaseEntity *pEnt)
84 edict_t *pEdict = gameents->BaseEntityToEdict((CBaseEntity *)pEnt);
88 g_pSM->LogMessage(myself, "Entity Error");
92 sm_sendprop_info_t info;
94 if (!gamehelpers->FindSendPropInfo(pEdict->GetNetworkable()->GetServerClass()->GetName(), "m_hOwnerEntity", &info))
96 g_pSM->LogMessage(myself, "Offset Error");
102 g_pSM->LogMessage(myself, "Invalid Forward");
103 return Result_Ignore;
108 CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)pEnt + info.actual_offset);
109 int index = CheckBaseHandle(hndl);
111 g_critForward->PushCell(index); //Client index
112 g_critForward->PushCell(engine->IndexOfEdict(pEdict)); // Weapon index
113 g_critForward->PushString(pEdict->GetClassName()); //Weapon classname
114 g_critForward->PushCellByRef(&returnValue); //return value
118 g_critForward->Execute(&result);
128 return Result_NoCrit;
133 return Result_Ignore;
137 DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelperMelee, bool)
139 DetourResult result = DetourCallback((CBaseEntity *)this);
141 if (result == Result_Ignore)
143 return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelperMelee)();
145 else if (result == Result_NoCrit)
155 DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelper, bool)
157 DetourResult result = DetourCallback((CBaseEntity *)this);
159 if (result == Result_Ignore)
161 return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelper)();
163 else if (result == Result_NoCrit)
173 DETOUR_DECL_MEMBER0(CalcIsAttackCriticalHelperBow, bool)
175 DetourResult result = DetourCallback((CBaseEntity *)this);
177 if (result == Result_Ignore)
179 return DETOUR_MEMBER_CALL(CalcIsAttackCriticalHelperBow)();
181 else if (result == Result_NoCrit)
191 bool InitialiseCritDetours()
193 calcIsAttackCriticalDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelper, "CalcCritical");
194 calcIsAttackCriticalMeleeDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelperMelee, "CalcCriticalMelee");
195 calcIsAttackCriticalBowDetour = DETOUR_CREATE_MEMBER(CalcIsAttackCriticalHelperBow, "CalcCriticalBow");
197 bool HookCreated = false;
199 if (calcIsAttackCriticalDetour != NULL)
201 calcIsAttackCriticalDetour->EnableDetour();
205 if (calcIsAttackCriticalMeleeDetour != NULL)
207 calcIsAttackCriticalMeleeDetour->EnableDetour();
211 if (calcIsAttackCriticalBowDetour != NULL)
213 calcIsAttackCriticalBowDetour->EnableDetour();
222 g_pSM->LogError(myself, "No critical hit forwards could be initialized - Disabled critical hit hooks");
227 void RemoveCritDetours()
229 if (calcIsAttackCriticalDetour != NULL)
231 calcIsAttackCriticalDetour->Destroy();
232 calcIsAttackCriticalDetour = NULL;
235 if (calcIsAttackCriticalMeleeDetour != NULL)
237 calcIsAttackCriticalMeleeDetour->Destroy();
238 calcIsAttackCriticalMeleeDetour = NULL;
241 if (calcIsAttackCriticalBowDetour != NULL)
243 calcIsAttackCriticalBowDetour->Destroy();
244 calcIsAttackCriticalBowDetour = NULL;