Project Perfect Mod Forums
:: Home :: Get Hosted :: PPM FAQ :: Forum FAQ :: Privacy Policy :: Search :: Memberlist :: Usergroups :: Register :: Profile :: Log in to check your private messages :: Log in ::


The time now is Tue Mar 19, 2024 7:47 am
All times are UTC + 0
Step by step on how to get the dll code into the VS debugger
Moderators: Global Moderators
Post new topic   Reply to topic Page 1 of 1 [9 Posts] Mark the topic unread ::  View previous topic :: View next topic
Author Message
jonwil
Rocket Infantry


Joined: 24 Jul 2005

PostPosted: Tue Jun 09, 2020 7:03 am    Post subject:  Step by step on how to get the dll code into the VS debugger Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
secondwtq
Light Infantry


Joined: 26 Jun 2010
Location: China

PostPosted: Wed Jun 10, 2020 12:45 pm    Post subject: Reply with quote  Mark this post and the followings unread

Thanks, this guide is extremely helpful!

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?

Back to top
View user's profile Send private message Send e-mail
jonwil
Rocket Infantry


Joined: 24 Jul 2005

PostPosted: Fri Jul 03, 2020 7:41 am    Post subject: Reply with quote  Mark this post and the followings unread

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

Back to top
View user's profile Send private message
CCHyper
Defense Minister


Joined: 07 Apr 2005

PostPosted: Fri Jul 03, 2020 1:14 pm    Post subject: Reply with quote  Mark this post and the followings unread

A better solution would be to run a batch script that does that for you.

NOTE: You can use REDALERT or TIBERIANDAWN to choose the game.

Code:
ClientG.exe GAME_INDEX=0 NO_EVENT_HANDLER MOD_DEBUG REDALERT
InstanceServerG.exe GAME_INDEX=0 NO_EVENT_HANDLER MOD_DEBUG CLIENT_PORT=16000 RUN_AS_APP NO_AUTO_EXIT LAUNCH_FROM_CLIENT=

Back to top
View user's profile Send private message
jonwil
Rocket Infantry


Joined: 24 Jul 2005

PostPosted: Fri Jul 03, 2020 11:20 pm    Post subject: Reply with quote  Mark this post and the followings unread

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.

Back to top
View user's profile Send private message
Oofjay
Civilian


Joined: 15 Jul 2020

PostPosted: Wed Jul 29, 2020 9:26 pm    Post subject: Reply with quote  Mark this post and the followings unread

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".

Back to top
View user's profile Send private message
jonwil
Rocket Infantry


Joined: 24 Jul 2005

PostPosted: Wed Aug 12, 2020 3:27 am    Post subject: Reply with quote  Mark this post and the followings unread

The game dll isn't loaded until you actually get in-game. If you are still in the main menu etc then its not loaded yet.

Back to top
View user's profile Send private message
GroovyDoovy
Civilian


Joined: 21 Nov 2020

PostPosted: Sat Nov 21, 2020 1:59 pm    Post subject: Reply with quote  Mark this post and the followings unread

@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!

Back to top
View user's profile Send private message
GroovyDoovy
Civilian


Joined: 21 Nov 2020

PostPosted: Sat Nov 21, 2020 2:52 pm    Post subject: Reply with quote  Mark this post and the followings unread

Also, @secondwtq,

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.

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [9 Posts] Mark the topic unread ::  View previous topic :: View next topic
 
Share on TwitterShare on FacebookShare on Google+Share on DiggShare on RedditShare on PInterestShare on Del.icio.usShare on Stumble Upon
Quick Reply
Username:


If you are visually impaired or cannot otherwise answer the challenges below please contact the Administrator for help.


Write only two of the following words separated by a sharp: Brotherhood, unity, peace! 

 
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


Powered by phpBB © phpBB Group

[ Time: 0.1444s ][ Queries: 11 (0.0082s) ][ Debug on ]