Skip to content

Commit fe07759

Browse files
committed
Added ini file, added several options to the borderless addon.
Skip DLL load if the addon is disabled in the ini. Added SetWindowPos and MoveWindow hooks.
1 parent 88a4f04 commit fe07759

5 files changed

Lines changed: 259 additions & 99 deletions

File tree

BorderlessAddon/BorderlessAddon.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
</ItemDefinitionGroup>
155155
<ItemGroup>
156156
<ClInclude Include="dllheader.h" />
157+
<ClInclude Include="iniManager.h" />
157158
</ItemGroup>
158159
<ItemGroup>
159160
<ClCompile Include="dllmain.cpp" />

BorderlessAddon/BorderlessAddon.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<ClInclude Include="dllheader.h">
1919
<Filter>Header Files</Filter>
2020
</ClInclude>
21+
<ClInclude Include="iniManager.h">
22+
<Filter>Header Files</Filter>
23+
</ClInclude>
2124
</ItemGroup>
2225
<ItemGroup>
2326
<ClCompile Include="dllmain.cpp">

BorderlessAddon/dllheader.h

Lines changed: 24 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
33
#include <windows.h>
4-
4+
#include "iniManager.h"
55

66

77
void MemsetOverridePerms(uintptr_t address, BYTE* data, DWORD size);
@@ -25,44 +25,12 @@ namespace FunctionHooks
2525
HMENU hMenu,
2626
HINSTANCE hInstance,
2727
LPVOID lpParam
28-
)
29-
{
30-
if (!hWndParent)
31-
{
32-
//We assume this is the main window
33-
dwStyle &= ~WS_OVERLAPPEDWINDOW;
34-
dwExStyle &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
35-
auto result = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
36-
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
37-
if (!mainWindow) mainWindow = result;
38-
return result;
39-
}
40-
else return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
41-
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
42-
}
28+
);
4329

4430
LONG_PTR WINAPI HookSetWindowLongPtrA(
45-
HWND hWnd,
46-
int nIndex,
47-
LONG dwNewLong)
48-
{
49-
if (hWnd == mainWindow)
50-
{
51-
switch (nIndex)
52-
{
53-
case GWL_STYLE:
54-
dwNewLong &= ~WS_OVERLAPPEDWINDOW;
55-
break;
56-
case GWL_EXSTYLE:
57-
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
58-
break;
59-
default:
60-
61-
break;
62-
}
63-
}
64-
return SetWindowLongPtrA(hWnd, nIndex, dwNewLong);
65-
}
31+
HWND hWnd,
32+
int nIndex,
33+
LONG dwNewLong);
6634

6735
HWND WINAPI HookCreateWindowExW(
6836
DWORD dwExStyle,
@@ -77,41 +45,26 @@ namespace FunctionHooks
7745
HMENU hMenu,
7846
HINSTANCE hInstance,
7947
LPVOID lpParam
80-
)
81-
{
82-
if (!hWndParent)
83-
{
84-
//We assume this is the main window
85-
dwStyle &= ~WS_OVERLAPPEDWINDOW;
86-
dwExStyle &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
87-
auto result = CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
88-
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
89-
if (!mainWindow) mainWindow = result;
90-
return result;
91-
}
92-
else return CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
93-
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
94-
}
48+
);
9549
LONG_PTR WINAPI HookSetWindowLongPtrW(
9650
HWND hWnd,
9751
int nIndex,
98-
LONG dwNewLong)
99-
{
100-
if (hWnd == mainWindow)
101-
{
102-
switch (nIndex)
103-
{
104-
case GWL_STYLE:
105-
dwNewLong &= ~WS_OVERLAPPEDWINDOW;
106-
break;
107-
case GWL_EXSTYLE:
108-
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
109-
break;
110-
default:
111-
112-
break;
113-
}
114-
}
115-
return SetWindowLongPtrW(hWnd, nIndex, dwNewLong);
116-
}
52+
LONG dwNewLong);
53+
BOOL WINAPI HookSetWindowPos(
54+
HWND hWnd,
55+
HWND hWndInsertAfter,
56+
int X,
57+
int Y,
58+
int cx,
59+
int cy,
60+
UINT uFlags
61+
);
62+
BOOL WINAPI HookMoveWindow(
63+
HWND hWnd,
64+
int X,
65+
int Y,
66+
int nWidth,
67+
int nHeight,
68+
BOOL bRepaint
69+
);
11770
}

BorderlessAddon/dllmain.cpp

