nmlgc / ssg

秋霜玉 / Shuusou Gyoku

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

(DirectDraw) Programmatically disable the 8- and 16-bit compatibility shim

nmlgc opened this issue · comments

commented

While #3 implemented a proper 32-bit mode, DirectDraw's DWM8And16BitMitigation might still be active from running a previous version of a Shuusou Gyoku binary from the same path. This mitigation provides the emulated 8- and 16-bit modes even on modern Windows systems that don't support them, and are what causes the infamous slowdown in the first place. Ideally, we would remove this mitigation programmatically and not even offer players the option to select an actually unsupported, emulated video mode.

Doing that is not trivial hough:

  • Removing the mitigation's registry keys manually requires admin rights, since they might be set system-wide under HKEY_LOCAL_MACHINE, in addition to HKEY_CURRENT_USER.
  • Even if we did delete both keys programmatically, they wouldn't apply to the currently running process. DirectDraw checks for the state of the mitigation by calling DWM8And16Bit_IsShimApplied_CallOut() from apphelp.dll. This DLL is loaded into the game process at startup, and the flag read by the above function call is set on its DLL entry point, before any of our code gets to run.

That only leaves IAT patching as the most reliable method to override this flag, which is also what DDrawCompat arrived at:
https://github.com/narzoul/DDrawCompat/blob/7a59458d585fbf7eb1b243fc133c091bbdf561ce/DDrawCompat/Win32/DisplayMode.cpp#L276

Too complicated to handle within the same push as #3.