2022-11-24 22:37:24 +01:00
|
|
|
using static CommonHelpers.Log;
|
|
|
|
|
|
|
|
|
|
namespace SteamController.Profiles
|
|
|
|
|
{
|
|
|
|
|
public class Context : IDisposable
|
|
|
|
|
{
|
|
|
|
|
public const double JoystickToMouseSensitivity = 1200;
|
|
|
|
|
public const double PadToMouseSensitivity = 200;
|
2022-11-25 07:48:01 +01:00
|
|
|
public const double PadToWhellSensitivity = 4;
|
|
|
|
|
public const double ThumbToWhellSensitivity = 4;
|
|
|
|
|
public static readonly TimeSpan ThumbToWhellFirstRepeat = TimeSpan.FromMilliseconds(30 * ThumbToWhellSensitivity);
|
|
|
|
|
public static readonly TimeSpan ThumbToWhellRepeat = TimeSpan.FromMilliseconds(30 * ThumbToWhellSensitivity);
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
public Devices.SteamController Steam { get; private set; }
|
|
|
|
|
public Devices.Xbox360Controller X360 { get; private set; }
|
|
|
|
|
public Devices.KeyboardController Keyboard { get; private set; }
|
|
|
|
|
public Devices.MouseController Mouse { get; private set; }
|
|
|
|
|
|
|
|
|
|
public List<Profile> Profiles { get; } = new List<Profile>();
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
public bool RequestEnable { get; set; } = true;
|
2022-11-24 22:37:24 +01:00
|
|
|
public bool RequestDesktopMode { get; set; } = true;
|
2022-11-25 07:48:01 +01:00
|
|
|
public bool DisableDueToSteam { get; set; } = false;
|
|
|
|
|
|
|
|
|
|
public bool Enabled
|
|
|
|
|
{
|
|
|
|
|
get { return RequestEnable && !DisableDueToSteam; }
|
|
|
|
|
}
|
2022-11-24 22:37:24 +01:00
|
|
|
|
|
|
|
|
public bool DesktopMode
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return RequestDesktopMode || !X360.Valid || !Mouse.Valid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Context()
|
|
|
|
|
{
|
|
|
|
|
Steam = new Devices.SteamController();
|
|
|
|
|
X360 = new Devices.Xbox360Controller();
|
|
|
|
|
Keyboard = new Devices.KeyboardController();
|
|
|
|
|
Mouse = new Devices.MouseController();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
using (Steam) { }
|
|
|
|
|
using (X360) { }
|
|
|
|
|
using (Keyboard) { }
|
|
|
|
|
using (Mouse) { }
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-25 07:48:01 +01:00
|
|
|
public void Tick()
|
|
|
|
|
{
|
|
|
|
|
X360.Tick();
|
|
|
|
|
|
|
|
|
|
foreach (Profile profile in Profiles)
|
|
|
|
|
{
|
|
|
|
|
try { profile.Tick(this); }
|
|
|
|
|
catch (Exception e) { TraceLine("Profile: {0}. Exception: {1}", e); }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
public bool Update()
|
|
|
|
|
{
|
2022-11-25 07:48:01 +01:00
|
|
|
if (!Enabled)
|
|
|
|
|
{
|
|
|
|
|
X360.Connected = false;
|
|
|
|
|
Steam.LizardButtons = true;
|
|
|
|
|
Steam.LizardMouse = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 22:37:24 +01:00
|
|
|
Steam.BeforeUpdate();
|
|
|
|
|
X360.BeforeUpdate();
|
|
|
|
|
Keyboard.BeforeUpdate();
|
|
|
|
|
Mouse.BeforeUpdate();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
bool skip = false;
|
|
|
|
|
|
|
|
|
|
foreach (Profile profile in Profiles)
|
|
|
|
|
{
|
|
|
|
|
if (!profile.RunAlways && skip)
|
|
|
|
|
{
|
|
|
|
|
profile.Skipped(this);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var status = profile.Run(this);
|
|
|
|
|
if (status == Profile.Status.Stop)
|
|
|
|
|
skip = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
TraceLine("Profile: Exception: {0}", e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
TraceLine("Controller: Exception: {0}", e);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
Steam.Update();
|
|
|
|
|
X360.Update();
|
|
|
|
|
Keyboard.Update();
|
|
|
|
|
Mouse.Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|