Вопрос Двухслойные чамсы

ППХУДЕР
Начинающий
Статус
Оффлайн
Регистрация
10 Фев 2020
Сообщения
422
Реакции[?]
23
Поинты[?]
6K
Кароче, захотел поверх регуляров сделать глоу. Крашит, дебаг тоже...
Что я сделал нетак?
C++:
#include "chams.hpp"
#include <fstream>

#include "../valve_sdk/csgostructs.hpp"
#include "../options.hpp"
#include "../hooks.hpp"
#include "../helpers/input.hpp"


Chams::Chams() {

    materialRegular = g_MatSystem->FindMaterial("debug/debugambientcube");
    materialFlat = g_MatSystem->FindMaterial("debug/debugdrawflat");
    materialGlow = g_MatSystem->FindMaterial("regular_glow");
    
}

Chams::~Chams() {
}


void Chams::OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba, const Color& rgba2) {
    Color col = rgba2;
    bool bFound = false;
    IMaterial* material = nullptr;
    IMaterial* material_style = nullptr;
    if (flat) {
        material = materialFlat;
    }

    if (g_Options.chams_player_glow) {
        material_style = materialGlow;
    }
    
    material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, ignoreZ);


    if (glass) {
        material = materialFlat;
        material->AlphaModulate(0.45f);
    }
    else {
        material->AlphaModulate(
            rgba.a() / 255.0f);
    }

    material->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, wireframe);
    material->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);
    material_style->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);

    g_MdlRender->ForcedMaterialOverride(material);
    g_MdlRender->ForcedMaterialOverride(material_style);
}


void Chams::OnDrawModelExecute(
    IMatRenderContext* ctx,
    const DrawModelState_t& state,
    const ModelRenderInfo_t& info,
    matrix3x4_t* matrix)
{
    static auto fnDME = Hooks::mdlrender_hook.get_original<decltype(&Hooks::hkDrawModelExecute)>(index::DrawModelExecute);

    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_Options.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_Options.chams_player_enemies_only)
                return;

            const auto clr_front = enemy ? g_Options.color_chams_player_enemy_visible : g_Options.color_chams_player_ally_visible;
            const auto clr_back = enemy ? g_Options.color_chams_player_enemy_occluded : g_Options.color_chams_player_ally_occluded;

            if (g_Options.chams_player_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_back,
                    g_Options.color_chams_player_glow);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_front,
                    g_Options.color_chams_player_glow);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    g_Options.chams_player_glass,
                    clr_front,
                    g_Options.color_chams_player_glow);
            }
        }
    }
    else if (is_sleeve && g_Options.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_Options.misc_no_hands) {
            //
            // No hands.
            //
            material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
            g_MdlRender->ForcedMaterialOverride(material);
        }
        else if (g_Options.chams_arms_enabled) {
            if (g_Options.chams_arms_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_occluded,
                    g_Options.color_chams_player_glow);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_visible,
                    g_Options.color_chams_player_glow);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    g_Options.chams_arms_glass,
                    g_Options.color_chams_arms_visible,
                    g_Options.color_chams_player_glow);
            }
        }
    }
}
база csgosimple
 
Пользователь
Статус
Оффлайн
Регистрация
10 Ноя 2019
Сообщения
839
Реакции[?]
135
Поинты[?]
0
Кароче, захотел поверх регуляров сделать глоу. Крашит, дебаг тоже...
Что я сделал нетак?
C++:
#include "chams.hpp"
#include <fstream>

#include "../valve_sdk/csgostructs.hpp"
#include "../options.hpp"
#include "../hooks.hpp"
#include "../helpers/input.hpp"


Chams::Chams() {

    materialRegular = g_MatSystem->FindMaterial("debug/debugambientcube");
    materialFlat = g_MatSystem->FindMaterial("debug/debugdrawflat");
    materialGlow = g_MatSystem->FindMaterial("regular_glow");
    
}

Chams::~Chams() {
}


void Chams::OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba, const Color& rgba2) {
    Color col = rgba2;
    bool bFound = false;
    IMaterial* material = nullptr;
    IMaterial* material_style = nullptr;
    if (flat) {
        material = materialFlat;
    }

    if (g_Options.chams_player_glow) {
        material_style = materialGlow;
    }
    
    material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, ignoreZ);


    if (glass) {
        material = materialFlat;
        material->AlphaModulate(0.45f);
    }
    else {
        material->AlphaModulate(
            rgba.a() / 255.0f);
    }

    material->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, wireframe);
    material->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);
    material_style->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);

    g_MdlRender->ForcedMaterialOverride(material);
    g_MdlRender->ForcedMaterialOverride(material_style);
}


