Source Code Mega Thread

Posts 1–9 of 9 · Page 1 of 1
Source Code Mega Thread
From now on post your source code snippets here, don't post full bases/menu's. This is just for code snippets.

Format:
Name of cheat
Code Snippet (use tags)

GodMode
Code:
if (PLAYER_GODMODE == true)
       {
		PLAYER::SET_PLAYER_INVINCIBLE(PLAYER, true);
		PED::CLEAR_PED_BLOOD_DAMAGE(PLAYER_PED);
		PED::RESET_PED_VISIBLE_DAMAGE(PLAYER_PED);
	}
if (PLAYER_GODMODE == false)
	{
		PLAYER::SET_PLAYER_INVINCIBLE(PLAYER, false);
	}
Clear Wanted Level:

Code:
void ClearWantedLevel(Player player)
{
	PLAYER::CLEAR_PLAYER_WANTED_LEVEL(player);
}
Dealing with tunables
Ptr class to make reading/writing memory easier:
Code:
#include <windows.h>
#include <initializer_list>

#define naked __declspec(naked)

struct Ptr
{
    DWORD64 pointer;

    explicit Ptr(DWORD64 ptr, std::initializer_list<DWORD64> offsets = {}) : pointer(ptr)
    {
        for each (DWORD64 offset in offsets)
        {
            pointer = *reinterpret_cast<DWORD64*>(pointer);
            pointer += offset;
        }
    }

    template <typename T> T get(DWORD64 offset = 0)
    {
        return *reinterpret_cast<T*>(pointer + offset);
    }

    template <typename T> void set(T value, DWORD64 offset = 0)
    {
        *reinterpret_cast<T*>(pointer + offset) = value;
    }

    void nop(DWORD64 length) const
    {
        for (int i = 0; i < length; ++i)
        {
            *reinterpret_cast<BYTE*>(pointer + i) = 0x90; // nop
        }
    }
};
Custom AOB Scanner

Code:
#include <windows.h>
#include <Psapi.h>
#include <string>
#include <vector>
#include <sstream>
#include <cassert>

DWORD64 AOBScan(DWORD64 begin, DWORD64 end, std::string pattern)
{
    struct PByte
    {
        byte byte;
        bool ignore;
    };

    std::vector<PByte> patterns;

    std::stringstream ss;
    ss << pattern;

    std::string sByte;

    while (ss >> sByte)
    {
        if (sByte == "?" || sByte == "??")
        {
            patterns.push_back({ NULL, true });
        }
        else
        {
            int iByte = stoi(sByte, nullptr, 16);
            assert(iByte >= 0 && iByte <= 255);
            patterns.push_back({ byte(iByte), false });
        }
    }

    for (DWORD64 i = begin; i < end - DWORD64(patterns.size()); ++i)
    {
        bool success = true;

        for (DWORD64 j = 0; j < DWORD64(patterns.size()); ++j)
        {
            byte memByte = *reinterpret_cast<byte*>(i + j);
            PByte pByte = patterns[j];
            if (memByte != pByte.byte && !pByte.ignore)
            {
                success = false;
                break;
            }
        }

        if (success)
        {
            return i;
        }
    }

    return NULL;
}

DWORD64 AOBScan(MODULEINFO moduleInfo, std::string pattern)
{
    DWORD64 begin = DWORD64(moduleInfo.lpBaseOfDll);
    DWORD64 end = begin + DWORD64(moduleInfo.SizeOfImage);
    return AOBScan(begin, end, pattern);
}
Get Tunable Pointer
Code:
Ptr TunablesPointer()
{
    DWORD64 base = DWORD64(g_MainModuleInfo.lpBaseOfDll);
    int patternResult = *reinterpret_cast<int*>(AOBScan(g_MainModuleInfo, "48 8B 8C C2 ? ? ? ? 48 85 C9 74 19") + 4);
    return Ptr(base + patternResult + 8, { 16 });
}
Get/Set Tunables
Code:
template <typename T> void SetTunable(int index, T value)
{
    static Ptr tunablesPointer = TunablesPointer();
    return tunablesPointer.set(value, index * 8);
}

template <typename T> T GetTunable(int index)
{
    static Ptr tunablesPointer = TunablesPointer();
    return tunablesPointer.get<T>(index * 8);
}
Quote Originally Posted by TGWW$Twhwrhwhw4ryhrh View Post
Ptr class to make reading/writing memory easier:
Can you please help me adding this to a source based on scripthookv injection (ENT), I tried to use your Brick's Menu source as an example but I failed, of course... I just want to add the snow tunable to the trainer

 
pattern.h

Code:
#include <windows.h>
#include <Psapi.h>
#include <string>
#include <vector>
#include <sstream>
#include <cassert>

