Jump to content

use at your own risk New Engine prediction for ur weave paste


Recommended Posts

in engineprediction.cpp

#include "EnginePrediction.h"
#include "checksum_md5.h"
#include "AntiAims.h"

int post_think(IBasePlayer* player) {
    getvfunc<void(__thiscall*)(void*)>(interfaces.model_cache, 33)(interfaces.model_cache);

    if (player->isAlive()
        || *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(player) + 0x3A81)) {
        getvfunc<void(__thiscall*)(void*)>(player, 339)(player);

        player->GetFlags()& FL_ONGROUND ? player->GetFallVelocity() = 0.f : 0;

        player->GetSequence() == -1 ? getvfunc<void(__thiscall*)(void*, int)>(player, 218)(player, 0) : 0;

        getvfunc<void(__thiscall*)(void*)>(player, 219)(player);

        static auto post_think_v_physics = reinterpret_cast <bool(__thiscall*)(IBasePlayer*)> (g_csgo->Utils.FindPatternIDA(GetModuleHandleA(g_Modules[fnv::hash(hs::client_dll::s().c_str())].c_str()),
            hs::post_think::s().c_str()));
        post_think_v_physics(player);
    }

    static auto simulate_player_simulated_entities = reinterpret_cast <bool(__thiscall*)(IBasePlayer*)> (g_csgo->Utils.FindPatternIDA(GetModuleHandleA(
        g_Modules[fnv::hash(hs::client_dll::s().c_str())].c_str()),
        hs::simulate_player::s().c_str()));
    simulate_player_simulated_entities(player);

    return getvfunc<int(__thiscall*)(void*)>(interfaces.model_cache, 34)(interfaces.model_cache);
}

/*void CEnginePrediction::Start(CUserCmd* cmd, IBasePlayer* local) {

    if (!local)
        return;

    backup_data.flags = local->GetFlags();
    backup_data.velocity = local->GetVelocity();

    interfaces.prediction->Update(g_csgo->client_state->iDeltaTick, g_csgo->client_state->iDeltaTick > 0, g_csgo->client_state->nLastCommandAck,
        g_csgo->client_state->nLastOutgoingCommand + g_csgo->client_state->iChokedCommands);

    old_vars.curtime = interfaces.global_vars->curtime;
    old_vars.frametime = interfaces.global_vars->frametime;
    old_vars.tickcount = interfaces.global_vars->tickcount;
    old_vars.m_in_prediction = interfaces.prediction->bInPrediction;
    old_vars.m_first_time_predicted = interfaces.prediction->bIsFirstTimePredicted;

    interfaces.global_vars->curtime = TICKS_TO_TIME(local->GetTickBase());
    interfaces.global_vars->frametime = interfaces.prediction->bEnginePaused ? 0.f : interfaces.global_vars->interval_per_tick;
    interfaces.global_vars->tickcount = TIME_TO_TICKS(interfaces.global_vars->curtime);
    interfaces.prediction->bInPrediction = true;
    interfaces.prediction->bIsFirstTimePredicted = false;

    *reinterpret_cast<CUserCmd**>(reinterpret_cast<uintptr_t>(local) + 0x3288) = cmd;

    if (!prediction_random_seed)
        prediction_random_seed = *reinterpret_cast <int**> (g_csgo->Utils.FindPatternIDA(GetModuleHandleA(g_Modules[fnv::hash(hs::client_dll::s().c_str())].c_str()), hs::random_seed::s().c_str()) + 0x1);

    if (!prediction_player)
        prediction_player = *reinterpret_cast <int**> (g_csgo->Utils.FindPatternIDA(GetModuleHandleA(g_Modules[fnv::hash(hs::client_dll::s().c_str())].c_str()), hs::prediction_player::s().c_str()) + 0x2);

    auto buttons_forced = *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(local) + 0x3334);
    auto buttons_disabled = *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(local) + 0x3330);

    cmd->buttons |= buttons_forced;
    cmd->buttons &= ~buttons_disabled;

    interfaces.move_helper->SetHost(local);
    interfaces.game_movement->StartTrackPredictionErrors(local);

    if (cmd->weaponselect) {
        auto weapon = reinterpret_cast<IBaseCombatWeapon*>(interfaces.ent_list->GetClientEntity(cmd->weaponselect));
        if (weapon) {
            auto weapon_data = weapon->GetCSWpnData();
            weapon_data ? local->SelectItem(weapon_data->m_szWeaponName, cmd->weaponsubtype) : 0;
        }
    }

    if (cmd->impulse)
        *local->GetImpulse() = cmd->impulse;

    auto buttons = cmd->buttons;
    auto buttons_changed = buttons ^ *local->GetButtons();

    local->GetButtonLast() = *local->GetButtons();
    *local->GetButtons() = buttons;
    local->GetButtonPressed() = buttons_changed & buttons;
    local->GetButtonReleased() = buttons_changed & ~buttons;

    interfaces.prediction->CheckMovingGround(local, interfaces.global_vars->frametime);

    local->SetLocalViewAngles(cmd->viewangles);

    local->PhysicsRunThink(0) ? local->PreThink() : 0;

    if (local->GetNextThinkTick()
        && *local->GetNextThinkTick() != -1
        && *local->GetNextThinkTick() <= local->GetTickBase()) {
        *local->GetNextThinkTick() = -1;
        local->UnkFunc();
        local->Think();
    }

    memset(&data, 0, sizeof(data));

    interfaces.prediction->SetupMove(local, cmd, interfaces.move_helper, &data);
    interfaces.game_movement->ProcessMovement(local, &data);
    interfaces.prediction->FinishMove(local, cmd, &data);

    interfaces.move_helper->ProcessImpacts();

    post_think(local);

    interfaces.prediction->bInPrediction = old_vars.m_in_prediction;
    interfaces.prediction->bIsFirstTimePredicted = old_vars.m_first_time_predicted;
}

void CEnginePrediction::Finish(IBasePlayer* local) {
    if (!local)
        return;

    interfaces.game_movement->FinishTrackPredictionErrors(local);
    interfaces.move_helper->SetHost(nullptr);
    interfaces.game_movement->Reset();

    *prediction_random_seed = -1;
    *prediction_player = 0;

    !interfaces.prediction->bEnginePaused&& interfaces.global_vars->frametime ? local->GetTickBasePtr()++ : 0;

    interfaces.global_vars->curtime = old_vars.curtime;
    interfaces.global_vars->frametime = old_vars.frametime;
}*/

