//--- Includes -----------------------------------------------------------------
#include <windows.h>
#include <fstream>
#include <stdio.h>
using namespace std;
//--- Globals ------------------------------------------------------------------
#define ID_EDIT_WCPATH 1000
#define ID_EDIT_NICK 1001
#define ID_EDIT_PASS 1002
#define ID_EDIT_CHAN 1003
#define ID_BUTTON_SETUP 1004
#define ID_BUTTON_CANCEL 1005
char szAppName[ ] = "WC3 AutoLogIn Setup";
char szAppTitle[ ] = "WC3 Autologin setup";
//--- Prototypes ---------------------------------------------------------------
LRESULT CALLBACK WinProc( HWND, UINT, WPARAM, LPARAM );
HWND doCreateChild( HWND, char *, char *, DWORD, DWORD, int, HINSTANCE );
void saveUserData( HWND, HWND, HWND, HWND );
bool loadUserData( HWND, HWND, HWND, HWND );
void decoder( char *, int );
void encoder( char *, int );
//--- Main ---------------------------------------------------------------------
WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) {
HWND hWnd;
WNDCLASS wc;
MSG msg;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon( 0, IDI_APPLICATION );
wc.hCursor = LoadCursor( 0, IDC_ARROW );
wc.hbrBackground = (HBRUSH) GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = 0;
wc.lpszClassName = szAppName;
if( !( RegisterClass( &wc ) ) ) {
MessageBox( 0, "Couldn't register window!", "Shutdown error!", MB_OK | MB_ICONERROR );
return 0;
}
hWnd = CreateWindowEx( WS_EX_TOOLWINDOW,
szAppName, szAppTitle,
WS_SYSMENU,
CW_USEDEFAULT, CW_USEDEFAULT, 300, 300,
0,
0,
hInstance,
0 );
if( !hWnd ) {
MessageBox( 0, "Couldn't create window!", "Shutdown error!", MB_OK | MB_ICONERROR );
return 0;
}
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
while( GetMessage( &msg, 0, 0, 0 ) ) {
if( IsDialogMessage( hWnd, &msg ) ) {
}
else {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
return( msg.wParam );
}
//--- Definitions --------------------------------------------------------------
LRESULT CALLBACK WinProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam ) {
HINSTANCE hInst;
static HWND hEdit1, hEdit2, hEdit3, hEdit4;
static HWND hButton1, hButton2;
static bool isFilled[ 4 ];
switch( message ) {
case WM_CREATE: {
hInst = ( ( LPCREATESTRUCT )lParam )->hInstance;
hEdit1 = doCreateChild( hWnd, "EDIT", "C:\\Programme\\Warcraft III\\Frozen Throne.exe", WS_EX_CLIENTEDGE, ES_AUTOHSCROLL | WS_TABSTOP, ID_EDIT_WCPATH, hInst );
hEdit2 = doCreateChild( hWnd, "EDIT", 0, WS_EX_CLIENTEDGE, WS_TABSTOP, ID_EDIT_NICK, hInst );
hEdit3 = doCreateChild( hWnd, "EDIT", 0, WS_EX_CLIENTEDGE, ES_PASSWORD | WS_TABSTOP, ID_EDIT_PASS, hInst );
hEdit4 = doCreateChild( hWnd, "EDIT", "Frozen Throne Deu-1", WS_EX_CLIENTEDGE, ES_AUTOHSCROLL | WS_TABSTOP, ID_EDIT_CHAN, hInst );
hButton1 = doCreateChild( hWnd, "BUTTON", "Setup!", 0, WS_TABSTOP, ID_BUTTON_SETUP, hInst );
hButton2 = doCreateChild( hWnd, "BUTTON", "Cancel", 0, WS_TABSTOP, ID_BUTTON_CANCEL, hInst );
SendMessage( hEdit2, EM_SETLIMITTEXT, 15, 0 );
SendMessage( hEdit3, EM_SETLIMITTEXT, 15, 0 );
SendMessage( hEdit3, EM_SETPASSWORDCHAR, (WPARAM)'#', 0 );
if( loadUserData( hEdit1, hEdit2, hEdit3, hEdit4 ) ) {
}
else {
for( int i = 0; i < 4; i++ ) {
isFilled[ i ] = false;
}
isFilled[ 0 ] = true;
isFilled[ 3 ] = true;
EnableWindow( hButton1, false );
SetFocus( hEdit2 );
}
return 0;
}
case WM_SIZE: {
MoveWindow( hEdit1, 10, 30, 275, 20, true );
MoveWindow( hEdit2, 10, 80, 150, 20, true );
MoveWindow( hEdit3, 10, 130, 150, 20, true );
MoveWindow( hEdit4, 10, 180, 275, 20, true );
MoveWindow( hButton1, 10, 230, 120, 30, true );
MoveWindow( hButton2, 165, 230, 120, 30, true );
return 0;
}
case WM_COMMAND: {
switch( LOWORD( wParam ) ) {
case ID_EDIT_WCPATH: {
switch( HIWORD( wParam ) ) {
case EN_UPDATE: {
if( ( SendMessage( hEdit1, WM_GETTEXTLENGTH, 0, 0 ) ) == 0 ) {
isFilled[ 0 ] = false;
EnableWindow( hButton1, false );
}
else {
isFilled[ 0 ] = true;
if( isFilled[ 0 ] && isFilled[ 1 ] && isFilled[ 2 ] && isFilled[ 3 ] ) {
EnableWindow( hButton1, true );
}
}
break;
}
}
break;
}
case ID_EDIT_NICK: {
switch( HIWORD( wParam ) ) {
case EN_UPDATE: {
if( ( SendMessage( hEdit2, WM_GETTEXTLENGTH, 0, 0 ) ) == 0 ) {
isFilled[ 1 ] = false;
EnableWindow( hButton1, false );
}
else {
isFilled[ 1 ] = true;
if( isFilled[ 0 ] && isFilled[ 1 ] && isFilled[ 2 ] && isFilled[ 3 ] ) {
EnableWindow( hButton1, true );
}
}
break;
}
}
break;
}
case ID_EDIT_PASS: {
switch( HIWORD( wParam ) ) {
case EN_UPDATE: {
if( ( SendMessage( hEdit3, WM_GETTEXTLENGTH, 0, 0 ) ) == 0 ) {
isFilled[ 2 ] = false;
EnableWindow( hButton1, false );
}
else {
isFilled[ 2 ] = true;
if( isFilled[ 0 ] && isFilled[ 1 ] && isFilled[ 2 ] && isFilled[ 3 ] ) {
EnableWindow( hButton1, true );
}
}
break;
}
}
break;
}
case ID_EDIT_CHAN: {
switch( HIWORD( wParam ) ) {
case EN_UPDATE: {
if( ( SendMessage( hEdit4, WM_GETTEXTLENGTH, 0, 0 ) ) == 0 ) {
isFilled[ 3 ] = false;
EnableWindow( hButton1, false );
}
else {
isFilled[ 3 ] = true;
if( isFilled[ 0 ] && isFilled[ 1 ] && isFilled[ 2 ] && isFilled[ 3 ] ) {
EnableWindow( hButton1, true );
}
}
break;
}
}
break;
}
case ID_BUTTON_SETUP: {
switch( HIWORD( wParam ) ) {
case BN_CLICKED: {
saveUserData( hEdit1, hEdit2, hEdit3, hEdit4 );
if( ( MessageBox( 0, "Do You want start \"AutoLogin\" now?", "Run it now?", MB_OKCANCEL | MB_ICONINFORMATION ) ) == IDOK ) {
ShellExecute( 0, "open", "AutoLogin.exe", 0, 0, SW_SHOWDEFAULT );
SendMessage( hWnd, WM_CLOSE, 0, 0 );
}
else {
SendMessage( hWnd, WM_CLOSE, 0, 0 );
}
break;
}
}
break;
}
case ID_BUTTON_CANCEL: {
switch( HIWORD( wParam ) ) {
case BN_CLICKED: {
SendMessage( hWnd, WM_CLOSE, 0, 0 );
break;
}
}
break;
}
}
return 0;
}
case WM_PAINT: {
HDC hDC;
PAINTSTRUCT ps;
hDC = BeginPaint( hWnd, &ps );
SetBkColor( hDC, TRANSPARENT );
SetTextColor( hDC, RGB( 255, 180, 0 ) );
TextOut( hDC, 10, 12, "Wc3 fullpath + exception name:", 30 );
TextOut( hDC, 10, 62, "Account-Name:", 13 );
TextOut( hDC, 10, 112, "Password:", 9 );
TextOut( hDC, 10, 162, "Favorite channel you want join:", 31 );
SetTextColor( hDC, RGB( 255, 0, 0 ) );
TextOut( hDC, 180, 80, "(max. 16 letters)", 17 );
TextOut( hDC, 180, 131, "(max. 16 letters)", 17 );
EndPaint( hWnd, &ps );
return 0;
}
case WM_DESTROY: {
PostQuitMessage( 0 );
return 0;
}
}
return( DefWindowProc( hWnd, message, wParam, lParam ) );
}
HWND doCreateChild( HWND hParent, char *szClassName, char *szTitle, DWORD exStyle, DWORD Style, int ID, HINSTANCE hInst ) {
HWND hChild = CreateWindowEx( exStyle,
szClassName, szTitle,
WS_CHILD | WS_VISIBLE |Style,
0, 0, 0, 0,
hParent,
(HMENU)ID,
hInst,
0 );
return( (HWND) hChild );
}
void saveUserData( HWND hEdit1, HWND hEdit2, HWND hEdit3, HWND hEdit4 ) {
char szBufferThis[ 256 ];
char szBufferPath[ 256 ];
char szBufferNick[ 17 ];
char szBufferPass[ 16 ];
char szBufferChan[ 128 ];
// ***** empty all strings *****
szBufferThis[ 0 ] = 0;
szBufferPath[ 0 ] = 0;
szBufferNick[ 0 ] = 0;
szBufferPass[ 0 ] = 0;
szBufferChan[ 0 ] = 0;
// ***** get current dic ( fullpath ) *****
GetCurrentDirectory( sizeof( szBufferThis ), szBufferThis );
// ***** fix up a bug ( '\' to '/' ) *****
for( int i = 0; i < (int)strlen( szBufferThis ); i++ ) {
if( szBufferThis[ i ] == '\\' ) {
szBufferThis[ i ] = '/';
}
}
// ***** insert ini file name to fullpath *****
strcat( szBufferThis, "/userdata.ini" );
// ***** now get all necessary informations from edits *****
SendMessage( hEdit1,
WM_GETTEXT,
(int)( SendMessage( hEdit1, WM_GETTEXTLENGTH, 0, 0 ) + 1 ),
(long)szBufferPath );
SendMessage( hEdit2,
WM_GETTEXT,
(int)( SendMessage( hEdit2, WM_GETTEXTLENGTH, 0, 0 ) + 1 ),
(long)szBufferNick );
SendMessage( hEdit3,
WM_GETTEXT,
(int)( SendMessage( hEdit3, WM_GETTEXTLENGTH, 0, 0 ) + 1 ),
(long)szBufferPass );
SendMessage( hEdit4,
WM_GETTEXT,
(int)( SendMessage( hEdit4, WM_GETTEXTLENGTH, 0, 0 ) + 1 ),
(long)szBufferChan );
// ***** proof nick and mark nick that autologin has to to wirte him *****
char szBuffer[ 17 ];
szBuffer[ 0 ] = 0;
GetPrivateProfileString( "ACCOUNT", "Nickname", "Error!", szBuffer, sizeof( szBuffer ), szBufferThis );
encoder( szBuffer, 3 );
// ***** nickname is not the same *****
if( ( strcmp( szBuffer, szBufferNick ) ) != 0 ) {
if( ( (int)strlen( szBuffer ) ) != 0 ) {
strcat( szBufferNick, "X" );
}
}
// ***** now we can create the ini file with all informations *****
WritePrivateProfileString( "WC3PATH", "Fullpath", szBufferPath, szBufferThis );
decoder( szBufferNick, 3 );
WritePrivateProfileString( "ACCOUNT", "Nickname", szBufferNick, szBufferThis );
decoder( szBufferPass, 7 );
WritePrivateProfileString( "ACCOUNT", "Password", szBufferPass, szBufferThis );
WritePrivateProfileString( "CHANNEL", "Channel", szBufferChan, szBufferThis );
}
bool loadUserData( HWND hEdit1, HWND hEdit2, HWND hEdit3, HWND hEdit4 ) {
// ***** proof whether the file exist *****
ifstream file;
file.open( "userdata.ini", ios::in );
if( !( file.good( ) ) ) {
// ***** if not?, close and quit here *****
file.close( );
return false;
}
// ***** else load all data *****
char szBufferThis[ 256 ];
char szBufferPath[ 256 ];
char szBufferNick[ 17 ];
char szBufferPass[ 16 ];
char szBufferChan[ 128 ];
// ***** empty all strings *****
szBufferThis[ 0 ] = 0;
szBufferPath[ 0 ] = 0;
szBufferNick[ 0 ] = 0;
szBufferPass[ 0 ] = 0;
szBufferChan[ 0 ] = 0;
// ***** get current dic ( fullpath ) *****
GetCurrentDirectory( sizeof( szBufferThis ), szBufferThis );
// ***** fix up a bug ( '\' to '/' ) *****
for( int i = 0; i < (int)strlen( szBufferThis ); i++ ) {
if( szBufferThis[ i ] == '\\' ) {
szBufferThis[ i ] = '/';
}
}
// ***** insert ini file name to fullpath *****
strcat( szBufferThis, "/userdata.ini" );
// ***** now we can proof if the ini file exist and read all informations *****
GetPrivateProfileString( "WC3PATH", "Fullpath", "Error!", szBufferPath, sizeof( szBufferPath ), szBufferThis );
GetPrivateProfileString( "ACCOUNT", "Nickname", "Error!", szBufferNick, sizeof( szBufferNick ), szBufferThis );
GetPrivateProfileString( "ACCOUNT", "Password", "Error!", szBufferPass, sizeof( szBufferPass ), szBufferThis );
GetPrivateProfileString( "CHANNEL", "Channel", "Error!", szBufferChan, sizeof( szBufferChan ), szBufferThis );
encoder( szBufferNick, 3 );
encoder( szBufferPass, 7 );
// ***** if nick is marked remove last char ( 'X' ) *****
int i = (int)strlen( szBufferNick );
if( ( szBufferNick[ i -1 ] ) == 'X' ) {
szBufferNick[ i - 1 ] = '\0';
}
// ***** now set all necessary informations from edits *****
SendMessage( hEdit1, WM_SETTEXT, 0, (long)szBufferPath );
SendMessage( hEdit2, WM_SETTEXT, 0, (long)szBufferNick );
SendMessage( hEdit3, WM_SETTEXT, 0, (long)szBufferPass );
SendMessage( hEdit4, WM_SETTEXT, 0, (long)szBufferChan );
// ***** now its done *****
return true;
}
// decode an array before it will saved *****
void decoder( char * szBuffer, int key ) {
int iLength = (int)strlen( szBuffer );
// ***** +( key * i ) *****
for( int i = 0; i < iLength; i++ ) {
szBuffer[ i ] += ( key * i );
}
}
// encode an array before it will loaded *****
void encoder( char * szBuffer, int key ) {
int iLength = (int)strlen( szBuffer );
// ***** -( key * i ) *****
for( int i = 0; i < iLength; i++ ) {
szBuffer[ i ] -= ( key * i );
}
}
//--- EXIT ---------------------------------------------------------------------