1
1
using Nefarius . ViGEm . Client ;
2
2
using Nefarius . ViGEm . Client . Targets ;
3
+ using Nefarius . ViGEm . Client . Targets . Xbox360 ;
3
4
using System ;
4
5
using System . Collections . Specialized ;
5
6
using System . Configuration ;
@@ -38,20 +39,20 @@ class Program
38
39
static IXbox360Controller VirtualXBOX ;
39
40
static XInputGirometer Gyrometer ;
40
41
static XInputAccelerometer Accelerometer ;
42
+ static UdpServer UDPServer ;
41
43
42
44
private delegate bool ConsoleEventDelegate ( int eventType ) ;
43
45
static ConsoleEventDelegate CurrentHandler ;
44
46
static int CurrenthWnd ;
45
47
46
48
static bool IsRunning = true ;
47
- static string CurrentPath , CurrentPathIni , CurrentPathCli ;
49
+ static string CurrentPath , CurrentProfilePath , CurrentPathCli ;
48
50
static PhysicalAddress PadMacAddress = new PhysicalAddress ( new byte [ ] { 0x10 , 0x10 , 0x10 , 0x10 , 0x10 , 0x10 } ) ;
49
51
50
52
// settings vars
51
53
static Settings settings = new Settings ( ) ;
52
54
static int UdpPort ;
53
55
static StringCollection HidHideDevices ;
54
- static bool EnableScreenRatio ;
55
56
56
57
static HidHide hidder ;
57
58
@@ -67,16 +68,12 @@ static void Main()
67
68
68
69
// paths
69
70
CurrentPath = Directory . GetCurrentDirectory ( ) ;
70
- CurrentPathIni = Path . Combine ( CurrentPath , "profiles" ) ;
71
+ CurrentProfilePath = Path . Combine ( CurrentPath , "profiles" ) ;
71
72
CurrentPathCli = @"C:\Program Files\Nefarius Software Solutions e.U\HidHideCLI\HidHideCLI.exe" ;
72
73
73
74
// settings
74
75
UpdateSettings ( ) ;
75
76
76
- // resolution settings
77
- Rectangle resolution = Screen . PrimaryScreen . Bounds ;
78
- float ratio = EnableScreenRatio ? ( ( float ) resolution . Width / ( float ) resolution . Height ) : 1.0f ;
79
-
80
77
if ( ! File . Exists ( CurrentPathCli ) )
81
78
{
82
79
Console . WriteLine ( "HidHide is missing. Please get it from: https://github.com/ViGEm/HidHide/releases" ) ;
@@ -153,7 +150,7 @@ static void Main()
153
150
}
154
151
155
152
// default is 10ms rating and 10 samples
156
- Gyrometer = new XInputGirometer ( settings , ratio ) ;
153
+ Gyrometer = new XInputGirometer ( settings ) ;
157
154
if ( Gyrometer . sensor == null )
158
155
{
159
156
Console . WriteLine ( "No Gyrometer detected. Application will stop." ) ;
@@ -170,15 +167,15 @@ static void Main()
170
167
Environment . Exit ( 0 ) ;
171
168
}
172
169
173
- // start UDP server (temp)
174
- UdpServer _udpServer = new UdpServer ( PadMacAddress ) ;
175
- _udpServer . Start ( UdpPort ) ;
170
+ // start UDP server
171
+ UDPServer = new UdpServer ( PadMacAddress ) ;
172
+ UDPServer . Start ( UdpPort ) ;
176
173
177
- if ( _udpServer != null )
174
+ if ( UDPServer != null )
178
175
{
179
176
Console . WriteLine ( $ "UDP server has started. Listening to port: { UdpPort } ") ;
180
177
Console . WriteLine ( ) ;
181
- PhysicalController . SetUdpServer ( _udpServer ) ;
178
+ PhysicalController . SetUdpServer ( UDPServer ) ;
182
179
}
183
180
184
181
VirtualXBOX . Connect ( ) ;
@@ -195,6 +192,10 @@ static void Main()
195
192
// listen to user inputs (a bit too rigid, improve me)
196
193
Thread MonitorConsole = new Thread ( ConsoleListener ) ;
197
194
MonitorConsole . Start ( ) ;
195
+
196
+ // monitor device battery status and notify UDP server
197
+ Thread MonitorBattery = new Thread ( MonitorBatteryLife ) ;
198
+ MonitorBattery . Start ( ) ;
198
199
}
199
200
200
201
static string Between ( string STR , string FirstString , string LastString )
@@ -206,6 +207,30 @@ static string Between(string STR, string FirstString, string LastString)
206
207
return FinalString ;
207
208
}
208
209
210
+ static void MonitorBatteryLife ( )
211
+ {
212
+ while ( IsRunning )
213
+ {
214
+ BatteryChargeStatus ChargeStatus = SystemInformation . PowerStatus . BatteryChargeStatus ;
215
+ // float ChargePercent = SystemInformation.PowerStatus.BatteryLifePercent;
216
+
217
+ if ( ChargeStatus . HasFlag ( BatteryChargeStatus . Charging ) )
218
+ UDPServer . padMeta . BatteryStatus = DsBattery . Charging ;
219
+ else if ( ChargeStatus . HasFlag ( BatteryChargeStatus . NoSystemBattery ) )
220
+ UDPServer . padMeta . BatteryStatus = DsBattery . None ;
221
+ else if ( ChargeStatus . HasFlag ( BatteryChargeStatus . High ) )
222
+ UDPServer . padMeta . BatteryStatus = DsBattery . High ;
223
+ else if ( ChargeStatus . HasFlag ( BatteryChargeStatus . Low ) )
224
+ UDPServer . padMeta . BatteryStatus = DsBattery . Low ;
225
+ else if ( ChargeStatus . HasFlag ( BatteryChargeStatus . Critical ) )
226
+ UDPServer . padMeta . BatteryStatus = DsBattery . Dying ;
227
+ else
228
+ UDPServer . padMeta . BatteryStatus = DsBattery . Medium ;
229
+
230
+ Thread . Sleep ( 1000 ) ;
231
+ }
232
+ }
233
+
209
234
static void ConsoleListener ( )
210
235
{
211
236
while ( IsRunning )
@@ -280,22 +305,35 @@ static void ConsoleListener()
280
305
281
306
static void UpdateSettings ( )
282
307
{
283
- settings . EnableGyroAiming = Properties . Settings . Default . EnableGyroAiming ;
284
- settings . GyroPullRate = Properties . Settings . Default . GyroPullRate ;
285
- settings . GyroMaxSample = Properties . Settings . Default . GyroMaxSample ;
286
- settings . GyroStickAggressivity = Properties . Settings . Default . GyroStickAggressivity ;
287
- settings . GyroStickRange = Properties . Settings . Default . GyroStickRange ;
288
- settings . GyroStickInvertAxisX = Properties . Settings . Default . GyroStickInvertAxisX ;
289
- settings . GyroStickInvertAxisY = Properties . Settings . Default . GyroStickInvertAxisY ;
290
- settings . GyroStickInvertAxisZ = Properties . Settings . Default . GyroStickInvertAxisZ ;
291
- settings . TriggerString = Properties . Settings . Default . TriggerString ;
308
+ string filename = $ "{ CurrentProfilePath } \\ default.json";
309
+ if ( File . Exists ( filename ) )
310
+ {
311
+ string jsonString = File . ReadAllText ( filename ) ;
312
+ settings = JsonSerializer . Deserialize < Settings > ( jsonString ) ;
313
+ }
314
+ else
315
+ {
316
+ Console . WriteLine ( "Missing default.json profile." ) ;
317
+ settings = new Settings
318
+ {
319
+ GyroAiming = true ,
320
+ PullRate = 10 ,
321
+ MaxSample = 1 ,
322
+ Aggressivity = 0.5f ,
323
+ Range = 10000.0f ,
324
+ InvertAxisX = false ,
325
+ InvertAxisY = false ,
326
+ InvertAxisZ = false ,
327
+ Trigger = "" ,
328
+ MonitorRatio = false
329
+ } ;
330
+ }
292
331
293
332
UdpPort = Properties . Settings . Default . UdpPort ; // 26760
294
333
HidHideDevices = Properties . Settings . Default . HidHideDevices ; // not yet implemented
295
- EnableScreenRatio = Properties . Settings . Default . EnableScreenRatio ;
296
334
297
335
// update controller settings
298
- if ( PhysicalController != null )
336
+ if ( PhysicalController != null && settings != null )
299
337
PhysicalController . UpdateSettings ( settings ) ;
300
338
}
301
339
@@ -316,7 +354,7 @@ static void MonitorProcess()
316
354
Process CurrentProcess = Process . GetProcessById ( ( int ) processId ) ;
317
355
318
356
// check if a specific profile exists for the foreground executable
319
- string filename = $ "{ CurrentPathIni } \\ { CurrentProcess . ProcessName } .json";
357
+ string filename = $ "{ CurrentProfilePath } \\ { CurrentProcess . ProcessName } .json";
320
358
if ( File . Exists ( filename ) )
321
359
{
322
360
string jsonString = File . ReadAllText ( filename ) ;
0 commit comments