Skip to content

Commit 671ccda

Browse files
authored
Merge branch 'master' into fix/improve-aclrequest-detection
2 parents bdd948b + 0f49768 commit 671ccda

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

+4728
-2854
lines changed
Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,62 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:v3="urn:schemas-microsoft-com:asm.v3">
3-
<assemblyIdentity type="win32" version="1.0.0.0" processorArchitecture="*" name="CEFLauncher" />
2+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
3+
xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
4+
manifestVersion="1.0">
5+
<assemblyIdentity type="win32"
6+
name="CEFLauncher"
7+
version="1.0.0.0"
8+
processorArchitecture="x86" />
49

5-
<v3:application>
6-
<windowsSettings>
7-
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
8-
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
9-
</windowsSettings>
10-
</v3:application>
10+
<description>MTA:SA CEF (Chromium Embedded Framework) Launcher</description>
1111

1212
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
1313
<application>
14-
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" /> <!-- Windows 10 and Windows 11 -->
15-
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" /> <!-- Windows 8.1 -->
16-
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" /> <!-- Windows 8 -->
17-
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" /> <!-- Windows 7 -->
14+
<!-- Windows 11 and Windows 10 -->
15+
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
16+
<!-- Windows 8.1 -->
17+
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
18+
<!-- Windows 8 -->
19+
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
20+
<!-- Windows 7 -->
21+
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
1822
</application>
1923
</compatibility>
2024

25+
<asmv3:application>
26+
<asmv3:windowsSettings
27+
xmlns:ws2005="http://schemas.microsoft.com/SMI/2005/WindowsSettings"
28+
xmlns:ws2013="http://schemas.microsoft.com/SMI/2013/WindowsSettings"
29+
xmlns:ws2016="http://schemas.microsoft.com/SMI/2016/WindowsSettings"
30+
xmlns:ws2017="http://schemas.microsoft.com/SMI/2017/WindowsSettings"
31+
xmlns:ws2019="http://schemas.microsoft.com/SMI/2019/WindowsSettings"
32+
xmlns:ws2020="http://schemas.microsoft.com/SMI/2020/WindowsSettings"
33+
xmlns:ws2024="http://schemas.microsoft.com/SMI/2024/WindowsSettings">
34+
<ws2005:dpiAware>true/pm</ws2005:dpiAware>
35+
<ws2016:dpiAwareness>PerMonitorV2, PerMonitor</ws2016:dpiAwareness>
36+
<ws2013:ultraHighResolutionScrollingAware>true</ws2013:ultraHighResolutionScrollingAware>
37+
<ws2016:longPathAware>true</ws2016:longPathAware>
38+
<ws2019:activeCodePage>UTF-8</ws2019:activeCodePage>
39+
<ws2020:heapType>SegmentHeap</ws2020:heapType>
40+
<ws2024:supportedArchitectures>x86</ws2024:supportedArchitectures>
41+
</asmv3:windowsSettings>
42+
</asmv3:application>
43+
2144
<dependency optional="yes">
2245
<dependentAssembly>
23-
<!-- Automatically use ComCtl32.dll version 6 or later. -->
24-
<assemblyIdentity
25-
type="win32"
26-
name="Microsoft.Windows.Common-Controls"
27-
version="6.0.0.0"
28-
processorArchitecture="*"
29-
publicKeyToken="6595b64144ccf1df"
30-
language="*" />
46+
<assemblyIdentity type="win32"
47+
name="Microsoft.Windows.Common-Controls"
48+
version="6.0.0.0"
49+
processorArchitecture="*"
50+
publicKeyToken="6595b64144ccf1df"
51+
language="*" />
3152
</dependentAssembly>
3253
</dependency>
54+
55+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
56+
<security>
57+
<requestedPrivileges>
58+
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
59+
</requestedPrivileges>
60+
</security>
61+
</trustInfo>
3362
</assembly>

Client/ceflauncher/Main.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,30 @@
2020
(set flag.new_cef_exe on the build server to generate new exe)
2121
*/
2222

23-
int _declspec(dllimport) InitCEF();
23+
#include <cstdlib>
24+
#include <functional>
2425

25-
using HINSTANCE = struct HINSTANCE__*;
26+
struct HINSTANCE__;
27+
using HINSTANCE = HINSTANCE__*;
2628
using LPSTR = char*;
2729

28-
int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdShow, int nCmdShow)
30+
[[nodiscard("InitCEF return value must be used")]] __declspec(dllimport) auto InitCEF() -> int;
31+
32+
// Users are faced with vague crashes in CEFLauncher.exe, so rather than over-engineering all this is intended
33+
// Do note that CEFLauncher.exe ends up hosting any GPU rendering processes of CEF
34+
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
2935
{
30-
return InitCEF();
36+
const auto init = std::function<int()>{InitCEF};
37+
const auto safe_invoke = [&]() noexcept -> int
38+
{
39+
try
40+
{
41+
return std::invoke_r<int>(init);
42+
}
43+
catch (...)
44+
{
45+
return EXIT_FAILURE;
46+
}
47+
};
48+
return safe_invoke();
3149
}

Client/ceflauncher/premake5.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ project "CEFLauncher"
2020
"*.manifest",
2121
}
2222

