Skip to content

Commit

Permalink
add motorsport support
Browse files Browse the repository at this point in the history
Adjust parse and API data to allow for Forza Motorsport 7/8 UDP streams.
  • Loading branch information
dusanders committed Dec 6, 2023
1 parent 950a075 commit 737c47f
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 79 deletions.
8 changes: 4 additions & 4 deletions src/ForzaInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public interface ForzaInterface {
default Thread startConnection(int port) {
return new Thread(() -> {
try (DatagramSocket datagramSocket = new DatagramSocket(port)) {
//Only 323 bytes are received from the Forza UDP stream
byte[] receive = new byte[323];
// Allocate the largest expected bytes - FM8
byte[] receive = new byte[ForzaTelemetryApi.FM8_PACKET_LENGTH];
DatagramPacket datagramPacket = new DatagramPacket(receive, receive.length);
int lastOrdinal = 0;
boolean isPaused = false, isConnected = false;
while (true) {
try {
datagramSocket.receive(datagramPacket);
if (!isConnected) {
ForzaTelemetryApi tempApi = new ForzaTelemetryApi(datagramPacket.getData());
ForzaTelemetryApi tempApi = new ForzaTelemetryApi(datagramPacket.getLength(), datagramPacket.getData());
if (tempApi.getTimeStampMS() != 0) {
lastOrdinal = tempApi.getOrdinal();
//Set ForzaApi to null if game is paused, as all values will return 0
Expand All @@ -32,7 +32,7 @@ default Thread startConnection(int port) {
//Send data to the ForzaApi parsing class
try {
byte[] data = datagramPacket.getData();
ForzaTelemetryApi api = new ForzaTelemetryApi(data);
ForzaTelemetryApi api = new ForzaTelemetryApi(datagramPacket.getLength(),data);
//Call onGamePaused when isRaceOn is false, call onGameUnpaused when true while game is paused
if(!api.getIsRaceOn() && !isPaused){
onGamePaused();
Expand Down
Loading

0 comments on commit 737c47f

Please sign in to comment.