2016-05-12 16:10:42 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Sample Extension
|
|
|
|
* 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 "CDetour/detours.h"
|
2017-01-30 18:59:50 +01:00
|
|
|
#include "iplayerinfo.h"
|
|
|
|
#include <sourcehook.h>
|
2016-05-12 16:10:42 +02:00
|
|
|
#include <sh_memory.h>
|
2017-01-30 18:59:50 +01:00
|
|
|
#include <IEngineTrace.h>
|
2017-07-05 23:10:12 +02:00
|
|
|
#include <server_class.h>
|
2019-10-01 18:49:38 +02:00
|
|
|
#include <ispatialpartition.h>
|
2017-07-05 23:10:12 +02:00
|
|
|
|
|
|
|
bool UTIL_ContainsDataTable(SendTable *pTable, const char *name)
|
|
|
|
{
|
|
|
|
const char *pname = pTable->GetName();
|
|
|
|
int props = pTable->GetNumProps();
|
|
|
|
SendProp *prop;
|
|
|
|
SendTable *table;
|
|
|
|
|
|
|
|
if (pname && strcmp(name, pname) == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
for (int i=0; i<props; i++)
|
|
|
|
{
|
|
|
|
prop = pTable->GetProp(i);
|
|
|
|
|
|
|
|
if ((table = prop->GetDataTable()) != NULL)
|
|
|
|
{
|
|
|
|
pname = table->GetName();
|
|
|
|
if (pname && strcmp(name, pname) == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (UTIL_ContainsDataTable(table, name))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
class CTraceFilterSimple : public CTraceFilter
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask ) = 0;
|
|
|
|
virtual void SetPassEntity( const IHandleEntity *pPassEntity ) = 0;
|
|
|
|
virtual void SetCollisionGroup( int iCollisionGroup ) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CTraceFilterSkipTwoEntities : public CTraceFilterSimple
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask ) = 0;
|
|
|
|
virtual void SetPassEntity2( const IHandleEntity *pPassEntity2 ) = 0;
|
|
|
|
};
|
2016-05-12 16:10:42 +02:00
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
class CTriggerMoved : public IPartitionEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity ) = 0;
|
|
|
|
};
|
|
|
|
|
2019-10-04 11:17:47 +02:00
|
|
|
class CTouchLinks : public IPartitionEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual IterationRetval_t EnumElement( IHandleEntity *pHandleEntity ) = 0;
|
|
|
|
};
|
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
static struct SrcdsPatch
|
|
|
|
{
|
|
|
|
const char *pSignature;
|
|
|
|
const unsigned char *pPatchSignature;
|
|
|
|
const char *pPatchPattern;
|
|
|
|
const unsigned char *pPatch;
|
|
|
|
|
|
|
|
unsigned char *pOriginal;
|
|
|
|
uintptr_t pAddress;
|
|
|
|
uintptr_t pPatchAddress;
|
2019-09-25 21:05:37 +02:00
|
|
|
bool engine;
|
2016-05-12 16:10:42 +02:00
|
|
|
} gs_Patches[] = {
|
2019-09-25 21:05:37 +02:00
|
|
|
// 0: game_ui should not apply FL_ONTRAIN flag, else client prediction turns off
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
|
|
|
"_ZN7CGameUI5ThinkEv",
|
|
|
|
(unsigned char *)"\xC7\x44\x24\x04\x10\x00\x00\x00\x89\x34\x24\xE8\x00\x00\x00\x00",
|
|
|
|
"xxxxxxxxxxxx????",
|
|
|
|
(unsigned char *)"\xC7\x44\x24\x04\x10\x00\x00\x00\x89\x34\x24\x90\x90\x90\x90\x90",
|
2019-09-25 21:05:37 +02:00
|
|
|
0, 0, 0, false
|
2016-05-12 16:10:42 +02:00
|
|
|
},
|
2019-09-25 21:05:37 +02:00
|
|
|
// 1: player_speedmod should not turn off flashlight
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
|
|
|
"_ZN17CMovementSpeedMod13InputSpeedModER11inputdata_t",
|
|
|
|
(unsigned char *)"\xFF\x90\x8C\x05\x00\x00\x85\xC0\x0F\x85\x75\x02\x00\x00",
|
|
|
|
"xxxxxxxxxxxxxx",
|
|
|
|
(unsigned char *)"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90",
|
2019-09-25 21:05:37 +02:00
|
|
|
0, 0, 0, false
|
2016-12-18 02:08:25 +01:00
|
|
|
},
|
2019-09-25 21:05:37 +02:00
|
|
|
// 2: only select CT spawnpoints
|
2016-12-18 02:08:25 +01:00
|
|
|
{
|
|
|
|
"_ZN9CCSPlayer19EntSelectSpawnPointEv",
|
|
|
|
(unsigned char *)"\x89\x1C\x24\xE8\x00\x00\x00\x00\x83\xF8\x03\x74\x4B",
|
|
|
|
"xxxx????xxxxx",
|
|
|
|
(unsigned char *)"\x89\x1C\x24\x90\x90\x90\x90\x90\x90\x90\x90\xEB\x4B",
|
2019-09-25 21:05:37 +02:00
|
|
|
0, 0, 0, false
|
2016-12-18 02:08:25 +01:00
|
|
|
},
|
2019-09-25 21:05:37 +02:00
|
|
|
// 3: don't check if we have T spawns
|
2016-12-18 02:08:25 +01:00
|
|
|
{
|
|
|
|
"_ZN12CCSGameRules18NeededPlayersCheckERb",
|
|
|
|
(unsigned char *)"\x74\x0E\x8B\x83\x80\x02\x00\x00\x85\xC0\x0F\x85\x9E\x00\x00\x00\xC7\x04\x24\xAC\xF7\x87\x00\xE8\xC2\x82\x91\x00",
|
|
|
|
"xxxxxxxxxxxxxxxx????????????",
|
|
|
|
(unsigned char *)"\x0F\x85\xA8\x00\x00\x00\x8B\x83\x80\x02\x00\x00\x85\xC0\x0F\x85\x9A\x00\x00\x00\x90\x90\x90\x90\x90\x90\x90\x90",
|
2019-09-25 21:05:37 +02:00
|
|
|
0, 0, 0, false
|
2017-07-05 23:10:12 +02:00
|
|
|
},
|
|
|
|
// 4: Special
|
|
|
|
{
|
|
|
|
"_Z25Physics_RunThinkFunctionsb",
|
|
|
|
(unsigned char *)"\x8B\x04\x9E\x85\xC0\x74\x13\xA1\x00\x00\x00\x00\x89\x78\x0C\x8B\x04\x9E\x89\x04\x24\xE8\x00\x00\x00\x00",
|
|
|
|
"xxxxxxxx????xxxxxxxxxx????",
|
|
|
|
NULL,
|
2019-09-25 21:05:37 +02:00
|
|
|
0, 0, 0, false
|
|
|
|
},
|
2016-05-12 16:10:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CBaseEntity;
|
|
|
|
struct variant_hax
|
|
|
|
{
|
|
|
|
const char *pszValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct inputdata_t
|
|
|
|
{
|
|
|
|
// The entity that initially caused this chain of output events.
|
|
|
|
CBaseEntity *pActivator;
|
|
|
|
// The entity that fired this particular output.
|
|
|
|
CBaseEntity *pCaller;
|
|
|
|
// The data parameter for this output.
|
|
|
|
variant_hax value;
|
|
|
|
// The unique ID of the output that was fired.
|
|
|
|
int nOutputID;
|
|
|
|
};
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
typedef bool (*ShouldHitFunc_t)( IHandleEntity *pHandleEntity, int contentsMask );
|
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
uintptr_t FindPattern(uintptr_t BaseAddr, const unsigned char *pData, const char *pPattern, size_t MaxSize);
|
2017-07-05 23:10:12 +02:00
|
|
|
uintptr_t FindFunctionCall(uintptr_t BaseAddr, uintptr_t Function, size_t MaxSize);
|
2016-05-12 16:10:42 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @file extension.cpp
|
|
|
|
* @brief Implement extension code here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CSSFixes g_Interface;
|
|
|
|
SMEXT_LINK(&g_Interface);
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
CGlobalVars *gpGlobals = NULL;
|
2016-05-12 16:10:42 +02:00
|
|
|
IGameConfig *g_pGameConf = NULL;
|
|
|
|
|
2016-12-16 23:45:05 +01:00
|
|
|
IForward *g_pOnRunThinkFunctions = NULL;
|
2019-10-01 18:49:38 +02:00
|
|
|
IForward *g_pOnPrePlayerThinkFunctions = NULL;
|
|
|
|
IForward *g_pOnPostPlayerThinkFunctions = NULL;
|
2016-12-16 23:45:05 +01:00
|
|
|
IForward *g_pOnRunThinkFunctionsPost = NULL;
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
CDetour *g_pDetour_InputTestActivator = NULL;
|
|
|
|
CDetour *g_pDetour_PostConstructor = NULL;
|
|
|
|
CDetour *g_pDetour_FindUseEntity = NULL;
|
|
|
|
CDetour *g_pDetour_CTraceFilterSimple = NULL;
|
|
|
|
CDetour *g_pDetour_RunThinkFunctions = NULL;
|
|
|
|
CDetour *g_pDetour_KeyValue = NULL;
|
|
|
|
CDetour *g_pDetour_FireBullets = NULL;
|
2017-07-05 23:10:12 +02:00
|
|
|
CDetour *g_pDetour_SwingOrStab = NULL;
|
|
|
|
int g_SH_SkipTwoEntitiesShouldHitEntity = 0;
|
|
|
|
int g_SH_SimpleShouldHitEntity = 0;
|
2019-10-01 18:49:38 +02:00
|
|
|
int g_SH_TriggerMoved = 0;
|
2019-10-04 11:17:47 +02:00
|
|
|
int g_SH_TouchLinks = 0;
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
uintptr_t g_CTraceFilterNoNPCsOrPlayer = 0;
|
|
|
|
CTraceFilterSkipTwoEntities *g_CTraceFilterSkipTwoEntities = NULL;
|
2017-07-05 23:10:12 +02:00
|
|
|
CTraceFilterSimple *g_CTraceFilterSimple = NULL;
|
2019-10-01 18:49:38 +02:00
|
|
|
CTriggerMoved *g_CTriggerMoved = 0;
|
2019-10-04 11:17:47 +02:00
|
|
|
CTouchLinks *g_CTouchLinks = 0;
|
2016-05-12 16:10:42 +02:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
/* Fix crash in CBaseFilter::InputTestActivator */
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_DECL_MEMBER1(DETOUR_InputTestActivator, void, inputdata_t *, inputdata)
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
|
|
|
if(!inputdata || !inputdata->pActivator || !inputdata->pCaller)
|
|
|
|
return;
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_MEMBER_CALL(DETOUR_InputTestActivator)(inputdata);
|
2016-05-12 16:10:42 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_DECL_MEMBER1(DETOUR_PostConstructor, void, const char *, szClassname)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
2016-12-18 02:08:25 +01:00
|
|
|
if(strncasecmp(szClassname, "info_player_", 12) == 0)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)this;
|
|
|
|
|
|
|
|
datamap_t *pMap = gamehelpers->GetDataMap(pEntity);
|
|
|
|
typedescription_t *td = gamehelpers->FindInDataMap(pMap, "m_iEFlags");
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
// Spawnpoints don't need edicts...
|
2016-08-18 06:41:58 +02:00
|
|
|
*(uint32 *)((intptr_t)pEntity + td->fieldOffset[TD_OFFSET_NORMAL]) |= (1<<9); // EFL_SERVER_ONLY
|
2016-12-19 03:31:42 +01:00
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
// Only CT spawnpoints
|
2016-12-19 03:31:42 +01:00
|
|
|
if(strcasecmp(szClassname, "info_player_terrorist") == 0)
|
2016-12-19 08:26:58 +01:00
|
|
|
szClassname = "info_player_counterterrorist";
|
2016-08-18 06:41:58 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_MEMBER_CALL(DETOUR_PostConstructor)(szClassname);
|
2016-08-18 06:41:58 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_DECL_MEMBER2(DETOUR_KeyValue, bool, const char *, szKeyName, const char *, szValue)
|
2016-12-18 02:08:25 +01:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
// Fix crash bug in engine
|
2016-12-18 02:08:25 +01:00
|
|
|
if(strcasecmp(szKeyName, "angle") == 0)
|
|
|
|
szKeyName = "angles";
|
|
|
|
|
|
|
|
else if(strcasecmp(szKeyName, "classname") == 0 &&
|
2016-12-19 03:31:42 +01:00
|
|
|
strcasecmp(szValue, "info_player_terrorist") == 0)
|
2016-12-18 02:08:25 +01:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
// Only CT spawnpoints
|
2016-12-19 08:26:58 +01:00
|
|
|
szValue = "info_player_counterterrorist";
|
2016-12-18 02:08:25 +01:00
|
|
|
}
|
2017-01-30 18:59:50 +01:00
|
|
|
else if(strcasecmp(szKeyName, "teamnum") == 0 || strcasecmp(szKeyName, "teamnum") == 0 )
|
|
|
|
{
|
|
|
|
CBaseEntity *pEntity = (CBaseEntity *)this;
|
|
|
|
const char *pClassname = gamehelpers->GetEntityClassname(pEntity);
|
|
|
|
|
|
|
|
// All buyzones should be CT buyzones
|
|
|
|
if(pClassname && strcasecmp(pClassname, "func_buyzone") == 0)
|
|
|
|
szValue = "3";
|
|
|
|
}
|
2016-12-18 02:08:25 +01:00
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
return DETOUR_MEMBER_CALL(DETOUR_KeyValue)(szKeyName, szValue);
|
2016-12-18 02:08:25 +01:00
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
/* Ignore players in +USE trace */
|
2019-10-08 18:08:24 +02:00
|
|
|
bool g_InFindUseEntity = false;
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_DECL_MEMBER0(DETOUR_FindUseEntity, CBaseEntity *)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
|
|
|
// Signal CTraceFilterSimple that we are in FindUseEntity
|
2019-10-08 18:08:24 +02:00
|
|
|
g_InFindUseEntity = true;
|
2017-01-30 18:59:50 +01:00
|
|
|
CBaseEntity *pEntity = DETOUR_MEMBER_CALL(DETOUR_FindUseEntity)();
|
2019-10-08 18:08:24 +02:00
|
|
|
g_InFindUseEntity = false;
|
2016-08-18 06:41:58 +02:00
|
|
|
return pEntity;
|
|
|
|
}
|
2017-07-05 23:10:12 +02:00
|
|
|
DETOUR_DECL_MEMBER3(DETOUR_CTraceFilterSimple, void, const IHandleEntity *, passedict, int, collisionGroup, ShouldHitFunc_t, pExtraShouldHitFunc)
|
|
|
|
{
|
|
|
|
DETOUR_MEMBER_CALL(DETOUR_CTraceFilterSimple)(passedict, collisionGroup, pExtraShouldHitFunc);
|
2016-08-18 06:41:58 +02:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
// If we're in FindUseEntity right now then switch out the VTable
|
2019-10-08 18:08:24 +02:00
|
|
|
if(g_InFindUseEntity)
|
2017-07-05 23:10:12 +02:00
|
|
|
*(uintptr_t *)this = g_CTraceFilterNoNPCsOrPlayer;
|
|
|
|
}
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
/* Make bullets ignore teammates */
|
2019-10-08 18:08:24 +02:00
|
|
|
char *g_pPhysboxToClientMap = NULL;
|
|
|
|
bool g_InFireBullets = false;
|
|
|
|
int g_FireBulletPlayerTeam = 0;
|
2017-07-05 23:10:12 +02:00
|
|
|
SH_DECL_HOOK2(CTraceFilterSkipTwoEntities, ShouldHitEntity, SH_NOATTRIB, 0, bool, IHandleEntity *, int);
|
|
|
|
SH_DECL_HOOK2(CTraceFilterSimple, ShouldHitEntity, SH_NOATTRIB, 0, bool, IHandleEntity *, int);
|
2017-01-30 18:59:50 +01:00
|
|
|
bool ShouldHitEntity(IHandleEntity *pHandleEntity, int contentsMask)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
2019-10-08 18:08:24 +02:00
|
|
|
if(!g_InFireBullets)
|
2017-09-26 15:06:41 +02:00
|
|
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
if(META_RESULT_ORIG_RET(bool) == false)
|
2017-09-26 15:06:41 +02:00
|
|
|
RETURN_META_VALUE(MRES_IGNORED, false);
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
IServerUnknown *pUnk = (IServerUnknown *)pHandleEntity;
|
2019-10-08 18:08:24 +02:00
|
|
|
CBaseHandle hndl = pUnk->GetRefEHandle();
|
|
|
|
int index = hndl.GetEntryIndex();
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
if(index > SM_MAXPLAYERS && g_pPhysboxToClientMap && index < 2048)
|
|
|
|
{
|
|
|
|
index = g_pPhysboxToClientMap[index];
|
|
|
|
}
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
if(index < 1 || index > SM_MAXPLAYERS)
|
2017-01-30 18:59:50 +01:00
|
|
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index);
|
2017-01-30 18:59:50 +01:00
|
|
|
if(!pPlayer)
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
|
|
|
|
|
|
|
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
|
|
|
|
if(!pInfo)
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
|
|
|
|
|
|
|
int iTeam = pInfo->GetTeamIndex();
|
2019-10-08 18:08:24 +02:00
|
|
|
if(iTeam == g_FireBulletPlayerTeam)
|
2017-01-30 18:59:50 +01:00
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, false);
|
|
|
|
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, true);
|
|
|
|
}
|
|
|
|
|
2017-09-26 15:06:41 +02:00
|
|
|
DETOUR_DECL_STATIC9(DETOUR_FireBullets, void, int, iPlayerIndex, const Vector *, vOrigin, const QAngle *, vAngles, int, iWeaponID, int, iMode, int, iSeed, float, flSpread, float, _f1, float, _f2)
|
2017-01-30 18:59:50 +01:00
|
|
|
{
|
|
|
|
if(iPlayerIndex <= 0 || iPlayerIndex > playerhelpers->GetMaxClients())
|
2017-09-26 15:06:41 +02:00
|
|
|
return DETOUR_STATIC_CALL(DETOUR_FireBullets)(iPlayerIndex, vOrigin, vAngles, iWeaponID, iMode, iSeed, flSpread, _f1, _f2);
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(iPlayerIndex);
|
|
|
|
if(!pPlayer)
|
2017-09-26 15:06:41 +02:00
|
|
|
return DETOUR_STATIC_CALL(DETOUR_FireBullets)(iPlayerIndex, vOrigin, vAngles, iWeaponID, iMode, iSeed, flSpread, _f1, _f2);
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
|
|
|
|
if(!pInfo)
|
2017-09-26 15:06:41 +02:00
|
|
|
return DETOUR_STATIC_CALL(DETOUR_FireBullets)(iPlayerIndex, vOrigin, vAngles, iWeaponID, iMode, iSeed, flSpread, _f1, _f2);
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
g_FireBulletPlayerTeam = pInfo->GetTeamIndex();
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
g_InFireBullets = true;
|
2017-09-26 15:06:41 +02:00
|
|
|
DETOUR_STATIC_CALL(DETOUR_FireBullets)(iPlayerIndex, vOrigin, vAngles, iWeaponID, iMode, iSeed, flSpread, _f1, _f2);
|
2019-10-08 18:08:24 +02:00
|
|
|
g_InFireBullets = false;
|
2017-01-30 18:59:50 +01:00
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
DETOUR_DECL_MEMBER1(DETOUR_SwingOrStab, bool, bool, bStab)
|
2017-01-30 18:59:50 +01:00
|
|
|
{
|
2017-07-05 23:10:12 +02:00
|
|
|
static int offset = 0;
|
|
|
|
if(!offset)
|
|
|
|
{
|
|
|
|
IServerUnknown *pUnk = (IServerUnknown *)this;
|
|
|
|
IServerNetworkable *pNet = pUnk->GetNetworkable();
|
2016-08-18 06:41:58 +02:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
if (!UTIL_ContainsDataTable(pNet->GetServerClass()->m_pTable, "DT_BaseCombatWeapon"))
|
|
|
|
return DETOUR_MEMBER_CALL(DETOUR_SwingOrStab)(bStab);
|
2016-08-18 06:41:58 +02:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
sm_sendprop_info_t spi;
|
|
|
|
if (!gamehelpers->FindSendPropInfo("CBaseCombatWeapon", "m_hOwnerEntity", &spi))
|
|
|
|
return DETOUR_MEMBER_CALL(DETOUR_SwingOrStab)(bStab);
|
|
|
|
|
|
|
|
offset = spi.actual_offset;
|
|
|
|
}
|
2016-12-04 14:08:20 +01:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
CBaseHandle &hndl = *(CBaseHandle *)((uint8_t *)this + offset);
|
|
|
|
|
|
|
|
edict_t *pEdict = gamehelpers->GetHandleEntity(hndl);
|
|
|
|
if(!pEdict)
|
|
|
|
return DETOUR_MEMBER_CALL(DETOUR_SwingOrStab)(bStab);
|
|
|
|
|
|
|
|
IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(pEdict);
|
|
|
|
if(!pPlayer)
|
|
|
|
return DETOUR_MEMBER_CALL(DETOUR_SwingOrStab)(bStab);
|
|
|
|
|
|
|
|
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
|
|
|
|
if(!pInfo)
|
|
|
|
return DETOUR_MEMBER_CALL(DETOUR_SwingOrStab)(bStab);
|
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
g_FireBulletPlayerTeam = pInfo->GetTeamIndex();
|
2017-07-05 23:10:12 +02:00
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
g_InFireBullets = true;
|
2017-07-05 23:10:12 +02:00
|
|
|
bool bRet = DETOUR_MEMBER_CALL(DETOUR_SwingOrStab)(bStab);
|
2019-10-08 18:08:24 +02:00
|
|
|
g_InFireBullets = false;
|
2017-07-05 23:10:12 +02:00
|
|
|
|
|
|
|
return bRet;
|
2016-12-04 14:08:20 +01:00
|
|
|
}
|
|
|
|
|
2019-10-08 18:08:24 +02:00
|
|
|
cell_t PhysboxToClientMap(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
|
|
|
if(params[2])
|
|
|
|
pContext->LocalToPhysAddr(params[1], (cell_t **)&g_pPhysboxToClientMap);
|
|
|
|
else
|
|
|
|
g_pPhysboxToClientMap = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_DECL_STATIC1(DETOUR_RunThinkFunctions, void, bool, simulating)
|
2016-12-16 23:45:05 +01:00
|
|
|
{
|
2019-10-01 18:49:38 +02:00
|
|
|
if(g_pOnRunThinkFunctions->GetFunctionCount())
|
|
|
|
{
|
|
|
|
g_pOnRunThinkFunctions->PushCell(simulating);
|
|
|
|
g_pOnRunThinkFunctions->Execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(g_pOnPrePlayerThinkFunctions->GetFunctionCount())
|
|
|
|
{
|
|
|
|
g_pOnPrePlayerThinkFunctions->Execute();
|
|
|
|
}
|
2016-12-16 23:45:05 +01:00
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
DETOUR_STATIC_CALL(DETOUR_RunThinkFunctions)(simulating);
|
2016-12-16 23:45:05 +01:00
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
if(g_pOnRunThinkFunctionsPost->GetFunctionCount())
|
|
|
|
{
|
|
|
|
g_pOnRunThinkFunctionsPost->PushCell(simulating);
|
|
|
|
g_pOnRunThinkFunctionsPost->Execute();
|
|
|
|
}
|
2016-12-16 23:45:05 +01:00
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
void (*g_pPhysics_SimulateEntity)(CBaseEntity *pEntity) = NULL;
|
|
|
|
void Physics_SimulateEntity_CustomLoop(CBaseEntity **ppList, int Count, float Startime)
|
|
|
|
{
|
|
|
|
CBaseEntity *apPlayers[SM_MAXPLAYERS];
|
|
|
|
int iPlayers = 0;
|
|
|
|
|
|
|
|
// Remove players from list and put into apPlayers
|
|
|
|
for(int i = 0; i < Count; i++)
|
|
|
|
{
|
|
|
|
CBaseEntity *pEntity = ppList[i];
|
|
|
|
if(!pEntity)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
edict_t *pEdict = gamehelpers->EdictOfIndex(gamehelpers->EntityToBCompatRef(pEntity));
|
|
|
|
if(!pEdict)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int Entity = gamehelpers->IndexOfEdict(pEdict);
|
|
|
|
if(Entity >= 1 && Entity <= SM_MAXPLAYERS)
|
|
|
|
{
|
|
|
|
apPlayers[iPlayers++] = pEntity;
|
|
|
|
ppList[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Shuffle players array
|
|
|
|
for(int i = iPlayers - 1; i > 0; i--)
|
|
|
|
{
|
|
|
|
int j = rand() % (i + 1);
|
|
|
|
CBaseEntity *pTmp = apPlayers[j];
|
|
|
|
apPlayers[j] = apPlayers[i];
|
|
|
|
apPlayers[i] = pTmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate players first
|
|
|
|
for(int i = 0; i < iPlayers; i++)
|
|
|
|
{
|
|
|
|
gpGlobals->curtime = Startime;
|
|
|
|
g_pPhysics_SimulateEntity(apPlayers[i]);
|
|
|
|
}
|
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
// Post Player simulation done
|
|
|
|
if(g_pOnPostPlayerThinkFunctions->GetFunctionCount())
|
|
|
|
{
|
|
|
|
g_pOnPostPlayerThinkFunctions->Execute();
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
// Now simulate the rest
|
|
|
|
for(int i = 0; i < Count; i++)
|
|
|
|
{
|
|
|
|
CBaseEntity *pEntity = ppList[i];
|
|
|
|
if(!pEntity)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gpGlobals->curtime = Startime;
|
|
|
|
g_pPhysics_SimulateEntity(pEntity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-07 23:59:59 +02:00
|
|
|
int g_TriggerEntityMoved;
|
2019-10-08 18:08:24 +02:00
|
|
|
char *g_pFilterTriggerTouchPlayers = NULL;
|
2019-10-05 15:16:35 +02:00
|
|
|
int g_FilterTriggerMoved = -1;
|
2019-10-01 18:49:38 +02:00
|
|
|
// void IVEngineServer::TriggerMoved( edict_t *pTriggerEnt, bool testSurroundingBoundsOnly ) = 0;
|
|
|
|
SH_DECL_HOOK2_void(IVEngineServer, TriggerMoved, SH_NOATTRIB, 0, edict_t *, bool);
|
|
|
|
void TriggerMoved(edict_t *pTriggerEnt, bool testSurroundingBoundsOnly)
|
|
|
|
{
|
2019-10-07 23:59:59 +02:00
|
|
|
g_TriggerEntityMoved = gamehelpers->IndexOfEdict(pTriggerEnt);
|
2019-10-05 15:16:35 +02:00
|
|
|
|
|
|
|
// Allow all
|
|
|
|
if(g_FilterTriggerMoved == -1)
|
2019-10-01 18:49:38 +02:00
|
|
|
{
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
2019-10-05 15:16:35 +02:00
|
|
|
// Block All
|
|
|
|
else if(g_FilterTriggerMoved == 0)
|
2019-10-01 18:49:38 +02:00
|
|
|
{
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// Decide per entity in TriggerMoved_EnumElement
|
2019-10-01 18:49:38 +02:00
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
|
|
|
// IterationRetval_t CTriggerMoved::EnumElement( IHandleEntity *pHandleEntity ) = 0;
|
|
|
|
SH_DECL_HOOK1(CTriggerMoved, EnumElement, SH_NOATTRIB, 0, IterationRetval_t, IHandleEntity *);
|
2019-10-04 11:17:47 +02:00
|
|
|
IterationRetval_t TriggerMoved_EnumElement(IHandleEntity *pHandleEntity)
|
2019-10-01 18:49:38 +02:00
|
|
|
{
|
2019-10-08 18:08:24 +02:00
|
|
|
if(g_FilterTriggerMoved <= 0 && !g_pFilterTriggerTouchPlayers)
|
2019-10-01 18:49:38 +02:00
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
IServerUnknown *pUnk = static_cast< IServerUnknown* >( pHandleEntity );
|
|
|
|
CBaseHandle hndl = pUnk->GetRefEHandle();
|
|
|
|
int index = hndl.GetEntryIndex();
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// We only care about players
|
|
|
|
if(index > SM_MAXPLAYERS)
|
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
2019-10-07 23:59:59 +02:00
|
|
|
// block touching any clients here if map exists and evaluates to true
|
2019-10-08 18:08:24 +02:00
|
|
|
if(g_pFilterTriggerTouchPlayers && g_pFilterTriggerTouchPlayers[g_TriggerEntityMoved])
|
2019-10-07 23:59:59 +02:00
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// only allow touching this player if filter is active
|
2019-10-05 15:16:35 +02:00
|
|
|
if(index == g_FilterTriggerMoved)
|
2019-10-01 18:49:38 +02:00
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
|
|
|
|
}
|
2019-10-03 17:29:36 +02:00
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// block from touch all other players
|
2019-10-03 17:29:36 +02:00
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
|
2019-10-01 18:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cell_t FilterTriggerMoved(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
2019-10-05 15:16:35 +02:00
|
|
|
g_FilterTriggerMoved = params[1];
|
2019-10-01 18:49:38 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-07 23:59:59 +02:00
|
|
|
cell_t FilterTriggerTouchPlayers(IPluginContext *pContext, const cell_t *params)
|
|
|
|
{
|
|
|
|
if(params[2])
|
2019-10-08 18:08:24 +02:00
|
|
|
pContext->LocalToPhysAddr(params[1], (cell_t **)&g_pFilterTriggerTouchPlayers);
|
2019-10-07 23:59:59 +02:00
|
|
|
else
|
2019-10-08 18:08:24 +02:00
|
|
|
g_pFilterTriggerTouchPlayers = NULL;
|
2019-10-07 23:59:59 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
int g_SolidEntityMoved;
|
|
|
|
int g_BlockSolidMoved = -1;
|
|
|
|
char *g_pFilterClientEntityMap = NULL;
|
2019-10-03 17:29:36 +02:00
|
|
|
// void IVEngineServer::SolidMoved( edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool testSurroundingBoundsOnly ) = 0;
|
|
|
|
SH_DECL_HOOK4_void(IVEngineServer, SolidMoved, SH_NOATTRIB, 0, edict_t *, ICollideable *, const Vector *, bool);
|
|
|
|
void SolidMoved(edict_t *pSolidEnt, ICollideable *pSolidCollide, const Vector *pPrevAbsOrigin, bool testSurroundingBoundsOnly)
|
|
|
|
{
|
2019-10-05 15:16:35 +02:00
|
|
|
g_SolidEntityMoved = gamehelpers->IndexOfEdict(pSolidEnt);
|
2019-10-04 11:17:47 +02:00
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// Allow all
|
|
|
|
if(g_BlockSolidMoved == -1)
|
2019-10-03 17:29:36 +02:00
|
|
|
{
|
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
2019-10-05 15:16:35 +02:00
|
|
|
// Block all
|
|
|
|
else if(g_BlockSolidMoved == 0)
|
2019-10-03 17:29:36 +02:00
|
|
|
{
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// Block filtered entity
|
|
|
|
if(g_SolidEntityMoved == g_BlockSolidMoved)
|
2019-10-03 17:29:36 +02:00
|
|
|
{
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// Allow all others
|
2019-10-03 17:29:36 +02:00
|
|
|
RETURN_META(MRES_IGNORED);
|
|
|
|
}
|
|
|
|
|
2019-10-04 11:17:47 +02:00
|
|
|
// IterationRetval_t CTouchLinks::EnumElement( IHandleEntity *pHandleEntity ) = 0;
|
|
|
|
SH_DECL_HOOK1(CTouchLinks, EnumElement, SH_NOATTRIB, 0, IterationRetval_t, IHandleEntity *);
|
|
|
|
IterationRetval_t TouchLinks_EnumElement(IHandleEntity *pHandleEntity)
|
|
|
|
{
|
|
|
|
IServerUnknown *pUnk = static_cast< IServerUnknown* >( pHandleEntity );
|
|
|
|
CBaseHandle hndl = pUnk->GetRefEHandle();
|
|
|
|
int index = hndl.GetEntryIndex();
|
|
|
|
|
|
|
|
// Optimization: Players shouldn't touch other players
|
2019-10-05 15:16:35 +02:00
|
|
|
if(g_SolidEntityMoved <= SM_MAXPLAYERS && index <= SM_MAXPLAYERS)
|
2019-10-04 11:17:47 +02:00
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// We only care about players
|
|
|
|
if(g_SolidEntityMoved > SM_MAXPLAYERS)
|
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do we have our filter map and is the entity within it? (can it even be > 2048?)
|
|
|
|
if(!g_pFilterClientEntityMap || index >= 2048)
|
2019-10-04 11:17:47 +02:00
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// SourcePawn char map[MAXPLAYERS + 1][2048]
|
|
|
|
// Contiguous memory, shift array by client idx * 2048
|
|
|
|
int arrayIdx = g_SolidEntityMoved * 2048 + index;
|
|
|
|
|
|
|
|
// Block player from touching this entity if it's filtered
|
|
|
|
if(g_pFilterClientEntityMap[arrayIdx])
|
2019-10-04 11:17:47 +02:00
|
|
|
{
|
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
// Allow otherwise
|
2019-10-04 11:17:47 +02:00
|
|
|
RETURN_META_VALUE(MRES_IGNORED, ITERATION_CONTINUE);
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
cell_t BlockSolidMoved(IPluginContext *pContext, const cell_t *params)
|
2019-10-04 11:17:47 +02:00
|
|
|
{
|
2019-10-05 15:16:35 +02:00
|
|
|
g_BlockSolidMoved = params[1];
|
2019-10-04 11:17:47 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-10-05 15:16:35 +02:00
|
|
|
cell_t FilterClientEntityMap(IPluginContext *pContext, const cell_t *params)
|
2019-10-03 17:29:36 +02:00
|
|
|
{
|
2019-10-05 15:16:35 +02:00
|
|
|
if(params[2])
|
|
|
|
pContext->LocalToPhysAddr(params[1], (cell_t **)&g_pFilterClientEntityMap);
|
|
|
|
else
|
|
|
|
g_pFilterClientEntityMap = NULL;
|
|
|
|
|
2019-10-03 17:29:36 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2019-10-01 18:49:38 +02:00
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
bool CSSFixes::SDK_OnLoad(char *error, size_t maxlength, bool late)
|
|
|
|
{
|
2017-07-05 23:10:12 +02:00
|
|
|
srand((unsigned int)time(NULL));
|
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
char conf_error[255] = "";
|
|
|
|
if(!gameconfs->LoadGameConfigFile("CSSFixes", &g_pGameConf, conf_error, sizeof(conf_error)))
|
|
|
|
{
|
|
|
|
if(conf_error[0])
|
|
|
|
snprintf(error, maxlength, "Could not read CSSFixes.txt: %s", conf_error);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_InputTestActivator = DETOUR_CREATE_MEMBER(DETOUR_InputTestActivator, "CBaseFilter_InputTestActivator");
|
|
|
|
if(g_pDetour_InputTestActivator == NULL)
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for CBaseFilter_InputTestActivator");
|
2016-12-16 23:45:05 +01:00
|
|
|
SDK_OnUnload();
|
2016-05-12 16:10:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_PostConstructor = DETOUR_CREATE_MEMBER(DETOUR_PostConstructor, "CBaseEntity_PostConstructor");
|
|
|
|
if(g_pDetour_PostConstructor == NULL)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for CBaseEntity_PostConstructor");
|
2016-12-16 23:45:05 +01:00
|
|
|
SDK_OnUnload();
|
2016-08-18 06:41:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_FindUseEntity = DETOUR_CREATE_MEMBER(DETOUR_FindUseEntity, "CBasePlayer_FindUseEntity");
|
|
|
|
if(g_pDetour_FindUseEntity == NULL)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for CBasePlayer_FindUseEntity");
|
2016-12-16 23:45:05 +01:00
|
|
|
SDK_OnUnload();
|
2016-08-18 06:41:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_CTraceFilterSimple = DETOUR_CREATE_MEMBER(DETOUR_CTraceFilterSimple, "CTraceFilterSimple_CTraceFilterSimple");
|
|
|
|
if(g_pDetour_CTraceFilterSimple == NULL)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for CTraceFilterSimple_CTraceFilterSimple");
|
2016-12-16 23:45:05 +01:00
|
|
|
SDK_OnUnload();
|
2016-08-18 06:41:58 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_RunThinkFunctions = DETOUR_CREATE_STATIC(DETOUR_RunThinkFunctions, "Physics_RunThinkFunctions");
|
|
|
|
if(g_pDetour_RunThinkFunctions == NULL)
|
2016-12-16 23:45:05 +01:00
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for Physics_RunThinkFunctions");
|
|
|
|
SDK_OnUnload();
|
2016-12-04 14:08:20 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-12-16 23:45:05 +01:00
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_KeyValue = DETOUR_CREATE_MEMBER(DETOUR_KeyValue, "CBaseEntity_KeyValue");
|
|
|
|
if(g_pDetour_KeyValue == NULL)
|
2016-12-18 02:08:25 +01:00
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for CBaseEntity_KeyValue");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_FireBullets = DETOUR_CREATE_STATIC(DETOUR_FireBullets, "FX_FireBullets");
|
|
|
|
if(g_pDetour_FireBullets == NULL)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for FX_FireBullets");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
g_pDetour_SwingOrStab = DETOUR_CREATE_MEMBER(DETOUR_SwingOrStab, "CKnife_SwingOrStab");
|
|
|
|
if(g_pDetour_SwingOrStab == NULL)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not create detour for CKnife_SwingOrStab");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_InputTestActivator->EnableDetour();
|
|
|
|
g_pDetour_PostConstructor->EnableDetour();
|
|
|
|
g_pDetour_FindUseEntity->EnableDetour();
|
|
|
|
g_pDetour_CTraceFilterSimple->EnableDetour();
|
|
|
|
g_pDetour_RunThinkFunctions->EnableDetour();
|
|
|
|
g_pDetour_KeyValue->EnableDetour();
|
|
|
|
g_pDetour_FireBullets->EnableDetour();
|
2017-07-05 23:10:12 +02:00
|
|
|
g_pDetour_SwingOrStab->EnableDetour();
|
2017-01-30 18:59:50 +01:00
|
|
|
|
|
|
|
// Find VTable for CTraceFilterSkipTwoEntities
|
|
|
|
uintptr_t pCTraceFilterSkipTwoEntities;
|
|
|
|
if(!g_pGameConf->GetMemSig("CTraceFilterSkipTwoEntities", (void **)(&pCTraceFilterSkipTwoEntities)) || !pCTraceFilterSkipTwoEntities)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Failed to find CTraceFilterSkipTwoEntities.\n");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// First function in VTable
|
|
|
|
g_CTraceFilterSkipTwoEntities = (CTraceFilterSkipTwoEntities *)(pCTraceFilterSkipTwoEntities + 8);
|
2016-12-04 14:08:20 +01:00
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
// Find VTable for CTraceFilterSimple
|
|
|
|
uintptr_t pCTraceFilterSimple;
|
|
|
|
if(!g_pGameConf->GetMemSig("CTraceFilterSimple", (void **)(&pCTraceFilterSimple)) || !pCTraceFilterSimple)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Failed to find CTraceFilterSimple.\n");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// First function in VTable
|
|
|
|
g_CTraceFilterSimple = (CTraceFilterSimple *)(pCTraceFilterSimple + 8);
|
|
|
|
|
2016-08-18 06:41:58 +02:00
|
|
|
// Find VTable for CTraceFilterNoNPCsOrPlayer
|
|
|
|
uintptr_t pCTraceFilterNoNPCsOrPlayer;
|
|
|
|
if(!g_pGameConf->GetMemSig("CTraceFilterNoNPCsOrPlayer", (void **)(&pCTraceFilterNoNPCsOrPlayer)) || !pCTraceFilterNoNPCsOrPlayer)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Failed to find CTraceFilterNoNPCsOrPlayer.\n");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// First function in VTable
|
|
|
|
g_CTraceFilterNoNPCsOrPlayer = pCTraceFilterNoNPCsOrPlayer + 8;
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
g_SH_SkipTwoEntitiesShouldHitEntity = SH_ADD_DVPHOOK(CTraceFilterSkipTwoEntities, ShouldHitEntity, g_CTraceFilterSkipTwoEntities, SH_STATIC(ShouldHitEntity), true);
|
|
|
|
g_SH_SimpleShouldHitEntity = SH_ADD_DVPHOOK(CTraceFilterSimple, ShouldHitEntity, g_CTraceFilterSimple, SH_STATIC(ShouldHitEntity), true);
|
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
// Find VTable for CTriggerMoved
|
|
|
|
uintptr_t pCTriggerMoved;
|
|
|
|
if(!g_pGameConf->GetMemSig("CTriggerMoved", (void **)(&pCTriggerMoved)) || !pCTriggerMoved)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Failed to find CTriggerMoved.\n");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// First function in VTable
|
|
|
|
g_CTriggerMoved = (CTriggerMoved *)(pCTriggerMoved + 8);
|
|
|
|
|
2019-10-04 11:17:47 +02:00
|
|
|
// Find VTable for CTouchLinks
|
|
|
|
uintptr_t pCTouchLinks;
|
|
|
|
if(!g_pGameConf->GetMemSig("CTouchLinks", (void **)(&pCTouchLinks)) || !pCTouchLinks)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Failed to find CTouchLinks.\n");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// First function in VTable
|
|
|
|
g_CTouchLinks = (CTouchLinks *)(pCTouchLinks + 8);
|
|
|
|
|
|
|
|
g_SH_TriggerMoved = SH_ADD_DVPHOOK(CTriggerMoved, EnumElement, g_CTriggerMoved, SH_STATIC(TriggerMoved_EnumElement), false);
|
|
|
|
g_SH_TouchLinks = SH_ADD_DVPHOOK(CTouchLinks, EnumElement, g_CTouchLinks, SH_STATIC(TouchLinks_EnumElement), false);
|
2019-10-01 18:49:38 +02:00
|
|
|
|
2019-10-03 17:29:36 +02:00
|
|
|
SH_ADD_HOOK(IVEngineServer, TriggerMoved, engine, SH_STATIC(TriggerMoved), false);
|
|
|
|
SH_ADD_HOOK(IVEngineServer, SolidMoved, engine, SH_STATIC(SolidMoved), false);
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
if(!g_pGameConf->GetMemSig("Physics_SimulateEntity", (void **)(&g_pPhysics_SimulateEntity)) || !g_pPhysics_SimulateEntity)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Failed to find Physics_SimulateEntity.\n");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
void *pServerSo = dlopen("cstrike/bin/server_srv.so", RTLD_NOW);
|
|
|
|
if(!pServerSo)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not dlopen server_srv.so");
|
2016-12-16 23:45:05 +01:00
|
|
|
SDK_OnUnload();
|
2016-05-12 16:10:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-25 21:05:37 +02:00
|
|
|
void *pEngineSo = dlopen("bin/engine_srv.so", RTLD_NOW);
|
|
|
|
if(!pEngineSo)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not dlopen engine_srv.so");
|
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
/* 4: Special */
|
|
|
|
uintptr_t pAddress = (uintptr_t)memutils->ResolveSymbol(pServerSo, gs_Patches[4].pSignature);
|
|
|
|
if(!pAddress)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not find symbol: %s", gs_Patches[4].pSignature);
|
|
|
|
dlclose(pServerSo);
|
2019-09-25 21:05:37 +02:00
|
|
|
dlclose(pEngineSo);
|
2017-07-05 23:10:12 +02:00
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t pPatchAddress = FindPattern(pAddress, gs_Patches[4].pPatchSignature, gs_Patches[4].pPatchPattern, 1024);
|
|
|
|
if(!pPatchAddress)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not find patch signature for symbol: %s", gs_Patches[4].pSignature);
|
|
|
|
dlclose(pServerSo);
|
2019-09-25 21:05:37 +02:00
|
|
|
dlclose(pEngineSo);
|
2017-07-05 23:10:12 +02:00
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mov [esp+8], edi ; startime
|
|
|
|
// mov [esp+4], eax ; count
|
|
|
|
// mov [esp], esi ; **list
|
|
|
|
// call NULL ; <- our func here
|
|
|
|
// mov eax, ds:gpGlobals ; restore
|
|
|
|
// jmp +11 ; jump over useless instructions
|
|
|
|
static unsigned char aPatch[] = "\x89\x7C\x24\x08\x89\x44\x24\x04\x89\x34\x24\xE8\x00\x00\x00\x00\xA1\x00\x00\x00\x00\xEB\x0B\x90\x90\x90";
|
|
|
|
gs_Patches[4].pPatch = aPatch;
|
|
|
|
|
|
|
|
// put our function address into the relative call instruction
|
|
|
|
// relative call: new PC = PC + imm1
|
|
|
|
// call is at + 11 after pPatchAddress
|
|
|
|
// PC will be past our call instruction so + 5
|
|
|
|
*(uintptr_t *)&aPatch[12] = (uintptr_t)Physics_SimulateEntity_CustomLoop - (pPatchAddress + 11 + 5);
|
|
|
|
|
|
|
|
// restore "mov eax, ds:gpGlobals" from original to our patch after the call
|
|
|
|
*(uintptr_t *)&aPatch[17] = *(uintptr_t *)(pPatchAddress + 8);
|
|
|
|
|
2016-08-18 06:41:58 +02:00
|
|
|
// Apply all patches
|
2016-07-11 15:39:05 +02:00
|
|
|
for(size_t i = 0; i < sizeof(gs_Patches) / sizeof(*gs_Patches); i++)
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
|
|
|
struct SrcdsPatch *pPatch = &gs_Patches[i];
|
|
|
|
int PatchLen = strlen(pPatch->pPatchPattern);
|
|
|
|
|
2019-09-25 21:05:37 +02:00
|
|
|
void *pBinary = pPatch->engine ? pEngineSo : pServerSo;
|
|
|
|
pPatch->pAddress = (uintptr_t)memutils->ResolveSymbol(pBinary, pPatch->pSignature);
|
2016-05-12 16:10:42 +02:00
|
|
|
if(!pPatch->pAddress)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not find symbol: %s", pPatch->pSignature);
|
|
|
|
dlclose(pServerSo);
|
2019-09-25 21:05:37 +02:00
|
|
|
dlclose(pEngineSo);
|
2016-05-12 16:10:42 +02:00
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPatch->pPatchAddress = FindPattern(pPatch->pAddress, pPatch->pPatchSignature, pPatch->pPatchPattern, 1024);
|
|
|
|
if(!pPatch->pPatchAddress)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlength, "Could not find patch signature for symbol: %s", pPatch->pSignature);
|
|
|
|
dlclose(pServerSo);
|
2019-09-25 21:05:37 +02:00
|
|
|
dlclose(pEngineSo);
|
2016-05-12 16:10:42 +02:00
|
|
|
SDK_OnUnload();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pPatch->pOriginal = (unsigned char *)malloc(PatchLen * sizeof(unsigned char));
|
|
|
|
|
|
|
|
SourceHook::SetMemAccess((void *)pPatch->pPatchAddress, PatchLen, SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
|
|
|
|
for(int j = 0; j < PatchLen; j++)
|
|
|
|
{
|
|
|
|
pPatch->pOriginal[j] = *(unsigned char *)(pPatch->pPatchAddress + j);
|
|
|
|
*(unsigned char *)(pPatch->pPatchAddress + j) = pPatch->pPatch[j];
|
|
|
|
}
|
|
|
|
SourceHook::SetMemAccess((void *)pPatch->pPatchAddress, PatchLen, SH_MEM_READ|SH_MEM_EXEC);
|
|
|
|
}
|
|
|
|
|
|
|
|
dlclose(pServerSo);
|
2019-09-25 21:05:37 +02:00
|
|
|
dlclose(pEngineSo);
|
2016-05-12 16:10:42 +02:00
|
|
|
|
2016-12-16 23:45:05 +01:00
|
|
|
g_pOnRunThinkFunctions = forwards->CreateForward("OnRunThinkFunctions", ET_Ignore, 1, NULL, Param_Cell);
|
2019-10-01 18:49:38 +02:00
|
|
|
g_pOnPrePlayerThinkFunctions = forwards->CreateForward("OnPrePlayerThinkFunctions", ET_Ignore, 0, NULL);
|
|
|
|
g_pOnPostPlayerThinkFunctions = forwards->CreateForward("OnPostPlayerThinkFunctions", ET_Ignore, 0, NULL);
|
2016-12-16 23:45:05 +01:00
|
|
|
g_pOnRunThinkFunctionsPost = forwards->CreateForward("OnRunThinkFunctionsPost", ET_Ignore, 1, NULL, Param_Cell);
|
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
const sp_nativeinfo_t MyNatives[] =
|
|
|
|
{
|
|
|
|
{ "FilterTriggerMoved", FilterTriggerMoved },
|
2019-10-03 17:29:36 +02:00
|
|
|
{ "BlockSolidMoved", BlockSolidMoved },
|
2019-10-05 15:16:35 +02:00
|
|
|
{ "FilterClientEntityMap", FilterClientEntityMap },
|
2019-10-07 23:59:59 +02:00
|
|
|
{ "FilterTriggerTouchPlayers", FilterTriggerTouchPlayers },
|
2019-10-08 18:08:24 +02:00
|
|
|
{ "PhysboxToClientMap", PhysboxToClientMap },
|
2019-10-01 18:49:38 +02:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
void CSSFixes::SDK_OnAllLoaded()
|
|
|
|
{
|
|
|
|
sharesys->AddNatives(myself, MyNatives);
|
2019-10-03 17:29:36 +02:00
|
|
|
sharesys->RegisterLibrary(myself, "CSSFixes");
|
2019-10-01 18:49:38 +02:00
|
|
|
}
|
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
void CSSFixes::SDK_OnUnload()
|
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
if(g_pDetour_InputTestActivator != NULL)
|
|
|
|
{
|
|
|
|
g_pDetour_InputTestActivator->Destroy();
|
|
|
|
g_pDetour_InputTestActivator = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(g_pDetour_PostConstructor != NULL)
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_PostConstructor->Destroy();
|
|
|
|
g_pDetour_PostConstructor = NULL;
|
2016-05-12 16:10:42 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
if(g_pDetour_FindUseEntity != NULL)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_FindUseEntity->Destroy();
|
|
|
|
g_pDetour_FindUseEntity = NULL;
|
2016-08-18 06:41:58 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
if(g_pDetour_CTraceFilterSimple != NULL)
|
2016-08-18 06:41:58 +02:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_CTraceFilterSimple->Destroy();
|
|
|
|
g_pDetour_CTraceFilterSimple = NULL;
|
2016-08-18 06:41:58 +02:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
if(g_pDetour_RunThinkFunctions != NULL)
|
2016-12-04 14:08:20 +01:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_RunThinkFunctions->Destroy();
|
|
|
|
g_pDetour_RunThinkFunctions = NULL;
|
2016-12-04 14:08:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
if(g_pDetour_KeyValue != NULL)
|
2016-12-16 23:45:05 +01:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_KeyValue->Destroy();
|
|
|
|
g_pDetour_KeyValue = NULL;
|
2016-12-16 23:45:05 +01:00
|
|
|
}
|
|
|
|
|
2017-01-30 18:59:50 +01:00
|
|
|
if(g_pDetour_FireBullets != NULL)
|
2016-12-18 02:08:25 +01:00
|
|
|
{
|
2017-01-30 18:59:50 +01:00
|
|
|
g_pDetour_FireBullets->Destroy();
|
|
|
|
g_pDetour_FireBullets = NULL;
|
2016-12-18 02:08:25 +01:00
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
if(g_pDetour_SwingOrStab != NULL)
|
|
|
|
{
|
|
|
|
g_pDetour_SwingOrStab->Destroy();
|
|
|
|
g_pDetour_SwingOrStab = NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-16 23:45:05 +01:00
|
|
|
if(g_pOnRunThinkFunctions != NULL)
|
|
|
|
{
|
|
|
|
forwards->ReleaseForward(g_pOnRunThinkFunctions);
|
|
|
|
g_pOnRunThinkFunctions = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(g_pOnRunThinkFunctionsPost != NULL)
|
|
|
|
{
|
|
|
|
forwards->ReleaseForward(g_pOnRunThinkFunctionsPost);
|
|
|
|
g_pOnRunThinkFunctionsPost = NULL;
|
|
|
|
}
|
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
if(g_pOnPrePlayerThinkFunctions != NULL)
|
|
|
|
{
|
|
|
|
forwards->ReleaseForward(g_pOnPrePlayerThinkFunctions);
|
|
|
|
g_pOnPrePlayerThinkFunctions = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(g_pOnPostPlayerThinkFunctions != NULL)
|
|
|
|
{
|
|
|
|
forwards->ReleaseForward(g_pOnPostPlayerThinkFunctions);
|
|
|
|
g_pOnPostPlayerThinkFunctions = NULL;
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:12 +02:00
|
|
|
if(g_SH_SkipTwoEntitiesShouldHitEntity)
|
|
|
|
SH_REMOVE_HOOK_ID(g_SH_SkipTwoEntitiesShouldHitEntity);
|
|
|
|
|
|
|
|
if(g_SH_SimpleShouldHitEntity)
|
|
|
|
SH_REMOVE_HOOK_ID(g_SH_SimpleShouldHitEntity);
|
2017-01-30 18:59:50 +01:00
|
|
|
|
2019-10-01 18:49:38 +02:00
|
|
|
if(g_SH_TriggerMoved)
|
|
|
|
SH_REMOVE_HOOK_ID(g_SH_TriggerMoved);
|
|
|
|
|
2019-10-04 11:17:47 +02:00
|
|
|
if(g_SH_TouchLinks)
|
|
|
|
SH_REMOVE_HOOK_ID(g_SH_TouchLinks);
|
|
|
|
|
2019-10-03 17:29:36 +02:00
|
|
|
SH_REMOVE_HOOK(IVEngineServer, TriggerMoved, engine, SH_STATIC(TriggerMoved), false);
|
|
|
|
SH_REMOVE_HOOK(IVEngineServer, SolidMoved, engine, SH_STATIC(SolidMoved), false);
|
|
|
|
|
2016-05-12 16:10:42 +02:00
|
|
|
gameconfs->CloseGameConfigFile(g_pGameConf);
|
|
|
|
|
2016-08-18 06:41:58 +02:00
|
|
|
// Revert all applied patches
|
2016-07-11 15:39:05 +02:00
|
|
|
for(size_t i = 0; i < sizeof(gs_Patches) / sizeof(*gs_Patches); i++)
|
2016-05-12 16:10:42 +02:00
|
|
|
{
|
|
|
|
struct SrcdsPatch *pPatch = &gs_Patches[i];
|
|
|
|
int PatchLen = strlen(pPatch->pPatchPattern);
|
|
|
|
|
|
|
|
if(!pPatch->pOriginal)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
SourceHook::SetMemAccess((void *)pPatch->pPatchAddress, PatchLen, SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC);
|
|
|
|
for(int j = 0; j < PatchLen; j++)
|
|
|
|
{
|
|
|
|
*(unsigned char *)(pPatch->pPatchAddress + j) = pPatch->pOriginal[j];
|
|
|
|
}
|
|
|
|
SourceHook::SetMemAccess((void *)pPatch->pPatchAddress, PatchLen, SH_MEM_READ|SH_MEM_EXEC);
|
|
|
|
|
|
|
|
free(pPatch->pOriginal);
|
|
|
|
pPatch->pOriginal = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CSSFixes::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
|
|
|
{
|
2016-12-04 14:08:20 +01:00
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
|
2017-07-05 23:10:12 +02:00
|
|
|
gpGlobals = ismm->GetCGlobals();
|
2016-05-12 16:10:42 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t FindPattern(uintptr_t BaseAddr, const unsigned char *pData, const char *pPattern, size_t MaxSize)
|
|
|
|
{
|
|
|
|
unsigned char *pMemory;
|
|
|
|
uintptr_t PatternLen = strlen(pPattern);
|
|
|
|
|
|
|
|
pMemory = reinterpret_cast<unsigned char *>(BaseAddr);
|
|
|
|
|
|
|
|
for(uintptr_t i = 0; i < MaxSize; i++)
|
|
|
|
{
|
|
|
|
uintptr_t Matches = 0;
|
|
|
|
while(*(pMemory + i + Matches) == pData[Matches] || pPattern[Matches] != 'x')
|
|
|
|
{
|
|
|
|
Matches++;
|
|
|
|
if(Matches == PatternLen)
|
|
|
|
return (uintptr_t)(pMemory + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0x00;
|
|
|
|
}
|
2017-07-05 23:10:12 +02:00
|
|
|
|
|
|
|
uintptr_t FindFunctionCall(uintptr_t BaseAddr, uintptr_t Function, size_t MaxSize)
|
|
|
|
{
|
|
|
|
unsigned char *pMemory;
|
|
|
|
pMemory = reinterpret_cast<unsigned char *>(BaseAddr);
|
|
|
|
|
|
|
|
for(uintptr_t i = 0; i < MaxSize; i++)
|
|
|
|
{
|
|
|
|
if(pMemory[i] == 0xE8) // CALL
|
|
|
|
{
|
|
|
|
uintptr_t CallAddr = *(uintptr_t *)(pMemory + i + 1);
|
|
|
|
|
|
|
|
CallAddr += (uintptr_t)(pMemory + i + 5);
|
|
|
|
|
|
|
|
if(CallAddr == Function)
|
|
|
|
return (uintptr_t)(pMemory + i);
|
|
|
|
|
|
|
|
i += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0x00;
|
|
|
|
}
|