Minhook chams

Пользователь
Статус
Оффлайн
Регистрация
26 Ноя 2017
Сообщения
73
Реакции[?]
34
Поинты[?]
0
Hello, I changed the hooks of csgosimple and I'm having problems with the draw model if someone can help
{sorry for my English}

hooks.hpp
C++:
    namespace draw_model_execute {
        using fn = void(__thiscall*)(void*, unsigned int, IMatRenderContext*, const DrawModelState_t&, const ModelRenderInfo_t&, matrix3x4_t*);
        void __fastcall hook(void* _this, int edx, IMatRenderContext* ctx, const DrawModelState_t& state, const ModelRenderInfo_t& pInfo, matrix3x4_t* pCustomBoneToWorld);
        inline static fn original;
    }
hooks inicialize
C++:
        if (MH_CreateHook(draw_model_target, &draw_model_execute::hook, reinterpret_cast<void**>(&draw_model_execute::original)) != MH_OK) {
            throw std::runtime_error("failed to initialize create_move. (outdated index?)");
            return false;
        }
index
Код:
auto draw_model_target = reinterpret_cast<void*>(get_virtual(g_MdlRender, 21));
draw model hooks
C++:
    void __fastcall draw_model_execute::hook(void* _this, int edx, IMatRenderContext* ctx, const DrawModelState_t& state, const ModelRenderInfo_t& pInfo, matrix3x4_t* pCustomBoneToWorld)
    {
        if (g_MdlRender->IsForcedMaterialOverride() &&
            !strstr(pInfo.pModel->szName, "arms") &&
            !strstr(pInfo.pModel->szName, "weapons/v_")) {
            return original(_this, edx, ctx, state, pInfo, pCustomBoneToWorld);
        }

        Chams::Get().OnDrawModelExecute(ctx, state, pInfo, pCustomBoneToWorld);

        original(_this, edx, ctx, state, pInfo, pCustomBoneToWorld);
        g_MdlRender->ForcedMaterialOverride(nullptr);
    }
