designer1337 / csgo-cheat-base

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

Cvars returns nullptr value #8

Closed sovissa closed 4 years ago

sovissa commented 4 years ago
namespace backtrack {
    struct stored_records {
        vec3_t head;
        float simtime;
        matrix_t matrix[ 128 ];
    };
    struct convars {
        convar *update_rate;
        convar *max_update_rate;
        convar *interp;
        convar *interp_ratio;
        convar *min_interp_ratio;
        convar *max_interp_ratio;
        convar *max_unlag;
    };
    void update();
    void run( c_usercmd *cmd );
    float get_lerp_time();
    int time_to_ticks( float time );
    bool valid_tick( float simtime );

    static void init() {
        std::deque<stored_records> records[ 65 ];
        convars cvars;
        records->clear();
        cvars.update_rate = ctx::console->get_convar( "cl_updaterate" );
        cvars.max_update_rate = ctx::console->get_convar( "sv_maxupdaterate" );
        cvars.interp = ctx::console->get_convar( "cl_interp" );
        cvars.interp_ratio = ctx::console->get_convar( "cl_interp_ratio" );
        cvars.min_interp_ratio = ctx::console->get_convar( "sv_client_min_interp_ratio" );
        cvars.max_interp_ratio = ctx::console->get_convar( "sv_client_max_interp_ratio" );
        cvars.max_unlag = ctx::console->get_convar( "sv_maxunlag" );
    }
};

in hooks.cpp:

void __stdcall hooks::frame::hook( int frame_stage ) {
    static bool backtrack_init = ( backtrack::init(), false );

    if ( frame_stage == FRAME_NET_UPDATE_END && ctx::engine->in_game() )
        backtrack::update();

    orig_frame( ctx::client, frame_stage );
}

but its crashing, when i calling this:

float get_lerp_time() {
        auto ratio = std::clamp( cvars.interp_ratio->get_float(), cvars.min_interp_ratio->get_float(), cvars.max_interp_ratio->get_float() );
        return max( cvars.interp->get_float(), ( ratio / ( ( cvars.max_update_rate ) ? cvars.max_update_rate->get_float() : cvars.update_rate->get_float() ) ) );
    }
designer1337 commented 4 years ago

most likely thats ur get_float() problem

    float get_float() {
        using original_fn = float(__thiscall*)(convar*);
        return (*(original_fn**)this)[12](this);
    }

works fine for me.

sovissa commented 4 years ago

backtrack::cvars.max_interp_ratio was nullptr. nop maybe init or hooks issue?

void __stdcall hooks::frame::hook( int frame_stage ) {
    static bool backtrack_init = ( backtrack::init(), false );

    if ( frame_stage == FRAME_NET_UPDATE_END && ctx::engine->in_game() )
        backtrack::update();

    orig_frame( ctx::client, frame_stage );
}

auto tg_frame = reinterpret_cast< void * >( get_virtual( ctx::client, 37 ) );

prediction::init( cmd ); {
        backtrack::run( cmd );
    } prediction::end();
namespace frame {
        using fn = void( __thiscall * )( i_base_client_dll *, int );
        void __stdcall hook( int frame_stage );
    }
sovissa commented 4 years ago

^^

bruhmoment21 commented 4 years ago

try changing int frame_stage to client_frame_stage_t frame_stage