Building rFactor plugins with Python using rFactor2Python

Thu 22 November 2012 // posts

rFactor2Python is a plugin for rFactor that forwards plugin calls to Python scripts, passing game data as well, making the task of programming rFactor plugins much easier, specially useful for prototyping, since Python is loaded with tons of useful modules ready to use.

Some of the features and possibilities are:

  • You don't have to know C++
  • You don't have to compile anything
  • Most of the rFactor Internals Plugin methods are exposed to Python!
  • Python provides huge functionality with little work and has high quality documentation
  • Multiple python plugins supported.

For example, you can easily:

  • Save players timings to a database
  • Create a webpage with live server status
  • Send an email with results, timings, etc, when a race ends
  • Interact with an Arduino

Changelog:

20110927 (experimental)

  • new: Python threading is now possible (finally...but needs further testing) download

20110606 (experimental)

  • new: Multiple plugins support! Place Python plugins inside rf2py_plugins/.
  • new: Plugins are classes now! See rfactor.py.
  • update: small updates here and there...

20110523

  • new: CheckHWControl implemented.
  • update: examples updated with CheckHWControl.

20110521

  • update: fixed a crash when calling xdecref on loaded module
  • update: print python version to log file
  • new: mysqldb example. rfactor-mysqldb.sql contains the database structure
  • new: test-score.py script. Very useful to simulate score updates and test
    rFactor2Python scripts.
  • new: rfactor-frames.py example. The output of this script can be used by
    test-score.py. Example output: rfactor2python.frames.txt.tar.gz

20110516

  • update: mLapDist field was missing. Added.

20110510

  • Examples directory added
  • Two examples added: log and serial
  • rfactor.py functions are empty now. A brief description, from original headers, was
    added at the top of every function.

20110509

  • Telemetry updates! New function available: UpdateTelemetry. (check rfactor.py)
  • Python exceptions tracebacks are now printed to log file. This helps debugging rfactor.py.

20110508

  • Initial release

Requirements:

  • Python (correct version) is the only requirement

Documentation:

  • rfactor.py is self explanatory.
  • rfactor2python_examples/ directory contains multiple plugin examples
  • All attributes and functions have the same name as in Internals Plugin SDK (download from official rFactor site)

Installation:

  1. Extract plugin zip file into rfactor root directory.
  2. Read rfactor.py.
  3. Place plugins inside rf2py_plugins/.

Problems:

  • If you have any issues, check rfactor2python.log file. Python exceptions are logged to this file.

social