Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
VolcanicArts committed Dec 20, 2023
2 parents 2d60231 + 30172a7 commit 6242ef9
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 174 deletions.
4 changes: 2 additions & 2 deletions VRCOSC.Desktop/VRCOSC.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<ApplicationIcon>game.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Version>0.0.0</Version>
<FileVersion>2023.1022.0</FileVersion>
<FileVersion>2023.1220.0</FileVersion>
<Title>VRCOSC</Title>
<Authors>VolcanicArts</Authors>
<Company>VolcanicArts</Company>
<Nullable>enable</Nullable>
<AssemblyVersion>2023.1022.0</AssemblyVersion>
<AssemblyVersion>2023.1220.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\VRCOSC.Game\VRCOSC.Game.csproj" />
Expand Down
2 changes: 0 additions & 2 deletions VRCOSC.Game/ChatBox/Clips/Clip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ private void removeInvalidStates(List<ClipState> localStates)
var currentStates = AssociatedModules.Where(moduleName => appManager.ModuleManager.GetModule(moduleName)!.Enabled.Value && chatBoxManager.StateValues.ContainsKey(moduleName) && chatBoxManager.StateValues[moduleName] is not null).Select(moduleName => chatBoxManager.StateValues[moduleName]).ToList();
currentStates.Sort();

if (!currentStates.Any()) return;

