Skip to content

Commit

Permalink
Merge branch 'master' into add-resource_client_file_checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha authored Oct 23, 2024
2 parents a63b5c9 + 792d9aa commit abf546c
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 226 deletions.
7 changes: 7 additions & 0 deletions Client/cefweb/CWebApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ CefRefPtr<CefResourceHandler> CWebApp::HandleError(const SString& strError, unsi

void CWebApp::OnBeforeCommandLineProcessing(const CefString& process_type, CefRefPtr<CefCommandLine> command_line)
{
CWebCore* pWebCore = static_cast<CWebCore*>(g_pCore->GetWebCore());

if (!pWebCore->GetGPUEnabled())
command_line->AppendSwitch("disable-gpu");

command_line->AppendSwitch("disable-gpu-compositing"); // always disable this, causes issues with official builds

// command_line->AppendSwitch("disable-d3d11");
command_line->AppendSwitch("enable-begin-frame-scheduling");

Expand Down
10 changes: 9 additions & 1 deletion Client/cefweb/CWebCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ CWebCore::~CWebCore()
delete m_pXmlConfig;
}

bool CWebCore::Initialise()
bool CWebCore::Initialise(bool gpuEnabled)
{
CefMainArgs mainArgs;
void* sandboxInfo = nullptr;

m_bGPUEnabled = gpuEnabled;

CefRefPtr<CWebApp> app(new CWebApp);

#ifdef CEF_ENABLE_SANDBOX
Expand Down Expand Up @@ -869,3 +872,8 @@ void CWebCore::StaticFetchBlacklistFinished(const SHttpDownloadResult& result)
OutputDebugLine("Updated browser blacklist!");
#endif
}

bool CWebCore::GetGPUEnabled() const noexcept
{
return m_bGPUEnabled;
}
7 changes: 6 additions & 1 deletion Client/cefweb/CWebCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CWebCore : public CWebCoreInterface
public:
CWebCore();
~CWebCore();
bool Initialise() override;
bool Initialise(bool gpuEnabled) override;

CWebViewInterface* CreateWebView(unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem, bool bTransparent);
void DestroyWebView(CWebViewInterface* pWebViewInterface);
Expand Down Expand Up @@ -108,6 +108,8 @@ class CWebCore : public CWebCoreInterface
static void StaticFetchWhitelistFinished(const SHttpDownloadResult& result);
static void StaticFetchBlacklistFinished(const SHttpDownloadResult& result);

bool GetGPUEnabled() const noexcept;

private:
typedef std::pair<bool, eWebFilterType> WebFilterPair;

Expand All @@ -129,4 +131,7 @@ class CWebCore : public CWebCoreInterface
CXMLFile* m_pXmlConfig;
int m_iWhitelistRevision;
int m_iBlacklistRevision;

// Shouldn't be changed after init
bool m_bGPUEnabled;
};
1 change: 1 addition & 0 deletions Client/core/CClientVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ void CClientVariables::LoadDefaults()
DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing
DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time
DEFAULT("_beta_qc_rightclick_command", _S("reconnect")); // Command to run when right clicking quick connect (beta - can be removed at any time)
DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function)

