|
1 | 1 | package bwapi; |
2 | 2 |
|
| 3 | +import com.sun.jna.Native; |
3 | 4 | import com.sun.jna.platform.win32.Kernel32; |
| 5 | +import com.sun.jna.win32.W32APIOptions; |
4 | 6 |
|
| 7 | +import java.io.FileNotFoundException; |
| 8 | +import java.io.IOException; |
| 9 | +import java.io.RandomAccessFile; |
5 | 10 | import java.nio.ByteBuffer; |
6 | 11 | import java.nio.ByteOrder; |
7 | 12 | import java.nio.CharBuffer; |
@@ -65,6 +70,12 @@ public void update(EventHandler handler) throws Throwable { |
65 | 70 | handler.operation(data.event(i)); |
66 | 71 | } |
67 | 72 |
|
| 73 | + interface MappingKernel extends Kernel32 { |
| 74 | + MappingKernel INSTANCE = Native.loadLibrary(MappingKernel.class, W32APIOptions.DEFAULT_OPTIONS); |
| 75 | + |
| 76 | + HANDLE OpenFileMapping(int desiredAccess, boolean inherit, String name); |
| 77 | + } |
| 78 | + |
68 | 79 | public interface EventHandler { |
69 | 80 | void operation(GameData.Event event); |
70 | 81 | } |
@@ -113,6 +124,34 @@ public Shape(int type, int coordType, int x1, int y1, int x2, int y2, int extra1 |
113 | 124 | } |
114 | 125 | } |
115 | 126 |
|
| 127 | + class LittleEndianPipe { |
| 128 | + RandomAccessFile pipe; |
| 129 | + |
| 130 | + LittleEndianPipe(String name, String mode) throws FileNotFoundException { |
| 131 | + pipe = new RandomAccessFile(name, mode); |
| 132 | + } |
| 133 | + |
| 134 | + final int readByte() throws IOException { |
| 135 | + return pipe.readByte(); |
| 136 | + } |
| 137 | + |
| 138 | + final void writeByte(int b) throws IOException { |
| 139 | + pipe.writeByte(b); |
| 140 | + } |
| 141 | + |
| 142 | + final int readInt() throws IOException { |
| 143 | + int b1 = readByte(), b2 = readByte(), b3 = readByte(), b4 = readByte(); |
| 144 | + return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1; |
| 145 | + } |
| 146 | + |
| 147 | + final void writeInt(int i) throws IOException { |
| 148 | + writeByte(i >> 24); |
| 149 | + writeByte((i >> 16) & 0xff); |
| 150 | + writeByte((i >> 8) & 0xff); |
| 151 | + writeByte(i & 0xff); |
| 152 | + } |
| 153 | + } |
| 154 | + |
116 | 155 | public final class GameData { |
117 | 156 | private static final int MetaOffset = 0; |
118 | 157 | private static final int ForceOffset = 0x18; |
|
0 commit comments