Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Client/core/CClientVariables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ void CClientVariables::LoadDefaults()
DEFAULT("dynamic_ped_shadows", 0); // Disable dynamic ped shadows
DEFAULT("fast_clothes_loading", 1); // 0-off 1-auto 2-on
DEFAULT("allow_screen_upload", 1); // 0-off 1-on
DEFAULT("allow_cpu_info", 1); // 0-off 1-on
DEFAULT("allow_external_sounds", 1); // 0-off 1-on
DEFAULT("max_clientscript_log_kb", 5000); // Max size in KB (0-No limit)
DEFAULT("display_fullscreen_style", 0); // 0-standard 1-borderless 2-borderless keep res 3-borderless stretch
Expand Down
32 changes: 32 additions & 0 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ void CSettings::ResetGuiPointers()
m_pCheckBoxDeviceSelectionDialog = NULL;
m_pCheckBoxShowUnsafeResolutions = NULL;
m_pCheckBoxAllowScreenUpload = NULL;
m_pCheckBoxAllowCPUInfo = NULL;
m_pCheckBoxAllowExternalSounds = NULL;
m_pCheckBoxCustomizedSAFiles = NULL;
m_pCheckBoxAllowDiscordRPC = NULL;
Expand Down Expand Up @@ -502,6 +503,7 @@ void CSettings::CreateGUI()
m_dwFrameCount = 0;
m_bShownVolumetricShadowsWarning = false;
m_bShownAllowScreenUploadMessage = false;
m_bShownAllowCPUInfoMessage = false;
CVector2D vecTemp;
CVector2D vecSize;

Expand Down Expand Up @@ -902,6 +904,11 @@ void CSettings::CreateGUI()
m_pCheckBoxAllowScreenUpload->GetPosition(vecTemp, false);
m_pCheckBoxAllowScreenUpload->AutoSize(NULL, 20.0f);

m_pCheckBoxAllowCPUInfo = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Allow CPU info"), true));
m_pCheckBoxAllowCPUInfo->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
m_pCheckBoxAllowCPUInfo->GetPosition(vecTemp, false);
m_pCheckBoxAllowCPUInfo->AutoSize(NULL, 20.0f);

m_pCheckBoxAllowExternalSounds = reinterpret_cast<CGUICheckBox*>(pManager->CreateCheckBox(pTabMultiplayer, _("Allow external sounds"), true));
m_pCheckBoxAllowExternalSounds->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f));
m_pCheckBoxAllowExternalSounds->GetPosition(vecTemp, false);
Expand Down Expand Up @@ -2001,6 +2008,7 @@ void CSettings::CreateGUI()
m_pComboFxQuality->SetSelectionHandler(GUI_CALLBACK(&CSettings::OnFxQualityChanged, this));
m_pCheckBoxVolumetricShadows->SetClickHandler(GUI_CALLBACK(&CSettings::OnVolumetricShadowsClick, this));
m_pCheckBoxAllowScreenUpload->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowScreenUploadClick, this));
m_pCheckBoxAllowCPUInfo->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowCPUInfoClick, this));
m_pCheckBoxAllowExternalSounds->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowExternalSoundsClick, this));
m_pCheckBoxAllowDiscordRPC->SetClickHandler(GUI_CALLBACK(&CSettings::OnAllowDiscordRPC, this));
m_pCheckBoxCustomizedSAFiles->SetClickHandler(GUI_CALLBACK(&CSettings::OnCustomizedSAFilesClick, this));
Expand Down Expand Up @@ -3981,6 +3989,10 @@ void CSettings::LoadData()
CVARS_GET("allow_screen_upload", bAllowScreenUploadEnabled);
m_pCheckBoxAllowScreenUpload->SetSelected(bAllowScreenUploadEnabled);

bool bAllowCPUInfoEnabled;
CVARS_GET("allow_cpu_info", bAllowCPUInfoEnabled);
m_pCheckBoxAllowCPUInfo->SetSelected(bAllowCPUInfoEnabled);

