Loading
Bookmark and Share

Guide: Debugging your AI DLL

in Forum > General
theferret 1 posts

You may not be aware, but it is possible to debug a hooked DLL in real-time. This guide will show you how, allowing you to step through your code, use breakpoints, all that debugging goodness.

I'll be using the ExampleAIModule.dll to demonstrate how.

1) Build the ExampleAIModule project in 'Debug'.
    - Open the project in Visual C++ 2008
    - Right click the VC project (on the left hand side by default) and select 'Properties'
    - Change the top left drop down box to read 'Debug' (it will probably read '(Active)Release' previously)
    - Under 'Configuration Properties -> C/C++ -> Code Generation', set the 'Runtime Library' field to 'Multi-threaded DLL /MD'
    - Under 'Configuration Properties -> Linker -> Input', set the 'Additional Dependencies' field to contain the following: '../../lib/BWAPI.lib ../../lib/BWTA.lib ../../lib/CGAL-vc90-mt.lib ../../lib/gmp-vc90-mt.lib ../../lib/libboost_thread-vc90-mt-1_38.lib ../../lib/mpfr-vc90-mt.lib'
    - Click 'Ok' at the bottom right of the dialog box.
    - Change the drop-down box located in the upper-middle of the screen from 'Release' to 'Debug'
    - Press F7 to build the project (or alternatively, select 'Build -> Build Solution'

2) Run the game.
    - Run the ChaosLauncher and begin a new single player custom match (loading with Windows Mode enabled is highly recommended)
    - You should recieve onscreen notification that the DLL has been successfully loaded

3) Attach the debugger.
    - Once the game has begun, return to Visual C++ 2008
    - Select 'Debug -> Attach To Process...'
    - At the bottom right hand of the screen, mark the checkbox labelled 'Show processes from all users'
    - Select 'Starcraft.exe' from the list and click 'Attach' located to the bottom right of the dialog

4) Debug.
    - Create a breakpoint at the start of your 'onFrame()' function (in the example, 'ExampleAIModule::onFrame()' to test for a successful hook
    - Continue debugging your application!

Note: You may need to restart Visual C++ 2008 with Administrator privileges. You can tell by checking Visual C++ 2008's title bar, it should contain '(Administrator)'.

GL HF

bweber 36 posts

Thanks for the post. I'll look into it next time BWAPI crashes StarCraft. It seems that the 2.2 release fixed a lot of stability issues and I'm now able to run several games without restarting StarCraft, thanks lowerlogic, deathknight, et al.

nolace 6 posts

Thanks for the post. I can debug the AImodule which doesn't use proxy. But for the proxybot, I cannot debuf the dlls cause there is no c++ project, I tried to overwrite the proxy version cpp and its header with the normal one, but when I am trying to debug I face these errors,

ExampleAIModule.obj : error LNK2019: unresolved external symbol _recv@16 referenced in function "public: virtual void __thiscall ExampleAIModule::onStart(void)" (?onStart@ExampleAIModule@@UAEXXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _send@16 referenced in function "public: virtual void __thiscall ExampleAIModule::onStart(void)" (?onStart@ExampleAIModule@@UAEXXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _connect@12 referenced in function "int __cdecl initSocket(void)" (?initSocket@@YAHXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function "int __cdecl initSocket(void)" (?initSocket@@YAHXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _htons@4 referenced in function "int __cdecl initSocket(void)" (?initSocket@@YAHXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function "int __cdecl initSocket(void)" (?initSocket@@YAHXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _gethostname@8 referenced in function "int __cdecl initSocket(void)" (?initSocket@@YAHXZ)
1>ExampleAIModule.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function "int __cdecl initSocket(void)" (?initSocket@@YAHXZ)

Any idea how to solve this one ?

ikefruusto 8 posts

I tried building the proxy module and got stuck with the same errors.

emartel 3 posts

You need to link wsock32.lib