void Chams::OnDrawModelExecute(
    IMatRenderContext* ctx,
    const DrawModelState_t& state,
    const ModelRenderInfo_t& info,
    matrix3x4_t* matrix)
{
    static auto fnDME = Hooks::mdlrender_hook.get_original<decltype(&Hooks::hkDrawModelExecute)>(index::DrawModelExecute);

    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_Options.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_Options.chams_player_enemies_only)
                return;

            const auto clr_front = enemy ? g_Options.color_chams_player_enemy_visible : g_Options.color_chams_player_ally_visible;
            const auto clr_back = enemy ? g_Options.color_chams_player_enemy_occluded : g_Options.color_chams_player_ally_occluded;

            if (g_Options.chams_player_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_back,
                    g_Options.color_chams_player_glow);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_front,
                    g_Options.color_chams_player_glow);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    g_Options.chams_player_glass,
                    clr_front,
                    g_Options.color_chams_player_glow);
            }
        }
    }
    else if (is_sleeve && g_Options.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_Options.misc_no_hands) {
            //
            // No hands.
            //
            material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
            g_MdlRender->ForcedMaterialOverride(material);
        }
        else if (g_Options.chams_arms_enabled) {
            if (g_Options.chams_arms_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_occluded,
                    g_Options.color_chams_player_glow);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_visible,
                    g_Options.color_chams_player_glow);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    g_Options.chams_arms_glass,
                    g_Options.color_chams_arms_visible,
                    g_Options.color_chams_player_glow);
            }
        }
    }
}
база csgosimple
Фикс был в инете, я забыл что там не так, так что могу сказать чтобы ты поискал :/
 
ставь чайник, зажигай плиту
Эксперт
Статус
Оффлайн
Регистрация
22 Май 2020
Сообщения
1,444
Реакции[?]
1,092
Поинты[?]
10K
Кароче, захотел поверх регуляров сделать глоу. Крашит, дебаг тоже...
Что я сделал нетак?
C++:
#include "chams.hpp"
#include <fstream>

#include "../valve_sdk/csgostructs.hpp"
#include "../options.hpp"
#include "../hooks.hpp"
#include "../helpers/input.hpp"


Chams::Chams() {

    materialRegular = g_MatSystem->FindMaterial("debug/debugambientcube");
    materialFlat = g_MatSystem->FindMaterial("debug/debugdrawflat");
    materialGlow = g_MatSystem->FindMaterial("regular_glow");
  
}

Chams::~Chams() {
}


void Chams::OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba, const Color& rgba2) {
    Color col = rgba2;
    bool bFound = false;
    IMaterial* material = nullptr;
    IMaterial* material_style = nullptr;
    if (flat) {
        material = materialFlat;
    }

    if (g_Options.chams_player_glow) {
        material_style = materialGlow;
    }
  
    material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, ignoreZ);


    if (glass) {
        material = materialFlat;
        material->AlphaModulate(0.45f);
    }
    else {
        material->AlphaModulate(
            rgba.a() / 255.0f);
    }

    material->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, wireframe);
    material->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);
    material_style->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);

    g_MdlRender->ForcedMaterialOverride(material);
    g_MdlRender->ForcedMaterialOverride(material_style);
}


void Chams::OnDrawModelExecute(
    IMatRenderContext* ctx,
    const DrawModelState_t& state,
    const ModelRenderInfo_t& info,
    matrix3x4_t* matrix)
{
    static auto fnDME = Hooks::mdlrender_hook.get_original<decltype(&Hooks::hkDrawModelExecute)>(index::DrawModelExecute);

    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_Options.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_Options.chams_player_enemies_only)
                return;

            const auto clr_front = enemy ? g_Options.color_chams_player_enemy_visible : g_Options.color_chams_player_ally_visible;
            const auto clr_back = enemy ? g_Options.color_chams_player_enemy_occluded : g_Options.color_chams_player_ally_occluded;

            if (g_Options.chams_player_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_back,
                    g_Options.color_chams_player_glow);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_front,
                    g_Options.color_chams_player_glow);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    g_Options.chams_player_glass,
                    clr_front,
                    g_Options.color_chams_player_glow);
            }
        }
    }
    else if (is_sleeve && g_Options.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_Options.misc_no_hands) {
            //
            // No hands.
            //
            material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
            g_MdlRender->ForcedMaterialOverride(material);
        }
        else if (g_Options.chams_arms_enabled) {
            if (g_Options.chams_arms_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_occluded,
                    g_Options.color_chams_player_glow);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_visible,
                    g_Options.color_chams_player_glow);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    g_Options.chams_arms_glass,
                    g_Options.color_chams_arms_visible,
                    g_Options.color_chams_player_glow);
            }
        }
    }
}
база csgosimple
Во-первых, ты форсишь nullptr, когда у тебя отключён доп. glow.
IMaterial* material_style = nullptr;
g_MdlRender->ForcedMaterialOverride(material_style);

