Skip to content

Commit 59a5302

Browse files
committed
Implemented Car Type
1 parent a163b13 commit 59a5302

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

opengsq/protocols/flatout2.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ class Flatout2(ProtocolBase):
2525
COMMAND_QUERY = b"\x18\x0c"
2626
PACKET_END = b"\x2e\x55\x19\xb4\xe1\x4f\x81\x4a"
2727

28+
# Car Type Identifiers (byte at position -8 from end)
29+
CAR_TYPE_IDENTIFIERS = {
30+
0x08: "Jeder", # Alle Wagentypen erlaubt
31+
0x18: "Derby", # Derby-Wagen
32+
0x28: "Rennen", # Rennwagen
33+
0x38: "Strasse", # Straßenwagen
34+
0xE8: "Wie Host", # Wagentyp wie Host-Einstellung
35+
}
36+
2837
# Game Mode Identifiers (byte at position -7 from end)
2938
GAME_MODE_IDENTIFIERS = {
3039
0x61: "Race", # Rennen
@@ -218,6 +227,24 @@ def _read_utf16_string(self, br: BinaryReader) -> str:
218227

219228
return bytes(bytes_list).decode('utf-16-le').strip()
220229

230+
def _extract_car_type(self, data: bytes) -> str:
231+
"""
232+
Extracts the car type from the payload data.
233+
Car type identifier is located at offset -8 (8 bytes from end).
234+
235+
:param data: The complete response data
236+
:return: The car type name or "Unknown" if not found
237+
"""
238+
try:
239+
if len(data) >= 8:
240+
car_type_id = data[-8] # 8 bytes from end
241+
return self.CAR_TYPE_IDENTIFIERS.get(car_type_id, f"Unknown (0x{car_type_id:02X})")
242+
else:
243+
return "Unknown"
244+
except Exception as e:
245+
print(f"Error extracting car type: {e}")
246+
return "Unknown"
247+
221248
def _extract_game_mode(self, data: bytes) -> str:
222249
"""
223250
Extracts the game mode from the payload data.
@@ -344,6 +371,11 @@ def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
344371
server_name = self._read_utf16_string(br)
345372
info["hostname"] = server_name
346373

374+
# Extract car type from the payload
375+
# Car type identifier at offset -8
376+
car_type = self._extract_car_type(original_data)
377+
info["car_type"] = car_type
378+
347379
# Extract game mode from the payload
348380
# Game mode identifier at offset -7
349381
game_mode = self._extract_game_mode(original_data)
@@ -416,6 +448,7 @@ def _parse_response(self, br: BinaryReader, original_data: bytes) -> Status:
416448
print(f"Error parsing response: {e}")
417449
# Set defaults on error
418450
info.setdefault("hostname", "Unknown Server")
451+
info.setdefault("car_type", "Unknown")
419452
info.setdefault("game_mode", "Unknown")
420453
info.setdefault("map", "Unknown Map")
421454
info.setdefault("lap_count", None)

0 commit comments

Comments
 (0)