From 0cc4f188846c8be75feae12ba67f6e768b3d43a8 Mon Sep 17 00:00:00 2001 From: Mywk Date: Sat, 9 Nov 2019 13:07:48 +0100 Subject: [PATCH 1/9] # Implemented changes by Alexx999 ~ Code cleanup, switch to AnyCPU --- .gitignore | 1 + scr/NoCableLauncher.sln | 21 ++- scr/NoCableLauncher/HotKeyManager.cs | 30 ++-- scr/NoCableLauncher/NoCableLauncher.csproj | 33 ++-- .../PortableSettingsProvider.cs | 58 +++---- scr/NoCableLauncher/Program.cs | 138 ++++++++--------- .../Properties/AssemblyInfo.cs | 1 - scr/NoCableLauncher/Settings.Designer.cs | 125 +++++++-------- scr/NoCableLauncher/Settings.cs | 30 ++-- scr/NoCableLauncher/SettingsClass.cs | 145 +++++++++--------- 10 files changed, 289 insertions(+), 293 deletions(-) diff --git a/.gitignore b/.gitignore index fd5204b..0fe4850 100644 --- a/.gitignore +++ b/.gitignore @@ -181,3 +181,4 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ +/scr/.vs diff --git a/scr/NoCableLauncher.sln b/scr/NoCableLauncher.sln index 9b68c78..1ef46fb 100644 --- a/scr/NoCableLauncher.sln +++ b/scr/NoCableLauncher.sln @@ -1,20 +1,25 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29020.237 +MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NoCableLauncher", "NoCableLauncher\NoCableLauncher.csproj", "{C677FB12-10B8-4E81-A0C3-EF03EF980DF9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Debug|x86.ActiveCfg = Debug|x86 - {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Debug|x86.Build.0 = Debug|x86 - {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Release|x86.ActiveCfg = Release|x86 - {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Release|x86.Build.0 = Release|x86 + {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C677FB12-10B8-4E81-A0C3-EF03EF980DF9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DE94F8D8-99C2-429F-98B3-CEF0B36ED02E} + EndGlobalSection EndGlobal diff --git a/scr/NoCableLauncher/HotKeyManager.cs b/scr/NoCableLauncher/HotKeyManager.cs index bc73a02..d785331 100644 --- a/scr/NoCableLauncher/HotKeyManager.cs +++ b/scr/NoCableLauncher/HotKeyManager.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -using System.Windows.Forms; using System.Threading; +using System.Windows.Forms; namespace NoCableLauncher { @@ -12,7 +12,7 @@ public static class HotKeyManager public static int RegisterHotKey(Keys key, KeyModifiers modifiers) { _windowReadyEvent.WaitOne(); - int id = System.Threading.Interlocked.Increment(ref _id); + int id = Interlocked.Increment(ref _id); _wnd.Invoke(new RegisterHotKeyDelegate(RegisterHotKeyInternal), _hwnd, id, (uint)modifiers, (uint)key); return id; } @@ -37,23 +37,19 @@ private static void UnRegisterHotKeyInternal(IntPtr hwnd, int id) private static void OnHotKeyPressed(HotKeyEventArgs e) { - if (HotKeyManager.HotKeyPressed != null) - { - HotKeyManager.HotKeyPressed(null, e); - } + HotKeyPressed?.Invoke(null, e); } private static volatile MessageWindow _wnd; private static volatile IntPtr _hwnd; - private static ManualResetEvent _windowReadyEvent = new ManualResetEvent(false); + private static readonly ManualResetEvent _windowReadyEvent = new ManualResetEvent(false); static HotKeyManager() { - Thread messageLoop = new Thread(delegate() + Thread messageLoop = new Thread(delegate() { Application.Run(new MessageWindow()); }) { - Application.Run(new MessageWindow()); - }); - messageLoop.Name = "MessageLoopThread"; - messageLoop.IsBackground = true; + Name = "MessageLoopThread", + IsBackground = true + }; messageLoop.Start(); } @@ -62,7 +58,7 @@ private class MessageWindow : Form public MessageWindow() { _wnd = this; - _hwnd = this.Handle; + _hwnd = Handle; _windowReadyEvent.Set(); } @@ -71,7 +67,7 @@ protected override void WndProc(ref Message m) if (m.Msg == WM_HOTKEY) { HotKeyEventArgs e = new HotKeyEventArgs(m.LParam); - HotKeyManager.OnHotKeyPressed(e); + OnHotKeyPressed(e); } base.WndProc(ref m); @@ -92,7 +88,7 @@ protected override void SetVisibleCore(bool value) [DllImport("user32", SetLastError = true)] private static extern bool UnregisterHotKey(IntPtr hWnd, int id); - private static int _id = 0; + private static int _id; } @@ -103,8 +99,8 @@ public class HotKeyEventArgs : EventArgs public HotKeyEventArgs(Keys key, KeyModifiers modifiers) { - this.Key = key; - this.Modifiers = modifiers; + Key = key; + Modifiers = modifiers; } public HotKeyEventArgs(IntPtr hotKeyParam) diff --git a/scr/NoCableLauncher/NoCableLauncher.csproj b/scr/NoCableLauncher/NoCableLauncher.csproj index cd2b0de..5d38553 100644 --- a/scr/NoCableLauncher/NoCableLauncher.csproj +++ b/scr/NoCableLauncher/NoCableLauncher.csproj @@ -29,32 +29,29 @@ false true - - x86 + + + + + Resources\rs14.ico + + true - full - false bin\Debug\ DEBUG;TRACE + full + AnyCPU prompt - 4 - false + MinimumRecommendedRules.ruleset - - x86 - pdbonly - true + bin\Release\ TRACE + true + pdbonly + AnyCPU prompt - 4 - false - - - - - - Resources\rs14.ico + MinimumRecommendedRules.ruleset diff --git a/scr/NoCableLauncher/PortableSettingsProvider.cs b/scr/NoCableLauncher/PortableSettingsProvider.cs index 7fd8369..2596a91 100644 --- a/scr/NoCableLauncher/PortableSettingsProvider.cs +++ b/scr/NoCableLauncher/PortableSettingsProvider.cs @@ -1,10 +1,10 @@ using System; -using System.Configuration; -using System.Xml; using System.Collections.Specialized; -using System.Windows.Forms; +using System.Configuration; using System.IO; using System.Linq; +using System.Windows.Forms; +using System.Xml; namespace NoCableLauncher { @@ -22,32 +22,28 @@ private string _filePath } } - private XmlNode _rootNode - { - get { return _rootDocument.SelectSingleNode(_rootNodeName); } - } + private XmlNode _rootNode => _rootDocument.SelectSingleNode(_rootNodeName); private XmlDocument _rootDocument { get { - if (_xmlDocument == null) + if (_xmlDocument != null) return _xmlDocument; + + try + { + _xmlDocument = new XmlDocument(); + _xmlDocument.Load(_filePath); + } + catch (Exception) { - try - { - _xmlDocument = new XmlDocument(); - _xmlDocument.Load(_filePath); - } - catch (Exception) - { - } + } - if (_xmlDocument.SelectSingleNode(_rootNodeName) != null) - return _xmlDocument; + if (_xmlDocument.SelectSingleNode(_rootNodeName) != null) + return _xmlDocument; - _xmlDocument = GetBlankXmlDocument(); - } + _xmlDocument = GetBlankXmlDocument(); return _xmlDocument; } @@ -55,14 +51,11 @@ private XmlDocument _rootDocument public override string ApplicationName { - get { return Path.GetFileNameWithoutExtension(Application.ExecutablePath); } + get => Path.GetFileNameWithoutExtension(Application.ExecutablePath); set { } } - public override string Name - { - get { return _className; } - } + public override string Name => _className; public override void Initialize(string name, NameValueCollection config) { @@ -109,7 +102,7 @@ public override SettingsPropertyValueCollection GetPropertyValues(SettingsContex private void SetValue(SettingsPropertyValue propertyValue) { - XmlNode settingNode = _rootNode.SelectSingleNode(string.Format("setting[@name='{0}']", propertyValue.Name)); + XmlNode settingNode = _rootNode.SelectSingleNode($"setting[@name='{propertyValue.Name}']"); if (settingNode != null) { @@ -126,7 +119,7 @@ private void SetValue(SettingsPropertyValue propertyValue) XmlAttribute nameAttribute = _rootDocument.CreateAttribute("name"); nameAttribute.Value = propertyValue.Name; - settingNode.Attributes.Append(nameAttribute); + settingNode.Attributes?.Append(nameAttribute); settingNode.InnerText = propertyValue.SerializedValue.ToString(); @@ -136,7 +129,7 @@ private void SetValue(SettingsPropertyValue propertyValue) private string GetValue(SettingsProperty property) { - XmlNode settingNode = _rootNode.SelectSingleNode(string.Format("setting[@name='{0}']", property.Name)); + XmlNode settingNode = _rootNode.SelectSingleNode($"setting[@name='{property.Name}']"); if (settingNode == null) return property.DefaultValue != null ? property.DefaultValue.ToString() : string.Empty; @@ -148,11 +141,10 @@ private XmlNode GetSettingsNode(string name) { XmlNode settingsNode = _rootNode.SelectSingleNode(name); - if (settingsNode == null) - { - settingsNode = _rootDocument.CreateElement(name); - _rootNode.AppendChild(settingsNode); - } + if (settingsNode != null) return settingsNode; + + settingsNode = _rootDocument.CreateElement(name); + _rootNode.AppendChild(settingsNode); return settingsNode; } diff --git a/scr/NoCableLauncher/Program.cs b/scr/NoCableLauncher/Program.cs index bc2104f..ee38ed0 100644 --- a/scr/NoCableLauncher/Program.cs +++ b/scr/NoCableLauncher/Program.cs @@ -1,12 +1,12 @@ using System; -using System.Runtime.InteropServices; using System.Diagnostics; -using System.Threading; -using System.Windows.Forms; using System.Globalization; using System.IO; -using NoCableLauncher.CoreAudioApi; using System.Linq; +using System.Runtime.InteropServices; +using System.Threading; +using System.Windows.Forms; +using NoCableLauncher.CoreAudioApi; namespace NoCableLauncher { @@ -17,51 +17,51 @@ public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId); [DllImport("kernel32.dll", SetLastError = true)] - static extern bool WriteProcessMemory(int hProcess, int lpBaseAddress, + static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int dwSize, ref int lpNumberOfBytesWritten); [DllImport("kernel32.dll", SetLastError = true)] - static extern bool ReadProcessMemory(int hProcess, int lpBaseAddress, + static extern bool ReadProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, int nSize, ref int lpNumberOfBytesRead); [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] public static extern - bool CloseHandle(int handle); + bool CloseHandle(IntPtr hHandle); public static SettingsClass.Settings settings = SettingsClass.Settings.Default; private static PolicyConfigClient pPolicyConfig = new PolicyConfigClient(); public const string steamName = "steam://rungameid/221680"; private const string exeName = "Rocksmith2014"; - private const int PROCESS_ALL_ACCESS = 2035711; + private const int PROCESS_ALL_ACCESS = 0x1F0FFF; - private static int offcetVID = 0; - private static int offcetPID = 0; + private static IntPtr offsetVID; + private static IntPtr offsetPID; private static byte[] vid = new byte[2]; private static byte[] pid = new byte[2]; //Realtone Cable ID's - private static readonly byte[] rtVid = new byte[2] { 186, 18 }; - private static readonly byte[] rtPid = new byte[2] { 255, 0 }; + private static readonly byte[] rtVid = { 0xBA, 0x12 }; + private static readonly byte[] rtPid = { 0xFF, 0x0 }; //Pattern to find cable ID's - private static readonly byte[] pattern = new byte[] { rtVid[0], rtVid[1], 146, 10, 16, 192, 17, 192, rtPid[0], rtPid[1] }; + private static readonly byte[] pattern = { rtVid[0], rtVid[1], 0x92, 0x0A, 0x10, 0xC0, 0x11, 0xC0, rtPid[0], rtPid[1] }; - private static int hotkeyID = 0; + private static int hotkeyID; //Game process handle - private static pInfo procInfo = new pInfo(); + private static pInfo procInfo; private struct pInfo { - public int Handle; - public int StartAddress; + public IntPtr Handle; + public IntPtr StartAddress; public int Size; } - private static bool stopWait = false; - private static bool gameRunning = false; + private static bool stopWait; + private static bool gameRunning; public static void SetDeviceState(string guid, bool enabled = false) @@ -80,7 +80,7 @@ public static int FromHex(string value) { value = value.Substring(2); } - return Int32.Parse(value, NumberStyles.HexNumber); + return int.Parse(value, NumberStyles.HexNumber); } public static byte GetByte(string value) @@ -100,7 +100,7 @@ private static byte[] GetDevId(string value) private static void ExitWithError(string value) { if (value != string.Empty) - MessageBox.Show(value, Application.ProductName + " Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(value, $"{Application.ProductName} Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } @@ -127,13 +127,13 @@ private static void ReadDeviceValues(bool multiplayer) } } - private static void ReadOffcetValues() + private static void ReadOffsetValues() { try { - //Getting RAM offcets - offcetVID = FromHex(settings.offcetVID); - offcetPID = FromHex(settings.offcetPID); + //Getting RAM offsets + offsetVID = new IntPtr(FromHex(settings.offsetVID)); + offsetPID = new IntPtr(FromHex(settings.offsetPID)); } catch (Exception exc) { @@ -149,15 +149,17 @@ private static void StartGame() { if (File.Exists(settings.gamePath)) { - var startInfo = new ProcessStartInfo(); - startInfo.FileName = Path.GetFileNameWithoutExtension(settings.gamePath); - startInfo.WorkingDirectory = Path.GetDirectoryName(settings.gamePath); + var startInfo = new ProcessStartInfo + { + FileName = Path.GetFileNameWithoutExtension(settings.gamePath), + WorkingDirectory = Path.GetDirectoryName(settings.gamePath) + }; Process.Start(startInfo); } else { - ExitWithError(string.Format("Exe file at \"{0}\" not found, check game path setting.", settings.gamePath)); + ExitWithError($"Exe file at \"{settings.gamePath}\" not found, check game path setting."); } } else @@ -178,29 +180,27 @@ private static void HookProcess() //Finding game process Process[] processes = Process.GetProcessesByName(exeName); - if (processes.Length > 0) - { - //If game process found + if (processes.Length <= 0) continue; - var process = processes[0]; + //If game process found - //Open process for writing - procInfo.Handle = (int)Program.OpenProcess(PROCESS_ALL_ACCESS, false, process.Id); - procInfo.StartAddress = (int)process.Modules[0].BaseAddress; - procInfo.Size = process.Modules[0].ModuleMemorySize; + var process = processes[0]; - if (settings.Multiplayer) - { - process.EnableRaisingEvents = true; - process.Exited += process_Exited; - gameRunning = true; - } + //Open process for writing + procInfo.Handle = OpenProcess(PROCESS_ALL_ACCESS, false, process.Id); + procInfo.StartAddress = process.Modules[0].BaseAddress; + procInfo.Size = process.Modules[0].ModuleMemorySize; - return; - } + if (!settings.Multiplayer) return; + + process.EnableRaisingEvents = true; + process.Exited += process_Exited; + gameRunning = true; + + return; } - ExitWithError(string.Format("Can't find process: {0}.exe", exeName)); + ExitWithError($"Can't find process: {exeName}.exe"); } private static void process_Exited(object sender, EventArgs e) @@ -209,20 +209,20 @@ private static void process_Exited(object sender, EventArgs e) stopWait = true; } - private static bool CheckOffcets() + private static bool CheckOffsets() { int output = 0; byte[] retVid = new byte[2]; byte[] retPid = new byte[2]; - ReadProcessMemory(procInfo.Handle, offcetVID, retVid, 2, ref output); - ReadProcessMemory(procInfo.Handle, offcetPID, retPid, 2, ref output); + ReadProcessMemory(procInfo.Handle, offsetVID, retVid, 2, ref output); + ReadProcessMemory(procInfo.Handle, offsetPID, retPid, 2, ref output); return (retPid.SequenceEqual(rtPid) && retVid.SequenceEqual(rtVid)); } - private static void FindOffcets() + private static void FindOffsets() { try { @@ -248,14 +248,14 @@ private static void FindOffcets() if (counter == pattern.Length) { - var result = i + procInfo.StartAddress; + var result = procInfo.StartAddress + i; - offcetVID = result; - offcetPID = result + (pattern.Length - 2); + offsetVID = result; + offsetPID = result + (pattern.Length - 2); - //Saving new offcets to settings - settings.offcetVID = offcetVID.ToString("X8"); - settings.offcetPID = offcetPID.ToString("X8"); + //Saving new offsets to settings + settings.offsetVID = offsetVID.ToString("X8"); + settings.offsetPID = offsetPID.ToString("X8"); settings.Save(); return; @@ -268,7 +268,7 @@ private static void FindOffcets() } } - ExitWithError("Offcets not found!"); + ExitWithError("Offsets not found!"); } catch (Exception exc) { @@ -282,8 +282,8 @@ private static void Patch() { //Patching! int output = 0; - WriteProcessMemory(procInfo.Handle, offcetVID, vid, 2, ref output); - WriteProcessMemory(procInfo.Handle, offcetPID, pid, 2, ref output); + WriteProcessMemory(procInfo.Handle, offsetVID, vid, 2, ref output); + WriteProcessMemory(procInfo.Handle, offsetPID, pid, 2, ref output); } catch (Exception) { @@ -294,7 +294,7 @@ private static void Patch() private static void InitHotKey() { hotkeyID = HotKeyManager.RegisterHotKey(Keys.M, KeyModifiers.Control); - HotKeyManager.HotKeyPressed += new EventHandler(HotKeyManager_HotKeyPressed); + HotKeyManager.HotKeyPressed += HotKeyManager_HotKeyPressed; } private static void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e) @@ -319,14 +319,14 @@ public static void Main(string[] args) if (settings.Multiplayer) { //Disable player2 record device - SetDeviceState(settings.GUID2, false); + SetDeviceState(settings.GUID2); //Register hotkey and press event InitHotKey(); } - //Reading Offcets - ReadOffcetValues(); + //Reading Offsets + ReadOffsetValues(); //Reading PID&VID values for Player1 ReadDeviceValues(false); @@ -337,14 +337,14 @@ public static void Main(string[] args) //Getting process id and setting exit event HookProcess(); - //Checking offcets to write - if (CheckOffcets() == false) + //Checking offsets to write + if (CheckOffsets() == false) { - if (settings.manualOffcets) - ExitWithError("Offcets values are wrong! Set proper values manually in settings or uncheck \"Manual Offcets\" to find it automatically."); + if (settings.manualOffsets) + ExitWithError("Offsets values are wrong! Set proper values manually in settings or uncheck \"Manual Offsets\" to find it automatically."); else - //Find offcets automatically - FindOffcets(); + //Find offsets automatically + FindOffsets(); } //Patching game diff --git a/scr/NoCableLauncher/Properties/AssemblyInfo.cs b/scr/NoCableLauncher/Properties/AssemblyInfo.cs index d3d928c..465a206 100644 --- a/scr/NoCableLauncher/Properties/AssemblyInfo.cs +++ b/scr/NoCableLauncher/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // Управление общими сведениями о сборке осуществляется с помощью diff --git a/scr/NoCableLauncher/Settings.Designer.cs b/scr/NoCableLauncher/Settings.Designer.cs index e7f94ad..62802f0 100644 --- a/scr/NoCableLauncher/Settings.Designer.cs +++ b/scr/NoCableLauncher/Settings.Designer.cs @@ -1,11 +1,14 @@ -namespace NoCableLauncher +using System.ComponentModel; +using System.Windows.Forms; + +namespace NoCableLauncher { partial class Settings { /// /// Required designer variable. /// - private System.ComponentModel.IContainer components = null; + private IContainer components = null; /// /// Clean up any resources being used. @@ -42,8 +45,8 @@ private void InitializeComponent() this.okButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button(); this.label5 = new System.Windows.Forms.Label(); - this.offcetVidTextBox = new System.Windows.Forms.TextBox(); - this.offcetPidTextBox = new System.Windows.Forms.TextBox(); + this.offsetVidTextBox = new System.Windows.Forms.TextBox(); + this.offsetPidTextBox = new System.Windows.Forms.TextBox(); this.player1GroupBox = new System.Windows.Forms.GroupBox(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.groupBox2 = new System.Windows.Forms.GroupBox(); @@ -59,7 +62,7 @@ private void InitializeComponent() this.p2DeviceCombo = new System.Windows.Forms.ComboBox(); this.p2pidTexBox = new System.Windows.Forms.TextBox(); this.p2vidTextBox = new System.Windows.Forms.TextBox(); - this.manualOffcetsCheckbox = new System.Windows.Forms.CheckBox(); + this.manualOffsetsCheckbox = new System.Windows.Forms.CheckBox(); this.player1GroupBox.SuspendLayout(); this.groupBox2.SuspendLayout(); this.player2GroupBox.SuspendLayout(); @@ -193,21 +196,21 @@ private void InitializeComponent() this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(57, 13); this.label5.TabIndex = 0; - this.label5.Text = "VID Offcet"; + this.label5.Text = "VID Offset"; // - // offcetVidTextBox + // offsetVidTextBox // - this.offcetVidTextBox.Location = new System.Drawing.Point(79, 95); - this.offcetVidTextBox.Name = "offcetVidTextBox"; - this.offcetVidTextBox.Size = new System.Drawing.Size(86, 20); - this.offcetVidTextBox.TabIndex = 5; + this.offsetVidTextBox.Location = new System.Drawing.Point(79, 95); + this.offsetVidTextBox.Name = "offsetVidTextBox"; + this.offsetVidTextBox.Size = new System.Drawing.Size(86, 20); + this.offsetVidTextBox.TabIndex = 5; // - // offcetPidTextBox + // offsetPidTextBox // - this.offcetPidTextBox.Location = new System.Drawing.Point(79, 120); - this.offcetPidTextBox.Name = "offcetPidTextBox"; - this.offcetPidTextBox.Size = new System.Drawing.Size(86, 20); - this.offcetPidTextBox.TabIndex = 6; + this.offsetPidTextBox.Location = new System.Drawing.Point(79, 120); + this.offsetPidTextBox.Name = "offsetPidTextBox"; + this.offsetPidTextBox.Size = new System.Drawing.Size(86, 20); + this.offsetPidTextBox.TabIndex = 6; // // player1GroupBox // @@ -232,16 +235,16 @@ private void InitializeComponent() // // groupBox2 // - this.groupBox2.Controls.Add(this.manualOffcetsCheckbox); + this.groupBox2.Controls.Add(this.manualOffsetsCheckbox); this.groupBox2.Controls.Add(this.label1); this.groupBox2.Controls.Add(this.label6); this.groupBox2.Controls.Add(this.label5); this.groupBox2.Controls.Add(this.pathTextBox); this.groupBox2.Controls.Add(this.browseButton); this.groupBox2.Controls.Add(this.multiplayerCheckBox); - this.groupBox2.Controls.Add(this.offcetVidTextBox); + this.groupBox2.Controls.Add(this.offsetVidTextBox); this.groupBox2.Controls.Add(this.steamCheckBox); - this.groupBox2.Controls.Add(this.offcetPidTextBox); + this.groupBox2.Controls.Add(this.offsetPidTextBox); this.groupBox2.Location = new System.Drawing.Point(12, 5); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(354, 151); @@ -256,7 +259,7 @@ private void InitializeComponent() this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(57, 13); this.label6.TabIndex = 0; - this.label6.Text = "PID Offcet"; + this.label6.Text = "PID Offset"; // // multiplayerCheckBox // @@ -369,16 +372,16 @@ private void InitializeComponent() this.p2vidTextBox.Size = new System.Drawing.Size(88, 20); this.p2vidTextBox.TabIndex = 14; // - // manualOffcetsCheckbox + // manualOffsetsCheckbox // - this.manualOffcetsCheckbox.AutoSize = true; - this.manualOffcetsCheckbox.Location = new System.Drawing.Point(79, 72); - this.manualOffcetsCheckbox.Name = "manualOffcetsCheckbox"; - this.manualOffcetsCheckbox.Size = new System.Drawing.Size(98, 17); - this.manualOffcetsCheckbox.TabIndex = 8; - this.manualOffcetsCheckbox.Text = "Manual Offcets"; - this.manualOffcetsCheckbox.UseVisualStyleBackColor = true; - this.manualOffcetsCheckbox.CheckedChanged += new System.EventHandler(this.manualOffcetsCheckbox_CheckedChanged); + this.manualOffsetsCheckbox.AutoSize = true; + this.manualOffsetsCheckbox.Location = new System.Drawing.Point(79, 72); + this.manualOffsetsCheckbox.Name = "manualOffsetsCheckbox"; + this.manualOffsetsCheckbox.Size = new System.Drawing.Size(98, 17); + this.manualOffsetsCheckbox.TabIndex = 8; + this.manualOffsetsCheckbox.Text = "Manual Offsets"; + this.manualOffsetsCheckbox.UseVisualStyleBackColor = true; + this.manualOffsetsCheckbox.CheckedChanged += new System.EventHandler(this.manualOffsetsCheckbox_CheckedChanged); // // Settings // @@ -411,37 +414,37 @@ private void InitializeComponent() #endregion - private System.Windows.Forms.Label label1; - private System.Windows.Forms.TextBox pathTextBox; - private System.Windows.Forms.CheckBox steamCheckBox; - private System.Windows.Forms.Button browseButton; - private System.Windows.Forms.ComboBox p1DeviceCombo; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.TextBox p1vidTextBox; - private System.Windows.Forms.TextBox p1pidTexBox; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.CheckBox p1manualCheckBox; - private System.Windows.Forms.Button okButton; - private System.Windows.Forms.Button cancelButton; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.TextBox offcetVidTextBox; - private System.Windows.Forms.TextBox offcetPidTextBox; - private System.Windows.Forms.GroupBox player1GroupBox; - private System.Windows.Forms.OpenFileDialog openFileDialog1; - private System.Windows.Forms.GroupBox groupBox2; - private System.Windows.Forms.GroupBox player2GroupBox; - private System.Windows.Forms.CheckBox p2manualCheckBox; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.Label label9; - private System.Windows.Forms.ComboBox p2DeviceCombo; - private System.Windows.Forms.TextBox p2pidTexBox; - private System.Windows.Forms.TextBox p2vidTextBox; - private System.Windows.Forms.CheckBox multiplayerCheckBox; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.Button inputDevButton; - private System.Windows.Forms.Label label12; - private System.Windows.Forms.CheckBox manualOffcetsCheckbox; + private Label label1; + private TextBox pathTextBox; + private CheckBox steamCheckBox; + private Button browseButton; + private ComboBox p1DeviceCombo; + private Label label2; + private TextBox p1vidTextBox; + private TextBox p1pidTexBox; + private Label label3; + private Label label4; + private CheckBox p1manualCheckBox; + private Button okButton; + private Button cancelButton; + private Label label5; + private TextBox offsetVidTextBox; + private TextBox offsetPidTextBox; + private GroupBox player1GroupBox; + private OpenFileDialog openFileDialog1; + private GroupBox groupBox2; + private GroupBox player2GroupBox; + private CheckBox p2manualCheckBox; + private Label label7; + private Label label8; + private Label label9; + private ComboBox p2DeviceCombo; + private TextBox p2pidTexBox; + private TextBox p2vidTextBox; + private CheckBox multiplayerCheckBox; + private Label label6; + private Button inputDevButton; + private Label label12; + private CheckBox manualOffsetsCheckbox; } } \ No newline at end of file diff --git a/scr/NoCableLauncher/Settings.cs b/scr/NoCableLauncher/Settings.cs index ac8e275..8331ddd 100644 --- a/scr/NoCableLauncher/Settings.cs +++ b/scr/NoCableLauncher/Settings.cs @@ -1,9 +1,9 @@ using System; -using System.Windows.Forms; using System.ComponentModel; -using NoCableLauncher.CoreAudioApi; using System.Diagnostics; - +using System.Windows.Forms; +using NoCableLauncher.CoreAudioApi; +using NoCableLauncher.Properties; namespace NoCableLauncher { @@ -89,7 +89,7 @@ private int GetDeviceIndex(string guid) private void Settings_Load(object sender, EventArgs e) { - this.Icon = Properties.Resources.rs14; + Icon = Resources.rs14; LoadDeviceList(); @@ -130,10 +130,10 @@ private void Settings_Load(object sender, EventArgs e) pathTextBox.Text = Program.settings.gamePath; - manualOffcetsCheckbox.Checked = Program.settings.manualOffcets; - offcetVidTextBox.Text = Program.settings.offcetVID; - offcetPidTextBox.Text = Program.settings.offcetPID; - manualOffcetsCheckbox_CheckedChanged(null, e); + manualOffsetsCheckbox.Checked = Program.settings.manualOffsets; + offsetVidTextBox.Text = Program.settings.offsetVID; + offsetPidTextBox.Text = Program.settings.offsetPID; + manualOffsetsCheckbox_CheckedChanged(null, e); } private void p1manualCheckBox_CheckedChanged(object sender, EventArgs e) @@ -150,10 +150,10 @@ private void p2manualCheckBox_CheckedChanged(object sender, EventArgs e) p2DeviceCombo.Enabled = !p2manualCheckBox.Checked; } - private void manualOffcetsCheckbox_CheckedChanged(object sender, EventArgs e) + private void manualOffsetsCheckbox_CheckedChanged(object sender, EventArgs e) { - offcetPidTextBox.ReadOnly = !manualOffcetsCheckbox.Checked; - offcetVidTextBox.ReadOnly = !manualOffcetsCheckbox.Checked; + offsetPidTextBox.ReadOnly = !manualOffsetsCheckbox.Checked; + offsetVidTextBox.ReadOnly = !manualOffsetsCheckbox.Checked; } private void DeviceIDcheck() @@ -173,9 +173,9 @@ private void SaveSettings() Program.settings.gamePath = pathTextBox.Text; Program.settings.isSteam = steamCheckBox.Checked; - Program.settings.offcetVID = offcetVidTextBox.Text; - Program.settings.offcetPID = offcetPidTextBox.Text; - Program.settings.manualOffcets = manualOffcetsCheckbox.Checked; + Program.settings.offsetVID = offsetVidTextBox.Text; + Program.settings.offsetPID = offsetPidTextBox.Text; + Program.settings.manualOffsets = manualOffsetsCheckbox.Checked; Program.settings.VID = p1vidTextBox.Text; Program.settings.PID = p1pidTexBox.Text; @@ -279,8 +279,6 @@ private void Settings_FormClosing(object sender, FormClosingEventArgs e) case DialogResult.No: //Do nothing break; - default: - break; } } } diff --git a/scr/NoCableLauncher/SettingsClass.cs b/scr/NoCableLauncher/SettingsClass.cs index 0012d49..32312cf 100644 --- a/scr/NoCableLauncher/SettingsClass.cs +++ b/scr/NoCableLauncher/SettingsClass.cs @@ -1,13 +1,18 @@ -namespace NoCableLauncher +using System.CodeDom.Compiler; +using System.Configuration; +using System.Diagnostics; +using System.Runtime.CompilerServices; + +namespace NoCableLauncher { class SettingsClass { - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + [CompilerGenerated] + [GeneratedCode("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] + internal sealed class Settings : ApplicationSettingsBase { - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + private static Settings defaultInstance = ((Settings)(Synchronized(new Settings()))); public static Settings Default { @@ -17,10 +22,10 @@ public static Settings Default } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute(Program.steamName)] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue(Program.steamName)] public string gamePath { get @@ -34,42 +39,42 @@ public string gamePath } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("012DE6EC")] - public string offcetVID + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("012DE6EC")] + public string offsetVID { get { - return ((string)(this["offcetVID"])); + return ((string)(this["offsetVID"])); } set { - this["offcetVID"] = value; + this["offsetVID"] = value; } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("012DE6F4")] - public string offcetPID + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("012DE6F4")] + public string offsetPID { get { - return ((string)(this["offcetPID"])); + return ((string)(this["offsetPID"])); } set { - this["offcetPID"] = value; + this["offsetPID"] = value; } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0000")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("0000")] public string PID { get @@ -82,10 +87,10 @@ public string PID } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0000")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("0000")] public string VID { get @@ -98,10 +103,10 @@ public string VID } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0000")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("0000")] public string PID2 { get @@ -114,10 +119,10 @@ public string PID2 } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("0000")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("0000")] public string VID2 { get @@ -130,10 +135,10 @@ public string VID2 } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("")] public string GUID1 { get @@ -146,10 +151,10 @@ public string GUID1 } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("")] public string GUID2 { get @@ -163,10 +168,10 @@ public string GUID2 } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("True")] public bool isSteam { get @@ -179,10 +184,10 @@ public bool isSteam } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("False")] public bool Multiplayer { get @@ -195,27 +200,27 @@ public bool Multiplayer } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool manualOffcets + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("False")] + public bool manualOffsets { get { - return ((bool)(this["manualOffcets"])); + return ((bool)(this["manualOffsets"])); } set { - this["manualOffcets"] = value; + this["manualOffsets"] = value; } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("False")] public bool manualDev1 { get @@ -228,10 +233,10 @@ public bool manualDev1 } } - [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] + [SettingsProvider(typeof(PortableSettingsProvider))] + [UserScopedSetting] + [DebuggerNonUserCode] + [DefaultSettingValue("False")] public bool manualDev2 { get From 4f02c0742db541199e3d683e6eaec7b50628670d Mon Sep 17 00:00:00 2001 From: Mywk Date: Sat, 9 Nov 2019 13:11:36 +0100 Subject: [PATCH 2/9] # Implemented changes by janabimustafa ~ Added automatic switching to secondary input if primary isn't plugged in --- scr/NoCableLauncher/Program.cs | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/scr/NoCableLauncher/Program.cs b/scr/NoCableLauncher/Program.cs index ee38ed0..e415e33 100644 --- a/scr/NoCableLauncher/Program.cs +++ b/scr/NoCableLauncher/Program.cs @@ -3,6 +3,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Management; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; @@ -97,6 +98,29 @@ private static byte[] GetDevId(string value) }; } + private static bool IsUsbDeviceConnected(string pid, string vid) + { + using (var searcher = + new ManagementObjectSearcher(@"Select * From Win32_USBControllerDevice")) + { + using (var collection = searcher.Get()) + { + foreach (var device in collection) + { + var usbDevice = Convert.ToString(device); + + if (usbDevice.Contains(pid) && usbDevice.Contains(vid)) + return true; + } + } + } + return false; + } + private static bool IsDeviceUsbAndConnected(string pid, string vid) + { + return ((settings.VID.All(number => number == 0) && settings.PID.All(number => number == 0)) || IsUsbDeviceConnected(settings.PID, settings.VID)); + } + private static void ExitWithError(string value) { if (value != string.Empty) @@ -109,8 +133,7 @@ private static void ReadDeviceValues(bool multiplayer) { try { - //Getting device VID & PID - if (!multiplayer) + if (IsDeviceUsbAndConnected(settings.PID, settings.VID) && !multiplayer) { vid = GetDevId(settings.VID); pid = GetDevId(settings.PID); @@ -316,7 +339,7 @@ public static void Main(string[] args) } else { - if (settings.Multiplayer) + if (settings.Multiplayer && IsDeviceUsbAndConnected(settings.PID, settings.VID)) { //Disable player2 record device SetDeviceState(settings.GUID2); From 9a2b636c7e0b2794951cf27b90b9dc11ebf75ef4 Mon Sep 17 00:00:00 2001 From: Mywk Date: Sun, 10 Nov 2019 15:15:09 +0100 Subject: [PATCH 3/9] ~ Interface re-design and improvements ~ Replaced logo + Started implementing onboard soundcard fixes (prevent duplicated controllers) ~ Automated enable/disable capture devices + Duplicated instance detection ~ IPolicyConfig now using the correct types + Settings state change tracker + EditSettings.bat automatically created if not present ~ Process detection should no longer crash if taking too long to open --- scr/NoCableLauncher/Common.cs | 99 + .../CoreAudioApi/Interfaces/IPolicyConfig.cs | 8 +- scr/NoCableLauncher/CoreAudioApi/MMDevice.cs | 15 + scr/NoCableLauncher/EditSettings.bat | 1 - scr/NoCableLauncher/Logo.ico | Bin 0 -> 22382 bytes scr/NoCableLauncher/NoCableLauncher.csproj | 15 +- scr/NoCableLauncher/Program.cs | 211 +- .../Properties/Resources.Designer.cs | 34 +- scr/NoCableLauncher/Properties/Resources.resx | 4 +- scr/NoCableLauncher/Resources/Logo.png | Bin 0 -> 7820 bytes scr/NoCableLauncher/Resources/refresh.png | Bin 0 -> 3511 bytes scr/NoCableLauncher/Resources/rs14.ico | Bin 7886 -> 0 bytes scr/NoCableLauncher/Settings.Designer.cs | 346 ++- scr/NoCableLauncher/Settings.cs | 224 +- scr/NoCableLauncher/Settings.resx | 1971 +++++++++++++++++ scr/NoCableLauncher/SettingsClass.cs | 17 + 16 files changed, 2719 insertions(+), 226 deletions(-) create mode 100644 scr/NoCableLauncher/Common.cs delete mode 100644 scr/NoCableLauncher/EditSettings.bat create mode 100644 scr/NoCableLauncher/Logo.ico create mode 100644 scr/NoCableLauncher/Resources/Logo.png create mode 100644 scr/NoCableLauncher/Resources/refresh.png delete mode 100644 scr/NoCableLauncher/Resources/rs14.ico diff --git a/scr/NoCableLauncher/Common.cs b/scr/NoCableLauncher/Common.cs new file mode 100644 index 0000000..64703b6 --- /dev/null +++ b/scr/NoCableLauncher/Common.cs @@ -0,0 +1,99 @@ +using NoCableLauncher.CoreAudioApi; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using static NoCableLauncher.Settings; + +namespace NoCableLauncher +{ + public static class Common + { + public static BindingList devices = new BindingList(); + private static MMDeviceCollection pDevices; + private static MMDeviceEnumerator DeviceEnumerator = new MMDeviceEnumerator(); + private static string defaultID = "0000"; + + private static PolicyConfigClient pPolicyConfig = new PolicyConfigClient(); + + public static string GetPDeviceId(int index) + { + return pDevices[index].ID; + } + + public static void LoadDeviceList() + { + devices.Clear(); + + pDevices = DeviceEnumerator.EnumerateAudioEndPoints(EDataFlow.eCapture, EDeviceState.Active | EDeviceState.Disabled); + + for (int i = 0; i < pDevices.Count; i++) + { + string devid = pDevices[i].HardwareID; + + string vid = defaultID; + string pid = defaultID; + + if (devid.Contains("PID_")) + { + vid = devid.Substring(devid.IndexOf("VID_") + 4, 4); + pid = devid.Substring(devid.IndexOf("PID_") + 4, 4); + } + + devices.Add(new SoundDevice(pDevices[i].FriendlyName, vid, pid)); + } + + } + + public static bool SetDeviceState(string guid, bool enabled = false) + { + if (guid != string.Empty) + { + pPolicyConfig.SetEndpointVisibility(guid, enabled); + return true; + } + + return false; + } + + private static List DisabledEndpoints = new List(); + + public static void DisableAllCaptureDevicesExcept(string guid) + { + for (int i = 0; i < pDevices.Count; i++) + { + if (pDevices[i].DeviceState == EDeviceState.Active && pDevices[i].ID != guid) + { + DisabledEndpoints.Add(pDevices[i].ID); + SetDeviceState(pDevices[i].ID); + } + } + } + + public static void ReEnableCaptureDevices() + { + foreach (var guid in DisabledEndpoints) + { + SetDeviceState(guid, true); + } + } + + public static int GetDeviceIndex(string guid) + { + if (guid != string.Empty) + { + for (int i = 0; i < pDevices.Count; i++) + { + if (pDevices[i].ID == guid) + { + return i; + } + } + } + + return 0; + } + + } +} diff --git a/scr/NoCableLauncher/CoreAudioApi/Interfaces/IPolicyConfig.cs b/scr/NoCableLauncher/CoreAudioApi/Interfaces/IPolicyConfig.cs index 222c1b7..d0df641 100644 --- a/scr/NoCableLauncher/CoreAudioApi/Interfaces/IPolicyConfig.cs +++ b/scr/NoCableLauncher/CoreAudioApi/Interfaces/IPolicyConfig.cs @@ -38,9 +38,13 @@ internal interface IPolicyConfig int SetPropertyValue(string pszDeviceName, bool bFxStore, IntPtr key, IntPtr pv); [PreserveSig] - int SetDefaultEndpoint(string pszDeviceName, ERole role); + int SetDefaultEndpoint( + [In] [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceName, + [In] [MarshalAs(UnmanagedType.U4)] ERole role); [PreserveSig] - int SetEndpointVisibility(string pszDeviceName, bool bVisible); + int SetEndpointVisibility( + [In] [MarshalAs(UnmanagedType.LPWStr)] string pszDeviceName, + [In] [MarshalAs(UnmanagedType.Bool)] bool bVisible); } } diff --git a/scr/NoCableLauncher/CoreAudioApi/MMDevice.cs b/scr/NoCableLauncher/CoreAudioApi/MMDevice.cs index 7fe078e..f540a57 100644 --- a/scr/NoCableLauncher/CoreAudioApi/MMDevice.cs +++ b/scr/NoCableLauncher/CoreAudioApi/MMDevice.cs @@ -93,9 +93,24 @@ public string ID } } + public NoCableLauncher.CoreAudioApi.EDeviceState DeviceState + { + get + { + NoCableLauncher.CoreAudioApi.EDeviceState Result; + Marshal.ThrowExceptionForHR(_RealDevice.GetState(out Result)); + return Result; + } + } + internal MMDevice(IMMDevice realDevice) { _RealDevice = realDevice; } + + public IMMDevice GetRealDevice() + { + return _RealDevice; + } } } diff --git a/scr/NoCableLauncher/EditSettings.bat b/scr/NoCableLauncher/EditSettings.bat deleted file mode 100644 index 4e686a5..0000000 --- a/scr/NoCableLauncher/EditSettings.bat +++ /dev/null @@ -1 +0,0 @@ -start NoCableLauncher.exe -set \ No newline at end of file diff --git a/scr/NoCableLauncher/Logo.ico b/scr/NoCableLauncher/Logo.ico new file mode 100644 index 0000000000000000000000000000000000000000..c1f1ba4a0edd92043972052cce44867d8ddb8367 GIT binary patch literal 22382 zcmeI42Xs|cy2oz{1PG8&rHm#JkpR-fMNtG6AWb@`6crql2hs%#C=WCUVucZbX9a1_ zV;DdkbsTX(U4TeY-q6H>(3?Q$kaG9?|90-VoLufDU_uawz1A=LoOAct<=cCI``hKj z;|cRbc$zfv$dC6VHuZSwdOV)^_{{qcV?CaS^ek3BzxRvuc=C7gcoG#xuXx4^o?F+% z<0%oHN#=v=f3Hj6x&*FE;JO6zNCII>C%=#u_7oSTMKMv>MUCDs5R~9`4W&TQR5qo@Wm;ZzKL?ns!g0>MMu60LyPY{E| zVzFC|`?N?E89vf|_b2rGX7PdOAj*kwajiP?9w&NE&B(H^D? zWDp~+MMv8$BPcudepGl>K9d~^mm#)^_eE1tROq#9#*tU_dRsAD>=IsK90FzFJa_rD zgH2+Bs4ohNYr#==#4e0kQet3AeKMdh@e^z1EiZP;= zxE5r9uCFJ?tDNhjqN36Z7A$BS3KS?{^5@HEB2-q|fWjH%5h>Z^&!6A$yAu{aU%q_k z#D9vxB3{t1eya|BcY}CLEDw(eKUuVBQ4>hv!i8-)X%CcLWwd23T%_;?VWSI2dllxe z;#(+M33S14)seU6Vy?<|v`CR6CN?(qJjG&7v0}ySJ-?}K7}`1YjErKP-{r@+-YXPs zWst0RlSCcyn`;BALyyW*Q{_$y4-4OvU+tbU0%ePdi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~g-5GdRS zBD*%wRpnr9)Ru=cC?j<4n0D~gQ%~9bW6tApZVH}Jy|~lo`c0kRbUSnw=PdNwY{A;o z#as{4XH2Iol%2XIKQ~C$jCcIz#>p!_=Y;efqdR$fO}!{l)=#sOe-qhL#|r9u;+I}} z$(H4V`&<622cRG9aYfE5>OHsTnNgx|XAD|5$;S4Be#raMM-E%ScF4uwZ?5lmH?{qnL5EYdl z`*eoDUcVGqT!Eeu+xQ+LA)%se|LEJq#LD&@YgK&*URCE=E&A?(eh!>*uyttgS72G=B zK^FDILt?aGZ)m2VOrMLt3dXlt;w|xl=r39b?Dg#0n}S@jBR|;o#0j+3{H}Y(?O#() zz4o8!{QdiEoR)G}XJJhRSfdcqr-F48Xe@&+j+F=z1M1W<$tVm>tl?ITZ}j_6u8nMpvl$ubX6>4__Wh@ye%jXPe4P>1OUPnWh?k=(RH(45_HDP> z?;jbP`344ChHIDoxix5i>O82v&9-S`Z;&qfpYIF!hC(lqhhBj%>pqFG zyMw+r`D33x_UtidFQ@~?Zfq6oC%#8f*pEcuTEaZW`35?-%9#evu=754qQY96luR)O zNv1#Q89K@BW-^X&_5s_;IR`;{ToWG-St#5Zy%?B&b3IR^o*37$`Q7l0`KP`=b*>GSA5L+xq5!b}hso3}aR0)3~a=q5UehN7%cm&iSb g5=xKL0RfQ`BV - Resources\rs14.ico + Logo.ico true @@ -64,6 +64,7 @@ + @@ -110,6 +111,7 @@ ResXFileCodeGenerator Resources.Designer.cs + Designer Settings.cs @@ -117,12 +119,6 @@ - - PreserveNewest - - - - @@ -141,6 +137,11 @@ true + + + + +