Call game function in C++

01/26/2025 20:08 Dupszot22#1
Hi I found function call of pick up items in metin2 and I call it with cheat engine. First I alloc memory then place there code nad create thread. It's work but if i use it will pick up item once. I try call this with DLL but game crash or can i make script in autoassembly that create thread every 1-5 second but I can't find anything.

Code:
#include "pch.h"
#include <Windows.h>
#include <iostream>
#include <stdio.h>

int Main()
{
	DWORD Arg1 = 0x01842824;
	DWORD Arg2 = 0x004A4FF0;
	DWORD Arg3 = 0x005A8BD0;

	__asm
	{
		mov ecx, Arg1 // Arg 1 
		call Arg2 // Arg 2
		jmp Arg3 // Arg3
		ret
	}
}


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		CloseHandle(CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)Main, hModule, 0, nullptr));
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}
01/26/2025 21:22 wolfcfx880#2
1 . Your C++ code doesn't handle any game logics such { Ingame mode , If player is alive etc.. }
this would crash the game surly

2 . Your ASM region ain't complete , might some registers missed { it also crash the app }

3 . Make sure that pointers you got are static not dynamic ones
dynamic ones need to be updated every single log-in

if 0x005A8BD0 is a return to the old original memory
try this

Code:

void DoPickUp()
{
	DWORD Arg1 = 0x01842824;
	DWORD Arg2 = 0x004A4FF0;
//	DWORD Arg3 = 0x005A8BD0;

	__asm
	{
		mov ecx, Arg1 // Arg 1 
		call Arg2 // Arg 2
		jmp DONE
		

		DONE:

	}

}

int Main()
{

				while (true)
				{
				if ( GetAsyncKeyState(VK_F11) &&1)
				{
					DoPickUp();
				}
				Sleep(200);
				}

return 0;
}
01/28/2025 09:26 Dupszot22#3
Quote:
Originally Posted by wolfcfx880 View Post
1 . Your C++ code doesn't handle any game logics such { Ingame mode , If player is alive etc.. }
this would crash the game surly

2 . Your ASM region ain't complete , might some registers missed { it also crash the app }

3 . Make sure that pointers you got are static not dynamic ones
dynamic ones need to be updated every single log-in

if 0x005A8BD0 is a return to the old original memory
try this

Code:



void DoPickUp()
{
	DWORD Arg1 = 0x01842824;
	DWORD Arg2 = 0x004A4FF0;
//	DWORD Arg3 = 0x005A8BD0;

	__asm
	{
		mov ecx, Arg1 // Arg 1 
		call Arg2 // Arg 2
		jmp DONE
		

		DONE:

	}

}

int Main()
{

				while (true)
				{
				if ( GetAsyncKeyState(VK_F11) &&1)
				{
					DoPickUp();
				}
				Sleep(200);
				}

return 0;
}
I tried but it doesn't work. With cheat engine my asm code work. Now I make progress with asm code. This work but I can't turn it off and dont crash game probably because I interrupt the code in progress. I need some check when I turn off script so that it finishes the code up to the call sleep line and then turns off. Is this possible in autoassembler?
Code:
[ENABLE]
// Allocate memory for the code
alloc(code, 512)

// Define the code to execute in a loop
code:
  // Loop start
  loop_start:
    mov ecx, [metin2client.exe+1472824]  // Load value into ecx
    call metin2client.exe+D4FF0          // Call the function
    inc [metin2client.exe+13D8C9C]       // Increment the value at the address
    mov eax, metin2client.exe+13D8C9C    // Move the address into eax
    push 1000                            // Sleep for 1000 milliseconds (1 second)
    call sleep                           // Call the sleep function
    jmp loop_start                       // Jump back to the start of the loop

// Create a thread to execute the code
createthread(code)

[DISABLE]
// Deallocate the memory and stop the thread
dealloc(code)
02/15/2025 17:03 sad666#4
I guess some functions don’t really work well with multi-threading. Maybe try hooking into the main loop or render function instead of creating a thread