Allow to lock steam controller locking files

- This locks `controller_neptune` configs when adding steam detection
- This overwrites default desktop/chord template
- This enables a desktop template
This commit is contained in:
Kamil Trzciński 2022-12-02 11:29:06 +01:00
parent cc085bfc2a
commit 19e7ed7012
14 changed files with 279 additions and 23 deletions

View file

@ -17,4 +17,5 @@ It does help this project on being supported.
- Fix using Playnite to launch Steam game where on exit Desktop was activated
- Build DEBUG that has all experimental features
- Introduce X360 Haptic profile to improve vibration (in DEBUG)
- Re-open Neptune controller every 10 failures
- Re-open Neptune controller every 10 failures
- Manage Steam default controller configs to prevent double inputs (in DEBUG, change Settings)

View file

@ -31,6 +31,7 @@ namespace SteamController
new Managers.ProcessManager(),
new Managers.SteamManager(),
new Managers.ProfileSwitcher(),
new Managers.SteamConfigsManager(),
new Managers.SharedDataManager()
}
};
@ -231,8 +232,8 @@ namespace SteamController
ignoreSteamItem.Visible = blacklistedSteamController is not null;
useX360WithSteamItem.Visible = blacklistedSteamController is not null;
steamSeparatorItem.Visible = blacklistedSteamController is not null;
useSteamInputItem.Visible = blacklistedSteamController is not null;
steamSeparatorItem.Visible = blacklistedSteamController is not null;
ignoreSteamItem.Checked = !Settings.Default.EnableSteamDetection || blacklistedSteamController == null;
useX360WithSteamItem.Checked = Settings.Default.EnableSteamDetection && blacklistedSteamController == true;
@ -260,6 +261,7 @@ namespace SteamController
Helpers.SteamConfiguration.KillSteam();
Helpers.SteamConfiguration.WaitForSteamClose(5000);
Helpers.SteamConfiguration.BackupSteamConfig();
var steamControllerUpdate = Helpers.SteamConfiguration.UpdateControllerBlacklist(
Devices.SteamController.VendorID,
Devices.SteamController.ProductID,
@ -271,7 +273,6 @@ namespace SteamController
blacklistX360Controller
);
Settings.Default.EnableSteamDetection = steamDetection;
Settings.Default.Save();
if (steamControllerUpdate && x360ControllerUpdate)
{

View file

@ -36,7 +36,7 @@ namespace SteamController.Devices
try
{
Marshal.StructureToPtr(haptic, handle.AddrOfPinnedObject(), false);
neptuneDevice.RequestFeatureReport(bytes);
neptuneDevice.RequestFeatureReportAsync(bytes);
return true;
}
catch (Exception e)
@ -69,7 +69,7 @@ namespace SteamController.Devices
var haptic = new SDCHapticPacket2()
{
position = position,
intensity = intensity,
intensity = (sbyte)(intensity - 5), // convert from dB to values
tsA = ts,
tsB = ts
};
@ -82,7 +82,7 @@ namespace SteamController.Devices
try
{
Marshal.StructureToPtr(haptic, handle.AddrOfPinnedObject(), false);
neptuneDevice.RequestFeatureReport(bytes);
neptuneDevice.RequestFeatureReportAsync(bytes);
return true;
}
catch (Exception e)

View file

@ -262,6 +262,83 @@ namespace SteamController.Helpers
}
}
public static bool? IsConfigFileOverwritten(String path, byte[] content)
{
try
{
var configPath = GetConfigPath(path);
if (configPath is null)
return null;
byte[] diskContent = File.ReadAllBytes(configPath);
return content.SequenceEqual(diskContent);
}
catch (IOException)
{
return null;
}
}
public static bool? ResetConfigFile(String path)
{
try
{
var configPath = GetConfigPath(path);
if (configPath is null)
return null;
File.Copy(configPath + ".orig", configPath, true);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
catch (System.Security.SecurityException)
{
return false;
}
catch (IOException)
{
return null;
}
}
public static bool? OverwriteConfigFile(String path, byte[] content, bool backup)
{
try
{
var configPath = GetConfigPath(path);
if (configPath is null)
return null;
try
{
byte[] diskContent = File.ReadAllBytes(configPath);
if (content.Equals(diskContent))
return false;
}
catch (IOException) { }
if (backup)
File.Copy(configPath, configPath + ".orig", true);
File.WriteAllBytes(configPath, content);
return true;
}
catch (UnauthorizedAccessException)
{
return false;
}
catch (System.Security.SecurityException)
{
return false;
}
catch (IOException)
{
return null;
}
}
private static T? GetValue<T>(string key, string value) where T : struct
{
try

View file

@ -0,0 +1,77 @@
using System.Diagnostics;
using SteamController.Helpers;
namespace SteamController.Managers
{
public sealed class SteamConfigsManager : Manager
{
static readonly Dictionary<String, byte[]> lockedSteamControllerFiles = new Dictionary<string, byte[]>
{
// Use existing defaults in BasicUI and BigPicture
// { "controller_base/basicui_neptune.vdf", Resources.basicui_neptune },
// { "controller_base/bigpicture_neptune.vdf", Resources.bigpicture_neptune },
{ "controller_base/desktop_neptune.vdf", Resources.empty_neptune },
{ "controller_base/chord_neptune.vdf", Resources.chord_neptune }
};
static readonly Dictionary<String, byte[]> installedSteamControllerFiles = new Dictionary<string, byte[]> {
{ "controller_base/templates/controller_neptune_steamcontroller.vdf", Resources.empty_neptune },
};
private bool? filesLocked;
public SteamConfigsManager()
{
// always unlock configs when changed
Settings.Default.SettingChanging += UnlockControllerFiles;
SetSteamControllerFilesLock(false);
}
private bool IsActive
{
get { return Settings.Default.ManageSteamControllerConfigs && Settings.Default.EnableSteamDetection; }
}
public override void Dispose()
{
SetSteamControllerFilesLock(false);
Settings.Default.SettingChanging -= UnlockControllerFiles;
}
private void UnlockControllerFiles(object sender, System.Configuration.SettingChangingEventArgs e)
{
SetSteamControllerFilesLock(false);
}
public override void Tick(Context context)
{
if (!IsActive)
return;
bool running = Helpers.SteamConfiguration.IsRunning;
if (running == filesLocked)
return;
SetSteamControllerFilesLock(running);
}
private void SetSteamControllerFilesLock(bool lockConfigs)
{
if (!IsActive)
return;
if (lockConfigs)
{
foreach (var config in lockedSteamControllerFiles)
Helpers.SteamConfiguration.OverwriteConfigFile(config.Key, config.Value, true);
foreach (var config in installedSteamControllerFiles)
Helpers.SteamConfiguration.OverwriteConfigFile(config.Key, config.Value, false);
}
else
{
foreach (var config in lockedSteamControllerFiles)
Helpers.SteamConfiguration.ResetConfigFile(config.Key);
}
filesLocked = lockConfigs;
}
}
}

View file

@ -10,7 +10,7 @@ namespace SteamController.Profiles
public override bool Selected(Context context)
{
return context.Enabled && context.State.SteamUsesSteamInput;
return context.Enabled && context.State.SteamUsesSteamInput && !Settings.Default.ManageSteamControllerConfigs;
}
public override Status Run(Context context)

View file

@ -19,12 +19,12 @@ namespace SteamController.Profiles
if (context.X360.FeedbackLargeMotor.GetValueOrDefault() > 0)
{
context.Steam.SendHaptic(1, 0);
context.Steam.SendHaptic(1, HapticSettings.LeftIntensity);
}
if (context.X360.FeedbackSmallMotor.GetValueOrDefault() > 0)
{
context.Steam.SendHaptic(0, 0);
context.Steam.SendHaptic(0, HapticSettings.RightIntensity);
}
context.X360.ResetFeedback();

View file

@ -21,17 +21,6 @@ namespace SteamController.Profiles
return Status.Done;
}
#if false
if (context.X360.FeedbackLargeMotor.GetValueOrDefault() > 0)
{
context.Steam.SetHaptic2(1, 0);
}
if (context.X360.FeedbackSmallMotor.GetValueOrDefault() > 0)
{
context.Steam.SetHaptic2(0, 0);
}
#else
if (context.X360.FeedbackLargeMotor.HasValue)
{
context.Steam.SetFeedback(
@ -43,7 +32,6 @@ namespace SteamController.Profiles
context.Steam.SetFeedback(
0, GetHapticAmplitude(context.X360.FeedbackSmallMotor), RumbleSettings.Period, FeedbackCount);
}
#endif
context.X360.ResetFeedback();

View file

@ -18,7 +18,7 @@ namespace SteamController.ProfilesSettings
}
[UserScopedSettingAttribute()]
[DefaultSettingValueAttribute("0")]
[DefaultSettingValueAttribute("5")]
[Description("Haptic intensity between -2dB and 10dB")]
public sbyte LeftIntensity
{
@ -27,7 +27,7 @@ namespace SteamController.ProfilesSettings
}
[UserScopedSettingAttribute()]
[DefaultSettingValueAttribute("0")]
[DefaultSettingValueAttribute("5")]
[Description("Haptic intensity between -2dB and 10dB")]
public sbyte RightIntensity
{

View file

@ -60,6 +60,26 @@ namespace SteamController {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] chord_neptune {
get {
object obj = ResourceManager.GetObject("chord_neptune", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] empty_neptune {
get {
object obj = ResourceManager.GetObject("empty_neptune", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Icon similar to (Icon).
/// </summary>

View file

@ -118,6 +118,12 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="chord_neptune" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\controller_base\chord_neptune.vdf;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="empty_neptune" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\controller_base\empty_neptune.vdf;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="laptop" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\laptop.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>

View file

@ -0,0 +1,35 @@
"controller_mappings"
{
"version" "3"
"title" "SteamController replaced Chord Configuration"
"description" "Template provided by SteamController to disable default mappings of Steam to prevent double inputs"
"controller_type" "controller_neptune"
"major_revision" "0"
"minor_revision" "0"
"actions"
{
"Preset_1000001"
{
"title" "Empty"
"legacy_set" "1"
}
}
"preset"
{
"id" "0"
"name" "Preset_1000001"
"group_source_bindings"
{
}
}
"action_layers"
{
}
"settings"
{
"left_trackpad_mode" "0"
"right_trackpad_mode" "0"
"action_set_trigger_cursor_show" "0"
"action_set_trigger_cursor_hide" "0"
}
}

View file

@ -0,0 +1,35 @@
"controller_mappings"
{
"version" "3"
"title" "SteamController provided empty configuration"
"description" "Template provided by SteamController to disable default mappings of Steam to prevent double inputs"
"controller_type" "controller_neptune"
"major_revision" "0"
"minor_revision" "0"
"actions"
{
"Preset_1000001"
{
"title" "Empty"
"legacy_set" "1"
}
}
"preset"
{
"id" "0"
"name" "Preset_1000001"
"group_source_bindings"
{
}
}
"action_layers"
{
}
"settings"
{
"left_trackpad_mode" "0"
"right_trackpad_mode" "0"
"action_set_trigger_cursor_show" "0"
"action_set_trigger_cursor_hide" "0"
}
}

View file

@ -35,6 +35,22 @@ namespace SteamController
set { this["StartupProfile"] = value; }
}
#if DEBUG
[UserScopedSetting]
[BrowsableAttribute(true)]
#else
[ApplicationScopedSetting]
[BrowsableAttribute(false)]
#endif
[DefaultSettingValue("False")]
[DisplayName("Manage Steam Controller Configs")]
[Description("This does replace Steam configuration for controllers to prevent double inputs")]
public bool ManageSteamControllerConfigs
{
get { return ((bool)(this["ManageSteamControllerConfigs"])); }
set { this["ManageSteamControllerConfigs"] = value; }
}
public override string ToString()
{
return "";