Skip to content

Commit 5f84805

Browse files
committed
Update to version 2.0
- Rewrite the patch in C and simplify the code - Remove MinHook source code zip file - Code cleanup
1 parent 99c6c0b commit 5f84805

7 files changed

+186
-226
lines changed

CMakeLists.txt

+1-11
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ if(NOT (CMAKE_SIZEOF_VOID_P EQUAL 4))
77
message(FATAL_ERROR "Only 32-bit is supported.")
88
endif()
99

10-
if(MINGW)
11-
option(BUILD_MINGW_STATIC "Use MinGW static runtime" ON)
12-
endif()
13-
1410
# Find MinHook
1511
set(MINHOOK_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/minhook/include)
1612

@@ -19,7 +15,7 @@ if(MINGW)
1915
endif()
2016

2117
add_library(NoRegPatch SHARED
22-
NoRegPatch.cpp
18+
NoRegPatch.c
2319
version.rc
2420
GalaxyWrp.def
2521
)
@@ -28,11 +24,5 @@ set_target_properties(NoRegPatch PROPERTIES PREFIX "")
2824
set_target_properties(NoRegPatch PROPERTIES OUTPUT_NAME "GalaxyWrp")
2925
set_target_properties(NoRegPatch PROPERTIES SUFFIX ".dll")
3026

31-
if(BUILD_MINGW_STATIC)
32-
target_link_options(NoRegPatch PRIVATE -static -static-libgcc -static-libstdc++)
33-
endif()
34-
3527
target_include_directories(NoRegPatch PRIVATE ${MINHOOK_INCLUDE_DIR})
36-
3728
target_link_libraries(NoRegPatch ${MINHOOK_LIBRARY})
38-

GalaxyWrp.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ EXPORTS
4949
Steam_GetHSteamUserCurrent = orig_GalaxyWrp.Steam_GetHSteamUserCurrent
5050
Steam_RegisterInterfaceFuncs = orig_GalaxyWrp.Steam_RegisterInterfaceFuncs
5151
Steam_RunCallbacks = orig_GalaxyWrp.Steam_RunCallbacks
52-
g_pSteamClientGameServer = orig_GalaxyWrp.g_pSteamClientGameServer
52+
g_pSteamClientGameServer = orig_GalaxyWrp.g_pSteamClientGameServer

LICENSE.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
No-Registry Patch for Fallout New Vegas
22

3-
Copyright (C) 2021 TANGaming <https://github.com/TAN-Gaming>
3+
Copyright (C) 2021-2023 TANGaming <https://github.com/TAN-Gaming>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

