Making a plugin survive driver swaps

cosimo

Registered
Hi,

I know some plugins do survive a driver swap, while others don't.
F.ex. my DeltaBest doesn't, but I don't know what is required to make a plugin work after a driver swap.
Any idea?

Any docs about it?
 
I think it's the same with my plugin(s), from a couple of reports I've seen over the years. Don't do driver swaps myself. I'm guessing there's a trigger missing that our plugins are looking for, but other plugins don't care about (enter realtime, or session start, or... something...)
 
My current theory is that "vinfo.mIsPlayer" is not enough if a driver swap takes place.
Now I'm testing my code with "vinfo.mIsPlayer || vinfo.mControl == 0" (where 0 = local player).
 
In the meantime, I've fixed the plugin to survive race restarts. That was easier than I thought.
I had set a main plugin on/off flag (in_realtime = true) only on EnterRealtime(). When race restarts, there's only a EndSession()/StartSession(), so I moved my flag initialization in StartSession(). All is well now.

Next step is to test the driver swap procedure, but I'm hopeful.
 
You could try my Monitor program from: https://github.com/TheIronWolfModding/rF2SharedMemoryMapPlugin
You need to build it because I am changing it actively.
It could give you an idea of what flag to use as a hint, just enable Light Mode and do driver swap while rf2 is windowed, see if there's anything you could depend on. Tried to upload screenshot so that you can see what it provides, but tinypic is down atm.... HTH
 
Last edited:
@The Iron Wolf Looking at the video again, I noticed that mInRealTime never returns true, what's going on there? I check if were in real time every update in my plugin and it shouldn't work if it didn't return true so this makes me confused.
 
IIRC, mInRealTime is in Garage/Monitor vs when you're driving. I can have a look when I get a chance, but it'll have to be next week.

EDIT: Actually, I checked plugin code, and there might be a bug here. I am using member variable mInRealtime in plugin, and set it with rF2 calls ExitRealtime/EnterRealtime. However, ScoringInfoV01 also has mInRealtime, so I need to investigate what is correct value to use here. Thanks for bringing that to my attention.

EDIT2: I think I finally got what you're saying. See implementation of myplugin, it might help:)
 
Last edited:
EDIT: Actually, I checked plugin code, and there might be a bug here. I am using member variable mInRealtime in plugin, and set it with rF2 calls ExitRealtime/EnterRealtime. However, ScoringInfoV01 also has mInRealtime, so I need to investigate what is correct value to use here. Thanks for bringing that to my attention.
When I tested this a few months ago, EnterRealtime was not called when taking over via a driver swap.
 
Last time i tested it, 10 days ago, DeltaBest survived. @cosimo must have the answer.

PedalOverlay is one plugin that i'm waiting to work with driver swap.
 
here are lines from cosimo's code https://github.com/cosimo/rFactor2-DeltaBest/blob/master/Source/DeltaBest.cpp:

Code:
for (long i = 0; i < info.mNumVehicles; ++i) {
243         VehicleScoringInfoV01 &vinfo = info.mVehicle[i];
244
 
245         /* If a swap happened, we are not the (original session) player, but we are now in control */
246         /* This is just my current theory atm, not sure it's true */
247         bool is_local_player = vinfo.mControl == 0;
248         if (! (vinfo.mIsPlayer || is_local_player))
249             continue;
250

Honestly, I am not clear what is meant by "plugin doesn't survive driver swap"? Does that mean after swap we can't tell which vehicle is player? I would guess there might be combination of flags/values that can be used to guess needed information. My Monitor program only visualizes what I needed so far, but feel free to extend it to show more information, because right now it doesn't show a lot of things available.
 
here are lines from cosimo's code https://github.com/cosimo/rFactor2-DeltaBest/blob/master/Source/DeltaBest.cpp:

Code:
for (long i = 0; i < info.mNumVehicles; ++i) {
243         VehicleScoringInfoV01 &vinfo = info.mVehicle[i];
244
 
245         /* If a swap happened, we are not the (original session) player, but we are now in control */
246         /* This is just my current theory atm, not sure it's true */
247         bool is_local_player = vinfo.mControl == 0;
248         if (! (vinfo.mIsPlayer || is_local_player))
249             continue;
250

Honestly, I am not clear what is meant by "plugin doesn't survive driver swap"? Does that mean after swap we can't tell which vehicle is player? I would guess there might be combination of flags/values that can be used to guess needed information. My Monitor program only visualizes what I needed so far, but feel free to extend it to show more information, because right now it doesn't show a lot of things available.

In order to do driver swaps in an online race you have to connect to the running session as spectator. Once the car you choose to take over drives into the pit you can preform the driver swap.

The problem at the moment is that most plugins just wont load when joining a session as spectator, or if they do load they do not show up at all.
Trackmap is the only plugin that does not have problems with this.
 
EDIT2: I think I finally got what you're saying. See implementation of myplugin, it might help:)

I took the same approach, controlling realtime status via EnterRealtime and ExitRealtime.

I check if were in real time every update in my plugin and it shouldn't work if it didn't return true so this makes me confused.

So assuming you're checking for realtime via ScoringInfoV01.mInRealtime, it should suffice to maintain a current realtime status and check against it; when the state changes either way, run the Enter/Exit code, and everything should be dandy. Might give that a go then.
 
Back
Top