The online racing simulator
LFSPoints (Replay Results Parser)
(15 posts, started )
LFSPoints (Replay Results Parser)
Hello, I just thought I'd post up a small program I've written.

It's designed to aid league managers in calculating the championship point results for races. It works by parsing the Multiplayer Replay files (.mpr) created by the game and comparing the results against a user-defined points table, which you can set in the options menu. It then gives a nice display of the results which can either be copied and pasted, or exported as an XML or CSV file.

I know there are probably other programs which do a similar thing, probably better, but I wanted to write something to practice my C# skills, as I hadn't programmed anything for a while. It is technically in beta form, so it may still have a few bugs here and there, although I haven't noticed any big issues. All bug reports, opinions, comments, suggestions and death threats are welcome.

As it's written in C# you'll need the Microsoft .NET Framework 2.0 or better to run it. Anyway I hope it is useful in some way to someone.

Changes in V0.8:

- Fixed a crash trying to calculate points when no replays are shown in the list.

Changes in 0.7:

- Rewritten fastest lap calculation, should work better (perfect) now.
- Added fastest lap to replay preview.

Changes in 0.6.1:

- Points for fastest lap had been mistakenly disabled while fixing the driver finishing order bug, the functionality has been restored and should be working as intended now.

Changes in 0.6:

- Fixed bug with lap display, it now works with races over 100 laps in length.
- Fixed bug with driver finishing order detection, now far more robust.

Changes in 0.5:

- Added points for fastest lap.
- Increased number of drivers to 32.

Changes in 0.4:

- Fixed crash when selecting replays from Kyoto Ring.
- Changed format used to save options.dat file, version 0.4 is not compatible with the options file created by earlier versions of the program.
Attached files
LFSPoints_V0.8.zip - 18.6 KB - 162 views
Great work!
#3 - Davo
Great tool. When selecting a replay file I get this error.

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.ThrowHelper.ThrowKeyNotFoundException()
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at LFSPoints.LFSReplay.get_FullTrackName()
at LFSPoints.LFSPoints.m_UpdateReplayPreview(LFSReplay replay)
at LFSPoints.LFSPoints.m_SelectedReplayChanged()
at LFSPoints.LFSPoints.m_ReplaysCheckedListBox_SelectedIndexChanged(Object sender, EventArgs e)
at System.Windows.Forms.ListBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.CheckedListBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ListBox.WmReflectCommand(Message& m)
at System.Windows.Forms.CheckedListBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ListBox.WndProc(Message& m)
at System.Windows.Forms.CheckedListBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
LFSPoints
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///E:/Game%20ISOs/LFS/extras/LFSPoints/LFSPoints.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Thanks for the report! Can I ask for some details from the replay files you are selecting when this error appears, such as the track/config/car etc..? I'm pretty sure I've just missed out a track config and it's looking for something in the tracks array that doesn't exist.

Damn bugs...
#5 - Davo
Sure the config is Kyoto National, Clear Day, no wind with FXO using LFS U30. Yup, all my replays with ky2 don't work so you must have missed it.
LOL - I didn't miss it, I just miss-spelled the word 'Kyoto'!

It's fixed.

Edit: Version 0.4 uploaded.
#7 - Davo
Thanks for the quick fix.
cool stuff,

i have some things for a wishlist and it hink they won't need that much work so here it is:
- Points for Poleposition
- Points for Highest Climber (compared from start to finish)
- Points for Leading a Lap
- Points for most laps leading


great tool anyway as it is now allthough i think there is something wrong. i have several replays where the actual winner in the replay wasn't the first one in your tool... and it also does not count the laps correctly. i have replays of 180 lap races where the result has only 108 according to the tool and also a wrong winner...
Thanks.

Those things would be very cool, but sadly I am very limited with what LFS stores in its replay files header. You can look here to see what I'm basically parsing from the files: http://www.liveforspeed.net/?page=MPR. All the data for the race, down to individual button presses, are of course stored in the replay files themselves, but after the header it's all basically LFS physics data and I don't have the skill, nor energy, to start pulling all that apart.

- Points for Poleposition (I believe qualifying results are stored in a seperate replay, I may be wrong. In fact I don't know what would happen if you loaded a qual replay in the program. I'll find out. This may be possible. The replay files themselves don't tell me what order the drivers started in however).
- Points for Highest Climber (compared from start to finish) (The replay header only stores the details for drivers which finished a race, it does not mention who started the race or what position they started in).
- Points for Leading a Lap (Again this information just isn't included in the header).
- Points for most laps leading (See above, no info on this sadly).

I do believe that these things could be realised using InSim and I do plan to start experimenting with InSim shortly. Once I've had a mess about and looked at what InSim is capable of (I know very little about it, from a technical standpoint), I a may release a version of the program which uses InSim and can determine lots more interesting tipbits, but as of now the program stands as it is. As I said I will look at how to handly qualifying replay files and see if they can be worked in.

Edit: Thanks for the bug reports, I'll double check how it is calculating the laps and race finishes. I realise now I'm calculating the laps incorrectly, but I'm not sure what's going on with the winner award. It just put all the drivers in an array and sorts them by their overall finishing time. I'll look into it. If you don't mind, could I actually have a copy of the replay file you are loading? I don't have any replays for races over 100 laps. :/
ok i can upload some for you on my server as they are pretty big. the 180 lapers are about 16MB and the 360 laper is about 32mb
If you don't want to upload them, you can email one to me using the mailing address in the readme file.

Edit: Actually don't worry about the file, I think I fixed both the bugs. V0.6 coming shortly.
Version 0.6 uploaded...

OK - hopefully both of these bugs should be fixed now.

I made a silly mistake with the way the laps were calculated, it will now work for races over 100 laps.

I totally rewrote the way the driver finishing order is detected. In fact I'm very pleased with my solution and it may allow me to add some more interesting features soon.

Hope it works better now. God bless betas.

EDit: Get V0.6.1. I mistakenly turned off points for fastest laps in 0.6, 0.6.1 restores this functionality.
ok, cool. can i delete the files from the server?
Um, yeah. Sorry if I put you out with that, I thought I might need a copy of the replay to fix it, but when I started looking at the code I realised what the problems were. Thanks for the help mate.
no problem. its just when i don't delete them i will forget it and wonder about reaching server limit in a few month. and then i will have to search through all directories to find the black sheep

anyway good to be a help in your thing

LFSPoints (Replay Results Parser)
(15 posts, started )
FGED GREDG RDFGDR GSFDG