#include <Windows.h>
#include <atomic>
#include <thread>
uintptr_t moduleBase = (uintptr_t)GetModuleHandleA("metin2client.exe");
std::atomic<bool> runTarget{ false };
std::atomic<bool> stopHotkeyThread{ false };
HANDLE hTargetThread = nullptr;
bool SendBattleAttack(int vId)
{
// NetPointer: metin2client.exe+2aaef74
DWORD NetPointer = *(DWORD*)(moduleBase + 0x2AAEF74);
// BattleCall: metin2client.exe+22e7300
DWORD BattleCall = moduleBase + 0x22E7300;
__asm
{
mov ecx, NetPointer
push vId
push 0
call BattleCall
}
return 0;
}
void Target()
{
while (runTarget)
{
// GetTargetVID: metin2client.exe+2AAF1B8 + 0x34A50
DWORD GetTargetVID = (*(DWORD*)(*(DWORD*)(moduleBase + 0x2AAF1B8) + 0x34A50));
SendBattleAttack(GetTargetVID);
Sleep(30);
}
}
DWORD WINAPI HotkeyThread(LPVOID lpParam)
{
HMODULE hModule = (HMODULE)lpParam;
while (!stopHotkeyThread)
{
if (GetAsyncKeyState(VK_F2) & 1)
{
if (!runTarget)
{
runTarget = true;
hTargetThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Target, NULL, 0, NULL);
}
}
if (GetAsyncKeyState(VK_F3) & 1)
{
runTarget = false;
stopHotkeyThread = true;
if (hTargetThread)
{
WaitForSingleObject(hTargetThread, 1000);
CloseHandle(hTargetThread);
}
FreeLibraryAndExitThread(hModule, 0);
}
Sleep(50);
}
return 0;
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DisableThreadLibraryCalls(hModule);
CreateThread(NULL, 0, HotkeyThread, hModule, 0, NULL);
break;
}
return TRUE;
}