// Allow external sounds
bool bAllowExternalSoundsEnabled;
CVARS_GET("allow_external_sounds", bAllowExternalSoundsEnabled);
Expand Down Expand Up @@ -4472,6 +4484,9 @@ void CSettings::SaveData()
bool bAllowScreenUploadEnabled = m_pCheckBoxAllowScreenUpload->GetSelected();
CVARS_SET("allow_screen_upload", bAllowScreenUploadEnabled);

bool bAllowCPUInfoEnabled = m_pCheckBoxAllowCPUInfo->GetSelected();
CVARS_SET("allow_cpu_info", bAllowCPUInfoEnabled);

// Allow external sounds
bool bAllowExternalSoundsEnabled = m_pCheckBoxAllowExternalSounds->GetSelected();
CVARS_SET("allow_external_sounds", bAllowExternalSoundsEnabled);
Expand Down Expand Up @@ -5736,6 +5751,23 @@ bool CSettings::OnAllowScreenUploadClick(CGUIElement* pElement)
return true;
}

//
// AllowCPUInfo
//
bool CSettings::OnAllowCPUInfoClick(CGUIElement* pElement)
{
if (!m_pCheckBoxAllowCPUInfo->GetSelected() && !m_bShownAllowCPUInfoMessage)
{
m_bShownAllowCPUInfoMessage = true;
SString strMessage;
strMessage +=
_("Some servers use CPU information to adjust quality or identify clients."
"\n\nDisabling this setting may prevent you from joining those servers.\n");
CCore::GetSingleton().ShowMessageBox(_("CPU INFO"), strMessage, MB_BUTTON_OK | MB_ICON_INFO);
}
return true;
}

//
// AllowExternalSounds
//
Expand Down
3 changes: 3 additions & 0 deletions Client/core/CSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class CSettings
CGUICheckBox* m_pCheckBoxDeviceSelectionDialog;
CGUICheckBox* m_pCheckBoxShowUnsafeResolutions;
CGUICheckBox* m_pCheckBoxAllowScreenUpload;
CGUICheckBox* m_pCheckBoxAllowCPUInfo;
CGUICheckBox* m_pCheckBoxAllowExternalSounds;
CGUICheckBox* m_pCheckBoxCustomizedSAFiles;
CGUICheckBox* m_pCheckBoxAllowDiscordRPC;
Expand Down Expand Up @@ -444,6 +445,7 @@ class CSettings
bool OnFxQualityChanged(CGUIElement* pElement);
bool OnVolumetricShadowsClick(CGUIElement* pElement);
bool OnAllowScreenUploadClick(CGUIElement* pElement);
bool OnAllowCPUInfoClick(CGUIElement* pElement);
bool OnAllowExternalSoundsClick(CGUIElement* pElement);
bool OnAllowDiscordRPC(CGUIElement* pElement);
bool OnCustomizedSAFilesClick(CGUIElement* pElement);
Expand Down Expand Up @@ -518,6 +520,7 @@ class CSettings
DWORD m_dwFrameCount;
bool m_bShownVolumetricShadowsWarning;
bool m_bShownAllowScreenUploadMessage;
bool m_bShownAllowCPUInfoMessage;
bool m_bShownAllowExternalSoundsMessage;
int m_iMaxAnisotropic;