23+
filter "system:windows"
24+
buildoptions {
25+
"/Zc:inline",
26+
"/Zc:throwingNew",
27+
"/diagnostics:caret",
28+
"/sdl",
29+
"/guard:cf"
30+
}
31+
editandcontinue "Off"
32+
linkoptions { "/guard:cf" }
33+
34+
filter {"system:windows", "configurations:Debug"}
35+
defines { "_DEBUG" }
36+
runtime "Debug"
37+
38+
filter {"system:windows", "configurations:Release"}
39+
optimize "Speed"
40+
defines { "NDEBUG" }
41+
42+
filter {"system:windows", "configurations:Nightly"}
43+
optimize "Speed"
44+
defines { "NDEBUG" }
45+
2346
filter "architecture:not x86"
2447
flags { "ExcludeFromBuild" }
2548

Client/ceflauncher_DLL/Main.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "CCefApp.h"
2121
#include <string>
2222
#include <cef3/cef/include/cef_sandbox_win.h>
23+
#include <SharedUtil.h>
2324

2425
// #define CEF_ENABLE_SANDBOX
2526
#ifdef CEF_ENABLE_SANDBOX
@@ -30,15 +31,18 @@ DWORD WINAPI CheckParentProcessAliveness(LPVOID);
3031

3132
int _declspec(dllexport) InitCEF()
3233
{
33-
// Get absolute CEFLauncher.exe path
34-
TCHAR buffer[MAX_PATH];
35-
GetModuleFileName(NULL, buffer, MAX_PATH);
36-
std::wstring currentFileName(buffer);
37-
38-
// Extract MTA path and set DLL directory (absolute path is required here)
39-
size_t pos = currentFileName.find_last_of(L'\\');
40-
std::wstring mtaPath = currentFileName.substr(0, pos - 3); // Strip "CEF"
41-
SetDllDirectory(mtaPath.c_str());
34+
// Get MTA base directory and set DLL directory to MTA folder
35+
const SString strBaseDir = SharedUtil::GetMTAProcessBaseDir();
36+
37+
if (strBaseDir.empty())
38+
{
39+
// Unable to determine base directory - CEF cannot initialize
40+
return -1;
41+
}
42+
43+
const SString strMTADir = SharedUtil::PathJoin(strBaseDir, "MTA");
44+
45+
SetDllDirectoryW(SharedUtil::FromUTF8(strMTADir));
4246

4347
// Load libcef.dll from the DLL directory
4448
assert(SUCCEEDED(__HrLoadAllImportsForDll("libcef.dll")));
@@ -70,9 +74,10 @@ static DWORD WINAPI CheckParentProcessAliveness(LPVOID)
7074
{
7175
NTSTATUS(NTAPI * queryInformation)(HANDLE, PROCESSINFOCLASS, PVOID, ULONG, PULONG) = nullptr;
7276

73-
if (HMODULE const ntdll = GetModuleHandleW(L"ntdll.dll"); ntdll != nullptr)
77+
if (auto ntdll = GetModuleHandleW(L"ntdll.dll"); ntdll != nullptr)
7478
{
75-
queryInformation = reinterpret_cast<decltype(queryInformation)>(GetProcAddress(ntdll, "NtQueryInformationProcess"));
79+
auto procAddr = GetProcAddress(ntdll, "NtQueryInformationProcess");
80+
queryInformation = reinterpret_cast<decltype(queryInformation)>(reinterpret_cast<void*>(procAddr));
7681
}
7782

7883
if (queryInformation == nullptr)

Client/ceflauncher_DLL/premake5.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project "CEFLauncher DLL"
44
targetname "CEFLauncher_DLL"
55
targetdir(buildpath("mta/cef"))
66

7-
includedirs { "../../vendor/cef3/cef" }
7+
includedirs { "../../vendor/cef3/cef", "../../Shared/sdk" }
88
libdirs { "../../vendor/cef3/cef/Release" }
99

1010
defines { "UNICODE", "PSAPI_VERSION=1" }
@@ -19,10 +19,11 @@ project "CEFLauncher DLL"
1919
files {
2020
"premake5.lua",
2121
"*.h",
22-
"*.cpp"
22+
"*.cpp",
23+
"../../Shared/sdk/SharedUtil.cpp"
2324
}
2425

25-
links { "delayimp", "CEF", "libcef.lib", "Psapi.lib", "version.lib", "Winmm.lib", "Ws2_32.lib", "DbgHelp.lib" }
26+
links { "delayimp", "CEF", "libcef.lib", "Psapi.lib", "version.lib", "Winmm.lib", "Ws2_32.lib", "DbgHelp.lib" }
2627
linkoptions { "/DELAYLOAD:libcef.dll" }
2728

2829
filter "architecture:not x86"

Client/cefweb/CAjaxResourceHandler.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,16 @@ bool CAjaxResourceHandler::ReadResponse(void* data_out, int bytes_to_read, int&
8484
}
8585

8686
// Are we done?
87-
if (m_strResponse.length() - m_DataOffset <= 0)
87+
if (m_strResponse.length() - m_DataOffset <= 0) [[unlikely]]
8888
return false;
8989

90-
int copyBytes = std::min((uint)bytes_to_read, m_strResponse.length() - m_DataOffset);
90+
if (bytes_to_read <= 0) [[unlikely]]
91+
return false;
92+
93+
const size_t copyBytes = std::min(static_cast<size_t>(bytes_to_read), m_strResponse.length() - m_DataOffset);
9194

9295
memcpy(data_out, m_strResponse.c_str() + m_DataOffset, copyBytes);
93-
bytes_read = copyBytes;
96+
bytes_read = static_cast<int>(copyBytes);
9497

9598
m_DataOffset += copyBytes;
9699

0 commit comments

Comments
 (0)