Well let's start
Here are the prerequisites :
- Bf2 editor must be installed Tutorial link
- Notepad++ Link
- Winrar or any software for extract .zip
- Bf2_r.exe fixed memory crash that can be found here Link
- And of course having launched the game normally at least once to adjust the profiles, graphics/resolution...
Now here are the different methods to debug bf2 :
The first that everyone knows is to launch the game in windowed mode so that an error appears, but unfortunately a lot of errors will not be displayed, among other things related to the AI for example, and you will get a crash without any visible error.
Here is an example of a shortcut to launch the game in windowed mode (classic method):
"A:\Battlefield 2\BF2.exe" +modPath mods/ModName +restart +szx 1920 +szy 1080 +fullscreen 0
"A:\Battlefield 2\BF2.exe" > represents the path of the executable, with the drive letter, personally it is A:\
+modPath mods/ModName > represents the mod to launch in your mods folder (replace ModName by the name of the mod you are using)
+restart > allows you to skip the cutscenes and save some time
+szx 1920 +szy 1080 > represents the resolution that will be used, it must be specified otherwise you will have display problems in game like black textures etc. It must be lower than the resolution of your screen to allow you to switch between the desktop and your game, for example I have a 2560x1440 screen, so I use 1920x1080 for debugging..
+fullscreen 0 > disable the fullscreen
With all this you will get errors to debug common things like missing textures.. here is an image of a missing texture, small thing too, always look at the loading bar, here it is the textures so rather easy to find.
Okay, well, that's all easy, now we're going to move on to the crashes that make us all angry, those that don't make an error appear, and even more vicious, those that are totally random and that make us waste a gargantuan amount of time.
Don't forget to replace the bf2_r.exe with the one in the link above, otherwise you will have crashes.
Let's take our shortcut, and change the executable, and add some more stuff :
Before :
"A:\Battlefield 2\BF2.exe" +modPath mods/ModName +restart +szx 1920 +szy 1080 +fullscreen 0
After :
"A:\Battlefield 2\BF2_r.exe" +modPath mods/ModName +restart +szx 1600 +szy 900 +fullscreen 0 +ignoreAsserts 1 +developer 1 +debugOutput 0
Use a lower resolution otherwise you will still have a memory related crash, for me if I use 1920x1080 it crashes, with 1600x900 no worries
The rest are things that allow ignoring the +50000000 error messages that are not useful
Don't forget to start bf2_r.exe with admin+xp sp2 or you will get DirectX error when launch
Ok now remember that bf2_r.exe is not based on bf2 patched 1.5, so when you go to launch it, you will have errors related to HUD etc which are not to be taken into account
Let's start the game, I purposely put 2 errors that will only be visible with bf2_r.exe
Here are mistakes we don't care about, just kill the button "continue" several times
Now you are on the menu, start a game as you wish
The novelty is that as soon as you launch bf2_r.exe, new files will be created in your mod folder.
The "Logs" folder is the one that will interest us, first file "BfLog_unknown" contains a detailed report, the second "Debug_unknown" a summary of errors.
"stats" folder contains .bin files about which I don't know much.
I purposely inserted an item index error to make it crash on load, you know? This kind of error that does not appear with the classic method.
Let's open the "logs" folder and open one of the two files with notepad++, you will surely have a lot of stuff in there that we don't care about, errors related to nametags, font, etc, or "Unknown object or method" in short, ignore that, on the other hand scroll to the bottom, usually the last error is the cause of the crash (be careful not always though).
Magic, we see the error of the item index :
Let's fix that, now this time I removed an ai template which will cause a random crash (this can happen after 5min as well as after an hour).
Don't forget to delete the logs folder to avoid having 50 files (it will create a new one at each launch).
Another type of error we don't care about, just click "continue" :
Okay so we are ingame, you will observe differences in graphics, and fov camera, this is perfectly normal.
Another thing, open the console with ², you will see new information such as effects played in real time etc.
Bf2_r.exe also support lines of code for debugging, little showcase Youtube
Then, remember that the game is written in real time in the log, so you can play and consult the log at the same time, there for example I deleted an ai template for rifles, this will surely cause a fairly rare crash for example after 30min, but I don't have time to wait, so let's leave the game open and consult the log.
Magic, we find the error in the log, you will see that it is written several times, and the game will continue to display it while it is running
This is typically the kind of error that will cause you to randomly spit your game, and which will never be displayed with the classic method.
And now, this tool is essential for me, it will save you precious time and reduce your rage in the event of a crash without an error message
Nevertheless, I want to specify an important thing, bf2_r.exe will not show you all the possible errors, some will always remain invisible, but rest assured, these are errors related to unusual things, such as complex manipulations with the HUD, and when you try for example to load files in the maps like running things from gpo "run ../../../Init_coop_16.con" wich is missing or have bad stuff into, or like running bad ai settings from maps.... in short this tool is cool, but will not solve all the problems if you play the sorcerer's apprentice without knowing what you are doing.
And here I think it's quite detailed, I took a really long time to write all this, don't hesitate to leave a comment to let me know if it was useful to you :)
For more information, join the discord modding server : Discord.gg
If you want to save that tutorial, use chrome, then print tool, and save to .pdf
What different this bf2_r.exe than bf2.exe by John price
It's explained in the article
Thank you ryan for making this debugger introduction.
Sadly the the debugger outputs so many errors, that one might not find the error one searches :)
Wow awesome article! Thanks for the detailed tutorial!
Good one, Ryan.
The Google drive link is dead
This comment is currently awaiting admin approval, join now to view.
Link fixed !
thanks bro