Finally got ExampleAIClient compile in Linux!

https://github.com/bwapi/bwapi
AleXoundOS
Posts: 2
Joined: Wed Jan 25, 2012 11:30 am

Finally got ExampleAIClient compile in Linux!

Postby AleXoundOS » Fri Jan 27, 2012 5:40 am

Hi everyone!

I managed to compile ExampleAIClient and connected it with BWAPI under WINE in Linux. Thanks to the creator of the mingw patch.
I have not fully tested BWAPI functionality and stability yet, but it seems to work fine.

The way of doing this was no trival, but I didn't expected it to be easy because not so long ago BWAPI was incompatible with WINE at all (the latest working revision was 1914). Linux is the only option for me, I used to it a lot, it is easier to configure and more comfortable to use.


[center]Here is a guide for installing StarCraft, compiling ExampleAIClient and running compiled client with BWAPI in Linux.
[/center]
Requirements are BWAPI 3.7 and higher, WINE 1.3.36 and higher. (You may try lower versions of WINE, but I'm not sure there was a version between 1.3.30 and 1.3.35 that failed to inject BWAPI.)

This is one of my tested specs, it must work for sure:
[font="Lucida Console] Arch Linux x86-64
Linux kernel 3.2.1
wine 1.3.37
nvidia driver 290.10
mingw32-gcc 4.6.2
BWAPI revision 4025 (3.7.2)[/font]

First of all make sure that you have "direct rendering" on, otherwise the game will be unplayable slow. You can check it by running:

Code: Select all

glxinfo|grep rendering
You should get this:

Code: Select all

direct rendering: Yes

glxinfo is included in mesa-demos package in ArchLinux. Refer to your distribution's wiki if you get "direct rendering: No".

I used retail version of "StarCraft: BroodWar" that was sold circa 2007. In order to run setup program add the path to your CD drive mount point in winecfg in section [font="Lucida Console]"Drives"[/font] or make sure that this path can be accessed by WINE and uncheck [font="Lucida Console]"Emulate a virtual desktop"[/font] in [font="Lucida Console]"Graphics"[/font] section (in my case the installer refused to work in windowed mode 640x480). Run setup program like this:

Code: Select all

wine "StarCraft (Windows).exe"

Then apply the patch after installation. But in fact StarCraft doesn't need an installer and you can simply get a directory with a working copy of StarCraft. So lets assume you have installed StarCraft to ~/.wine/drive_c/Program Files/StarCraft/. Navigate to your installation path, run "wine StarCraft.exe" and most likely the game should run without problems.
If you have problems like crashing, black screen or low framerate you can try to add the key "HKCU/Software/Wine/Direct3D/" in regedit and populate it with these strings:
[font="Times New Roman]DirectDrawRenderer=opengl
OffscreenRenderingMode=fbo
RenderTargetLockMode=readtex
VideoMemorySize=<size of your video card physical memory in megabytes>[/font]

Also you may want to run StarCraft in a window, so launch winecfg and set virtual desktop to 640x480 in [font="Lucida Console]"Graphics"[/font] section and check [font="Lucida Console]"Automatically capture the mouse in full-screen windows"[/font] (the way of getting out of cursor "prison" while the game is running depends on your Window Manager, I suppose alt-tab must work in most non-tiling WMs).
If the game still crashes and you are using 64bit OS, make sure that you have installed 32bit versions of ALSA and nvidia-utils (or ati, intel).
I'm not focused a lot on guide for installing StarCraft, because usually it has no problems except you are using very old hardware and there are already lots of examples on how to do it. With Pentium D 3.2GHz and Nvidia 9800GT the game runs very very smooth, even at 16x speed, unless there are 8 computer zergs in a replay watched at 16x speed.


[center]Now comes the most important part - compiling ExampleAIClient.[/center]
In order to get the sources and compile them we need to install subversion, make and mingw32-gcc.
If you are using ArchLinux:

Code: Select all

pacman -S subversion make mingw32-gcc
And also I recommend you to do:

Code: Select all

pacman -Sy --sysupgrade
as it often solves unexpected problems.

Prepare a directory for the sources and run:

Code: Select all

svn -r 4025 checkout http://bwapi.googlecode.com/svn/ 4025

Navigate into ./4025/trunk/bwapi/. Copy svnrev_template.h to svnrev.h

Code: Select all

cp svnrev_template.h svnrev.h

Edit svnrev.h and replace the first two lines with:

Code: Select all

#define SVN_REV 4025
#define SVN_REV_STR "4025"

Then navigate into ./mingw-client/ and edit Makefile. Replace this line:

Code: Select all

CXX         = g++
with this:

Code: Select all

CXX         = i486-mingw32-g++

Then edit these files: ../include/BWAPI/Client/Event.h, ../BWAPIClient/Source/GameImpl.cpp, ../BWAPIClient/Source/UnitImpl.cpp. Here I pointed to the files where you need to replace "" symbol with this "/" in the #include strings.
Once you've done it, run make. It must create a file libBWAPI.a. Link it or copy to ../ExampleAIClient/Source/ directory, for example:

Code: Select all

ln libBWAPI.a ../ExampleAIClient/Source/libBWAPI.a

ExampleAIClient.cpp uses BWAPI header files. I don't have any experience of creating Makefile, so the solution is to copy or link the contents of the folder 4025/trunk/bwapi/include/ in your svn sources directory to /usr/i486-mingw32/include/ (this is a directory where mingw32 stores it's include files in my case).

Code: Select all

cp -r ../include/* /usr/i486-mingw32/include/
Then navigate to ../ExampleAIClient/Source/ and edit ExampleAIClient.cpp. Correct the lines containing #include in the same manner as it was described previously. Now you can compile ExampleAIClient.cpp by issuing a command:

Code: Select all

i486-mingw32-g++ -L. -lBWAPI ExampleAIClient.cpp -o ExampleAIClient.exe


[center]The next aim is to launch ExampleAIClient.exe and connect it with BWAPI.[/center]
First download and extract BWAPI 3.7.2.
Copy BWAPI 3.7.2/Chaoslauncher/BWAPI.dll into your ~/.wine/drive_c/Program Files/StarCraft/ folder.
Copy the contents of BWAPI 3.7.2/Starcraft/ to your ~/.wine/drive_c/Program Files/StarCraft/ folder.
Copy the contents of BWAPI 3.7.2/WINDOWS/ to ~/.wine/drive_c/windows/.
Also there are BWTA headers in BWAPI 3.7.2/include/ directory which you may want to link or copy to /usr/i486-mingw32/include/. But they were not necessary for compiling ExampleAIClient.cpp provided by 4025 revision, as all the lines related to BWTA are commented by default.

Download and extract InfectedStarCraft injector.
Copy InfectedStarCraft.exe, InfectedStarcraft.exe.injlist and InfectedStarcraft.exe.visitor to ~/.wine/drive_c/Program Files/StarCraft/.
Remove everything in InfectedStarcraft.exe.injlist and add only one line containing:

Code: Select all

BWAPI.dll

Download and install vcredist_x86.exe.

Navigate to your ~/.wine/drive_c/Program Files/StarCraft/bwapi-data/AI/ directory. Link or copy your compiled ExampleAIClient.exe here. So I decided to collect the needed libraries here. These 3 files must be linked or copied to ~/.wine/drive_c/Program Files/StarCraft/bwapi-data/AI/:
  • libBWAPI.a
  • /usr/i486-mingw32/lib/libgcc_s_sjlj-1.dll
  • /usr/i486-mingw32/lib/libstdc++-6.dll
I think it's better to link ExampleAIClient.exe, libBWAPI.a and other libraries because if you will recompile them in the svn sources directory you will not need to copy the things again.

If you installed StarCraft with installer (not just copying the folder) the registry must contain a key containing a string called "InstallPath" where the installation path is stored. If you don't have such a registry entry it seems that BWAPI cannot find bwapi.ini and read the settings. So I think it is advisable to add this entry:
InstallPath.reg

Code: Select all

REGEDIT4

[HKEY_LOCAL_MACHINESoftwareBlizzard EntertainmentStarcraft]
"InstallPath"="C:Program FilesStarCraft"
execute:

Code: Select all

regedit InstallPath.reg
Or simply create the it manually using regedit.

Now check that

Code: Select all

shared_memory = ON
in ~/.wine/drive_c/Program Files/StarCraft/bwapi-data/bwapi.ini. The drawback is that with shared_memory option turned on, the game freezes with a black screen if ExampleAIClient.exe instance was not already launched (advice: "wineserver -k" kills WINE in this case instantly).

At this point you need two terminals.
In the first terminal navigate to ~/.wine/drive_c/Program Files/StarCraft/bwapi-data/AI/ and execute

Code: Select all

wine ExampleAIClient.exe

In the second terminal navigate to ~/.wine/drive_c/Program Files/StarCraft/ and execute

Code: Select all

wine InfectedStarCraft.exe

And eventually connection between BWAPI and ExampleAIClient will be established!
The first terminal will show something like:

Code: Select all

Connecting...0 | 35 | 0 | 3895
1 | 4294967295 | 0 | 0
2 | 4294967295 | 0 | 0
3 | 4294967295 | 0 | 0
4 | 4294967295 | 0 | 0
5 | 4294967295 | 0 | 0
6 | 4294967295 | 0 | 0
7 | 4294967295 | 0 | 0

Launch a melee game and you will be assured that it works.
That's it!

You can also use this command:

Code: Select all

wine bwapi-data/AI/ExampleAIClient.exe & wine InfectedStarCraft.exe; wineserver -k


As for ExampleAIModule it seems that I don't have enough knowledge to compile it. Namely I don't know exactly what compiler options I need to use to compile Dll.cpp and ExampleAIModule.cpp and at least do I need to compile them both. I'm really newbie in these things. I tried adding

Code: Select all

void ExampleAIModule::onStart() {
}
into Dll.cpp for every virtual void as it was described here and then compiled it like this:

Code: Select all

i486-mingw32-g++ -shared -L. -lBWAPI Dll.cpp -o Dll.dll
i486-mingw32-g++ -shared -L. -lBWAPI ExampleAIModule.cpp Dll.dll -o ExampleAIModule.dll

But BWAPI refuses this module. And finally I don't know if currently is it possible to launch and compile ExampleAIModule in Linux.

I have never written an AI, but I have lots of ideas, and now I wish I will manage to realise them.
So I wish the further versions of BWAPI will be compatible with WINE.
Sorry for such a big post, but I think it can be usefull.
krasi0
Posts: 254
Joined: Thu Dec 18, 2008 12:42 pm

Postby krasi0 » Fri Jan 27, 2012 11:32 am

[quote name='AleXoundOS' date='27 January 2012 - 07:40 AM' timestamp='1327642855' post='10696']
...
[/quote]
That's awesome, dude! Thanks from all the linux users :P
I will try to add this to the wiki or if I don't have access, ask Heinermann to do it.
Please keep us updated on any issues that you encounter.
Heinermann
Posts: 362
Joined: Thu Apr 26, 2007 12:42 am

Postby Heinermann » Sat Jan 28, 2012 3:58 pm

I changed the backslashes to forward slashes in the head revision so that a future tutorial does not need this step.

Also "Project Contributors" should have wiki access. I can give it to both of you (krasi0 should already have it though). I will need your google code account name/email.
EuPhobos
Posts: 4
Joined: Sun Feb 12, 2012 6:58 am

Postby EuPhobos » Sun Feb 12, 2012 7:03 am

Hi! Someone help me pls. I have problem to join BWAPI.dll to any Enjector, try Chaosloader, MPQDraft and InfectedStarcraft, they are one problem to run StarCraft, with BWAPI all them says:
"The problem occurred while trying to load the file:
fontfont.gid"
Without bwapi.dll they all runs perfectly under wine 1.3.37..
In which way to dig?
EuPhobos
Posts: 4
Joined: Sun Feb 12, 2012 6:58 am

Postby EuPhobos » Wed Feb 15, 2012 8:17 am

Solved! By using winject.exe
krasi0
Posts: 254
Joined: Thu Dec 18, 2008 12:42 pm

Postby krasi0 » Fri Feb 17, 2012 12:58 pm

There is a make file for mingw in bwapimingw-client to anyone who might be interested

Return to “BWAPI (wrappers in other languages / questions and announcements related to BWAPI itself)”

Who is online

Users browsing this forum: No registered users and 1 guest