-
Автор темы
- #1
не получается узнать здоровье игрока, пытаюсь считать localPlayerController, выдает 0
main.cpp
memory.cpp
main.cpp
C++:
#include <iostream>
#include "memory.cpp"
#include "offsets.h"
int main()
{
HWND hwnd;
do {
hwnd = FindWindowA(0, "Counter-Strike 2");
Sleep(50);
} while (!hwnd);
DWORD pid;
pid = memory::PIDByName(L"cs2.exe");
DWORD client;
client = memory::getmoduleadres(pid, L"client.dll");
HANDLE proc;
proc = OpenProcess(PROCESS_ALL_ACCESS, false, pid);
uintptr_t localPlayerController = memory::memory_read<uintptr_t>(proc, client + 0x1823128);
int health = memory::memory_read<int>(proc, localPlayerController + 0x344);
std::cout << health << "\n";
}
C++:
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <thread>
namespace memory
{
static DWORD getmoduleadres(DWORD pid, const WCHAR* name)
{
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pid);
MODULEENTRY32 mEntry;
mEntry.dwSize = sizeof(MODULEENTRY32);
do
{
if (mEntry.szModule == name)
{
std::cout << mEntry.szModule;
CloseHandle(snapshot);
return (DWORD)mEntry.modBaseAddr;
}
} while (Module32Next(snapshot, &mEntry));
}
static DWORD PIDByName(const WCHAR* AProcessName)
{
HANDLE pHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 ProcessEntry;
DWORD pid;
ProcessEntry.dwSize = sizeof(ProcessEntry);
bool Loop = Process32First(pHandle, &ProcessEntry);
while (Loop)
{
if (wcsstr(ProcessEntry.szExeFile, AProcessName))
{
pid = ProcessEntry.th32ProcessID;
CloseHandle(pHandle);
return pid;
}
Loop = Process32Next(pHandle, &ProcessEntry);
}
return 0;
}
template <typename T>
T memory_write(HANDLE process, DWORD address, T value)
{
WriteProcessMemory(process, (LPVOID)address, &value, sizeof(value), 0);
}
template <typename T>
T memory_read(HANDLE process, const std::uintptr_t& address)
{
T value = { };
::ReadProcessMemory(process, (LPVOID)address, &value, sizeof(T), 0);
return value;
}
}