This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dllmain.cpp
139 lines (110 loc) · 4.01 KB
/
dllmain.cpp
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
// NFS Underground - proper windowed mode
// by Xan/Tenjoin
#include "stdafx.h"
#include "stdio.h"
#include <windows.h>
#include "..\includes\injector\injector.hpp"
#include "..\includes\IniReader.h"
bool bEnableWindowed = false;
bool bBorderlessWindowed = false;
bool bEnableWindowResize = false;
bool bRelocateWindow = false;
int RelocateX = 0;
int RelocateY = 0;
int DesktopX = 0;
int DesktopY = 0;
int WSFixResX = 0;
int WSFixResY = 0;
HWND GameHWND = NULL;
RECT windowRect;
int GetDesktopRes(int32_t* DesktopResW, int32_t* DesktopResH)
{
HMONITOR monitor = MonitorFromWindow(GetDesktopWindow(), MONITOR_DEFAULTTONEAREST);
MONITORINFO info = {};
info.cbSize = sizeof(MONITORINFO);
GetMonitorInfo(monitor, &info);
*DesktopResW = info.rcMonitor.right - info.rcMonitor.left;
*DesktopResH = info.rcMonitor.bottom - info.rcMonitor.top;
return 0;
}
BOOL WINAPI AdjustWindowRect_Hook(LPRECT lpRect, DWORD dwStyle, BOOL bMenu)
{
DWORD newStyle = 0;
if (!bBorderlessWindowed)
newStyle = WS_CAPTION;
return AdjustWindowRect(lpRect, newStyle, bMenu);
}
HWND WINAPI CreateWindowExA_Hook(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
{
int WindowPosX = RelocateX;
int WindowPosY = RelocateY;
GetDesktopRes(&DesktopX, &DesktopY);
if (!bRelocateWindow)
{
// fix the window to open at the center of the screen...
WindowPosX = (int)(((float)DesktopX / 2.0f) - ((float)nWidth / 2.0f));
WindowPosY = (int)(((float)DesktopY / 2.0f) - ((float)nHeight / 2.0f));
}
GameHWND = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, 0, WindowPosX, WindowPosY, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
LONG lStyle = GetWindowLong(GameHWND, GWL_STYLE);
if (bBorderlessWindowed)
lStyle &= ~(WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_SYSMENU);
else
{
lStyle |= (WS_MINIMIZEBOX | WS_SYSMENU);
if (bEnableWindowResize)
lStyle |= (WS_MAXIMIZEBOX | WS_THICKFRAME);
}
SetWindowLong(GameHWND, GWL_STYLE, lStyle);
SetWindowPos(GameHWND, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);
return GameHWND;
}
void InitConfig()
{
CIniReader inireader("");
bEnableWindowed = inireader.ReadInteger("NFSUWindow", "EnableWindowed", 0);
bBorderlessWindowed = inireader.ReadInteger("NFSUWindow", "BorderlessWindowed", 0);
bEnableWindowResize = inireader.ReadInteger("NFSUWindow", "EnableWindowResize", 0);
bRelocateWindow = inireader.ReadInteger("NFSUWindow", "RelocateWindow", 0);
if (bRelocateWindow)
{
RelocateX = inireader.ReadInteger("WindowLocation", "X", 0);
RelocateY = inireader.ReadInteger("WindowLocation", "Y", 0);
}
}
void InitWSFixConfig()
{
CIniReader inireader("NFSUnderground.WidescreenFix.ini");
WSFixResX = inireader.ReadInteger("MAIN", "ResX", 0);
WSFixResY = inireader.ReadInteger("MAIN", "ResY", 0);
if ((!WSFixResX) || (!WSFixResY))
GetDesktopRes(&WSFixResX, &WSFixResY);
}
int Init()
{
// skip SetWindowLong because it messes things up (also negates icon fixes by widescreen fix but oh well)
injector::MakeJMP(0x00408AA1, 0x00408AB5, true);
// hook the offending functions
injector::MakeNOP(0x004089B1, 6, true);
injector::MakeCALL(0x004089B1, CreateWindowExA_Hook, true);
injector::MakeNOP(0x00408975, 6, true);
injector::MakeCALL(0x00408975, AdjustWindowRect_Hook, true);
injector::MakeNOP(0x004086CB, 2, true); // perhaps not necessary
if (bEnableWindowed)
*(int*)0x0073637C = 1;
// initial ResX
*(int*)0x00701034 = WSFixResX;
// initial ResY
*(int*)0x00701038 = WSFixResY;
return 0;
}
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD reason, LPVOID /*lpReserved*/)
{
if (reason == DLL_PROCESS_ATTACH)
{
InitConfig();
InitWSFixConfig();
Init();
}
return TRUE;
}