1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

Added RemoveBorders setting

This commit is contained in:
narzoul 2022-05-11 22:48:54 +02:00
parent 0ee03e4553
commit 04c29d1f38
9 changed files with 166 additions and 11 deletions

View File

@ -13,6 +13,7 @@ namespace Config
Settings::DisplayResolution displayResolution;
Settings::ForceD3D9On12 forceD3D9On12;
Settings::FullscreenMode fullscreenMode;
Settings::RemoveBorders removeBorders;
Settings::RenderColorDepth renderColorDepth;
Settings::ResolutionScale resolutionScale;
Settings::SpriteDetection spriteDetection;

View File

@ -11,6 +11,7 @@
#include <Config/Settings/DisplayResolution.h>
#include <Config/Settings/ForceD3D9On12.h>
#include <Config/Settings/FullscreenMode.h>
#include <Config/Settings/RemoveBorders.h>
#include <Config/Settings/RenderColorDepth.h>
#include <Config/Settings/ResolutionScale.h>
#include <Config/Settings/SpriteDetection.h>
@ -34,6 +35,7 @@ namespace Config
extern Settings::DisplayResolution displayResolution;
extern Settings::ForceD3D9On12 forceD3D9On12;
extern Settings::FullscreenMode fullscreenMode;
extern Settings::RemoveBorders removeBorders;
extern Settings::RenderColorDepth renderColorDepth;
extern Settings::ResolutionScale resolutionScale;
extern Settings::SpriteDetection spriteDetection;

View File

@ -0,0 +1,18 @@
#pragma once
#include <Config/EnumSetting.h>
namespace Config
{
namespace Settings
{
class RemoveBorders : public MappedSetting<bool>
{
public:
RemoveBorders()
: MappedSetting("RemoveBorders", "off", { {"off", false}, {"on", true} })
{
}
};
}
}

View File

@ -83,7 +83,18 @@ namespace
HRESULT result = getOrigVtable(This).SetCooperativeLevel(This, hWnd, dwFlags);
if (SUCCEEDED(result))
{
DDraw::TagSurface::create(*CompatPtr<IDirectDraw>::from(This));
auto tagSurface = DDraw::TagSurface::get(*CompatPtr<IDirectDraw>::from(This));
if (tagSurface)
{
if (dwFlags & DDSCL_FULLSCREEN)
{
tagSurface->setFullscreenWindow(hWnd);
}
else if (dwFlags & DDSCL_NORMAL)
{
tagSurface->setFullscreenWindow(nullptr);
}
}
}
return result;
}

View File

@ -1,5 +1,6 @@
#include <map>
#include <Config/Config.h>
#include <DDraw/DirectDraw.h>
#include <DDraw/Surfaces/TagSurface.h>
@ -10,14 +11,23 @@ namespace
namespace DDraw
{
TagSurface::TagSurface(DWORD origCaps, void* ddObject)
: Surface(origCaps)
, m_ddObject(ddObject)
, m_fullscreenWindow(nullptr)
, m_fullscreenWindowStyle(0)
, m_fullscreenWindowExStyle(0)
{
}
TagSurface::~TagSurface()
{
setFullscreenWindow(nullptr);
g_ddObjects.erase(m_ddObject);
}
HRESULT TagSurface::create(CompatRef<IDirectDraw> dd)
{
auto ddObject = DDraw::DirectDraw::getDdObject(dd.get());
if (g_ddObjects.find(ddObject) != g_ddObjects.end())
{
return DD_OK;
}
DDSURFACEDESC desc = {};
desc.dwSize = sizeof(desc);
desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS;
@ -25,6 +35,7 @@ namespace DDraw
desc.dwHeight = 1;
desc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;
auto ddObject = DDraw::DirectDraw::getDdObject(dd.get());
auto privateData(std::make_unique<TagSurface>(desc.ddsCaps.dwCaps, ddObject));
g_ddObjects[ddObject] = privateData.get();
@ -32,6 +43,18 @@ namespace DDraw
return Surface::create(dd, desc, surface, std::move(privateData));
}
TagSurface* TagSurface::findFullscreenWindow(HWND hwnd)
{
for (auto& pair : g_ddObjects)
{
if (hwnd == pair.second->m_fullscreenWindow)
{
return pair.second;
}
}
return nullptr;
}
void TagSurface::forEachDirectDraw(std::function<void(CompatRef<IDirectDraw7>)> callback)
{
struct DirectDrawInterface
@ -49,8 +72,75 @@ namespace DDraw
}
}
TagSurface::~TagSurface()
TagSurface* TagSurface::get(CompatRef<IDirectDraw> dd)
{
g_ddObjects.erase(m_ddObject);
auto ddObject = DDraw::DirectDraw::getDdObject(dd.get());
auto it = g_ddObjects.find(ddObject);
if (it != g_ddObjects.end())
{
return it->second;
}
if (FAILED(create(dd)))
{
return nullptr;
}
return g_ddObjects[ddObject];
}
void TagSurface::setFullscreenWindow(HWND hwnd)
{
if (m_fullscreenWindow == hwnd)
{
return;
}
HWND prevFullscreenWindow = m_fullscreenWindow;
m_fullscreenWindow = hwnd;
if (Config::removeBorders.get())
{
if (hwnd)
{
setWindowStyle(CALL_ORIG_FUNC(GetWindowLongA)(hwnd, GWL_STYLE));
setWindowExStyle(CALL_ORIG_FUNC(GetWindowLongA)(hwnd, GWL_EXSTYLE));
}
else if (prevFullscreenWindow)
{
CALL_ORIG_FUNC(SetWindowLongA)(prevFullscreenWindow, GWL_STYLE, m_fullscreenWindowStyle);
CALL_ORIG_FUNC(SetWindowLongA)(prevFullscreenWindow, GWL_EXSTYLE, m_fullscreenWindowExStyle);
m_fullscreenWindowStyle = 0;
m_fullscreenWindowExStyle = 0;
}
}
}
LONG TagSurface::setWindowStyle(LONG style)
{
auto lastError = GetLastError();
SetLastError(0);
LONG prevStyle = CALL_ORIG_FUNC(SetWindowLongA)(m_fullscreenWindow, GWL_STYLE, style);
if (0 != prevStyle || 0 == GetLastError())
{
CALL_ORIG_FUNC(SetWindowLongA)(m_fullscreenWindow, GWL_STYLE,
(style | WS_POPUP) & ~(WS_BORDER | WS_DLGFRAME | WS_SYSMENU | WS_THICKFRAME));
m_fullscreenWindowStyle = style;
SetLastError(lastError);
}
return prevStyle;
}
LONG TagSurface::setWindowExStyle(LONG exStyle)
{
auto lastError = GetLastError();
SetLastError(0);
LONG prevExStyle = CALL_ORIG_FUNC(SetWindowLongA)(m_fullscreenWindow, GWL_EXSTYLE, exStyle);
if (0 != prevExStyle || 0 == GetLastError())
{
CALL_ORIG_FUNC(SetWindowLongA)(m_fullscreenWindow, GWL_EXSTYLE,
exStyle & ~(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE | WS_EX_WINDOWEDGE));
m_fullscreenWindowExStyle = exStyle;
SetLastError(lastError);
}
return prevExStyle;
}
}

