Skip to content

Commit cade1a9

Browse files
author
Aytackydln
committed
add icue profile
1 parent fb28816 commit cade1a9

31 files changed

Lines changed: 1118 additions & 51 deletions

Project-Aurora/Project-Aurora/AuroraApp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public AuroraApp(bool isSilent)
6262
_processesModule,
6363
new LogitechSdkModule(ProcessesModule.RunningProcessMonitor),
6464
new RazerSdkModule(),
65+
new IcueModule(ProcessesModule.RunningProcessMonitor),
6566
new GamebarGamesModule(),
6667
PluginsModule,
6768
lightingStateManagerModule,
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Threading.Tasks;
4+
using AuroraRgb.Modules.ProcessMonitor;
5+
using iCUE_ReverseEngineer.Icue;
6+
7+
namespace AuroraRgb.Modules.Icue;
8+
9+
public enum IcueServerStatus
10+
{
11+
[Description("Disabled")]
12+
Disabled,
13+
[Description("Waiting for Games")]
14+
Waiting,
15+
[Description("Pipes in Use")]
16+
PipesInUse,
17+
Conflicted,
18+
}
19+
20+
public sealed class AuroraIcueServer : IDisposable, IAsyncDisposable
21+
{
22+
public IcueGsi Gsi { get; } = new();
23+
public IcueSdk Sdk { get; } = new();
24+
25+
public event EventHandler? StatusChanged;
26+
27+
private IcueServerStatus _serverStatus = IcueServerStatus.Disabled;
28+
29+
public IcueServerStatus ServerStatus
30+
{
31+
get => _serverStatus;
32+
private set
33+
{
34+
if (_serverStatus == value) return;
35+
_serverStatus = value;
36+
StatusChanged?.Invoke(this, EventArgs.Empty);
37+
}
38+
}
39+
40+
private IcueServer? _icueServer;
41+
private GameHandler? _gameHandler;
42+
43+
public void RunServer(RunningProcessMonitor processMonitor)
44+
{
45+
Sdk.RunningProcessMonitor = processMonitor;
46+
var runApproved = IcueInstallationUtils.IsIcueInstalled() && IcueInstallationUtils.IsIcueAutorunEnabled();
47+
if (runApproved || processMonitor.IsProcessRunning(IcueInstallationUtils.IcueExe))
48+
{
49+
ServerStatus = IcueServerStatus.Conflicted;
50+
return;
51+
}
52+
53+
TryStartServer();
54+
}
55+
56+
private void TryStartServer()
57+
{
58+
try
59+
{
60+
// Dispose previous just in case
61+
if (_icueServer != null)
62+
{
63+
_icueServer.Dispose();
64+
_icueServer.GameConnected -= OnGameConnected;
65+
_icueServer = null;
66+
}
67+
68+
_icueServer = new IcueServer();
69+
_icueServer.GameConnected += OnGameConnected;
70+
_icueServer.Run();
71+
ServerStatus = IcueServerStatus.Waiting;
72+
}
73+
catch (Exception)
74+
{
75+
// Most likely pipes are in use by iCUE at this moment
76+
_icueServer = null;
77+
ServerStatus = IcueServerStatus.PipesInUse;
78+
}
79+
}
80+
81+
private void OnGameConnected(object? sender, GameHandler gameHandler)
82+
{
83+
_gameHandler = gameHandler;
84+
Gsi.SetGsiHandler(gameHandler.GsiHandler);
85+
Sdk.SetSdkHandler(gameHandler.SdkHandler, gameHandler.GamePid);
86+
87+
gameHandler.GameDisconnected += OnGameDisconnected;
88+
}
89+
90+
private void OnGameDisconnected(object? sender, EventArgs e)
91+
{
92+
_gameHandler?.Dispose();
93+
_gameHandler = null;
94+
Gsi.ClearGsiHandler();
95+
Sdk.ClearSdkHandler();
96+
}
97+
98+
public void Dispose()
99+
{
100+
ServerStatus = IcueServerStatus.Disabled;
101+
if (_icueServer == null) return;
102+
_icueServer.GameConnected -= OnGameConnected;
103+
_icueServer.Dispose();
104+
}
105+
106+
public async ValueTask DisposeAsync()
107+
{
108+
ServerStatus = IcueServerStatus.Disabled;
109+
if (_icueServer == null)
110+
{
111+
return;
112+
}
113+
114+
_icueServer.GameConnected -= OnGameConnected;
115+
await _icueServer.DisposeAsync();
116+
}
117+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using System.Collections.Frozen;
2+
using System.Collections.Generic;
3+
using Common.Devices;
4+
using iCUE_ReverseEngineer;
5+
6+
namespace AuroraRgb.Modules.Icue;
7+
8+
public static class IcueAuroraKeyMapping
9+
{
10+
public static FrozenDictionary<IcueLedId, DeviceKeys> KeyMapping { get; } = new Dictionary<IcueLedId, DeviceKeys>
11+
{
12+
{ IcueLedId.Escape, DeviceKeys.ESC },
13+
{ IcueLedId.F1, DeviceKeys.F1 },
14+
{ IcueLedId.F2, DeviceKeys.F2 },
15+
{ IcueLedId.F3, DeviceKeys.F3 },
16+
{ IcueLedId.F4, DeviceKeys.F4 },
17+
{ IcueLedId.F5, DeviceKeys.F5 },
18+
{ IcueLedId.F6, DeviceKeys.F6 },
19+
{ IcueLedId.F7, DeviceKeys.F7 },
20+
{ IcueLedId.F8, DeviceKeys.F8 },
21+
{ IcueLedId.F9, DeviceKeys.F9 },
22+
{ IcueLedId.F10, DeviceKeys.F10 },
23+
{ IcueLedId.F11, DeviceKeys.F11 },
24+
{ IcueLedId.F12, DeviceKeys.F12 },
25+
26+
{ IcueLedId.PrintScreen, DeviceKeys.PRINT_SCREEN },
27+
{ IcueLedId.ScrollLock, DeviceKeys.SCROLL_LOCK },
28+
{ IcueLedId.PauseBreak, DeviceKeys.PAUSE_BREAK },
29+
30+
{ IcueLedId.Tilde, DeviceKeys.HASHTAG },
31+
32+
{ IcueLedId.One, DeviceKeys.ONE },
33+
{ IcueLedId.Two, DeviceKeys.TWO },
34+
{ IcueLedId.Three, DeviceKeys.THREE },
35+
{ IcueLedId.Four, DeviceKeys.FOUR },
36+
{ IcueLedId.Five, DeviceKeys.FIVE },
37+
{ IcueLedId.Six, DeviceKeys.SIX },
38+
{ IcueLedId.Seven, DeviceKeys.SEVEN },
39+
{ IcueLedId.Eight, DeviceKeys.EIGHT },
40+
{ IcueLedId.Nine, DeviceKeys.NINE },
41+
{ IcueLedId.Zero, DeviceKeys.ZERO },
42+
43+
{ IcueLedId.Minus, DeviceKeys.MINUS },
44+
{ IcueLedId.Equals, DeviceKeys.EQUALS },
45+
{ IcueLedId.Backspace, DeviceKeys.BACKSPACE },
46+
47+
{ IcueLedId.Insert, DeviceKeys.INSERT },
48+
{ IcueLedId.Home, DeviceKeys.HOME },
49+
{ IcueLedId.PageUp, DeviceKeys.PAGE_UP },
50+
51+
{ IcueLedId.NumLock, DeviceKeys.NUM_LOCK },
52+
{ IcueLedId.NumpadSlash, DeviceKeys.NUM_SLASH },
53+
{ IcueLedId.NumpadAsterisk, DeviceKeys.NUM_ASTERISK },
54+
{ IcueLedId.NumpadMinus, DeviceKeys.NUM_MINUS },
55+
56+
{ IcueLedId.Tab, DeviceKeys.TAB },
57+
58+
{ IcueLedId.Q, DeviceKeys.Q },
59+
{ IcueLedId.W, DeviceKeys.W },
60+
{ IcueLedId.E, DeviceKeys.E },
61+
{ IcueLedId.R, DeviceKeys.R },
62+
{ IcueLedId.T, DeviceKeys.T },
63+
{ IcueLedId.Y, DeviceKeys.Y },
64+
{ IcueLedId.U, DeviceKeys.U },
65+
{ IcueLedId.I, DeviceKeys.I },
66+
{ IcueLedId.O, DeviceKeys.O },
67+
{ IcueLedId.P, DeviceKeys.P },
68+
69+
{ IcueLedId.OpenBracket, DeviceKeys.OPEN_BRACKET },
70+
{ IcueLedId.CloseBracket, DeviceKeys.CLOSE_BRACKET },
71+
{ IcueLedId.Enter, DeviceKeys.ENTER },
72+
73+
{ IcueLedId.Delete, DeviceKeys.DELETE },
74+
{ IcueLedId.End, DeviceKeys.END },
75+
{ IcueLedId.PageDown, DeviceKeys.PAGE_DOWN },
76+
77+
{ IcueLedId.CapsLock, DeviceKeys.CAPS_LOCK },
78+
79+
{ IcueLedId.A, DeviceKeys.A },
80+
{ IcueLedId.S, DeviceKeys.S },
81+
{ IcueLedId.D, DeviceKeys.D },
82+
{ IcueLedId.F, DeviceKeys.F },
83+
{ IcueLedId.G, DeviceKeys.G },
84+
{ IcueLedId.H, DeviceKeys.H },
85+
{ IcueLedId.J, DeviceKeys.J },
86+
{ IcueLedId.K, DeviceKeys.K },
87+
{ IcueLedId.L, DeviceKeys.L },
88+
89+
{ IcueLedId.Semicolon, DeviceKeys.SEMICOLON },
90+
{ IcueLedId.SingleQuote, DeviceKeys.APOSTROPHE },
91+
// nonustilde
92+
//{ IcueLedId.NonUsTilde, DeviceKeys.NON_US_TILDE },
93+
94+
{ IcueLedId.ShiftLeft, DeviceKeys.LEFT_SHIFT },
95+
{ IcueLedId.Backslash, DeviceKeys.BACKSLASH_UK },
96+
{ IcueLedId.Z, DeviceKeys.Z },
97+
{ IcueLedId.X, DeviceKeys.X },
98+
{ IcueLedId.C, DeviceKeys.C },
99+
{ IcueLedId.V, DeviceKeys.V },
100+
{ IcueLedId.B, DeviceKeys.B },
101+
{ IcueLedId.N, DeviceKeys.N },
102+
{ IcueLedId.M, DeviceKeys.M },
103+
104+
{ IcueLedId.Comma, DeviceKeys.COMMA },
105+
{ IcueLedId.Period, DeviceKeys.PERIOD },
106+
{ IcueLedId.ForwardSlash, DeviceKeys.FORWARD_SLASH },
107+
108+
{ IcueLedId.RightShift, DeviceKeys.RIGHT_SHIFT },
109+
110+
{ IcueLedId.UpArrow, DeviceKeys.ARROW_UP },
111+
112+
{ IcueLedId.LeftControl, DeviceKeys.LEFT_CONTROL },
113+
{ IcueLedId.LeftWindows, DeviceKeys.LEFT_WINDOWS },
114+
{ IcueLedId.LeftAlt, DeviceKeys.LEFT_ALT },
115+
116+
{ IcueLedId.Space, DeviceKeys.SPACE },
117+
118+
{ IcueLedId.RightAlt, DeviceKeys.RIGHT_ALT },
119+
{ IcueLedId.ContextMenu, DeviceKeys.APPLICATION_SELECT },
120+
{ IcueLedId.Fn, DeviceKeys.FN_Key },
121+
{ IcueLedId.RightControl, DeviceKeys.RIGHT_CONTROL },
122+
123+
{ IcueLedId.LeftArrow, DeviceKeys.ARROW_LEFT },
124+
{ IcueLedId.DownArrow, DeviceKeys.ARROW_DOWN },
125+
{ IcueLedId.RightArrow, DeviceKeys.ARROW_RIGHT },
126+
127+
{ IcueLedId.NumpadSeven, DeviceKeys.NUM_SEVEN },
128+
{ IcueLedId.NumpadEight, DeviceKeys.NUM_EIGHT },
129+
{ IcueLedId.NumpadNine, DeviceKeys.NUM_NINE },
130+
{ IcueLedId.NumpadPlus, DeviceKeys.NUM_PLUS },
131+
132+
{ IcueLedId.NumpadFour, DeviceKeys.NUM_FOUR },
133+
{ IcueLedId.NumpadFive, DeviceKeys.NUM_FIVE },
134+
{ IcueLedId.NumpadSix, DeviceKeys.NUM_SIX },
135+
136+
{ IcueLedId.NumpadOne, DeviceKeys.NUM_ONE },
137+
{ IcueLedId.NumpadTwo, DeviceKeys.NUM_TWO },
138+
{ IcueLedId.NumpadThree, DeviceKeys.NUM_THREE },
139+
{ IcueLedId.NumpadZero, DeviceKeys.NUM_ZERO },
140+
141+
{ IcueLedId.NumpadPeriod, DeviceKeys.NUM_PERIOD },
142+
{ IcueLedId.NumpadEnter, DeviceKeys.NUM_ENTER },
143+
}.ToFrozenDictionary();
144+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using iCUE_ReverseEngineer.Icue.Gsi;
4+
5+
namespace AuroraRgb.Modules.Icue;
6+
7+
public class IcueGsi
8+
{
9+
public event EventHandler<IcueStateEventArgs>? EventReceived;
10+
public HashSet<string> States { get; } = [];
11+
12+
private GsiHandler? _gsiHandler;
13+
14+
public void SetGsiHandler(GsiHandler gsiHandler)
15+
{
16+
_gsiHandler = gsiHandler;
17+
_gsiHandler.StateAdded += OnStateAdded;
18+
_gsiHandler.StateRemoved += OnStateRemoved;
19+
_gsiHandler.StatesCleared += OnStatesCleared;
20+
_gsiHandler.EventAdded += OnEventAdded;
21+
}
22+
23+
public void ClearGsiHandler()
24+
{
25+
if (_gsiHandler == null)
26+
{
27+
return;
28+
}
29+
30+
_gsiHandler.StateAdded -= OnStateAdded;
31+
_gsiHandler.StateRemoved -= OnStateRemoved;
32+
_gsiHandler.StatesCleared -= OnStatesCleared;
33+
_gsiHandler.EventAdded -= OnEventAdded;
34+
35+
_gsiHandler = null;
36+
}
37+
38+
private void OnStateAdded(object? sender, IcueStateEventArgs icueStateEventArgs)
39+
{
40+
States.Add(icueStateEventArgs.StateName);
41+
}
42+
43+
private void OnStateRemoved(object? sender, IcueStateEventArgs icueStateEventArgs)
44+
{
45+
States.Remove(icueStateEventArgs.StateName);
46+
}
47+
48+
private void OnStatesCleared(object? sender, EventArgs e)
49+
{
50+
States.Clear();
51+
}
52+
53+
private void OnEventAdded(object? sender, IcueStateEventArgs icueStateEventArgs)
54+
{
55+
EventReceived?.Invoke(this, icueStateEventArgs);
56+
}
57+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Collections.Frozen;
2+
using AuroraRgb.Utils;
3+
4+
namespace AuroraRgb.Modules.Icue;
5+
6+
public static class IcueInstallationUtils
7+
{
8+
public const string IcueExe = "icue.exe";
9+
10+
private static readonly FrozenSet<string> IcueAutoStartNames = new[]
11+
{
12+
"Corsair iCUE5 Software",
13+
}.ToFrozenSet();
14+
15+
public static bool IsIcueInstalled()
16+
{
17+
return AutoStartUtils.IsSoftwareInstalled(IcueAutoStartNames);
18+
}
19+
20+
public static bool IsIcueAutorunEnabled()
21+
{
22+
return AutoStartUtils.IsAutorunEnabled(IcueAutoStartNames);
23+
}
24+
}

0 commit comments

Comments
 (0)