weather.cpp:
#include "../include_cheat.h"
enum PrecipitationType_t
{
PRECIPITATION_TYPE_RAIN = 0,
PRECIPITATION_TYPE_SNOW,
PRECIPITATION_TYPE_ASH,
PRECIPITATION_TYPE_SNOWFALL,
};
class C_Precipitation : public C_BaseEntity
{
public:
NETVAR( get_mins, Vector, CBaseEntity_m_vecMins )
NETVAR( get_maxs, Vector, CBaseEntity_m_vecMaxs )
NETVAR( get_precip_type, int, CPrecipitation_m_nPrecipType )
};
static C_Precipitation* m_ent = {};
static C_Precipitation* create( const int type )
{
auto clazz = interfaces::client()->GetAllClasses();
while ( clazz && clazz->m_ClassID != ClassId::CPrecipitation )
clazz = clazz->m_pNext;
if ( !clazz || !clazz->m_pCreateFn )
return nullptr;
constexpr auto max_edicts = 8192;
if ( !clazz->m_pCreateFn( max_edicts - 1, 0 ) )
return nullptr;
const auto ent = reinterpret_cast< C_Precipitation* >( interfaces::entity_list()->get_client_entity( max_edicts - 1 ) );
if ( !ent )
return nullptr;
ent->get_precip_type() = type;
ent->PreDataUpdate( DATA_UPDATE_CREATED );
ent->OnPreDataChanged( DATA_UPDATE_CREATED );
ent->get_mins() = Vector( -32767.f, -32767.f, -32767.f );
ent->get_maxs() = Vector( 32767.f, 32767.f, 32767.f );
if ( const auto collid = ent->GetCollideable() )
{
collid->OBBMins() = Vector( -32767.f, -32767.f, -32767.f );
collid->OBBMaxs() = Vector( 32767.f, 32767.f, 32767.f );
}
ent->OnDataChanged( DATA_UPDATE_CREATED );
ent->PostDataUpdate( DATA_UPDATE_CREATED );
return ent;
}
void weather::run( const ClientFrameStage_t stage )
{
if ( stage != FRAME_NET_UPDATE_POSTDATAUPDATE_START )
return;
const auto type = static_cast< int >( vars::visuals.weather->get<float>() );
if ( !interfaces::engine()->IsConnected() || !interfaces::engine()->IsInGame() || !local_player || !local_player->get_alive() || !type )
{
m_ent = nullptr;
return;
}
if ( !m_ent )
m_ent = create( type - 1 );
if ( m_ent )
m_ent->get_precip_type() = type - 1;
}
weather.h:
#pragma once
namespace weather
{
void run( const ClientFrameStage_t stage );
}