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
13 changes: 13 additions & 0 deletions Client/core/Graphics/CRenderItemManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Client/core/Graphics/CRenderItemManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 7 additions & 0 deletions Client/sdk/core/CRenderItemManagerInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ enum eDxTestMode
DX_TEST_MODE_NO_SHADER,
};

struct BasicGPUInfo
{
std::string name;
std::uint32_t memoryKB;
};

struct SDxStatus
{
eDxTestMode testMode;
Expand Down Expand Up @@ -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;
};

////////////////////////////////////////////////////////////////
Expand Down
43 changes: 41 additions & 2 deletions Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*****************************************************************************/

#include "StdInc.h"
#ifdef MTA_CLIENT
#include <SharedUtil.SysInfo.h>
#endif
#include "CLuaUtilDefs.h"
#include "CScriptArgReader.h"
#include "Utils.h"
Expand Down Expand Up @@ -73,6 +76,10 @@ void CLuaUtilDefs::LoadFunctions()
{"gettok", GetTok},
{"tocolor", tocolor},
{"getProcessMemoryStats", ArgumentParser<GetProcessMemoryStats>},

#ifdef MTA_CLIENT
{"getSystemInfo", ArgumentParser<GetSystemInfo>},
#endif
};

// Add functions
Expand Down Expand Up @@ -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<unsigned char>(iRed), static_cast<unsigned char>(iGreen),
static_cast<unsigned char>(iBlue), static_cast<unsigned char>(iAlpha));
unsigned long ulColor = COLOR_RGBA(static_cast<unsigned char>(iRed), static_cast<unsigned char>(iGreen), static_cast<unsigned char>(iBlue),
static_cast<unsigned char>(iAlpha));
lua_pushinteger(luaVM, static_cast<lua_Integer>(ulColor));
return 1;
}
Expand All @@ -739,3 +746,35 @@ int CLuaUtilDefs::tocolor(lua_State* luaVM)
lua_pushnumber(luaVM, static_cast<lua_Number>(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<lua_Number>(info.CPU.MaxClockSpeed)},
{"Name", info.CPU.Name},
{"NumberOfCores", static_cast<lua_Number>(info.CPU.NumberOfCores)},
{"NumberOfLogicalProcessors", static_cast<lua_Number>(info.CPU.NumberOfLogicalProcessors)},
});

table["TotalPhysicalMemory"] = static_cast<lua_Number>(info.TotalPhysicalMemory);

BasicGPUInfo gpu;
g_pCore->GetGraphics()->GetRenderItemManager()->GetBasicGPUInfo(gpu);
table.emplace("GPU", DataSubTable{
{"RAM", static_cast<lua_Number>(gpu.memoryKB)},
{"Name", gpu.name},
});

return table;
}();

return outValue;
}

#endif
7 changes: 7 additions & 0 deletions Shared/mods/deathmatch/logic/luadefs/CLuaUtilDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#pragma once
#include "luadefs/CLuaDefs.h"

using DataSubTable = std::unordered_map<std::string, std::variant<std::string, lua_Number>>;
using MainTable = std::unordered_map<std::string, std::variant<DataSubTable, lua_Number>>;

class CLuaUtilDefs : public CLuaDefs
{
public:
Expand Down Expand Up @@ -52,4 +55,8 @@ class CLuaUtilDefs : public CLuaDefs
// Utility functions
LUA_DECLARE(GetTok);
LUA_DECLARE(tocolor);

#ifdef MTA_CLIENT
static const MainTable& GetSystemInfo();
#endif
};
41 changes: 28 additions & 13 deletions Shared/sdk/SharedUtil.SysInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,27 @@
#pragma once

#ifdef WIN32
#include <vector>
#include "SString.h"
#include <windows.h>
#include "WinVer.h"
#include <vector>
#include "SString.h"
#include <windows.h>
#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<std::vector<SString> >
{
};
Expand All @@ -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<SString>& outEnabledList, std::vector<SString>& outDisabledList);
void GetInstalledHotFixList(std::vector<SString>& 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<SString>& outEnabledList, std::vector<SString>& outDisabledList);
void GetInstalledHotFixList(std::vector<SString>& outInstalledList);
bool IsHotFixInstalled(const SString& strHotFixId);
bool GetLibVersionInfo(const SString& strLibName, SLibVersionInfo* pOutLibVersionInfo);
bool Is64BitOS();
WMISystemInfo GetWMISystemInfo();
} // namespace SharedUtil

#endif
32 changes: 32 additions & 0 deletions Shared/sdk/SharedUtil.SysInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::uint32_t>(std::atoll(row[0]));
cpu.Name = row[1].TrimEnd(" "); // Remove whitespace from the end
cpu.NumberOfCores = static_cast<std::uint32_t>(std::atoll(row[2]));
cpu.NumberOfLogicalProcessors = static_cast<std::uint32_t>(std::atoll(row[3]));
}
}

return temp;
}();

return info;
}

#endif // MTA_CLIENT
Loading