https://pastebin.com/R90wcUNs
TODO: remove dead links etc.
We assume that StarCraft/Broodwar already works with your wine configuration and BWAPI 3.7.4 injects fine with InfectedStarCraft.
Note, in this guide:
- Broodwar installation path is called
$BroodwarPath
- Wine configuration path is called
$WINEPREFIX
- BWAPI svn sources path is called
$BWAPI_SOURCES
- The path
/usr/lib32/
means a place where 32bit libraries are stored. It depends on your distribution. Or if you are using 32bit distribution it should be always/usr/lib/
Some additional tools required: svn (for downloading source), dos2unix (for converting CRLF to LF line breaks).
Sometimes it is useful to have a separate wine configuration (called WINEPREFIX
), for example, to have unique settings for different applications. I recommend to do everything related to BWAPI under "~/.wine-bwapi" prefix. So you have to set this environmental variable in every bash/terminal you work with BWAPI:export WINEPREFIX=~/.wine-bwapi
Everything was tested with:
- Linux 3.4.8
- gcc 4.7.1
- wine 1.5.10
The best way to compile and run C++ client is using winelib, because it allows to use Linux API and the resulting binary is ELF. Btw, it also allows to use WinAPI in the same program too.
Part One: C++ client (winelib)
- Download BWAPI r4160 sources:
svn -r 4160 checkout http://bwapi.googlecode.com/svn/ $BWAPI_SOURCES
- Apply the patch:
Download the patch into $BWAPI_SOURCES
and execute:
cd $BWAPI_SOURCES
find . -not -type d -exec dos2unix -b --d2u "{}" \;
zcat BWAPI-r4160-winelib.patch.gz | patch -p1
- The patch contains some minor changes to allow winelib compile the client library and several Makefiles.
- Without converting CRLF to LF line breaks the patch will fail. You can use any other means to do the conversion instead of dos2unix.
- If everything went ok, it should look like:
patching file trunk/bwapi/ExampleAIClient/Source/Makefile
patching file trunk/bwapi/ExampleAIClient/Source/Makefile.mingw
patching file trunk/bwapi/ExampleAIModule/Source/ExampleAIModule.cpp
patching file trunk/bwapi/ExampleAIModule/Source/Makefile
patching file trunk/bwapi/include/BWAPI/Color.h
patching file trunk/bwapi/mingw-client/Makefile
patching file trunk/bwapi/mingw-client/Makefile.mingw
patching file trunk/bwapi/svnrev.h
patching file trunk/bwapi/Util/Source/Util/Gnu.h
patching file trunk/bwapi/Util/Source/Util/Types.h
- Compile BWAPI library:
cd $BWAPI_SOURCES/trunk/bwapi/mingw-client/
make
ln -s $(pwd)/libBWAPI.dll.so /usr/lib32/
- For 32bit OS soft link should be placed in /usr/lib/ . On 64bit OS it depends on your distribution, but usually /usr/lib32/ .
- "march" and "mtune" optimization parameters in Makefiles are used in order to get best performance for your architecture and processor. Use "-O3" with caution.
- Use "make clean" to delete compiled output if needed
- Compile client program:
cd $BWAPI_SOURCES/trunk/bwapi/ExampleAIClient/Source/
make
ln -s $(pwd)/ExampleAIClient.exe.so $BroodwarPath/bwapi-data/AI/
[*][b]Launch Broodwar with client:[/b]
Basically it can be done executing:
echo BWAPI.dll > InfectedStarCraft.exe.injlist
wine InfectedStarCraft.exe &
wine bwapi-data/AI/ExampleAIClient.exe.so
Or you can simply use [color="#2E8B57"][b]launch_winelib_client[/b][/color] script from here considering that you have copied everything from archive to $BroodwarPath
.
If you get an error:wine: Bad EXE format for ...
It can be due to missing libraries linked to your client program. Check it using ldd, for example: ldd $BroodwarPath/bwapi-data/AI/ExampleAIClient.exe.so
BWTA library:
BWTA.lib
static library cannot be linked using mingw or winelib
.
It needs a linker that understands the MSVC linker format.
Though it is possible to compile BWTA library using winelib
,
unfortunately winelib compiled BWTA crashes in CGAL when analyzing.
But this may change if someone familiar with BWTA code corrects the bugs.
Steps to compile BWTA and reproduce the crash:
BWTA depends on these libraries: CGAL, GMP, MPFR, Boost.
(You need to install 32bit versions of these libraries. I used CGAL 4.0.2, GMP 5.0.5, MPFR 3.1.1, Boost 1.50).
- Download BWTA r187 sources:
svn checkout http://bwta.googlecode.com/svn/trunk/ BWTA-r187
- Apply the patch:
download the patch
into BWTA sources path and execute there:find . -not -type d -exec dos2unix -b --d2u "{}" \; zcat BWTA-r187-winelib.patch.gz | patch -p1
Compile BWTA library:
Correct INCLUDEBWAPIPATH in Makefile if needed, then execute:
make
ln -s $(pwd)/Release/libBWTA.dll.so /usr/lib32/
Compile client program that uses BWTA:
Uncomment lines related to BWTA from ExampleAIClient.cpp.
Edit Makefile for client and add BWTA include path to compiler flags
(CXXFLAGS) and "-lBWTA" to the linker (CXXLIBS). Then compile.
Launch Broodwar with client and try to analyze the map:
After several seconds of game the crash will occur.
May be it is possible to use VC++ compiler under wine, but then there
is no benefit from using Linux.
So currently only Java client is capable of using BWTA under Linux
(because it does not require to use any static libraries but uses
client-bridge shared library).
Part Two: C++ client (mingw)
- Download BWAPI r4160 sources:[/b]
svn -r 4160 checkout http://bwapi.googlecode.com/svn/ $BWAPI_SOURCES
- Apply the patch:[/b]
Download the patch
into $BWAPI_SOURCES and execute:
cd $BWAPI_SOURCES
find . -not -type d -exec dos2unix -b --d2u "{}" \;
zcat BWAPI-r4160-winelib.patch.gz | patch -p1
- The patch contains some minor changes to allow winelib compile the
client library and several Makefiles. - Without converting CRLF to LF line breaks the patch will fail.
You can use any other means to do the conversion instead of dos2unix. - If everything went ok, it should look like:
patching file trunk/bwapi/ExampleAIClient/Source/Makefile patching file trunk/bwapi/ExampleAIClient/Source/Makefile.mingw patching file trunk/bwapi/ExampleAIModule/Source/ExampleAIModule.cpp patching file trunk/bwapi/ExampleAIModule/Source/Makefile patching file trunk/bwapi/include/BWAPI/Color.h patching file trunk/bwapi/mingw-client/Makefile patching file trunk/bwapi/mingw-client/Makefile.mingw patching file trunk/bwapi/svnrev.h patching file trunk/bwapi/Util/Source/Util/Gnu.h patching file trunk/bwapi/Util/Source/Util/Types.h
Compile BWAPI library:
cd $BWAPI_SOURCES/trunk/bwapi/mingw-client/
make -f Makefile.mingw
ln -s $(pwd)/libBWAPI.dll $WINEPREFIX/drive_c/windows/
-
"march" and "mtune" optimization parameters in Makefiles are used in order to get best performance for your architecture and processor. Use "-O3" with caution.
-
Use "make -f Makefile.mingw clean" to delete compiled output if needed
-
Compile client program:
cd $BWAPI_SOURCES/trunk/bwapi/ExampleAIClient/Source/ make -f Makefile.mingw ln -s $(pwd)/ExampleAIClient.exe $BroodwarPath/bwapi-data/AI/
-
Launch Broodwar with client:
Basically it can be done executing:echo BWAPI.dll > InfectedStarCraft.exe.injlist wine InfectedStarCraft.exe & wine bwapi-data/AI/ExampleAIClient.exe
Or you can simply use
launch_mingw_client
script from
here
considering that you have copied everything from archive to $BroodwarPath.
Part Three: C++ module (mingw) [does not work]
[list=1]
[][b]Download BWAPI r4160 sources:[/b][xml]svn -r 4160 checkout http://bwapi.googlecode.com/svn/ $BWAPI_SOURCES[/xml]
[][b]Apply the patch:[/b]
Download the [url="http://www.broodwarai.com/forums/index.php?app=core&module=attach§ion=attach&attach_id=3087"]patch[/url] into $BWAPI_SOURCES and execute:[xml]cd $BWAPI_SOURCES
find . -not -type d -exec dos2unix -b --d2u "{}" \;
zcat BWAPI-r4160-winelib.patch.gz | patch -p1[/xml]
[][b]Compile BWAPI library:[/b][xml]cd $BWAPI_SOURCES/trunk/bwapi/mingw-client/
make -f Makefile.mingw
ln -s $(pwd)/libBWAPI.dll $WINEPREFIX/drive_c/windows/[/xml]
[][b]Compile module program:[/b][xml]cd $BWAPI_SOURCES/trunk/bwapi/ExampleAIModule/Source/
make
ln -s $(pwd)/ExampleAIModule.dll $BroodwarPath/bwapi-data/AI/[/xml]
[*][b]Launch Broodwar with module:[/b]
Basically it can be done executing:[xml]echo BWAPI.dll > InfectedStarCraft.exe.injlist
wine InfectedStarCraft.exe[/xml]Or you can simply use [color="#2E8B57"][b]launch_mingw_module[/b][/color] script from [url="http://www.broodwarai.com/forums/index.php?app=core&module=attach§ion=attach&attach_id=3086"]here[/url] considering that you have copied everything from archive to $BroodwarPath.
The game will crash immediately after start. May be it occurs when it attempts to get address of onUnitCreate. And probably the implementation of vtable differs between different compilers. Or compiler/linker options are wrong...
[/list][hr]
[size="5"][center]Part Four: [b]Java client (wine)[/b][/center][/size]
[list=1]
[*][b]Install JDK7 (Java Development Kit 7) package for your distribution.[/b]
[][b]Download and install [url="http://www.oracle.com/technetwork/java/javase/downloads/java-se-jre-7-download-432155.html"]Oracle JRE7 for windows:[/url][/b][xml]wine jre-7-windows-i586.exe[/xml]
[][b]Download and extract JNI-BWAPI 0.2.2 (r29) (Compatible with BWAPI 3.7.2):[/b]
Assume $JNI_BWAPI is the path of JNI-BWAPI extracted archive release. For extracting 7z archive P7ZIP tool is used here.[xml]wget "http://jnibwapi.googlecode.com/files/jni-bwapi-0.2.2%2Bdependencies.7z"
7z x -o$JNI_BWAPI jni-bwapi-0.2.2+dependencies.7z
ln -s $JNI_BWAPI/release/client-bridge-x86.dll $WINEPREFIX/drive_c/windows/[/xml]Also check that GMP and MPFR libraries are present in $WINEPREFIX/drive_c/windows/ path (they are released with BWAPI).
[*][b]Compile javabot:[/b][xml]cd $JNI_BWAPI/src/
mkdir META-INF
echo -e Manifest-Version: 1.0'\n'Main-Class: javabot.JavaBot > META-INF/MANIFEST.MF
cd javabot/model/
javac -cp .. *.java
cd ../../
cd javabot/types/
javac -cp .. *.java
cd ../../
cd javabot/util/
javac -cp .. *.java
cd ../../
cd javabot/
javac -cp .. *.java
cd ../
jar cmf META-INF/MANIFEST.MF javabot.jar javabot/
ln -s $(pwd)/javabot.jar $BroodwarPath/bwapi-data/AI/[/xml]
[*][b]Launch Broodwar with java client[/b]
Because the latest JNI-BWAPI release supports only BWAPI 3.7.2, BWAPI.dll of 4025 revision is used here.
[xml]echo BWAPI.dll_4025 > InfectedStarCraft.exe.injlist
wine InfectedStarCraft.exe &
cd ./bwapi-data/AI/
wine java -jar javabot.jar[/xml]Or you can simply use [color="#2E8B57"][b]launch_jni_client[/b][/color] script from [url="http://www.broodwarai.com/forums/index.php?app=core&module=attach§ion=attach&attach_id=3086"]here[/url] considering that you have copied everything from archive to $BroodwarPath. The [url="http://www.broodwarai.com/forums/index.php?app=core&module=attach§ion=attach&attach_id=3086"]archive[/url] already contains BWAPI 4025 revision dll.
For the first time the game will freeze because of BWTA analyzing the map. And then you will see execution of 5th Pool.
[/list][hr]
[cutoff]
(http://stackoverflow.com/questions/2472924/linking-to-msvc-dll-from-mingw
http://www.mingw.org/wiki/CreateImportLibraries
ftp://ftp.winehq.org/pub/wine/docs/en/winelib-guide.html
http://www.transmissionzero.co.uk/computing/advanced-mingw-dll-topics/).
[/cutoff]
I could miss something. Please, feel free to ask questions.
Attached files:
[attachment=3086:InfectedStarCraft+launch.tar.gz]
[attachment=3087:BWAPI-r4160-winelib.patch.gz]
[attachment=3088:BWTA-r187-winelib.patch.gz]