Во-вторых, ты делаешь это неправильно.
Для каждого материала должна быть такая структура:
->ForcedMatOverride(material)
original

Если это DME, то в конце самого хука также необходимо делать ForcedMaterialOverride(nullptr)

Что я могу посоветовать в твоём случае: верни дефолтную функция оверрайда из симпла, а для доп. материала просто вызывай эту функцию ещё раз, подобно
Пожалуйста, авторизуйтесь для просмотра ссылки.
 
ППХУДЕР
Начинающий
Статус
Оффлайн
Регистрация
10 Фев 2020
Сообщения
422
Реакции[?]
23
Поинты[?]
6K
Во-первых, ты форсишь nullptr, когда у тебя отключён доп. glow.




Во-вторых, ты делаешь это неправильно.
Для каждого материала должна быть такая структура:
->ForcedMatOverride(material)
original

Если это DME, то в конце самого хука также необходимо делать ForcedMaterialOverride(nullptr)

Что я могу посоветовать в твоём случае: верни дефолтную функция оверрайда из симпла, а для доп. материала просто вызывай эту функцию ещё раз, подобно
Пожалуйста, авторизуйтесь для просмотра ссылки.
вроде сделал все как ты сказал, но у меня рендерится только 1 материал
C++:
#include "chams.hpp"
#include <fstream>
#include "../KeyValues.hpp"
#include "../valve_sdk/csgostructs.hpp"
#include "../options.hpp"
#include "../hooks.hpp"
#include "../helpers/input.hpp"


Chams::Chams() {
    materialRegular = g_MatSystem->FindMaterial("debug/debugambientcube");
    materialFlat = g_MatSystem->FindMaterial("debug/debugdrawflat");
    KeyValues* GlowChams = new KeyValues("NameChams");
    GlowChams->LoadFromBuffer(GlowChams, "NameChams", R"#("VertexLitGeneric" {

    "$additive" "1"
    "$envmap" "models/effects/cube_white"
    "$envmaptint" "[1 1 1]"
    "$envmapfresnel" "1"
    "$envmapfresnelminmaxexp" "[0 1 2]"
    "$alpha" "0.6"
    })#");
    materialGlow = g_MatSystem->CreateMaterial("GlowChams", GlowChams);
    materialGlow->IncrementReferenceCount();
}

Chams::~Chams() {
}


void Chams::OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba) {
    IMaterial* material = nullptr;

    if (flat) {
        material = materialFlat;
    }
    else {
        material = materialRegular;
    }
    material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, ignoreZ);


    if (glass) {
        material = materialFlat;
        material->AlphaModulate(0.45f);
    }
    else {
        material->AlphaModulate(
            rgba.a() / 255.0f);
    }

    material->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, wireframe);
    material->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);
    
    g_MdlRender->ForcedMaterialOverride(material);
}
void Chams::OverrideMaterial2() {
    g_MdlRender->ForcedMaterialOverride(materialGlow);
}
void Chams::OnDrawModelExecute(
    IMatRenderContext* ctx,
    const DrawModelState_t& state,
    const ModelRenderInfo_t& info,
    matrix3x4_t* matrix)
{
    static auto fnDME = Hooks::mdlrender_hook.get_original<decltype(&Hooks::hkDrawModelExecute)>(index::DrawModelExecute);

    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_Options.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_Options.chams_player_enemies_only)
                return;

            const auto clr_front = enemy ? g_Options.color_chams_player_enemy_visible : g_Options.color_chams_player_ally_visible;
            const auto clr_back = enemy ? g_Options.color_chams_player_enemy_occluded : g_Options.color_chams_player_ally_occluded;

            if (g_Options.chams_player_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_back);
                OverrideMaterial2();
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_front);
                OverrideMaterial2();
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    g_Options.chams_player_glass,
                    clr_front);
                OverrideMaterial2();
            }
        }
    }
    else if (is_sleeve && g_Options.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_Options.misc_no_hands) {
            //
            // No hands.
            //
            material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
            g_MdlRender->ForcedMaterialOverride(material);
        }
        else if (g_Options.chams_arms_enabled) {
            if (g_Options.chams_arms_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_occluded);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_visible);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    g_Options.chams_arms_glass,
                    g_Options.color_chams_arms_visible);
            }
        }
    }
}
не бей если сделал не так
 
