Skip to content

Commit

Permalink
Implement Shared project (Valkirie#372)
Browse files Browse the repository at this point in the history
* implement Shared project

* remove NotImplementedException

* added try catch to ADLX_Wrapper on IntializeAdlx()

* implement PipeServer

* update libraries

* Remove Debug.WriteLine

* On AMDGPU, if we couldn't pick a display by its name, pick first

* reduce loading time and improve threading

- Make MultimediaManager async
- Make HotkeysManager async
- Don't load OverlayMode on startup
  • Loading branch information
Valkirie authored Nov 24, 2024
1 parent 8eb047c commit 688f267
Show file tree
Hide file tree
Showing 87 changed files with 484 additions and 144 deletions.
11 changes: 11 additions & 0 deletions HandheldCompanion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HandheldCompanion", "HandheldCompanion\HandheldCompanion.csproj", "{AD4B9060-93FE-4FD2-B64D-4D31EABC7C4D}"
ProjectSection(ProjectDependencies) = postProject
{430DD98B-FF67-42A2-9996-D2F90369E625} = {430DD98B-FF67-42A2-9996-D2F90369E625}
{F7283783-81EF-4CD2-BD86-598FE193C11F} = {F7283783-81EF-4CD2-BD86-598FE193C11F}
EndProjectSection
EndProject
Expand All @@ -20,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "steam-hidapi.net", "steam-h
{9B860078-9AD1-45DD-8F85-E6D806E5DC9B} = {9B860078-9AD1-45DD-8F85-E6D806E5DC9B}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{430DD98B-FF67-42A2-9996-D2F90369E625}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -52,6 +55,14 @@ Global
{F7283783-81EF-4CD2-BD86-598FE193C11F}.Release|Any CPU.Build.0 = Release|Any CPU
{F7283783-81EF-4CD2-BD86-598FE193C11F}.Release|x64.ActiveCfg = Release|x64
{F7283783-81EF-4CD2-BD86-598FE193C11F}.Release|x64.Build.0 = Release|x64
{430DD98B-FF67-42A2-9996-D2F90369E625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Debug|Any CPU.Build.0 = Debug|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Debug|x64.ActiveCfg = Debug|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Debug|x64.Build.0 = Debug|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Release|Any CPU.ActiveCfg = Release|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Release|Any CPU.Build.0 = Release|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Release|x64.ActiveCfg = Release|Any CPU
{430DD98B-FF67-42A2-9996-D2F90369E625}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
33 changes: 24 additions & 9 deletions HandheldCompanion/ADLX/ADLXBackend.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;

namespace HandheldCompanion.ADLX
Expand Down Expand Up @@ -70,20 +73,17 @@ public enum ADLX_RESULT
ADLX_GPU_INACTIVE /**< @ENG_START_DOX This result indicates that the GPU is inactive. @ENG_END_DOX */
}

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool IntializeAdlx();
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool InitializeAdlxWithIncompatibleDriver();
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] private static extern bool IntializeAdlx();
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] private static extern bool InitializeAdlxWithIncompatibleDriver();
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool CloseAdlx();

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern ADLX_RESULT GetNumberOfDisplays(ref int displayNum);

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
public static extern ADLX_RESULT GetDisplayName(int idx, StringBuilder dispName, int nameLength);
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern ADLX_RESULT GetDisplayName(int idx, StringBuilder dispName, int nameLength);

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)]
public static extern ADLX_RESULT GetDisplayGPU(int idx, ref int UniqueId);
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern ADLX_RESULT GetDisplayGPU(int idx, ref int UniqueId);

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)]
public static extern ADLX_RESULT GetGPUIndex(int UniqueId, ref int idx);
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern ADLX_RESULT GetGPUIndex(int UniqueId, ref int idx);

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool HasRSRSupport();
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool GetRSR();
Expand Down Expand Up @@ -128,5 +128,20 @@ public enum ADLX_RESULT
[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool SetScalingMode(int displayIdx, int mode);

[DllImport(ADLX_Wrapper, CallingConvention = CallingConvention.Cdecl)] public static extern bool GetAdlxTelemetry(int GPU, ref AdlxTelemetryData adlxTelemetryData);

static ADLXBackend() { }

[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
public static bool SafeIntializeAdlx()
{
try
{
return IntializeAdlx();
}
catch (Exception ex) { }

return false;
}
}
}
Binary file modified HandheldCompanion/ADLX_Wrapper.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion HandheldCompanion/Actions/IActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public virtual void Execute(ButtonFlags button, bool value, ShiftSlot shiftSlot
value = true;
}

