-
Автор темы
- #1
Код:
#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", "Model textures");
materialFlat = g_MatSystem->FindMaterial("debug/debugdrawflat", "Model textures");
materialGold = g_MatSystem->FindMaterial("models/inventory_items/trophy_majors/gold", TEXTURE_GROUP_OTHER);
materialGlass = g_MatSystem->FindMaterial("models/inventory_items/cologne_prediction/cologne_prediction_glass", TEXTURE_GROUP_OTHER);
materialGloss = g_MatSystem->FindMaterial("models/inventory_items/trophy_majors/gloss", TEXTURE_GROUP_OTHER);
materialCrystal = g_MatSystem->FindMaterial("models/inventory_items/trophy_majors/crystal_clear", TEXTURE_GROUP_OTHER);
materialCrystalBlue = g_MatSystem->FindMaterial("models/inventory_items/trophy_majors/crystal_blue", TEXTURE_GROUP_OTHER);
materialSilver = g_MatSystem->FindMaterial("models/inventory_items/hydra_crystal/hydra_crystal_detail", TEXTURE_GROUP_OTHER);
}
Chams::~Chams()
{
}
void Chams::OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba, bool modulate, bool gold, bool crystal, bool crystal2, bool silver)
{
IMaterial* material = nullptr;
if (modulate) {
if (flat)
material = materialFlat;
else if (gold)
material = materialGold;
else if (crystal)
material = materialCrystal;
else if (glass)
material = materialGlass;
else if (crystal2)
material = materialCrystalBlue;
else if (silver)
material = materialSilver;
else
material = materialRegular;
}
bool bFound = false;
IMaterialVar* pMatVar = material->FindVar("$envmaptint", &bFound);
material->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, ignoreZ);
material->SetMaterialVarFlag(MATERIAL_VAR_WIREFRAME, wireframe);
material->ColorModulate(
rgba.r() / 255.0f,
rgba.g() / 255.0f,
rgba.b() / 255.0f);
material->AlphaModulate(
rgba.a() / 255.0f);
material->IncrementReferenceCount();
g_MdlRender->ForcedMaterialOverride(material);
}
void Chams::OnDrawModelExecute(IMatRenderContext* ctx, const DrawModelState_t& state, const ModelRenderInfo_t& info, matrix3x4_t* matrix) {
static auto fnDME = Hooks::mdlrender_hook.GetOriginal<decltype(&Hooks::hkDrawModelExecute)>();
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) {
auto ent = C_BasePlayer::GetPlayerByIndex(info.entity_index);
if (ent && g_LocalPlayer && ent->IsAlive()) {
const auto enemy = ent->m_iTeamNum() != g_LocalPlayer->m_iTeamNum();
const auto clr_front = enemy ? Color(g_Options.color_chams_player_enemy_visible) : Color(g_Options.color_chams_player_ally_visible);
const auto clr_back = enemy ? Color(g_Options.color_chams_player_enemy_occluded) : Color(g_Options.color_chams_player_ally_occluded);
if (!enemy && g_Options.chams_player_enemies_only)
return;
if (g_Options.chams_player_enemies_player) {
OverrideMaterial(
true,
g_Options.chams_player_flat,
g_Options.chams_player_wireframe,
g_Options.chams_player_glass,
clr_back,
g_Options.chams_player_modulate,
g_Options.chams_player_gold,
g_Options.chams_player_crystal,
g_Options.chams_player_crystal2,
g_Options.chams_player_silver
);
fnDME(g_MdlRender, 0, ctx, state, info, matrix);
g_MdlRender->ForcedMaterialOverride(nullptr);
OverrideMaterial(
false,
g_Options.chams_player_flat,
g_Options.chams_player_wireframe,
g_Options.chams_player_glass,
clr_front,
g_Options.chams_player_modulate,
g_Options.chams_player_gold,
g_Options.chams_player_crystal,
g_Options.chams_player_crystal2,
g_Options.chams_player_silver
);
}
else {
OverrideMaterial(
false,
g_Options.chams_player_flat,
g_Options.chams_player_wireframe,
g_Options.chams_player_glass,
clr_front,
false,
false,
false,
false,
false);
}
}
}
else if (is_sleeve && g_Options.chams_sleeves_enabled) {
OverrideMaterial(
false,
g_Options.chams_sleeves_flat,
false,
false,
Color(g_Options.color_chams_sleeves),
true,
false,
false,
false,
false
);
}
else if (!is_arm && !is_sleeve && is_weapon && g_Options.chams_weapon_enabled)
{
OverrideMaterial(
false,
g_Options.chams_weapon_flat,
false,
false,
Color(g_Options.color_chams_weapons),
true,
false,
false,
false,
false
);
}
else if (is_arm && !is_sleeve) {
auto material = g_MatSystem->FindMaterial(mdl->szName, TEXTURE_GROUP_MODEL);
if (!material)
return;
if (g_Options.other_no_hands) {
material->SetMaterialVarFlag(MATERIAL_VAR_NO_DRAW, true);
g_MdlRender->ForcedMaterialOverride(material);
}
else if (g_Options.other_hand_chams) {
OverrideMaterial(
false,
g_Options.chams_hand_flat,
false,
false,
Color(g_Options.color_chams_hands),
true,
false,
false,
false,
false
);
}
}
bool forced_mat = !g_MdlRender->IsForcedMaterialOverride();
if (forced_mat) {
if (forced_mat)
g_MdlRender->ForcedMaterialOverride(NULL);
}
}
Код:
#pragma once
#include "../singleton.hpp"
class IMatRenderContext;
struct DrawModelState_t;
struct ModelRenderInfo_t;
class matrix3x4_t;
class IMaterial;
class Color;
class Chams
: public Singleton<Chams>
{
friend class Singleton<Chams>;
Chams();
~Chams();
public:
void OnDrawModelExecute(
IMatRenderContext* ctx,
const DrawModelState_t& state,
const ModelRenderInfo_t& pInfo,
matrix3x4_t* pCustomBoneToWorld
);
private:
void OverrideMaterial(bool ignoreZ, bool flat, bool wireframe, bool glass, const Color& rgba, bool modulate, bool gold, bool crystal , bool crystal2, bool silver);
IMaterial* materialRegular = nullptr;
IMaterial* materialRegularIgnoreZ = nullptr;
IMaterial* materialFlatIgnoreZ = nullptr;
IMaterial* materialFlat = nullptr;
IMaterial* materialGold = nullptr;
IMaterial* materialGlass = nullptr;
IMaterial* materialGloss = nullptr;
IMaterial* materialCrystal = nullptr;
IMaterial* materialCrystalBlue = nullptr;
IMaterial* materialSilver = nullptr;
};