Skip to content

Commit 299c5c4

Browse files
authored
Merge branch 'master' into l10n/master
2 parents 284c8fd + 44d0fad commit 299c5c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3349
-757
lines changed

Client/core/CCrashDumpWriter.cpp

Lines changed: 1077 additions & 260 deletions
Large diffs are not rendered by default.

Client/core/CExceptionInformation_Impl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include <SharedUtil.Misc.h>
1314

1415
#define MAX_MODULE_PATH 512
1516

@@ -149,16 +150,16 @@ bool CExceptionInformation_Impl::GetModule(void* pQueryAddress, char* szOutputBu
149150
* See if we're able to use GetModuleHandleExA. According to Microsoft,
150151
* this API is only available on Windows XP and Vista.
151152
*/
152-
auto pfnGetModuleHandleExA = reinterpret_cast<_pfnGetModuleHandleExA>(static_cast<void*>(GetProcAddress(hKern32, "GetModuleHandleExA")));
153+
_pfnGetModuleHandleExA pfnGetModuleHandleExA = nullptr;
154+
if (!SharedUtil::TryGetProcAddress(hKern32, "GetModuleHandleExA", pfnGetModuleHandleExA))
155+
return false;
153156

154157
/*
155158
* TODO: Possibly use our own code to do this for other systems.
156159
* It is possible to enumerate all modules and get their starting/ending
157160
* offsets, so it would just be a simple comparison of addresses to
158161
* do this...
159162
*/
160-
if (NULL == pfnGetModuleHandleExA)
161-
return false;
162163

163164
if (0 == pfnGetModuleHandleExA(0x00000004 /*GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS*/, (LPCSTR)pQueryAddress, &hModule))
164165
{

Client/core/CModManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include <SharedUtil.Misc.h>
1314
#include "CModManager.h"
1415
#define DECLARE_PROFILER_SECTION_CModManager
1516
#include "profiler/SharedUtil.Profiler.h"
@@ -186,17 +187,16 @@ bool CModManager::TryStart()
186187
return false;
187188
}
188189

189-
CClientBase* (__cdecl * InitClient)() = nullptr;
190-
InitClient = reinterpret_cast<decltype(InitClient)>(static_cast<void*>(GetProcAddress(library, "InitClient")));
191-
192-
if (InitClient == nullptr)
190+
using InitClientFn = CClientBase* (__cdecl*)();
191+
InitClientFn initClient = nullptr;
192+
if (!SharedUtil::TryGetProcAddress(library, "InitClient", initClient))
193193
{
194194
CCore::GetSingleton().GetConsole()->Printf("Unable to initialize deathmatch's DLL (missing init)");
195195
FreeLibrary(library);
196196
return false;
197197
}
198198

199-
CClientBase* client = InitClient();
199+
CClientBase* client = initClient();
200200

201201
if (client == nullptr || client->ClientInitialize(m_arguments.c_str(), CCore::GetSingletonPtr()) != 0)
202202
{

Client/core/CModuleLoader.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*****************************************************************************/
1111

1212
#include "StdInc.h"
13+
#include <SharedUtil.Misc.h>
1314

1415
using std::string;
1516

@@ -62,14 +63,14 @@ PVOID CModuleLoader::GetFunctionPointer(const string& FunctionName)
6263
{
6364
if (m_bStatus)
6465
{
65-
FARPROC fpProcAddr;
66-
67-
fpProcAddr = GetProcAddress(m_hLoadedModule, FunctionName.c_str());
66+
FARPROC fpProcAddr = nullptr;
67+
if (!SharedUtil::TryGetProcAddress(m_hLoadedModule, FunctionName.c_str(), fpProcAddr))
68+
return nullptr;
6869

6970
return static_cast<PVOID>(fpProcAddr);
7071
}
7172
else
72-
return NULL;
73+
return nullptr;
7374
}
7475

7576
const SString& CModuleLoader::GetLastErrorMessage() const

Client/core/CSteamClient.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <WinTrust.h>
1616
#include <SoftPub.h>
1717
#include <Psapi.h>
18+
#include <SharedUtil.Misc.h>
1819

1920
#define STEAM_GTASA_APP_ID "12120"
2021

@@ -46,6 +47,33 @@ struct HandleDeleter
4647

4748
using HandleScope = std::unique_ptr<std::remove_pointer_t<HANDLE>, HandleDeleter>;
4849

50+
namespace
51+
{
52+
DWORD GetProcessBaseName(HANDLE process, LPWSTR buffer, DWORD bufferLength)
53+
{
54+
using ModuleBaseNameFn = DWORD(WINAPI*)(HANDLE, HMODULE, LPWSTR, DWORD);
55+
ModuleBaseNameFn moduleBaseNameFn = nullptr;
56+
57+
if (HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); kernel32 != nullptr)
58+
{
59+
if (SharedUtil::TryGetProcAddress(kernel32, "K32GetModuleBaseNameW", moduleBaseNameFn) ||
60+
SharedUtil::TryGetProcAddress(kernel32, "GetModuleBaseNameW", moduleBaseNameFn))
61+
{
62+
return moduleBaseNameFn(process, nullptr, buffer, bufferLength);
63+
}
64+
}
65+
66+
HMODULE psapi = GetModuleHandleW(L"psapi.dll");
67+
if (psapi == nullptr)
68+
psapi = LoadLibraryW(L"psapi.dll");
69+
70+
if (psapi != nullptr && SharedUtil::TryGetProcAddress(psapi, "GetModuleBaseNameW", moduleBaseNameFn))
71+
return moduleBaseNameFn(process, nullptr, buffer, bufferLength);
72+
73+
return 0;
74+
}
75+
} // namespace
76+
4977
struct SignerInfo
5078
{
5179
SignerInfo(HCRYPTMSG Msg)
@@ -325,7 +353,7 @@ static bool IsSteamProcess(DWORD pid)
325353

326354
wchar_t processName[MAX_PATH];
327355

328-
if (!GetModuleBaseNameW(process, nullptr, processName, sizeof(processName) / sizeof(wchar_t)))
356+
if (GetProcessBaseName(process, processName, static_cast<DWORD>(sizeof(processName) / sizeof(processName[0]))) == 0)
329357
return false;
330358

331359
if (wcsicmp(processName, L"steam.exe") != 0)
@@ -380,7 +408,10 @@ bool CSteamClient::Load()
380408
static auto pAddDllDirectory = ([]() -> decltype(&AddDllDirectory) {
381409
if (const HMODULE kernel32 = GetModuleHandleW(L"kernel32.dll"); kernel32 != nullptr)
382410
{
383-
return reinterpret_cast<decltype(&AddDllDirectory)>(static_cast<void*>(GetProcAddress(kernel32, "AddDllDirectory")));
411+
decltype(&AddDllDirectory) addDllDirectory = nullptr;
412+
if (!SharedUtil::TryGetProcAddress(kernel32, "AddDllDirectory", addDllDirectory))
413+
return nullptr;
414+
return addDllDirectory;
384415
}
385416

386417
return nullptr;
@@ -439,10 +470,8 @@ bool CSteamClient::Load()
439470
}
440471

441472
releaseLibraryLock.reset();
442-
443-
Native::CreateInterface = reinterpret_cast<decltype(Native::CreateInterface)>(static_cast<void*>(GetProcAddress(dll, "CreateInterface")));
444473

445-
if (!Native::CreateInterface)
474+
if (!SharedUtil::TryGetProcAddress(dll, "CreateInterface", Native::CreateInterface))
446475
{
447476
FreeLibrary(dll);
448477
return false;

0 commit comments

Comments
 (0)