void CEnginePrediction::Start(CUserCmd* cmd, IBasePlayer* local) {

    if (!local)
        return;

    // runcommand is only called on frames, when ur framerate dips, ur cmds wont be predicted (in time), so lots of things like desync etc fuck up
    // by simply forcing prediction on our cmds in CM, we circumvent all problems caused by this flawed setup where prediction is based on framerate
    interfaces.prediction->Update(g_csgo->client_state->iDeltaTick, true, g_csgo->client_state->nLastCommandAck, g_csgo->client_state->nLastOutgoingCommand + g_csgo->client_state->iChokedCommands);

    // random_seed isn't generated in ClientMode::CreateMove yet, we must generate it ourselves
    if (!prediction_random_seed)
        prediction_random_seed = *reinterpret_cast <int**> (g_csgo->Utils.FindPatternIDA(GetModuleHandleA(g_Modules[fnv::hash(hs::client_dll::s().c_str())].c_str()), hs::random_seed::s().c_str()) + 0x1);

    // backup globals.
    old_vars.curtime = interfaces.global_vars->curtime;
    old_vars.frametime = interfaces.global_vars->frametime;
    old_vars.tickcount = interfaces.global_vars->tickcount;

    // backup prediction states
    old_vars.m_in_prediction = interfaces.prediction->bInPrediction;
    old_vars.m_first_time_predicted = interfaces.prediction->bIsFirstTimePredicted;

    // set corrected values
    interfaces.global_vars->curtime = TICKS_TO_TIME(GetTickbase(cmd, local));
    interfaces.global_vars->frametime = interfaces.prediction->bEnginePaused ? 0.f : interfaces.global_vars->interval_per_tick;
    interfaces.global_vars->tickcount = TIME_TO_TICKS(interfaces.global_vars->curtime);

    interfaces.prediction->bInPrediction = true;
    interfaces.prediction->bIsFirstTimePredicted = false;

    *reinterpret_cast<CUserCmd**>(reinterpret_cast<uintptr_t>(local) + 0x3288) = cmd;

    if (!prediction_player)
        prediction_player = *reinterpret_cast <int**> (g_csgo->Utils.FindPatternIDA(GetModuleHandleA(g_Modules[fnv::hash(hs::client_dll::s().c_str())].c_str()), hs::prediction_player::s().c_str()) + 0x2);

    auto buttons_forced = *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(local) + 0x3334);
    auto buttons_disabled = *reinterpret_cast<int*>(reinterpret_cast<uintptr_t>(local) + 0x3330);

    cmd->buttons |= buttons_forced;
    cmd->buttons &= ~buttons_disabled;

    //weapon predict
    if (cmd->weaponselect) {
        auto weapon = reinterpret_cast<IBaseCombatWeapon*>(interfaces.ent_list->GetClientEntity(cmd->weaponselect));
        if (weapon) {
            auto weapon_data = weapon->GetCSWpnData();
            weapon_data ? local->SelectItem(weapon_data->m_szWeaponName, cmd->weaponsubtype) : 0;
        }
    }

    if (cmd->impulse)
        *local->GetImpulse() = cmd->impulse;

    auto buttons = cmd->buttons;
    auto buttons_changed = buttons ^ *local->GetButtons();

    // sync m_afButtonLast
    local->GetButtonLast() = *local->GetButtons();

    // syn m_nButtons
    *local->GetButtons() = buttons;

    // sync m_afButtonPressed
    local->GetButtonPressed() = buttons_changed & buttons;

    // sync m_afButtonReleased
    local->GetButtonReleased() = buttons_changed & ~buttons;

    // check if the player is standing on a moving entity and adjusts velocity and basevelocity appropriately
    interfaces.prediction->CheckMovingGround(local, interfaces.global_vars->frametime);

    // copy angles from command to player
    local->SetLocalViewAngles(cmd->viewangles);

    if (local->PhysicsRunThink(0)) //0 THINK_FIRE_ALL_FUNCTIONS
        local->PreThink();

    // run think
    if (local->GetNextThinkTick() > 0 && *local->GetNextThinkTick() <= GetTickbase(cmd, local))
    {
        *local->GetNextThinkTick() = -1;
        local->UnkFunc();
        local->Think();
    }

    // set target player ( host ).
    interfaces.move_helper->SetHost(local);
    interfaces.game_movement->StartTrackPredictionErrors(local);

    // setup move
    memset(&data, 0, sizeof(data));
    interfaces.prediction->SetupMove(local, cmd, interfaces.move_helper, &data);
    interfaces.game_movement->ProcessMovement(local, &data);

    // finish move
    interfaces.prediction->FinishMove(local, cmd, &data);
    interfaces.move_helper->ProcessImpacts();

    // run post think
    post_think(local);

    // restore prediction states
    interfaces.prediction->bInPrediction = old_vars.m_in_prediction;
    interfaces.prediction->bIsFirstTimePredicted = old_vars.m_first_time_predicted;
}