if (!Exists("locale"))
{
Expand Down
6 changes: 5 additions & 1 deletion Client/core/CCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,12 @@ CWebCoreInterface* CCore::GetWebCore()
{
if (m_pWebCore == nullptr)
{
bool gpuEnabled;
auto cvars = g_pCore->GetCVars();
cvars->Get("browser_enable_gpu", gpuEnabled);

m_pWebCore = CreateModule<CWebCoreInterface>(m_WebCoreModule, "CefWeb", "cefweb", "InitWebCoreInterface", this);
m_pWebCore->Initialise();
m_pWebCore->Initialise(gpuEnabled);
}
return m_pWebCore;
}
Expand Down
22 changes: 14 additions & 8 deletions Client/core/CGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ CLocalGUI::~CLocalGUI()

void CLocalGUI::SetSkin(const char* szName)
{
CVector2D consolePos, consoleSize;

bool guiWasLoaded = m_pMainMenu != NULL;
if (guiWasLoaded)
{
consolePos = m_pConsole->GetPosition();
consoleSize = m_pConsole->GetSize();
DestroyWindows();
}

std::string error;

Expand Down Expand Up @@ -93,7 +99,11 @@ void CLocalGUI::SetSkin(const char* szName)
m_LastSettingsRevision = cvars->GetRevision();

if (guiWasLoaded)
{
CreateWindows(guiWasLoaded);
m_pConsole->SetPosition(consolePos);
m_pConsole->SetSize(consoleSize);
}

if (CCore::GetSingleton().GetConsole() && !error.empty())
CCore::GetSingleton().GetConsole()->Echo(error.c_str());
Expand All @@ -104,8 +114,8 @@ void CLocalGUI::ChangeLocale(const char* szName)
bool guiWasLoaded = m_pMainMenu != NULL;
assert(guiWasLoaded);

CVector2D vPos = m_pConsole->GetPosition();
CVector2D vSize = m_pConsole->GetSize();
CVector2D consolePos = m_pConsole->GetPosition();
CVector2D consoleSize = m_pConsole->GetSize();

if (guiWasLoaded)
DestroyWindows();
Expand All @@ -119,12 +129,8 @@ void CLocalGUI::ChangeLocale(const char* szName)
if (guiWasLoaded)
{
CreateWindows(guiWasLoaded);

if (m_pConsole != nullptr)
{
m_pConsole->SetPosition(vPos);
m_pConsole->SetSize(vSize);
}
m_pConsole->SetPosition(consolePos);
m_pConsole->SetSize(consoleSize);
}
}

Expand Down
15 changes: 14 additions & 1 deletion Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,10 @@ void CSettings::CreateGUI()
m_pCheckBoxRemoteJavascript->GetPosition(vecTemp);
m_pCheckBoxRemoteJavascript->AutoSize(NULL, 20.0f);

m_pCheckBoxBrowserGPUEnabled = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(m_pTabBrowser, _("Enable GPU rendering"), true));
m_pCheckBoxBrowserGPUEnabled->SetPosition(CVector2D(vecTemp.fX + 300.0f, vecTemp.fY - 25.0f));
m_pCheckBoxBrowserGPUEnabled->AutoSize(NULL, 20.0f);

m_pLabelBrowserCustomBlacklist = reinterpret_cast<CGUILabel*>(pManager->CreateLabel(m_pTabBrowser, _("Custom blacklist")));
m_pLabelBrowserCustomBlacklist->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 30.0f));
m_pLabelBrowserCustomBlacklist->GetPosition(vecTemp);
Expand Down Expand Up @@ -3287,6 +3291,8 @@ void CSettings::LoadData()
m_pCheckBoxRemoteBrowser->SetSelected(bVar);
CVARS_GET("browser_remote_javascript", bVar);
m_pCheckBoxRemoteJavascript->SetSelected(bVar);
CVARS_GET("browser_enable_gpu", bVar);
m_pCheckBoxBrowserGPUEnabled->SetSelected(bVar);

ReloadBrowserLists();
}
Expand Down Expand Up @@ -3711,6 +3717,13 @@ void CSettings::SaveData()
bBrowserSettingChanged = true;
}

bool bBrowserGPUEnabled = false;
CVARS_GET("browser_enable_gpu", bBrowserGPUEnabled);

bool bBrowserGPUSetting = m_pCheckBoxBrowserGPUEnabled->GetSelected();
bool bBrowserGPUSettingChanged = (bBrowserGPUSetting != bBrowserGPUEnabled);
CVARS_SET("browser_enable_gpu", bBrowserGPUSetting);

// Ensure CVARS ranges ok
CClientVariables::GetSingleton().ValidateValues();

Expand All @@ -3720,7 +3733,7 @@ void CSettings::SaveData()
gameSettings->Save();

// Ask to restart?
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged)
if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged || bBrowserGPUSettingChanged)
ShowRestartQuestion();
else if (CModManager::GetSingleton().IsLoaded() && bBrowserSettingChanged)
ShowDisconnectQuestion();
Expand Down
1 change: 1 addition & 0 deletions Client/core/CSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ class CSettings
CGUIButton* m_pButtonBrowserWhitelistAdd;
CGUIGridList* m_pGridBrowserWhitelist;
CGUIButton* m_pButtonBrowserWhitelistRemove;
CGUICheckBox* m_pCheckBoxBrowserGPUEnabled;
bool m_bBrowserListsChanged;
bool m_bBrowserListsLoadEnabled;

Expand Down
12 changes: 8 additions & 4 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1345,16 +1345,20 @@ void CVehicleSA::RecalculateHandling()
continue;

// If NOS is installed we need set the flag
if ((upgradeID >= 1008 && upgradeID <= 1010) && !(uiHandlingFlags & HANDLING_NOS_Flag))
if ((upgradeID >= 1008 && upgradeID <= 1010))
{
uiHandlingFlags |= HANDLING_NOS_Flag;
if (!(uiHandlingFlags & HANDLING_NOS_Flag))
uiHandlingFlags |= HANDLING_NOS_Flag;

nitroInstalled = true;
}

