-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
307 lines (286 loc) · 12.2 KB
/
Copy pathMain.cpp
File metadata and controls
307 lines (286 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include "plugin.h"
#include <vector>
#include <filesystem>
using namespace plugin;
using namespace std;
uintptr_t gWndProc = 0;
uintptr_t gFullscreenAddr = 0;
LONG GetWindowedWindowStyle() {
return WS_VISIBLE | WS_MINIMIZEBOX | WS_POPUP;
}
LONG GetWindowedClassStyle() {
return CS_DBLCLKS | CS_CLASSDC;
}
bool &IsFullscreen() {
static bool isFullscreen = false;
return isFullscreen;
}
void EnableDPIAwareness() {
HMODULE hShcore = LoadLibraryA("Shcore.dll");
if (hShcore) {
typedef HRESULT(WINAPI *SetDpiAwarenessFunc)(int);
SetDpiAwarenessFunc SetProcessDpiAwareness = (SetDpiAwarenessFunc)GetProcAddress(hShcore, "SetProcessDpiAwareness");
if (SetProcessDpiAwareness)
SetProcessDpiAwareness(1);
FreeLibrary(hShcore);
}
else {
HMODULE hUser32 = LoadLibraryA("User32.dll");
if (hUser32) {
typedef BOOL(WINAPI *SetDPIAwareFunc)();
SetDPIAwareFunc SetProcessDPIAware = (SetDPIAwareFunc)GetProcAddress(hUser32, "SetProcessDPIAware");
if (SetProcessDPIAware)
SetProcessDPIAware();
FreeLibrary(hUser32);
}
}
}
struct WindowRect {
int X, Y, Width, Height;
};
WindowRect &InitialWindowRect() {
static WindowRect initialWindowRect;
return initialWindowRect;
}
WindowRect CalcWindowRect(int X, int Y, int Width, int Height, bool StoreInitialRect) {
WindowRect rect;
rect.X = X;
rect.Y = Y;
rect.Width = Width;
rect.Height = Height;
auto screenW = GetSystemMetrics(SM_CXMAXIMIZED);
auto screenH = GetSystemMetrics(SM_CYMAXIMIZED);
if (rect.Width < (screenW - 100) && rect.Height < (screenH - 100)) {
rect.X = screenW / 2 - rect.Width / 2;
rect.Y = screenH / 2 - rect.Height / 2;
}
else {
rect.X = 0;
rect.Y = 0;
rect.Height -= 1;
}
if (StoreInitialRect) {
static bool storedInitialRect = false;
if (!storedInitialRect) {
InitialWindowRect() = rect;
storedInitialRect = true;
}
}
return rect;
}
HWND __stdcall MyCreateWindowExA(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int Width, int Height, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) {
IsFullscreen() = dwStyle != GetWindowedWindowStyle();
if (!IsFullscreen()) {
EnableDPIAwareness();
auto rect = CalcWindowRect(X, Y, Width, Height, true);
HWND hWnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, GetWindowedWindowStyle(),
rect.X, rect.Y, rect.Width, rect.Height, hWndParent, hMenu, hInstance, lpParam);
SetWindowPos(hWnd, HWND_NOTOPMOST, rect.X, rect.Y, rect.Width, rect.Height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
return hWnd;
}
return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, Width, Height, hWndParent, hMenu, hInstance, lpParam);
}
char MyCreateWindowExA_14_restore[6];
uintptr_t CreateWindowRestoreAddr = 0;
HWND __stdcall MyCreateWindowExA_14(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int Width, int Height, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) {
if (CreateWindowRestoreAddr)
patch::MemCpy(CreateWindowRestoreAddr, MyCreateWindowExA_14_restore, 6);
if (*(uint32_t *)gFullscreenAddr == 0) {
EnableDPIAwareness();
auto rect = CalcWindowRect(X, Y, Width, Height, true);
HWND hWnd = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, GetWindowedWindowStyle(),
rect.X, rect.Y, rect.Width, rect.Height, hWndParent, hMenu, hInstance, lpParam);
SetWindowPos(hWnd, HWND_NOTOPMOST, rect.X, rect.Y, rect.Width, rect.Height, SWP_FRAMECHANGED | SWP_SHOWWINDOW);
return hWnd;
}
return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, Width, Height, hWndParent, hMenu, hInstance, lpParam);
}
LONG __stdcall MySetWindowLong(HWND hWnd, int nIndex, LONG dwNewLong) {
if (!IsFullscreen())
return SetWindowLongA(hWnd, nIndex, GetWindowedWindowStyle());
return SetWindowLongA(hWnd, nIndex, dwNewLong);
}
HWND __stdcall MyCreateWindowExA_10(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int Width, int Height, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam) {
EnableDPIAwareness();
return CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, Width, Height, hWndParent, hMenu, hInstance, lpParam);
}
LONG __stdcall MySetWindowLong_10(HWND hWnd, int nIndex, LONG dwNewLong) {
IsFullscreen() = true;
if (dwNewLong == 0x10CF0000) {
dwNewLong = GetWindowedWindowStyle();
IsFullscreen() = false;
}
return SetWindowLongA(hWnd, nIndex, dwNewLong);
}
BOOL __stdcall MyMoveWindow(HWND hWnd, int X, int Y, int Width, int Height, BOOL bRepaint) {
auto rect = CalcWindowRect(X, Y, Width, Height, true);
return MoveWindow(hWnd, rect.X, rect.Y, rect.Width, rect.Height, bRepaint);
}
BOOL __stdcall MyAdjustWindowRect(LPRECT lpRect, DWORD dwStyle, BOOL bMenu) {
return AdjustWindowRect(lpRect, GetWindowedWindowStyle(), bMenu);
}
int __stdcall MyWndProc(HWND hWnd, UINT uCmd, WPARAM wParam, LPARAM lParam) {
bool isWindowed = false;
if (gFullscreenAddr)
isWindowed = *(uint32_t *)gFullscreenAddr == 0;
else
isWindowed = !IsFullscreen();
if (isWindowed) {
static POINT ptStart;
static POINT ptOffset;
static BOOL bDragging = FALSE;
static const unsigned int BORDERLESS_MOVEBAR_HEIGHT = 20;
if (uCmd == WM_LBUTTONDOWN) {
if (!bDragging) {
GetCursorPos(&ptStart);
RECT rect;
GetWindowRect(hWnd, &rect);
ptOffset.x = ptStart.x - rect.left;
ptOffset.y = ptStart.y - rect.top;
if (ptStart.y <= (rect.top + BORDERLESS_MOVEBAR_HEIGHT)) {
bDragging = TRUE;
SetCapture(hWnd);
}
}
}
else if (uCmd == WM_MOUSEMOVE) {
if (bDragging) {
POINT pt;
GetCursorPos(&pt);
int dx = pt.x - ptStart.x;
int dy = pt.y - ptStart.y;
RECT rect;
GetWindowRect(hWnd, &rect);
MoveWindow(hWnd, rect.left + dx, rect.top + dy, rect.right - rect.left, rect.bottom - rect.top, TRUE);
ptStart = pt;
}
}
else if (uCmd == WM_LBUTTONUP) {
bDragging = FALSE;
ReleaseCapture();
}
else if (uCmd == WM_LBUTTONDBLCLK) {
POINT pt;
GetCursorPos(&pt);
ScreenToClient(hWnd, &pt);
RECT rect;
GetClientRect(hWnd, &rect);
if (pt.y <= BORDERLESS_MOVEBAR_HEIGHT) {
MoveWindow(hWnd, InitialWindowRect().X, InitialWindowRect().Y,
InitialWindowRect().Width, InitialWindowRect().Height, TRUE);
}
}
}
return CallMethodAndReturnDynGlobal<int>(gWndProc, 0, hWnd, uCmd, wParam, lParam);
}
void NopWinapiMethod(uintptr_t address, uint32_t numParams) {
patch::SetUChar(address, 0x83);
patch::SetUChar(address + 1, 0xC4);
patch::SetUChar(address + 2, numParams * 4);
patch::Nop(address + 3, 3);
}
int MyPrintf(const char *Format, ...) {
return 0;
}
class FifaBorderlessMode {
public:
FifaBorderlessMode() {
if (!CheckPluginName(Magic<'B','o','r','d','e','r','l','e','s','s','M','o','d','e','.','a','s','i'>()))
return;
auto v = FIFA::GetAppVersion();
switch (v.id()) {
case ID_FIFA14_1700:
patch::SetUInt(0x14DC296 + 3, GetWindowedClassStyle());
patch::SetUInt(0x14DC2F3 + 1, GetWindowedWindowStyle());
CreateWindowRestoreAddr = 0x14DC382;
patch::MemCpy(MyCreateWindowExA_14_restore, CreateWindowRestoreAddr, 6);
patch::Nop(0x14DC382, 1);
patch::RedirectCall(0x14DC382 + 1, MyCreateWindowExA_14);
gWndProc = patch::SetPointer(0x14DC28F + 3, MyWndProc);
gFullscreenAddr = 0x49EAAFC;
break;
case ID_FIFA14_1400_3DM:
patch::SetUInt(0x14E6876 + 3, GetWindowedClassStyle());
patch::SetUInt(0x14E68D3 + 1, GetWindowedWindowStyle());
//CreateWindowRestoreAddr = 0x14E6962;
//patch::MemCpy(MyCreateWindowExA_14_restore, CreateWindowRestoreAddr, 6);
//patch::Nop(0x14E6962, 1);
//patch::RedirectCall(0x14E6962 + 1, MyCreateWindowExA_14);
gWndProc = patch::SetPointer(0x14E686F + 3, MyWndProc);
patch::SetPointer(0x3BD5A68, MyCreateWindowExA);
gFullscreenAddr = 0x4994ACC;
break;
case ID_FIFA13_1700_RLD:
patch::SetUInt(0x12A517D + 3, GetWindowedClassStyle());
patch::SetUInt(0x12A51DA + 1, GetWindowedWindowStyle());
patch::RedirectCall(0x12A5269, MyCreateWindowExA);
patch::Nop(0x12A5269 + 5, 1);
patch::RedirectCall(0x12A3A3E, MySetWindowLong);
patch::Nop(0x12A3A3E + 5, 1);
gWndProc = patch::GetUInt(0x12A5176 + 3);
patch::SetPointer(0x12A5176 + 3, MyWndProc);
break;
case ID_FIFA13_1800:
patch::SetUInt(0x12A21FD + 3, GetWindowedClassStyle());
patch::SetUInt(0x12A225A + 1, GetWindowedWindowStyle());
patch::RedirectCall(0x12A22E9, MyCreateWindowExA);
patch::Nop(0x12A22E9 + 5, 1);
patch::RedirectCall(0x12A0ABE, MySetWindowLong);
patch::Nop(0x12A0ABE + 5, 1);
gWndProc = patch::GetUInt(0x12A21F6 + 3);
patch::SetPointer(0x12A21F6 + 3, MyWndProc);
break;
case ID_FIFA12_1700:
patch::SetUInt(0xB9E92B + 4, GetWindowedClassStyle());
patch::SetUInt(0xB9E997 + 1, GetWindowedWindowStyle());
patch::RedirectCall(0x1650648, MyCreateWindowExA);
patch::Nop(0x1650648 + 5, 1);
gWndProc = patch::GetUInt(0xB9E923 + 4);
patch::SetPointer(0xB9E923 + 4, MyWndProc);
patch::Nop(0xE55D45, 6);
break;
case ID_FIFA12_1500_SKD:
patch::SetUInt(0xB9CB1B + 4, GetWindowedClassStyle());
patch::SetUInt(0xB9CB87 + 1, GetWindowedWindowStyle());
patch::RedirectCall(0xB9CC27, MyCreateWindowExA);
patch::Nop(0xB9CC27 + 5, 1);
gWndProc = patch::GetUInt(0xB9CB13 + 4);
patch::SetPointer(0xB9CB13 + 4, MyWndProc);
patch::Nop(0xE52745, 6);
break;
case ID_FIFA12_1000_RLD:
patch::SetUInt(0x51CF14 + 4, GetWindowedClassStyle());
patch::SetUInt(0x51CF80 + 1, GetWindowedWindowStyle());
patch::RedirectCall(0x51D020, MyCreateWindowExA);
patch::Nop(0x51D020 + 5, 1);
gWndProc = patch::GetUInt(0x51CF0C + 4);
patch::SetPointer(0x51CF0C + 4, MyWndProc);
patch::Nop(0x80C7E5, 6);
break;
case ID_FIFA11_1010_FLT:
case ID_FIFA11_1010:
patch::SetUInt(0x8EA752 + 4, GetWindowedClassStyle());
patch::SetUInt(0x8EA7BD + 1, GetWindowedWindowStyle());
patch::RedirectCall(0x8EA856, MyCreateWindowExA);
patch::Nop(0x8EA856 + 5, 1);
gWndProc = patch::GetUInt(0x8EA74A + 4);
patch::SetPointer(0x8EA74A + 4, MyWndProc);
break;
case ID_FIFA09_1200_RZR:
//patch::SetUChar(0x6208BA + 2, GetWindowedClassStyle());
//patch::RedirectCall(0x620939, MyCreateWindowExA_10);
//patch::Nop(0x620939 + 5, 1);
//patch::RedirectCall(0x61F7E0, MySetWindowLong_10);
//patch::Nop(0x61F7E0 + 5, 1);
//patch::RedirectCall(0x61F816, MyMoveWindow);
//patch::Nop(0x61F816 + 5, 1);
//patch::RedirectCall(0x61F7EE, MyAdjustWindowRect);
//patch::Nop(0x61F7EE + 5, 1);
//NopWinapiMethod(0x61F8F9, 2);
//NopWinapiMethod(0x61F96B, 2);
//patch::Nop(0x62CD13, 26);
////gWndProc = patch::SetPointer(0x620878 + 4, MyWndProc);
break;
}
}
} fifaBorderlessMode;