Making a plugin survive driver swaps

Discussion in 'Plugins' started by cosimo, Oct 6, 2015.

  1. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    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?
     
  2. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    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...)
     
  3. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    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).
     
  4. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    That would make sense :)

    I hope you are able to confirm the reason for this.
     
  5. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    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.
     
    Ernie likes this.
  6. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Still no luck making this work.
     
  7. Martin Vindis

    Martin Vindis Registered

    Joined:
    Apr 15, 2014
    Messages:
    146
    Likes Received:
    98
    Still nothing cosimo?
     
  8. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Got in touch with Marcel Offermanns about it. We are trying to fix the problem.
     
  9. Martin Vindis

    Martin Vindis Registered

    Joined:
    Apr 15, 2014
    Messages:
    146
    Likes Received:
    98
    I'm still fighting this, anyone figured it our yet?
     
  10. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    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: Feb 7, 2017
    Jego and Martin Vindis like this.
  11. Martin Vindis

    Martin Vindis Registered

    Joined:
    Apr 15, 2014
    Messages:
    146
    Likes Received:
    98
    Thanks Wolf!
    This is it, all you have to check for is mIsPlayer.
    Here is a video
     
  12. Martin Vindis

    Martin Vindis Registered

    Joined:
    Apr 15, 2014
    Messages:
    146
    Likes Received:
    98
    @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.
     
    The Iron Wolf likes this.
  13. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    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: Feb 20, 2017
  14. Josh.H

    Josh.H Registered

    Joined:
    Dec 19, 2013
    Messages:
    45
    Likes Received:
    9
    When I tested this a few months ago, EnterRealtime was not called when taking over via a driver swap.
     
  15. ebeninca

    ebeninca Registered

    Joined:
    Sep 7, 2016
    Messages:
    740
    Likes Received:
    526
    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.
     
  16. The Iron Wolf

    The Iron Wolf Registered

    Joined:
    Feb 20, 2016
    Messages:
    984
    Likes Received:
    984
    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.
     
  17. jerrymcc

    jerrymcc Registered

    Joined:
    Oct 5, 2010
    Messages:
    160
    Likes Received:
    35
    He means the plugin doesn't work after the driver swap. Probably just disappears from the screen.
     
  18. Jego

    Jego Registered

    Joined:
    Feb 18, 2016
    Messages:
    147
    Likes Received:
    55
    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.
     
  19. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    For my DAMPlugin, those are two things that would both stop it working if correct.
     
  20. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,382
    Likes Received:
    6,600
    I took the same approach, controlling realtime status via EnterRealtime and ExitRealtime.

    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.
     
    WiZPER and The Iron Wolf like this.

Share This Page