VSync patch

Since I bought a new LCD monitor (Iiyama ProLite B2403WS), I've been experiencing tearing effects on games. Most of the time, forcing the vsync option will fix the problem. However, it's not as simple for windowed FFXI. I've been reading the DirectX 8 documentation and found an interesting value for SwapEffect in the D3DPRESENT_PARAMETERS structure:

From the Direct3D 8 API:
D3DSWAPEFFECT_COPY_VSYNC Like D3DSWAPEFFECT_COPY, this swap effect may be used only with a swap chain made of a single back buffer. It guarantees that a Present operation applied to the swap chain will exhibit copy semantics, as described above for D3DSWAPEFFECT_COPY. For a windowed swap chain, a Present operation causes the back buffer content to be copied to the client area of the target window. The runtime will attempt to eliminate tearing effects by avoiding the copy operation while the adapter is scanning within the destination rectangle on the display. It will also perform at most one such copy operation during the adapter's refresh period and thus limit the presentation frequency. Note, however, that if the adapter does not support the ability to report the raster status, the swap chain will behave as though it had been created with the D3DSWAPEFFECT_COPY swap effect. (Refer to the description of the D3DCAPS_READ_SCANLINE flag value for the Caps member of D3DCAPS8.) For a full-screen swap chain, D3DSWAPEFFECT_COPY_VSYNC is identical to D3DSWAPEFFECT_COPY, except that the D3DPRESENT_INTERVAL_IMMEDIATE flag is meaningless when used in conjunction with D3DSWAPEFFECT_COPY_VSYNC. (Refer to the description of the FullScreen_PresentationInterval member of the D3DPRESENT_PARAMETERS structure.)

To force Vsync in the windower DLL, you will need any hexadecimal editor and modify the value for SwapEffect manually.
The offset of the value for SwapEffect in the Windower 3.431 Hook.dll is 0x000961E8. Simply replace 01 with 04.
You could also try to change the value at offset 0x000961DA to 02 (BackBufferCount) for “triple buffering”.

Here is the dissassembly of the relevent code:

.text:10096DBF mov ecx, dword_100F3F14
.text:10096DC5 mov [ebp+var_6C], ecx
.text:10096DC8 mov edx, dword_100F3F18
.text:10096DCE mov [ebp+var_68], edx
.text:10096DD1 mov eax, [ebp+var_74]
.text:10096DD4 mov [ebp+var_64], eax
.text:10096DD7 mov [ebp+var_60], 1
.text:10096DDE mov [ebp+var_5C], 0
.text:10096DE5 mov [ebp+var_58], 1
.text:10096DEC mov ecx, [ebp+hWnd]
.text:10096DEF mov [ebp+var_54], ecx
.text:10096DF2 mov [ebp+var_50], 1
.text:10096DF9 mov [ebp+var_4C], 1
.text:10096E00 mov [ebp+var_48], 75
.text:10096E07 mov [ebp+var_44], 0
.text:10096E0E mov [ebp+var_40], 0
.text:10096E15 mov [ebp+var_3C], 0

vsync.txt · Last modified: 15/08/2018 11:14 by xebeth