[REL] rF2 Shared Memory Tools for Developers

Discussion in 'Other' started by The Iron Wolf, Jan 19, 2017.

  1. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Version 2 of a plugin is out. See the first page.

    This is a complete rework/redesign of a plugin. Essentially, it is straight double buffered memcpy of rF2 internals read model now.
    As some of you know this work started as a rework of rF1 plugin. However, as I learned rF2 more I realized that rF1 plugin roots were making it difficult to expose rF2 internals completely. Namely, rF1 plugin had Telemetry and Scoring in a single buffer.

    New plugin removes that limitation, and now operates at full rF2 speed and precision. Each of the exposed structures is given independent pair of buffers. Interpolation isn't necessary anymore, because game reports accurate positions at 50FPS.
     
    Last edited: Jul 22, 2017
  2. DaVeX

    DaVeX Registered

    Joined:
    Feb 7, 2015
    Messages:
    637
    Likes Received:
    701
    Can we download and use it with CC?
     
  3. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    CC already comes with the newest version and always will. This is for people who want to build something based on this.
     
  4. k3nny

    k3nny Registered

    Joined:
    Jan 20, 2013
    Messages:
    84
    Likes Received:
    2
    Hi,

    thanks for the new version, my display programm is ported. But one advise I can give you to make it easier for people like me that have no experience how you filled the mmap and in which order. Make only a little table with the order and which type and lenght and that helps all to find out what they find in which position. I need some time with try and error to find out why some position are not there where I expected.

    But nothing at all thanks mate.
     
  5. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Kenny,
    I am glad it works for you. Could you please elaborate on your suggestion?

    Generally, I intentionally don't do anything extra in the plugin - remember, my goal is minimum CPU impact on the game thread. I do agree with you this version is more complicated, especially the part of performing partial data read (it is much faster) and mapping of mIDs to indices in arrays. But, I hope you found use examples in the Monitor app.
     
  6. k3nny

    k3nny Registered

    Joined:
    Jan 20, 2013
    Messages:
    84
    Likes Received:
    2
    Hi Iron Wolf,

    what I mean is that I have Problems with the start of the files, with which data it begins, because without knowing how you contruct the mmap file it is hard to see what you placed at which point. Followed my example of a list with the infos I mean, that would be helpful without opening your project and check the rf2state file and then you not know what put in front of the first rf2 value.

    rf2vehicletelemetry without wheels:
    ('mCurrentRead', c_bool),
    ('mVersion', c_char*8),
    ('mID', c_long),
    ('mDeltaTime', c_double),
    ('mElapsedTime', c_double),
    ('mLapNumber', c_long),
    ('mLapStartET', c_double),
    ('mVehicleName', c_char *64),
    ('mTrackName', c_char *64),
    ('mPos', c_double*3),
    ('mLocalVel', c_double*3),
    ('mLocalAccel', c_double*3),
    ('mOri', c_double*9),
    ('mLocalRot', c_double*3),
    ('mLocalRotAccel', c_double*3),
    ('mGear', c_long),
    ('mEngineRPM', c_double),
    ('mEngineWaterTemp', c_double),
    ('mEngineOilTemp', c_double),
    ('mClutchRPM', c_double),
    ('mUnfilteredThrottle', c_double),
    ('mUnfilteredBrake', c_double),
    ('mUnfilteredSteering', c_double),
    ('mUnfilteredClutch', c_double),
    ('mFilteredThrottle', c_double),
    ('mFilteredBrake', c_double),
    ('mFilteredSteering', c_double),
    ('mFilteredClutch', c_double),
    ('mSteeringShaftTorque', c_double),
    ('mFront3rdDeflection', c_double),
    ('mRear3rdDeflection', c_double),
    ('mFrontWingHeight', c_double),
    ('mFrontRideHeight', c_double),
    ('mRearRideHeight', c_double),
    ('mDrag', c_double),
    ('mFrontDownforce', c_double),
    ('mRearDownforce', c_double),
    ('mFuel', c_double),
    ('mEngineMaxRPM', c_double),
    ('mScheduledStops', c_ubyte),
    ('mOverheating', c_bool),
    ('mDetached', c_bool),
    ('mHeadlights', c_bool),
    ('mDentSeverity', c_ubyte * 8),
    ('mLastImpactET', c_double),
    ('mLastImpactMagnitude', c_double),
    ('mLastImpactPos', c_double*3),
    ('mEngineTorque', c_double),
    ('mCurrentSector', c_long),
    ('mSpeedLimiter', c_ubyte),
    ('mMaxGears', c_ubyte),
    ('mFrontTireCompoundIndex', c_ubyte),
    ('mRearTireCompoundIndex', c_ubyte),
    ('mFuelCapacity', c_double),
    ('mFrontFlapActivated', c_ubyte),
    ('mRearFlapActivated', c_ubyte),
    ('mRearFlapLegalStatus', c_ubyte),
    ('mIgnitionStarter', c_ubyte),
    ('mFrontTireCompoundName', c_char*18),
    ('mRearTireCompoundName', c_char*18),
    ('mSpeedLimiterAvailable', c_ubyte),
    ('mAntiStallActivated', c_ubyte),
    ('mUnused', c_ubyte*2),
    ('mVisualSteeringWheelRange', c_float),
    ('mRearBrakeBias', c_double),
    ('mTurboBoostPressure', c_double),
    ('mPhysicsToGraphicsOffset', c_float*3),
    ('mPhysicalSteeringWheelRange', c_float),
    ('mExpansionTelem', c_ubyte*152)

    But I have problem now, everytime I start my tool first and start then rf2, the plugin write to the debug log this message "Failed to map file 1" and crash after loading the track, that was not with the previous version. I found out that I have to wait until rf2 is open that I can start my tool. Is there a way to have the behavior of the previous version, because I have not found a solution to prevent this with python?
     
  7. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    K
    Kenny,
    This VehicleTelemetry structure does not match rF2VehicleTelemetry structure from sample app (my structure doesn't have mVersion). If you're trying to expand rF2Telemetry, note expansion is not correct in such case either. The best way to make sure mapping is exactly correct is to take C# struct and adapt it for your uses. I understand that using this is a bit tricky, but the goal of this plugin is to do minimal work and expose rF2 internals 1:1 (except for pointer types), I can't simplify it (because that means i'll need to do more work on the game thread). Note that layout is different from V1, quite significantly. Also, pack is 4 bytes now. I do not want to sound bad - but this is low-levelish stuff, and it is by nature not straightforward :(

    The mapping of files between V1 and V2 has not changed (at least I can't think of how it is different). I will add more detailed report to get the exact Win32 error code (thanks for pointing this problem out, seems like my error handling is not verbose enough). My guess what is happening is mapping fails because file already exists. I am not familiar with Python, but my guess - make sure you are passing right flags to open API, namely, not to create file if it doesn't exist. Most open APIs default to create if not found.

    Could you please paste me my plugin debug output? And lastly, are you saying rF2 crashes in this case? Thanks!
     
    Last edited: Jul 30, 2017
  8. k3nny

    k3nny Registered

    Joined:
    Jan 20, 2013
    Messages:
    84
    Likes Received:
    2
    Now I´m confused when you said you have not change the content of the file. One example in v2 mSpeed doesn't exist anymore. The names are placeholder before mId, this content for example I mean I was not able to find them in your project to verify what it is, so I use this. But
    nevertheless it works for me in this way.

    I followed the supposition that my tool create the file before rf2 does it. I have change the procedure and so that I wait 15 sec. after finding the PID of rf2 and then check the file and it works.
    Attached the debug when
     

    Attached Files:

  9. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    v2 structures are quite different - v1 was telemetry/scoring jammed together. V2 is pretty much mirror of what rF2 sends, and it is different. Clients need to calculate mSpeed etc outside of plugin. Biggest difference, however, you will have to use Scoring buf er to figure out mID of player's vehicle and find its telemetry in telemetry buffer, and be prepared that there might be nothing there.

    Monitor app does all that. Thanks for finding a crash, I'll fix it :)
     
  10. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Crash itself is fixed in V2.1.0.1 but I will improve error logging and try to delete existing shared memory view before failing to operate, thanks again man :)
     
  11. k3nny

    k3nny Registered

    Joined:
    Jan 20, 2013
    Messages:
    84
    Likes Received:
    2
    Hi,

    I´ve notice when I´m in multiplayer that you change the telemetry output to all cars that are on track, thats for me tool very bad because I now see note my telemetry. It is possible for me to configure it back to the configuration that only the player car telemetry data will be send or that the player telemetry is everytime the first data in the file? Because for me it´s massive more code to find the telemetry data of my car.
    Thanks for your help.
     
    Last edited: Aug 5, 2017
  12. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Kenny, since you are using this for private data display IIRC, why don't you just stick with V1 of a plugin? I kept it in V1 svc branch. I will think about adding player telemetry option, but I can't promise I'll do it nor say when that will happen. It will be a nice feature for sure.

    In case you're not aware, Monitor app figures out which car is player, but I understand what you're saying - if you're not reading Scoring buffers, it's some work.
     
  13. k3nny

    k3nny Registered

    Joined:
    Jan 20, 2013
    Messages:
    84
    Likes Received:
    2
    That is not the problem that I can´t find out what my car is, but it blow up my code because I have to check every scoring information from each car on track if mIsPlayer is true. And then not to forget the massive code of the telemetry variables.
    You reduce the cpu usage, but I have to increase it ;):(.

    But Ok, then I have to go back to V1 and have to wait, I hope you think about it.

    Regards.
     
  14. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    New version is out.

    9/01/2017 - v2.1.1.1

    Plugin:

    • Fix crash in physics update that happens when buffer can't be mapped.
    • Expose TrackRules01 as rF2Rules buffer.
    • Improve Win32 error tracing.
    • Minor reliability improvements.
    Monitor:

    • Add rF2Rules tracking.
    • Force invariant culture on the app.
     
    Magus likes this.
  15. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    New version's out:
    10/04/2017 - v2.2.1.0
    Plugin:
    • Expose rF2MultiRules buffer
    • Expose rF2TrackRulesAction on rF2Rules
    • Add rF2SessionTransitionCapture to rF2Extended. This allows tracking some state on session transition.
    • Add mSessionStarted, mTicksSessionStarted and mTicksSessionStarted to rF2Extended to help tracking session transitions.
    • Buffers are no longer cleared out on EndSession. This is neccessary to capture data in StartSession.
    Monitor:
    • Add Frozen Order rules detection.
     
    Ernie likes this.
  16. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    new version's out:

    01/02/2018 - v2.3.1.2

    Plugin:

    • Allow hosting of StockCarRules.dll plugin. Capture mMessage members filled out by SCR plugin and pass them out via SM.
    • Remove .ini file config and move to standard rF2 plugin config via CustomPluginVariables.json.
    Monitor:

    • Minor fixes and changes to support SCR plugin hosting feature.
     
    Corti likes this.
  17. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    Version 3 of tools is out.
    I finally got to do what I wanted to for a while - remove mutexes. Now, plugin is truly reusable, universal and can be used by as many tools as needed without any impact on the rF2 plugin thread.

    For the future, I am also considering adding write capability, where clients could write into shared memory and plugin would apply those changes using rF2 plugin model. However, as Crew Chief does not currently need this, there is no immediate need to do this. But if you're working on a tool that applies weather, sets messages etc, let me know if adding write model is something you'd like to happen. No promises, but given enough interest I might do it, I have an idea how to make that happen efficiently.
     
    bravotangosix and Corti like this.
  18. Will Mazeo

    Will Mazeo Registered

    Joined:
    Sep 12, 2015
    Messages:
    2,220
    Likes Received:
    1,578
    hmm can you do a pit window plugin with that?
     
  19. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    02/21/2018 - v3.0.0.1

    Hotfix for physics options not being captured.
     
    bravotangosix likes this.
  20. Nibo

    Nibo Registered

    Joined:
    Oct 12, 2010
    Messages:
    2,251
    Likes Received:
    965
    Is there a way to know that some rF2Scoring.vehicels array position is actually a leftover after some position before it was removed from server? Because I see now if I boot some AI from server the one after it in rF2Scoring.vehicels array jumps in upper position, but leaves copy of its data in old position. So now I have 2 same drivers in that array and no way to tell which one is live and which one is old data leftover?

    UPD. Sorry was not thinking straight. The answer appears to be sort by position and show only mNumVehicles drivers.
     
    Last edited: Mar 13, 2018

Share This Page