NoRegPatch.c

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/*
2+
* No-Registry Patch for Fallout New Vegas
3+
*
4+
* Copyright (C) 2021-2023 TANGaming <https://github.com/TAN-Gaming>
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
#include <windows.h>
26+
#include <strsafe.h>
27+
28+
#include <MinHook.h>
29+
30+
typedef LONG (WINAPI *PFREGOPENKEYEXW)(HKEY, LPCWSTR, DWORD, REGSAM, PHKEY);
31+
typedef LONG (WINAPI *PFREGQUERYVALUEEXW)(HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD);
32+
typedef LONG (WINAPI *PFREGCLOSEKEY)(HKEY);
33+
34+
/* For calling original functions */
35+
PFREGOPENKEYEXW Real_RegOpenKeyExW = NULL;
36+
PFREGQUERYVALUEEXW Real_RegQueryValueExW = NULL;
37+
PFREGCLOSEKEY Real_RegCloseKey = NULL;
38+
39+
BOOL bUseHooked = FALSE;
40+
LPWSTR pszGameDir = NULL;
41+
42+
LPWSTR NoRegPatch_GetGameDir(void)
43+
{
44+
DWORD dwRet;
45+
LPWSTR pszPath;
46+
47+
dwRet = GetCurrentDirectoryW(0, NULL);
48+
if (dwRet == 0)
49+
return NULL;
50+
51+
/* NOTE: Included the length of '\' (1) */
52+
pszPath = HeapAlloc(GetProcessHeap(), 0, (dwRet + 1) * sizeof(WCHAR));
53+
if (!pszPath)
54+
return NULL;
55+
56+
if (GetCurrentDirectoryW(dwRet, pszPath) == 0)
57+
{
58+
HeapFree(GetProcessHeap(), 0, pszPath);
59+
return NULL;
60+
}
61+
62+
StringCchCatW(pszPath, dwRet + 1, L"\\");
63+
64+
return pszPath;
65+
}
66+
67+
/* Hooked RegOpenKeyExW */
68+
LONG WINAPI Hooked_RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
69+
{
70+
if (_wcsicmp(lpSubKey, L"Software\\Bethesda Softworks\\FalloutNV") == 0)
71+
{
72+
bUseHooked = TRUE;
73+
return ERROR_SUCCESS;
74+
}
75+
76+
return Real_RegOpenKeyExW(hKey, lpSubKey, ulOptions, samDesired, phkResult);
77+
}
78+
79+
/* Hooked RegQueryValueExW */
80+
LONG WINAPI Hooked_RegQueryValueExW(HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
81+
{
82+
if (bUseHooked)
83+
{
84+
if (wcscmp(lpValueName, L"Installed Path") == 0)
85+
{
86+
DWORD cbData = (wcslen(pszGameDir) + 1) * sizeof(WCHAR);
87+
88+
if (!lpData && lpcbData)
89+
{
90+
*lpcbData = cbData;
91+
return ERROR_SUCCESS;
92+
}
93+
else if (lpData && (lpcbData && (*lpcbData >= cbData)))
94+
{
95+
memcpy(lpData, pszGameDir, cbData);
96+
*lpcbData = cbData;
97+
return ERROR_SUCCESS;
98+
}
99+
}
100+
}
101+
102+
return Real_RegQueryValueExW(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
103+
}
104+
105+
/* Hooked RegCloseKey */
106+
LONG WINAPI Hooked_RegCloseKey(HKEY hKey)
107+
{
108+
bUseHooked = FALSE;
109+
return Real_RegCloseKey(hKey);
110+
}
111+
112+
void NoRegPatch_Init(void)
113+
{
114+
/* Get game folder path */
115+
pszGameDir = NoRegPatch_GetGameDir();
116+
if (!pszGameDir)
117+
{
118+
MessageBoxW(NULL, L"Failed to retrieve the game directory.", L"NoRegPatch", MB_ICONERROR | MB_OK);
119+
TerminateProcess(GetCurrentProcess(), 0);
120+
}
121+
122+
/* Initialize MinHook */
123+
if (MH_Initialize() != MH_OK)
124+
{
125+
MessageBoxW(NULL, L"Failed to initialize MinHook.", L"NoRegPatch", MB_ICONERROR | MB_OK);
126+
TerminateProcess(GetCurrentProcess(), 0);
127+
}
128+
129+
MH_CreateHook((LPVOID*)(&RegOpenKeyExW), (LPVOID*)(&Hooked_RegOpenKeyExW), (LPVOID*)(&Real_RegOpenKeyExW));
130+
MH_CreateHook((LPVOID*)(&RegQueryValueExW), (LPVOID*)(&Hooked_RegQueryValueExW), (LPVOID*)(&Real_RegQueryValueExW));
131+
MH_CreateHook((LPVOID*)(&RegCloseKey), (LPVOID*)(&Hooked_RegCloseKey), (LPVOID*)(&Real_RegCloseKey));
132+
133+
MH_EnableHook(MH_ALL_HOOKS);
134+
}
135+
136+
void NoRegPatch_Uninit(void)
137+
{
138+
MH_DisableHook(MH_ALL_HOOKS);
139+
140+
/* Uninitialize MinHook. */
141+
MH_Uninitialize();
142+
143+
HeapFree(GetProcessHeap(), 0, pszGameDir);
144+
}
145+
146+
/* DLL entry point */
147+
BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD dwReason, LPVOID lpReserved)
148+
{
149+
if (dwReason == DLL_PROCESS_ATTACH)
150+
{
151+
NoRegPatch_Init();
152+
}
153+
else if (dwReason == DLL_PROCESS_DETACH)
154+
{
155+
NoRegPatch_Uninit();
156+
}
157+
158+
return TRUE;
159+
}

NoRegPatch.cpp

-188
This file was deleted.

minhook/minhook-master.zip

-66.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)