187 lines
2.8 KiB
C++
187 lines
2.8 KiB
C++
#pragma once
|
|
|
|
namespace cache
|
|
{
|
|
enum class types
|
|
{
|
|
none = 0,
|
|
|
|
player,
|
|
dummie,
|
|
|
|
npc,
|
|
|
|
loot,
|
|
dynamic_prop,
|
|
script_prop,
|
|
};
|
|
|
|
enum class prop_dynamic_types
|
|
{
|
|
none = 0,
|
|
|
|
shooting_range_target,
|
|
|
|
trap_gas,
|
|
trap_fence,
|
|
};
|
|
|
|
struct entity_t
|
|
{
|
|
bool m_valid;
|
|
uint64_t m_identifier;
|
|
math::Vector3 m_origin;
|
|
math::Vector3 m_center;
|
|
};
|
|
|
|
struct player_t : entity_t
|
|
{
|
|
int m_life_state;
|
|
int m_bleedout_state;
|
|
int m_team_number;
|
|
int m_health;
|
|
int m_health_max;
|
|
int m_armor;
|
|
int m_armor_max;
|
|
|
|
bool m_visible;
|
|
bool m_teammate;
|
|
|
|
respawn::color_t m_color;
|
|
|
|
math::Vector3 m_origin;
|
|
math::Vector3 m_velocity;
|
|
math::Vector3 m_bones[20];
|
|
|
|
char m_name[32];
|
|
|
|
bool is_alive() noexcept { return (m_life_state == LIFE_ALIVE); }
|
|
};
|
|
|
|
struct npc_t : entity_t
|
|
{
|
|
uint8_t m_life_state;
|
|
|
|
int m_health;
|
|
int m_health_max;
|
|
};
|
|
|
|
struct prop_dynamic_t : entity_t
|
|
{
|
|
prop_dynamic_types m_type;
|
|
};
|
|
|
|
struct loot_t : entity_t
|
|
{
|
|
int m_script_id;
|
|
};
|
|
|
|
struct entry_t
|
|
{
|
|
bool valid;
|
|
int index;
|
|
types type;
|
|
respawn::entity_types entity_type;
|
|
void* m_pointer;
|
|
|
|
char m_model_name[MAX_PATH];
|
|
|
|
struct
|
|
{
|
|
player_t plr;
|
|
npc_t npc;
|
|
loot_t loot;
|
|
prop_dynamic_t prop_dynamic;
|
|
} type_specific;
|
|
};
|
|
|
|
constexpr size_t capacity = 0x10000;
|
|
|
|
extern void process_player(int index, respawn::c_player* player, cache::entry_t& entry, cache::player_t& data);
|
|
extern void process_npc(int index, respawn::c_npc* npc, cache::entry_t& entry, cache::npc_t& data);
|
|
extern void process_loot(int index, respawn::c_prop_survival* entity, cache::loot_t& data);
|
|
extern void process_dynamic_prop(int index, respawn::c_entity* entity, cache::entry_t& entry, cache::prop_dynamic_t& data);
|
|
extern void process_base(int index, respawn::c_entity* entity, cache::entry_t& entry);
|
|
};
|
|
|
|
class c_entity_cache
|
|
{
|
|
public:
|
|
//
|
|
//
|
|
//
|
|
void initialize();
|
|
|
|
//
|
|
//
|
|
//
|
|
void on_createmove();
|
|
|
|
//
|
|
//
|
|
//
|
|
void collect_entities();
|
|
|
|
//
|
|
//
|
|
//
|
|
void on_update();
|
|
|
|
//
|
|
//
|
|
//
|
|
void reset();
|
|
|
|
//
|
|
//
|
|
//
|
|
const auto count() { return _entity_count; }
|
|
|
|
auto get_neutral(size_t index) -> cache::entry_t
|
|
{
|
|
if (index >= _entity_count || index >= cache::capacity)
|
|
return {};
|
|
|
|
auto info = _entities[index];
|
|
|
|
if (!info.valid)
|
|
return {};
|
|
|
|
return info;
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
auto get_player(size_t index) -> cache::player_t
|
|
{
|
|
if (index >= _entity_count || index >= cache::capacity)
|
|
return {};
|
|
|
|
auto info = _entities[index];
|
|
|
|
if (!info.valid)
|
|
return {};
|
|
|
|
if (info.type != cache::types::player &&
|
|
info.type != cache::types::dummie)
|
|
return {};
|
|
|
|
return info.type_specific.plr;
|
|
}
|
|
|
|
//
|
|
//
|
|
//
|
|
template < typename T >
|
|
T get_pointer(size_t index)
|
|
{
|
|
return (T)get_pointer_internal(index);
|
|
}
|
|
private:
|
|
void* get_pointer_internal(size_t index);
|
|
private:
|
|
size_t _entity_count;
|
|
cache::entry_t* _entities = nullptr;
|
|
};
|