-
Notifications
You must be signed in to change notification settings - Fork 0
/
save.py
executable file
·30 lines (25 loc) · 1.15 KB
/
save.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/env python
"""Reads telemetry data from Forza Horizon 4 and saves it into a .csv file"""
from argparse import ArgumentParser
from csv import writer
from socket import AF_INET, SOCK_DGRAM, socket
from struct import unpack
FORMAT = "<iI27f4i20f5i12x17fH6B3bx"
parser = ArgumentParser(description=__doc__)
parser.add_argument("--file", default="data.csv", help="output .csv filepath (extension not added automatically)")
parser.add_argument("--address", default="localhost", help="DATA OUT ADDRESS (IPv4 or hostname, defaults to localhost) (useful if Forza is running on another machine)")
parser.add_argument("--port", default=0, help="DATA OUT PORT (defaults to any available UDP port)", type=int)
args = parser.parse_args()
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind((args.address, args.port))
try:
with open(args.file, "x") as f:
csv = writer(f)
print("Go to menu options -> HUD and gameplay")
print("DATA OUT = ON")
print(f"DATA OUT ADDRESS = {sock.getsockname()[0]}")
print(f"DATA OUT PORT = {sock.getsockname()[1]}")
print()
print("Press Ctrl+c to exit")
while True: csv.writerow(unpack(FORMAT, sock.recv(324)))
except KeyboardInterrupt: pass