Skip to content

Commit a15aa45

Browse files
author
Jasper Geurtz
committed
Support OpenBW client connection on macOS (including Apple Silicon)
1 parent 484be45 commit a15aa45

3 files changed

Lines changed: 42 additions & 14 deletions

File tree

‎build_with_openbw.md‎

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,30 @@ unzip starcraft.zip "maps/BroodWar/ICCup/ICCup Destination 1.1.scx"
2626
BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP="maps/BroodWar/ICCup/ICCup Destination 1.1.scx" ./bin/BWAPILauncher
2727
```
2828

29-
Compiling and running openbw on macos with client support (not working):
29+
Compiling and running openbw on macos with client support:
3030

3131
```bash
32-
brew install cmake sdl2 sdl2_mixer gcc
32+
# Download build deps
33+
brew install cmake sdl2 sdl2_mixer
34+
35+
# Build openbw with client support
36+
git clone https://github.com/basil-ladder/openbw
37+
git clone -b linux-client-support https://github.com/basil-ladder/bwapi
38+
cd bwapi
39+
mkdir build
40+
cd build
41+
cmake .. -DCMAKE_BUILD_TYPE=Release -DOPENBW_DIR=../../openbw -DOPENBW_ENABLE_UI=1 -DCMAKE_POLICY_VERSION_MINIMUM=3.5
42+
make -j4
43+
44+
# Download runtime deps
45+
curl -L "https://web.archive.org/web/20250823150201id_/https://www.cs.mun.ca/~dchurchill/starcraftaicomp/files/Starcraft_1161.zip" -o starcraft.zip
46+
unzip starcraft.zip patch_rt.mpq BROODAT.MPQ STARDAT.MPQ
47+
mv patch_rt.mpq Patch_rt.mpq.tmp && mv Patch_rt.mpq.tmp Patch_rt.mpq
48+
mv BROODAT.MPQ BrooDat.mpq.tmp && mv BrooDat.mpq.tmp BrooDat.mpq
49+
mv STARDAT.MPQ StarDat.mpq.tmp && mv StarDat.mpq.tmp StarDat.mpq
50+
51+
# Run openbw using the map: Destination 1.1.scx
52+
unzip starcraft.zip "maps/BroodWar/ICCup/ICCup Destination 1.1.scx"
3353

34-
cmake .. -D CMAKE_C_COMPILER=gcc-11 -D CMAKE_CXX_COMPILER=g++-11 -DCMAKE_BUILD_TYPE=Release -DOPENBW_DIR=../../openbw -DOPENBW_ENABLE_UI=1
35-
make -j4
54+
BWAPI_CONFIG_AUTO_MENU__RACE=Terran BWAPI_CONFIG_AUTO_MENU__MAP="maps/BroodWar/ICCup/ICCup Destination 1.1.scx" OPENBW_ENABLE_UI=1 ./bin/BWAPILauncher
3655
```

‎pom.xml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,14 @@
144144
</profiles>
145145
<dependencies>
146146
<dependency>
147-
<groupId>no.fiken.oss.junixsocket</groupId>
147+
<groupId>com.kohlschutter.junixsocket</groupId>
148148
<artifactId>junixsocket-common</artifactId>
149-
<version>1.0.2</version>
149+
<version>2.10.1</version>
150150
</dependency>
151151
<dependency>
152-
<groupId>no.fiken.oss.junixsocket</groupId>
152+
<groupId>com.kohlschutter.junixsocket</groupId>
153153
<artifactId>junixsocket-native-common</artifactId>
154-
<version>1.0.2</version>
154+
<version>2.10.1</version>
155155
</dependency>
156156

157157
<dependency>

‎src/main/java/bwapi/ClientConnectionPosix.java‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ClientConnectionPosix implements ClientConnection {
2424
interface LibCExt extends LibC {
2525
LibCExt INSTANCE = Native.load(LibCExt.class);
2626

27-
Pointer mmap(Pointer addr, int length, int prot, int flags, int fd, int offset) throws LastErrorException;
27+
Pointer mmap(Pointer addr, long length, int prot, int flags, int fd, long offset) throws LastErrorException;
2828
}
2929

3030
interface PosixShm extends Library {
@@ -57,17 +57,26 @@ public void disconnect() {
5757
public WrappedBuffer getGameTable() {
5858
int fd = PosixShm.INSTANCE.shm_open("/bwapi_shared_memory_game_list", Fcntl.O_RDWR, 0);
5959
if (fd < 0) throw new IllegalStateException("SHM not found");
60-
Pointer gameTableView = LibCExt.INSTANCE.mmap(Pointer.NULL, GameTable.SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
61-
return new WrappedBuffer(gameTableView, GameTable.SIZE);
60+
try {
61+
Pointer gameTableView = LibCExt.INSTANCE.mmap(Pointer.NULL, GameTable.SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
62+
return new WrappedBuffer(gameTableView, GameTable.SIZE);
63+
} finally {
64+
LibCExt.INSTANCE.close(fd);
65+
}
6266
}
6367

6468
@Override
6569
public WrappedBuffer getSharedMemory(int serverProcID) {
6670
String sharedMemoryName = "/bwapi_shared_memory_" + serverProcID;
6771
try {
68-
Pointer mapFileView = LibCExt.INSTANCE.mmap(Pointer.NULL, ClientData.GameData.SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, LibRT.INSTANCE.shm_open(sharedMemoryName, Fcntl.O_RDWR, 0),
69-
0);
70-
return new WrappedBuffer(mapFileView, ClientData.GameData.SIZE);
72+
int fd = PosixShm.INSTANCE.shm_open(sharedMemoryName, Fcntl.O_RDWR, 0);
73+
if (fd < 0) throw new IllegalStateException("SHM not found");
74+
try {
75+
Pointer mapFileView = LibCExt.INSTANCE.mmap(Pointer.NULL, ClientData.GameData.SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
76+
return new WrappedBuffer(mapFileView, ClientData.GameData.SIZE);
77+
} finally {
78+
LibCExt.INSTANCE.close(fd);
79+
}
7180
} catch (Exception e) {
7281
throw new SharedMemoryConnectionException(sharedMemoryName, e);
7382
}

0 commit comments

Comments
 (0)