Refueling Time Bug Fix

Posted by MikhailM 
Refueling Time Bug Fix
Date: September 27, 2017 05:23AM
Posted by: MikhailM
Hi all,

As you probably know, there is a bug in the original game where, for a relatively small percentage of pit stops, the car doesn't stay in the pits anywhere near as long as it should, given how much fuel is added. This is most evident on 1-stop strategies where most cars will take 12-15 seconds to refuel but sometimes a car will be out in less than 7 with the full fuel amount. I wasn't able to find any fix for this online, so once it annoyed me enough, I decided to try to figure out a way to fix it myself (even though I pretty much had to learn assembly programming from scratch). After around 5 weeks of messing with it, I finally got it figured out and want to share it with everyone.

Fix

Fixing this bug requires a change to gp4.exe. Open the decrypted (v1.02) gp4.exe with your favorite hex editor (back it up first of course), and make the following change starting at offset 0x0E681D:

Original file:
8B C6 8B 51 44 C1 E0 04 03 C6 83 7C C2 24 05 0F 84 8C 00 00 00 8B 85 BC 5D A9 00 85 C0 0F 8F 92 00 00 00
Replace with:
8B 85 BC 5D A9 00 85 C0 0F 8F A7 00 00 00 8B C6 8B 51 44 C1 E0 04 03 C6 83 7C C2 24 05 0F 84 7E 00 00 00

(Note: there are smaller changes that would surely fix the bug as well; the above change, though, preserves all of the original game's code, just rearranges it)

This fix should be compatible with any tools that modify gp4.exe (not aware of any tool the modifies this part of the code), though I haven't tested it all that extensively. If anyone finds issues using this, please let me know. I'll also be running some more test races to ensure that nothing else is broken with this.

I might make a patch program at some later point to make it simpler, although I think it would be better to get this incorporated into one of the other tools if possible.


Explanation and Known Issue

The bug stems from a poorly-implemented feature. The idea appears to have been that for a small percentage of pit stops, the mechanic would have trouble detaching the fuel nozzle from the car at the end of the stop, leading to a longer stop. However, the way the code handles this particular type of pit stops is that once a car arrives for a stop and is jacked up, the code starts checking (I believe) whether the 2 pit crew members responsible for refueling have finished their animations, and if they have, it considers the refueling part of the stop to be done. But the only animation being played at this point in the stop is the one for inserting the fuel nozzle... so as soon as it's inserted, the refueling part of the stop is over, and the nozzle is taken right back out. All this, even with the "problem" version of the detaching animation, takes less time than the tyre changes, so the end result is that for these stops, the refueling is basically instant, and the tyre change time is the only thing that determines the overall pit stop time.

The fix switches around 2 of the conditions used when checking whether refueling should be completed, so that now the "problem"-specific checks will only be done after the normal refueling is completed. This ensures that refueling will take the normal amount of time for every kind of stop.

The fix does not, however, implement the "refueling problem" feature itself, because there are other problems with the code as well (namely, that the code never checks whether the nozzle detaching animation is complete, neither for normal nor "problem" versions of the animation, when determining whether the pit stop as a whole is over). As a result, this fix introduces a small animation glitch for these "problem" pit stops, where the car drives away while the pit crew is still trying to detach the nozzle. This has no impact on the game beyond the animation looking weird - for all intents and purposes, the "problem" stops with the fix behave just like a normal stop would. This glitch itself can be fixed pretty easily if needed - for example, by changing the race normalchange.ssc file inside anim.wad (change the "fuel_problem" scenescript to match the "normal_change" one aside from the name).


Can the "Refueling Problem" Feature Be Enabled?

I won't say that for sure it can't - after all, all the needed pieces are there in the game already - but I played around with a few relatively simple test fixes and wasn't able to get this feature working without also adversely impacting normal stops. So most likely a fix to properly enable this feature would be quite complex.


(EDIT: Added clarification on which gp4.exe version to use and an explanation of what the fix actually does).



Edited 1 time(s). Last edit at 09/28/2017 12:35AM by MikhailM.
Re: Refueling Time Bug Fix
Date: September 27, 2017 11:16AM
Posted by: Turbo Lover
Nice find, great work. I will try it out.



My Grand Prix 4 Files

I'm a total dick. How many people can say that?
Re: Refueling Time Bug Fix
Date: September 27, 2017 12:07PM
Posted by: klausfeldmann
Wow, it's overwhelming to see this bug being fixed after such a long time. Very great, you tried to find a fix on your own and had success! I will try this fix and tell you, if there appeared some new problems.

BTW:
You told, you learned assemler. What are your recommendations to learn this language (special website, special book, etc.)?
Re: Refueling Time Bug Fix
Date: September 27, 2017 02:53PM
Posted by: phantaman
is this intended for gp4.exe version 1.00 or 1.02? :/

----signature--------------------------------------------------------

RELEASE => Physics (under FIA Technical Regulations)
MagicDatas? Setups? Pit Stop Strategies? Track Specific Performances? Up2Date GP?
Power Torque Curve? Where's this stuff? All download is available at ..
Re: Refueling Time Bug Fix
Date: September 27, 2017 03:29PM
Posted by: Soutsen
That's awesome! Thanks!

___________________________________________________________________________
For a list of EVERY download for GP4, look here:[docs.google.com]
Re: Refueling Time Bug Fix
Date: September 27, 2017 11:10PM
Posted by: SDI
Well done! Those were 5 weeks well spent :)

