2022-11-25 10:56:17 +01:00
|
|
|
using System.Diagnostics;
|
|
|
|
|
using SteamController.Helpers;
|
|
|
|
|
|
|
|
|
|
namespace SteamController.Managers
|
|
|
|
|
{
|
|
|
|
|
public sealed class SteamManager : Manager
|
|
|
|
|
{
|
2022-12-04 21:14:08 +01:00
|
|
|
public const int DebounceStates = 1;
|
|
|
|
|
|
2022-12-04 20:43:57 +01:00
|
|
|
private string? lastState;
|
2022-12-04 21:14:08 +01:00
|
|
|
private int stateChanged;
|
2022-11-27 13:41:28 +01:00
|
|
|
|
2022-11-25 10:56:17 +01:00
|
|
|
public override void Tick(Context context)
|
|
|
|
|
{
|
2023-01-21 21:41:55 +01:00
|
|
|
if (Settings.Default.EnableSteamDetection != true)
|
2022-11-25 10:56:17 +01:00
|
|
|
{
|
2022-11-29 22:50:07 +01:00
|
|
|
context.State.SteamUsesSteamInput = false;
|
|
|
|
|
context.State.SteamUsesX360Controller = false;
|
2022-12-04 20:43:57 +01:00
|
|
|
lastState = null;
|
2022-12-04 21:14:08 +01:00
|
|
|
stateChanged = 0;
|
2022-11-25 10:56:17 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-04 20:43:57 +01:00
|
|
|
var usesController = UsesController();
|
2022-11-27 13:41:28 +01:00
|
|
|
if (lastState == usesController)
|
2022-12-04 21:14:08 +01:00
|
|
|
{
|
|
|
|
|
stateChanged = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else if (stateChanged < DebounceStates)
|
|
|
|
|
{
|
|
|
|
|
stateChanged++;
|
2022-11-27 13:41:28 +01:00
|
|
|
return;
|
2022-12-04 21:14:08 +01:00
|
|
|
}
|
2022-11-27 13:41:28 +01:00
|
|
|
|
2022-12-04 20:43:57 +01:00
|
|
|
if (usesController is not null)
|
2022-11-27 13:41:28 +01:00
|
|
|
{
|
2022-11-29 22:50:07 +01:00
|
|
|
context.State.SteamUsesSteamInput = Helpers.SteamConfiguration.IsControllerBlacklisted(
|
2022-11-27 13:41:28 +01:00
|
|
|
Devices.SteamController.VendorID,
|
|
|
|
|
Devices.SteamController.ProductID
|
|
|
|
|
) != true;
|
|
|
|
|
|
2022-11-29 22:50:07 +01:00
|
|
|
context.State.SteamUsesX360Controller = Helpers.SteamConfiguration.IsControllerBlacklisted(
|
2022-11-27 13:41:28 +01:00
|
|
|
Devices.Xbox360Controller.VendorID,
|
|
|
|
|
Devices.Xbox360Controller.ProductID
|
|
|
|
|
) != true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-11-29 22:50:07 +01:00
|
|
|
context.State.SteamUsesSteamInput = false;
|
|
|
|
|
context.State.SteamUsesX360Controller = false;
|
2022-11-27 13:41:28 +01:00
|
|
|
}
|
2022-11-25 10:56:17 +01:00
|
|
|
|
2022-11-27 13:41:28 +01:00
|
|
|
lastState = usesController;
|
2022-12-04 21:14:08 +01:00
|
|
|
stateChanged = 0;
|
2022-12-04 20:43:57 +01:00
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
CommonHelpers.Log.TraceLine(
|
|
|
|
|
"SteamManager: uses={0}, isRunning={1}, usesSteamInput={2}, usesX360={3}",
|
|
|
|
|
usesController,
|
|
|
|
|
SteamConfiguration.IsRunning,
|
|
|
|
|
context.State.SteamUsesSteamInput,
|
|
|
|
|
context.State.SteamUsesX360Controller
|
|
|
|
|
);
|
|
|
|
|
#endif
|
2022-11-25 10:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-04 20:43:57 +01:00
|
|
|
private string? UsesController()
|
2022-11-25 10:56:17 +01:00
|
|
|
{
|
2022-11-28 20:28:21 +01:00
|
|
|
if (!SteamConfiguration.IsRunning)
|
2022-11-25 10:56:17 +01:00
|
|
|
return null;
|
2022-12-04 20:43:57 +01:00
|
|
|
if (SteamConfiguration.IsBigPictureMode.GetValueOrDefault(false))
|
|
|
|
|
return "bigpicture";
|
|
|
|
|
if (SteamConfiguration.IsRunningGame.GetValueOrDefault(false))
|
|
|
|
|
return "game";
|
|
|
|
|
if (SteamConfiguration.IsGamePadUI)
|
|
|
|
|
return "gamepadui";
|
2022-12-06 21:19:10 +01:00
|
|
|
if (SteamConfiguration.IsPossibleGamePadUI)
|
|
|
|
|
return "possiblegamepadui";
|
2022-12-04 20:43:57 +01:00
|
|
|
return null;
|
2022-11-25 10:56:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|