From a48e21ea649d7ed9adfdb4c0031f292b45bbe2a7 Mon Sep 17 00:00:00 2001 From: ccw808 Date: Tue, 19 Sep 2017 02:42:42 +0100 Subject: [PATCH] Added workaround for configuration issues --- Client/loader/MainFunctions.cpp | 11 +++++++---- Client/loader/Utils.cpp | 23 +++++++++++++---------- Client/loader/Utils.h | 1 + 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Client/loader/MainFunctions.cpp b/Client/loader/MainFunctions.cpp index d57467d6b4..06c16a63fa 100644 --- a/Client/loader/MainFunctions.cpp +++ b/Client/loader/MainFunctions.cpp @@ -1094,7 +1094,11 @@ int LaunchGame ( SString strCmdLine ) SString strMtaDir = PathJoin( strMTASAPath, "mta" ); SetDllDirectory( strMtaDir ); - CheckService ( CHECK_SERVICE_PRE_CREATE ); + if (!CheckService(CHECK_SERVICE_PRE_CREATE) && !IsUserAdmin()) + { + RelaunchAsAdmin(strCmdLine, _("Fix configuration issue")); + ExitProcess(EXIT_OK); + } // Do some D3D things BeginD3DStuff(); @@ -1143,9 +1147,8 @@ int LaunchGame ( SString strCmdLine ) if ( dwError == ERROR_ELEVATION_REQUIRED && !bDoneAdmin ) { // Try to relaunch as admin if not done so already - ReleaseSingleInstanceMutex (); - ShellExecuteNonBlocking( "runas", PathJoin ( strMTASAPath, MTA_EXE_NAME ), strCmdLine + " /done-admin" ); - return 5; + RelaunchAsAdmin(strCmdLine + " /done-admin", _("Fix elevation required error")); + ExitProcess(EXIT_OK); } else { diff --git a/Client/loader/Utils.cpp b/Client/loader/Utils.cpp index 661c057093..eb39a66815 100644 --- a/Client/loader/Utils.cpp +++ b/Client/loader/Utils.cpp @@ -1250,17 +1250,20 @@ Return Value: } -static SString HashBuffer ( char* pData, uint uiLength ) +////////////////////////////////////////////////////////// +// +// RelaunchAsAdmin +// +// Relaunch as admin if user agrees +// +////////////////////////////////////////////////////////// +void RelaunchAsAdmin(const SString& strCmdLine, const SString& strReason) { - DWORD dwSum1 = 0; - DWORD dwSum2 = 0x1234; - for ( uint i = 0 ; i < uiLength ; i++ ) - { - dwSum1 += pData[i]; - dwSum2 += pData[i]; - dwSum2 ^= ( dwSum2 << 2 ) + 0x93; - } - return SString ( "%08x%08x%08x", dwSum1, dwSum2, uiLength ); + HideSplash(); + AddReportLog(7115, SString("Loader - Request to elevate privilages (%s)", *strReason)); + MessageBoxUTF8(NULL, SString ( _("MTA:SA needs Administrator access for the following task:\n\n '%s'\n\nPlease confirm in the next window."), *strReason), "Multi Theft Auto: San Andreas", MB_OK | MB_ICONINFORMATION | MB_TOPMOST); + ReleaseSingleInstanceMutex(); + ShellExecuteNonBlocking("runas", PathJoin(GetMTASAPath(), MTA_EXE_NAME), strCmdLine); } diff --git a/Client/loader/Utils.h b/Client/loader/Utils.h index 1963d86bc7..42b92689c9 100644 --- a/Client/loader/Utils.h +++ b/Client/loader/Utils.h @@ -96,6 +96,7 @@ bool IsWindows10OrGreater ( void ); bool IsWindows10Threshold2OrGreater ( void ); BOOL IsUserAdmin ( void ); +void RelaunchAsAdmin (const SString& strCmdLine, const SString& strReason); void UpdateMTAVersionApplicationSetting ( bool bQuiet = false ); bool Is32bitProcess ( DWORD processID );