how to доказать всем что не еблан
Пользователь
Статус
Оффлайн
Регистрация
14 Авг 2019
Сообщения
386
Реакции[?]
108
Поинты[?]
17K
вроде сделал все как ты сказал, но у меня рендерится только 1 материал
C++:
#include "chams.hpp"
#include <fstream>
#include "../KeyValues.hpp"
#include "../valve_sdk/csgostructs.hpp"
#include "../options.hpp"
#include "../hooks.hpp"
#include "../helpers/input.hpp"


Chams::Chams() {
    materialRegular = g_MatSystem->FindMaterial("debug/debugambientcube");
    materialFlat = g_MatSystem->FindMaterial("debug/debugdrawflat");
    KeyValues* GlowChams = new KeyValues("NameChams");
    GlowChams->LoadFromBuffer(GlowChams, "NameChams", R"#("VertexLitGeneric" {

    "$additive" "1"
    "$envmap" "models/effects/cube_white"
    "$envmaptint" "[1 1 1]"
    "$envmapfresnel" "1"
    "$envmapfresnelminmaxexp" "[0 1 2]"
    "$alpha" "0.6"
    })#");
    materialGlow = g_MatSystem->CreateMaterial("GlowChams", GlowChams);
    materialGlow->IncrementReferenceCount();
}

Chams::~Chams() {
}


void Chams::OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba) {
    IMaterial* material = nullptr;

    if (flat) {
        material = materialFlat;
    }
    else {
        material = materialRegular;
    }
    material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, ignoreZ);


    if (glass) {
        material = materialFlat;
        material->AlphaModulate(0.45f);
    }
    else {
        material->AlphaModulate(
            rgba.a() / 255.0f);
    }

    material->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, wireframe);
    material->ColorModulate(
        rgba.r() / 255.0f,
        rgba.g() / 255.0f,
        rgba.b() / 255.0f);
  
    g_MdlRender->ForcedMaterialOverride(material);
}
void Chams::OverrideMaterial2() {
    g_MdlRender->ForcedMaterialOverride(materialGlow);
}
void Chams::OnDrawModelExecute(
    IMatRenderContext* ctx,
    const DrawModelState_t& state,
    const ModelRenderInfo_t& info,
    matrix3x4_t* matrix)
{
    static auto fnDME = Hooks::mdlrender_hook.get_original<decltype(&Hooks::hkDrawModelExecute)>(index::DrawModelExecute);

    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_Options.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_Options.chams_player_enemies_only)
                return;

            const auto clr_front = enemy ? g_Options.color_chams_player_enemy_visible : g_Options.color_chams_player_ally_visible;
            const auto clr_back = enemy ? g_Options.color_chams_player_enemy_occluded : g_Options.color_chams_player_ally_occluded;

            if (g_Options.chams_player_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_back);
                OverrideMaterial2();
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    false,
                    clr_front);
                OverrideMaterial2();
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_player_flat,
                    g_Options.chams_player_wireframe,
                    g_Options.chams_player_glass,
                    clr_front);
                OverrideMaterial2();
            }
        }
    }
    else if (is_sleeve && g_Options.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_Options.misc_no_hands) {
            //
            // No hands.
            //
            material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
            g_MdlRender->ForcedMaterialOverride(material);
        }
        else if (g_Options.chams_arms_enabled) {
            if (g_Options.chams_arms_ignorez) {
                OverrideMaterial(
                    true,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_occluded);
                fnDME(g_MdlRender, 0, ctx, state, info, matrix);
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    false,
                    g_Options.color_chams_arms_visible);
            }
            else {
                OverrideMaterial(
                    false,
                    g_Options.chams_arms_flat,
                    g_Options.chams_arms_wireframe,
                    g_Options.chams_arms_glass,
                    g_Options.color_chams_arms_visible);
            }
        }
    }
}
не бей если сделал не так
1625992325337.png
DME вызывается всего 1 раз
после каждого оверрайда материала ты должен вызвать ориг DME
C++:
OverrideMaterial(
true,
g_Options.chams_arms_flat,
g_Options.chams_arms_wireframe,
false,
g_Options.color_chams_arms_occluded);
fnDME(g_MdlRender, 0, ctx, state, info, matrix);
OverrideMaterial(
false,
g_Options.chams_arms_flat,
g_Options.chams_arms_wireframe,
false,
g_Options.color_chams_arms_visible);
fnDME(g_MdlRender, 0, ctx, state, info, matrix);
утак вот получается
 
Похожие темы
Сверху Снизу