Skip to content

Commit

Permalink
Merge pull request #37 from patmagauran/main
Browse files Browse the repository at this point in the history
[In Testing / WiP] Add support for multiple profiles and Non-Forza Games
  • Loading branch information
cosmii02 authored Dec 30, 2023
2 parents 9adaf06 + 6d776b2 commit 2c3b32f
Show file tree
Hide file tree
Showing 34 changed files with 5,441 additions and 3,331 deletions.
Binary file modified .vs/ForzaDSX/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified .vs/ForzaDSX/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/ForzaDSX/v17/.suo
Binary file not shown.
109 changes: 83 additions & 26 deletions AppCheckThread.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ForzaDSX
{
Expand All @@ -9,7 +11,7 @@ public enum AppType : ushort
{
NONE = 0,
DSX = 1,
FORZA = 2
GAME = 2
}

public AppCheckReportStruct(AppType type, string msg, bool val = false)
Expand Down Expand Up @@ -40,56 +42,111 @@ public AppCheckReportStruct(AppType type)

internal class AppCheckThread
{
readonly ForzaDSX.Properties.Settings settings;
readonly IProgress<AppCheckReportStruct> progressReporter;
readonly ForzaDSX.Config.Config settings;
private Dictionary<String, String> processProfilePairs = new Dictionary<string, string>();

readonly IProgress<AppCheckReportStruct> progressReporter;

protected bool bRunning = false;

public AppCheckThread(ref ForzaDSX.Properties.Settings currentSettings, IProgress<AppCheckReportStruct> progressReporter)
public AppCheckThread(ref ForzaDSX.Config.Config currentSettings, IProgress<AppCheckReportStruct> progressReporter)
{

settings = currentSettings;
this.progressReporter = progressReporter;

this.progressReporter = progressReporter;

bRunning = false;
}

public void updateExecutables()
{
lock (this)
{
processProfilePairs.Clear();

foreach (var profile in settings.Profiles)
{
if (!profile.Value.IsEnabled) { continue; }
profile.Value.executableNames.ForEach((name) =>
{
if (!processProfilePairs.ContainsKey(name))
{
processProfilePairs.Add(name, profile.Key);
}
});
}
// settings = currentSettings;
}
}

public void Run()
{
bRunning = true;
processProfilePairs.Clear();

foreach (var profile in settings.Profiles)
{
if (!profile.Value.IsEnabled) { continue; }
profile.Value.executableNames.ForEach((name) =>
{
if (!processProfilePairs.ContainsKey(name))
{
processProfilePairs.Add(name, profile.Key);
}
});
}
bRunning = true;
try
{
if (progressReporter != null)
{
progressReporter.Report(new AppCheckReportStruct(0, "Connecting to Forza and DSX"));
}

int forzaProcesses = 0;
//int forzaProcesses = 0;
Process[] DSX, DSX_2;

AppCheckReportStruct dsxReport = new AppCheckReportStruct(AppCheckReportStruct.AppType.DSX);
AppCheckReportStruct forzaReport = new AppCheckReportStruct(AppCheckReportStruct.AppType.FORZA);
AppCheckReportStruct forzaReport = new AppCheckReportStruct(AppCheckReportStruct.AppType.GAME);

while (bRunning/*forzaProcesses == 0 || DSX.Length + DSX_2.Length == 0*/)
{
System.Threading.Thread.Sleep(1000);

forzaProcesses = Process.GetProcessesByName("ForzaHorizon5").Length;
forzaProcesses += Process.GetProcessesByName("ForzaHorizon4").Length; //Guess at name
forzaProcesses += Process.GetProcessesByName("ForzaMotorsport7").Length; //Guess at name
forzaProcesses += Process.GetProcessesByName("forza_gaming.desktop.x64_release_final").Length; //Guess at name
forzaProcesses += Process.GetProcessesByName("forza_steamworks_release_final").Length; //Guess at name

// DSX = "DSX" or "DualSenseX"
DSX = Process.GetProcessesByName("DSX");
DSX_2 = Process.GetProcessesByName("DualsenseX");

dsxReport.value = (DSX.Length + DSX_2.Length) > 0;
forzaReport.value = forzaProcesses > 0;

if (progressReporter != null)
{
progressReporter.Report(dsxReport);
progressReporter.Report(forzaReport);
lock (this) {
if (!bRunning) { break; }
forzaReport.value = false;
forzaReport.message = "";
foreach (var processName in processProfilePairs.Keys.AsEnumerable())
{

if (Process.GetProcessesByName(processName).Length > 0)
{
forzaReport.value = true;
forzaReport.message = processProfilePairs[processName];
break;
}
}
/* forzaProcesses = Process.GetProcessesByName("ForzaHorizon5").Length;
forzaProcesses += Process.GetProcessesByName("ForzaHorizon4").Length; //Guess at name
forzaProcesses += Process.GetProcessesByName("ForzaMotorsport7").Length; //Guess at name
forzaProcesses += Process.GetProcessesByName("forza_gaming.desktop.x64_release_final").Length; //Guess at name
forzaProcesses += Process.GetProcessesByName("forza_steamworks_release_final").Length; //Guess at name*/

// DSX = "DSX" or "DualSenseX"
DSX = Process.GetProcessesByName("DSX");
DSX_2 = Process.GetProcessesByName("DualsenseX");

dsxReport.value = (DSX.Length + DSX_2.Length) > 0;
//forzaReport.value = forzaProcesses > 0;

//forzaReport.value = true;
//TODO: CHANGE
if (!bRunning) { break; }
if (progressReporter != null)
{
progressReporter.Report(dsxReport);
progressReporter.Report(forzaReport);
}
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions Config/BrakeSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForzaDSX.Config
{
public class BrakeSettings
{
public TriggerMode TriggerMode { get; set; } = TriggerMode.Vibration;

public float EffectIntensity { get; set; } = 0.7f;

public float GripLossValue { get; set; } = 0.5f;
public int VibrationStart { get; set; } = 20;
public int VibrationModeStart { get; set; } = 10;
public int MinVibration { get; set; } = 3;
public int MaxVibration { get; set; } = 35;
public float VibrationSmoothing { get; set; } = 1f;
public int MinStiffness { get; set; } = 200;
public int MaxStiffness { get; set; } = 1;
public int MinResistance { get; set; } = 1;
public int MaxResistance { get; set; } = 6;
public float ResistanceSmoothing { get; set; } = 1f;
}
}
22 changes: 22 additions & 0 deletions Config/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace ForzaDSX.Config
{
public class Config
{
public bool DisableAppCheck { get; set; }
public VerboseLevel VerboseLevel { get; set; } = VerboseLevel.Off;
public Dictionary<String, Profile> Profiles { get; set; } = new Dictionary<String, Profile>();
[JsonIgnore]
public Profile ActiveProfile { get; set; } = null;

public int DSXPort { get; set; } = 6900;

public String DefaultProfile { get; set; } = "Forza";
}
}
109 changes: 109 additions & 0 deletions Config/ConfigHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using ForzaDSX.GameParsers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ForzaDSX.Config
{
public class ConfigHandler
{
//Methods to read config file
//Method to initialize config file (Using default values), need to account for the different default profiles
//Method to write config file
//Singleton access to config data
private static readonly String configFilePath = "RacingDSX.json";
private static Config configData;

private static void InitializeConfig()
{
configData ??= ReadConfigFromDisk();
configData ??= new Config();
configData = AddDefaultProfiles(configData);
SaveConfig();
}




private static Config AddDefaultProfiles(Config config)
{
config.Profiles ??= new Dictionary<string, Profile>();
if (!config.Profiles.ContainsKey("Forza"))
{
Profile profile = new Profile
{
Name = "Forza",
gameUDPPort = 5300,
GameType = GameTypes.Forza,
};
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;
}

private static Config ReadConfigFromDisk()
{

try
{
if (!File.Exists(configFilePath)) {
return null;
}
string jsonString = File.ReadAllText(configFilePath);

Config config = JsonSerializer.Deserialize<Config>(jsonString);
return config;
}
catch (Exception)
{
return null;
}

}
private static void WriteConfigToDisk()
{
try
{
string jsonString = JsonSerializer.Serialize(configData);
File.WriteAllText(configFilePath, jsonString);
} catch (Exception)
{

}
}

public static void SaveConfig()
{
WriteConfigToDisk();

}

public static Config GetConfig()
{
if (configData == null)
{
InitializeConfig();
}
return configData;
}
}
}
22 changes: 22 additions & 0 deletions Config/Profile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using ForzaDSX.GameParsers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForzaDSX.Config
{
public class Profile
{
public GameTypes GameType { get; set; } = GameTypes.None;
public bool IsEnabled { get; set; } = true;
public string Name { get; set; }
public int gameUDPPort { get; set; }
public List<string> executableNames { get; set; } = new List<string>();
public ThrottleSettings throttleSettings { get; set; } = new ThrottleSettings();
public BrakeSettings brakeSettings { get; set; } = new BrakeSettings();

public float RPMRedlineRatio { get; set; } = 0.9f;
}
}
28 changes: 28 additions & 0 deletions Config/ThrottleSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForzaDSX.Config
{
public class ThrottleSettings
{
public TriggerMode TriggerMode { get; set; } = TriggerMode.Vibration;
public float GripLossValue { get; set; } = 0.2f;
public float EffectIntensity { get; set; } = 0.9f;
public float TurnAccelerationScale { get; set; } = 0.5f;
public float ForwardAccelerationScale { get; set; } = 1.0f;
public int AccelerationLimit { get; set; } = 10;
public int VibrationModeStart { get; set; } = 5;
public int MinVibration { get; set; } = 3;
public int MaxVibration { get; set; } = 35;
public float VibrationSmoothing { get; set; } = 0.5f;
public int MinStiffness { get; set; } = 200;
public int MaxStiffness { get; set; } = 75;
public int MinResistance { get; set; } = 1;
public int MaxResistance { get; set; } = 6;
public float ResistanceSmoothing { get; set; } = 0.01f;

}
}
15 changes: 15 additions & 0 deletions Config/TriggerMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForzaDSX.Config
{
public enum TriggerMode : sbyte
{
Off,
Resistance,
Vibration
}
}
15 changes: 15 additions & 0 deletions Config/VerboseLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ForzaDSX.Config
{
public enum VerboseLevel
{
Off = 0,
Limited,
Full
}
}
Loading

0 comments on commit 2c3b32f

Please sign in to comment.