Expand Down
30 changes: 30 additions & 0 deletions Client/mods/deathmatch/logic/CClientGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "StdInc.h"
#include <net/SyncStructures.h>
#include <SharedUtil.SysInfo.h>
#include <game/C3DMarkers.h>
#include <game/CAnimBlendAssocGroup.h>
#include <game/CAnimBlendAssociation.h>
Expand Down Expand Up @@ -728,6 +729,35 @@ bool CClientGame::StartGame(const char* szNick, const char* szPassword, eServerT
g_pNet->SendPacket(PACKET_ID_PLAYER_JOINDATA, pBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(pBitStream);

// CPU info is a separate packet so old servers can ignore the unknown id.
// AllowCPUInfo=false is still sent so the server can tell opt-out from "no packet".
{
bool bAllowCPUInfo = true;
g_pCore->GetCVars()->Get("allow_cpu_info", bAllowCPUInfo);

NetBitStreamInterface* pCPUBitStream = g_pNet->AllocateNetBitStream();
if (pCPUBitStream)
{
pCPUBitStream->WriteBit(bAllowCPUInfo);
if (bAllowCPUInfo)
{
SharedUtil::SCPUInfo cpuInfo;
SharedUtil::GetCPUInfo(cpuInfo);
if (cpuInfo.strName.length() > 128)
cpuInfo.strName = cpuInfo.strName.Left(128);
pCPUBitStream->WriteString(cpuInfo.strName);
pCPUBitStream->Write(cpuInfo.uiMaxClockSpeedMHz);
pCPUBitStream->Write(cpuInfo.uiCores);
pCPUBitStream->Write(cpuInfo.uiThreads);
pCPUBitStream->Write(cpuInfo.uiL1CacheKB);
pCPUBitStream->Write(cpuInfo.uiL2CacheKB);
pCPUBitStream->Write(cpuInfo.uiL3CacheKB);
}
g_pNet->SendPacket(PACKET_ID_PLAYER_CPUINFO, pCPUBitStream, PACKET_PRIORITY_HIGH, PACKET_RELIABILITY_RELIABLE_ORDERED);
g_pNet->DeallocateNetBitStream(pCPUBitStream);
}
}

return true;
}
}
Expand Down
37 changes: 36 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "StdInc.h"
#include "CLuaClientDefs.h"
#include "lua/CLuaFunctionParser.h"
#include <SharedUtil.SysInfo.h>

void CLuaClientDefs::LoadFunctions()
{
Expand All @@ -23,7 +24,8 @@ void CLuaClientDefs::LoadFunctions()
{"isChatInputBlocked", ArgumentParser<IsChatInputBlocked>},
{"clearDebugBox", ArgumentParser<ClearDebug>},
{"isMTAWindowFocused", ArgumentParser<IsMTAWindowFocused>},
{"isCapsLockEnabled", ArgumentParser<IsCapsLockEnabled>}};
{"isCapsLockEnabled", ArgumentParser<IsCapsLockEnabled>},
{"getCPUInfo", ArgumentParser<GetCPUInfo>}};

for (const auto& [name, func] : functions)
CLuaCFunctions::AddFunction(name, func);
Expand Down Expand Up @@ -80,3 +82,36 @@ bool CLuaClientDefs::IsCapsLockEnabled()
{
return ((::GetKeyState(VK_CAPITAL) & 0x0001) != 0);
}

CLuaArguments CLuaClientDefs::GetCPUInfo()
{
CLuaArguments table;
bool bAllowCPUInfo = true;
g_pCore->GetCVars()->Get("allow_cpu_info", bAllowCPUInfo);

table.PushString("AllowCPUInfo");
table.PushBoolean(bAllowCPUInfo);

// Opt-out must omit hardware fields so server scripts cannot recover them from a client event.
if (!bAllowCPUInfo)
return table;

SharedUtil::SCPUInfo info;
SharedUtil::GetCPUInfo(info);

table.PushString("Name");
table.PushString(info.strName);
table.PushString("MaxClockSpeedMHz");
table.PushNumber(info.uiMaxClockSpeedMHz);
table.PushString("Cores");
table.PushNumber(info.uiCores);
table.PushString("Threads");
table.PushNumber(info.uiThreads);
table.PushString("L1CacheKB");
table.PushNumber(info.uiL1CacheKB);
table.PushString("L2CacheKB");
table.PushNumber(info.uiL2CacheKB);
table.PushString("L3CacheKB");
table.PushNumber(info.uiL3CacheKB);
return table;
}
20 changes: 11 additions & 9 deletions Client/mods/deathmatch/logic/luadefs/CLuaClientDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@
#pragma once

