Начинающий
Начинающий
- Статус
- Оффлайн
- Регистрация
- 19 Мар 2021
- Сообщения
- 5
- Реакции
- 0
Не знаю что не так я делаю, но не он не прыгает. Будьте добры, подскажите что я не так делаю..
сурс:
#include "pch.h"
#include <cstdint>
#include <vector>
#include <cstring>
#include <MinHook.h>
#include <iostream>
#include <atomic>
#include <cstdio>
#include "../includes/offsets.hpp"
#include "../includes/client_dll.hpp"
#include <Windows.h>
namespace test_input {
static uintptr_t ccsgoInputPtr = 0;
using CreateMoveFn = void(__fastcall*)(void* rcx, int edx, char r8, void* r9, void* a5, void* a6, void* a7, const char* a8);
static CreateMoveFn g_originalCreateMove = nullptr;
struct CUserCmd {
int32_t command_number;
int32_t tick_count;
float viewangles[3];
float aimdirection[3];
float forwardmove;
float sidemove;
float upmove;
int64_t buttons;
uint8_t impulse;
uint8_t pad_35[3];
int32_t weaponselect;
int32_t weaponsubtype;
int32_t random_seed;
int16_t mousedx;
int16_t mousedy;
uint8_t hasbeenpredicted;
uint8_t pad_49[0x78 - 0x49];
};
enum ECommandButtons : std::uint64_t {
IN_ATTACK = 1ull << 0,
IN_JUMP = 1ull << 1,
IN_DUCK = 1ull << 2,
IN_FORWARD= 1ull << 3,
IN_BACK = 1ull << 4,
IN_USE = 1ull << 5,
};
static const char* kCreateMovePattern = "48 8B C4 4C 89 40 ? 48 89 48 ? 55 53 41 57";
static const char* kCCSGOInputPattern = "48 8B 0D ? ? ? ? 48 8B 01 FF 50 ? 8B DF";
template<class T>
T absolute_to(uintptr_t value, ptrdiff_t rel_offset = 0x1, ptrdiff_t abs_offset = 0x0) noexcept {
const auto jmp = value + rel_offset;
const auto target = *reinterpret_cast<int32_t*>(jmp);
if (target)
return reinterpret_cast<T>(jmp + abs_offset + sizeof(int32_t) + target);
return T();
}
static std::uint8_t* PatternScan(const char* module_name, const char* signature) noexcept {
const HMODULE module_handle = GetModuleHandleA(module_name);
if (!module_handle) return nullptr;
auto pattern_to_byte = [](const char* pattern) {
std::vector<int> bytes;
const char* end = pattern + std::strlen(pattern);
for (const char* current = pattern; current < end; ++current) {
if (*current == ' ') continue;
if (*current == '?') {
++current;
if (current < end && *current == '?') ++current;
bytes.push_back(-1);
} else {
bytes.push_back(std::strtoul(current, const_cast<char**>(¤t), 16));
}
}
return bytes;
};
const auto dos_header = reinterpret_cast<PIMAGE_DOS_HEADER>(module_handle);
const auto nt_headers = reinterpret_cast<PIMAGE_NT_HEADERS>(reinterpret_cast<std::uint8_t*>(module_handle) + dos_header->e_lfanew);
const size_t size_of_image = nt_headers->OptionalHeader.SizeOfImage;
const auto pattern_bytes = pattern_to_byte(signature);
auto scan_bytes = reinterpret_cast<std::uint8_t*>(module_handle);
const size_t s = pattern_bytes.size();
const int* d = pattern_bytes.data();
for (size_t i = 0; i + s <= size_of_image; ++i) {
bool found = true;
for (size_t j = 0; j < s; ++j) {
if (d[j] != -1 && scan_bytes[i + j] != d[j]) { found = false; break; }
}
if (found) return &scan_bytes[i];
}
return nullptr;
}
static uintptr_t GetVTable(void* object, int index) {
if (!object) return 0;
uintptr_t* vtablePtr = reinterpret_cast<uintptr_t*>(object);
uintptr_t vtable = *vtablePtr;
return reinterpret_cast<uintptr_t*>(vtable)[index];
}
static bool IsReadablePtr(const void* p) {
if (!p) return false;
MEMORY_BASIC_INFORMATION mbi{};
if (!VirtualQuery(p, &mbi, sizeof(mbi))) return false;
return (mbi.State == MEM_COMMIT) && (mbi.Protect != PAGE_NOACCESS);
}
static uintptr_t GetLocalPawn() {
uintptr_t entitySystem = *reinterpret_cast<uintptr_t*>(GetModuleHandleA("client.dll") + cs2_dumper::offsets::client_dll::dwEntityList);
if (!entitySystem) return 0;
uintptr_t localController = *reinterpret_cast<uintptr_t*>(entitySystem + 0x8 * (1));
if (!localController) return 0;
return *reinterpret_cast<uintptr_t*>(localController + cs2_dumper::schemas::client_dll::CBasePlayerController::m_hPawn);
}
static bool IsOnGround(uintptr_t pawn) {
if (!pawn) return false;
int flags = *reinterpret_cast<int*>(pawn + cs2_dumper::schemas::client_dll::C_BaseEntity::m_fFlags);
return (flags & 1) != 0;
}
static void* GetInputSystemInterface() {
HMODULE client = GetModuleHandleA("client.dll");
if (!client) return nullptr;
auto createInterface = reinterpret_cast<void* (*)(const char*, int*)>(
GetProcAddress(client, "CreateInterface"));
if (!createInterface) return nullptr;
int returnCode = 0;
void* inputSystem = createInterface("InputSystemVersion001", &returnCode);
if (inputSystem) {
std::cout << "[test_input] Input System interface found at 0x" << std::hex
<< reinterpret_cast<uintptr_t>(inputSystem) << std::dec << std::endl;
} else {
std::cout << "[test_input] Failed to get Input System interface, return code: " << returnCode << std::endl;
}
return inputSystem;
}
static void* GetInputSystemViaVTable() {
HMODULE client = GetModuleHandleA("client.dll");
if (!client) return nullptr;
std::uint8_t* inputPattern = PatternScan("client.dll", "48 8B 0D ? ? ? ? 4C 8B C6 8B 10 E8");
if (!inputPattern) return nullptr;
void** inputSystemPtr = absolute_to<void**>(reinterpret_cast<uintptr_t>(inputPattern), 0x3, 0x0);
if (!inputSystemPtr || !*inputSystemPtr) return nullptr;
std::cout << "[test_input] Input System found via VTable at 0x" << std::hex
<< reinterpret_cast<uintptr_t>(*inputSystemPtr) << std::dec << std::endl;
return *inputSystemPtr;
}
static std::atomic<bool> g_consoleAttached{false};
static void __fastcall CreateMove_Hook(void* rcx, int edx, char r8, void* r9, void* a5, void* a6, void* a7, const char* a8) {
g_originalCreateMove(rcx, edx, r8, r9, a5, a6, a7, a8);
if (!ccsgoInputPtr) return;
uintptr_t input = *reinterpret_cast<uintptr_t*>(ccsgoInputPtr);
if (!input || !IsReadablePtr(reinterpret_cast<void*>(input))) return;
uintptr_t localPawn = GetLocalPawn();
if (!localPawn) return;
int tickBase = *reinterpret_cast<int*>(localPawn + cs2_dumper::schemas::client_dll::CBasePlayerController::m_nTickBase);
int index = tickBase % 150;
CUserCmd* cmd = reinterpret_cast<CUserCmd*>(input + 0x170 + index * sizeof(CUserCmd));
if (!cmd || !IsReadablePtr(cmd)) return;
if (cmd->buttons & (1ULL << 1)) {
if (!IsOnGround(localPawn)) {
cmd->buttons &= ~(1ULL << 1);
}
}
cmd->viewangles[0] = 0.f;
}
static void AttachDebugConsole() {
if (g_consoleAttached.load()) return;
AllocConsole();
freopen_s(reinterpret_cast<FILE**>(stdout), "CONOUT$", "w", stdout);
freopen_s(reinterpret_cast<FILE**>(stdin), "CONIN$", "r", stdin);
freopen_s(reinterpret_cast<FILE**>(stderr), "CONOUT$", "w", stderr);
g_consoleAttached.store(true);
std::cout << "[test_input] Debug console attached!" << std::endl;
}
static void FreeDebugConsole() {
if (!g_consoleAttached.load()) return;
FreeConsole();
g_consoleAttached.store(false);
}
static void InitializeHook() {
if (MH_Initialize() != MH_OK) {
if (g_consoleAttached.load()) std::cout << "[test_input] MH_Initialize failed" << std::endl;
return;
}
HMODULE client = nullptr;
for (int i = 0; i < 50; i++) {
client = GetModuleHandleA("client.dll");
if (client) break;
Sleep(100);
}
if (!client) {
std::cout << "[test_input] client.dll not found after 5s" << std::endl;
MH_Uninitialize();
return;
}
std::cout << "[test_input] client.dll found at 0x" << std::hex << reinterpret_cast<uintptr_t>(client) << std::dec << std::endl;
std::cout << "[test_input] Trying to get Input System via interface..." << std::endl;
void* inputSystem = GetInputSystemInterface();
if (inputSystem) {
std::cout << "[test_input] Input System obtained via interface successfully!" << std::endl;
int index = 5;
uintptr_t createMoveAddr = GetVTable(inputSystem, index);
if (createMoveAddr && IsReadablePtr(reinterpret_cast<void*>(createMoveAddr))) {
std::cout << "[test_input] Found CreateMove at VTable index " << index << " at 0x" << std::hex << createMoveAddr << std::dec << std::endl;
if (MH_CreateHook(reinterpret_cast<LPVOID>(createMoveAddr), reinterpret_cast<LPVOID>(&CreateMove_Hook),
reinterpret_cast<LPVOID*>(&g_originalCreateMove)) == MH_OK) {
if (MH_EnableHook(reinterpret_cast<LPVOID>(createMoveAddr)) == MH_OK) {
std::cout << "[test_input] Input System CreateMove hook enabled successfully at index " << index << "!" << std::endl;
return;
} else {
std::cout << "[test_input] MH_EnableHook failed for Input System CreateMove at index " << index << std::endl;
MH_RemoveHook(reinterpret_cast<LPVOID>(createMoveAddr));
}
} else {
std::cout << "[test_input] MH_CreateHook failed for Input System CreateMove at index " << index << std::endl;
}
}
std::cout << "[test_input] Input System CreateMove hook failed, trying fallback methods..." << std::endl;
} else {
std::cout << "[test_input] Input System interface failed, trying VTable method..." << std::endl;
void* inputSystem = GetInputSystemViaVTable();
if (inputSystem) {
int index = 5;
uintptr_t createMoveAddr = GetVTable(inputSystem, index);
if (createMoveAddr && IsReadablePtr(reinterpret_cast<void*>(createMoveAddr))) {
std::cout << "[test_input] Found CreateMove at VTable index " << index << " at 0x" << std::hex << createMoveAddr << std::dec << std::endl;
if (MH_CreateHook(reinterpret_cast<LPVOID>(createMoveAddr), reinterpret_cast<LPVOID>(&CreateMove_Hook),
reinterpret_cast<LPVOID*>(&g_originalCreateMove)) == MH_OK) {
if (MH_EnableHook(reinterpret_cast<LPVOID>(createMoveAddr)) == MH_OK) {
std::cout << "[test_input] VTable Input System CreateMove hook enabled successfully at index " << index << "!" << std::endl;
return;
} else {
std::cout << "[test_input] MH_EnableHook failed for VTable Input System CreateMove at index " << index << std::endl;
MH_RemoveHook(reinterpret_cast<LPVOID>(createMoveAddr));
}
} else {
std::cout << "[test_input] MH_CreateHook failed for VTable Input System CreateMove at index " << index << std::endl;
}
}
}
}
std::cout << "[test_input] Trying direct CreateMove hook..." << std::endl;
std::uint8_t* createMoveAddr = PatternScan("client.dll", kCreateMovePattern);
if (createMoveAddr) {
std::cout << "[test_input] CreateMove found at 0x" << std::hex << reinterpret_cast<uintptr_t>(createMoveAddr) << std::dec << std::endl;
if (MH_CreateHook(reinterpret_cast<LPVOID>(createMoveAddr), reinterpret_cast<LPVOID>(&CreateMove_Hook),
reinterpret_cast<LPVOID*>(&g_originalCreateMove)) == MH_OK) {
if (MH_EnableHook(reinterpret_cast<LPVOID>(createMoveAddr)) == MH_OK) {
std::cout << "[test_input] Direct CreateMove hook enabled successfully!" << std::endl;
return;
} else {
std::cout << "[test_input] MH_EnableHook failed for direct CreateMove" << std::endl;
}
} else {
std::cout << "[test_input] MH_CreateHook failed for direct CreateMove" << std::endl;
}
std::cout << "[test_input] Direct CreateMove hook failed, trying VTable..." << std::endl;
}
std::cout << "[test_input] Trying VTable hook on CCSGOInput..." << std::endl;
std::uint8_t* ccsgoInput = PatternScan("client.dll", kCCSGOInputPattern);
if (!ccsgoInput) {
std::cout << "[test_input] CCSGOInput not found!" << std::endl;
MH_Uninitialize();
return;
}
std::cout << "[test_input] CCSGOInput pattern found at 0x" << std::hex << reinterpret_cast<uintptr_t>(ccsgoInput) << std::dec << std::endl;
void** ccsgoInputPtrTemp = absolute_to<void**>(reinterpret_cast<uintptr_t>(ccsgoInput), 0x3, 0x0);
if (!ccsgoInputPtrTemp || !*ccsgoInputPtrTemp) {
std::cout << "[test_input] Failed to get CCSGOInput pointer!" << std::endl;
MH_Uninitialize();
return;
}
if (!IsReadablePtr(*ccsgoInputPtrTemp)) {
std::cout << "[test_input] CCSGOInput pointer is not readable!" << std::endl;
MH_Uninitialize();
return;
}
ccsgoInputPtr = reinterpret_cast<uintptr_t>(ccsgoInputPtrTemp);
std::cout << "[test_input] CCSGOInput pointer found at 0x" << std::hex << reinterpret_cast<uintptr_t>(*ccsgoInputPtrTemp) << std::dec << std::endl;
int index = 5;
uintptr_t vtable = GetVTable(*ccsgoInputPtrTemp, index);
if (vtable && IsReadablePtr(reinterpret_cast<void*>(vtable))) {
std::cout << "[test_input] Found CreateMove at CCSGOInput VTable index " << index << " at 0x" << std::hex << vtable << std::dec << std::endl;
if (MH_CreateHook(reinterpret_cast<LPVOID>(vtable), reinterpret_cast<LPVOID>(&CreateMove_Hook),
reinterpret_cast<LPVOID*>(&g_originalCreateMove)) == MH_OK) {
if (MH_EnableHook(reinterpret_cast<LPVOID>(vtable)) == MH_OK) {
std::cout << "[test_input] VTable hook on CCSGOInput CreateMove enabled successfully at index " << index << "!" << std::endl;
return;
} else {
std::cout << "[test_input] MH_EnableHook failed for CCSGOInput VTable hook at index " << index << std::endl;
MH_RemoveHook(reinterpret_cast<LPVOID>(vtable));
}
} else {
std::cout << "[test_input] MH_CreateHook failed for CCSGOInput VTable hook at index " << index << std::endl;
}
}
std::cout << "[test_input] Failed to hook CreateMove!" << std::endl;
MH_Uninitialize();
}
static void ShutdownHook() {
MH_DisableHook(MH_ALL_HOOKS);
MH_Uninitialize();
}
static DWORD WINAPI InitThread(LPVOID module) {
AttachDebugConsole();
InitializeHook();
int counter = 0;
while (true) {
Sleep(1000);
counter++;
std::cout << "[test_input] Thread alive, counter: " << counter << std::endl;
if (GetAsyncKeyState(VK_DELETE) & 0x8000) {
std::cout << "[test_input] DELETE key detected!" << std::endl;
}
if (GetAsyncKeyState(VK_SPACE) & 0x8000) {
std::cout << "[test_input] SPACE key detected!" << std::endl;
}
}
return 0;
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID) {
using namespace test_input;
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hModule);
HANDLE h = CreateThread(nullptr, 0, InitThread, hModule, 0, nullptr);
if (h) CloseHandle(h);
} else if (ul_reason_for_call == DLL_PROCESS_DETACH) {
ShutdownHook();
FreeDebugConsole();
}
return TRUE;
}