If you wish, I can incorporate your fix in GPxPatch.

The last part of the code is slightly different in GP4 1.00. I'm not sure if your fix has the same result there. Unless 1.00 doesn't have this bug...

René Smit, Independent Software Developer.
Download my GPx tools here.
Re: Refueling Time Bug Fix
Date: September 28, 2017 12:28AM
Posted by: MikhailM
Thanks all!

Sorry didn't specify which version; this is for the decrypted gp4.exe, version 1.02. I don't have a decrypted 1.00 version (didn't know that existed :) ), so not able to research what the difference is - could anyone point me to where I can find it?

The fix will definitely not work with the original (encrypted) exe.


SDI Wrote:
-------------------------------------------------------
> If you wish, I can incorporate your fix in
> GPxPatch.

That would be amazing, thanks! Might be best to wait until a few people have tried it out though, in case there are any issues or other considerations I hadn't thought of like the different versions.


klausfeldmann Wrote:
-------------------------------------------------------
> BTW:
> You told, you learned assemler. What are your
> recommendations to learn this language (special
> website, special book, etc.)?

Not sure my approach would be useful for everyone, but I got the high-level overview of how it works from the Wikipedia page; from there, my "learning" consisted primarily of going through the (disassembled) GP4.exe code and trying to figure out what it was doing, looking up things I didn't know as needed online. Intel's own developer manual is quite extensive, useful for looking up individual instructions, though I didn't use it much (I actually didn't find the easily navigable version until typing this response, otherwise I probably would have used it :) ; instead I used a site someone else compiled from the instruction set reference portion of that manual, which can be found here).

A couple of other resources I found useful:

Assembly x86 Emulator - useful for testing out assembly programs without all the overhead of having to make your own Windows or DOS executable, although unfortunately it doesn't emulate the full set of x86 instructions (it has most of the ones commonly encountered in the GP4 exe though).

Online x86 / x64 Assembler and Disassembler - useful for assembling and disassembling small blocks of code.
Re: Refueling Time Bug Fix
Date: September 28, 2017 12:39PM
Posted by: klausfeldmann
MikhailM schrieb:
-------------------------------------------------------
> [...]


Thanks for all these resources. I will have a look at them all. Especially the wikipedia-site looks like a great site to beginn with and is much better than the german one (Y).
Re: Refueling Time Bug Fix
Date: September 29, 2017 07:37AM
Posted by: TomMK
Any chance this "bug" can be turned into a "feature" to enable quicker pitstops every time, for the no-refueling era?

Combined with the no-refuelling animation patch this would be pretty cool.

=====================================================


Intel NUC 8i3, 8GB RAM, MS Sidewinder Wheel
Re: Refueling Time Bug Fix
Date: September 29, 2017 05:14PM
Posted by: TGF1Driver2
Yes, pit stops without refueling. But that might be boring. I wonder since 15 years why the cars need between 10 and 15 seconds for a pit stop and the real F1 cars took about 5 to 8 seconds. That's annoying, especially when you're in a hurry to get 1st place and the AI cars often seems to be faster than me.
Re: Refueling Time Bug Fix
Date: September 29, 2017 11:47PM
Posted by: MikhailM
TomMK Wrote:
-------------------------------------------------------
> Any chance this "bug" can be turned into a
> "feature" to enable quicker pitstops every time,
> for the no-refueling era?
>
> Combined with the no-refuelling animation patch
> this would be pretty cool.


Yes, this can be done (I had actually done this in my testing in order to confirm that this was in fact the code causing the bug). Although can't something like this be done with GP4Tweaker by just setting the refueling time to something negligible?

Here are the same 35 bytes of gp4.exe (version 1.02 as before) with the change that should make every pit stop refuel instantly. Let me know if this doesn't work - I hadn't saved the version I used for testing and just came up with this real quick... but it should work:

8B C6 8B 51 44 C1 E0 04 03 C6 83 7C C2 24 05 90 E9 8C 00 00 00 8B 85 BC 5D A9 00 85 C0 0F 8F 92 00 00 00

