Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Autoconnect.cpp - Directly connect to a server upon starting the game.
- Jason Hood, 1 September, 2016.
- Usage:
- Add "-I[server[:password]]" (internet) or "-L[server[:password]]" (LAN)
- to automatically connect to that server. Server may be either the name
- or address; only a prefix is necessary (whatever matches first). If
- password is absent, it will be prompted as usual.
- Install:
- Copy Autoconnect.dll to your EXE directory and add it to the
- [Libraries] section of dacom.ini.
- */
- #include "patch.h"
- #include <string>
- using std::wstring;
- #define ADDR_MENU 0x575360
- #define ADDR_SERVER (0x56FF59+1)
- #define ADDR_PASSWORD ((PDWORD)(0x5721A8+1))
- #define ADDR_INTERNET ((bool*)0x615B10)
- #define ADDR_VERSION ((PDWORD)0x67ECB8)
- wstring server, password;
- struct Connection // partial
- {
- UINT dunno1;
- wchar_t* addr;
- BYTE stuff[16 * 4];
- wchar_t* name;
- BYTE more[16 * 4];
- DWORD version;
- };
- DWORD Menu_Old;
- NAKED
- void Menu_Hook( void )
- {
- __asm {
- mov eax, Menu_Old
- mov ds:[ADDR_MENU], eax // restore the menu
- jmp dword ptr ds:[ADDR_MENU+12] // Multiplayer state
- align 16
- }
- }
- bool FASTCALL SvrTest( const Connection& srvr )
- {
- return (srvr.version == *ADDR_VERSION &&
- (_wcsnicmp( srvr.name, server.c_str(), server.length()) == 0 ||
- _wcsnicmp( srvr.addr, server.c_str(), server.length()) == 0));
- }
- DWORD Server_Old, Server_Org;
- NAKED
- void Server_Hook( void )
- {
- __asm {
- cmp dword ptr [esi+0x114], 1
- je done
- push ecx
- push eax
- mov ecx, eax
- call SvrTest
- test al, al
- pop eax
- pop ecx
- jz done
- mov edx, Server_Org
- mov dword ptr [esi+0x114], 1
- mov ds:[ADDR_SERVER], edx
- mov edx, 0x572100
- push eax
- call edx
- mov edx, 0x571FC0
- mov ecx, esi
- call edx
- ret 8
- done:
- jmp Server_Old
- align 16
- }
- }
- DWORD Password_Old, Password_Org;
- struct vc6wstring
- {
- UINT allocator;
- const wchar_t* ptr;
- size_t len, res;
- };
- bool Password_Hook( UINT, vc6wstring& pwd, UINT, UINT )
- {
- *ADDR_PASSWORD = Password_Org;
- wchar_t* sz = new wchar_t[password.capacity()];
- memcpy_s(sz, password.capacity() * sizeof(wchar_t), password.c_str(), (password.size() + 1) * sizeof(wchar_t));
- pwd.ptr = sz;
- pwd.len = password.size();
- pwd.res = password.capacity();
- return true;
- }
- void Patch()
- {
- ProtectX( (PVOID)ADDR_MENU, 4 );
- ProtectX( (PVOID)ADDR_SERVER, 4 );
- Server_Org = *(PDWORD)ADDR_SERVER;
- NEWABS( (PDWORD)ADDR_MENU, Menu );
- NEWOFS( (PDWORD)ADDR_SERVER, Server );
- if (!password.empty())
- {
- ProtectX( ADDR_PASSWORD, 4 );
- Password_Org = *ADDR_PASSWORD;
- NEWOFS( ADDR_PASSWORD, Password );
- }
- }
- BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
- {
- if (fdwReason == DLL_PROCESS_ATTACH)
- {
- LPCWSTR cmdline = GetCommandLineW();
- while (*cmdline != '\0')
- {
- if (*cmdline == ' ' && cmdline[1] == '-' &&
- (cmdline[2] == 'I' || cmdline[2] == 'L'))
- {
- if (cmdline[2] == 'L')
- *ADDR_INTERNET = false;
- int len = 0;
- cmdline += 3;
- while (cmdline[len] > ' ' && cmdline[len] != ':')
- ++len;
- server.assign( cmdline, len );
- if (cmdline[len] == ':')
- {
- cmdline += len + 1;
- len = 0;
- while (cmdline[len] > ' ')
- ++len;
- password.assign( cmdline, len );
- }
- Patch();
- }
- ++cmdline;
- }
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement