#include "pch.h"
#include <windows.h>
#include <string>
extern "C" void __declspec(dllexport) __stdcall function1()
{
}
namespace {
enum L2ConsoleState {
Loading = 0,
Unknown = 1,
Login = 2,
CharCreate = 3,
CharSelect = 4,
InGame = 5
};
class UL2ConsoleWnd {};
UL2ConsoleWnd* UL2ConsoleWndPtr = nullptr;
uintptr_t consoleOffset = 0x3663bc;
}
class UNetworkHandler {};
typedef int(__fastcall* RequestAuthLoginFn)(UNetworkHandler*, int, const wchar_t*, const wchar_t*, int);
const uintptr_t unetworkOffset = 0x81F538;
UNetworkHandler** unetwork = nullptr;
RequestAuthLoginFn requestAuthLoginFn = nullptr;
static void RequestLogin(const std::wstring& login, const std::wstring& password) {
if (!unetwork || !requestAuthLoginFn) {
return;
}
requestAuthLoginFn(*unetwork, 0, login.c_str(), password.c_str(), 0);
}
static void ReadIniString() {
std::wstring login;
std::wstring password;
wchar_t buffer[256] = { 0 };
GetPrivateProfileStringW(L"AutoLogin", L"Login", L"", buffer, _countof(buffer), L".\\AutoLogin.ini");
login = buffer;
GetPrivateProfileStringW(L"AutoLogin", L"Login", L"", buffer, _countof(buffer), L".\\AutoLogin.ini");
password = buffer;
RequestLogin(login, password);
}
static void L2StatusLoad() {
HMODULE hNwindowModule = nullptr;
while (hNwindowModule == nullptr)
{
hNwindowModule = GetModuleHandleW(L"nwindow.dll");
Sleep(1000);
}
uintptr_t pUL2ConsoleWnd = (reinterpret_cast<uintptr_t>(hNwindowModule)) + consoleOffset;
while (UL2ConsoleWndPtr == nullptr)
{
UL2ConsoleWndPtr = *reinterpret_cast<UL2ConsoleWnd**>(pUL2ConsoleWnd);
Sleep(300);
}
L2ConsoleState* statePtr = reinterpret_cast<L2ConsoleState*>(UL2ConsoleWndPtr + 0x38);
while (true)
{
L2ConsoleState currentState = *statePtr;
switch (currentState)
{
case L2ConsoleState::Loading:
ReadIniString();
exit;
break;
case L2ConsoleState::Login:
break;
case L2ConsoleState::CharCreate:
break;
case L2ConsoleState::CharSelect:
break;
case L2ConsoleState::InGame:
break;
}
Sleep(5000);
}
}
static DWORD WINAPI TestThread(LPVOID lpParameter) {
L2StatusLoad();
return 0;
}
extern "C" __declspec(dllexport)
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hModule);
HMODULE engineModule = GetModuleHandleW(L"engine.dll");
if (engineModule) {
unetwork = reinterpret_cast<UNetworkHandler**>(reinterpret_cast<uintptr_t>(engineModule) + unetworkOffset);
requestAuthLoginFn = (RequestAuthLoginFn)GetProcAddress(engineModule, "?RequestAuthLogin@UNetworkHandler@@UAEHPAG0H@Z");
}
CreateThread(nullptr, 0, TestThread, nullptr, 0, nullptr);
}
return TRUE;
}