Skip to content

Commit

Permalink
major refactoring WIP, implemented ViGEmTargets (Xbox360, DualShock4)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Dec 31, 2021
1 parent 9771c26 commit 3e87f00
Show file tree
Hide file tree
Showing 27 changed files with 372 additions and 291 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.cs]

# CA1416: Valider la compatibilité de la plateforme
dotnet_diagnostic.CA1416.severity = none
3 changes: 3 additions & 0 deletions ControllerCommon/ControllerCommon.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<PackageReference Include="Nefarius.ViGEm.Client" Version="1.17.178" />
<PackageReference Include="NetCoreNamedPipeWrapper" Version="1.0.4" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.DirectInput" Version="4.2.0" />
<PackageReference Include="SharpDX.XInput" Version="4.2.0" />
<PackageReference Include="System.IO.Pipes.AccessControl" Version="5.0.0" />
<PackageReference Include="System.Management" Version="6.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" />
Expand Down
15 changes: 15 additions & 0 deletions ControllerCommon/HIDmode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerCommon
{
public enum HIDmode
{
DualShock4Controller = 0,
Xbox360Controller = 1,
NoController = 2,
}
}
11 changes: 8 additions & 3 deletions ControllerCommon/PipeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public PipeClient(string pipeName)
client.Error += OnError;
}

public override string ToString()
{
return this.GetType().Name;
}

public PipeClient(string pipeName, ILogger logger) : this(pipeName)
{
this.logger = logger;
Expand All @@ -61,7 +66,7 @@ public void Start()
return;

client.Start();
logger?.LogInformation($"Pipe Client has started");
logger?.LogInformation("{0} has started" , this.ToString());
}

public void Stop()
Expand All @@ -70,7 +75,7 @@ public void Stop()
return;

client.Stop();
logger?.LogInformation($"Pipe Client has stopped");
logger?.LogInformation("{0} has stopped", this.ToString());
}

private void OnServerMessage(NamedPipeConnection<PipeMessage, PipeMessage> connection, PipeMessage message)
Expand All @@ -90,7 +95,7 @@ private void OnServerMessage(NamedPipeConnection<PipeMessage, PipeMessage> conne

private void OnError(Exception exception)
{
logger?.LogError("PipClient failed. {0}", exception.Message);
logger?.LogError("{0} failed. {1}", this.ToString(), exception.Message);
}

public void SendMessage(PipeMessage message)
Expand Down
2 changes: 1 addition & 1 deletion ControllerCommon/PipeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public PipeClientScreen()
[Serializable]
public class PipeClientSettings : PipeMessage
{
public Dictionary<string, string> settings = new();
public Dictionary<string, object> settings = new();

public PipeClientSettings()
{
Expand Down
11 changes: 8 additions & 3 deletions ControllerCommon/PipeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public PipeServer(string pipeName)
server.Error += OnError;
}

public override string ToString()
{
return this.GetType().Name;
}

public PipeServer(string pipeName, ILogger logger) : this(pipeName)
{
this.logger = logger;
Expand All @@ -94,7 +99,7 @@ public void Start()
return;

server.Start();
logger?.LogInformation($"Pipe Server has started");
logger?.LogInformation("{0} has started", this.ToString());
}

public void Stop()
Expand All @@ -103,7 +108,7 @@ public void Stop()
return;

server = null;
logger?.LogInformation($"Pipe Server has stopped");
logger?.LogInformation("{0} has stopped", this.ToString());
}

private void OnClientConnected(NamedPipeConnection<PipeMessage, PipeMessage> connection)
Expand Down Expand Up @@ -133,7 +138,7 @@ private void OnClientMessage(NamedPipeConnection<PipeMessage, PipeMessage> conne

private void OnError(Exception exception)
{
logger?.LogError("PipeServer failed. {0}", exception.Message);
logger?.LogError("{0} failed. {1}", this.ToString(), exception.Message);
}

public void SendMessage(PipeMessage message)
Expand Down
35 changes: 1 addition & 34 deletions ControllerCommon/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ public enum InputStyle
Mouse = 3
}

public class ProfileButton : DualShock4Button
{
public ProfileButton(int id, string name, ushort value) : base(id, name, value)
{
}

public static ProfileButton AlwaysOn = new ProfileButton(12, "Always On", 8);
}

[Serializable]
public class Profile
{
Expand All @@ -50,7 +41,7 @@ public class Profile
public float umc_sensivity { get; set; } = 2.0f;
public float umc_intensity { get; set; } = 1.0f;

public int umc_trigger { get; set; } = 0;
public uint umc_trigger { get; set; } = 0;

[JsonIgnore] public ProfileErrorCode error;
[JsonIgnore] public string fullpath { get; set; }
Expand Down Expand Up @@ -81,29 +72,5 @@ public override string ToString()
{
return name;
}

public static Dictionary<int, DualShock4Button> ListTriggers()
{
return new Dictionary<int, DualShock4Button>() {
{ ProfileButton.AlwaysOn.Value, ProfileButton.AlwaysOn },

{ DualShock4Button.ThumbRight.Value, DualShock4Button.ThumbRight },
{ DualShock4Button.ThumbLeft.Value, DualShock4Button.ThumbLeft },

{ DualShock4Button.Options.Value, DualShock4Button.Options },
{ DualShock4Button.Share.Value, DualShock4Button.Share },

{ DualShock4Button.TriggerRight.Value, DualShock4Button.TriggerRight },
{ DualShock4Button.TriggerLeft.Value, DualShock4Button.TriggerLeft },

{ DualShock4Button.ShoulderRight.Value, DualShock4Button.ShoulderRight },
{ DualShock4Button.ShoulderLeft.Value, DualShock4Button.ShoulderLeft },

{ DualShock4Button.Triangle.Value, DualShock4Button.Triangle },
{ DualShock4Button.Circle.Value, DualShock4Button.Circle },
{ DualShock4Button.Cross.Value, DualShock4Button.Cross },
{ DualShock4Button.Square.Value, DualShock4Button.Square },
};
}
}
}
24 changes: 24 additions & 0 deletions ControllerCommon/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.Toolkit.Uwp.Notifications;
using SharpDX.XInput;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Management;
Expand Down Expand Up @@ -31,6 +33,28 @@ public enum BinaryType : uint
static extern uint QueryFullProcessImageName(IntPtr hProcess, uint flags, StringBuilder text, out uint size);
#endregion

[Flags]
public enum GamepadButtonFlags : uint
{
DPadUp = 1,
DPadDown = 2,
DPadLeft = 4,
DPadRight = 8,
Start = 16,
Back = 32,
LeftThumb = 64,
RightThumb = 128,
LeftShoulder = 256,
RightShoulder = 512,
LeftTrigger = 1024,
RightTrigger = 2048,
A = 4096,
B = 8192,
X = 16384,
Y = 32768,
AlwaysOn = 65536
}

public static void SendToast(string title, string content)
{
string url = "file:///" + AppDomain.CurrentDomain.BaseDirectory + "Toast.png";
Expand Down
17 changes: 0 additions & 17 deletions ControllerHelper/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,4 @@ public override string ToString()
return this.ProductName;
}
}

class HIDmode
{
public string mode;
public string name;

public HIDmode(string mode, string name)
{
this.mode = mode;
this.name = name;
}

public override string ToString()
{
return this.name;
}
}
}
4 changes: 3 additions & 1 deletion ControllerHelper/ControllerHelper.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3e87f00

Please sign in to comment.