#define _CRT_NON_CONFORMING_WCSTOK
#include <iostream>
#include <Windows.h>
#include <codecvt>
#include "dx_overlay.h"
#include "dx_renderer.h"
#include "Offsets.h"
#include "structs.h"
using namespace std;
HWND hwnd;
HANDLE handle;
DWORD pID;
char name[999];
float matrix[16];
bool WorldToScreen(vec3d_f pos, vec3d_f& screen, float matrix[16], int windowWidth, int windowHeight)
{
clipCoords.x = pos.x * matrix[0] + pos.y * matrix[4] + pos.z * matrix[8] + matrix[12];
clipCoords.y = pos.x * matrix[1] + pos.y * matrix[5] + pos.z * matrix[9] + matrix[13];
clipCoords.z = pos.x * matrix[2] + pos.y * matrix[6] + pos.z * matrix[10] + matrix[14];
clipCoords.w = pos.x * matrix[3] + pos.y * matrix[7] + pos.z * matrix[11] + matrix[15];
NDC.x = clipCoords.x / clipCoords.w;
NDC.y = clipCoords.y / clipCoords.w;
NDC.z = clipCoords.z / clipCoords.w;
screen.x = (windowWidth / 2 * NDC.x) + (NDC.x + windowWidth / 2);
screen.y = -(windowHeight / 2 * NDC.y) + (NDC.y + windowHeight / 2);
return true;
}
template <class T>
T Read(DWORD address)
{
T VALUE;
ReadProcessMemory(handle, (LPVOID)(address), &VALUE, sizeof(T), 0);
return VALUE;
}
std::wstring readpChar(DWORD address) {
try {
if (address != 0) {
const size_t namesize = 200;
char x[namesize];
ReadProcessMemory(handle, (LPCVOID)address, &x, namesize, NULL);
std::wstring tmpname = std::wstring(&x[0], &x[namesize]);
wchar_t* czech = wcstok(&tmpname[0], L"\0");
if (czech != nullptr) return czech;
}
}
catch (const std::exception& exc) {}
return std::wstring(L"\0");
}
std::wstring stringToWstring(const std::string& t_str)
{
typedef std::codecvt_utf8<wchar_t> convert_type;
std::wstring_convert<convert_type, wchar_t> converter;
return converter.from_bytes(t_str);
}
int main()
{
hwnd = FindWindowA(NULL, "Cube 2: Sauerbraten");
GetWindowThreadProcessId(hwnd, &pID);
handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pID);
forceinline::dx_overlay overlay(L"SDL_app", L"Cube 2: Sauerbraten", true/**/);
if (!overlay.is_initialized())
return -1;
MSG m;
ZeroMemory(&m, sizeof(m));
forceinline::dx_renderer renderer = overlay.create_renderer();
while (m.message != WM_QUIT)
{
if (PeekMessage(&m, overlay.get_overlay_wnd(), NULL, NULL, PM_REMOVE))
{
TranslateMessage(&m);
DispatchMessage(&m);
}
renderer.begin_rendering();
//009F0000 - sauerbraten.exe -> Game Module
int players = Read<int>(0x009F0000 + offsets::players);
DWORD entitylist;
ReadProcessMemory(handle, (LPVOID)(0x009F0000 + offsets::entitybase), &entitylist, sizeof(entitylist), 0);
ReadProcessMemory(handle, (LPVOID)offsets::viewMatrix, &matrix, sizeof(matrix), 0);
for (int i = 0; i < players; i++)
{
DWORD ent;
ReadProcessMemory(handle, LPVOID(entitylist + (i * 4)),&ent,sizeof(ent), 0);
if (!ent)
continue;
int playerhealth = Read<int>(ent + offsets::health);
if (playerhealth <= 0)
continue;
vec3d_f location_enemy = Read<vec3d_f>(ent + offsets::x);
vec3d_f location_enemy2 = Read<vec3d_f>(ent + offsets::y);
vec3d_f location_enemy_out;
wstring nameplayer = readpChar(ent + offsets::name);
printf("Players:%d", players);
if (WorldToScreen(location_enemy, location_enemy_out, matrix, 1024, 768))
{
//renderer.draw_outlined_rect(50, 50, 50, 50, 0xFFFFFFFF);
renderer.draw_text(nameplayer, location_enemy_out.x, location_enemy_out.y + 15,0xFFFFFFFF,false);
}
system("cls");
renderer.end_rendering();
}
[SIZE=6]Good Luck :P[/SIZE]
}
}