Skip to content

Commit

Permalink
Add workaround to fix fullscreen working incorrectly on modern windows
Browse files Browse the repository at this point in the history
  • Loading branch information
leejeonghun committed Jul 26, 2024
1 parent 7fe8c4f commit 1d7cd83
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
27 changes: 27 additions & 0 deletions version/fullscreen_fix.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 jeonghun

#include "fullscreen_fix.h"
#include <ddraw.h>
#include "dll_loader.h"

namespace fullscreen {

bool fix(HWND hwnd) {
static dll_loader ddraw(L"ddraw.dll", true);

IDirectDraw* ddraw_ptr = nullptr;
if (SUCCEEDED(ddraw.call<decltype(&DirectDrawCreate)>(
"DirectDrawCreate", nullptr, &ddraw_ptr, nullptr))) {
HRESULT hr = ddraw_ptr->SetCooperativeLevel(
hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NOWINDOWCHANGES);
if (FAILED(hr))
return false;

hr = ddraw_ptr->SetDisplayMode(1024, 768, 32);
return SUCCEEDED(hr);
}

return true;
}

} // namespace fullscreen
12 changes: 12 additions & 0 deletions version/fullscreen_fix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2024 jeonghun

#ifndef SAN9PK_WIN10_VERSION_FULLSCREEN_FIX_H_
#define SAN9PK_WIN10_VERSION_FULLSCREEN_FIX_H_

namespace fullscreen {

bool fix(HWND hwnd);

} // namespace fullscreen

#endif // SAN9PK_WIN10_VERSION_FULLSCREEN_FIX_H_
12 changes: 10 additions & 2 deletions version/secdrv_emulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <winternl.h>
#include <cassert>
#include "func_hooker.h"
#include "fullscreen_fix.h"
#include "../third_party/SafeDiscShim/src/secdrv_ioctl.h"

using namespace secdrvIoctl;
Expand Down Expand Up @@ -53,13 +54,20 @@ HWND WINAPI hook_createwindowexa(DWORD dwExStyle, LPCSTR lpClassName,
LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) {
func_hooker::rehook_on_exit rehook(createwindowexa);
HWND hwnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);

if (lstrcmpiA(lpClassName, "dummy") != 0) {
rehook.cancel();
ntdeviceiocontrolfile.unhook();
createfilea.unhook();

if (~dwStyle & WS_CAPTION) {
fullscreen::fix(hwnd);
}
}
return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);

return hwnd;
}

bool emulate() {
Expand Down
2 changes: 2 additions & 0 deletions version/version.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)secdrv</AdditionalIncludeDirectories>
</ClCompile>
<ClCompile Include="code_patcher.cc" />
<ClCompile Include="fullscreen_fix.cc" />
<ClCompile Include="func_hooker.cc" />
<ClCompile Include="nocd_patch.cc" />
<ClCompile Include="main.cc" />
Expand All @@ -106,6 +107,7 @@
<ClInclude Include="..\third_party\SafeDiscShim\src\secdrv_ioctl.h" />
<ClInclude Include="code_patcher.h" />
<ClInclude Include="dll_loader.h" />
<ClInclude Include="fullscreen_fix.h" />
<ClInclude Include="func_hooker.h" />
<ClInclude Include="nocd_patch.h" />
<ClInclude Include="precompile.h" />
Expand Down
6 changes: 6 additions & 0 deletions version/version.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<ClCompile Include="..\third_party\SafeDiscShim\src\secdrv_ioctl.cpp">
<Filter>Source Files\secdrv</Filter>
</ClCompile>
<ClCompile Include="fullscreen_fix.cc">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="dll_loader.h">
Expand Down Expand Up @@ -71,6 +74,9 @@
<ClInclude Include="resource.h">
<Filter>Resource Files</Filter>
</ClInclude>
<ClInclude Include="fullscreen_fix.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="version.def">
Expand Down

0 comments on commit 1d7cd83

Please sign in to comment.