Initial commit
This commit is contained in:
@@ -0,0 +1,434 @@
|
||||
#include <include.h>
|
||||
|
||||
bool respawn::initialize()
|
||||
{
|
||||
_ident_table.insert({ _XC(0x726579616c70), entity_types::PLAYER });
|
||||
_ident_table.insert({ _XC(0x6d6d75645f63706e), entity_types::DUMMIE });
|
||||
_ident_table.insert({ _XC(0x776f72705f63706e), entity_types::PROWLER });
|
||||
_ident_table.insert({ _XC(0x7275735f706f7270), entity_types::PROP_SURVIVAL });
|
||||
_ident_table.insert({ _XC(0x6e79645f706f7270), entity_types::PROP_DYNAMIC });
|
||||
_ident_table.insert({ _XC(0x7263735f706f7270), entity_types::PROP_SCRIPT });
|
||||
_ident_table.insert({ _XC(0x6165645f706f7270), entity_types::PROP_DEATH_BOX });
|
||||
|
||||
_heirloom_table.insert(_XS("mdl/weapons/kunai/ptpov_kunai_wraith.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/bloodhound_axe/ptpov_bloodhound_axe.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/drumstick/ptpov_baton_lifeline.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/pathfinder_gloves/ptpov_pathfinder_gloves.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/octane_knife/ptpov_octane_knife.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/mirage_heirloom/ptpov_mirage_heirloom.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/caustic_heirloom/ptpov_caustic_heirloom.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/gibraltar_heirloom/gibraltar_heirloom_v.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/bangalore_heirloom/ptpov_bangalore_heirloom.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/revenant_heirloom/revenant_heirloom_v21_base_v.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/rampart_heirloom/ptpov_rampart_heirloom.rmdl"));
|
||||
_heirloom_table.insert(_XS("mdl/weapons/wattson_heirloom/wattson_heirloom_v21_base_v.rmdl"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
respawn::c_player* respawn::get_local_player()
|
||||
{
|
||||
if (!ix::engine_client->is_in_game())
|
||||
return nullptr;
|
||||
|
||||
const auto index = ix::engine_client->get_local_player();
|
||||
const auto result = ix::entity_list->get_client_entity<respawn::c_player>(index);
|
||||
|
||||
if (result == nullptr || !respawn::is_player(result))
|
||||
return nullptr;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
respawn::color_t respawn::get_player_color(respawn::c_player* player)
|
||||
{
|
||||
const auto& local_player = g::p::cache.local_player;
|
||||
|
||||
if (player == nullptr || player->life_state() != 0)
|
||||
return colors::white;
|
||||
|
||||
//
|
||||
// dummy
|
||||
// skip do bleed out checks and such.
|
||||
//
|
||||
if (respawn::is_dummy(player))
|
||||
return colors::yellow;
|
||||
|
||||
//
|
||||
// bleeding out
|
||||
//
|
||||
if (player->bleed_out_state() != 0)
|
||||
return colors::red;
|
||||
|
||||
//
|
||||
// team mate
|
||||
//
|
||||
if (is_teammate(player))
|
||||
return colors::cyan;
|
||||
|
||||
//
|
||||
// opponent
|
||||
//
|
||||
return colors::yellow;
|
||||
}
|
||||
|
||||
void* get_create_interface()
|
||||
{
|
||||
using fn = void* (__fastcall)();
|
||||
|
||||
const auto fn_address = dyn_addr::get_dynamic_address(_XS("fn_create_interface"));
|
||||
auto* const fn_ptr = mem::addr(fn_address).As<fn*>();
|
||||
|
||||
return fn_ptr();
|
||||
}
|
||||
|
||||
void* respawn::create_interface(const char* name)
|
||||
{
|
||||
auto* const fn_ptr = mem::addr(get_create_interface()).As<create_interface_fn>();
|
||||
|
||||
if (fn_ptr == nullptr)
|
||||
return nullptr;
|
||||
|
||||
return fn_ptr(name, 0);
|
||||
}
|
||||
|
||||
int respawn::get_sequence_count(void* model)
|
||||
{
|
||||
auto v6 = *(uint64_t*)(BASE_OF(model) + 16);
|
||||
|
||||
int numseq = v6 ? *(uint32_t*)(v6 + 32) : *(uint32_t*)(*(uint64_t*)(BASE_OF(model) + 8) + 192i64);
|
||||
|
||||
return numseq;
|
||||
}
|
||||
|
||||
respawn::mstudioseqdesc_t* respawn::seq_desc(void* model, int sequence)
|
||||
{
|
||||
using fn = mstudioseqdesc_t* (__fastcall*)(void*, int);
|
||||
|
||||
const auto fn_address = dyn_addr::get_dynamic_address(_XS("fn_seq_desc"));
|
||||
auto* const fn_ptr = mem::addr(fn_address).As<fn>();
|
||||
|
||||
return fn_ptr(model, sequence);
|
||||
}
|
||||
|
||||
respawn::entity_types respawn::get_entity_type(c_entity* entity)
|
||||
{
|
||||
auto identifier = entity->identifier();
|
||||
|
||||
if (!identifier)
|
||||
return entity_types::NONE;
|
||||
|
||||
auto hash = *(uint64_t*)( identifier );
|
||||
auto result = respawn::entity_types{};
|
||||
|
||||
for (auto i = 0ull; i < _ident_table.count(); i++)
|
||||
{
|
||||
auto* const entry = _ident_table[i];
|
||||
|
||||
if (entry == nullptr)
|
||||
continue;
|
||||
|
||||
if (hash == _XC(entry->first))
|
||||
return entry->second;
|
||||
}
|
||||
|
||||
return entity_types::UNKNOWN;
|
||||
}
|
||||
|
||||
uint64_t respawn::get_entity_identifier(c_entity* entity)
|
||||
{
|
||||
auto identifier = entity->identifier();
|
||||
|
||||
if (!identifier)
|
||||
return 0;
|
||||
|
||||
auto hash = *(uint64_t*)(identifier);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool respawn::is_player(respawn::c_entity* entity, bool player, bool dummy)
|
||||
{
|
||||
auto type = get_entity_type(entity);
|
||||
|
||||
if ((player && type == entity_types::PLAYER) ||
|
||||
(dummy && type == entity_types::DUMMIE)
|
||||
)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool respawn::is_survival_prop(respawn::c_entity* entity)
|
||||
{
|
||||
return get_entity_type(entity) == entity_types::PROP_SURVIVAL;
|
||||
}
|
||||
|
||||
bool respawn::is_of_type(respawn::c_entity* entity, const char* name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool respawn::is_alive(respawn::c_player* player)
|
||||
{
|
||||
return (player->life_state() == LIFE_ALIVE);
|
||||
}
|
||||
|
||||
bool respawn::is_knocked(respawn::c_player* player)
|
||||
{
|
||||
return (player->bleed_out_state() != NULL);
|
||||
}
|
||||
|
||||
respawn::game_modes respawn::get_game_mode()
|
||||
{
|
||||
const auto address = DYN_ADDR("ptr_game_instance_data");
|
||||
|
||||
if (address)
|
||||
{
|
||||
auto base = *(uintptr_t*)address;
|
||||
|
||||
if (base)
|
||||
{
|
||||
auto name = *(const char**)(base + 0x58);
|
||||
auto length = stl::strlen(name);
|
||||
|
||||
if (length)
|
||||
{
|
||||
auto hash = crc_calculate32(name, length);
|
||||
|
||||
switch (hash)
|
||||
{
|
||||
case 0xe765d4cd: return game_modes::survival;
|
||||
case 0xeddb2c4b: return game_modes::control;
|
||||
case 0x0a235588: return game_modes::arenas;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return game_modes::invalid;
|
||||
}
|
||||
|
||||
void respawn::start_drawing(respawn::c_mat_system_surface* mssf)
|
||||
{
|
||||
if (mssf == nullptr)
|
||||
return;
|
||||
|
||||
using fn = void(__fastcall*)(void*);
|
||||
|
||||
const auto address = dyn_addr::get_dynamic_address(_XS("paint_start_drawing"));
|
||||
const auto function = reinterpret_cast<fn>(address);
|
||||
|
||||
if (!address || !function)
|
||||
return;
|
||||
|
||||
return function(mssf);
|
||||
}
|
||||
|
||||
void respawn::finish_drawing()
|
||||
{
|
||||
using fn = void(__fastcall*)();
|
||||
|
||||
const auto address = dyn_addr::get_dynamic_address(_XS("paint_finish_drawing"));
|
||||
const auto function = reinterpret_cast<fn>(address);
|
||||
|
||||
if (!address || !function)
|
||||
return;
|
||||
|
||||
return function();
|
||||
}
|
||||
|
||||
bool respawn::world_to_screen(math::Vector3& vIn, math::Vector3& vOut)
|
||||
{
|
||||
auto pvMatrix = ix::view_render->get_view_matrix();
|
||||
|
||||
if (pvMatrix == nullptr)
|
||||
return false;
|
||||
|
||||
auto vMatrix = *pvMatrix;
|
||||
|
||||
vOut.x = vMatrix.m[0][0] * vIn.x + vMatrix.m[0][1] * vIn.y + vMatrix.m[0][2] * vIn.z + vMatrix.m[0][3];
|
||||
vOut.y = vMatrix.m[1][0] * vIn.x + vMatrix.m[1][1] * vIn.y + vMatrix.m[1][2] * vIn.z + vMatrix.m[1][3];
|
||||
|
||||
float w = vMatrix.m[3][0] * vIn.x + vMatrix.m[3][1] * vIn.y + vMatrix.m[3][2] * vIn.z + vMatrix.m[3][3];
|
||||
|
||||
if (w < 0.01)
|
||||
return false;
|
||||
|
||||
float invw = 1.0f / w;
|
||||
|
||||
vOut.x *= invw;
|
||||
vOut.y *= invw;
|
||||
|
||||
const auto Cl_width = g::p::screen.w;
|
||||
const auto Cl_height = g::p::screen.h;
|
||||
|
||||
auto x = static_cast<float>(Cl_width) / 2.f;
|
||||
auto y = static_cast<float>(Cl_height) / 2.f;
|
||||
|
||||
x += 0.5f * vOut.x * Cl_width + 0.5f;
|
||||
y -= 0.5f * vOut.y * Cl_height + 0.5f;
|
||||
|
||||
vOut.x = x;
|
||||
vOut.y = y;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void respawn::on_update_cache(respawn::c_player* me, respawn::c_weapon* my_wpn, respawn::c_net_chan* nc)
|
||||
{
|
||||
auto& cache = g::p::cache;
|
||||
|
||||
auto& local_player_data = cache.local_player;
|
||||
auto& local_weapon_data = cache.local_weapon;
|
||||
|
||||
auto& net_chan_data = cache.net_chan;
|
||||
|
||||
local_player_data.index = ix::engine_client->get_local_player();
|
||||
local_player_data.address = mem::addr(me).Base();
|
||||
local_player_data.team_number = me->team_number();
|
||||
local_player_data.origin = me->origin();
|
||||
local_player_data.eye_angle = me->eye_angles();
|
||||
local_player_data.zooming = me->is_zooming();
|
||||
local_player_data.shoot_pos = me->view_offset();
|
||||
|
||||
if ( !(my_wpn == nullptr) )
|
||||
{
|
||||
local_weapon_data.address = mem::addr(my_wpn).Base();
|
||||
local_weapon_data.reloading = my_wpn->is_reloading();
|
||||
local_weapon_data.next_primary_attack = my_wpn->next_primary_attack();
|
||||
local_weapon_data.next_ready_time = my_wpn->next_ready_time();
|
||||
local_weapon_data.can_fire = my_wpn->can_fire(me);
|
||||
}
|
||||
|
||||
net_chan_data.out_sequence_nr = nc->out_sequence_nr();
|
||||
net_chan_data.num_choked_packets = nc->num_choked_packets();
|
||||
}
|
||||
|
||||
bool respawn::is_teammate(c_player* player)
|
||||
{
|
||||
if (player == nullptr)
|
||||
return false;
|
||||
|
||||
const auto& lp_data = g::p::cache.local_player;
|
||||
const auto is_control = (g::p::game_mode == game_modes::control);
|
||||
|
||||
if (is_control)
|
||||
{
|
||||
auto convert_team = [](int num)
|
||||
{
|
||||
return ( (num % 2) ? 1: 2 );
|
||||
};
|
||||
|
||||
return (convert_team(player->team_number()) == convert_team(lp_data.team_number));
|
||||
}
|
||||
|
||||
return (player->team_number() == lp_data.team_number);
|
||||
}
|
||||
|
||||
bool respawn::get_entity_center_pos(respawn::c_entity* entity, math::Vector3& result)
|
||||
{
|
||||
if (entity == nullptr)
|
||||
return false;
|
||||
|
||||
auto collision = entity->collision();
|
||||
|
||||
if (collision == nullptr)
|
||||
return false;
|
||||
|
||||
auto mins = collision->vec_mins();
|
||||
auto maxs = collision->vec_maxs();
|
||||
|
||||
result = entity->origin();
|
||||
result.z += (mins.z + maxs.z) * 0.5f;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void respawn::script::dump_to_disk(const char* name, char* buffer, size_t length)
|
||||
{
|
||||
if (!name || !buffer || !length)
|
||||
{
|
||||
log_info_("invalid params!");
|
||||
return;
|
||||
}
|
||||
|
||||
char path_fmt[MAX_PATH];
|
||||
char path_base[MAX_PATH];
|
||||
|
||||
memset(path_fmt, 0, sizeof(path_fmt));
|
||||
memset(path_base, 0, sizeof(path_base));
|
||||
|
||||
if (!util::get_desktop_directory(path_base, sizeof(path_base)))
|
||||
{
|
||||
log_info_("failed to get desktop directory.");
|
||||
return;
|
||||
}
|
||||
|
||||
util::format_string(path_fmt, sizeof(path_fmt), _XS("%s\\RSPN\\%s"), path_base, stl::basename(name));
|
||||
|
||||
if (util::file_exists(path_fmt))
|
||||
{
|
||||
log_info_("!! skipping existing script file.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (util::write_data_reg(buffer, length, path_fmt))
|
||||
{
|
||||
log_info_("!! dumped file to disk.");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_info_("!! failed to dump file.");
|
||||
}
|
||||
}
|
||||
|
||||
void respawn::script::override_from_disk(const char* name, char* buffer, size_t* length)
|
||||
{
|
||||
char override_file_path[MAX_PATH];
|
||||
char path_base[MAX_PATH];
|
||||
|
||||
wchar_t override_file_path_wide[MAX_PATH];
|
||||
|
||||
memset(override_file_path, 0, sizeof(override_file_path));
|
||||
memset(override_file_path_wide, 0, sizeof(override_file_path_wide));
|
||||
memset(path_base, 0, sizeof(path_base));
|
||||
|
||||
if (!util::get_desktop_directory(path_base, sizeof(path_base)))
|
||||
{
|
||||
log_info_("failed to get desktop directory.");
|
||||
return;
|
||||
}
|
||||
|
||||
util::format_string(override_file_path, sizeof(override_file_path), _XS("\\??\\%s\\RSPN\\%s"), path_base, stl::basename(name));
|
||||
stl::mbstowcs(override_file_path_wide, override_file_path, 0, sizeof(override_file_path_wide));
|
||||
|
||||
if (!util::file_exists(override_file_path))
|
||||
{
|
||||
dump_to_disk(name, buffer, *length);
|
||||
return;
|
||||
}
|
||||
|
||||
auto override_file_length = util::get_file_size(override_file_path);
|
||||
|
||||
if (override_file_length <= 0)
|
||||
return;
|
||||
|
||||
auto override_file_buffer = stl::mem_alloc<char*>( static_cast<size_t>(override_file_length) + 1);
|
||||
|
||||
if (!override_file_buffer)
|
||||
return;
|
||||
|
||||
memset(override_file_buffer, 0, static_cast<size_t>(override_file_length) + 1);
|
||||
|
||||
if (util::read_file_ex(override_file_path_wide, override_file_buffer, override_file_length))
|
||||
{
|
||||
*length = override_file_length;
|
||||
|
||||
memcpy(buffer, override_file_buffer, static_cast<size_t>(override_file_length) + 1);
|
||||
|
||||
//log_info("!! overridden the script file '%s'.", stl::basename(name));
|
||||
}
|
||||
|
||||
stl::mem_free(override_file_buffer);
|
||||
}
|
||||
Reference in New Issue
Block a user