Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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 "gamemovement_hack.h"
- FlashboostEnabler g_FlashboostEnabler;
- SMEXT_LINK(&g_FlashboostEnabler );
- typedef const Vector&(*GetPlayerViewVector_t)(CGameMovement*);
- GetPlayerViewVector_t g_pGetPlayerMins = nullptr;
- GetPlayerViewVector_t g_pGetPlayerMaxs = nullptr;
- IEngineTrace* enginetrace = nullptr;
- CGameMovement* g_pGameMovement = nullptr;
- SH_DECL_MANUALHOOK3( MHook_TestPlayerPosition, 0, 0, 0, CBaseHandle, const Vector&, int, trace_t& );
- bool FlashboostEnabler::SDK_OnLoad( char *error, size_t maxlen, bool late )
- {
- g_pSM->LogMessage( myself, "Got interfaces: enginetrace=%p, g_pGameMovement=%p", enginetrace, g_pGameMovement );
- IGameConfig* cfg;
- char conf_error[255];
- if( !gameconfs->LoadGameConfigFile( "flashboost-enabler.games", &cfg, conf_error, sizeof( conf_error ) ) )
- {
- if( conf_error[0] )
- snprintf( error, maxlen, "Could not read config file flashboost-enabler.games.txt: %s", conf_error );
- return false;
- }
- int offset;
- if( cfg->GetOffset( "CGameMovement::TestPlayerPosition", &offset ) )
- {
- SH_MANUALHOOK_RECONFIGURE( MHook_TestPlayerPosition, offset, 0, 0 );
- }
- else
- {
- snprintf( error, maxlen, "Could not get offset for CGameMovement::TestPlayerPosition" );
- gameconfs->CloseGameConfigFile( cfg );
- return false;
- }
- if( cfg->GetOffset( "CGameMovement::GetPlayerMins", &offset ) )
- {
- int* pVtable = *reinterpret_cast<int**>( g_pGameMovement );
- g_pGetPlayerMins = reinterpret_cast<GetPlayerViewVector_t>( pVtable[offset] );
- }
- else
- {
- snprintf( error, maxlen, "Could not get offset for CGameMovement::GetPlayerMins" );
- gameconfs->CloseGameConfigFile( cfg );
- return false;
- }
- if( cfg->GetOffset( "CGameMovement::GetPlayerMaxs", &offset ) )
- {
- int* pVtable = *reinterpret_cast<int**>( g_pGameMovement );
- g_pGetPlayerMaxs = reinterpret_cast<GetPlayerViewVector_t>( pVtable[offset] );
- }
- else
- {
- snprintf( error, maxlen, "Could not get offset for CGameMovement::GetPlayerMaxs" );
- gameconfs->CloseGameConfigFile( cfg );
- return false;
- }
- cfg->GetAddress( "CTraceFilterSimple::ShouldHitEntity", reinterpret_cast<void**>( &g_pShouldHitEntity ) );
- if( g_pShouldHitEntity == nullptr )
- {
- snprintf( error, maxlen, "Failed to obtain CTraceFilterSimple::ShouldHitEntity from gamedata" );
- gameconfs->CloseGameConfigFile( cfg );
- return false;
- }
- gameconfs->CloseGameConfigFile( cfg );
- SH_ADD_MANUALHOOK( MHook_TestPlayerPosition, g_pGameMovement, SH_MEMBER( this, &FlashboostEnabler::Hook_TestPlayerPosition ), false );
- g_pSM->LogMessage( myself, "Successfully hooked/loaded" );
- return true;
- }
- void FlashboostEnabler::SDK_OnUnload()
- {
- SH_REMOVE_MANUALHOOK( MHook_TestPlayerPosition, g_pGameMovement, SH_MEMBER( this, &FlashboostEnabler::Hook_TestPlayerPosition ), false );
- }
- bool FlashboostEnabler::SDK_OnMetamodLoad( ISmmAPI* ismm, char* error, size_t maxlen, bool late )
- {
- GET_V_IFACE_ANY( GetEngineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER );
- GET_V_IFACE_ANY( GetServerFactory, g_pGameMovement, CGameMovement, INTERFACENAME_GAMEMOVEMENT );
- return true;
- }
- CBaseHandle FlashboostEnabler::Hook_TestPlayerPosition( const Vector& pos, int collisiongroup, trace_t& pm )
- {
- g_pSM->LogMessage( myself, "Ran TestPlayerPosition" );
- Vector mins = g_pGetPlayerMins( g_pGameMovement );
- g_pSM->LogMessage( myself, "Got player mins: (%f, %f, %f)", mins.x, mins.y, mins.z );
- Vector maxs = g_pGetPlayerMaxs( g_pGameMovement );
- g_pSM->LogMessage( myself, "Got player maxs: (%f, %f, %f)", maxs.x, maxs.y, maxs.z );
- g_pSM->LogMessage( myself, "Creating ray ..." );
- Ray_t ray;
- ray.Init( pos, pos, mins, maxs );
- g_pSM->LogMessage( myself, "Ray created" );
- g_pSM->LogMessage( myself, "Creating trace filter ..." );
- IHandleEntity* playerhandle = reinterpret_cast<IHandleEntity*>( gamehelpers->GetHandleEntity( g_pGameMovement->mv->m_nPlayerHandle ) );
- CTraceFilterSimple traceFilter( playerhandle, collisiongroup );
- g_pSM->LogMessage( myself, "Trace filter created" );
- g_pSM->LogMessage( myself, "Doing trace ..." );
- enginetrace->TraceRay( ray, MASK_PLAYERSOLID, &tracefilter, &pm );
- g_pSM->LogMessage( myself, "Trace finished" );
- if( (pm.contents & MASK_PLAYERSOLID) && pm.m_pEnt )
- {
- g_pSM->LogMessage( myself, "END 1: standing on entity" );
- RETURN_META_VALUE( MRES_SUPERCEDE, reinterpret_cast<IHandleEntity*>(pm.m_pEnt)->GetRefEHandle() );
- }
- else
- {
- g_pSM->LogMessage( myself, "END 2: not standing on entity" );
- RETURN_META_VALUE( MRES_SUPERCEDE, INVALID_EHANDLE_INDEX );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement