How to change values internal [SOLVED]

Scraatch

Well-Known Member
Joined
Jan 14, 2017
Messages
76
Likes
2
Points
38
Location
Germany
#1
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.

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;
}
 

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,810
Likes
265
Points
113
Location
Lithuania
Website
ugbase.eu
20
#2
Can be used like.:
C++:
DWORD HealthPtr = 0xA9C0DC;

ReadProcessMemory(pHandle, (LPVOID)HealthPtr, &HealthPtrRTN, sizeof(HealthPtrRTN), NULL;
uintptr_t HealthFullPtr = HealthPtrRTN + 0x540;
ReadProcessMemory(pHandle, (LPVOID)HealthFullPtr, &HealthFullPtrRTN, sizeof(HealthFullPtrRTN), NULL;
 
OP
OP
Scraatch

Scraatch

Well-Known Member
Joined
Jan 14, 2017
Messages
76
Likes
2
Points
38
Location
Germany
#3
Can be used like.:
C++:
DWORD HealthPtr = 0xA9C0DC;

ReadProcessMemory(pHandle, (LPVOID)HealthPtr, &HealthPtrRTN, sizeof(HealthPtrRTN), NULL;
uintptr_t HealthFullPtr = HealthPtrRTN + 0x540;
ReadProcessMemory(pHandle, (LPVOID)HealthFullPtr, &HealthFullPtrRTN, sizeof(HealthFullPtrRTN), NULL;
How do i use it? cause i have no pHandle but i think thats my dwSAMP. but where do i get HealthPtrRTN and HealthFullPtrRTN? sry, have no much experience
 

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,810
Likes
265
Points
113
Location
Lithuania
Website
ugbase.eu
20
#4
C++:
HWND hWnd = FindWindowA(0, ("GTA:SA:MP"));

        GetWindowThreadProcessId(hWnd, &pid);
        HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
 
OP
OP
Scraatch

Scraatch

Well-Known Member
Joined
Jan 14, 2017
Messages
76
Likes
2
Points
38
Location
Germany
#5
C++:
HWND hWnd = FindWindowA(0, ("GTA:SA:MP"));

        GetWindowThreadProcessId(hWnd, &pid);
        HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
is this right?

C++:
[...]
DWORD pid;
    HWND hWnd = FindWindowA(0, ("GTA:SA:MP"));
    GetWindowThreadProcessId(hWnd, &pid);
    HANDLE pHandle = OpenProcess(PROCESS_VM_READ, FALSE, pid);
    do {
        if (GetAsyncKeyState(VK_NUMPAD1))
        {
            DWORD HealthPtrRTN;
            DWORD HealthFullPtrRTN;
            ReadProcessMemory(pHandle, (LPVOID)HealthPtr, &HealthPtrRTN, sizeof(HealthPtrRTN), NULL);
            uintptr_t HealthFullPtr = HealthPtrRTN + 0x540;
            ReadProcessMemory(pHandle, (LPVOID)HealthFullPtr, &HealthFullPtrRTN, sizeof(HealthFullPtrRTN), NULL);
[...]
 
Top