Rewrite lua to C++

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
166
Location
Poland
Hi, I need the help of a person who would rewrite the script lua to C++:
Code:
local memory = require 'memory'
function main()
wait(-1)
end
function patch()

if memory.getuint8(0x748C2B) == 0xE8 then
memory.fill(0x748C2B, 0x90, 5, true)
elseif memory.getuint8(0x748C7B) == 0xE8 then
memory.fill(0x748C7B, 0x90, 5, true)
end
if memory.getuint8(0x5909AA) == 0xBE then
memory.write(0x5909AB, 1, 1, true)
end
if memory.getuint8(0x590A1D) == 0xBE then
memory.write(0x590A1D, 0xE9, 1, true)
memory.write(0x590A1E, 0x8D, 4, true)
end
if memory.getuint8(0x748C6B) == 0xC6 then
memory.fill(0x748C6B, 0x90, 7, true)
elseif memory.getuint8(0x748CBB) == 0xC6 then
memory.fill(0x748CBB, 0x90, 7, true)
end
if memory.getuint8(0x590AF0) == 0xA1 then
memory.write(0x590AF0, 0xE9, 1, true)
memory.write(0x590AF1, 0x140, 4, true)
end
end

patch()
 
Last edited:

dphome

Well-known member
Joined
Mar 21, 2020
Messages
456
Solutions
9
Reaction score
166
Location
Poland
PROBLEM SOLVED
new_cheats.h
Code:
bool quickLoadPatches();
new_cheats.cpp
Code:
#define patch(a, v, s) _patch((void*)(a), (void*)(v), (s))
void _patch(void*, void*, int);
#define nop(a, s) _nop((void*)(a), (s))
void _nop(void*, int);
bool check(void*, unsigned char, const char*, bool);
bool _check(void*, unsigned char);

bool quickLoadPatches()
{
    unsigned long dwValue;
    //dwValue = 5;
    //patch(0xC8D4C0, &dwValue, 4); // Skip ads

    if (check((void*)0x748C2B, 0xE8, "Legal info fade-in", true)) nop(0x748C2B, 5); // Legal info fade-in
    else if (check((void*)0x748C7B, 0xE8, "Legal info fade-in", true)) nop(0x748C7B, 5); // Legal info fade-in
    dwValue = 1;
    if (check((void*)0x5909AA, 0xBE, "Legal info", true)) patch(0x5909AB, &dwValue, 4); // Legal info
    if (check((void*)0x590A1D, 0xBE, "Legal info fade-out", true))
    {
        dwValue = 0xE9;
        patch(0x590A1D, &dwValue, 1); // Legal info fade-out
        dwValue = 0x0000008D;
        patch(0x590A1E, &dwValue, 4); // Legal info fade-out
    }
    dwValue = 0x75;
    if (check((void*)0x5737E0, 0x74, "Skip confim", true)) patch(0x5737E0, &dwValue, 1); // Skip confim

    if (check((void*)0x590AF0, 0xA1, "Skip loading", true))
    {
        dwValue = 0xE9;
        patch(0x590AF0, &dwValue, 1); // Skip loading
        dwValue = 0x00000140;
        patch(0x590AF1, &dwValue, 4); // Skip loading
    }

    return TRUE;
}

void _patch(void* pAddress, void* pData, int iSize)
{
    unsigned long dwProtect[2];
    VirtualProtect(pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
    memcpy(pAddress, pData, iSize);
}

void _nop(void* pAddress, int iSize)
{
    unsigned long dwProtect[2];
    VirtualProtect(pAddress, iSize, PAGE_EXECUTE_READWRITE, &dwProtect[0]);
    memset(pAddress, 0x90, iSize);
    VirtualProtect(pAddress, iSize, dwProtect[0], &dwProtect[1]);
}

bool check(void* pAddress, unsigned char cByte, const char* sExp, bool bContinue)
{
    if (_check(pAddress, cByte)) return true;
    if (bContinue) return false;
    /*char buf[1024];
    sprintf_s(buf, 1024, "An unknown code found at 0x%08X (%s).\nDo you want to continue without this Function?", pAddress, sExp);
    if (MessageBox(0, buf, "crashes.asi quick connect patches", MB_YESNO | MB_ICONERROR | MB_DEFBUTTON2) == IDNO) ExitProcess(0);*/
    return false;
}

bool _check(void* pAddress, unsigned char cByte)
{
    unsigned long dwProtect[2];
    unsigned char cValue = cByte;
    VirtualProtect(pAddress, 1, PAGE_EXECUTE_READ, &dwProtect[0]);
    memcpy(&cValue, pAddress, 1);
    VirtualProtect(pAddress, 1, dwProtect[0], &dwProtect[1]);
    return (cValue == cByte);
}
main.cpp
Code:
    case DLL_PROCESS_ATTACH:
        DisableThreadLibraryCalls( hModule );
        // windows aero fix for windows 7 and vista
        EnableWindowsAero();
        quickLoadPatches(); //<-----------------------------
        g_hDllModule = hModule;
        OrigExceptionFilter = SetUnhandledExceptionFilter( unhandledExceptionFilter );
        break;
 
Top