Skip to content

Commit

Permalink
feat: dumper and new code style formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
stdNullPtr committed Dec 20, 2024
1 parent 8f9e70b commit 8f3a764
Show file tree
Hide file tree
Showing 37 changed files with 334 additions and 337 deletions.
14 changes: 7 additions & 7 deletions um-client/src/controller/Aim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace cheat::aim

inline std::optional<Vec2> find_valid_aim_target_in_circle(const Vec2& center, const float& radius, const std::vector<Vec2>& aim_targets)
{
const float radius_squared{radius * radius};
float min_distance_squared{std::numeric_limits<float>::max()};
std::optional<Vec2> aim_target{std::nullopt};
const float radius_squared{ radius * radius };
float min_distance_squared{ std::numeric_limits<float>::max() };
std::optional<Vec2> aim_target{ std::nullopt };

for (const auto& target : aim_targets)
{
const float dist_squared{center.distance_squared(target)};
const float dist_squared{ center.distance_squared(target) };

if (dist_squared <= radius_squared && dist_squared < min_distance_squared)
{
Expand All @@ -42,16 +42,16 @@ namespace cheat::aim

inline void aim_loop(const std::stop_token& stop_token, const std::optional<Vec2>& aim_target)
{
static const ImVec2 crosshair{g::screen_center};
static const ImVec2 crosshair{ g::screen_center };

while (!stop_token.stop_requested())
{
if (aim_target && g::toggles::aim_hack && !g::toggles::show_menu)
{
if (GetAsyncKeyState(VK_MBUTTON) & 0x8000 || (g::toggles::aim_assist && GetAsyncKeyState(VK_LBUTTON) & 0x8000))
{
const float delta_x{aim_target->x - crosshair.x};
const float delta_y{aim_target->y - crosshair.y};
const float delta_x{ aim_target->x - crosshair.x };
const float delta_y{ aim_target->y - crosshair.y };

move_mouse(delta_x, delta_y);
sleep_for(10us);
Expand Down
49 changes: 24 additions & 25 deletions um-client/src/controller/Cs2CheatController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace cheat
{
std::optional<DWORD> Cs2CheatController::get_cs2_process_id()
{
const auto process_id{commons::process::GetProcessIdByName(g::cs2_process_name)};
const auto process_id{ commons::process::GetProcessIdByName(g::cs2_process_name) };
if (!process_id.has_value())
{
std::wcerr << XORW(L"Failed to find pid of requested process.\n");
Expand All @@ -20,7 +20,7 @@ namespace cheat

std::optional<uintptr_t> Cs2CheatController::find_client_dll_base() const
{
const auto client_dll_base{commons::process::GetModuleBaseAddress(cs2_process_id_, g::client_dll_module_name)};
const auto client_dll_base{ commons::process::GetModuleBaseAddress(cs2_process_id_, g::client_dll_module_name) };
if (!client_dll_base.has_value())
{
std::wcerr << XORW(L"Failed GetModuleBaseAddress for Client DLL.\n");
Expand All @@ -36,7 +36,7 @@ namespace cheat

std::optional<uintptr_t> Cs2CheatController::find_engine_dll_base() const
{
const auto engine_dll_base{commons::process::GetModuleBaseAddress(cs2_process_id_, g::engine_dll_module_name)};
const auto engine_dll_base{ commons::process::GetModuleBaseAddress(cs2_process_id_, g::engine_dll_module_name) };
if (!engine_dll_base.has_value())
{
std::wcerr << XORW(L"Failed GetModuleBaseAddress for Engine DLL.\n");
Expand Down Expand Up @@ -88,7 +88,7 @@ namespace cheat

bool Cs2CheatController::init(const driver::Driver& driver)
{
auto result{true};
auto result{ true };

result &= (cs2_process_id_ = get_cs2_process_id().value_or(0)) != 0;
result &= (client_dll_base_ = find_client_dll_base().value_or(0)) != 0;
Expand All @@ -102,15 +102,15 @@ namespace cheat
bool Cs2CheatController::build_number_changed(const driver::Driver& driver) const
{
//TODO read the json info.json dont be an idiot
static constexpr DWORD expected_build{14055};
static constexpr DWORD expected_build{ 14055 };

return driver.read<DWORD>(engine_dll_base_ + cs2_dumper::offsets::engine2_dll::dwBuildNumber) != expected_build;
}

bool Cs2CheatController::is_in_game(const driver::Driver& driver) const
{
const auto is_background{driver.read<bool>(get_network_client(driver) + cs2_dumper::offsets::engine2_dll::dwNetworkGameClient_isBackgroundMap)};
const auto state{driver.read<int>(get_network_client(driver) + cs2_dumper::offsets::engine2_dll::dwNetworkGameClient_signOnState)};
const auto is_background{ driver.read<bool>(get_network_client(driver) + cs2_dumper::offsets::engine2_dll::dwNetworkGameClient_isBackgroundMap) };
const auto state{ driver.read<int>(get_network_client(driver) + cs2_dumper::offsets::engine2_dll::dwNetworkGameClient_signOnState) };
return !is_background && state >= 6;
}

Expand All @@ -121,24 +121,24 @@ namespace cheat

std::optional<entity::Entity> Cs2CheatController::get_entity_from_list(const driver::Driver& driver, const int& index) const
{
const auto controller{get_entity_controller(driver, index)};
const auto controller{ get_entity_controller(driver, index) };
if (!controller)
{
return std::nullopt;
}

const auto entity_pawn{get_entity_pawn(driver, *controller)};
const auto entity_pawn{ get_entity_pawn(driver, *controller) };
if (!entity_pawn)
{
return std::nullopt;
}

return entity::Entity{*controller, *entity_pawn};
return entity::Entity{ *controller, *entity_pawn };
}

entity::Entity Cs2CheatController::get_local_player(const driver::Driver& driver) const
{
return entity::Entity{find_local_player_controller(driver), find_local_player_pawn(driver)};
return entity::Entity{ find_local_player_controller(driver), find_local_player_pawn(driver) };
}

util::ViewMatrix Cs2CheatController::get_view_matrix(const driver::Driver& driver) const
Expand All @@ -148,40 +148,39 @@ namespace cheat

float Cs2CheatController::c4_blow_remaining_time(const driver::Driver& driver) const
{
const auto dw_game_rules{driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwGameRules)};
const auto bomb_planted{driver.read<bool>(dw_game_rules + cs2_dumper::schemas::client_dll::C_CSGameRules::m_bBombPlanted)};
const auto dw_game_rules{ driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwGameRules) };
const auto bomb_planted{ driver.read<bool>(dw_game_rules + cs2_dumper::schemas::client_dll::C_CSGameRules::m_bBombPlanted) };

if (!bomb_planted)
{
if (!bomb_planted){
return 0.0f;
}

const auto planted_c4{driver.read<uintptr_t>(driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwPlantedC4))};
const auto global_vars{driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwGlobalVars)};
const auto planted_c4{ driver.read<uintptr_t>(driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwPlantedC4)) };
const auto global_vars{ driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwGlobalVars) };

const auto c4_time{driver.read<float>(planted_c4 + cs2_dumper::schemas::client_dll::C_PlantedC4::m_flC4Blow)};
const auto global_time{driver.read<float>(global_vars + 0x34)};
const auto c4_time{ driver.read<float>(planted_c4 + cs2_dumper::schemas::client_dll::C_PlantedC4::m_flC4Blow) };
const auto global_time{ driver.read<float>(global_vars + 0x34) };

return c4_time - global_time;
}

bool Cs2CheatController::c4_is_bomb_site_a(const driver::Driver& driver) const
{
const auto planted_c4{driver.read<uintptr_t>(driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwPlantedC4))};
const auto bomb_site{driver.read<int>(planted_c4 + cs2_dumper::schemas::client_dll::C_PlantedC4::m_nBombSite)};
const auto planted_c4{ driver.read<uintptr_t>(driver.read<uintptr_t>(client_dll_base_ + cs2_dumper::offsets::client_dll::dwPlantedC4)) };
const auto bomb_site{ driver.read<int>(planted_c4 + cs2_dumper::schemas::client_dll::C_PlantedC4::m_nBombSite) };

return bomb_site == 0;
}

std::optional<uintptr_t> Cs2CheatController::get_entity_controller(const driver::Driver& driver, const int& i) const
{
const auto list_entity{driver.read<uintptr_t>(entity_system_ + ((8 * (i & 0x7FFF) >> 9) + 16))};
const auto list_entity{ driver.read<uintptr_t>(entity_system_ + ((8 * (i & 0x7FFF) >> 9) + 16)) };
if (!list_entity)
{
return std::nullopt;
}

const auto entity_controller{driver.read<uintptr_t>(list_entity + 0x78 * (i & 0x1FF))};
const auto entity_controller{ driver.read<uintptr_t>(list_entity + 0x78 * (i & 0x1FF)) };
if (!entity_controller)
{
return std::nullopt;
Expand All @@ -192,7 +191,7 @@ namespace cheat

std::optional<uintptr_t> Cs2CheatController::get_entity_pawn(const driver::Driver& driver, const uintptr_t& entity_controller) const
{
const auto entity_controller_pawn{driver.read<uintptr_t>(entity_controller + cs2_dumper::schemas::client_dll::CCSPlayerController::m_hPlayerPawn)};
const auto entity_controller_pawn{ driver.read<uintptr_t>(entity_controller + cs2_dumper::schemas::client_dll::CCSPlayerController::m_hPlayerPawn) };
if (!entity_controller_pawn)
{
return std::nullopt;
Expand All @@ -204,7 +203,7 @@ namespace cheat
return std::nullopt;
}

const auto entity_pawn{driver.read<uintptr_t>(list_entity + 0x78 * (entity_controller_pawn & 0x1FF))};
const auto entity_pawn{ driver.read<uintptr_t>(list_entity + 0x78 * (entity_controller_pawn & 0x1FF)) };
if (!entity_pawn)
{
std::wcerr << XORW(L"Cant grab player pawn, maybe the player disconnected?\n");
Expand Down
8 changes: 4 additions & 4 deletions um-client/src/controller/Cs2CheatController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ namespace cheat
class Cs2CheatController
{
private:
DWORD cs2_process_id_{0};
uintptr_t client_dll_base_{0};
uintptr_t engine_dll_base_{0};
uintptr_t entity_system_{0};
DWORD cs2_process_id_{ 0 };
uintptr_t client_dll_base_{ 0 };
uintptr_t engine_dll_base_{ 0 };
uintptr_t entity_system_{ 0 };

private:
[[nodiscard]] static std::optional<DWORD> get_cs2_process_id();
Expand Down
37 changes: 18 additions & 19 deletions um-client/src/controller/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ namespace cheat::entity
}

Entity::Entity(const uintptr_t& entity_controller, const uintptr_t& entity_pawn) : entity_controller_(entity_controller), entity_pawn_(entity_pawn)
{
}
{}

std::string Entity::get_name(const driver::Driver& driver) const
{
Expand All @@ -30,9 +29,9 @@ namespace cheat::entity
char buf[20];
};

const auto str{driver.read<str_wrap>(entity_name_address)};
const auto str{ driver.read<str_wrap>(entity_name_address) };

return {str.buf, str.buf + strnlen(str.buf, sizeof(str.buf))};
return { str.buf, str.buf + strnlen(str.buf, sizeof(str.buf)) };
}

std::string Entity::get_weapon_name(const driver::Driver& driver) const
Expand All @@ -42,12 +41,12 @@ namespace cheat::entity
char buf[20];
};

const auto weapon_base{driver.read<uintptr_t>(entity_pawn_ + client_dll::C_CSPlayerPawnBase::m_pClippingWeapon)};
const auto identity{driver.read<uintptr_t>(weapon_base + client_dll::CEntityInstance::m_pEntity)};
const auto designer_name{driver.read<uintptr_t>(identity + client_dll::CEntityIdentity::m_designerName)};
const auto str{driver.read<str_wrap>(designer_name)};
const auto weapon_base{ driver.read<uintptr_t>(entity_pawn_ + client_dll::C_CSPlayerPawnBase::m_pClippingWeapon) };
const auto identity{ driver.read<uintptr_t>(weapon_base + client_dll::CEntityInstance::m_pEntity) };
const auto designer_name{ driver.read<uintptr_t>(identity + client_dll::CEntityIdentity::m_designerName) };
const auto str{ driver.read<str_wrap>(designer_name) };

return {str.buf, str.buf + strnlen(str.buf, sizeof(str.buf))};
return { str.buf, str.buf + strnlen(str.buf, sizeof(str.buf)) };
}

int Entity::get_team(const driver::Driver& driver) const
Expand All @@ -62,8 +61,8 @@ namespace cheat::entity

bool Entity::is_spotted(const driver::Driver& driver) const
{
const auto p_entity_spotted_state{entity_pawn_ + client_dll::C_CSPlayerPawn::m_entitySpottedState};
const auto entity_spotted_address{p_entity_spotted_state + client_dll::EntitySpottedState_t::m_bSpotted};
const auto p_entity_spotted_state{ entity_pawn_ + client_dll::C_CSPlayerPawn::m_entitySpottedState };
const auto entity_spotted_address{ p_entity_spotted_state + client_dll::EntitySpottedState_t::m_bSpotted };
return driver.read<bool>(entity_spotted_address);
}

Expand Down Expand Up @@ -95,14 +94,14 @@ namespace cheat::entity
}

const auto p_entity_spotted_state{ entity_pawn_ + client_dll::C_CSPlayerPawn::m_entitySpottedState };
const auto entity_spotted_by_mask{ driver.read<uint64_t>(p_entity_spotted_state + client_dll::EntitySpottedState_t::m_bSpottedByMask )};
const auto entity_spotted_by_mask{ driver.read<uint64_t>(p_entity_spotted_state + client_dll::EntitySpottedState_t::m_bSpottedByMask) };

return entity_spotted_by_mask & (DWORD64(1) << (local_player_index));
}

util::Vec3 Entity::get_forward_vector(const driver::Driver& driver) const
{
const auto movement_services{get_movement_services(driver)};
const auto movement_services{ get_movement_services(driver) };
return driver.read<util::Vec3>(movement_services + client_dll::CCSPlayer_MovementServices::m_vecForward);
}

Expand All @@ -118,19 +117,19 @@ namespace cheat::entity

util::Vec3 Entity::get_head_bone_pos(const driver::Driver& driver) const
{
constexpr auto bone_head{6};
constexpr auto bone_head{ 6 };

const auto game_scene_node{get_game_scene_node(driver)};
const auto bone_array{driver.read<uintptr_t>(game_scene_node + client_dll::CPlayer_MovementServices_Humanoid::m_groundNormal)};
const auto head{driver.read<util::Vec3>(bone_array + bone_head * 32)};
const auto game_scene_node{ get_game_scene_node(driver) };
const auto bone_array{ driver.read<uintptr_t>(game_scene_node + client_dll::CPlayer_MovementServices_Humanoid::m_groundNormal) };
const auto head{ driver.read<util::Vec3>(bone_array + bone_head * 32) };

return head;
}

void Entity::set_spotted(const driver::Driver& driver, const bool& spotted) const
{
const auto p_entity_spotted_state{entity_pawn_ + client_dll::C_CSPlayerPawn::m_entitySpottedState};
const auto entity_spotted_address{p_entity_spotted_state + client_dll::EntitySpottedState_t::m_bSpotted};
const auto p_entity_spotted_state{ entity_pawn_ + client_dll::C_CSPlayerPawn::m_entitySpottedState };
const auto entity_spotted_address{ p_entity_spotted_state + client_dll::EntitySpottedState_t::m_bSpotted };
driver.write(entity_spotted_address, spotted);
}

Expand Down
5 changes: 2 additions & 3 deletions um-client/src/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace driver
{
Driver::Driver(): handle_(create_handle())
{
}
Driver::Driver() : handle_(create_handle())
{}

Driver::~Driver()
{
Expand Down
6 changes: 3 additions & 3 deletions um-client/src/driver/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace driver
// TODO this duplication between user mode and kernel mode is error prone
namespace control_codes
{
constexpr ULONG attach{CTL_CODE(FILE_DEVICE_UNKNOWN, 0xA1, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)};
constexpr ULONG read{CTL_CODE(FILE_DEVICE_UNKNOWN, 0xA2, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)};
constexpr ULONG write{CTL_CODE(FILE_DEVICE_UNKNOWN, 0xA3, METHOD_BUFFERED, FILE_SPECIAL_ACCESS)};
constexpr ULONG attach{ CTL_CODE(FILE_DEVICE_UNKNOWN, 0xA1, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) };
constexpr ULONG read{ CTL_CODE(FILE_DEVICE_UNKNOWN, 0xA2, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) };
constexpr ULONG write{ CTL_CODE(FILE_DEVICE_UNKNOWN, 0xA3, METHOD_BUFFERED, FILE_SPECIAL_ACCESS) };
}

class Driver
Expand Down
50 changes: 25 additions & 25 deletions um-client/src/global.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,38 @@

namespace g
{
static const std::wstring cs2_process_name{XORW(L"cs2.exe")};
static const std::wstring cs2_window_name{XORW(L"Counter-Strike 2")};
static const std::wstring client_dll_module_name{XORW(L"client.dll")};
static const std::wstring engine_dll_module_name{XORW(L"engine2.dll")};
static const int screen_width{GetSystemMetrics(SM_CXSCREEN)};
static const int screen_height{GetSystemMetrics(SM_CYSCREEN)};
static const ImVec2 screen_center{screen_width / 2.0f, screen_height / 2.0f};
static const std::wstring cs2_process_name{ XORW(L"cs2.exe") };
static const std::wstring cs2_window_name{ XORW(L"Counter-Strike 2") };
static const std::wstring client_dll_module_name{ XORW(L"client.dll") };
static const std::wstring engine_dll_module_name{ XORW(L"engine2.dll") };
static const int screen_width{ GetSystemMetrics(SM_CXSCREEN) };
static const int screen_height{ GetSystemMetrics(SM_CYSCREEN) };
static const ImVec2 screen_center{ screen_width / 2.0f, screen_height / 2.0f };

static ImVec4 esp_color{255.0f, 0.0f, 0.0f, 255.0f};
static ImVec4 esp_color{ 255.0f, 0.0f, 0.0f, 255.0f };
static ImVec4 esp_color_enemy_visible{ 0.0f, 0.0f, 255.0f, 255.0f };
static float esp_box_thickness{1.0f};
static ImVec4 esp_health_color{0.0f, 255.0f, 0.0f, 255.0f};
static ImVec4 text_color{0.0f, 255.0f, 0.0f, 255.0f};
static ImVec4 weapon_awp_text_color{255.0f, 0.0f, 0.0f, 255.0f};
static ImVec4 weapon_knife_text_color{0.0f, 0.0f, 255.0f, 255.0f};
static ImVec4 additional_screen_info_text_color{255.0f, 0.0f, 0.0f, 255.0f};
static int additional_screen_info_position_x{100};
static int additional_screen_info_position_y{350};
static float esp_box_thickness{ 1.0f };
static ImVec4 esp_health_color{ 0.0f, 255.0f, 0.0f, 255.0f };
static ImVec4 text_color{ 0.0f, 255.0f, 0.0f, 255.0f };
static ImVec4 weapon_awp_text_color{ 255.0f, 0.0f, 0.0f, 255.0f };
static ImVec4 weapon_knife_text_color{ 0.0f, 0.0f, 255.0f, 255.0f };
static ImVec4 additional_screen_info_text_color{ 255.0f, 0.0f, 0.0f, 255.0f };
static int additional_screen_info_position_x{ 100 };
static int additional_screen_info_position_y{ 350 };

static float aim_fov{50.0f};
static float aim_fov{ 50.0f };

namespace toggles
{
//TODO atomic
static bool is_paused{false};
static bool show_menu{false};
static bool radar_hack{false};
static bool glow_hack{false};
static bool no_flash_hack{false};
static bool esp_hack{false};
static bool aim_hack{false};
static bool aim_assist{false};
static bool is_paused{ false };
static bool show_menu{ false };
static bool radar_hack{ false };
static bool glow_hack{ false };
static bool no_flash_hack{ false };
static bool esp_hack{ false };
static bool aim_hack{ false };
static bool aim_assist{ false };

inline void reset_toggles()
{
Expand Down
Loading

0 comments on commit 8f3a764

Please sign in to comment.