chams
C++:
void Chams::OnDrawModelExecute(IMatRenderContext* ctx, const DrawModelState_t& state, const ModelRenderInfo_t& info, matrix3x4_t* matrix)
{
    const auto mdl = info.pModel;

    bool is_arm = strstr(mdl->szName, "arms") != nullptr;
    bool is_player = strstr(mdl->szName, "models/player") != nullptr;
    bool is_sleeve = strstr(mdl->szName, "sleeve") != nullptr;
    //bool is_weapon = strstr(mdl->szName, "weapons/v_")  != nullptr;

    if (is_player && g_Settings.chams_player_enabled) {
        // Draw player Chams.
        auto ent = C_BasePlayer::GetPlayerByIndex(info.entity_index);

        if (ent && g_LocalPlayer && ent->IsAlive()) {
            const auto enemy = ent->m_iTeamNum() != g_LocalPlayer->m_iTeamNum();
            if (!enemy && g_Settings.chams_player_enemies_only)
                return;

            const auto clr_front = enemy ? Color(g_Settings.color_chams_player_enemy_visible) : Color(g_Settings.color_chams_player_ally_visible);
            const auto clr_back = enemy ? Color(g_Settings.color_chams_player_enemy_occluded) : Color(g_Settings.color_chams_player_ally_occluded);

            if (g_Settings.chams_player_ignorez) {
                OverrideMaterialPlayer(
                    true,
                    g_Settings.chams_player_wireframe,
                    g_Settings.chams_material,
                    clr_back);
                Hooks::draw_model_execute::original(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterialPlayer(
                    false,
                    g_Settings.chams_player_wireframe,
                    g_Settings.chams_material,
                    clr_front);
            }
            else {
                OverrideMaterialPlayer(
                    false,
                    g_Settings.chams_player_wireframe,
                    g_Settings.chams_material,
                    clr_front);
            }
        }
    }
    else if (is_sleeve && g_Settings.chams_arms_enabled) {
        auto material = g_MatSystem->FindMaterial(mdl->szName, TEXTURE_GROUP_MODEL);
        if (!material)
            return;
        // Remove sleeves when drawing Chams.
        material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
        g_MdlRender->ForcedMaterialOverride(material);
    }
    else if (is_arm) {
        auto material = g_MatSystem->FindMaterial(mdl->szName, TEXTURE_GROUP_MODEL);
        if (!material)
            return;
        if (g_Settings.misc_no_hands) {
            // No hands.
            material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
            g_MdlRender->ForcedMaterialOverride(material);
        }
        else if (g_Settings.chams_arms_enabled) {
            if (g_Settings.chams_arms_ignorez) {
                OverrideMaterialArms(
                    true,
                    g_Settings.chams_arms_wireframe,
                    g_Settings.chams_material_arms,
                    Color(g_Settings.color_chams_arms_occluded));
                Hooks::draw_model_execute::original(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterialArms(
                    false,
                    g_Settings.chams_arms_wireframe,
                    g_Settings.chams_material_arms,
                    Color(g_Settings.color_chams_arms_visible));
            }
            else {
                OverrideMaterialArms(
                    false,
                    g_Settings.chams_arms_wireframe,
                    g_Settings.chams_material_arms,
                    Color(g_Settings.color_chams_arms_visible));
            }
        }
    }
}
 
oooh my...
Пользователь
Статус
Оффлайн
Регистрация
5 Янв 2018
Сообщения
168
Реакции[?]
66
Поинты[?]
0
if (MH_CreateHook(draw_model_target, &draw_model_execute::hook, reinterpret_cast<void**>(&draw_model_execute::original)) != MH_OK) { throw std::runtime_error("failed to initialize create_move. (outdated index?)"); return false; }
Ты создал хук, но не включил его

C++:
if (MH_EnableHook(draw_model_target) != MH_OK)
{
    std::runtime_error("failed to enable create_move");
}
Ниже можешь посмотреть пример от разрабов либы, там ярко виден алгоритм создания хука
C++:
#include <Windows.h>
#include "MinHook.h"

#if defined _M_X64
#pragma comment(lib, "libMinHook.x64.lib")
#elif defined _M_IX86
#pragma comment(lib, "libMinHook.x86.lib")
#endif

// Helper function for MH_CreateHookApi().
template <typename T>
inline MH_STATUS MH_CreateHookApiEx(LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, T** ppOriginal)
{
    return MH_CreateHookApi(pszModule, pszProcName, pDetour, reinterpret_cast<LPVOID*>(ppOriginal));
}

typedef int (WINAPI *MESSAGEBOXW)(HWND, LPCWSTR, LPCWSTR, UINT);

// Pointer for calling original MessageBoxW.
MESSAGEBOXW fpMessageBoxW = NULL;

// Detour function which overrides MessageBoxW.
int WINAPI DetourMessageBoxW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType)
{
    return fpMessageBoxW(hWnd, L"Hooked!", lpCaption, uType);
}

int main()
{
    // Initialize MinHook.
    if (MH_Initialize() != MH_OK)
    {
        return 1;
    }

    // Create a hook for MessageBoxW, in disabled state.
    if (MH_CreateHookApiEx(L"user32", "MessageBoxW", &DetourMessageBoxW, &fpMessageBoxW) != MH_OK)
    {
        return 1;
    }

    // Enable the hook for MessageBoxW.
    if (MH_EnableHook(&MessageBoxW) != MH_OK)
    {
        return 1;
    }

    // Expected to tell "Hooked!".
    MessageBoxW(NULL, L"Not hooked...", L"MinHook Sample", MB_OK);

    // Disable the hook for MessageBoxW.
    if (MH_DisableHook(&MessageBoxW) != MH_OK)
    {
        return 1;
    }

    // Expected to tell "Not hooked...".
    MessageBoxW(NULL, L"Not hooked...", L"MinHook Sample", MB_OK);

    // Uninitialize MinHook.
    if (MH_Uninitialize() != MH_OK)
    {
        return 1;
    }

    return 0;
}
 
Последнее редактирование:
Забаненный
Статус
Оффлайн
Регистрация
14 Авг 2020
Сообщения
23
Реакции[?]
10
Поинты[?]
0
Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
look at the shonax's weave source
 
Сверху Снизу