#include "CLuaDefs.h"
#include "lua/CLuaArguments.h"

class CLuaClientDefs : public CLuaDefs
{
public:
static void LoadFunctions();

private:
static bool SetTransferBoxVisible(bool visible);
static bool IsTransferBoxVisible();
static bool IsTransferBoxAlwaysVisible();
static bool ShowChat(bool bVisible, std::optional<bool> optInputBlocked);
static bool IsChatVisible();
static bool IsChatInputBlocked();
static bool ClearDebug();
static bool IsMTAWindowFocused();
static bool IsCapsLockEnabled();
static bool SetTransferBoxVisible(bool visible);
static bool IsTransferBoxVisible();
static bool IsTransferBoxAlwaysVisible();
static bool ShowChat(bool bVisible, std::optional<bool> optInputBlocked);
static bool IsChatVisible();
static bool IsChatInputBlocked();
static bool ClearDebug();
static bool IsMTAWindowFocused();
static bool IsCapsLockEnabled();
static CLuaArguments GetCPUInfo();
};
35 changes: 35 additions & 0 deletions Server/mods/deathmatch/logic/CGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,6 +1341,12 @@ bool CGame::ProcessPacket(CPacket& Packet)
return true;
}

case PACKET_ID_PLAYER_CPUINFO:
{
Packet_PlayerCPUInfo(static_cast<CPlayerCPUInfoPacket&>(Packet));
return true;
}

case PACKET_ID_PLAYER_SCREENSHOT:
{
Packet_PlayerScreenShot(static_cast<CPlayerScreenShotPacket&>(Packet));
Expand Down Expand Up @@ -1704,6 +1710,7 @@ void CGame::AddBuiltInEvents()
m_Events.AddEvent("onPlayerCommand", "command", NULL, false);
m_Events.AddEvent("onPlayerModInfo", "filename, itemlist", NULL, false);
m_Events.AddEvent("onPlayerACInfo", "aclist, size, md5, sha256", NULL, false);
m_Events.AddEvent("onPlayerCPUInfo", "allowed, name, maxClockSpeedMHz, cores, threads, l1CacheKB, l2CacheKB, l3CacheKB", NULL, false);
m_Events.AddEvent("onPlayerNetworkStatus", "type, ticks", NULL, false);
m_Events.AddEvent("onPlayerScreenShot", "resource, status, file_data, timestamp, tag", NULL, false);
m_Events.AddEvent("onPlayerResourceStart", "resource", NULL, false);
Expand Down Expand Up @@ -4670,6 +4677,34 @@ void CGame::Packet_PlayerACInfo(CPlayerACInfoPacket& Packet)
}
}

void CGame::Packet_PlayerCPUInfo(CPlayerCPUInfoPacket& Packet)
{
CPlayer* pPlayer = Packet.GetSourcePlayer();
if (!pPlayer)
return;

pPlayer->m_bCPUInfoReceived = true;
pPlayer->m_bAllowCPUInfo = Packet.m_bAllowCPUInfo;
pPlayer->m_strCPUName = Packet.m_strName;
pPlayer->m_uiCPUMaxClockSpeedMHz = Packet.m_uiMaxClockSpeedMHz;
pPlayer->m_uiCPUCores = Packet.m_uiCores;
pPlayer->m_uiCPUThreads = Packet.m_uiThreads;
pPlayer->m_uiCPUL1CacheKB = Packet.m_uiL1CacheKB;
pPlayer->m_uiCPUL2CacheKB = Packet.m_uiL2CacheKB;
pPlayer->m_uiCPUL3CacheKB = Packet.m_uiL3CacheKB;

CLuaArguments Arguments;
Arguments.PushBoolean(Packet.m_bAllowCPUInfo);
Arguments.PushString(Packet.m_strName);
Arguments.PushNumber(Packet.m_uiMaxClockSpeedMHz);
Arguments.PushNumber(Packet.m_uiCores);
Arguments.PushNumber(Packet.m_uiThreads);
Arguments.PushNumber(Packet.m_uiL1CacheKB);
Arguments.PushNumber(Packet.m_uiL2CacheKB);
Arguments.PushNumber(Packet.m_uiL3CacheKB);
pPlayer->CallEvent("onPlayerCPUInfo", Arguments);
}