foreach (var clipState in localStates.ToImmutableList())
{
var clipStateStates = clipState.StateNames;
Expand Down
4 changes: 3 additions & 1 deletion VRCOSC.Game/OSC/VRChat/VRChatOscClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
using osu.Framework.IO.Network;
using osu.Framework.Logging;
using VRC.OSCQuery;
using VRCOSC.Game.OSC.Client;
Expand Down Expand Up @@ -72,7 +73,8 @@ public void Reset()
{
if (QueryPort is null) return null;

var url = $"http://127.0.0.1:{QueryPort}/avatar/parameters/{parameterName}";
var parameterNameEncoded = UrlEncoding.UrlEncode(parameterName);
var url = $"http://127.0.0.1:{QueryPort}/avatar/parameters/{parameterNameEncoded}";

var response = await client.GetAsync(new Uri(url));
var content = await response.Content.ReadAsStringAsync();
Expand Down
10 changes: 9 additions & 1 deletion VRCOSC.Game/OpenVR/OVRHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// Copyright (c) VolcanicArts. Licensed under the GPL-3.0 License.
// See the LICENSE file in the repository root for full license text.

using System;
Expand Down Expand Up @@ -108,6 +108,8 @@ internal static IEnumerable<uint> GetIndexesForTrackedDeviceClass(ETrackedDevice

internal static bool GetBoolTrackedDeviceProperty(uint index, ETrackedDeviceProperty property)
{
if (index == Valve.VR.OpenVR.k_unTrackedDeviceIndexInvalid) return default;

var error = new ETrackedPropertyError();
var value = Valve.VR.OpenVR.System.GetBoolTrackedDeviceProperty(index, property, ref error);

Expand All @@ -119,6 +121,8 @@ internal static bool GetBoolTrackedDeviceProperty(uint index, ETrackedDeviceProp

internal static int GetInt32TrackedDeviceProperty(uint index, ETrackedDeviceProperty property)
{
if (index == Valve.VR.OpenVR.k_unTrackedDeviceIndexInvalid) return default;

var error = new ETrackedPropertyError();
var value = Valve.VR.OpenVR.System.GetInt32TrackedDeviceProperty(index, property, ref error);

Expand All @@ -130,6 +134,8 @@ internal static int GetInt32TrackedDeviceProperty(uint index, ETrackedDeviceProp

internal static float GetFloatTrackedDeviceProperty(uint index, ETrackedDeviceProperty property)
{
if (index == Valve.VR.OpenVR.k_unTrackedDeviceIndexInvalid) return default;

var error = new ETrackedPropertyError();
var value = Valve.VR.OpenVR.System.GetFloatTrackedDeviceProperty(index, property, ref error);

Expand All @@ -143,6 +149,8 @@ internal static float GetFloatTrackedDeviceProperty(uint index, ETrackedDevicePr

internal static string GetStringTrackedDeviceProperty(uint index, ETrackedDeviceProperty property)
{
if (index == Valve.VR.OpenVR.k_unTrackedDeviceIndexInvalid) return string.Empty;

var error = new ETrackedPropertyError();
sb.Clear();
Valve.VR.OpenVR.System.GetStringTrackedDeviceProperty(index, property, sb, Valve.VR.OpenVR.k_unMaxPropertyStringSize, ref error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,50 @@

using System;
using System.Collections.Generic;
using System.Linq;
using LibreHardwareMonitor.Hardware;

namespace VRCOSC.Game.Providers.Hardware;

public class SensorInfoList
{
public readonly List<SensorInfo> InfoList = new();

public SensorInfoList(SensorType type, params string[] names)
{
foreach (var name in names) InfoList.Add(new SensorInfo(type, name));
}
}
public record SensorPair(SensorType Type, string Name);

public class SensorInfo
{
public readonly string Name;
public readonly SensorType Type;
public readonly List<SensorPair> Pairs = new();

public SensorInfo(SensorType type, string name)
public SensorInfo(SensorType type, params string[] names)
{
Type = type;
Name = name;
foreach (var name in names) Pairs.Add(new SensorPair(type, name));
}
}

public abstract class HardwareComponent
{
protected virtual SensorInfo LoadInfo => throw new NotImplementedException();

public readonly int Id;

public float Usage { get; private set; }

protected HardwareComponent(int id)
{
Id = id;
}

protected bool GetIntValue(ISensor sensor, SensorInfoList infoList, out int value)
protected static bool GetIntValue(ISensor sensor, SensorInfo info, out int value)
{
foreach (var info in infoList.InfoList)
if (!GetFloatValue(sensor, info, out var floatValue))
{
if (!GetIntValue(sensor, info, out var intValue)) continue;

value = intValue;
value = (int)MathF.Round(floatValue);
return true;
}

value = 0;
return false;
}

protected bool GetIntValue(ISensor sensor, SensorInfo info, out int value)
protected static bool GetFloatValue(ISensor sensor, SensorInfo info, out float value)
{
if (GetFloatValue(sensor, info, out var valueFloat))
{
value = (int)Math.Round(valueFloat);
return true;
}

value = 0;
return false;
}

protected bool GetFloatValue(ISensor sensor, SensorInfo info, out float value)
{
if (sensor.Name == info.Name && sensor.SensorType == info.Type)
if (info.Pairs.Any(pair => sensor.SensorType == pair.Type && sensor.Name == pair.Name))
{
value = sensor.Value ?? 0f;
return true;
}

value = 0f;
value = 0;
return false;
}

Expand All @@ -90,16 +60,11 @@ public abstract class CPU : HardwareComponent
{
protected override SensorInfo LoadInfo => new(SensorType.Load, "CPU Total");
protected virtual SensorInfo PowerInfo => throw new NotImplementedException();
protected virtual SensorInfoList TemperatureInfo => throw new NotImplementedException();
protected virtual SensorInfo TemperatureInfo => throw new NotImplementedException();

public int Power { get; private set; }
public int Temperature { get; private set; }

protected CPU(int id)
: base(id)
{
}

public override void Update(ISensor sensor)
{
base.Update(sensor);
Expand All @@ -111,24 +76,14 @@ public override void Update(ISensor sensor)
public class IntelCPU : CPU
{
protected override SensorInfo PowerInfo => new(SensorType.Power, "CPU Package");
protected override SensorInfoList TemperatureInfo => new(SensorType.Temperature, "CPU Package");

public IntelCPU(int id)
: base(id)
{
}
protected override SensorInfo TemperatureInfo => new(SensorType.Temperature, "CPU Package");
}

// ReSharper disable once InconsistentNaming
public class AMDCPU : CPU
{
protected override SensorInfo PowerInfo => new(SensorType.Power, "Package");
protected override SensorInfoList TemperatureInfo => new(SensorType.Temperature, "Core (Tdie)", "Core (Tctl/Tdie)", "CPU Cores");

public AMDCPU(int id)
: base(id)
{
}
protected override SensorInfo TemperatureInfo => new(SensorType.Temperature, "Core (Tdie)", "Core (Tctl/Tdie)", "CPU Cores");
}

public class GPU : HardwareComponent
Expand All @@ -137,7 +92,7 @@ public class GPU : HardwareComponent
private readonly SensorInfo powerInfo = new(SensorType.Power, "GPU Package");
private readonly SensorInfo temperatureInfo = new(SensorType.Temperature, "GPU Core");
private readonly SensorInfo memoryFreeInfo = new(SensorType.SmallData, "GPU Memory Free");
private readonly SensorInfo memoryUsedINfo = new(SensorType.SmallData, "GPU Memory Used");
private readonly SensorInfo memoryUsedInfo = new(SensorType.SmallData, "GPU Memory Used", "D3D Dedicated Memory Used");
private readonly SensorInfo memoryTotalInfo = new(SensorType.SmallData, "GPU Memory Total");

public int Power { get; private set; }
Expand All @@ -147,18 +102,13 @@ public class GPU : HardwareComponent
public float MemoryTotal { get; private set; }
public float MemoryUsage => MemoryUsed / MemoryTotal;

public GPU(int id)
: base(id)
{
}

public override void Update(ISensor sensor)
{
base.Update(sensor);
if (GetIntValue(sensor, powerInfo, out var powerValue)) Power = powerValue;
if (GetIntValue(sensor, temperatureInfo, out var temperatureValue)) Temperature = temperatureValue;
if (GetFloatValue(sensor, memoryFreeInfo, out var memoryFreeValue)) MemoryFree = memoryFreeValue;
if (GetFloatValue(sensor, memoryUsedINfo, out var memoryUsedValue)) MemoryUsed = memoryUsedValue;
if (GetFloatValue(sensor, memoryUsedInfo, out var memoryUsedValue)) MemoryUsed = memoryUsedValue;
if (GetFloatValue(sensor, memoryTotalInfo, out var memoryTotalValue)) MemoryTotal = memoryTotalValue;
}
}
Expand All @@ -173,11 +123,6 @@ public class RAM : HardwareComponent
public float Available { get; private set; }
public float Total => Used + Available;

public RAM()
: base(0)
{
}

public override void Update(ISensor sensor)
{
base.Update(sensor);
Expand Down
Loading

0 comments on commit 6242ef9

Please sign in to comment.