@@ -566,13 +566,15 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
566566 WriteDebugEvent (" CProxyDirect3DDevice9::Reset - Invalid presentation parameters" );
567567 return D3DERR_INVALIDCALL;
568568 }
569-
570- // Reset gamma state since display mode might change
569+
570+ // Preserve existing gamma snapshot so we can restore it if the reset fails.
571+ SGammaState previousGammaState;
572+ bool gammaStateCleared = false ;
571573 {
572574 std::lock_guard<std::mutex> gammaLock (g_gammaStateMutex);
573- g_GammaState. bOriginalGammaStored = false ;
574- g_GammaState. bLastWasBorderless = false ;
575- ZeroMemory (&g_GammaState. originalGammaRamp , sizeof (g_GammaState. originalGammaRamp )) ;
575+ previousGammaState = g_GammaState ;
576+ g_GammaState = SGammaState () ;
577+ gammaStateCleared = true ;
576578 }
577579 WriteDebugEvent (" Reset gamma state due to device reset" );
578580
@@ -686,9 +688,13 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
686688 {
687689 WriteDebugEvent (" CProxyDirect3DDevice9::Reset - Failed to begin scene for driver sync" );
688690 }
689- else if (! EndSceneWithoutProxy (m_pDevice, ESceneOwner::MTA))
691+ else
690692 {
691- WriteDebugEvent (" CProxyDirect3DDevice9::Reset - Failed to end scene for driver sync" );
693+ if (!EndSceneWithoutProxy (m_pDevice, ESceneOwner::MTA))
694+ {
695+ WriteDebugEvent (" CProxyDirect3DDevice9::Reset - Failed to end scene for driver sync" );
696+ g_bInMTAScene.store (false , std::memory_order_release);
697+ }
692698 }
693699
694700 WriteDebugEvent (SString (" BackBufferWidth:%d Height:%d Format:%d Count:%d" , pPresentationParameters->BackBufferWidth ,
@@ -716,6 +722,12 @@ HRESULT CProxyDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS* pPresentationParamet
716722 else
717723 {
718724 WriteDebugEvent (SString (" CProxyDirect3DDevice9::Reset failed with HRESULT: %08x" , hResult));
725+ if (gammaStateCleared)
726+ {
727+ std::lock_guard<std::mutex> gammaLock (g_gammaStateMutex);
728+ g_GammaState = previousGammaState;
729+ WriteDebugEvent (" CProxyDirect3DDevice9::Reset - Restored prior gamma state after failed reset" );
730+ }
719731 }
720732
721733 return hResult;
@@ -819,8 +831,8 @@ VOID CProxyDirect3DDevice9::SetGammaRamp(UINT iSwapChain, DWORD Flags, CONST D3D
819831
820832 // Use lighter gamma correction to prevent darkening effect
821833 // and optimize brightness boost for better visibility
822- const float fGammaCorrection = 1 .0f / 1 .3f ;
823- const float fBrightnessBoost = 1 . 4f ;
834+ const float fGammaCorrection = 0 . 4f ; // Equivalent to 1.0f / 1.3f
835+ const float fBrightnessBoost = 0 . 7f ;
824836
825837 const auto convertNormalizedToGammaWord = [](float normalized) -> WORD {
826838 const float scaled = std::clamp (normalized * 65535 .0f , 0 .0f , 65535 .0f );
@@ -1597,6 +1609,14 @@ bool EndSceneWithoutProxy(IDirect3DDevice9* pDevice, ESceneOwner owner)
15971609 if (FAILED (hr))
15981610 {
15991611 WriteDebugEvent (SString (" EndSceneWithoutProxy failed: %08x" , hr));
1612+ if (owner == ESceneOwner::GTA)
1613+ {
1614+ ResetGTASceneState ();
1615+ }
1616+ else if (owner == ESceneOwner::MTA)
1617+ {
1618+ g_bInMTAScene.store (false , std::memory_order_release);
1619+ }
16001620 return false ;
16011621 }
16021622
0 commit comments