Saturday, March 1, 2014

Developer Log: Cut out the middleman && unmanaged+managed=harmony

For those of you who do not know, I have been having issues regarding my menu implementation in Project: AA recently. Today I learned that sometimes it is best to cut out the middleman, and just go straight to the hardware, and that calling unmanaged code inside of managed code works rather well.

The issue I have been having is that when the user presses start game after the second time of starting the game, and they attempt to go to the pause menu, it wont work unless you press escape twice.

Very odd issue, huh?

This is issue is actually a priority in terms of solving because if the user wants to pause the game to take a break, and this issue still exists, they would lose their progress first.

I have been struggling with this issue for about 2 weeks, until I finally decided on a rather extreme solution.

I am going to cut out the middleman, so to speak. What I did was create yet another bool, that only became true after you went to the Main Menu from the Pause Menu. Then I imported a Win32 C/C++ DLL (user32.DLL) containing the Win32 API version of SendKeys. Once I imported it and created a PressKey and ReleaseKey method, I called VK_ESCAPE = 0x1B if the bool was true. This calls the Escape key press event, and the Escape key release event programmatically.

This way when the user begins the game, it automatically presses Escape for them to get rid of the bug. Then once they press Escape by themselves it will go to the Pause Screen as intended.

This is a really... hacky bool hack, for lack of a better term. It works however, and that is great. Just goes to show you, sometimes forcing a key event using low level managed code is what you need to fix a bug.

No comments:

Post a Comment