switch(ShiftSlot)
switch (ShiftSlot)
{
case ShiftSlot.None:
if (shiftSlot != ShiftSlot.None)
Expand Down
4 changes: 0 additions & 4 deletions HandheldCompanion/Actions/ShiftActions.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Simulators;
using System;
using System.ComponentModel;
using System.Numerics;
using WindowsInput.Events;

namespace HandheldCompanion.Actions
{
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</sectionGroup>
</configSections>
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true"/>
<AppContextSwitchOverrides value="Switch.System.Windows.Media.HostVisual.DisconnectsOnWrongThread=true"/>
</runtime>
<userSettings>
Expand Down
4 changes: 3 additions & 1 deletion HandheldCompanion/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using HandheldCompanion.Views;
using Sentry;
Expand Down Expand Up @@ -44,8 +45,9 @@ protected override void OnStartup(StartupEventArgs args)
string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string logDirectory = System.IO.Path.Combine(myDocumentsPath, "HandheldCompanion", "logs");

// Set the LOG_PATH environment variable
// Set environment variables
Environment.SetEnvironmentVariable("LOG_PATH", logDirectory);
Environment.SetEnvironmentVariable("COMPlus_legacyCorruptedStateExceptionsPolicy", "1");

// initialize log
LogManager.Initialize("HandheldCompanion");
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Controllers/GordonController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HandheldCompanion.Helpers;
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using SharpDX.XInput;
using steam_hidapi.net;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Controllers/IController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Misc;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using System;
using System.Collections.Generic;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Controllers/NeptuneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HandheldCompanion.Helpers;
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using SharpDX.XInput;
using steam_hidapi.net;
using steam_hidapi.net.Hid;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Devices;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Devices;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using System;
using System.Collections.Generic;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/DSU/DSUServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HandheldCompanion.Helpers;
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using System;
using System.Collections.Generic;
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Devices/AOKZOE/AOKZOEA1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HidLibrary;
using System;
using System.Collections.Generic;
Expand Down
5 changes: 1 addition & 4 deletions HandheldCompanion/Devices/ASUS/AsusACPI.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System;
using System.Management;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -265,8 +265,6 @@ protected byte[] CallMethod(uint MethodID, byte[] args)
BitConverter.GetBytes((uint)args.Length).CopyTo(acpiBuf, 4);
Array.Copy(args, 0, acpiBuf, 8, args.Length);

// if (MethodID == DEVS) Debug.WriteLine(BitConverter.ToString(acpiBuf, 0, acpiBuf.Length));

Control(CONTROL_CODE, acpiBuf, outBuffer);

return outBuffer;
Expand Down Expand Up @@ -474,7 +472,6 @@ public void TUFKeyboardRGB(int mode, System.Drawing.Color color, int speed)
setting[5] = (byte)speed;

DeviceSet(TUF_KB, setting, "TUF RGB");
//Debug.WriteLine(BitConverter.ToString(setting));
}

public void TUFKeyboardPower(bool awake = true, bool boot = false, bool sleep = false, bool shutdown = false)
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Devices/GPD/GPDWin4.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System;
using System.Collections.Generic;
using System.Numerics;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Devices/IDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using HandheldCompanion.Misc;
using HandheldCompanion.Models;
using HandheldCompanion.Sensors;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using HidLibrary;
using Nefarius.Utilities.DeviceManagement.PnP;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Devices/Lenovo/LegionGo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Misc;
using HandheldCompanion.Shared;
using HidLibrary;
using Nefarius.Utilities.DeviceManagement.PnP;
using System;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Devices/MSI/ClawA1M.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HandheldCompanion.Utils;
using HidLibrary;
using Nefarius.Utilities.DeviceManagement.PnP;
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Devices/OneXPlayer/OneXPlayer2.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System.Numerics;
using WindowsInput.Events;

Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Devices/OneXPlayer/OneXPlayerMini.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System.Collections.Generic;
using System.Numerics;
using WindowsInput.Events;
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Devices/OneXPlayer/OneXPlayerMiniPro.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System.Numerics;
using WindowsInput.Events;

Expand Down
6 changes: 3 additions & 3 deletions HandheldCompanion/Devices/OneXPlayer/OneXPlayerOneXFly.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using HidLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Windows.Media;
using WindowsInput.Events;
namespace HandheldCompanion.Devices;
using static HandheldCompanion.Utils.DeviceUtils;


namespace HandheldCompanion.Devices;
public class OneXPlayerOneXFly : IDevice
{
HidDevice hidDevice;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Devices/OneXPlayer/OneXPlayerX1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using HandheldCompanion.Misc.Threading.Tasks;
using HandheldCompanion.Models;
using HandheldCompanion.Sensors;
using HandheldCompanion.Shared;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Devices/Valve/SteamDeck.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using HandheldCompanion.Inputs;
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System;
using System.Linq;

Expand Down
9 changes: 6 additions & 3 deletions HandheldCompanion/GraphicsProcessingUnit/AMDGPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ public AMDGPU(AdapterInformation adapterInformation) : base(adapterInformation)
if (result != ADLX_RESULT.ADLX_OK)
return;

if (adapterCount == 1)
displayIdx = 0;
else
if (adapterCount > 1)
{
for (int idx = 0; idx < adapterCount; idx++)
{
Expand All @@ -322,6 +320,11 @@ public AMDGPU(AdapterInformation adapterInformation) : base(adapterInformation)
}
}

// we couldn't pick a display by its name, pick first
// todo: improve me
if (displayIdx == -1)
displayIdx = 0;

if (displayIdx != -1)
{
// get the associated GPU UniqueId
Expand Down
20 changes: 2 additions & 18 deletions HandheldCompanion/HandheldCompanion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,9 @@
<PackageReference Include="GregsStack.InputSimulatorStandard" Version="1.3.5" />
<PackageReference Include="HelixToolkit.Core.Wpf" Version="2.25.0" />
<PackageReference Include="iNKORE.UI.WPF.Modern" Version="0.9.30" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.4-pre353" />
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.4-pre358" />
<PackageReference Include="LiveCharts.Wpf.Core" Version="0.9.8" />
<PackageReference Include="MathConverter" Version="2.2.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="NAudio.Vorbis" Version="1.5.0" />
Expand All @@ -220,19 +217,11 @@
<PackageReference Include="PixiEditor.ColorPicker" Version="3.3.1" />
<PackageReference Include="PrecisionTimer.NET" Version="3.0.0.7" />
<PackageReference Include="Sentry" Version="4.13.0" />
<PackageReference Include="Sentry.Profiling" Version="4.13.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.Direct3D9" Version="4.2.0" />
<PackageReference Include="SharpDX.DirectInput" Version="4.2.0" />
<PackageReference Include="SharpDX.XInput" Version="4.2.0" />
<PackageReference Include="System.Drawing.Common" Version="9.0.0" />
<PackageReference Include="System.IO.Ports" Version="9.0.0" />
<PackageReference Include="System.Management" Version="9.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="9.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.0" />
<PackageReference Include="WindowsAPICodePack" Version="8.0.6" />
Expand All @@ -242,6 +231,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
<ProjectReference Include="..\steam-hidapi.net\steam-hidapi.net.csproj" />
</ItemGroup>

Expand Down Expand Up @@ -276,9 +266,6 @@
</ItemGroup>

<ItemGroup>
<None Update="ADLX_Wrapper.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="GamepadMotion.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -2371,9 +2358,6 @@
<Reference Include="Microsoft.Win32.TaskScheduler">
<HintPath>..\Resources\Microsoft.Win32.TaskScheduler.dll</HintPath>
</Reference>
<Reference Include="Nefarius.Utilities.DeviceManagement">
<HintPath>..\Resources\Nefarius.Utilities.DeviceManagement.dll</HintPath>
</Reference>
<Reference Include="Nefarius.ViGEm.Client">
<HintPath>..\Resources\Nefarius.ViGEm.Client.dll</HintPath>
</Reference>
Expand Down
2 changes: 1 addition & 1 deletion HandheldCompanion/Helpers/RyzenSMU.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down
1 change: 1 addition & 0 deletions HandheldCompanion/Helpers/VangoghGPU.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HandheldCompanion.Managers;
using HandheldCompanion.Shared;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down
4 changes: 2 additions & 2 deletions HandheldCompanion/Localization/StaticExtension.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace HandheldCompanion.Localization;


using System.Windows.Data;

namespace HandheldCompanion.Localization;
public class StaticExtension : Binding
{
public StaticExtension(string name) : base("[" + name + "]")
Expand Down
Loading

0 comments on commit 688f267

Please sign in to comment.