void CEnginePrediction::Finish(IBasePlayer* local) {
    if (!local)
        return;

    interfaces.game_movement->FinishTrackPredictionErrors(local);
    // reset host player
    interfaces.move_helper->SetHost(nullptr);

    interfaces.game_movement->Reset();

    *prediction_random_seed = -1;
    *prediction_player = 0;

    //restore globals
    interfaces.global_vars->curtime = old_vars.curtime;
    interfaces.global_vars->frametime = old_vars.frametime;
    interfaces.global_vars->tickcount = old_vars.tickcount;//why wernt u restroing tick count before -_-

    !interfaces.prediction->bEnginePaused&& interfaces.global_vars->frametime ? local->GetTickBasePtr()++ : 0;
}
//fixing tickbase this way is -_-
//we fix tickbase in our prediction so we can just use fixed curtime and the fix curtime help with other shit
int CEnginePrediction::GetTickbase(CUserCmd* pCmd, IBasePlayer* pLocal)
{
    static int iTick = 0;
    static CUserCmd* pLastCmd = nullptr;

    if (pCmd != nullptr)
    {
        // if command was not predicted - increment tickbase
        if (pLastCmd == nullptr || pLastCmd->hasbeenpredicted)
            iTick = pLocal->GetTickBase();
        else
            iTick++;

        pLastCmd = pCmd;
    }

    return iTick;
}

 in h files

#pragma once
#include "hooks.h"
#define ZERO Vector(0.0f, 0.0f, 0.0f)
#define MULTIPLAYER_BACKUP 150

struct backup
{
    int flags = 0;
    Vector velocity = Vector(0, 0, 0);
};

class CEnginePrediction : public Singleton<CEnginePrediction>
{
public:
    void Start(CUserCmd* cmd, IBasePlayer* local);
    void Finish(IBasePlayer* local);

    int GetTickbase(CUserCmd* pCmd, IBasePlayer* pLocal);

    backup backup_data;
private:
    CMoveData data;
    CUserCmd* last_cmd{};
    int32_t tick_base{};
    struct {
        float curtime, frametime;
        int tickcount, tickbase;
        bool m_in_prediction, m_first_time_predicted;
    }old_vars;
    int* prediction_random_seed = nullptr;
    int* prediction_player = nullptr;
};

/*class CEnginePrediction : public Singleton<CEnginePrediction>
{
public:
    void Start(CUserCmd* cmd, IBasePlayer* local);
    void Finish(IBasePlayer* local);

    backup backup_data;
private:
    CMoveData data;
    struct {
        float curtime, frametime;
        int tickcount, tickbase;
        bool m_in_prediction, m_first_time_predicted;
    }old_vars;
    int* prediction_random_seed = nullptr;
    int* prediction_player = nullptr;
};*/

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...