Начинающий
- Статус
- Оффлайн
- Регистрация
- 22 Июл 2024
- Сообщения
- 122
- Реакции
- 2
C++:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cstdint>
#include <thread>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <sys/uio.h>
class MemoryReader {
private:
pid_t pid;
public:
MemoryReader(pid_t target_pid) : pid(target_pid) {}
template<typename T>
T read_memory(uint64_t address) {
T value;
struct iovec local_iov[] = { {&value, sizeof(T)} };
struct iovec remote_iov[] = { {reinterpret_cast<void*>(address), sizeof(T)} };
ssize_t bytes_read = process_vm_readv(pid, local_iov, 1, remote_iov, 1, 0);
if (bytes_read != sizeof(T)) {
throw std::runtime_error("Failed to read memory at address " + std::to_string(address));
}
return value;
}
bool is_valid_address(uint64_t address) {
return (address != 0) && (address >= 0x10000) && (address < 0x7FFFFFFFFFFF);
}
};
uint64_t find_lib_base_address(pid_t pid, const std::string& lib_name) {
std::string maps_path = "/proc/" + std::to_string(pid) + "/maps";
std::ifstream maps_file(maps_path);
std::string line;
while (std::getline(maps_file, line)) {
if (line.find(lib_name) != std::string::npos && line.find("r-xp") != std::string::npos) {
size_t dash_pos = line.find('-');
if (dash_pos != std::string::npos) {
return std::stoul(line.substr(0, dash_pos), nullptr, 16);
}
}
}
throw std::runtime_error("Library " + lib_name + " not found in process " + std::to_string(pid));
}
pid_t get_cs2_pid() {
FILE* pipe = popen("pidof cs2", "r");
if (!pipe) {
throw std::runtime_error("Failed to run pidof command");
}
char buffer[128];
if (!fgets(buffer, sizeof(buffer), pipe)) {
pclose(pipe);
throw std::runtime_error("CS2 not running");
}
pclose(pipe);
return static_cast<pid_t>(std::stoi(buffer));
}
class MouseController {
private:
Display* display;
public:
MouseController() {
display = XOpenDisplay(nullptr);
if (!display) {
throw std::runtime_error("Cannot open X display");
}
}
~MouseController() {
if (display) {
XCloseDisplay(display);
}
}
void click_left() {
XTestFakeButtonEvent(display, 1, True, CurrentTime);
XFlush(display);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
XTestFakeButtonEvent(display, 1, False, CurrentTime);
XFlush(display);
}
};
class KeyboardMonitor {
private:
Display* display;
KeyCode caps_lock_keycode;
KeyCode f8_keycode;
public:
KeyboardMonitor() {
display = XOpenDisplay(nullptr);
if (!display) {
throw std::runtime_error("Cannot open X display");
}
caps_lock_keycode = XKeysymToKeycode(display, XK_Caps_Lock);
f8_keycode = XKeysymToKeycode(display, XK_F8);
}
~KeyboardMonitor() {
if (display) {
XCloseDisplay(display);
}
}
bool is_caps_lock_pressed() {
char keys[32];
XQueryKeymap(display, keys);
return (keys[caps_lock_keycode / 8] & (1 << (caps_lock_keycode % 8))) != 0;
}
bool is_f8_pressed() {
char keys[32];
XQueryKeymap(display, keys);
return (keys[f8_keycode / 8] & (1 << (f8_keycode % 8))) != 0;
}
};
class TriggerBot {
private:
MemoryReader& memory;
uint64_t libclient_base;
struct Offsets {
uint64_t dwLocalPlayerPawn = 0x1BF1FA0;
uint64_t m_iIDEntIndex = 0x3EDC;
uint64_t dwEntityList = 0x1D16758;
uint64_t m_iHealth = 0x34C;
uint64_t m_iTeamNum = 0x3EB;
} offsets;
public:
TriggerBot(MemoryReader& mem, uint64_t base) : memory(mem), libclient_base(base) {}
void print_debug_info() {
try {
uint64_t local_player = memory.read_memory<uint64_t>(libclient_base + offsets.dwLocalPlayerPawn);
if (!memory.is_valid_address(local_player)) {
std::cout << "❌ Local player not found" << std::endl;
return;
}
int entity_id = memory.read_memory<int32_t>(local_player + offsets.m_iIDEntIndex);
std::cout << "🎯 Entity ID in crosshair: " << entity_id << std::endl;
if (entity_id <= 0 || entity_id > 64) {
std::cout << "❌ No valid target in crosshair" << std::endl;
return;
}
// Получаем команду локального игрока
int local_team = memory.read_memory<int32_t>(local_player + offsets.m_iTeamNum);
std::cout << "👤 Local player team: " << local_team << std::endl;
// Получаем entity из entity list
uint64_t entity_list = memory.read_memory<uint64_t>(libclient_base + offsets.dwEntityList);
if (!memory.is_valid_address(entity_list)) {
std::cout << "❌ Entity list not found" << std::endl;
return;
}
uint64_t list_entry = memory.read_memory<uint64_t>(entity_list + 0x8 * ((entity_id & 0x7FFF) >> 9) + 0x10);
if (!memory.is_valid_address(list_entry)) {
std::cout << "❌ List entry not found" << std::endl;
return;
}
uint64_t entity = memory.read_memory<uint64_t>(list_entry + 120 * (entity_id & 0x1FF));
if (!memory.is_valid_address(entity)) {
std::cout << "❌ Entity not found" << std::endl;
return;
}
// Получаем информацию о entity
int entity_health = memory.read_memory<int32_t>(entity + offsets.m_iHealth);
int entity_team = memory.read_memory<int32_t>(entity + offsets.m_iTeamNum);
std::cout << "🔍 Target info - Health: " << entity_health << ", Team: " << entity_team << std::endl;
// Проверяем условия для выстрела
if (entity_health > 0 && entity_team > 0 && local_team > 0 && entity_team != local_team) {
std::cout << "✅ VALID TARGET - Enemy spotted! Ready to fire!" << std::endl;
} else if (entity_team == local_team) {
std::cout << "🚫 INVALID TARGET - Friendly player" << std::endl;
} else if (entity_health <= 0) {
std::cout << "💀 INVALID TARGET - Target is dead" << std::endl;
} else {
std::cout << "❓ UNKNOWN TARGET - Cannot determine target type" << std::endl;
}
} catch (const std::exception& e) {
std::cout << "💥 Error reading memory: " << e.what() << std::endl;
}
}
bool should_trigger() {
try {
uint64_t local_player_addr = libclient_base + offsets.dwLocalPlayerPawn;
std::cout << "DEBUG: Local player address: 0x" << std::hex << local_player_addr << std::dec << std::endl;
uint64_t local_player = memory.read_memory<uint64_t>(local_player_addr);
int entity_id = memory.read_memory<int32_t>(local_player + offsets.m_iIDEntIndex);
if (entity_id <= 0 || entity_id > 64) {
return false;
}
int local_team = memory.read_memory<int32_t>(local_player + offsets.m_iTeamNum);
uint64_t entity_list = memory.read_memory<uint64_t>(libclient_base + offsets.dwEntityList);
if (!memory.is_valid_address(entity_list)) {
return false;
}
uint64_t list_entry = memory.read_memory<uint64_t>(entity_list + 0x8 * ((entity_id & 0x7FFF) >> 9) + 0x10);
if (!memory.is_valid_address(list_entry)) {
return false;
}
uint64_t entity = memory.read_memory<uint64_t>(list_entry + 120 * (entity_id & 0x1FF));
if (!memory.is_valid_address(entity)) {
return false;
}
int entity_health = memory.read_memory<int32_t>(entity + offsets.m_iHealth);
int entity_team = memory.read_memory<int32_t>(entity + offsets.m_iTeamNum);
return (entity_health > 0 && entity_team > 0 && local_team > 0 && entity_team != local_team);
} catch (const std::exception& e) {
return false;
}
}
};
int main() {
try {
pid_t pid = get_cs2_pid();
std::cout << "🎮 CS2 PID: " << pid << std::endl;
MemoryReader memory(pid);
uint64_t libclient = find_lib_base_address(pid, "libclient.so");
std::cout << "📍 libclient.so base: 0x" << std::hex << libclient << std::dec << std::endl;
MouseController mouse;
KeyboardMonitor keyboard;
TriggerBot trigger_bot(memory, libclient);
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> delay(0.02, 0.04);
std::cout << "🚀 Trigger bot started!" << std::endl;
std::cout << "💡 Controls: CapsLock = Trigger, F8 = Exit" << std::endl;
std::cout << "🔍 Debug mode: Press any key to see crosshair target info" << std::endl;
bool was_caps_lock_pressed = false;
auto last_debug_time = std::chrono::steady_clock::now();
while (true) {
// Выход по F8
if (keyboard.is_f8_pressed()) {
std::cout << "👋 Exiting..." << std::endl;
break;
}
bool is_caps_lock_pressed = keyboard.is_caps_lock_pressed();
auto now = std::chrono::steady_clock::now();
if (std::chrono::duration_cast<std::chrono::seconds>(now - last_debug_time).count() >= 2) {
std::cout << "\n=== DEBUG INFO ===" << std::endl;
trigger_bot.print_debug_info();
std::cout << "==================" << std::endl;
last_debug_time = now;
}
if (is_caps_lock_pressed && !was_caps_lock_pressed) {
if (trigger_bot.should_trigger()) {
std::cout << "🔥 FIRING at enemy!" << std::endl;
std::this_thread::sleep_for(std::chrono::duration<double>(delay(gen)));
mouse.click_left();
}
}
was_caps_lock_pressed = is_caps_lock_pressed;
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
} catch (const std::exception& e) {
std::cerr << "💥 Error: " << e.what() << std::endl;
return 1;
}
return 0;
}