Hello im making a CS2 internal cheat and ive just made chams but im wondering if someone knows how to color the players differently if they are visible or not, i already have XQZ:
and my XQZ and vis mat:
C++:
#include "hk_genprim.h"
#include "../config.h"
#include "../features/visuals/chams/chams.h"
#include "../sdk/entity.h"
#include "../sdk/globals.h"
#include "../sdk/offsets/client_dll.h"
#include "../utils/log.h"
#include "../utils/memory.h"
#include "../utils/pattern.h"
#include <MinHook.h>
#include <Windows.h>
namespace hooks
{
struct MeshData
{
void* data;
uint8_t pad_08[0x10];
void* scene_animatable;
void* material;
void* material2;
uint8_t pad_30[0x10];
void* some_ptr;
uint8_t pad_48[0x08];
uint32_t color;
uint8_t pad_54[0x1C];
};
static_assert(sizeof(MeshData) == 0x70, "stride is wrong update it");
struct OutputBuffer
{
MeshData* meshes;
int max_primitives;
int start_primitive;
};
struct SceneObject
{
uint8_t pad_00[0x78];
uint32_t flags; // bit 3 pvs
uint8_t pad_7C[0x44];
uint32_t owner_handle;
};
using GeneratePrimitivesFn = void(__fastcall*)(void*, void*, void*, void*);
static GeneratePrimitivesFn original = nullptr;
static uint32_t pack_rgba(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
return (uint32_t)r | ((uint32_t)g << 8) | ((uint32_t)b << 16) | ((uint32_t)a << 24);
}
static void apply_material(MeshData& mesh, void* material, uint32_t color)
{
mesh.material = material;
mesh.material2 = material;
mesh.color = color;
}
static void override_range(MeshData* meshes, int from, int to, void* mat, uint32_t color)
{
for (int i = from; i < to; ++i)
{
__try
{
apply_material(meshes[i], mat, color);
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
}
}
static uintptr_t resolve_player(void* scene_object)
{
if (!scene_object || (uintptr_t)scene_object < 0x10000)
return 0;
__try
{
uint32_t handle = ((SceneObject*)scene_object)->owner_handle;
int index = handle & 0x7FFF;
if (index <= 0 || index > 2048)
return 0;
uintptr_t entity = entity::by_index(index);
if (!mem::valid_ptr(entity))
return 0;
for (int step = 0; step < 4 && mem::valid_ptr(entity); ++step)
{
int health = entity::health(entity);
if (health > 0 && health <= 200)
return entity;
uint32_t owner_handle = mem::read<uint32_t>(entity + cs2_dumper::schemas::client_dll::C_BaseEntity::m_hOwnerEntity);
uintptr_t next = entity::by_handle(owner_handle);
if (!mem::valid_ptr(next) || next == entity)
break;
entity = next;
}
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
return 0;
}
static void __fastcall on_generate_primitives(void* desc, void* scene, void* a3, void* buf)
{
if (!cfg::chams_enabled || !scene || (uintptr_t)scene < 0x10000 || !buf)
{
if (original)
original(desc, scene, a3, buf);
return;
}
auto* output = (OutputBuffer*)buf;
int prev_count = output->start_primitive;
original(desc, scene, a3, buf);
uintptr_t entity = resolve_player(scene);
if (!entity)
return;
uintptr_t local = entity::local_pawn();
if (!mem::valid_ptr(local) || entity::health(local) <= 0)
local = globals::local_pawn_global();
int team = (int)entity::team_num(entity);
if (team != 2 && team != 3)
return;
int my_team = mem::valid_ptr(local) ? (int)entity::team_num(local) : 0;
bool enemy = (team != my_team);
if (enemy && !cfg::chams_enemy)
return;
if (!enemy && !cfg::chams_team)
return;
// colour
ImVec4 col = enemy ? cfg::chams_color_enemy : cfg::chams_color_team;
uint32_t pk = pack_rgba((uint8_t)(col.x * 255.f), (uint8_t)(col.y * 255.f), (uint8_t)(col.z * 255.f), (uint8_t)(col.w * 255.f));
void* mat_visible = chams::get_mat_visible();
void* mat_invisible = chams::get_mat_invisible();
// disable the pvs
__try
{
((SceneObject*)scene)->flags &= ~(1u << 3);
}
__except (EXCEPTION_EXECUTE_HANDLER) {}
if (cfg::chams_xqz && mat_invisible && mat_visible)
{
override_range(output->meshes, prev_count, output->start_primitive, mat_invisible, pk);
int prev_vis = output->start_primitive;
original(desc, scene, a3, buf);
// visible pass on top
override_range(output->meshes, prev_vis, output->start_primitive, mat_visible, pk);
}
else if (mat_visible)
{
override_range(output->meshes, prev_count, output->start_primitive, mat_visible, pk);
}
}
bool init_genprim_hook()
{
HMODULE scenesystem = GetModuleHandleA("scenesystem.dll");
if (!scenesystem)
{
LOG_FAIL("genprim", "scenesystem.dll not found");
return false;
}
uintptr_t address = pattern::scan(scenesystem,
"48 8B C4 48 89 58 ? 48 89 50 ? 55 56 57 "
"41 54 41 55 41 56 41 57 48 8D A8 ? ? ? ? "
"48 81 EC ? ? ? ? 0F 29 70 ? 45 33 F6");
if (!address)
{
LOG_FAIL("genprim", "signature not found");
return false;
}
if (MH_CreateHook((void*)address, &on_generate_primitives, (void**)&original) != MH_OK)
{
LOG_FAIL("genprim", "MH_CreateHook failed");
return false;
}
if (MH_EnableHook((void*)address) != MH_OK)
{
LOG_FAIL("genprim", "MH_EnableHook failed");
return false;
}
LOG_OK("genprim", "installed");
return true;
}
void shutdown_genprim_hook()
{
}
}
and my XQZ and vis mat:
XQZ material:
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
Shader = "csgo_unlitgeneric.vfx"
F_IGNOREZ = 1
F_DISABLE_Z_WRITE = 1
F_DISABLE_Z_BUFFERING = 1
F_TRANSLUCENT = 1
F_RENDER_BACKFACES = 1
g_vColorTint = [1.0, 1.0, 1.0, 1.0]
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
}
VIS mat:
<!-- kv3 encoding:text:version{e21c7f3c-8a33-41c5-9977-a76d3a32aa0d} format:generic:version{7412167c-06e9-4698-aff2-e63eb59037e7} -->
{
Shader = "csgo_unlitgeneric.vfx"
F_IGNOREZ = 0
F_DISABLE_Z_WRITE = 0
F_DISABLE_Z_BUFFERING = 0
F_TRANSLUCENT = 1
F_RENDER_BACKFACES = 1
g_vColorTint = [1.0, 1.0, 1.0, 1.0]
g_tColor = resource:"materials/dev/primary_white_color_tga_f7b257f6.vtex"
g_tNormal = resource:"materials/default/default_normal_tga_7652cb.vtex"
}