Esempio n. 1
0
////////////////////////////////////////////////////
//
//  CNewsBrowser::SetVisible
//
//
//
////////////////////////////////////////////////////
void CNewsBrowser::SetVisible(bool bVisible)
{
    if (!bVisible && !m_pWindow)
        return;

    // HACK: Recreate GUI if left shift held (for editing)
    if ((GetAsyncKeyState(VK_LSHIFT) & 0x8000) != 0)
    {
        DestroyGUI();
        CreateGUI();
    }

    if (!m_pWindow)
        CreateGUI();

    // Hide / show the form
    m_pWindow->SetVisible(bVisible);

    if (bVisible)
    {
        // Bring it all forward
        m_pWindow->Activate();
        m_pWindow->SetAlwaysOnTop(true);
        m_pWindow->BringToFront();
        if (GetApplicationSettingInt("news-updated") == 1)
        {
            SetApplicationSettingInt("news-updated", 0);
            CreateHeadlines();
        }
    }
}
Esempio n. 2
0
//////////////////////////////////////////////////////////
//
// UpdatePatchStatusTimestamp
//
// Change the link timestamp in gta_sa.exe to trick windows 7 into using aero
//
//////////////////////////////////////////////////////////
EPatchResult UpdatePatchStatusTimestamp( const SString& strGTAEXEPath, EPatchMode mode )
{
    // Get the top byte of the file link timestamp
    uchar ucTimeStamp = 0;
    FILE* fh = fopen ( strGTAEXEPath, "rb" );
    if ( fh )
    {
        if ( !fseek ( fh, 0x8B, SEEK_SET ) )
        {
            if ( fread ( &ucTimeStamp, sizeof ( ucTimeStamp ), 1, fh ) != 1 )
            {
                ucTimeStamp = 0;
            }
        }
        fclose ( fh );
    }

    const uchar AERO_DISABLED = 0x42;
    const uchar AERO_ENABLED  = 0x43;

    // Return status if just checking
    if ( mode == PATCH_CHECK )
    {
        if ( ucTimeStamp == AERO_ENABLED )
            return PATCH_CHECK_RESULT_ON;
        return PATCH_CHECK_RESULT_OFF;
    }

    // Check it's a value we're expecting
    bool bCanChangeAeroSetting = ( ucTimeStamp == AERO_DISABLED || ucTimeStamp == AERO_ENABLED );
    SetApplicationSettingInt ( "aero-changeable", bCanChangeAeroSetting );

    if ( bCanChangeAeroSetting )
    {
        // Get option to set
        bool bAeroEnabled = ( mode == PATCH_SET_ON );
        uchar ucTimeStampRequired = bAeroEnabled ? AERO_ENABLED : AERO_DISABLED;
        if ( ucTimeStamp != ucTimeStampRequired )
        {
            // Change needed!
            SetFileAttributes ( strGTAEXEPath, FILE_ATTRIBUTE_NORMAL );
            FILE* fh = fopen ( strGTAEXEPath, "r+b" );
            if ( !fh )
            {
                return PATCH_SET_RESULT_REQ_ADMIN;
            }
            if ( !fseek ( fh, 0x8B, SEEK_SET ) )
            {
                fwrite ( &ucTimeStampRequired, sizeof ( ucTimeStampRequired ), 1, fh );
            }
            fclose ( fh );
        }
    }
    return PATCH_SET_RESULT_OK;
}
Esempio n. 3
0
//////////////////////////////////////////////////////////
//
// CInstallManager::_InstallNewsItems
//
//
//
//////////////////////////////////////////////////////////
SString CInstallManager::_InstallNewsItems ( void )
{
    // Get install news queue
    CArgMap queue;
    queue.SetFromString ( GetApplicationSetting ( "news-install" ) );
    SetApplicationSetting ( "news-install", "" );

    std::vector < SString > keyList;
    queue.GetKeys ( keyList );
    for ( uint i = 0 ; i < keyList.size () ; i++ )
    {
        // Install each file
        SString strDate = keyList[i];
        SString strFileLocation = queue.Get ( strDate );

        // Save cwd
        SString strSavedDir = GetSystemCurrentDirectory ();

        // Calc and make target dir
        SString strTargetDir = PathJoin ( GetMTADataPath (), "news", strDate );
        MkDir ( strTargetDir );

        // Extract into target dir
        SetCurrentDirectory ( strTargetDir );

        // Try to extract the files
        if ( !ExtractFiles ( strFileLocation ) )
        {
            // If extract failed and update file is an exe, try to run it
            if ( ExtractExtension ( strFileLocation ).CompareI ( "exe" ) )
                ShellExecuteBlocking ( "open", strFileLocation, "-s" );
        }

        // Restore cwd
        SetCurrentDirectory ( strSavedDir );

        // Check result
        if ( FileExists ( PathJoin ( strTargetDir, "files.xml" ) ) )
        {
            SetApplicationSettingInt ( "news-updated", 1 );
            AddReportLog ( 2051, SString ( "InstallNewsItems ok for '%s'", *strDate ) );
        }
        else
        {
            AddReportLog ( 4048, SString ( "InstallNewsItems failed with '%s' '%s' '%s'", *strDate, *strFileLocation, *strTargetDir ) );
        }
    }
    return "ok";
}
Esempio n. 4
0
///////////////////////////////////////////////////////////////
//
// CVideoModeManager::LoadCVars
//
// Loads to current
//
///////////////////////////////////////////////////////////////
void CVideoModeManager::LoadCVars ( void )
{
    // Upgrade display_alttab_handler
    bool bAltTabHandlerWasEnabled = CVARS_GET_VALUE < bool > ( "display_alttab_handler" );
    int iFullscreenStyle = CVARS_GET_VALUE < int > ( "display_fullscreen_style" );
    if ( bAltTabHandlerWasEnabled && iFullscreenStyle == 0 )
    {
        CVARS_SET ( "display_alttab_handler", false );
        CVARS_SET ( "display_fullscreen_style", FULLSCREEN_BORDERLESS );
    }

    // Apply override
    if ( GetApplicationSettingInt( "nvhacks", "optimus-force-windowed" ) )
    {
        SetApplicationSettingInt( "nvhacks", "optimus-force-windowed", 0 );
        CVARS_SET ( "display_windowed", true );
    }

    m_iCurrentVideoMode = m_pGameSettings->GetCurrentVideoMode ();
    CVARS_GET ( "display_windowed",             m_bCurrentWindowed );
    CVARS_GET ( "display_fullscreen_style",     m_iCurrentFullscreenStyle );
    CVARS_GET ( "multimon_fullscreen_minimize", m_bCurrentFullScreenMinimize );
}
Esempio n. 5
0
////////////////////////////////////////////////
//
// HandleCreateDeviceResult
//
// Log result and possibly fix everything
//
////////////////////////////////////////////////
HRESULT HandleCreateDeviceResult(HRESULT hResult, IDirect3D9* pDirect3D, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags,
                                 D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface)
{
    // Log graphic card name
    D3DADAPTER_IDENTIFIER9 AdapterIdent;
    pDirect3D->GetAdapterIdentifier(Adapter, 0, &AdapterIdent);
    WriteDebugEvent(ToString(AdapterIdent));

    uint uiCurrentStatus = 0;            //  0-unknown  1-fail  2-success after retry  3-success

    if (hResult == D3D_OK)
    {
        // Log success and creation parameters
        WriteDebugEvent("CreateDevice success");
        uiCurrentStatus = CREATE_DEVICE_SUCCESS;
        WriteDebugEvent(ToString(Adapter, DeviceType, hFocusWindow, BehaviorFlags, *pPresentationParameters));
    }

    if (hResult != D3D_OK)
    {
        // Handle failure of initial create device call
        WriteDebugEvent(SString("CreateDevice failed #0: %08x", hResult));

        // Try create device again
        hResult = DoCreateDevice(pDirect3D, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface);

        // Handle retry result
        if (hResult != D3D_OK)
        {
            WriteDebugEvent("--CreateDevice failed after retry");
            uiCurrentStatus = CREATE_DEVICE_FAIL;
        }
        else
        {
            WriteDebugEvent("++CreateDevice succeeded after retry");
            uiCurrentStatus = CREATE_DEVICE_RETRY_SUCCESS;

            // Apply input hook
            CMessageLoopHook::GetSingleton().ApplyHook(hFocusWindow);

            GetVideoModeManager()->PostCreateDevice(*ppReturnedDeviceInterface, pPresentationParameters);

            // We must first store the presentation values.
            CDirect3DData::GetSingleton().StoreViewport(0, 0, pPresentationParameters->BackBufferWidth, pPresentationParameters->BackBufferHeight);

            // Calc and store readable depth format for shader use
            ERenderFormat ReadableDepthFormat = CDirect3DEvents9::DiscoverReadableDepthFormat(
                *ppReturnedDeviceInterface, pPresentationParameters->MultiSampleType, pPresentationParameters->Windowed != 0);
            CGraphics::GetSingleton().GetRenderItemManager()->SetDepthBufferFormat(ReadableDepthFormat);

            // Now create the proxy device.
            *ppReturnedDeviceInterface = new CProxyDirect3DDevice9(*ppReturnedDeviceInterface);

            // Debug output
            D3DDEVICE_CREATION_PARAMETERS parameters;
            (*ppReturnedDeviceInterface)->GetCreationParameters(&parameters);

            WriteDebugEvent(SString("    Adapter:%d  DeviceType:%d  BehaviorFlags:0x%x  ReadableDepth:%s", parameters.AdapterOrdinal, parameters.DeviceType,
                                    parameters.BehaviorFlags, ReadableDepthFormat ? std::string((char*)&ReadableDepthFormat, 4).c_str() : "None"));
        }
    }

    uint uiLastStatus = GetApplicationSettingInt("diagnostics", "createdevice-last-status");
    SetApplicationSettingInt("diagnostics", "createdevice-last-status", uiCurrentStatus);

    // Calc log level to use
    uint uiDiagnosticLogLevel = 0;
    if (uiLastStatus == CREATE_DEVICE_FAIL && uiCurrentStatus != CREATE_DEVICE_FAIL)
        uiDiagnosticLogLevel = 1;            // Log and continue - If changing from fail status
    if (uiCurrentStatus == CREATE_DEVICE_FAIL)
        uiDiagnosticLogLevel = 2;            // Log and wait - If fail status

    bool bDetectOptimus = (GetModuleHandle("nvd3d9wrap.dll") != NULL);

    bool bFixCaps = false;
    if (GetApplicationSettingInt("nvhacks", "optimus") || bDetectOptimus)
    {
        bFixCaps = true;
        if (uiDiagnosticLogLevel == 0)
            uiDiagnosticLogLevel = 1;
    }

    AddCapsReport(Adapter, pDirect3D, *ppReturnedDeviceInterface, bFixCaps);

    if (uiDiagnosticLogLevel)
    {
        // Prevent statup warning in loader
        WatchDogCompletedSection("L3");
        CCore::GetSingleton().GetNetwork()->ResetStub('dia3', *ms_strExtraLogBuffer, uiDiagnosticLogLevel);
    }
    ms_strExtraLogBuffer.clear();

    if (hResult != D3D_OK)
    {
        // Handle fatal error
        SString strMessage;
        strMessage += "There was a problem starting MTA:SA\n\n";
        strMessage += SString("Direct3D CreateDevice error: %08x", hResult);
        BrowseToSolution("d3dcreatedevice-fail", EXIT_GAME_FIRST | ASK_GO_ONLINE, strMessage);
    }

    return hResult;
}
Esempio n. 6
0
//////////////////////////////////////////////////////////
//
// BeginD3DStuff
//
// Look all busy and important in case any graphic drivers are looking
//
//////////////////////////////////////////////////////////
void BeginD3DStuff( void )
{
    pD3D9 = Direct3DCreate9( D3D_SDK_VERSION );

    if ( !pD3D9 )
    {
        WriteDebugEvent( "D3DStuff - Direct3DCreate9 failed" );
        return;
    }

    WriteDebugEvent( "D3DStuff -------------------------" );
    WriteDebugEvent( SString( "D3DStuff - Direct3DCreate9: 0x%08x", pD3D9 ) );

    bool bDetectedOptimus = false;
    bool bDetectedNVidia = false;
    // Get info about each connected adapter
    uint uiNumAdapters = pD3D9->GetAdapterCount();
    WriteDebugEvent( SString( "D3DStuff - %d Adapters", uiNumAdapters ) );

    for ( uint i = 0 ; i < uiNumAdapters ; i++ )
    {
        D3DADAPTER_IDENTIFIER9 Identifier;
        D3DDISPLAYMODE DisplayMode;
        D3DCAPS9 Caps9;

        HRESULT hr1 = pD3D9->GetAdapterIdentifier( i, 0, &Identifier );
        HRESULT hr2 = pD3D9->GetAdapterDisplayMode( i, &DisplayMode );
        HRESULT hr3 = pD3D9->GetDeviceCaps( i, D3DDEVTYPE_HAL, &Caps9 );
        UINT ModeCount = pD3D9->GetAdapterModeCount( i, D3DFMT_X8R8G8B8 );
        HMONITOR hMonitor = pD3D9->GetAdapterMonitor( i );

        if ( FAILED( hr1 ) || FAILED( hr2 ) || FAILED( hr3 ) )
        {
            WriteDebugEvent( SString( "D3DStuff %d Failed GetAdapterIdentifier(%x) GetAdapterDisplayMode(%x) GetDeviceCaps(%x) ", i, hr1, hr2, hr3 ) );
            continue;
        }

        // Detect Optimus combo
        if ( SStringX( Identifier.Driver ).BeginsWithI( "nv" )
            && SStringX( Identifier.Description ).BeginsWithI( "Intel" )
            )
        {
            bDetectedOptimus = true;
            WriteDebugEvent( SString( "D3DStuff %d - Detected Optimus Combo", i ) );
        }
        if ( GetModuleHandle( "nvd3d9wrap.dll" ) != NULL )
        {
            bDetectedOptimus = true;
            WriteDebugEvent( SString( "D3DStuff %d - Detected nvd3d9wrap", i ) );
        }
        if ( SStringX( Identifier.Driver ).BeginsWithI( "nv" ) )
        {
            bDetectedNVidia = true;
        }

        WriteDebugEvent( SString( "D3DStuff %d Identifier - %s", i, *ToString( Identifier ) ) );
        WriteDebugEvent( SString( "D3DStuff %d DisplayMode - %s", i, *ToString( DisplayMode ) ) );
        WriteDebugEvent( SString( "D3DStuff %d  hMonitor:0x%08x  ModeCount:%d", i, hMonitor, ModeCount ) );
        WriteDebugEvent( SString( "D3DStuff %d Caps9 - %s ", i, *ToString( Caps9 ) ) );
    }

    if ( GetApplicationSettingInt( "nvhacks", "optimus-force-detection" ) )
        bDetectedOptimus = true;

    if ( NvOptimusDetect() )
        bDetectedOptimus = true;

    SetApplicationSettingInt( "nvhacks", "optimus", bDetectedOptimus );
    SetApplicationSettingInt( "nvhacks", "nvidia", bDetectedNVidia );

    if ( bDetectedOptimus )
    {
        ShowOptimusDialog ( g_hInstance );
        HideOptimusDialog ();
    }
    else
    {
        SetApplicationSettingInt( "nvhacks", "optimus-alt-startup", 0 );
        SetApplicationSettingInt( "nvhacks", "optimus-rename-exe", 0 );
        SetApplicationSettingInt( "nvhacks", "optimus-export-enablement", 0 );
        SetApplicationSettingInt( "nvhacks", "optimus-force-windowed", 0 );
    }
}
Esempio n. 7
0
//////////////////////////////////////////////////////////
//
// CInstallManager::_ProcessLayoutChecks
//
// Make sure new reg/dir structure is ok
//
//////////////////////////////////////////////////////////
SString CInstallManager::_ProcessLayoutChecks ( void )
{
    //
    // Validation
    //

    // Check data dir exists
    {
        if ( !DirectoryExists ( GetMTADataPath () ) )
            ShowLayoutError ( "[Data directory not present]" );   // Can't find directory
    }

    // Check reg key exists
    //{
    //    if ( GetRegistryValue ( "", "Last Install Location" ).empty () )
    //        ShowLayoutError ( "[Registry key not present]" );   // Can't find reg key
    //}

    // Check data dir writable
    {
        SString strTestFilePath = PathJoin ( GetMTADataPath (), "testdir", "testfile.txt" );

        FileDelete ( strTestFilePath );
        RemoveDirectory ( ExtractPath ( strTestFilePath ) );

        SString strContent = "test";
        if ( !FileSave ( strTestFilePath, strContent ) )
            ShowLayoutError ( "[Data directory not writable]" );   // Can't save file

        FileDelete ( strTestFilePath );
        RemoveDirectory ( ExtractPath ( strTestFilePath ) );
    }

    // Check reg key writable
    {
        RemoveRegistryKey ( "testkeypath" );

        SString strValue = GetTimeString( true, true );
        SetRegistryValue ( "testkeypath", "testname", strValue );
        SString strValueCheck = GetRegistryValue ( "testkeypath", "testname" );
        if ( strValueCheck != strValue )
            ShowLayoutError ( "[Registry key not writable]" );   // Can't write reg key

        RemoveRegistryKey ( "testkeypath" );
    }

    // Check install dir writable
    {
        SString strTestFilePath = CalcMTASAPath ( PathJoin ( "mta", "writetest.txt" ) );

        FileDelete ( strTestFilePath );

        SString strContent = "test";
        if ( !FileSave ( strTestFilePath, strContent ) )
            ShowLayoutError ( "[Install directory not writable]" );   // Can't save file

        FileDelete ( strTestFilePath );
    }

    //
    // Migration
    //

    // If news/temp/upcache folder doesn't exist in new, but does in old place, move it
    {
        const char* folders[] = { "news", "temp", "upcache" };
        for ( uint i = 0 ; i < NUMELMS( folders ) ; i++ )
        {
            SString strSrc = PathJoin ( GetSystemLocalAppDataPath (), "MTA San Andreas " + GetMajorVersionString (), folders[i] );
            SString strDest = PathJoin ( GetMTADataPath (), folders[i] );
            if ( !DirectoryExists ( strDest ) && DirectoryExists ( strSrc ) )
                MoveFile ( strSrc, strDest );
        }
    }

    // If aero option reg entry doesn't exist in new, but does in old place, move it
    {
        if ( GetApplicationSetting ( "aero-enabled" ).empty () )
        {
            SString strLegacyValue = GetVersionRegistryValueLegacy ( GetMajorVersionString (), PathJoin ( "Settings", "general" ), "aero-enabled" );
            if ( !strLegacyValue.empty () )
                SetApplicationSettingInt ( "aero-enabled", atoi ( strLegacyValue ) );
            else
                SetApplicationSettingInt ( "aero-enabled", 1 );
        }
    }

    return "ok";
}
Esempio n. 8
0
void SharedUtil::WatchDogSetUncleanStop ( bool bOn )
{
    SetApplicationSettingInt ( "watchdog", "uncleanstop", bOn );
    bWatchDogWasUncleanStopCached = true;
    bWatchDogWasUncleanStopValue = bOn;
}
///////////////////////////////////////////////////////////////
//
// CModelCacheManagerImpl::PreLoad
//
// Cache all weapons and upgrades
//
// Peds KB:                64,832 KB         7-312     306  296 valid, 10 not so valid               219   KB/model             4.45/MB
// Weapons KB:             470               321-372   52   39 valid, 3 invalid(329,332,340)         470   KB all weapons
// Upgrades KB:            2,716             1000-1193 194  all valid                              2,716   KB all upgrades
// Vehicles(400-499) KB:   14,622                                                                    140   KB/model             7/MB
// Vehicles(500-599) KB:   14,888
//
///////////////////////////////////////////////////////////////
void CModelCacheManagerImpl::PreLoad ( void )
{
    if ( m_bDonePreLoad )
        return;

    m_bDonePreLoad = true;

    CTickCount startTicks = CTickCount::Now ();
#if 0
    for ( uint i = 321 ; i <= 372 ; i++ )
    {
        if ( CClientPedManager::IsValidWeaponModel ( i ) )
            AddModelRefCount ( i );
    }
#endif
    m_pGame->GetStreaming()->LoadAllRequestedModels ( false );

    // Get current limits
    int bSlowMethod = GetApplicationSettingInt( DIAG_PRELOAD_UPGRADES_SLOW );
    int iLowestUnsafeUpgrade = GetApplicationSettingInt( DIAG_PRELOAD_UPGRADES_LOWEST_UNSAFE );
    SetApplicationSetting( DIAG_CRASH_EXTRA_MSG, "** AUTO FIXING CRASH (Step 1/2) **\n\n** Please continue and connect to a server **" );

    // Crashed during previous PreLoad?
    if ( WatchDogIsSectionOpen( WD_SECTION_PRELOAD_UPGRADES ) )
    {
        AddReportLog( 8545, SString( "PreLoad Upgrades - Crash detect - bSlowMethod:%d  iLowestUnsafeUpgrade:%d", bSlowMethod, iLowestUnsafeUpgrade ) );
        iLowestUnsafeUpgrade = GetApplicationSettingInt( DIAG_PRELOAD_UPGRADE_ATTEMPT_ID );
        bSlowMethod = 1;
        SetApplicationSettingInt( DIAG_PRELOAD_UPGRADES_LOWEST_UNSAFE, iLowestUnsafeUpgrade );
        SetApplicationSettingInt( DIAG_PRELOAD_UPGRADES_SLOW, bSlowMethod );
        SetApplicationSetting( DIAG_CRASH_EXTRA_MSG, "** AUTO FIXING CRASH (Step 2/2) **\n\n** Please continue and connect to a server **" );
    }

    if ( iLowestUnsafeUpgrade == 0 )
        iLowestUnsafeUpgrade = 1194;

    // PreLoad upgrades
    WatchDogBeginSection( WD_SECTION_PRELOAD_UPGRADES );
    {
        for ( int i = 1000 ; i < iLowestUnsafeUpgrade ; i++ )
        {
            if ( bSlowMethod )
                SetApplicationSettingInt( DIAG_PRELOAD_UPGRADE_ATTEMPT_ID, i );
            AddModelRefCount ( i );
            if ( bSlowMethod )
                m_pGame->GetStreaming()->LoadAllRequestedModels ( false );
        }
        m_pGame->GetStreaming()->LoadAllRequestedModels ( false );
    }
    WatchDogCompletedSection( WD_SECTION_PRELOAD_UPGRADES );
    SetApplicationSetting( DIAG_CRASH_EXTRA_MSG, "" );

    // Report if LowestUnsafeUpgrade has fallen
    int iPrevHiScore = GetApplicationSettingInt( DIAG_PRELOAD_UPGRADES_HISCORE );
    SetApplicationSettingInt( DIAG_PRELOAD_UPGRADES_HISCORE, iLowestUnsafeUpgrade );
    if ( iPrevHiScore > iLowestUnsafeUpgrade )
        AddReportLog( 8544, SString( "PreLoad Upgrades - LowestUnsafeUpgrade fallen from %d to %d", iPrevHiScore, iLowestUnsafeUpgrade ) );

    CTickCount deltaTicks = CTickCount::Now () - startTicks;
    OutputDebugLine ( SString ( "CModelCacheManagerImpl::PreLoad completed in %d ms", deltaTicks.ToInt () ) );
}
Esempio n. 10
0
void SharedUtil::WatchDogClearCounter ( const SString& str )
{
    SetApplicationSettingInt ( "watchdog", str, 0 );
}
Esempio n. 11
0
// Counter
void SharedUtil::WatchDogIncCounter ( const SString& str )
{
    SetApplicationSettingInt ( "watchdog", str, WatchDogGetCounter ( str ) + 1 );
}
Esempio n. 12
0
void SharedUtil::WatchDogCompletedSection ( const SString& str )
{
    SetApplicationSettingInt ( "watchdog", str, 0 );
}
Esempio n. 13
0
void SharedUtil::WatchDogBeginSection ( const SString& str )
{
    SetApplicationSettingInt ( "watchdog", str, 1 );
}
Esempio n. 14
0
void SharedUtil::SetApplicationSettingInt ( const SString& strName, int iValue )
{
    SetApplicationSettingInt ( "general", strName, iValue );
}