From 0e8a8038ee37d192d25bd7a63813c9c3eb2ec685 Mon Sep 17 00:00:00 2001 From: Patrick Magauran Date: Tue, 26 Dec 2023 20:19:11 -0500 Subject: [PATCH] Support for multiple Game Types. Support for DiRT 1/2. --- .vs/ForzaDSX/v17/.suo | Bin 87040 -> 85504 bytes AppCheckThread.cs | 20 +++++++--- Config/ConfigHandler.cs | 12 ++++++ ForzaDSXWorker.cs | 53 +++++++-------------------- GameParsers/DirtParser.cs | 59 ++++++++++++++++++++++++++++++ GameParsers/NullParser.cs | 30 +++++++++++++++ UI.Designer.cs | 56 +++++++++++++++++++++------- UI.cs | 75 ++++++++++++++++++++++++++++++++------ 8 files changed, 234 insertions(+), 71 deletions(-) create mode 100644 GameParsers/DirtParser.cs create mode 100644 GameParsers/NullParser.cs diff --git a/.vs/ForzaDSX/v17/.suo b/.vs/ForzaDSX/v17/.suo index 9b8d6f757c59d36353a2f6e6a5a43cd15cd20fd4..39f7cabc37963a3f10318ac3826b912e91e28e86 100644 GIT binary patch delta 7999 zcmeHM3sh9q8a{iNf#JPsBi(Jq;h0NAQ2`QG(ly=@{!7g z`AvFQ*&u35*D5)cmR=bW!!#31z16i=S+}g{Wul?N+<(slK_Rv0y?3=)-|T z{|QSSD%`7)$`|7g7FQr#VXc;HaN$;lVLJs8jqpH(BXDg?@kDw|uQq+C4BI{kN5l|B zGU8suV1z$Hf}oQpV;zjR8!-$q5fOpt!oCEo6A?)aQ)wCOf{jRoFG7l-4|2v@hzLc{ z1)Xd)rD=(}p*;`V4Tz11@rWSA6ohrO**p&EX}#LsNb?y#h8cmxbVMLx1|k(Ps5X7H z>>ecMB61K^a`z$bN8lVrg_w^RiBKadYtt8U^+*^vg||>eWp7p3cjt;zsc7iQsY>j8 zyJ~2gs)mZ3ir=mpDqbp9yK3k-F1BfHR}H1@1)ouA(T$y9*Nwg1OE;E9)VCzZ0g@D0Qu5_72xAV3rvF2Ek@ zBGd(G(4j_0JM9=`YeT*$luLaSYD5bD7$m5>zwvj*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SQ5Oo~BqOaY2UDNKGNiZe7~dZ;`R3$HZ! zLRPFlsFn-inPYXJIB~@n6O#s0XDPG58b_=O zuu!d2Yt(ZdD$-duK86#MdN5)57e($GZRtF%dXaUJfiCLC+2W9AlciB>%Rv2g46GlW z0*cQ9h27bt+P>ax?jovzRjl4vAte*LaJb=Lgc8CtR=5*A$l^ncAwsf(@6ITnwr}sI zgp*p{LX}PH;d9DJtdaPW!2z8d=Se^3NyxeqZG1^Wf~8tKds`c1rlkS>2%x;n_ZIb2 zSxv1%^Au5~60AxM?9T0dQP8ayIh2HOo|vb+tHbs6R-*lFvZ+S#R*gctF?(GSc&jB2 zZA1wj2E$KkX8Kh#!}y9nDR%PsUax_VD2Lt_<+=_ftqojIeIN6rNL%G5|BtVWVJ7*12ZJ*ONhkl8eE)boSLQ6h?U zwJC!iam{0p_NosHB%fh&W%(i+YiJwuX^X31nMTojaN)Z!O6M8QaA^mTuCxijzp-Xo z)XEXcK8hg0fm0m8XIy9Sp~lIh#u=G;t9f~@dQp+}0%*$$ZndaGNZPIDe_Dvc;Pm62 zqtSYIC_;IgAnWB}(~iDNy7gVc91KZU9{sH@uvH7c z)dg5H-(BXvebwNI$^TPzfs~LK>%{@{RaZfj+q7|bxuQUHMPoEeh+FSP!!Z20$gwF% zmai--E1p*}E6T^ZyK{_Uw7r%WeH8U>SC8Ni%pEP#yc8*#_KbGwJH^g}>9smFU diff --git a/AppCheckThread.cs b/AppCheckThread.cs index fb00822..0d968c1 100644 --- a/AppCheckThread.cs +++ b/AppCheckThread.cs @@ -63,14 +63,18 @@ public void updateExecutables() { lock (this) { - foreach (var profile in settings.Profiles) + processProfilePairs.Clear(); + + foreach (var profile in settings.Profiles) { if (!profile.Value.IsEnabled) { continue; } - processProfilePairs.Clear(); profile.Value.executableNames.ForEach((name) => { - processProfilePairs.Add(name, profile.Key); - }); + if (!processProfilePairs.ContainsKey(name)) + { + processProfilePairs.Add(name, profile.Key); + } + }); } // settings = currentSettings; } @@ -78,13 +82,17 @@ public void updateExecutables() public void Run() { + processProfilePairs.Clear(); + foreach (var profile in settings.Profiles) { if (!profile.Value.IsEnabled) { continue; } - processProfilePairs.Clear(); profile.Value.executableNames.ForEach((name) => { - processProfilePairs.Add(name, profile.Key); + if (!processProfilePairs.ContainsKey(name)) + { + processProfilePairs.Add(name, profile.Key); + } }); } bRunning = true; diff --git a/Config/ConfigHandler.cs b/Config/ConfigHandler.cs index 8f8c29c..12eb83a 100644 --- a/Config/ConfigHandler.cs +++ b/Config/ConfigHandler.cs @@ -44,6 +44,18 @@ private static Config AddDefaultProfiles(Config config) profile.executableNames.AddRange(new string[] { "ForzaHorizon5", "ForzaHorizon4", "ForzaMotorsport7", "forza_gaming.desktop.x64_release_final", "forza_steamworks_release_final" }); config.Profiles.Add("Forza", profile); } + if (!config.Profiles.ContainsKey("Dirt")) + { + Profile profile = new Profile + { + Name = "Dirt", + gameUDPPort = 5300, + GameType = GameTypes.Dirt + }; + profile.throttleSettings.GripLossValue = 0.4f; + profile.executableNames.AddRange(new string[] { "drt"}); + config.Profiles.Add("Dirt", profile); + } return config; } diff --git a/ForzaDSXWorker.cs b/ForzaDSXWorker.cs index 8a70ee2..ca12355 100644 --- a/ForzaDSXWorker.cs +++ b/ForzaDSXWorker.cs @@ -315,7 +315,19 @@ public void Run() } return; } - parser = new ForzaParser(settings); + switch (settings.ActiveProfile.GameType) + { + case GameTypes.Forza: + parser = new ForzaParser(settings); + break; + case GameTypes.Dirt: + parser = new DirtParser(settings); + break; + default: + parser = new NullParser(settings); + break; + } + //parser = new ForzaParser(settings); //Connect to Forza ipEndPoint = new IPEndPoint(IPAddress.Loopback, settings.ActiveProfile.gameUDPPort); client = new UdpClient(settings.ActiveProfile.gameUDPPort); @@ -397,46 +409,7 @@ public void Stop() - DataPacket parseDirtData(byte[] packet) - { - DataPacket data = new DataPacket(); - //data.AccelerationX - - data.IsRaceOn = true; - data.Power = 1; - data.CurrentEngineRpm = PacketParse.GetSingle(packet, 148) * 10.0f; - data.Speed = PacketParse.GetSingle(packet, 28); - data.frontLeftContactPatchV = PacketParse.GetSingle(packet, 108); - data.TireCombinedSlipFrontLeft = calcTireSlip(PacketParse.GetSingle(packet, 108), data.Speed); - data.TireCombinedSlipFrontRight = calcTireSlip(PacketParse.GetSingle(packet, 112), data.Speed); - data.TireCombinedSlipRearLeft = calcTireSlip(PacketParse.GetSingle(packet, 100), data.Speed); - data.TireCombinedSlipRearRight = calcTireSlip(PacketParse.GetSingle(packet, 104), data.Speed); - - - data.CarClass = 0; - - data.CarPerformanceIndex = 0; - - data.AccelerationX = PacketParse.GetSingle(packet, 136); - data.AccelerationZ = PacketParse.GetSingle(packet, 140); - - data.Accelerator = (uint)(PacketParse.GetSingle(packet, 116)* 255.0f); - - data.Brake = (uint)(PacketParse.GetSingle(packet, 120) * 255.0f); - - data.EngineMaxRpm = PacketParse.GetSingle(packet, 252) * 10.0f; - data.EngineIdleRpm = 0; - return data; - } - static float calcTireSlip(float contactPatchSpeed, float vehicleSpeed) - { - if (Math.Abs(vehicleSpeed) < 0.1f) - { - return 0; - } - return 3.0f * (Math.Abs(Math.Abs(contactPatchSpeed) - vehicleSpeed) / vehicleSpeed); - } //Parses data from Forza into a DataPacket /* DataPacket ParseData(byte[] packet) { diff --git a/GameParsers/DirtParser.cs b/GameParsers/DirtParser.cs new file mode 100644 index 0000000..07e5892 --- /dev/null +++ b/GameParsers/DirtParser.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ForzaDSX.GameParsers +{ + internal class DirtParser : Parser + { + public DirtParser(Config.Config settings) : base(settings) + { + } + + public override void ParsePacket(byte[] packet) + { + data = new DataPacket(); + //data.AccelerationX + + data.IsRaceOn = true; + data.Power = 1; + data.CurrentEngineRpm = PacketParse.GetSingle(packet, 148) * 10.0f; + data.Speed = PacketParse.GetSingle(packet, 28); + data.frontLeftContactPatchV = PacketParse.GetSingle(packet, 108); + data.TireCombinedSlipFrontLeft = calcTireSlip(PacketParse.GetSingle(packet, 108), data.Speed); + data.TireCombinedSlipFrontRight = calcTireSlip(PacketParse.GetSingle(packet, 112), data.Speed); + data.TireCombinedSlipRearLeft = calcTireSlip(PacketParse.GetSingle(packet, 100), data.Speed); + data.TireCombinedSlipRearRight = calcTireSlip(PacketParse.GetSingle(packet, 104), data.Speed); + + + data.CarClass = 0; + + data.CarPerformanceIndex = 0; + + data.AccelerationX = PacketParse.GetSingle(packet, 136); + + data.AccelerationZ = PacketParse.GetSingle(packet, 140); + + data.Accelerator = (uint)(PacketParse.GetSingle(packet, 116) * 255.0f); + + data.Brake = (uint)(PacketParse.GetSingle(packet, 120) * 255.0f); + + data.EngineMaxRpm = PacketParse.GetSingle(packet, 252) * 10.0f; + data.EngineIdleRpm = 0; + data.FourWheelCombinedTireSlip = (Math.Abs(data.TireCombinedSlipFrontLeft) + Math.Abs(data.TireCombinedSlipFrontRight) + Math.Abs(data.TireCombinedSlipRearLeft) + Math.Abs(data.TireCombinedSlipRearRight)) / 4; + data.FrontWheelsCombinedTireSlip = (Math.Abs(data.TireCombinedSlipFrontLeft) + Math.Abs(data.TireCombinedSlipFrontRight)) / 2; + data.RearWheelsCombinedTireSlip = (Math.Abs(data.TireCombinedSlipRearLeft) + Math.Abs(data.TireCombinedSlipRearRight)) / 2; + } + static float calcTireSlip(float contactPatchSpeed, float vehicleSpeed) + { + if (Math.Abs(vehicleSpeed) < 0.1f) + { + return 0; + } + return 3.0f * (Math.Abs(Math.Abs(contactPatchSpeed) - vehicleSpeed) / vehicleSpeed); + } + + } +} diff --git a/GameParsers/NullParser.cs b/GameParsers/NullParser.cs new file mode 100644 index 0000000..b78c346 --- /dev/null +++ b/GameParsers/NullParser.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ForzaDSX.GameParsers +{ + internal class NullParser : Parser + { + public NullParser(Config.Config settings) : base(settings) + { + } + + public override void ParsePacket(byte[] packet) + { + data = new DataPacket(); + //data.AccelerationX + + data.IsRaceOn = true; + data.Power = 1; + data.CurrentEngineRpm = 0; + data.Speed = 0; + data.TireCombinedSlipFrontLeft = 0; + data.TireCombinedSlipFrontRight = 0; + data.TireCombinedSlipRearLeft = 0; + data.TireCombinedSlipRearRight = 0; + } + } +} diff --git a/UI.Designer.cs b/UI.Designer.cs index 8915353..742b6d6 100644 --- a/UI.Designer.cs +++ b/UI.Designer.cs @@ -55,6 +55,8 @@ private void InitializeComponent() AddExecutableButton = new System.Windows.Forms.Button(); EditExecutableButton = new System.Windows.Forms.Button(); RemoveExecutableButton = new System.Windows.Forms.Button(); + GameModeLabel = new System.Windows.Forms.Label(); + GameModeComboBox = new System.Windows.Forms.ComboBox(); brakeConfigTabPage = new System.Windows.Forms.TabPage(); brakeTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); brakeResistanceSmoothNumericUpDown = new System.Windows.Forms.NumericUpDown(); @@ -344,16 +346,19 @@ private void InitializeComponent() miscTableLayoutPanel.Controls.Add(rpmLabel, 0, 0); miscTableLayoutPanel.Controls.Add(rpmTrackBar, 1, 0); miscTableLayoutPanel.Controls.Add(rpmValueNumericUpDown, 2, 0); - miscTableLayoutPanel.Controls.Add(buttonApplyMisc, 1, 6); - miscTableLayoutPanel.Controls.Add(miscDefaultsButton, 2, 6); - miscTableLayoutPanel.Controls.Add(ExecutableListLabel, 0, 5); - miscTableLayoutPanel.Controls.Add(ExecutableListBox, 1, 5); - miscTableLayoutPanel.Controls.Add(flowLayoutPanel1, 2, 5); + miscTableLayoutPanel.Controls.Add(buttonApplyMisc, 1, 7); + miscTableLayoutPanel.Controls.Add(miscDefaultsButton, 2, 7); + miscTableLayoutPanel.Controls.Add(ExecutableListLabel, 0, 6); + miscTableLayoutPanel.Controls.Add(ExecutableListBox, 1, 6); + miscTableLayoutPanel.Controls.Add(flowLayoutPanel1, 2, 6); + miscTableLayoutPanel.Controls.Add(GameModeLabel, 0, 5); + miscTableLayoutPanel.Controls.Add(GameModeComboBox, 1, 5); miscTableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; miscTableLayoutPanel.Location = new System.Drawing.Point(4, 5); miscTableLayoutPanel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); miscTableLayoutPanel.Name = "miscTableLayoutPanel"; - miscTableLayoutPanel.RowCount = 7; + miscTableLayoutPanel.RowCount = 8; + miscTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); miscTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); miscTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); miscTableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); @@ -371,10 +376,8 @@ private void InitializeComponent() forzaPortNumericUpDown.Location = new System.Drawing.Point(190, 84); forzaPortNumericUpDown.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); forzaPortNumericUpDown.Maximum = new decimal(new int[] { 65353, 0, 0, 0 }); - forzaPortNumericUpDown.MaximumSize = new System.Drawing.Size(143, 0); - forzaPortNumericUpDown.MinimumSize = new System.Drawing.Size(140, 0); forzaPortNumericUpDown.Name = "forzaPortNumericUpDown"; - forzaPortNumericUpDown.Size = new System.Drawing.Size(143, 31); + forzaPortNumericUpDown.Size = new System.Drawing.Size(593, 31); forzaPortNumericUpDown.TabIndex = 7; toolTip.SetToolTip(forzaPortNumericUpDown, "Port for Forza UDP server"); forzaPortNumericUpDown.ValueChanged += forzaPortNumericUpDown_ValueChanged; @@ -439,7 +442,7 @@ private void InitializeComponent() // buttonApplyMisc // buttonApplyMisc.Dock = System.Windows.Forms.DockStyle.Top; - buttonApplyMisc.Location = new System.Drawing.Point(190, 281); + buttonApplyMisc.Location = new System.Drawing.Point(190, 320); buttonApplyMisc.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); buttonApplyMisc.MaximumSize = new System.Drawing.Size(429, 50); buttonApplyMisc.MinimumSize = new System.Drawing.Size(286, 42); @@ -452,7 +455,7 @@ private void InitializeComponent() // // miscDefaultsButton // - miscDefaultsButton.Location = new System.Drawing.Point(791, 281); + miscDefaultsButton.Location = new System.Drawing.Point(791, 320); miscDefaultsButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); miscDefaultsButton.Name = "miscDefaultsButton"; miscDefaultsButton.Size = new System.Drawing.Size(107, 38); @@ -465,7 +468,7 @@ private void InitializeComponent() // ExecutableListLabel.Anchor = System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; ExecutableListLabel.AutoSize = true; - ExecutableListLabel.Location = new System.Drawing.Point(3, 185); + ExecutableListLabel.Location = new System.Drawing.Point(3, 224); ExecutableListLabel.Name = "ExecutableListLabel"; ExecutableListLabel.Size = new System.Drawing.Size(180, 25); ExecutableListLabel.TabIndex = 40; @@ -478,7 +481,7 @@ private void InitializeComponent() ExecutableListBox.Dock = System.Windows.Forms.DockStyle.Fill; ExecutableListBox.FormattingEnabled = true; ExecutableListBox.ItemHeight = 25; - ExecutableListBox.Location = new System.Drawing.Point(189, 123); + ExecutableListBox.Location = new System.Drawing.Point(189, 162); ExecutableListBox.Name = "ExecutableListBox"; ExecutableListBox.Size = new System.Drawing.Size(595, 150); ExecutableListBox.TabIndex = 41; @@ -491,7 +494,7 @@ private void InitializeComponent() flowLayoutPanel1.Controls.Add(RemoveExecutableButton); flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; - flowLayoutPanel1.Location = new System.Drawing.Point(790, 123); + flowLayoutPanel1.Location = new System.Drawing.Point(790, 162); flowLayoutPanel1.Name = "flowLayoutPanel1"; flowLayoutPanel1.Size = new System.Drawing.Size(799, 150); flowLayoutPanel1.TabIndex = 42; @@ -526,6 +529,29 @@ private void InitializeComponent() RemoveExecutableButton.UseVisualStyleBackColor = true; RemoveExecutableButton.Click += RemoveExecutableButton_Click; // + // GameModeLabel + // + GameModeLabel.Anchor = System.Windows.Forms.AnchorStyles.Right; + GameModeLabel.AutoSize = true; + GameModeLabel.Location = new System.Drawing.Point(84, 127); + GameModeLabel.Name = "GameModeLabel"; + GameModeLabel.Size = new System.Drawing.Size(99, 25); + GameModeLabel.TabIndex = 43; + GameModeLabel.Text = "UDP Mode"; + GameModeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleRight; + toolTip.SetToolTip(GameModeLabel, "The Parser and backend to use to conver the game UDP to the DSX Commands"); + // + // GameModeComboBox + // + GameModeComboBox.Anchor = System.Windows.Forms.AnchorStyles.Left; + GameModeComboBox.FormattingEnabled = true; + GameModeComboBox.Items.AddRange(new object[] { "(None)", "Forza", "Dirt" }); + GameModeComboBox.Location = new System.Drawing.Point(189, 123); + GameModeComboBox.Name = "GameModeComboBox"; + GameModeComboBox.Size = new System.Drawing.Size(182, 33); + GameModeComboBox.TabIndex = 44; + GameModeComboBox.SelectedIndexChanged += GameModeComboBox_SelectedIndexChanged; + // // brakeConfigTabPage // brakeConfigTabPage.Controls.Add(brakeTableLayoutPanel); @@ -2456,5 +2482,7 @@ private void InitializeComponent() private System.Windows.Forms.Button AddExecutableButton; private System.Windows.Forms.Button EditExecutableButton; private System.Windows.Forms.Button RemoveExecutableButton; + private System.Windows.Forms.Label GameModeLabel; + private System.Windows.Forms.ComboBox GameModeComboBox; } } \ No newline at end of file diff --git a/UI.cs b/UI.cs index c35d777..6ddfb8f 100644 --- a/UI.cs +++ b/UI.cs @@ -1,4 +1,5 @@ using ForzaDSX.Config; +using ForzaDSX.GameParsers; using ForzaDSX.Properties; using System; using System.ComponentModel; @@ -146,7 +147,8 @@ protected void AppCheckReporter(AppCheckReportStruct value) if (value.value) { SwitchActiveProfile(value.message); - } else + } + else { SwitchActiveProfile(null); } @@ -171,7 +173,7 @@ protected void AppCheckReporter(AppCheckReportStruct value) protected void SwitchActiveProfile(String profileName) { Profile profile = null; - + if (profileName == "") { // profileName = selectedProfile.Name; @@ -183,7 +185,7 @@ protected void SwitchActiveProfile(String profileName) if (profileName != null && currentSettings.Profiles.ContainsKey(profileName)) { profile = currentSettings.Profiles[profileName]; - + } currentSettings.ActiveProfile = profile; ConfigHandler.SaveConfig(); @@ -197,6 +199,7 @@ protected void SwitchActiveProfile(String profileName) protected void RestartAppCheckThread() { StopAppCheckThread(); + System.Threading.Thread.Sleep(1100); startAppCheckThread(); } @@ -410,8 +413,8 @@ void loadProfilesIntoList() void SwitchDisplayedProfile(String profileName = "") { - - if (profileName == null || profileName == "" ) + + if (profileName == null || profileName == "") { if (selectedProfile == null) { @@ -435,6 +438,7 @@ void SwitchDisplayedProfile(String profileName = "") this.rpmTrackBar.Value = DenormalizeValue(selectedProfile.RPMRedlineRatio); rpmValueNumericUpDown.Value = rpmTrackBar.Value; this.forzaPortNumericUpDown.Value = selectedProfile.gameUDPPort; + this.GameModeComboBox.SelectedIndex = (int)selectedProfile.GameType; // Brake Panel this.brakeTriggerModeComboBox.SelectedIndex = (int)brakeSettings.TriggerMode; @@ -1056,6 +1060,7 @@ private void buttonApplyMisc_Click(object sender, EventArgs e) if (forzaDSXWorker != null) { selectedProfile.executableNames = executables.ToList(); + forzaDSXWorker.SetSettings(CurrentSettings); ConfigHandler.SaveConfig(); appCheckWorker.updateExecutables(); @@ -1151,7 +1156,7 @@ private void toolStripAppCheckOnItem_Click(object sender, EventArgs e) private void toolStripAppCheckOffItem_Click(object sender, EventArgs e) { - disableAppCheck(); + disableAppCheck(); } @@ -1275,6 +1280,13 @@ private void newToolStripMenuItem_Click(object sender, EventArgs e) String newProfileName = NameForm.ShowDialog("", "Please enter the Profile Name"); if (newProfileName != "") { + if (currentSettings.Profiles.ContainsKey(newProfileName)) + { + string message = "You cannot have a duplicate Profile Name!"; + MessageBox.Show(message); + return; + + } Profile newProfile = new Profile(); newProfile.Name = newProfileName; currentSettings.Profiles.Add(newProfileName, newProfile); @@ -1290,6 +1302,13 @@ private void renameToolStripMenuItem_Click(object sender, EventArgs e) String newProfileName = NameForm.ShowDialog(oldProfileName, "Please enter the Profile Name"); if (newProfileName != "" && oldProfileName != newProfileName) { + if (currentSettings.Profiles.ContainsKey(newProfileName)) + { + string message = "You cannot have a duplicate Profile Name!"; + MessageBox.Show(message); + return; + + } Profile newProfile = currentSettings.Profiles[oldProfileName]; currentSettings.Profiles.Remove(oldProfileName); newProfile.Name = newProfileName; @@ -1360,6 +1379,14 @@ private void AddExecutableButton_Click(object sender, EventArgs e) String newExecutableName = NameForm.ShowDialog("", "Please enter the Executable Name"); ; if (newExecutableName != "") { + var prof = currentSettings.Profiles.Values.Where(x => x.executableNames.Contains(newExecutableName)); + if (prof.Count() > 0) + { + string message = "You cannot have a duplicate Executable Name! Executable already part of Profile " + prof.First().Name; + MessageBox.Show(message); + return; + + } executables.Add(newExecutableName); // ExecutableListBox.Items.Add(newExecutableName); @@ -1372,9 +1399,16 @@ private void EditExecutableButton_Click(object sender, EventArgs e) String newExecutableName = NameForm.ShowDialog(oldExecutableName, "Please enter the Executable Name"); ; if (newExecutableName != "") { + var prof = currentSettings.Profiles.Values.Where(x => x.executableNames.Contains(newExecutableName)); + if (prof.Count() > 0) + { + string message = "You cannot have a duplicate Executable Name! Executable already part of Profile " + prof.First().Name; + MessageBox.Show(message); + return; + } int index = selectedProfile.executableNames.IndexOf(oldExecutableName); executables[index] = newExecutableName; - // ExecutableListBox.SelectedIndex = -1; + // ExecutableListBox.SelectedIndex = -1; // ExecutableListBox.Items.Add(newExecutableName); } @@ -1383,8 +1417,8 @@ private void EditExecutableButton_Click(object sender, EventArgs e) private void RemoveExecutableButton_Click(object sender, EventArgs e) { String oldExecutableName = ExecutableListBox.SelectedItems[0].ToString(); - - executables.Remove(oldExecutableName); + + executables.Remove(oldExecutableName); } @@ -1397,15 +1431,34 @@ private void ExecutableListBox_SelectedIndexChanged(object sender, EventArgs e) RemoveExecutableButton.Enabled = true; return; - } else if (ExecutableListBox.SelectedItems.Count == 0) + } + else if (ExecutableListBox.SelectedItems.Count == 0) { EditExecutableButton.Enabled = false; RemoveExecutableButton.Enabled = false; - } else if (ExecutableListBox.SelectedItems.Count == 1) + } + else if (ExecutableListBox.SelectedItems.Count == 1) { EditExecutableButton.Enabled = true; RemoveExecutableButton.Enabled = true; } } + + private void GameModeComboBox_SelectedIndexChanged(object sender, EventArgs e) + { + switch (GameModeComboBox.SelectedItem) + { + case "Forza": + selectedProfile.GameType = GameTypes.Forza; + break; + case "Dirt": + selectedProfile.GameType = GameTypes.Dirt; + break; + case "(None)": + selectedProfile.GameType = GameTypes.None; + break; + } + + } } } \ No newline at end of file