View File

@ -11,13 +11,24 @@ namespace DDraw
class TagSurface : public Surface
{
public:
TagSurface(DWORD origCaps, void* ddObject) : Surface(origCaps), m_ddObject(ddObject) {}
TagSurface(DWORD origCaps, void* ddObject);
virtual ~TagSurface() override;
static HRESULT create(CompatRef<IDirectDraw> dd);
static TagSurface* get(CompatRef<IDirectDraw> dd);
static TagSurface* findFullscreenWindow(HWND hwnd);
static void forEachDirectDraw(std::function<void(CompatRef<IDirectDraw7>)> callback);
void setFullscreenWindow(HWND hwnd);
LONG setWindowStyle(LONG style);
LONG setWindowExStyle(LONG exStyle);
private:
static HRESULT create(CompatRef<IDirectDraw> dd);
void* m_ddObject;
HWND m_fullscreenWindow;
LONG m_fullscreenWindowStyle;
LONG m_fullscreenWindowExStyle;
};
}

View File

@ -228,6 +228,7 @@
<ClInclude Include="Config\Settings\DisplayResolution.h" />
<ClInclude Include="Config\Settings\ForceD3D9On12.h" />
<ClInclude Include="Config\Settings\FullscreenMode.h" />
<ClInclude Include="Config\Settings\RemoveBorders.h" />
<ClInclude Include="Config\Settings\RenderColorDepth.h" />
<ClInclude Include="Config\Settings\ResolutionScale.h" />
<ClInclude Include="Config\Settings\SpriteDetection.h" />

View File

@ -552,6 +552,9 @@
<ClInclude Include="Config\Settings\AltTabFix.h">
<Filter>Header Files\Config\Settings</Filter>
</ClInclude>
<ClInclude Include="Config\Settings\RemoveBorders.h">
<Filter>Header Files\Config\Settings</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Gdi\Gdi.cpp">

View File

@ -6,10 +6,12 @@
#include <Common/Hook.h>
#include <Common/Log.h>
#include <Common/ScopedSrwLock.h>
#include <Config/Config.h>
#include <Dll/Dll.h>
#include <DDraw/DirectDraw.h>
#include <DDraw/RealPrimarySurface.h>
#include <DDraw/Surfaces/PrimarySurface.h>
#include <DDraw/Surfaces/TagSurface.h>
#include <Gdi/CompatDc.h>
#include <Gdi/Cursor.h>
#include <Gdi/Dc.h>
@ -426,6 +428,22 @@ namespace
return reinterpret_cast<LONG>(oldWndProc);
}
}
else if ((GWL_STYLE == nIndex || GWL_EXSTYLE == nIndex) && Config::removeBorders.get())
{
auto tagSurface = DDraw::TagSurface::findFullscreenWindow(hWnd);
if (tagSurface)
{
if (GWL_STYLE == nIndex)
{
return tagSurface->setWindowStyle(dwNewLong);
}
else
{
return tagSurface->setWindowExStyle(dwNewLong);
}
}
}
return origSetWindowLong(hWnd, nIndex, dwNewLong);
}