Skip to content

Commit 3ac2740

Browse files
committed
gta3: workaround for console gamma crash
1 parent e28eefb commit 3ac2740

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

data/GTA3.WidescreenFix/scripts/GTA3.WidescreenFix.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ForceMultisamplingLevel = max
1414
HideAABug = 2
1515
; Makes menu background transparent with a blur (0|1).
1616
TransparentMenu = 0
17-
; A custom gamma curve similar to how GTA IV looked on the Xbox 360 (0|1).
17+
; A custom gamma curve similar to how GTA IV looked on the Xbox 360 (0|1). Currently only works in windowed mode.
1818
ConsoleGamma = 0
1919

2020
[MISC]

source/GTA3.WidescreenFix/ConsoleGamma.ixx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ private:
4747
static inline UINT nScreenWidth = 0;
4848
static inline UINT nScreenHeight = 0;
4949
static inline bool bInitialized = false;
50+
static inline bool bIsWindowed = false;
51+
static inline bool bWindowedCached = false;
5052

5153
static inline D3DXHANDLE hInputTex2D = nullptr;
5254
static inline D3DXHANDLE hGammaTechnique = nullptr;
@@ -63,6 +65,25 @@ private:
6365
return dev9;
6466
}
6567

68+
static bool IsWindowed(IDirect3DDevice9* dev)
69+
{
70+
if (bWindowedCached)
71+
return bIsWindowed;
72+
73+
bIsWindowed = false;
74+
IDirect3DSwapChain9* pSwap = nullptr;
75+
if (SUCCEEDED(dev->GetSwapChain(0, &pSwap)) && pSwap)
76+
{
77+
D3DPRESENT_PARAMETERS pp{};
78+
if (SUCCEEDED(pSwap->GetPresentParameters(&pp)))
79+
bIsWindowed = pp.Windowed != FALSE;
80+
pSwap->Release();
81+
}
82+
83+
bWindowedCached = true;
84+
return bIsWindowed;
85+
}
86+
6687
static bool Initialize(IDirect3DDevice9* dev)
6788
{
6889
if (bInitialized) return true;
@@ -156,6 +177,8 @@ public:
156177
IDirect3DDevice9* dev = GetDevice9();
157178
if (!dev) return;
158179

180+
if (!IsWindowed(dev)) return;
181+
159182
if (!Initialize(dev)) return;
160183

161184
IDirect3DSurface9* currentRT = nullptr;
@@ -190,6 +213,7 @@ public:
190213

191214
static void OnDeviceReset()
192215
{
216+
bWindowedCached = false;
193217
ReleaseResources();
194218
}
195219
} ConsoleGamma;

0 commit comments

Comments
 (0)