SOLVED How-To: Use VisualStudio Debugger to debug code of PlugIns

Discussion in 'Plugins' started by MerlinC, Aug 22, 2014.

  1. MerlinC

    MerlinC Registered

    Joined:
    Nov 3, 2012
    Messages:
    282
    Likes Received:
    3
    Because I did not find any information in regard settings to be used to debug an rF2 plugin with VisualStudio I was conserned that this is, like in rFactor1, not possible as well.

    The good news is that you can use the debugger of VisualStudio to develop rF2 PlugIns. I used "VisualStudio Express 2010" (German) to do the settings - but had to upgrade to "VisualStudio Express 2013" change the language. To verify the installation I just used the InternalPlugIn Demo from the DevCorner of rF2.

    Here is my brief description on how to get the debugger running.

    Assuming VisualStudio is installed on your computer you need to execute the following steps:

    (1) Download and unpack the InternalPlug-Demo from the rF2 website (http://downloads.imagespaceinc.com/rf2/plugin/InternalsPlugin6.zip) in a separate directory (do not recommend to unpack in rFactor directories).

    (2) Start VisualStudio and open the Microsoft visual studio solution file named "InternalsPlugIn" which is located in the Win32 sub-directory.

    (3) Visual Studio will convert the format to the current format.

    (3) Afterwards open the project setting by doing a right-click on the project and select "Properties"

    View attachment 14028

    (4) Change Configuration Properties for General and Debugging.

    View attachment 14029

    View attachment 14030

    Steps you have to do every time you start debugging:

    (4) Compile and start debugger. When the rFactor_Launcher has started, start rFactor as you normaly do (I recommend windowed mode).

    (5) After rFactor has started go in VisualStudio to the menu "Debug/Attach to Process". And Attach the rFactor2 Exe.

    View attachment 14031

    If you set some breakpoints (and did everything right) rF2 should stop execution and you are able to go step-by-step through your code, watch variables, etc. Just like you excpect it if you ever have developed software within an IDE. If rF2 does not stop execution and VC seems to ignore breakpoints you very likely missed to do Step 5 ;-)

    I assume that the profiler will run as well but did not test so far.

    If there any questions, this information was helping or was unclear in same areas please let me know by just posting into this thread.
     
    Last edited by a moderator: Aug 23, 2014
  2. Mee

    Mee Registered

    Joined:
    Oct 4, 2010
    Messages:
    154
    Likes Received:
    13
    Attaching it to a dedicated server process running on another computer is a bridge too far I suppose? :)
     
  3. MerlinC

    MerlinC Registered

    Joined:
    Nov 3, 2012
    Messages:
    282
    Likes Received:
    3
    Well i never did test but there is one debugger called remote debugger which allows to debug processes on another machine.

    On the other hand I don't see that you really will debug code when others are connected. Thus you could run the dedicated server and the rFactor client on your local computer.


    Sent with Tapatalk
     
  4. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    35
    Hello

    MerlinC, did you or someone could provide a simple project in Visual Studio, starting from InternalsPlugin6, showing a form getting real-time information (car speed for example) and a button to do some action within the game (change the camera for example)?

    That would be very important for those who want to start developing, may have an idea how to start.

    Thank you
     
  5. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    Most of what you are requesting is already demonstrated in the sample plugin right from ISI. Camera changing isn't though.

    Here is some sample code for changing cameras:
    Code:
    bool ExampleInternalsPlugin::WantsToViewVehicle( CameraControlInfoV01 &camControl )
    {
    	// 0 = TV cockpit
    	// 1 = cockpit
    	// 2 = nosecam
    	// 3 = swingman
    	// 4 = trackside (nearest)
    	// 5 = onboard000
    	// :
    	// :
    	// 1004 = onboard999
    	// 1005+ = (currently unsupported, in the future may be able to set/get specific trackside camera)
    
    	camControl.mCameraType = 4;
    	camControl.mID = 0;
    	return(true);
    }
    
    In this sample it would select the trackside camera and focus on the driver that is in slot 0. UpdateScoring will give you the slot ID for all the drivers. Also, if you simply want to see what camera and driver is currently selected, you can find that in camControl... just be sure to return a false if you're not planning to change the camera.
     
  6. Lazza

    Lazza Registered

    Joined:
    Oct 5, 2010
    Messages:
    12,610
    Likes Received:
    6,759
    To be honest, if someone wants to develop plugins they need to get a basic understanding of C++ first, and then understand how the pieces of the plugin fit together - and like a few of the ISI game data files (cars and tracks) there are comments on just about every line which make it very possible to see how things work, and how to do something.

    Providing examples of how to do A and B may help the copy-paste 'programmers' do something very similar, but as soon as they want something different they'll be asking how to do it, because they never really understood what they were doing in the first place.

    It's a bit like wanting to make a track without knowing how to model an object in 3D software, or working on car physics without knowing about suspension geometry, engine/turbo performance curves and tables, or even what scientific notation is.

    There was a time when games were simpler and they provided their own simple tools for pretty much anyone to make something in 10 mins. As games get more complex it becomes more difficult, and it takes time to get into it. Unfortunately that's just the way it goes. (my own experience was with Quake... it came with its own pseudo-C scripting language that I had all sorts of fun creating custom weapons with, then along came Quake II which used 'proper' C++ plugins and I was lost - not because I had no idea with C++, but because I didn't find a simple plugin to start with (there were probably plenty around, I just didn't find them quickly). In rF2 the simple plugin is provided by ISI already, but doing anything with it unavoidably requires some knowledge of programming)


    As for the OP which I didn't see until now, I wasn't aware you could do that so that's cool. I still test classes separately so I don't need start up rF2 at all to quickly test logic and code performance, and I did set up a very simple main class that calls some of the plugin functions in a similar manner and pattern to rF2, but sometimes being able to jump in properly will be helpful. Thanks :)
     
  7. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    35
    I think often able to analyze a complete project (even if simple) helps us to understand better and faster the operating logic of things. But ok.

    Thanks
     
  8. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    But the sample from ISI is a complete project ready to compile.
     
  9. Jeferson Richart

    Jeferson Richart Registered

    Joined:
    Oct 23, 2013
    Messages:
    174
    Likes Received:
    35
    Ok, I will try to analyze and understand the sample of ISI... to pick up and send data.

    Thanks
     

Share This Page