예제 #1
0
//////////////////////////////////////////////////////////
//
// HandleIfGTAIsAlreadyRunning
//
// Check for and maybe stop a running GTA process
//
//////////////////////////////////////////////////////////
void HandleIfGTAIsAlreadyRunning( void )
{
    if ( IsGTARunning () )
    {
        if ( MessageBoxUTF8 ( 0, _("An instance of GTA: San Andreas is already running. It needs to be terminated before MTA:SA can be started. Do you want to do that now?"), _("Information")+_E("CL10"), MB_YESNO | MB_ICONQUESTION | MB_TOPMOST ) == IDYES )
        {
            TerminateGTAIfRunning ();
            if ( IsGTARunning () )
            {
                MessageBoxUTF8 ( 0, _("Unable to terminate GTA: San Andreas. If the problem persists, please restart your computer."), _("Information")+_E("CL11"), MB_OK | MB_ICONERROR | MB_TOPMOST );
                return ExitProcess( EXIT_ERROR );
            }       
        }
        else
            return ExitProcess( EXIT_OK );
    }
}
예제 #2
0
//////////////////////////////////////////////////////////
//
// HandleDuplicateLaunching
//
// Handle duplicate launching, or running from mtasa:// URI ?
//
//////////////////////////////////////////////////////////
void HandleDuplicateLaunching( void )
{
    LPSTR lpCmdLine = GetCommandLine();

    int iRecheckTimeLimit = 2000;
    while ( ! CreateSingleInstanceMutex () )
    {
        if ( strcmp ( lpCmdLine, "" ) != 0 )
        {
            HWND hwMTAWindow = FindWindow( NULL, "MTA: San Andreas" );
#ifdef MTA_DEBUG
            if( hwMTAWindow == NULL )
                hwMTAWindow = FindWindow( NULL, "MTA: San Andreas [DEBUG]" );
#endif
            if( hwMTAWindow != NULL )
            {
                LPWSTR szCommandLine = GetCommandLineW ();
                int numArgs;
                LPWSTR* aCommandLineArgs = CommandLineToArgvW ( szCommandLine, &numArgs );
                for ( int i = 0; i < numArgs; ++i )
                {
                    if ( StrCmpW ( aCommandLineArgs[i], L"-c" ) == 0 && numArgs > i )
                    {
                        WString wideConnectInfo = aCommandLineArgs[i + 1];
                        SString strConnectInfo = ToUTF8 ( wideConnectInfo );

                        COPYDATASTRUCT cdStruct;
                        cdStruct.cbData = strConnectInfo.length () + 1;
                        cdStruct.lpData = const_cast<char *> ( strConnectInfo.c_str () );
                        cdStruct.dwData = URI_CONNECT;

                        SendMessage( hwMTAWindow, WM_COPYDATA, NULL, (LPARAM)&cdStruct );
                        break;
                    }
                }

                
            }
            else
            {
                if ( iRecheckTimeLimit > 0 )
                {
                    // Sleep a little bit and check the mutex again
                    Sleep ( 500 );
                    iRecheckTimeLimit -= 500;
                    continue;
                }
                SString strMessage;
                strMessage += _(    "Trouble restarting MTA:SA\n\n"
                                    "If the problem persists, open Task Manager and\n"
                                    "stop the 'gta_sa.exe' and 'Multi Theft Auto.exe' processes\n\n\n"
                                    "Try to launch MTA:SA again?" );
                if ( MessageBoxUTF8( 0, strMessage, _("Error")+_E("CL04"), MB_ICONWARNING | MB_YESNO | MB_TOPMOST  ) == IDYES ) // Trouble restarting MTA:SA
                {
                    TerminateGTAIfRunning ();
                    TerminateOtherMTAIfRunning ();
                    ShellExecuteNonBlocking( "open", PathJoin ( GetMTASAPath (), MTA_EXE_NAME ), lpCmdLine );
                }
                return ExitProcess( EXIT_ERROR );
            }
        }
        else
        {
            if ( !IsGTARunning () && !IsOtherMTARunning () )
            {
                MessageBoxUTF8 ( 0, _("Another instance of MTA is already running.\n\nIf this problem persists, please restart your computer"), _("Error")+_E("CL05"), MB_ICONERROR | MB_TOPMOST  );
            }
            else
            if ( MessageBoxUTF8( 0, _("Another instance of MTA is already running.\n\nDo you want to terminate it?"), _("Error")+_E("CL06"), MB_ICONQUESTION | MB_YESNO | MB_TOPMOST  ) == IDYES )
            {
                TerminateGTAIfRunning ();
                TerminateOtherMTAIfRunning ();
                ShellExecuteNonBlocking( "open", PathJoin ( GetMTASAPath (), MTA_EXE_NAME ), lpCmdLine );
            }
        }
        return ExitProcess( EXIT_ERROR );
    }
}
예제 #3
0
void CLauncherDlg::OnLaunch() 
{
	char szParams[1024];
	char szNick[32];
	char szServerIP[128];
	char szPort[32];
	char szPassword[32];

	// Get the nick box text
	GetDlgItemText(IDC_NICK, szNick, sizeof(szNick));
	
	// Get the ip box text
	GetDlgItemText(IDC_SERVER_IP, szServerIP, sizeof(szServerIP));
	
	// Get the port box text
	GetDlgItemText(IDC_PORT, szPort, sizeof(szPort));

	// Get the password box text
	GetDlgItemText(IDC_SERVER_PASSWORD, szPassword, sizeof(szPassword));

	// Try to open the VCMP registry key
	HKEY hKey = 0;
	RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\VICEP",0,KEY_WRITE,&hKey);

	// If the key doesn't exist create it
	if(!hKey) {
		RegCreateKey(HKEY_LOCAL_MACHINE,"Software\\VICEP",&hKey);
	}
	
	if(hKey) {
		// Set the registry key size and type
		DWORD dwSize = sizeof(szNick);
		DWORD dwType = REG_SZ;

		// Save the registry key
		RegSetValueEx(hKey, "nick", 0, dwType, (PUCHAR)szNick, dwSize);

		// Set the registry key size and type
		dwSize = sizeof(szServerIP);
		dwType = REG_SZ;

		// Save the registry key
		RegSetValueEx(hKey, "server", 0, dwType, (PUCHAR)szServerIP, dwSize);

		// Set the registry key size and type
		dwSize = sizeof(szPort);
		dwType = REG_SZ;

		// Save the registry key
		RegSetValueEx(hKey, "port", 0, dwType, (PUCHAR)szPort, dwSize);

		// Close the registry key
		RegCloseKey(hKey);
	}

	// Format the command line
	sprintf(szParams,"\"gta-vc.exe\" -c -h %s -p %s -n %s",szServerIP,szPort,szNick);

	// If we have a password add it to the command line
	if(strlen(szPassword) > 0) {
		strcat(szParams," -z ");
		strcat(szParams,szPassword);
	}

	// If the windowed checkbox is checked add a '-w' to the command line
	if(m_windowedCheckBox.GetCheck()) {
		strcat(szParams, " -w ");
	}

	// Get the library path
	char szLibraryPath[1024];
	sprintf(szLibraryPath, "%s" CLIENT_DLL, GetAppPath());

	// Check if Client(_d).dll exists
	WIN32_FIND_DATA fdFileInfo;
	if(FindFirstFile(szLibraryPath, &fdFileInfo) == INVALID_HANDLE_VALUE) {
		MessageBox("Couldn't find " CLIENT_DLL ".");
		return;
	}

	// Get the gta exe path
	char szGtaExe[1024];
	sprintf(szGtaExe, "%sgta-vc.exe", GetAppPath());

	// Start gta-vc.exe
	STARTUPINFO siStartupInfo;
	PROCESS_INFORMATION piProcessInfo;
	memset(&siStartupInfo, 0, sizeof(siStartupInfo));
	memset(&piProcessInfo, 0, sizeof(piProcessInfo));
	siStartupInfo.cb = sizeof(siStartupInfo);
	if(!CreateProcess(szGtaExe, szParams, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, GetAppPath(), &siStartupInfo, 
		&piProcessInfo)) {
		MessageBox("Couldn't launch gta-vc.exe.\nDid you install Vice City: Players to your Vice City directory?");
		return;
	}

	if ( !TerminateGTAIfRunning () )
    {
		MessageBox ("Vice City Players could not start because an another instance of GTA: Vice City is running.", "Error", MB_ICONERROR );
        return;
    }

	// Inject our code into LaunchGTAIV.exe
	if(!InjectLibraryIntoProcess(piProcessInfo.hProcess, szLibraryPath)) {
		TerminateProcess(piProcessInfo.hProcess, 0);
		MessageBox("Couldn't inject " CLIENT_DLL ".");
		return;
	}

	// Resume the gta-vc.exe thread
	ResumeThread(piProcessInfo.hThread);
}