Lines changed: 193 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,43 +48,205 @@ void* GetIATFunctionAddress(BYTE* base, const char* dll_name, const char* search
4848
}
4949
return nullptr;
5050
}
51+
52+
53+
namespace FunctionHooks
54+
{
55+
56+
HWND WINAPI HookCreateWindowExA(
57+
DWORD dwExStyle,
58+
LPCSTR lpClassName,
59+
LPCSTR lpWindowName,
60+
DWORD dwStyle,
61+
int X,
62+
int Y,
63+
int nWidth,
64+
int nHeight,
65+
HWND hWndParent,
66+
HMENU hMenu,
67+
HINSTANCE hInstance,
68+
LPVOID lpParam
69+
)
70+
{
71+
if (!hWndParent)
72+
{
73+
//We assume this is the main window
74+
dwStyle &= ~WS_OVERLAPPEDWINDOW;
75+
dwExStyle &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
76+
auto result = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
77+
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
78+
if (!mainWindow) mainWindow = result;
79+
return result;
80+
}
81+
else return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
82+
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
83+
}
84+
85+
LONG_PTR WINAPI HookSetWindowLongPtrA(
86+
HWND hWnd,
87+
int nIndex,
88+
LONG dwNewLong)
89+
{
90+
if (hWnd == mainWindow)
91+
{
92+
switch (nIndex)
93+
{
94+
case GWL_STYLE:
95+
dwNewLong &= ~WS_OVERLAPPEDWINDOW;
96+
break;
97+
case GWL_EXSTYLE:
98+
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
99+
break;
100+
default:
101+
102+
break;
103+
}
104+
}
105+
return SetWindowLongPtrA(hWnd, nIndex, dwNewLong);
106+
}
107+
108+
HWND WINAPI HookCreateWindowExW(
109+
DWORD dwExStyle,
110+
LPCWSTR lpClassName,
111+
LPCWSTR lpWindowName,
112+
DWORD dwStyle,
113+
int X,
114+
int Y,
115+
int nWidth,
116+
int nHeight,
117+
HWND hWndParent,
118+
HMENU hMenu,
119+
HINSTANCE hInstance,
120+
LPVOID lpParam
121+
)
122+
{
123+
if (!hWndParent)
124+
{
125+
//We assume this is the main window
126+
dwStyle &= ~WS_OVERLAPPEDWINDOW;
127+
dwExStyle &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
128+
auto result = CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
129+
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
130+
if (!mainWindow || !::IsWindow(mainWindow)) mainWindow = result;
131+
return result;
132+
}
133+
else return CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y,
134+
nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
135+
}
136+
LONG_PTR WINAPI HookSetWindowLongPtrW(
137+
HWND hWnd,
138+
int nIndex,
139+
LONG dwNewLong)
140+
{
141+
if (hWnd == mainWindow)
142+
{
143+
switch (nIndex)
144+
{
145+
case GWL_STYLE:
146+
dwNewLong &= ~WS_OVERLAPPEDWINDOW;
147+
break;
148+
case GWL_EXSTYLE:
149+
dwNewLong &= ~(WS_EX_OVERLAPPEDWINDOW | WS_EX_TOPMOST);
150+
break;
151+
default:
152+
153+
break;
154+
}
155+
}
156+
return SetWindowLongPtrW(hWnd, nIndex, dwNewLong);
157+
}
158+
BOOL WINAPI HookSetWindowPos(
159+
HWND hWnd,
160+
HWND hWndInsertAfter,
161+
int X,
162+
int Y,
163+
int cx,
164+
int cy,
165+
UINT uFlags
166+
) {
167+
if (hWnd == mainWindow)
168+
{
169+
if (BorderlessSettings::WindowModeOverride == 1) hWndInsertAfter = HWND_TOPMOST;
170+
else if (BorderlessSettings::WindowModeOverride == 2) hWndInsertAfter = HWND_TOP;
171+
if (BorderlessSettings::EnableCustomWindowParameters)
172+
{
173+
cx = BorderlessSettings::CustomWindowParameters::CustomWidth;
174+
cy = BorderlessSettings::CustomWindowParameters::CustomHeight;
175+
X = BorderlessSettings::CustomWindowParameters::CustomPositionX;
176+
Y = BorderlessSettings::CustomWindowParameters::CustomPositionY;
177+
}
178+
}
179+
180+
return SetWindowPos(hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);
181+
}
182+
BOOL WINAPI HookMoveWindow(
183+
HWND hWnd,
184+
int X,
185+
int Y,
186+
int nWidth,
187+
int nHeight,
188+
BOOL bRepaint
189+
) {
190+
191+
if (hWnd == mainWindow && BorderlessSettings::EnableCustomWindowParameters)
192+
{
193+
nWidth = BorderlessSettings::CustomWindowParameters::CustomWidth;
194+
nHeight = BorderlessSettings::CustomWindowParameters::CustomHeight;
195+
X = BorderlessSettings::CustomWindowParameters::CustomPositionX;
196+
Y = BorderlessSettings::CustomWindowParameters::CustomPositionY;
197+
}
198+
return ::MoveWindow(hWnd, X, Y, nWidth, nHeight, bRepaint);
199+
200+
}
201+
}
202+
203+
204+
51205
//In the DLLMain, we create our hooks
52206
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID reserved)
53207
{
54-
208+
if (!BorderlessSettings::settingsSetUpComplete) SetUpDLLIniDir(hInstance);
209+
if (!BorderlessSettings::Enabled) return FALSE;
55210
//Process attach is where our library gets attached to the process
56211
//Therefore we create our hooks here
57-
if (dwReason == DLL_PROCESS_ATTACH) {
58-
59-
212+
if (dwReason == DLL_PROCESS_ATTACH) {
60213
//Since we do not need the thread library calls provided by the runtime, we disable them for our module
61-
DisableThreadLibraryCalls((HMODULE)hInstance);
214+
DisableThreadLibraryCalls((HMODULE)hInstance);
62215
//In these calls, we detour the original functions to our desired code paths.
63216
if (auto CreateWindowIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "CreateWindowExW"))
64217
{
65218
PatchAddressPointer((uintptr_t)CreateWindowIATAddress, (uintptr_t)&FunctionHooks::HookCreateWindowExW);
66-
void* SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrW");
67-
if (!SetWindowAddress) SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongW");
68-
if (SetWindowAddress)
219+
void* SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrW");
220+
if (!SetWindowLPtrIATAddress) SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongW");
221+
if (SetWindowLPtrIATAddress)
69222
{
70-
PatchAddressPointer((uintptr_t)SetWindowAddress, (uintptr_t)&FunctionHooks::HookSetWindowLongPtrW);
223+
PatchAddressPointer((uintptr_t)SetWindowLPtrIATAddress, (uintptr_t)&FunctionHooks::HookSetWindowLongPtrW);
71224
}
225+
72226
}
73227
if (auto CreateWindowIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "CreateWindowExA"))
74228
{
75229
PatchAddressPointer((uintptr_t)CreateWindowIATAddress, (uintptr_t)&FunctionHooks::HookCreateWindowExA);
76-
void* SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrA");
77-
if (!SetWindowAddress) SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongA");
78-
if (SetWindowAddress)
230+
void* SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrA");
231+
if (!SetWindowLPtrIATAddress) SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongA");
232+
if (SetWindowLPtrIATAddress)
79233
{
80-
PatchAddressPointer((uintptr_t)SetWindowAddress, (uintptr_t)&FunctionHooks::HookSetWindowLongPtrA);
234+
PatchAddressPointer((uintptr_t)SetWindowLPtrIATAddress, (uintptr_t)&FunctionHooks::HookSetWindowLongPtrA);
81235
}
82236

83237
}
84-
}
238+
if (auto SetWindowsPosIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowPos"))
239+
{
240+
PatchAddressPointer((uintptr_t)SetWindowsPosIATAddress, (uintptr_t)FunctionHooks::HookSetWindowPos);
241+
}
242+
if (auto MoveWindowIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "MoveWindow"))
243+
{
244+
PatchAddressPointer((uintptr_t)MoveWindowIATAddress, (uintptr_t)FunctionHooks::HookMoveWindow);
245+
}
246+
}
85247
//Detach message, which is where the process unloads all our changes.
86248
//Here, we return everything to its original state
87-
else if (dwReason == DLL_PROCESS_DETACH) {
249+
else if (dwReason == DLL_PROCESS_DETACH) {
88250
if (auto CreateWindowIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "CreateWindowExW"))
89251
{
90252
PatchAddressPointer((uintptr_t)CreateWindowIATAddress, (uintptr_t)::CreateWindowExW);
@@ -93,22 +255,25 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID reserved)
93255
{
94256
PatchAddressPointer((uintptr_t)CreateWindowIATAddress, (uintptr_t)::CreateWindowExA);
95257
}
96-
void* SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrW");
97-
if (!SetWindowAddress) SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongW");
98-
if (SetWindowAddress)
258+
void* SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrW");
259+
if (!SetWindowLPtrIATAddress) SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongW");
260+
if (SetWindowLPtrIATAddress)
261+
{
262+
PatchAddressPointer((uintptr_t)SetWindowLPtrIATAddress, (uintptr_t)SetWindowLongPtrW);
263+
}
264+
265+
266+
SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrA");
267+
if (!SetWindowLPtrIATAddress) SetWindowLPtrIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongA");
268+
if (SetWindowLPtrIATAddress)
99269
{
100-
PatchAddressPointer((uintptr_t)SetWindowAddress, (uintptr_t)SetWindowLongPtrW);
270+
PatchAddressPointer((uintptr_t)SetWindowLPtrIATAddress, (uintptr_t)SetWindowLongPtrA);
101271
}
102-
103-
104-
SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongPtrA");
105-
if (!SetWindowAddress) SetWindowAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowLongA");
106-
if (SetWindowAddress)
272+
if (auto SetWindowsPosIATAddress = GetIATFunctionAddress((BYTE*)GetModuleHandle(NULL), "USER32.dll", "SetWindowPos"))
107273
{
108-
PatchAddressPointer((uintptr_t)SetWindowAddress, (uintptr_t)SetWindowLongPtrA);
274+
PatchAddressPointer((uintptr_t)SetWindowsPosIATAddress, (uintptr_t)::SetWindowPos);
109275
}
110-
111276

112-
}
113-
return TRUE;
277+
}
278+
return TRUE;
114279
}

0 commit comments

Comments
 (0)