I am learning to code with c++ and i try to make an samp cheat as an dll/asi file. Now i want to change the health and i now that the player pointer is 0xB6F5F0 and the health offset is 0x540 . how can i acces to that? i tried this and this is my whole code:
btw: the unlimited ammo function is working.
btw: the unlimited ammo function is working.
C++:
#pragma comment(lib, "Open-SAMP-API.lib")
#include <iostream>
#include "SAMP_API.h"
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#include "mem.h"
#define SAMP_DLL "samp.dll"
#define SAMP_CMP "F8036A004050518D4C24"
using namespace std;
int unlimitammo = 0;
DWORD CPed = 0xB6F5F0;
DWORD ADDR_INFIRUN = 0xB7CEE4;
DWORD ADDR_ALLNITRO = 0x969165;
DWORD ADDR_INFIAMMO = 0x969178;
DWORD ADDR_CURRENT_WEAPON = 0xBAA410;
DWORD ADDR_VEHICLE_PTR = 0xBA18FC;
DWORD OFFSET_PLAYER_HEALTH = 0x540;
DWORD ADDR_PLAYER_HEALTH = CPed + OFFSET_PLAYER_HEALTH;
uintptr_t dwSAMP = (uintptr_t)GetModuleHandle(L"GTA:SA:MP");
int HackThread(void)
{
do {
if (GetAsyncKeyState(VK_NUMPAD1))
{
uintptr_t ADDR_HEALTH = mem::FindDMAAddy(dwSAMP + 0xB6F5F0, { 0x540 });
int* PLAYER_HEALTH = (int*)ADDR_HEALTH;
*PLAYER_HEALTH = 50;
AddChatMessage("Health changed");
cout << "[FUNC] Health changed" << endl;
Sleep(100);
}
if (GetAsyncKeyState(VK_NUMPAD8))
{
unlimitammo = !unlimitammo;
if (unlimitammo) {
*(int*)(ADDR_INFIAMMO) = 1;
cout << "[FUNC] Infinity ammunation activated" << endl;
}
else {
*(int*)(ADDR_INFIAMMO) = 0;
cout << "[FUNC] Infinity ammunation deactivated" << endl;
}
char buf[256];
sprintf_s(buf, "unlimited ammo %s", unlimitammo ? "{FF00FF}activated" : "{00FFFF}deactivated");
AddChatMessage(buf);
Sleep(100);
}
Sleep(10);
} while (!GetAsyncKeyState(VK_DELETE));
ShowGameText("~r~Cheat disabled", 3000, 3);
return 0;
}
class TextOverlay
{
int _id = -1;
public:
~TextOverlay()
{
destroy();
}
bool create()
{
if (_id != -1)
return false;
return (_id = TextCreate("Arial", 5, false, false, 0, -3, 0xFFFFFFFF, "{FFFF00}SA:MP Cheat by Ashkan", true, true)) != -1;
}
bool destroy()
{
if (_id == -1)
return false;
bool bRes = TextDestroy(_id) == 1;
_id = -1;
return bRes;
}
operator int()
{
return _id;
}
};
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)HackThread, NULL, 0, 0);
AllocConsole();
FILE* fp;
freopen_s(&fp, "CONOUT$", "w", stdout);
cout << "SA:MP 0.3.7 Cheat by Ashkan\n\n DEBUG MODE\n_______________________\nPress DELETE to unload the cheat!\n\n\a";
break;
case DLL_PROCESS_DETACH:
break;
}
return true;
}