Skip to content

Commit

Permalink
Add functionality to fetch and display RAM DDR version
Browse files Browse the repository at this point in the history
Introduce methods to query and display DDR version in ComponentStatsModule.
Add System.Management namespace and update project file.
Enhance UI with a checkbox to toggle DDR version display.
Update ComponentStatsItem and ViewModel classes to support new feature.
  • Loading branch information
BoiHanny committed Nov 16, 2024
1 parent 17c3c58 commit ac865bc
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 1 deletion.
86 changes: 85 additions & 1 deletion vrcosc-magicchatbox/Classes/Modules/ComponentStatsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Management;
using System.Threading.Tasks;
using System.Windows;
using vrcosc_magicchatbox.Classes.DataAndSecurity;
Expand All @@ -20,16 +21,78 @@ public class ComponentStatsModule
private readonly List<ComponentStatsItem> _componentStats = new List<ComponentStatsItem>();
private static string FileName = null;
public bool started = false;
private string _ramDDRVersion = "Unknown";

public void StartModule()
{
if (ViewModel.Instance.IntgrComponentStats && ViewModel.Instance.IntgrComponentStats_VR &&
ViewModel.Instance.IsVRRunning || ViewModel.Instance.IntgrComponentStats &&
ViewModel.Instance.IntgrComponentStats_DESKTOP &&
!ViewModel.Instance.IsVRRunning)
{
LoadComponentStats();
FetchAndStoreDDRVersion();
}

}

private void FetchAndStoreDDRVersion()
{
_ramDDRVersion = GetDDRVersion();
var ramItem = _componentStats.FirstOrDefault(stat => stat.ComponentType == StatsComponentType.RAM);
if (ramItem != null)
{
ramItem.DDRVersion = _ramDDRVersion;
}
}

public static string GetDDRVersion()
{
try
{
using (ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT SMBIOSMemoryType FROM Win32_PhysicalMemory"))
{
HashSet<int> memoryTypes = new HashSet<int>();

foreach (ManagementObject mo in mos.Get())
{
var smbiosMemoryType = mo["SMBIOSMemoryType"];

if (smbiosMemoryType != null)
{
int type = Convert.ToInt32(smbiosMemoryType);
memoryTypes.Add(type);
}
}

if (memoryTypes.Count > 0)
{
return MapMemoryTypeToDDR(memoryTypes.First());
}
}
}
catch (Exception ex)
{
Logging.WriteException(ex, MSGBox: false);
}
return "Unknown";
}

private static string MapMemoryTypeToDDR(int type)
{
switch (type)
{
case 20: return "ᴰᴰᴿ";
case 21: return "ᴰᴰᴿ²";
case 24: return "ᴰᴰᴿ³";
case 26: return "ᴰᴰᴿ⁴";
case 28:
case 34: return "ᴰᴰᴿ⁵";
default: return string.Empty;
}
}


public IReadOnlyList<ComponentStatsItem> GetAllStats()
{
return _componentStats.AsReadOnly();
Expand Down Expand Up @@ -346,6 +409,21 @@ public void SetShowGPUTemperature(bool state)
}
}

public bool GetShowRamDDRVersion()
{
var item = _componentStats.FirstOrDefault(stat => stat.ComponentType == StatsComponentType.RAM);
return item?.ShowDDRVersion ?? false;
}

public void SetShowRamDDRVersion(bool state)
{
var item = _componentStats.FirstOrDefault(stat => stat.ComponentType == StatsComponentType.RAM);
if (item != null)
{
item.ShowDDRVersion = state;
}
}

public bool GetShowGPUHotspotTemperature()
{
var item = _componentStats.FirstOrDefault(stat => stat.ComponentType == StatsComponentType.GPU);
Expand Down Expand Up @@ -499,7 +577,6 @@ public void SetStatMaxValueShown(StatsComponentType type, bool state)
StatsComponentType.GPU,
StatsComponentType.VRAM,
StatsComponentType.RAM,
//StatsComponentType.FPS
};

public string GenerateStatsDescription()
Expand Down Expand Up @@ -551,6 +628,11 @@ public string GenerateStatsDescription()
}
}

if (stat.ComponentType == StatsComponentType.RAM && stat.ShowDDRVersion)
{
componentDescription += $" ⁽{stat.DDRVersion}⁾";
}

// Combine the additionalInfo parts with a single space
string additionalInfo = string.Join(" ", additionalInfoParts).Trim();

Expand Down Expand Up @@ -1100,6 +1182,8 @@ private static string FetchStat(
}
}



private static string FetchHotspotTemperatureStat(IHardware hardware, ComponentStatsItem item)
{
foreach (var sensor in hardware.Sensors)
Expand Down
1 change: 1 addition & 0 deletions vrcosc-magicchatbox/MagicChatbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
<PackageReference Include="NHotkey.Wpf" Version="3.0.0" />
<PackageReference Include="NLog" Version="5.3.4" />
<PackageReference Include="OpenAI-DotNet" Version="8.4.1" />
<PackageReference Include="System.Management" Version="9.0.0" />
<PackageReference Include="VRChat.OSCQuery" Version="0.0.7" />
</ItemGroup>

Expand Down
13 changes: 13 additions & 0 deletions vrcosc-magicchatbox/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3834,6 +3834,19 @@
IsChecked="{Binding RAM_ShowMaxValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Style="{DynamicResource SettingsCheckbox}"
ToolTip="When checked, the VRAM usage label will display the model name of ur GPU." />
<CheckBox
x:Name="RAM_ShowDDRVersion_checkbox"
Height="20"
Margin="5,5"
BorderBrush="#FF2D1265"
Checked="Update_Click"
Content="Show RAM DDR version"
FontFamily="Comfortaa Light"
FontSize="18"
Foreground="#FFB9B5C1"
IsChecked="{Binding RAM_ShowDDRVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Style="{DynamicResource SettingsCheckbox}"
ToolTip="When checked, the DDR version of the RAM will be displayed." />
<CheckBox
x:Name="RAM_NumberTrailingZeros_checkbox"
Height="20"
Expand Down
2 changes: 2 additions & 0 deletions vrcosc-magicchatbox/ViewModels/Models/ComponentStatsItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class ComponentStatsItem
public bool ShowMaxValue { get; set; }
public bool IsEnabled { get; set; } = true;
public bool ShowSmallName { get; set; } = true;
public bool ShowDDRVersion { get; set; } = true;
public string DDRVersion { get; set; }

public string GetFormattedValue() { return ShowUnit ? $"{ComponentValue}{Unit}" : ComponentValue; }
public string GetFormattedMaxValue()
Expand Down
17 changes: 17 additions & 0 deletions vrcosc-magicchatbox/ViewModels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,23 @@ public bool RAM_ShowMaxValue
}
}

public bool RAM_ShowDDRVersion
{
get => _statsManager.GetShowRamDDRVersion();
set
{
if (value)
{
_statsManager.SetShowRamDDRVersion(true);
}
else
{
_statsManager.SetShowRamDDRVersion(false);
}
NotifyPropertyChanged(nameof(RAM_ShowDDRVersion));
}
}

public bool JoinedAlphaChannel
{
get { return _JoinedAlphaChannel; }
Expand Down

0 comments on commit ac865bc

Please sign in to comment.