extern MODULEINFO g_MainModuleInfo;

//Custom AOB Scanner

DWORD64 AOBScan(DWORD64 begin, DWORD64 end, std::string pattern)
{
	struct PByte
	{
		byte byte;
		bool ignore;
	};

	std::vector<PByte> patterns;

	std::stringstream ss;
	ss << pattern;

	std::string sByte;

	while (ss >> sByte)
	{
		if (sByte == "?" || sByte == "??")
		{
			patterns.push_back({ NULL, true });
		}
		else
		{
			int iByte = stoi(sByte, nullptr, 16);
			assert(iByte >= 0 && iByte <= 255);
			patterns.push_back({ byte(iByte), false });
		}
	}

	for (DWORD64 i = begin; i < end - DWORD64(patterns.size()); ++i)
	{
		bool success = true;

		for (DWORD64 j = 0; j < DWORD64(patterns.size()); ++j)
		{
			byte memByte = *reinterpret_cast<byte*>(i + j);
			PByte pByte = patterns[j];
			if (memByte != pByte.byte && !pByte.ignore)
			{
				success = false;
				break;
			}
		}

		if (success)
		{
			return i;
		}
	}

	return NULL;
}

DWORD64 AOBScan(MODULEINFO moduleInfo, std::string pattern)
{
	DWORD64 begin = DWORD64(moduleInfo.lpBaseOfDll);
	DWORD64 end = begin + DWORD64(moduleInfo.SizeOfImage);
	return AOBScan(begin, end, pattern);
}


 
main.cpp

Code:
MODULEINFO g_MainModuleInfo = { 0 };

BOOL APIENTRY DllMain(HMODULE hInstance, DWORD reason, LPVOID lpReserved)
{
	switch (reason)
	{
	case DLL_PROCESS_ATTACH:

		if (!GetModuleInformation(GetCurrentProcess(), GetModuleHandle(nullptr), &g_MainModuleInfo, sizeof(g_MainModuleInfo)))
		{
			write_text_to_log_file("Unable to get MODULEINFO from GTA5.exe");
		}
		scriptRegister(hInstance, ScriptMain);
		keyboardHandlerRegister(OnKeyboardMessage);
		break;
	case DLL_PROCESS_DETACH:
		scriptUnregister(ScriptMain);
		keyboardHandlerUnregister(OnKeyboardMessage);
		ScriptTidyUp();
		break;
	}
	return TRUE;
}


 
main.h

#include <windows.h>
#include <initializer_list>

#define naked __declspec(naked)

struct Ptr
{
DWORD64 pointer;

explicit Ptr(DWORD64 ptr, std::initializer_list<DWORD64> offsets = {}) : pointer(ptr)
{
for each (DWORD64 offset in offsets)
{
pointer = *reinterpret_cast<DWORD64*>(pointer);
pointer += offset;
}
}

template <typename T> T get(DWORD64 offset = 0)
{
return *reinterpret_cast<T*>(pointer + offset);
}

template <typename T> void set(T value, DWORD64 offset = 0)
{
*reinterpret_cast<T*>(pointer + offset) = value;
}

void nop(DWORD64 length) const
{
for (int i = 0; i < length; ++i)
{
*reinterpret_cast<BYTE*>(pointer + i) = 0x90; // nop
}
}
};


 
script.cpp

Code:
Ptr TunablesPointer()
{
	DWORD64 base = DWORD64(g_MainModuleInfo.lpBaseOfDll);
	int patternResult = *reinterpret_cast<int*>(AOBScan(g_MainModuleInfo, "48 8B 8C C2 ? ? ? ? 48 85 C9 74 19") + 4);
	return Ptr(base + patternResult + 8, { 16 });
}

bool featureSnow = false;

if (featureSnow)
{
        SetTunable(4856, 1);
	SetTunable(7210, 0);
	SetTunable(7217, 10);
	SetTunable(7218, 10);
}
else
{
	SetTunable(4856, 0);
	SetTunable(7210, 1);
	SetTunable(7217, 0);
	SetTunable(7218, 0);
}


 
script.h

Code:
Ptr TunablesPointer();

template <typename T> void SetTunable(int index, T value)
{
	static Ptr tunablesPointer = TunablesPointer();
	return tunablesPointer.set(value, index * 8);
}

template <typename T> T GetTunable(int index)
{
	static Ptr tunablesPointer = TunablesPointer();
	return tunablesPointer.get<T>(index * 8);
}


Nothing happens when enabling the option in game
Explosive ammo, make sure to call it inside your loop:

Code:
SET_EXPLOSIVE_AMMO_THIS_FRAME(playerhandle);
Max Vehicle

