designer1337 / csgo-cheat-base

simple csgo internal base.
MIT License
242 stars 50 forks source link

sv_cheats help #7

Closed bruhmoment21 closed 4 years ago

bruhmoment21 commented 4 years ago

i am trying to hook sv_cheats like this

// .hpp file
namespace sv_cheats {
        using fn = bool( __thiscall* )( convar* );
        static bool __fastcall hook( ) noexcept;
    }

// .cpp file
hooks::sv_cheats::fn sv_cheats_original = nullptr;
auto sv_cheats_target = reinterpret_cast< void* >( get_virtual( interfaces::console->get_convar( "sv_cheats" ), 13 ) );

if ( MH_CreateHook( sv_cheats_target, &sv_cheats::hook, reinterpret_cast< void** >( &sv_cheats_original ) ) != MH_OK ) {
        throw std::runtime_error( "failed to initialize sv_cheats. (outdated index?)" );
        return false;
    }

static bool __fastcall hooks::sv_cheats::hook( ) noexcept {
    if ( interfaces::engine->is_in_game( ) && config_system.esp.thirdperson ) {
        static auto think = utilities::pattern_scan( GetModuleHandleA( "client_panorama.dll" ), "85 C0 75 30 38 86" );
        static auto original_fn = sv_cheats_original( interfaces::console->get_convar( "sv_cheats" ) );
        if ( !original_fn )
            return false;

        if ( reinterpret_cast< DWORD >( _ReturnAddress( ) ) == reinterpret_cast< DWORD >( think ) )
            return true;
        return original_fn;
    }
}

image this is what i get for hooking it. i appreciate any help!

designer1337 commented 4 years ago

No need to cast sig and return address to DWORD...

bool __fastcall hooks::sv_cheats_get_bool::hook(PVOID convar, int edx) {
    if ((_ReturnAddress()) == cam_think)
        return true;
    else
        return sv_cheats_get_bool_original(convar);
}
bruhmoment21 commented 4 years ago

still have it. didn't fix

designer1337 commented 4 years ago

works fine for me using method above

bruhmoment21 commented 4 years ago

lol it worked the whole time. with alphauc hooking method you could use commands that needed sv_cheats like r_drawothermodels with this hooking method you can't use them