Skip to content

Commit

Permalink
Hooked up VSync (looks like it never worked, at least with 1.4 and 1.…
Browse files Browse the repository at this point in the history
…32 patches)
  • Loading branch information
CookiePLMonster committed Apr 7, 2018
1 parent ae8b818 commit 2d3bded
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
20 changes: 17 additions & 3 deletions SilentPatchFarCry/D3D9Hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
#include "MemoryMgr.h"
#include "Trampoline.h"

// ========= Custom VSync hook =========
const int* r_VSync = nullptr;
static D3DPRESENT_PARAMETERS* FixupVSyncParameter( D3DPRESENT_PARAMETERS* params )
{
if ( r_VSync != nullptr && params != nullptr )
{
if ( *r_VSync != 0 && params->PresentationInterval == D3DPRESENT_INTERVAL_IMMEDIATE )
{
params->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
}
}
return params;
}

static IDirect3D9* (WINAPI *orgDirect3DCreate9)(UINT SDKVersion);
static IDirect3D9* WINAPI FCDirect3DCreate9(UINT SDKVersion)
{
Expand Down Expand Up @@ -119,7 +133,7 @@ HRESULT FCDirect3D9::CreateDevice(UINT Adapter, D3DDEVTYPE DeviceType, HWND hFoc
{
IDirect3DDevice9* device = nullptr;

HRESULT result = m_direct3D9->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, &device);
HRESULT result = m_direct3D9->CreateDevice(Adapter, DeviceType, hFocusWindow, BehaviorFlags, FixupVSyncParameter(pPresentationParameters), &device);
if ( FAILED(result) )
{
*ppReturnedDeviceInterface = nullptr;
Expand Down Expand Up @@ -215,7 +229,7 @@ BOOL FCDirect3DDevice9::ShowCursor(BOOL bShow)

HRESULT FCDirect3DDevice9::CreateAdditionalSwapChain(D3DPRESENT_PARAMETERS * pPresentationParameters, IDirect3DSwapChain9 ** pSwapChain)
{
return m_direct3DDevice9->CreateAdditionalSwapChain(pPresentationParameters, pSwapChain);
return m_direct3DDevice9->CreateAdditionalSwapChain(FixupVSyncParameter(pPresentationParameters), pSwapChain);
}

HRESULT FCDirect3DDevice9::GetSwapChain(UINT iSwapChain, IDirect3DSwapChain9 ** pSwapChain)
Expand All @@ -230,7 +244,7 @@ UINT FCDirect3DDevice9::GetNumberOfSwapChains(void)

HRESULT FCDirect3DDevice9::Reset(D3DPRESENT_PARAMETERS * pPresentationParameters)
{
return m_direct3DDevice9->Reset(pPresentationParameters);
return m_direct3DDevice9->Reset(FixupVSyncParameter(pPresentationParameters));
}

HRESULT FCDirect3DDevice9::Present(const RECT * pSourceRect, const RECT * pDestRect, HWND hDestWindowOverride, const RGNDATA * pDirtyRegion)
Expand Down
9 changes: 9 additions & 0 deletions SilentPatchFarCry/SilentPatchFarCry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
TrampolineMgr trampolines;

void InstallD3D9Hook( void* func, Trampoline& trampoline );
extern const int* r_VSync;

class CrySystem
{
Expand All @@ -44,6 +45,14 @@ class CrySystem
#endif

InstallD3D9Hook( createD3D, trampolines.MakeTrampoline( module ) );

// VSync hook
#if !Is64Bit
r_VSync = *hook::make_module_pattern( module, "A1 ? ? ? ? 3B 86 E8 67 01 00" ).get_first<int*>( 0x1 );
#else
uintptr_t addr = reinterpret_cast<uintptr_t>(hook::make_module_pattern( module, "8B 05 ? ? ? ? 41 3B 85 24 76 01 00" ).get_first());
r_VSync = reinterpret_cast<int*>( addr + 6 + *reinterpret_cast<int32_t*>(addr+2) );
#endif

d3d9Hooked = true;
}
Expand Down

1 comment on commit 2d3bded

@mirh
Copy link

@mirh mirh commented on 2d3bded Apr 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you try 1.00?

Please sign in to comment.