Code:
void Max_veh(Vehicle VehicleHandle) {
	SET_VEHICLE_FIXED(VehicleHandle);
	SET_VEHICLE_DEFORMATION_FIXED(VehicleHandle);
	SET_VEHICLE_DIRT_LEVEL(VehicleHandle, 0);
	SET_VEHICLE_TYRES_CAN_BURST(VehicleHandle, 0);
	SET_VEHICLE_WHEELS_CAN_BREAK(VehicleHandle, 0);
	SET_VEHICLE_HAS_STRONG_AXLES(VehicleHandle, 1);
	SET_VEHICLE_MOD_KIT(VehicleHandle, 0);
	SET_VEHICLE_CUSTOM_SECONDARY_COLOUR(VehicleHandle, rand() % 255, rand() % 255, rand() % 255);
	SET_VEHICLE_CUSTOM_PRIMARY_COLOUR(VehicleHandle, rand() % 255, rand() % 255, rand() % 255);
	TOGGLE_VEHICLE_MOD(VehicleHandle, 18, 1);
	TOGGLE_VEHICLE_MOD(VehicleHandle, 22, 1);
	SET_VEHICLE_MOD(VehicleHandle, 16, 5, 0);
	SET_VEHICLE_MOD(VehicleHandle, 12, 2, 0);
	SET_VEHICLE_MOD(VehicleHandle, 11, 3, 0);
	SET_VEHICLE_MOD(VehicleHandle, 14, 14, 0);
	SET_VEHICLE_MOD(VehicleHandle, 15, 3, 0);
	SET_VEHICLE_MOD(VehicleHandle, 13, 2, 0);
	SET_VEHICLE_WHEEL_TYPE(VehicleHandle, 6);
	SET_VEHICLE_WINDOW_TINT(VehicleHandle, 1);
	SET_VEHICLE_MOD(VehicleHandle, 23, 14, 2);
	SET_VEHICLE_MOD(VehicleHandle, 0, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 1, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 2, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 3, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 4, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 5, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 6, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 7, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 8, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 9, 1, 0);
	SET_VEHICLE_MOD(VehicleHandle, 10, 1, 0);
	_SET_VEHICLE_NEON_LIGHT_ENABLED(VehicleHandle, 0, 1);
	_SET_VEHICLE_NEON_LIGHT_ENABLED(VehicleHandle, 1, 1);
	_SET_VEHICLE_NEON_LIGHT_ENABLED(VehicleHandle, 2, 1);
	_SET_VEHICLE_NEON_LIGHT_ENABLED(VehicleHandle, 3, 1);
	_SET_VEHICLE_NEON_LIGHTS_COLOUR(VehicleHandle, rand() % 255, rand() % 255, rand() % 255);
	SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(VehicleHandle, PLATE_YELLOWONBLACK);
	SET_VEHICLE_NUMBER_PLATE_TEXT(VehicleHandle, "MPGH");

}
Put This In Your Other Loop
Code:
if(godmode[0]){
        PLAYER::SET_PLAYER_INVINCIBLE(PLAYER, true);
        PED::CLEAR_PED_BLOOD_DAMAGE(PLAYER_PED);
        PED::RESET_PED_VISIBLE_DAMAGE(PLAYER_PED);
}
else{
	PLAYER::SET_PLAYER_INVINCIBLE(PLAYER, false);
}
Put This Is Your Submenu Options
Code:
addBoolOption("GodMode", &godmode[0]);
Put This In Your Switch
Code:
case 1: if (!godmode[0]){
        drawNotification("GodMode ~r~Disabled");
}
else{
        drawNotification("GodMode ~g~Enabled");
}
break;
Put This Near The Top Of Your File
Code:
bool godmode[50];
Use the checkboxes in bool arrays, looks cleaner
Quote Originally Posted by PhucedMODZ View Post
Put This In Your Other Loop
Code:
if(godmode[0]){
        PLAYER::SET_PLAYER_INVINCIBLE(PLAYER, true);
        PED::CLEAR_PED_BLOOD_DAMAGE(PLAYER_PED);
        PED::RESET_PED_VISIBLE_DAMAGE(PLAYER_PED);
}
else{
	PLAYER::SET_PLAYER_INVINCIBLE(PLAYER, false);
}
Put This Is Your Submenu Options
Code:
addBoolOption("GodMode", &godmode[0]);
Put This In Your Switch
Code:
case 1: if (!godmode[0]){
        drawNotification("GodMode ~r~Disabled");
}
else{
        drawNotification("GodMode ~g~Enabled");
}
break;
Put This Near The Top Of Your File
Code:
bool godmode[50];
Use the checkboxes in bool arrays, looks cleaner
That is detected and poorly optimized you moron
nice thanks
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?