From 5a863e37083b6ce8fb7f498274bc229bd512127c Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 12 Nov 2025 21:04:51 +0100 Subject: [PATCH] getSystemInfo --- Client/core/Graphics/CRenderItemManager.cpp | 13 ++++++ Client/core/Graphics/CRenderItemManager.h | 1 + Client/sdk/core/CRenderItemManagerInterface.h | 7 +++ .../deathmatch/logic/luadefs/CLuaUtilDefs.cpp | 43 ++++++++++++++++++- .../deathmatch/logic/luadefs/CLuaUtilDefs.h | 7 +++ Shared/sdk/SharedUtil.SysInfo.h | 41 ++++++++++++------ Shared/sdk/SharedUtil.SysInfo.hpp | 32 ++++++++++++++ 7 files changed, 129 insertions(+), 15 deletions(-) diff --git a/Client/core/Graphics/CRenderItemManager.cpp b/Client/core/Graphics/CRenderItemManager.cpp index d48415bdc68..fd962dbca92 100644 --- a/Client/core/Graphics/CRenderItemManager.cpp +++ b/Client/core/Graphics/CRenderItemManager.cpp @@ -850,6 +850,19 @@ void CRenderItemManager::UpdateMemoryUsage() m_iMemoryKBFreeForMTA = std::max(0, m_iMemoryKBFreeForMTA); } +//////////////////////////////////////////////////////////////// +// +// CRenderItemManager::GetBasicGPUInfo +// +// +// +//////////////////////////////////////////////////////////////// +void CRenderItemManager::GetBasicGPUInfo(BasicGPUInfo& outInfo) +{ + outInfo.name = m_strVideoCardName; + outInfo.memoryKB = m_iVideoCardMemoryKBTotal; +} + //////////////////////////////////////////////////////////////// // // CRenderItemManager::GetDxStatus diff --git a/Client/core/Graphics/CRenderItemManager.h b/Client/core/Graphics/CRenderItemManager.h index 3a7925d6159..42bd391c719 100644 --- a/Client/core/Graphics/CRenderItemManager.h +++ b/Client/core/Graphics/CRenderItemManager.h @@ -58,6 +58,7 @@ class CRenderItemManager : public CRenderItemManagerInterface virtual void FlushNonAARenderTarget(); virtual HRESULT HandleStretchRect(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, int Filter); + virtual void GetBasicGPUInfo(BasicGPUInfo& outInfo) override; // CRenderItemManager void NotifyContructRenderItem(CRenderItem* pItem); diff --git a/Client/sdk/core/CRenderItemManagerInterface.h b/Client/sdk/core/CRenderItemManagerInterface.h index 2940eb1d517..343d8f6b346 100644 --- a/Client/sdk/core/CRenderItemManagerInterface.h +++ b/Client/sdk/core/CRenderItemManagerInterface.h @@ -84,6 +84,12 @@ enum eDxTestMode DX_TEST_MODE_NO_SHADER, }; +struct BasicGPUInfo +{ + std::string name; + std::uint32_t memoryKB; +}; + struct SDxStatus { eDxTestMode testMode; @@ -187,6 +193,7 @@ class CRenderItemManagerInterface virtual void FlushNonAARenderTarget() = 0; virtual HRESULT HandleStretchRect(IDirect3DSurface9* pSourceSurface, CONST RECT* pSourceRect, IDirect3DSurface9* pDestSurface, CONST RECT* pDestRect, int Filter) = 0; + virtual void GetBasicGPUInfo(BasicGPUInfo& outInfo) = 0; }; //////////////////////////////////////////////////////////////// diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp index b2c39a0b6c4..de6fc15b257 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp @@ -9,6 +9,9 @@ *****************************************************************************/ #include "StdInc.h" +#ifdef MTA_CLIENT + #include +#endif #include "CLuaUtilDefs.h" #include "CScriptArgReader.h" #include "Utils.h" @@ -73,6 +76,10 @@ void CLuaUtilDefs::LoadFunctions() {"gettok", GetTok}, {"tocolor", tocolor}, {"getProcessMemoryStats", ArgumentParser}, + +#ifdef MTA_CLIENT + {"getSystemInfo", ArgumentParser}, +#endif }; // Add functions @@ -728,8 +735,8 @@ int CLuaUtilDefs::tocolor(lua_State* luaVM) if (!argStream.HasErrors()) { // Make it into an unsigned long - unsigned long ulColor = COLOR_RGBA(static_cast(iRed), static_cast(iGreen), - static_cast(iBlue), static_cast(iAlpha)); + unsigned long ulColor = COLOR_RGBA(static_cast(iRed), static_cast(iGreen), static_cast(iBlue), + static_cast(iAlpha)); lua_pushinteger(luaVM, static_cast(ulColor)); return 1; } @@ -739,3 +746,35 @@ int CLuaUtilDefs::tocolor(lua_State* luaVM) lua_pushnumber(luaVM, static_cast(ulColor)); return 1; } + +#ifdef MTA_CLIENT +const MainTable& CLuaUtilDefs::GetSystemInfo() +{ + static const MainTable outValue = []() -> MainTable + { + MainTable table; + auto info = SharedUtil::GetWMISystemInfo(); + + table.emplace("CPU", DataSubTable{ + {"MaxClockSpeed", static_cast(info.CPU.MaxClockSpeed)}, + {"Name", info.CPU.Name}, + {"NumberOfCores", static_cast(info.CPU.NumberOfCores)}, + {"NumberOfLogicalProcessors", static_cast(info.CPU.NumberOfLogicalProcessors)}, + }); + + table["TotalPhysicalMemory"] = static_cast(info.TotalPhysicalMemory); + + BasicGPUInfo gpu; + g_pCore->GetGraphics()->GetRenderItemManager()->GetBasicGPUInfo(gpu); + table.emplace("GPU", DataSubTable{ + {"RAM", static_cast(gpu.memoryKB)}, + {"Name", gpu.name}, + }); + + return table; + }(); + + return outValue; +} + +#endif diff --git a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.h b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.h index e690c7cf3ca..229b37a6901 100644 --- a/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.h +++ b/Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.h @@ -11,6 +11,9 @@ #pragma once #include "luadefs/CLuaDefs.h" +using DataSubTable = std::unordered_map>; +using MainTable = std::unordered_map>; + class CLuaUtilDefs : public CLuaDefs { public: @@ -52,4 +55,8 @@ class CLuaUtilDefs : public CLuaDefs // Utility functions LUA_DECLARE(GetTok); LUA_DECLARE(tocolor); + + #ifdef MTA_CLIENT + static const MainTable& GetSystemInfo(); + #endif }; diff --git a/Shared/sdk/SharedUtil.SysInfo.h b/Shared/sdk/SharedUtil.SysInfo.h index 76e6fa2ab0c..61c97355b47 100644 --- a/Shared/sdk/SharedUtil.SysInfo.h +++ b/Shared/sdk/SharedUtil.SysInfo.h @@ -11,13 +11,27 @@ #pragma once #ifdef WIN32 -#include -#include "SString.h" -#include -#include "WinVer.h" + #include + #include "SString.h" + #include + #include "WinVer.h" namespace SharedUtil { + struct WMIProcessorInfo + { + std::uint32_t MaxClockSpeed{0}; + std::string Name{}; + std::uint32_t NumberOfCores{0}; + std::uint32_t NumberOfLogicalProcessors{0}; + }; + + struct WMISystemInfo + { + WMIProcessorInfo CPU{}; + std::uint64_t TotalPhysicalMemory{0}; // In KiB + }; + struct SQueryWMIResult : public std::vector > { }; @@ -36,15 +50,16 @@ namespace SharedUtil SString strProductName; }; - bool QueryWMI(SQueryWMIResult& outResult, const SString& strQuery, const SString& strKeys, const SString& strNamespace = "CIMV2"); - SString GetWMIOSVersion(); - unsigned int GetWMIVideoAdapterMemorySize(const unsigned long ulVen, const unsigned long ulDev); - long long GetWMITotalPhysicalMemory(); - void GetWMIAntiVirusStatus(std::vector& outEnabledList, std::vector& outDisabledList); - void GetInstalledHotFixList(std::vector& outInstalledList); - bool IsHotFixInstalled(const SString& strHotFixId); - bool GetLibVersionInfo(const SString& strLibName, SLibVersionInfo* pOutLibVersionInfo); - bool Is64BitOS(); + bool QueryWMI(SQueryWMIResult& outResult, const SString& strQuery, const SString& strKeys, const SString& strNamespace = "CIMV2"); + SString GetWMIOSVersion(); + unsigned int GetWMIVideoAdapterMemorySize(const unsigned long ulVen, const unsigned long ulDev); + long long GetWMITotalPhysicalMemory(); + void GetWMIAntiVirusStatus(std::vector& outEnabledList, std::vector& outDisabledList); + void GetInstalledHotFixList(std::vector& outInstalledList); + bool IsHotFixInstalled(const SString& strHotFixId); + bool GetLibVersionInfo(const SString& strLibName, SLibVersionInfo* pOutLibVersionInfo); + bool Is64BitOS(); + WMISystemInfo GetWMISystemInfo(); } // namespace SharedUtil #endif diff --git a/Shared/sdk/SharedUtil.SysInfo.hpp b/Shared/sdk/SharedUtil.SysInfo.hpp index e79751ca4f1..42c58a8de8e 100644 --- a/Shared/sdk/SharedUtil.SysInfo.hpp +++ b/Shared/sdk/SharedUtil.SysInfo.hpp @@ -538,4 +538,36 @@ bool SharedUtil::Is64BitOS() return bIs64BitOS; } +SharedUtil::WMISystemInfo SharedUtil::GetWMISystemInfo() +{ + // Cache result, because these wont change while the PC is running + static WMISystemInfo info = []() -> WMISystemInfo + { + WMISystemInfo temp; + + temp.TotalPhysicalMemory = GetWMITotalPhysicalMemory() / 1024; + + SQueryWMIResult result; + QueryWMI(result, "Win32_Processor", "MaxClockSpeed,Name,NumberOfCores,NumberOfLogicalProcessors"); + + if (!result.empty()) + { + const auto& row = result[0]; + if (row.size() >= 4) + { + auto& cpu = temp.CPU; + + cpu.MaxClockSpeed = static_cast(std::atoll(row[0])); + cpu.Name = row[1].TrimEnd(" "); // Remove whitespace from the end + cpu.NumberOfCores = static_cast(std::atoll(row[2])); + cpu.NumberOfLogicalProcessors = static_cast(std::atoll(row[3])); + } + } + + return temp; + }(); + + return info; +} + #endif // MTA_CLIENT