namespace index {
constexpr auto ListLeavesInBox = 6;
}
vfunc_hook bsp_query_hook;
bsp_query_hook.setup( g_EngineClient->GetBSPTreeQuery() );
bsp_query_hook.hook_index( index::ListLeavesInBox, hkListLeavesInBox );
struct RenderableInfo_t {
IClientRenderable* m_pRenderable;
void* m_pAlphaProperty;
int m_EnumCount;
int m_nRenderFrame;
unsigned short m_FirstShadow;
unsigned short m_LeafList;
short m_Area;
uint16_t m_Flags; // 0x0016
uint16_t m_Flags2; // 0x0018
Vector m_vecBloatedAbsMins;
Vector m_vecBloatedAbsMaxs;
Vector m_vecAbsMins;
Vector m_vecAbsMaxs;
int pad;
};
#define MAX_COORD_FLOAT ( 16384.0f )
#define MIN_COORD_FLOAT ( -MAX_COORD_FLOAT )
int __fastcall hkListLeavesInBox( void* bsp, void* edx, Vector& mins, Vector& maxs, unsigned short* pList, int listMax ) {
typedef int( __thiscall * ListLeavesInBox )( void*, const Vector&, const Vector&, unsigned short*, int );
static auto ofunc = bsp_query_hook.get_original< ListLeavesInBox >( index::ListLeavesInBox );
// occulusion getting updated on player movement/angle change,
// in RecomputeRenderableLeaves (https://github.com/pmrowla/hl2sdk-csgo/blob/master/game/client/clientleafsystem.cpp#L674 );
// check for return in CClientLeafSystem::InsertIntoTree
if ( !g_Options.chams.active || !g_Options.chams.player_enabled || !g_Options.chams.disable_occulusion || *(uint32_t*)_ReturnAddress() != 0x14244489 ) // 89 44 24 14 ( 0x14244489 ) - new / 8B 7D 08 8B ( 0x8B087D8B ) - old
return ofunc( bsp, mins, maxs, pList, listMax );
// get current renderable info from stack ( https://github.com/pmrowla/hl2sdk-csgo/blob/master/game/client/clientleafsystem.cpp#L1470 )
auto info = *(RenderableInfo_t**)( (uintptr_t)_AddressOfReturnAddress() + 0x14 );
if ( !info || !info->m_pRenderable )
return ofunc( bsp, mins, maxs, pList, listMax );
// check if disabling occulusion for players ( https://github.com/pmrowla/hl2sdk-csgo/blob/master/game/client/clientleafsystem.cpp#L1491 )
auto base_entity = info->m_pRenderable->GetIClientUnknown()->GetBaseEntity();
if ( !base_entity || !base_entity->IsPlayer() )
return ofunc( bsp, mins, maxs, pList, listMax );
// fix render order, force translucent group ( https://www.unknowncheats.me/forum/2429206-post15.html )
// AddRenderablesToRenderLists: https://i.imgur.com/hcg0NB5.png (https://github.com/pmrowla/hl2sdk-csgo/blob/master/game/client/clientleafsystem.cpp#L2473)
info->m_Flags &= ~0x100;
info->m_Flags2 |= 0xC0;
// extend world space bounds to maximum ( https://github.com/pmrowla/hl2sdk-csgo/blob/master/game/client/clientleafsystem.cpp#L707 )
static const Vector map_min = Vector( MIN_COORD_FLOAT, MIN_COORD_FLOAT, MIN_COORD_FLOAT );
static const Vector map_max = Vector( MAX_COORD_FLOAT, MAX_COORD_FLOAT, MAX_COORD_FLOAT );
auto count = ofunc( bsp, map_min, map_max, pList, listMax );
return count;
}