Skip to content

Commit

Permalink
Support for multiple Game Types. Support for DiRT 1/2.
Browse files Browse the repository at this point in the history
  • Loading branch information
patmagauran committed Dec 27, 2023
1 parent b9ffe2f commit 0e8a803
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 71 deletions.
Binary file modified .vs/ForzaDSX/v17/.suo
Binary file not shown.
20 changes: 14 additions & 6 deletions AppCheckThread.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,36 @@ 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;
}
}

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;
Expand Down
12 changes: 12 additions & 0 deletions Config/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
53 changes: 13 additions & 40 deletions ForzaDSXWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down
59 changes: 59 additions & 0 deletions GameParsers/DirtParser.cs
Original file line number Diff line number Diff line change
@@ -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);
}

}
}
30 changes: 30 additions & 0 deletions GameParsers/NullParser.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
56 changes: 42 additions & 14 deletions UI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0e8a803

Please sign in to comment.