### isTrackLoaded() — Session State Check Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Checks if rFactor 2 has started a session and a track is loaded. This is a prerequisite for reading scoring or telemetry data. ```APIDOC ## isTrackLoaded() — Session State Check ### Description Returns `True` when rF2 has started a session and a track is loaded, detected via the `mSessionStarted` flag in the Extended buffer. This is a prerequisite check before attempting to read meaningful scoring or telemetry data. ### Method Signature `isTrackLoaded()` ### Returns - `bool`: `True` if a track is loaded, `False` otherwise. ### Example Usage ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() if info.isRF2running() and info.isSharedMemoryAvailable(): if info.isTrackLoaded(): track = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mTrackName) session = info.Rf2Scor.mScoringInfo.mSession # session: 0=testday, 1-4=practice, 5-8=qualifying, 9=warmup, 10-13=race print(f"Track loaded: {track}, Session type: {session}") else: print("No track loaded (monitor/garage screen)") ``` ``` -------------------------------- ### Get Driver and Vehicle Names Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Reads the player's driver and vehicle names from the scoring buffer. Decodes them from C byte arrays to Python strings. ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() driver = info.driverName() # e.g. "Tony Whitley" vehicle = info.vehicleName() # e.g. "McLaren MP4/30" print(f"Driver: {driver}") print(f"Vehicle: {vehicle}") ``` -------------------------------- ### SimInfo - Low-Level Memory Map Constructor Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt The SimInfo class, located in `rF2data.py`, provides direct access to the raw ctypes structures for rFactor 2's telemetry, scoring, and extended shared memory buffers. It can be used for detailed, low-level data retrieval. ```APIDOC ## SimInfo — Low-Level Memory Map Constructor `SimInfo` (in `rF2data.py`) directly opens the three core memory-mapped files — Telemetry, Scoring, and Extended — and exposes them as ctypes structure instances. It is the base class for `SimInfoAPI` and can be used standalone for raw struct access. ```python import ctypes import mmap from rF2data import SimInfo, rF2Telemetry, rF2Scoring, rF2Extended info = SimInfo() # Direct access to raw ctypes structs num_vehicles = info.Rf2Tele.mNumVehicles print(f"Vehicles on track: {num_vehicles}") # Read first vehicle's engine RPM rpm = info.Rf2Tele.mVehicles[0].mEngineRPM print(f"Engine RPM (slot 0): {rpm:.1f}") # Read session elapsed time current_time = info.Rf2Scor.mScoringInfo.mCurrentET print(f"Session elapsed time: {current_time:.3f}s") info.close() ``` ``` -------------------------------- ### Initialize and Check rF2 Connection with SimInfoAPI Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Use SimInfoAPI to connect to rFactor 2's shared memory. It checks if the game is running and if the shared memory is compatible. Always close the connection to release resources. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() # Check rF2 is running and memory map is valid if info.isRF2running(): print("rFactor 2 process found") if info.isSharedMemoryAvailable(): version = Cbytestring2Python(info.Rf2Ext.mVersion) print(f"Shared memory version: {version}") # e.g. "3.6.0.0" else: print(info.versionCheckMsg) # Explains why verification failed else: print("rFactor 2 is not running") # Always close to release memory-mapped file handles info.close() ``` -------------------------------- ### Check if rF2 Session and Track are Loaded Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Use this to ensure rF2 is running and a track is loaded before accessing scoring or telemetry data. Requires `SimInfoAPI` and `Cbytestring2Python`. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() if info.isRF2running() and info.isSharedMemoryAvailable(): if info.isTrackLoaded(): track = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mTrackName) session = info.Rf2Scor.mScoringInfo.mSession # session: 0=testday, 1-4=practice, 5-8=qualifying, 9=warmup, 10-13=race print(f"Track loaded: {track}, Session type: {session}") else: print("No track loaded (monitor/garage screen)") ``` -------------------------------- ### SimInfoAPI - High-Level Access Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt The SimInfoAPI class provides a convenient way to interact with rFactor 2's shared memory. It handles process detection, version compatibility checks, and provides live access to telemetry, scoring, and extended state data. ```APIDOC ## SimInfoAPI — High-Level Access Class `SimInfoAPI` is the primary entry point for consuming rF2 shared memory. It inherits from `rF2data.SimInfo`, opens all memory-mapped buffers on construction, performs a version compatibility check, and locates the rFactor 2 process. All shared memory buffers (`Rf2Tele`, `Rf2Scor`, `Rf2Ext`) are available as attributes and are updated live as rF2 writes to them. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() # Check rF2 is running and memory map is valid if info.isRF2running(): print("rFactor 2 process found") if info.isSharedMemoryAvailable(): version = Cbytestring2Python(info.Rf2Ext.mVersion) print(f"Shared memory version: {version}") # e.g. "3.6.0.0" else: print(info.versionCheckMsg) # Explains why verification failed else: print("rFactor 2 is not running") # Always close to release memory-mapped file handles info.close() ``` ``` -------------------------------- ### isRF2running() - Process Detection Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt This method checks if the rFactor 2 process (`rfactor2.exe`) is currently running. It employs internal counters to optimize scan frequency, reducing overhead when the process is not detected or is actively running. ```APIDOC ## isRF2running() — Process Detection Checks whether the `rfactor2.exe` process is active. To avoid expensive process-list scans on every call, it uses two counters: `find_counter` (how often to scan when rF2 is not detected) and `found_counter` (how often to re-verify once it is found). Shared memory availability is also used as a fast shortcut. ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() # Default: scan every 200 calls when not found, every 5 calls once found running = info.isRF2running() # Custom polling frequency — scan every 100 calls, re-check every 10 running = info.isRF2running(find_counter=100, found_counter=10) if running: print(f"rF2 PID: {info.rf2_pid}") else: print("rFactor 2 is not running") ``` ``` -------------------------------- ### Access Raw Shared Memory Data with SimInfo Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Use the SimInfo class for direct access to low-level ctypes structs representing rFactor 2's telemetry, scoring, and extended data. This provides granular control over reading game state. ```python import ctypes import mmap from rF2data import SimInfo, rF2Telemetry, rF2Scoring, rF2Extended info = SimInfo() # Direct access to raw ctypes structs num_vehicles = info.Rf2Tele.mNumVehicles print(f"Vehicles on track: {num_vehicles}") # Read first vehicle's engine RPM rpm = info.Rf2Tele.mVehicles[0].mEngineRPM print(f"Engine RPM (slot 0): {rpm:.1f}") # Read session elapsed time current_time = info.Rf2Scor.mScoringInfo.mCurrentET print(f"Session elapsed time: {current_time:.3f}s") info.close() ``` -------------------------------- ### Check rFactor 2 Process Status with isRF2running() Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt The isRF2running() method checks if the 'rfactor2.exe' process is active. It uses internal counters to manage scan frequency, optimizing performance by avoiding constant process list checks. ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() # Default: scan every 200 calls when not found, every 5 calls once found running = info.isRF2running() # Custom polling frequency — scan every 100 calls, re-check every 10 running = info.isRF2running(find_counter=100, found_counter=10) if running: print(f"rF2 PID: {info.rf2_pid}") else: print("rFactor 2 is not running") ``` -------------------------------- ### isSharedMemoryAvailable() - Version Verification Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Verifies the compatibility of the rFactor 2 shared memory by reading the version from the Extended buffer. It ensures the version meets the minimum supported requirement (3.6.0.0) and that the 64-bit flag is set. ```APIDOC ## isSharedMemoryAvailable() — Version Verification Reads `mVersion` from the Extended shared memory buffer and verifies it meets the minimum supported version (`3.6.0.0`). Returns `True` only when the version string is present, correctly formatted, numerically sufficient, and the 64-bit flag is set. Sets `info.sharedMemoryVerified` as a side effect. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() if info.isSharedMemoryAvailable(): print("Memory map verified:", info.sharedMemoryVerified) # True print("Version:", Cbytestring2Python(info.Rf2Ext.mVersion)) else: # Message explains the failure reason print(info.versionCheckMsg) # Possible outputs: # "\nrFactor 2 Shared Memory not present. ..." # "Unsupported rFactor 2 Shared Memory version: 3.5.0.9 Minimum supported version is: 3.6.0.0 ..." # "Corrupt or leaked rFactor 2 Shared Memory ..." ``` ``` -------------------------------- ### driverName() / vehicleName() Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Convenience wrappers that read the player's driver name and vehicle name from the scoring buffer and decode them from C byte arrays to Python strings. ```APIDOC ## driverName() / vehicleName() ### Description Reads the player's driver name and vehicle name from the scoring buffer and decodes them from C byte arrays to Python strings. ### Method ```python info.driverName() info.vehicleName() ``` ### Parameters None ### Returns - `str`: The driver name or vehicle name. ### Example ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() driver = info.driverName() # e.g. "Tony Whitley" vehicle = info.vehicleName() # e.g. "McLaren MP4/30" print(f"Driver: {driver}") print(f"Vehicle: {vehicle}") ``` ``` -------------------------------- ### isAiDriving() — AI Control Detection Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Detects if the player's vehicle slot is under AI control. ```APIDOC ## isAiDriving() — AI Control Detection ### Description Returns `True` when the player's vehicle slot is under AI control (`mControl == 1`). Useful for pausing data recording or overlays when the AI takes over. ### Method Signature `isAiDriving()` ### Returns - `bool`: `True` if the AI is in control, `False` otherwise. ### Example Usage ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() if info.isOnTrack(): if info.isAiDriving(): print("AI is in control — skipping driver input logging") else: clutch = info.playersVehicleTelemetry().mUnfilteredClutch # 0.0–1.0 throttle = info.playersVehicleTelemetry().mUnfilteredThrottle brake = info.playersVehicleTelemetry().mUnfilteredBrake steering = info.playersVehicleTelemetry().mUnfilteredSteering # -1.0–1.0 print(f"Throttle: {throttle:.2f}, Brake: {brake:.2f}, " f"Clutch: {clutch:.2f}, Steer: {steering:.3f}") ``` ``` -------------------------------- ### Verify Shared Memory Version Compatibility Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt isSharedMemoryAvailable() reads the shared memory version and checks if it meets the minimum requirement (e.g., '3.6.0.0'). It returns True only if the version is valid, correctly formatted, and the 64-bit flag is set. Sets info.sharedMemoryVerified. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() if info.isSharedMemoryAvailable(): print("Memory map verified:", info.sharedMemoryVerified) # True print("Version:", Cbytestring2Python(info.Rf2Ext.mVersion)) else: # Message explains the failure reason print(info.versionCheckMsg) # Possible outputs: # "\nrFactor 2 Shared Memory not present. ..." # "Unsupported rFactor 2 Shared Memory version: 3.5.0.9 Minimum supported version is: 3.6.0.0 ..." # "Corrupt or leaked rFactor 2 Shared Memory ..." ``` -------------------------------- ### Access Player Vehicle Telemetry Data Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Retrieves real-time telemetry data for the player's vehicle, including position, velocity, wheel states, and engine data. Requires `SimInfoAPI` and `Cbytestring2Python`. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() tele = info.playersVehicleTelemetry() vehicle_name = Cbytestring2Python(tele.mVehicleName) fuel = tele.mFuel # litres remaining fuel_cap = tele.mFuelCapacity # litres total overheating = bool(tele.mOverheating) # Wheel data (FL, FR, RL, RR) for i, label in enumerate(['FL', 'FR', 'RL', 'RR']): w = tele.mWheels[i] # Tyre temperature: left/center/right readings in Kelvin → Celsius temps = [t - 273.15 for t in w.mTemperature] print(f"{label}: pressure={w.mPressure:.1f}kPa, " f"wear={w.mWear:.3f}, " f"temps={temps[0]:.1f}/{temps[1]:.1f}/{temps[2]:.1f}°C") print(f"{vehicle_name} | Fuel: {fuel:.2f}/{fuel_cap:.1f}L | Overheating: {overheating}") ``` -------------------------------- ### isOnTrack() — Realtime Driving State Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Determines if the player's car is actively on track in real-time, as opposed to viewing from the monitor. ```APIDOC ## isOnTrack() — Realtime Driving State ### Description Returns `True` when the player's car is actively on track in realtime (i.e., not viewing from the monitor). Reads `mInRealtimeFC` from the Extended buffer. Use this to gate telemetry reads that only make sense while driving. ### Method Signature `isOnTrack()` ### Returns - `bool`: `True` if the player is actively on track, `False` otherwise. ### Example Usage ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() if info.isTrackLoaded() and info.isOnTrack(): tele = info.playersVehicleTelemetry() gear = tele.mGear # -1=reverse, 0=neutral, 1+ = forward rpm = tele.mEngineRPM speed_ms = (tele.mLocalVel.x**2 + tele.mLocalVel.y**2 + tele.mLocalVel.z**2) ** 0.5 print(f"Gear: {gear}, RPM: {rpm:.0f}, Speed: {speed_ms * 3.6:.1f} km/h") else: print("Player is not currently driving on track") ``` ``` -------------------------------- ### Check if Player is Actively Driving On Track Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Verifies if the player is actively driving on track in real-time, not just spectating. Use this to gate telemetry reads that are only relevant while driving. Requires `SimInfoAPI`. ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() if info.isTrackLoaded() and info.isOnTrack(): tele = info.playersVehicleTelemetry() gear = tele.mGear # -1=reverse, 0=neutral, 1+ = forward rpm = tele.mEngineRPM speed_ms = (tele.mLocalVel.x**2 + tele.mLocalVel.y**2 + tele.mLocalVel.z**2) ** 0.5 print(f"Gear: {gear}, RPM: {rpm:.0f}, Speed: {speed_ms * 3.6:.1f} km/h") else: print("Player is not currently driving on track") ``` -------------------------------- ### playersVehicleTelemetry() — Per-Vehicle Telemetry Access Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Retrieves the real-time telemetry data for the player's vehicle. ```APIDOC ## playersVehicleTelemetry() — Per-Vehicle Telemetry Access ### Description Returns the `rF2VehicleTelemetry` ctypes struct for the player's vehicle, located by scanning `mIsPlayer` in the scoring buffer. The struct contains position, velocity, acceleration, orientation, all four wheel states, engine data, damage, and more — all updated in real time. ### Method Signature `playersVehicleTelemetry()` ### Returns - `rF2VehicleTelemetry`: A struct containing detailed real-time telemetry data for the player's vehicle. ### Example Usage ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() tele = info.playersVehicleTelemetry() vehicle_name = Cbytestring2Python(tele.mVehicleName) fuel = tele.mFuel # litres remaining fuel_cap = tele.mFuelCapacity # litres total overheating = bool(tele.mOverheating) # Wheel data (FL, FR, RL, RR) for i, label in enumerate(['FL', 'FR', 'RL', 'RR']): w = tele.mWheels[i] # Tyre temperature: left/center/right readings in Kelvin → Celsius temps = [t - 273.15 for t in w.mTemperature] print(f"{label}: pressure={w.mPressure:.1f}kPa, " f"wear={w.mWear:.3f}, " f"temps={temps[0]:.1f}/{temps[1]:.1f}/{temps[2]:.1f}°C") print(f"{vehicle_name} | Fuel: {fuel:.2f}/{fuel_cap:.1f}L | Overheating: {overheating}") ``` ``` -------------------------------- ### Cbytestring2Python() Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Standalone utility function that converts a ctypes byte array (C-style null-terminated string) to a Python `str`. Attempts UTF-8 first, falls back to Windows-1252, and finally uses UTF-8 with error ignoring. ```APIDOC ## Cbytestring2Python() ### Description Converts a ctypes byte array (C-style null-terminated string) to a Python `str`. It attempts UTF-8 decoding first, falls back to Windows-1252, and uses UTF-8 with error ignoring as a last resort. ### Method ```python Cbytestring2Python(byte_array) ``` ### Parameters - **byte_array** (ctypes.c_ubyte array): The C-style byte array to decode. ### Returns - `str`: The decoded Python string. ### Example ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() # Any ctypes ubyte array field can be decoded this way track = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mTrackName) player = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mPlayerName) server = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mServerName) version = Cbytestring2Python(info.Rf2Ext.mVersion) print(f"Track: {track}") # e.g. "Sebring International Raceway" print(f"Player: {player}") # e.g. "Driver Name" print(f"Server: {server}") # e.g. "" (empty in offline sessions) print(f"SM Version: {version}") # e.g. "3.6.0.0" ``` ``` -------------------------------- ### Direct Access to Raw Shared Memory Structs Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Provides direct access to rF2 shared memory structures using ctypes classes for lower-level operations or custom tool development. This allows access to data not exposed through the SimInfoAPI. ```python from rF2data import ( SimInfo, rF2Telemetry, rF2Scoring, rF2Extended, rF2Rules, rF2ForceFeedback, rF2Graphics, rF2GamePhase, rF2YellowFlagState, rF2PitState, ) info = SimInfo() # --- Extended: physics options, damage tracking, plugin state --- physics = info.Rf2Ext.mPhysics print(f"Traction control: {physics.mTractionControl}") # 0–3 print(f"ABS: {physics.mAntiLockBrakes}") # 0–2 print(f"Auto shift: {physics.mAutoShift}") # 0=off,1=up,2=down,3=all # --- Scoring: session-wide info --- si = info.Rf2Scor.mScoringInfo phase = rF2GamePhase(si.mGamePhase) print(f"Game phase: {phase.name}") # e.g. "GreenFlag" print(f"Ambient temp: {si.mAmbientTemp:.1f}°C") print(f"Track temp: {si.mTrackTemp:.1f}°C") print(f"Raining: {si.mRaining:.2f}") # 0.0–1.0 # --- Scoring: all vehicles in session --- for i in range(info.Rf2Scor.mScoringInfo.mNumVehicles): v = info.Rf2Scor.mVehicles[i] pit = rF2PitState(v.mPitState) print(f" P{v.mPlace}: slot={v.mID}, pit_state={pit.name}") info.close() ``` -------------------------------- ### Access Player Vehicle Scoring Data Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Fetches scoring data for the player's vehicle, such as lap times, position, and pit state. Useful for timing overlays or stint analysis. Requires `SimInfoAPI` and `Cbytestring2Python`. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() scor = info.playersVehicleScoring() driver = Cbytestring2Python(scor.mDriverName) place = scor.mPlace # 1-based race position total_laps = scor.mTotalLaps best_lap = scor.mBestLapTime # seconds last_lap = scor.mLastLapTime best_s1 = scor.mBestSector1 best_s2 = scor.mBestSector2 # cumulative S1+S2 penalties = scor.mNumPenalties pit_state = scor.mPitState # 0=none,1=request,2=entering,3=stopped,4=exiting print(f"Driver: {driver} | P{place} | Laps: {total_laps}") print(f"Best: {best_lap:.3f}s Last: {last_lap:.3f}s") print(f"Best S1: {best_s1:.3f}s Best S1+S2: {best_s2:.3f}s") print(f"Penalties: {penalties} | Pit state: {pit_state}") ``` -------------------------------- ### Raw Shared Memory Structs Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Direct access to all rF2 shared memory structures available as ctypes classes in `rF2data.py`. Useful for lower-level access or custom tools. ```APIDOC ## Raw Shared Memory Structs ### Description Provides direct access to all rF2 shared memory structures, exposed as ctypes classes in `rF2data.py`. This is useful for lower-level data access or when building custom tools that require data not directly exposed through `SimInfoAPI`. ### Usage Instantiate `SimInfo` to access the various shared memory structs. ### Example ```python from rF2data import ( SimInfo, rF2Telemetry, rF2Scoring, rF2Extended, rF2Rules, rF2ForceFeedback, rF2Graphics, rF2GamePhase, rF2YellowFlagState, rF2PitState ) info = SimInfo() # --- Extended: physics options, damage tracking, plugin state --- physics = info.Rf2Ext.mPhysics print(f"Traction control: {physics.mTractionControl}") # 0–3 print(f"ABS: {physics.mAntiLockBrakes}") # 0–2 print(f"Auto shift: {physics.mAutoShift}") # 0=off,1=up,2=down,3=all # --- Scoring: session-wide info --- si = info.Rf2Scor.mScoringInfo phase = rF2GamePhase(si.mGamePhase) print(f"Game phase: {phase.name}") # e.g. "GreenFlag" print(f"Ambient temp: {si.mAmbientTemp:.1f}°C") print(f"Track temp: {si.mTrackTemp:.1f}°C") print(f"Raining: {si.mRaining:.2f}") # 0.0–1.0 # --- Scoring: all vehicles in session --- for i in range(info.Rf2Scor.mScoringInfo.mNumVehicles): v = info.Rf2Scor.mVehicles[i] pit = rF2PitState(v.mPitState) print(f" P{v.mPlace}: slot={v.mID}, pit_state={pit.name}") info.close() ``` ``` -------------------------------- ### playersVehicleScoring() — Per-Vehicle Scoring Access Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Retrieves the scoring data for the player's vehicle, including lap times, position, and penalties. ```APIDOC ## playersVehicleScoring() — Per-Vehicle Scoring Access ### Description Returns the `rF2VehicleScoring` ctypes struct for the player's vehicle. Contains lap times, sector times, position, pit state, penalties, and flags — the key data for a timing overlay or stint analysis tool. ### Method Signature `playersVehicleScoring()` ### Returns - `rF2VehicleScoring`: A struct containing scoring data for the player's vehicle. ### Example Usage ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() scor = info.playersVehicleScoring() driver = Cbytestring2Python(scor.mDriverName) place = scor.mPlace # 1-based race position total_laps = scor.mTotalLaps best_lap = scor.mBestLapTime # seconds last_lap = scor.mLastLapTime best_s1 = scor.mBestSector1 best_s2 = scor.mBestSector2 # cumulative S1+S2 penalties = scor.mNumPenalties pit_state = scor.mPitState # 0=none,1=request,2=entering,3=stopped,4=exiting print(f"Driver: {driver} | P{place} | Laps: {total_laps}") print(f"Best: {best_lap:.3f}s Last: {last_lap:.3f}s") print(f"Best S1: {best_s1:.3f}s Best S1+S2: {best_s2:.3f}s") print(f"Penalties: {penalties} | Pit state: {pit_state}") ``` ``` -------------------------------- ### Convert C Byte Array to Python String Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Standalone utility function to convert a ctypes byte array (C-style null-terminated string) to a Python string. It attempts UTF-8 decoding first, falls back to Windows-1252, and finally uses UTF-8 with error ignoring. ```python from sharedMemoryAPI import SimInfoAPI, Cbytestring2Python info = SimInfoAPI() # Any ctypes ubyte array field can be decoded this way track = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mTrackName) player = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mPlayerName) server = Cbytestring2Python(info.Rf2Scor.mScoringInfo.mServerName) version = Cbytestring2Python(info.Rf2Ext.mVersion) print(f"Track: {track}") # e.g. "Sebring International Raceway" print(f"Player: {player}") # e.g. "Driver Name" print(f"Server: {server}") # e.g. "" (empty in offline sessions) print(f"SM Version: {version}") # e.g. "3.6.0.0" ``` -------------------------------- ### Detect if AI is Controlling the Player's Vehicle Source: https://context7.com/tonywhitley/pyrfactor2sharedmemory/llms.txt Determines if the player's vehicle is under AI control. Useful for pausing data logging or overlays when AI takes over. Requires `SimInfoAPI`. ```python from sharedMemoryAPI import SimInfoAPI info = SimInfoAPI() if info.isOnTrack(): if info.isAiDriving(): print("AI is in control — skipping driver input logging") else: clutch = info.playersVehicleTelemetry().mUnfilteredClutch # 0.0–1.0 throttle = info.playersVehicleTelemetry().mUnfilteredThrottle brake = info.playersVehicleTelemetry().mUnfilteredBrake steering = info.playersVehicleTelemetry().mUnfilteredSteering # -1.0–1.0 print(f"Throttle: {throttle:.2f}, Brake: {brake:.2f}, " f"Clutch: {clutch:.2f}, Steer: {steering:.3f}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.