// If hydraulics is installed we need set the flag
if ((upgradeID == 1087) && !(uiHandlingFlags & HANDLING_Hydraulics_Flag))
if ((upgradeID == 1087))
{
uiHandlingFlags |= HANDLING_Hydraulics_Flag;
if (!(uiHandlingFlags & HANDLING_Hydraulics_Flag))
uiHandlingFlags |= HANDLING_Hydraulics_Flag;

hydralicsInstalled = true;
}
}
Expand Down
7 changes: 7 additions & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void CLuaBrowserDefs::LoadFunctions()
{"resizeBrowser", ResizeBrowser},
{"guiCreateBrowser", GUICreateBrowser},
{"guiGetBrowser", GUIGetBrowser},
{"isBrowserGPUEnabled", ArgumentParser<IsBrowserGPUEnabled>},
};

// Add browser functions
Expand Down Expand Up @@ -97,6 +98,7 @@ void CLuaBrowserDefs::AddClass(lua_State* luaVM)
lua_classvariable(luaVM, "renderingPaused", "setBrowserRenderingPaused", "isBrowserRenderingPaused");
lua_classvariable(luaVM, "volume", "setBrowserVolume", "getBrowserVolume");
lua_classvariable(luaVM, "devTools", "toggleBrowserDevTools", nullptr);
lua_classvariable(luaVM, "gpuEnabled", nullptr, "isBrowserGPUEnabled");

lua_registerclass(luaVM, "Browser", "DxTexture");

Expand Down Expand Up @@ -1054,3 +1056,8 @@ int CLuaBrowserDefs::SetBrowserAjaxHandler(lua_State* luaVM)
lua_pushboolean(luaVM, false);
return 1;
}

bool CLuaBrowserDefs::IsBrowserGPUEnabled() noexcept
{
return g_pCore->GetWebCore()->GetGPUEnabled();
}
1 change: 1 addition & 0 deletions Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ class CLuaBrowserDefs : public CLuaDefs
LUA_DECLARE(ResizeBrowser);
LUA_DECLARE(GUICreateBrowser);
LUA_DECLARE(GUIGetBrowser);
static bool IsBrowserGPUEnabled() noexcept;
};
4 changes: 3 additions & 1 deletion Client/sdk/core/CWebCoreInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CWebCoreInterface
{
public:
virtual ~CWebCoreInterface() {}
virtual bool Initialise() = 0;
virtual bool Initialise(bool gpuEnabled) = 0;

virtual CWebViewInterface* CreateWebView(unsigned int uiWidth, unsigned int uiHeight, bool bIsLocal, CWebBrowserItem* pWebBrowserRenderItem,
bool bTransparent) = 0;
Expand Down Expand Up @@ -90,4 +90,6 @@ class CWebCoreInterface
virtual void WriteCustomList(const SString& strListName, const std::vector<SString>& customList, bool bReset = true) = 0;
virtual void GetFilterEntriesByType(std::vector<std::pair<SString, bool>>& outEntries, eWebFilterType filterType,
eWebFilterState state = eWebFilterState::WEBFILTER_ALL) = 0;

virtual bool GetGPUEnabled() const noexcept = 0;
};
17 changes: 16 additions & 1 deletion Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#include "version.h"
#include "net/SimHeaders.h"
#include <signal.h>
#include <regex>

#define MAX_BULLETSYNC_DISTANCE 400.0f
#define MAX_EXPLOSION_SYNC_DISTANCE 400.0f
Expand Down Expand Up @@ -1783,7 +1784,21 @@ void CGame::Packet_PlayerJoinData(CPlayerJoinDataPacket& Packet)

SString strIP = pPlayer->GetSourceIP();
SString strIPAndSerial("IP: %s Serial: %s Version: %s", strIP.c_str(), strSerial.c_str(), strPlayerVersion.c_str());
if (!CheckNickProvided(szNick)) // check the nick is valid

// Prevent player from connecting if serial is invalid
const std::regex serialRegex("^[A-F0-9]{32}$");
if (!std::regex_match(strSerial, serialRegex))
{
// Tell the console
CLogger::LogPrintf("CONNECT: %s failed to connect (Invalid serial) (%s)\n", szNick, strIPAndSerial.c_str());

// Tell the player the problem
DisconnectPlayer(this, *pPlayer, CPlayerDisconnectedPacket::SERIAL_VERIFICATION);
return;
}

// Check the nick is valid
if (!CheckNickProvided(szNick))
{
// Tell the console
CLogger::LogPrintf("CONNECT: %s failed to connect (Invalid nickname) (%s)\n", szNick, strIPAndSerial.c_str());
Expand Down
Loading

0 comments on commit abf546c

Please sign in to comment.