- 33
- 2
Переписать external cheat в internal для MTA оказалось труднее, чем я думал(инжект работает и не банит). Заранее извиняюсь если код выглядит плохо, только учусь. Крашит после инжекта, пробовал изменять функцию world_to_screen, крашит в if'ах(внутри функции). Помогите если не трудно
C++:
#include "pch.h"
#include <windows.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <string>
std::vector<int> world_to_screen(std::vector<std::vector<float>> ViewMatrix1, float x, float y, float z) {
std::vector<int> badcord = { -1, -1 };
std::vector<int> result(2);
float screenz = (z * ViewMatrix1[2][2]) + (y * ViewMatrix1[1][2]) + (x * ViewMatrix1[0][2]) + ViewMatrix1[3][2];
if (screenz < 0.01f) {
return badcord;
}
float screenx = (ViewMatrix1[2][0] * z) + (ViewMatrix1[1][0] * y) + (ViewMatrix1[0][0] * x) + ViewMatrix1[3][0];
float screeny = (ViewMatrix1[2][1] * z) + (ViewMatrix1[1][1] * y) + (ViewMatrix1[0][1] * x) + ViewMatrix1[3][1];
float recip = 1.0f / screenz;
screenx *= recip * 1920;
screeny *= recip * 1080;
if (1920 >= screenx && screenx >= 0 && 1080 >= screeny && screeny >= 0) {
result[0] = static_cast<int>(screenx);
result[1] = static_cast<int>(screeny);
return result;
}
else {
return badcord;
}
}
DWORD WINAPI MainThread(HMODULE hModule)
{
AllocConsole();
system("title First project");
FILE* f;
freopen_s(&f, "CONOUT$", "w", stdout);
//printf("Test 1");
Sleep(200);
DWORD offsetview = 0xB6FA2C;
bool espstatus = false;
DWORD* cped = (DWORD*)0xB6F5F0;
float* myhealth = (float*)(*cped + 0x540);
float* myarmour = (float*)(*cped + 0x548);
DWORD* xyz = (DWORD*)(*cped + 0x14);
float* x = (float*)(*xyz + 0x30);
float* y = (float*)(*xyz + 0x30 + 4);
float* z = (float*)(*xyz + 0x30 + 8);
std::vector<std::vector<float>> ViewMatrix(4, std::vector<float>(4));
while (!GetAsyncKeyState(VK_END))
{
if (GetAsyncKeyState(VK_INSERT)) {
espstatus = true;
}
if (GetAsyncKeyState(VK_DELETE)) {
espstatus = false;
}
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
ViewMatrix[i][j] = *(float*)(offsetview + 16 * i + 4 * j);
}
}
for (int i = 1; i < 120; i++) {
DWORD* cpedsearch = (DWORD*)(cped + i * 0x7c4);
float* health = (float*)(cpedsearch + 0x540);
if (*health <= 160.0f && *health >= 4.0f) {
DWORD* pointercoords = (DWORD*)(cpedsearch + 0x14);
float* hisx = (float*)(*cpedsearch + 0x30);
float* hisy = (float*)(*cpedsearch + 0x34);
float* hisz = (float*)(*cpedsearch + 0x38);
std::vector<int> onscreen = world_to_screen(ViewMatrix, *hisx, *hisy, *hisz);
//далее будет рисование, но пока упустим
}
}
}
if (GetAsyncKeyState(VK_END))
{
FreeConsole();
fclose(f);
}
FreeLibraryAndExitThread(hModule, 0);
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule); //disables attach and detach notifications
CloseHandle(CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)MainThread, hModule, 0, nullptr));
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}