void CGame::PlayerCompleteConnect(CPlayer* pPlayer)
{
SString strIPAndSerial("IP: %s Serial: %s Version: %s", pPlayer->GetSourceIP(), pPlayer->GetSerial().c_str(), pPlayer->GetPlayerVersion().c_str());
Expand Down
2 changes: 2 additions & 0 deletions Server/mods/deathmatch/logic/CGame.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CGame;
#include "packets/CPlayerDiagnosticPacket.h"
#include "packets/CPlayerModInfoPacket.h"
#include "packets/CPlayerACInfoPacket.h"
#include "packets/CPlayerCPUInfoPacket.h"
#include "packets/CPlayerScreenShotPacket.h"

#include "CRPCFunctions.h"
Expand Down Expand Up @@ -520,6 +521,7 @@ class CGame
void Packet_PlayerDiagnostic(class CPlayerDiagnosticPacket& Packet);
void Packet_PlayerModInfo(class CPlayerModInfoPacket& Packet);
void Packet_PlayerACInfo(class CPlayerACInfoPacket& Packet);
void Packet_PlayerCPUInfo(class CPlayerCPUInfoPacket& Packet);
void Packet_PlayerScreenShot(class CPlayerScreenShotPacket& Packet);
void Packet_PlayerNoSocket(class CPlayerNoSocketPacket& Packet);
void Packet_PlayerNetworkStatus(class CPlayerNetworkStatusPacket& Packet);
Expand Down
5 changes: 5 additions & 0 deletions Server/mods/deathmatch/logic/CPacketTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "packets/CPlayerDiagnosticPacket.h"
#include "packets/CPlayerModInfoPacket.h"
#include "packets/CPlayerACInfoPacket.h"
#include "packets/CPlayerCPUInfoPacket.h"
#include "packets/CPlayerScreenShotPacket.h"
#include "packets/CUnoccupiedVehiclePushPacket.h"
#include "packets/CPlayerNoSocketPacket.h"
Expand Down Expand Up @@ -193,6 +194,10 @@ CPacket* CPacketTranslator::Translate(const NetServerPlayerID& Socket, ePacketID
pTemp = new CPlayerACInfoPacket;
break;

case PACKET_ID_PLAYER_CPUINFO:
pTemp = new CPlayerCPUInfoPacket;
break;

case PACKET_ID_PLAYER_SCREENSHOT:
pTemp = new CPlayerScreenShotPacket;
break;
Expand Down
9 changes: 9 additions & 0 deletions Server/mods/deathmatch/logic/CPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ class CPlayer final : public CPed, public CClient
uint m_uiD3d9Size;
SString m_strD3d9Md5;
SString m_strD3d9Sha256;
bool m_bCPUInfoReceived = false;
bool m_bAllowCPUInfo = false;
SString m_strCPUName;
unsigned int m_uiCPUMaxClockSpeedMHz = 0;
unsigned int m_uiCPUCores = 0;
unsigned int m_uiCPUThreads = 0;
unsigned int m_uiCPUL1CacheKB = 0;
unsigned int m_uiCPUL2CacheKB = 0;
unsigned int m_uiCPUL3CacheKB = 0;

// Per-player token bucket throttling for onPlayerResourceStart acks. Genuine duplicates
// consume a token; race-condition acks (resource stopped/restarted before the ack arrived)
Expand Down
Loading
Loading