(Only the 2 highlighted bytes are actually different from the original file)



Edited 1 time(s). Last edit at 09/29/2017 11:49PM by MikhailM.
Re: Refueling Time Bug Fix
Date: September 30, 2017 02:10PM
Posted by: gezere
I love this thread . Impressive work, Amazing find (Y)

Re: Refueling Time Bug Fix
Date: October 05, 2017 12:53PM
Posted by: klausfeldmann
For me, sadly, this fix doesn't work. CCcars get stuck in the pit with wheels still running and pit crew isn't doing anything. I tried it on various tracks, but this bug is reproducable so far. On some tracks it needs some time (~1 minute) till the pit crew lifts the car and starts to work.



Has anyone else this problem, too?

I just found out, it is because of the physics file. Original GP4 physics works fine. As it seems, my low braking force value seems to interfere with the pit stops.
I will solve it on my own.



Edited 1 time(s). Last edit at 10/05/2017 02:05PM by klausfeldmann.
Re: Refueling Time Bug Fix
Date: October 15, 2017 10:19PM
Posted by: huskyman49
Sorry but I can't find an offset value '0x0E681D' using HxD tool... ?:-o
Re: Refueling Time Bug Fix
Date: October 15, 2017 11:32PM
Posted by: Atticus.
Wow, excellent work, thank you very much!



My workthread - [www.grandprixgames.org]
Full of classic F1/non-F1 track layouts

My blog about F1 performance analysis - [thef1formbook.wordpress.com]
Re: Refueling Time Bug Fix
Date: October 16, 2017 11:27AM
Posted by: rracunis
huskyman49 Wrote:
-------------------------------------------------------
> Sorry but I can't find an offset value '0x0E681D'
> using HxD tool... ?:-o

Same here :-o
Re: Refueling Time Bug Fix
Date: October 16, 2017 12:03PM
Posted by: klausfeldmann
rracunis schrieb:
-------------------------------------------------------
> huskyman49 Wrote:
> --------------------------------------------------
> -----
> > Sorry but I can't find an offset value
> '0x0E681D'
> > using HxD tool... ?:-o
>
> Same here :-o


In your Hex-editor the line's name is probabaly 0x0E6810. Have a look at the hex-data right from it. The sequence 8B C6 8B 51 44 C1 E0 04 03 C6 83 7C C2 24 05 0F 84 8C 00 00 00 8B 85 BC 5D A9 00 85 C0 0F 8F 92 00 00 00 begins right in this line.
Re: Refueling Time Bug Fix
Date: October 16, 2017 03:10PM
Posted by: phantaman
And in a MoD by CSM (ZaZ GP4 Tools), in the file Patch.ini would be:

; Refueling time bugfix
Offset1 = 0x0E681D
Code1 = 0x8B, 0xC6, 0x8B, 0x51, 0x44, 0xC1, 0xE0, 0x04, 0x03, 0xC6, 0x83, 0x7C, 0xC2, 0x24, 0x05, 0x90, 0xE9, 0x8C, 0x00, 0x00, 0x00, 0x8B, 0x85, 0xBC, 0x5D, 0xA9, 0x00, 0x85, 0xC0, 0x0F, 0x8F, 0x92, 0x00, 0x00, 0x00

----signature--------------------------------------------------------

RELEASE => Physics (under FIA Technical Regulations)
MagicDatas? Setups? Pit Stop Strategies? Track Specific Performances? Up2Date GP?
Power Torque Curve? Where's this stuff? All download is available at ..
Re: Refueling Time Bug Fix
Date: October 16, 2017 09:47PM
Posted by: huskyman49
my offset (h) goes from '00000000' up to '005FBFE0'.. There's nowhere any combination as '0x0E681D'... (N)
Re: Refueling Time Bug Fix
Date: October 16, 2017 10:46PM
Posted by: phantaman
huskyman49 Wrote:
-------------------------------------------------------
> my offset (h) goes from '00000000' up to
> '005FBFE0'.. There's nowhere any combination as
> '0x0E681D'... (N)

In a MoD by CSM (ZaZ GP4 Tools), not by replacing files ;-) ;)



----signature--------------------------------------------------------

RELEASE => Physics (under FIA Technical Regulations)
MagicDatas? Setups? Pit Stop Strategies? Track Specific Performances? Up2Date GP?
Power Torque Curve? Where's this stuff? All download is available at ..




Edited 1 time(s). Last edit at 10/16/2017 10:50PM by phantaman.
Sorry, only registered users may post in this forum.

Click here to login

Maintainer: mortal, stephan | Design: stephan, Lo2k | Moderatoren: mortal, TomMK, Noog, stephan | Downloads: Lo2k | Supported by: Atlassian Experts Berlin | Forum Rules | Policy