#ifndef CONCAT_IMPL
#define CONCAT_IMPL(x, y) x##y
#ifndef MACRO_CONCAT
#define MACRO_CONCAT(x, y) CONCAT_IMPL(x, y)
#ifndef PAD
#define PAD(SIZE) BYTE MACRO_CONCAT(_pad, __COUNTER__)[SIZE];
#endif
#endif
#endif
class KeyValues {
public:
PAD(32)
};
IMaterial *create_material(bool shade, bool wireframe, bool ignorez, int rimlight_boost = 0) {
static const std::string material_name = "csgo\\materials\\shiny_mat.vmt";
const std::string material_type = shade ? "VertexLitGeneric" : "UnlitGeneric";
std::string material_data;
material_data += "\"" + material_type + "\"\n{\n";
material_data += "\t\"$basetexture\" \"vgui/white_additive\"\n";
material_data += "\t\"$envmap\" \"env_cubemap\"\n";
material_data += "\t\"$normalmapalphaenvmapmask\" \"1\"\n";
material_data += "\t\"$envmapcontrast\" \"1\"\n";
material_data += "\t\"$nofog\" \"1\"\n";
material_data += "\t\"$model\" \"1\"\n";
material_data += "\t\"$nocull\" \"0\"\n";
material_data += "\t\"$selfillum\" \"1\"\n";
material_data += "\t\"$halflambert\" \"1\"\n";
material_data += "\t\"$znearer\" \"0\"\n";
material_data += "\t\"$flat\" \"1\"\n";
material_data += "\t\"$rimlightboost\" \"" + std::to_string(rimlight_boost) + "\"\n";
material_data += "\t\"$rimlightexponent\" \"" + std::to_string(4) + "\"\n";
material_data += "\t\"$ambientreflectionboost\" \"0.2\"\n";
material_data += "\t\"$envmaplightscale\" \"" + std::to_string(0.1) + "\"\n";
material_data += "\t\"$wireframe\" \"" + std::to_string(wireframe) + "\"\n";
material_data += "\t\"$ignorez\" \"" + std::to_string(ignorez) + "\"\n";
material_data += "}\n";
auto init_key_values = [](KeyValues *keyvalues, const char *key_name) -> void {
using InitKeyValues_t = void(__thiscall *)(void *, const char *);
static InitKeyValues_t InitKeyValuesEx = nullptr;
static auto pThis = *reinterpret_cast<DWORD**>(Utils::FindSignature2("client_panorama.dll", "B9 ? ? ? ? E8 ? ? ? ? 8B 5D 08") + 1);
if (!InitKeyValuesEx)
InitKeyValuesEx = *reinterpret_cast<InitKeyValues_t>(Utils::FindSignature2("client_panorama.dll", "55 8B EC 51 33 C0 C7 45"));
InitKeyValuesEx(keyvalues, key_name);
};
auto load_from_buffer = [](KeyValues *key_values, const char *resource_name, const char *buf, void *file_sys = nullptr, const char *path_id = nullptr, void *eval_sym_proc = nullptr, void *unk = nullptr) -> void {
using LoadFromBuffer_t = void(__thiscall *)(void *, const char *, const char *, void *, const char *, void *, void *);
static LoadFromBuffer_t LoadFromBufferEx = nullptr;
if (!LoadFromBufferEx)
LoadFromBufferEx = *reinterpret_cast<LoadFromBuffer_t>(Utils::FindSignature2("client_panorama.dll", "55 8B EC 83 E4 F8 83 EC 34 53 8B 5D 0C 89"));
LoadFromBufferEx(key_values, resource_name, buf, file_sys, path_id, eval_sym_proc, unk);
};
auto *key_values = new KeyValues();
init_key_values(key_values, material_type.c_str());
load_from_buffer(key_values, material_name.c_str(), material_data.c_str());
return Interfaces::MaterialSystem->CreateMaterial(material_name.c_str(), key_values);
}
float color_vis[4] = { 1.f, 0.f, 0.f, 1.f };
float color_invis[4] = { 0.f, 0.f, 0.f, 1.f };
void CChams::SceneEnd()
{
if (!Vars.chams_player_enabled)
return;
for (int i = 1; i < Interfaces::GlobalVars->maxClients; ++i)
{
auto ent = static_cast<C_BasePlayer*>(Interfaces::EntityList->GetClientEntity(i));
if (ent && ent->IsAlive() && !(ent->IsTeammate() && Vars.chams_player_ignore_team) && !ent->IsDormant()/*&& SmokeCheck(ent)*/)
{
if (ent->IsTeammate()) {
color_vis[0] = Vars.color_chams_team_visible[0];
color_vis[1] = Vars.color_chams_team_visible[1];
color_vis[2] = Vars.color_chams_team_visible[2];
color_vis[3] = Vars.color_chams_team_visible[3];
}
else {
color_vis[0] = Vars.color_chams_enemy_visible[0];
color_vis[1] = Vars.color_chams_enemy_visible[1];
color_vis[2] = Vars.color_chams_enemy_visible[2];
color_vis[3] = Vars.color_chams_enemy_visible[3];
}
if (ent->IsTeammate()) {
color_invis[0] = Vars.color_chams_team_hidden[0];
color_invis[1] = Vars.color_chams_team_hidden[1];
color_invis[2] = Vars.color_chams_team_hidden[2];
color_invis[3] = Vars.color_chams_team_hidden[3];
}
else {
color_invis[0] = Vars.color_chams_enemy_hidden[0];
color_invis[1] = Vars.color_chams_enemy_hidden[1];
color_invis[2] = Vars.color_chams_enemy_hidden[2];
color_invis[3] = Vars.color_chams_enemy_hidden[3];
}
static std::vector< IMaterial * > materials;
static bool once{ false };
if (!once) {
materials.push_back(create_material(true, false, false)); // material.
materials.push_back(create_material(false, false, false, 0)); // flat.
materials.push_back(create_material(true, false, true)); // material zignore.
materials.push_back(create_material(false, false, true)); // flat zignore.
once = true;
}
if (materials.at(0))
{
if (Vars.chams_player_visible_only)
{
Interfaces::RenderView->SetColorModulation(color_vis);
Interfaces::ModelRender->ForcedMaterialOverride(materials.at(0));
ent->DrawModel(0x1, 255);
Interfaces::ModelRender->ForcedMaterialOverride(nullptr);
}
else
{
Interfaces::RenderView->SetColorModulation(color_invis);
materials.at(0)->IncrementReferenceCount();
materials.at(0)->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, true);
Interfaces::ModelRender->ForcedMaterialOverride(materials.at(0));
ent->DrawModel(0x1, 255);
Interfaces::ModelRender->ForcedMaterialOverride(nullptr);
Interfaces::RenderView->SetColorModulation(color_vis);
materials.at(0)->IncrementReferenceCount();
materials.at(0)->SetMaterialVarFlag(MATERIAL_VAR_IGNOREZ, false);
Interfaces::ModelRender->ForcedMaterialOverride(materials.at(0));
ent->DrawModel(0x1, 255);
Interfaces::ModelRender->ForcedMaterialOverride(nullptr);
}
}
}
}
}