Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.06 KB | None | 0 0
  1. /**
  2.  * vim: set ts=4 :
  3.  * =============================================================================
  4.  * SourceMod Sample Extension
  5.  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
  6.  * =============================================================================
  7.  *
  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.
  11.  *
  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
  15.  * details.
  16.  *
  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/>.
  19.  *
  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>.
  28.  *
  29.  * Version: $Id$
  30.  */
  31.  
  32. #include "extension.h"
  33. #include "gamemovement_hack.h"
  34.  
  35. FlashboostEnabler g_FlashboostEnabler;
  36.  
  37. SMEXT_LINK(&g_FlashboostEnabler );
  38.  
  39. typedef const Vector&(*GetPlayerViewVector_t)(CGameMovement*);
  40.  
  41. GetPlayerViewVector_t g_pGetPlayerMins = nullptr;
  42. GetPlayerViewVector_t g_pGetPlayerMaxs = nullptr;
  43.  
  44.  
  45. IEngineTrace* enginetrace = nullptr;
  46. CGameMovement* g_pGameMovement = nullptr;
  47.  
  48. SH_DECL_MANUALHOOK3( MHook_TestPlayerPosition, 0, 0, 0, CBaseHandle, const Vector&, int, trace_t& );
  49.  
  50. bool FlashboostEnabler::SDK_OnLoad( char *error, size_t maxlen, bool late )
  51. {
  52.     g_pSM->LogMessage( myself, "Got interfaces: enginetrace=%p, g_pGameMovement=%p", enginetrace, g_pGameMovement );
  53.  
  54.     IGameConfig* cfg;
  55.  
  56.     char conf_error[255];
  57.     if( !gameconfs->LoadGameConfigFile( "flashboost-enabler.games", &cfg, conf_error, sizeof( conf_error ) ) )
  58.     {
  59.         if( conf_error[0] )
  60.             snprintf( error, maxlen, "Could not read config file flashboost-enabler.games.txt: %s", conf_error );
  61.  
  62.         return false;
  63.     }
  64.  
  65.     int offset;
  66.  
  67.     if( cfg->GetOffset( "CGameMovement::TestPlayerPosition", &offset ) )
  68.     {
  69.         SH_MANUALHOOK_RECONFIGURE( MHook_TestPlayerPosition, offset, 0, 0 );
  70.     }
  71.     else
  72.     {
  73.         snprintf( error, maxlen, "Could not get offset for CGameMovement::TestPlayerPosition" );
  74.  
  75.         gameconfs->CloseGameConfigFile( cfg );
  76.         return false;
  77.     }
  78.  
  79.     if( cfg->GetOffset( "CGameMovement::GetPlayerMins", &offset ) )
  80.     {
  81.         int* pVtable = *reinterpret_cast<int**>( g_pGameMovement );
  82.         g_pGetPlayerMins = reinterpret_cast<GetPlayerViewVector_t>( pVtable[offset] );
  83.     }
  84.     else
  85.     {
  86.         snprintf( error, maxlen, "Could not get offset for CGameMovement::GetPlayerMins" );
  87.  
  88.         gameconfs->CloseGameConfigFile( cfg );
  89.         return false;
  90.     }
  91.  
  92.     if( cfg->GetOffset( "CGameMovement::GetPlayerMaxs", &offset ) )
  93.     {
  94.         int* pVtable = *reinterpret_cast<int**>( g_pGameMovement );
  95.         g_pGetPlayerMaxs = reinterpret_cast<GetPlayerViewVector_t>( pVtable[offset] );
  96.     }
  97.     else
  98.     {
  99.         snprintf( error, maxlen, "Could not get offset for CGameMovement::GetPlayerMaxs" );
  100.  
  101.         gameconfs->CloseGameConfigFile( cfg );
  102.         return false;
  103.     }
  104.  
  105.     cfg->GetAddress( "CTraceFilterSimple::ShouldHitEntity", reinterpret_cast<void**>( &g_pShouldHitEntity ) );
  106.     if( g_pShouldHitEntity == nullptr )
  107.     {
  108.         snprintf( error, maxlen, "Failed to obtain CTraceFilterSimple::ShouldHitEntity from gamedata" );
  109.         gameconfs->CloseGameConfigFile( cfg );
  110.         return false;
  111.     }
  112.  
  113.     gameconfs->CloseGameConfigFile( cfg );
  114.  
  115.     SH_ADD_MANUALHOOK( MHook_TestPlayerPosition, g_pGameMovement, SH_MEMBER( this, &FlashboostEnabler::Hook_TestPlayerPosition ), false );
  116.  
  117.     g_pSM->LogMessage( myself, "Successfully hooked/loaded" );
  118.  
  119.     return true;
  120. }
  121.  
  122. void FlashboostEnabler::SDK_OnUnload()
  123. {
  124.     SH_REMOVE_MANUALHOOK( MHook_TestPlayerPosition, g_pGameMovement, SH_MEMBER( this, &FlashboostEnabler::Hook_TestPlayerPosition ), false );
  125. }
  126.  
  127. bool FlashboostEnabler::SDK_OnMetamodLoad( ISmmAPI* ismm, char* error, size_t maxlen, bool late )
  128. {
  129.     GET_V_IFACE_ANY( GetEngineFactory, enginetrace, IEngineTrace, INTERFACEVERSION_ENGINETRACE_SERVER );
  130.     GET_V_IFACE_ANY( GetServerFactory, g_pGameMovement, CGameMovement, INTERFACENAME_GAMEMOVEMENT );
  131.  
  132.     return true;
  133. }
  134.  
  135. CBaseHandle FlashboostEnabler::Hook_TestPlayerPosition( const Vector& pos, int collisiongroup, trace_t& pm )
  136. {
  137.     g_pSM->LogMessage( myself, "Ran TestPlayerPosition" );
  138.     Vector mins = g_pGetPlayerMins( g_pGameMovement );
  139.     g_pSM->LogMessage( myself, "Got player mins: (%f, %f, %f)", mins.x, mins.y, mins.z );
  140.     Vector maxs = g_pGetPlayerMaxs( g_pGameMovement );
  141.     g_pSM->LogMessage( myself, "Got player maxs: (%f, %f, %f)", maxs.x, maxs.y, maxs.z );
  142.  
  143.  
  144.     g_pSM->LogMessage( myself, "Creating ray ..." );
  145.     Ray_t ray;
  146.     ray.Init( pos, pos, mins, maxs );
  147.     g_pSM->LogMessage( myself, "Ray created" );
  148.  
  149.     g_pSM->LogMessage( myself, "Creating trace filter ..." );
  150.     IHandleEntity* playerhandle = reinterpret_cast<IHandleEntity*>( gamehelpers->GetHandleEntity( g_pGameMovement->mv->m_nPlayerHandle ) );
  151.     CTraceFilterSimple traceFilter( playerhandle, collisiongroup );
  152.     g_pSM->LogMessage( myself, "Trace filter created" );
  153.  
  154.     g_pSM->LogMessage( myself, "Doing trace ..." );
  155.     enginetrace->TraceRay( ray, MASK_PLAYERSOLID, &tracefilter, &pm );
  156.     g_pSM->LogMessage( myself, "Trace finished" );
  157.  
  158.     if( (pm.contents & MASK_PLAYERSOLID) && pm.m_pEnt )
  159.     {
  160.         g_pSM->LogMessage( myself, "END 1: standing on entity" );
  161.         RETURN_META_VALUE( MRES_SUPERCEDE, reinterpret_cast<IHandleEntity*>(pm.m_pEnt)->GetRefEHandle() );
  162.     }
  163.     else
  164.     {
  165.         g_pSM->LogMessage( myself, "END 2: not standing on entity" );
  166.         RETURN_META_VALUE( MRES_SUPERCEDE, INVALID_EHANDLE_INDEX );
  167.     }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement