Posted: Tue Jun 09, 2020 7:03 am Post subject:
Step by step on how to get the dll code into the VS debugger
1.Build your mod dll and load the mod into the remaster and activate it.
2.Start ClientLauncherG.exe with the parameter NO_EVENT_HANDLER
3.Pick your game.
4.Let the game load.
5.Activate windowed mode (you want this otherwise you can get stuck where you are stuck on a breakpoint in VS but can't alt-tab to VS because the full-screen game is frozen)
6.Open VS and (using ctrl to select multiple entries in the attach list) attach both to ClientG.exe and InstanceServerG.exe.
7.Let the code run and it will hit your breakpoints. Note that if you sit on the breakpoint too long, ClientG.exe will timeout waiting for data from InstanceServerG.exe and things will stop working. QUICK_EDIT
Note there is a problem that DLLs compiled with /Od crash the game. I did some debugging and got TD running by removing Init_MMX() in DLL_Startup() of startup.cpp (not sure about RA).
Still it's very strange ...
Edit: Alright someone at Westwood just turned a blind eye to calling convention while writing this assembly routine. And "fortunately" it gets by in both MSVC and ICC with optimization. But maybe with optimizations off the register pressure rises. I guess those "real gamedevs" at Westwood/Petroglyph just never debug with /Od? QUICK_EDIT
I have figured out how to run clientg.exe directly (e.g. if you want to start it in a debugger rather than attaching to it or if you want to get the game inside something like nvidia nsight to take a look at the graphics rendering).
You need to run ClientG.exe with these parameters GAME_INDEX=0 NO_EVENT_HANDLER MOD_DEBUG REDALERT
Then run InstanceServerG.exe with these parameters while the splash screen is visible GAME_INDEX=0 NO_EVENT_HANDLER MOD_DEBUG CLIENT_PORT=16000 RUN_AS_APP NO_AUTO_EXIT LAUNCH_FROM_CLIENT=
Do that and things should work properly QUICK_EDIT
If you need to have one of the binaries (either clientg or instanceserverg) run from inside a specific tool such as nvidia nsight (which I was using yesterday to track down the shader code used to do team color remapping) then a batch file that launches both wont be that useful. QUICK_EDIT
I just cannot get the debugging to work. I've opened ClientLauncherG.exe with NO_EVENT_HANDLER, but when I attach both processes, I cannot see TiberianDawn.dll in the modules window. When I place a breakpoint in UnitClass::Harvesting, it says "No executable code is associated with this line". QUICK_EDIT
@jonwil Thanks so much for posting this info! I had been trying for several days to attach the debugger, unsuccessfully. I followed these directions and it worked!
Also, FYI, I initially tried using Visual Studio 2019, but anytime I used the Tiberiandawn.dll built with VS2109, it would crash after a couple of minutes. So I instead tried using VS2017, and that has been working much better for me. No crashes so far. And able to set breakpoints and trace through the code! QUICK_EDIT
When I attempt to use /Od , it doesn't seem to outright crash the game for me. Instead, it just seems to make one of the initial loading screens hang. But, I did discover that you can have the project as a whole set to /O2, but that you can turn off optimizations for individual source files by right clicking the file and setting the optimization for that one file to /Od. For example, I did that with LOGIC.CPP and I was able to add some debug code that assigned values to otherwise unused debug variables. I was able to turn on /Od for just that one file, and I was able to view the debug variables just fine in the debugger, whereas without /Od , this code was getting optimized out. QUICK_EDIT
You cannot post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum