-
Автор темы
- #1
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
hooks inicialize
index
draw model hooks
chams
{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;
}
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;
}
Код:
auto draw_model_target = reinterpret_cast<void*>(get_virtual(g_MdlRender, 21));
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);
}
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));
}
}
}
}