Skip to content

Commit

Permalink
Allow overriding refresh rate for Direct3D9
Browse files Browse the repository at this point in the history
  • Loading branch information
elishacloud committed Sep 6, 2023
1 parent 177b720 commit d0f60a8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dllmain/BuildNo.rc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILD_NUMBER 6796
#define BUILD_NUMBER 6797
2 changes: 1 addition & 1 deletion Settings/AllSettings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ DdrawOverrideWidth = 0
DdrawOverrideHeight = 0
DdrawOverridePrimaryWidth = 0
DdrawOverridePrimaryHeight = 0
DdrawOverrideRefreshRate = 0
DdrawOverrideStencilFormat = 0
DdrawIntegerScalingClamp = 0
DdrawMaintainAspectRatio = 0
Expand All @@ -83,6 +82,7 @@ AntiAliasing = 0
CacheClipPlane = 0
EnableVSync = 0
ForceVsyncMode = 0
OverrideRefreshRate = 0
EnableWindowMode = 0
WindowModeBorder = 0
SetInitialWindowPosition = 0
Expand Down
12 changes: 8 additions & 4 deletions Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace Settings
size_t BytesToWriteCount = 0; // Count of bytes to hot patch
bool Force16bitColor; // Forces DirectX to use 16bit color
bool Force32bitColor; // Forces DirectX to use 32bit color
DWORD DdrawOverrideRefreshRate = 0; // Legacy setting

// Function declarations
bool IsValueEnabled(char*);
Expand Down Expand Up @@ -279,6 +280,8 @@ void __stdcall Settings::ParseCallback(char* name, char* value)
Config.DisableMaxWindowedModeNotSet = false;
}

SET_LOCAL_VALUE(DdrawOverrideRefreshRate);

// Set Value of local settings
VISIT_LOCAL_SETTINGS(SET_LOCAL_VALUE);

Expand Down Expand Up @@ -636,10 +639,11 @@ void CONFIG::SetConfig()
}

// Check anti-aliasing value
if (AntiAliasing == 1)
{
AntiAliasing = 16;
}
AntiAliasing = (AntiAliasing == 1) ? 16 : AntiAliasing;

// Enable refresh rate
OverrideRefreshRate = (DdrawOverrideRefreshRate && !OverrideRefreshRate) ? DdrawOverrideRefreshRate : OverrideRefreshRate;
DdrawOverrideRefreshRate = 0;

// Enable wrapper settings
Dinputto8 = (Dinputto8 || IsSet(Dinput8HookSystem32));
Expand Down
4 changes: 2 additions & 2 deletions Settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
visit(DdrawOverrideHeight) \
visit(DdrawOverridePrimaryWidth) \
visit(DdrawOverridePrimaryHeight) \
visit(DdrawOverrideRefreshRate) \
visit(DdrawOverrideStencilFormat) \
visit(DdrawResolutionHack) \
visit(DdrawUseDirect3D9Ex) \
Expand Down Expand Up @@ -101,6 +100,7 @@
visit(LoopSleepTime) \
visit(Num2DBuffers) \
visit(Num3DBuffers) \
visit(OverrideRefreshRate) \
visit(PrimaryBufferBits) \
visit(PrimaryBufferChannels) \
visit(PrimaryBufferSamples) \
Expand Down Expand Up @@ -223,7 +223,7 @@ struct CONFIG
DWORD DdrawOverrideHeight = 0; // Force Direct3d9 to use this height when using Dd7to9
DWORD DdrawOverridePrimaryWidth = 0; // Force Dd7to9 to use this width for the primary/backbuffer surface
DWORD DdrawOverridePrimaryHeight = 0; // Force Dd7to9 to use this height for the primary/backbuffer surface
DWORD DdrawOverrideRefreshRate = 0; // Force Direct3d9 to use this refresh rate when using Dd7to9
DWORD OverrideRefreshRate = 0; // Force Direct3d9 to use this refresh rate, only works in exclusive fullscreen mode
DWORD DdrawOverrideStencilFormat = 0; // Force Direct3d9 to use this AutoStencilFormat when using Dd7to9
bool DdrawEnableMouseHook = false; // Allow to hook into mouse to limit it to the chosen resolution
DWORD DdrawHookSystem32 = 0; // Hooks the ddraw.dll file in the Windows System32 folder
Expand Down
2 changes: 1 addition & 1 deletion Settings/Settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ DdrawLimitDisplayModeCount = 0
DdrawUseNativeResolution = 0
DdrawOverrideWidth = 0
DdrawOverrideHeight = 0
DdrawOverrideRefreshRate = 0
DdrawIntegerScalingClamp = 0
DdrawMaintainAspectRatio = 0

Expand All @@ -63,6 +62,7 @@ AnisotropicFiltering = 0
AntiAliasing = 0
EnableVSync = 0
ForceVsyncMode = 0
OverrideRefreshRate = 0
EnableWindowMode = 0
WindowModeBorder = 0
SetInitialWindowPosition = 0
Expand Down
6 changes: 6 additions & 0 deletions d3d9/IDirect3D9Ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ void UpdatePresentParameter(D3DPRESENT_PARAMETERS* pPresentationParameters, HWND
pPresentationParameters->FullScreen_RefreshRateInHz = 0;
}

// Set refresh rate if using exclusive fullscreen mode
if (Config.OverrideRefreshRate && !pPresentationParameters->Windowed)
{
pPresentationParameters->FullScreen_RefreshRateInHz = Config.OverrideRefreshRate;
}

// Store last window data
LONG LastBufferWidth = BufferWidth;
LONG LastBufferHeight = BufferHeight;
Expand Down
4 changes: 2 additions & 2 deletions ddraw/IDirectDrawX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ HRESULT m_IDirectDrawX::SetDisplayMode(DWORD dwWidth, DWORD dwHeight, DWORD dwBP
// Display resolution
Device.Width = (Config.DdrawUseNativeResolution || Config.DdrawOverrideWidth) ? Device.Width : FoundWidth;
Device.Height = (Config.DdrawUseNativeResolution || Config.DdrawOverrideHeight) ? Device.Height : FoundHeight;
Device.RefreshRate = (Config.DdrawOverrideRefreshRate) ? Device.RefreshRate : DisplayMode.RefreshRate;
Device.RefreshRate = DisplayMode.RefreshRate;
}

// Set exclusive mode resolution
Expand Down Expand Up @@ -2312,7 +2312,7 @@ void m_IDirectDrawX::InitDdraw(DWORD DirectXVersion)
Device.Width = (Config.DdrawOverrideWidth) ? Config.DdrawOverrideWidth : 0;
Device.Height = (Config.DdrawOverrideHeight) ? Config.DdrawOverrideHeight : 0;
}
Device.RefreshRate = (Config.DdrawOverrideRefreshRate) ? Config.DdrawOverrideRefreshRate : 0;
Device.RefreshRate = 0;

// Mouse hook
static bool EnableMouseHook = Config.DdrawEnableMouseHook &&
Expand Down

0 comments on commit d0f60a8

Please sign in to comment.