Skip to content

Commit

Permalink
feat(mapview): Showing multi and f2p map zones
Browse files Browse the repository at this point in the history
  • Loading branch information
Pazaz committed Aug 4, 2024
1 parent 2449a81 commit 51cf71e
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 10 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ build/

loader/src/main/java/sig.java
loader/src/main/java/sign/signlink.java

mapview/src/main/java/sig.java

/worldmap.jag
/*.png
/*.raw
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ Thanks to these individuals' projects for shedding light on some things - this w
## Running

Because there are multiple entry points, instead of `gradle run` you have to execute `gradle client:run` or `gradle mapview:run` else it will launch both sequentially.

### Mapview Applet

1. Copy worldmap.jag to the root folder.
2. Run `gradle mapSig --args="worldmap.jag"`
3. Run `gradle mapview:run`
133 changes: 128 additions & 5 deletions mapview/src/main/java/mapview.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
@OriginalClass("mapview!mapview")
public final class mapview extends GameShell {

// 2005 mapview applet features
private static final boolean shouldDrawBorders = false;
private static final boolean shouldDrawLabels = true;

private static final boolean showMultiZones = false;
private static final boolean showFreeZones = false;

private boolean[][] objTiles;
private boolean[][] npcTiles;
private boolean[][] multiTiles;
private boolean[][] freeTiles;

// overworld
private final short startX = 3200;
private final short startZ = 3200;
Expand Down Expand Up @@ -72,10 +79,6 @@ public final class mapview extends GameShell {
@OriginalMember(owner = "mapview!mapview", name = "U", descriptor = "[[B")
private byte[][] locMapscenes;

private boolean[][] objTiles;

private boolean[][] npcTiles;

@OriginalMember(owner = "mapview!mapview", name = "X", descriptor = "Lmapview!j;")
private PixFont b12;

Expand Down Expand Up @@ -312,6 +315,20 @@ protected void load() {
this.npcTiles = new boolean[this.sizeX][this.sizeZ];
this.readNpcData(npcData, this.npcTiles);

try {
byte[] multiData = worldmap.read("multi.dat", null);
this.multiTiles = new boolean[this.sizeX][this.sizeZ];
this.readMultiData(multiData, this.multiTiles);
} catch (Exception ex) {
}

try {
byte[] freeData = worldmap.read("free.dat", null);
this.freeTiles = new boolean[this.sizeX][this.sizeZ];
this.readFreeData(freeData, this.freeTiles);
} catch (Exception ex) {
}

try {
for (int i = 0; i < 50; i++) {
this.imageMapscene[i] = new Pix8(worldmap, "mapscene", i);
Expand Down Expand Up @@ -445,6 +462,48 @@ private void readNpcData(byte[] data, boolean[][] npcs) {
}
}

private void readMultiData(byte[] data, boolean[][] multimap) {
int pos = 0;
while (pos < data.length) {
int mx = (data[pos++] & 0xFF) * 64 - this.originX;
int mz = (data[pos++] & 0xFF) * 64 - this.originZ;

if (mx > 0 && mz > 0 && mx + 64 < this.sizeX && mz + 64 < this.sizeZ) {
for (int x = 0; x < 64; x++) {
boolean[] map = multimap[x + mx];
int zIndex = this.sizeZ - mz - 1;

for (int z = -64; z < 0; z++) {
map[zIndex--] = data[pos++] == 1;
}
}
} else {
pos += 4096;
}
}
}

private void readFreeData(byte[] data, boolean[][] freemap) {
int pos = 0;
while (pos < data.length) {
int mx = (data[pos++] & 0xFF) * 64 - this.originX;
int mz = (data[pos++] & 0xFF) * 64 - this.originZ;

if (mx > 0 && mz > 0 && mx + 64 < this.sizeX && mz + 64 < this.sizeZ) {
for (int x = 0; x < 64; x++) {
boolean[] map = freemap[x + mx];
int zIndex = this.sizeZ - mz - 1;

for (int z = -64; z < 0; z++) {
map[zIndex--] = data[pos++] == 1;
}
}
} else {
pos += 4096;
}
}
}

@OriginalMember(owner = "mapview!mapview", name = "a", descriptor = "([B[[B)V")
private void readUnderlayData(@OriginalArg(0) byte[] data, @OriginalArg(1) byte[][] underlays) {
@Pc(3) int pos = 0;
Expand Down Expand Up @@ -614,6 +673,8 @@ protected void unload() {
this.locMapscenes = null;
this.objTiles = null;
this.npcTiles = null;
this.multiTiles = null;
this.freeTiles = null;
this.imageMapscene = null;
this.imageMapfunction = null;
this.imageMapdot0 = null;
Expand Down Expand Up @@ -1187,6 +1248,68 @@ private void drawMap(@OriginalArg(0) int left, @OriginalArg(1) int top, @Origina
}
}

if (showMultiZones) {
for (int x = 0; x < visibleX; x++) {
int startX = widthRatio * x >> 16;
int endX = widthRatio * (x + 1) >> 16;
int lengthX = endX - startX;
if (lengthX <= 0) {
continue;
}

startX += widthOffset;
endX += widthOffset;

boolean[] multi = this.multiTiles[x + left];
for (int y = 0; y < visibleY; y++) {
int startY = heightRatio * y >> 16;
int endY = heightRatio * (y + 1) >> 16;
int lengthY = endY - startY;
if (lengthY <= 0) {
continue;
}

startY += heightOffset;
endY += heightOffset;

if (multi[y + top]) {
Pix2D.fillRectTrans(startX, startY, lengthX, lengthY, 0xff0000, 96);
}
}
}
}

if (showFreeZones) {
for (int x = 0; x < visibleX; x++) {
int startX = widthRatio * x >> 16;
int endX = widthRatio * (x + 1) >> 16;
int lengthX = endX - startX;
if (lengthX <= 0) {
continue;
}

startX += widthOffset;
endX += widthOffset;

boolean[] free = this.freeTiles[x + left];
for (int y = 0; y < visibleY; y++) {
int startY = heightRatio * y >> 16;
int endY = heightRatio * (y + 1) >> 16;
int lengthY = endY - startY;
if (lengthY <= 0) {
continue;
}

startY += heightOffset;
endY += heightOffset;

if (free[y + top]) {
Pix2D.fillRectTrans(startX, startY, lengthX, lengthY, 0x00ff00, 96);
}
}
}
}

for (int i = 0; i < visibleMapFunctionCount; i++) {
this.imageMapfunction[this.visibleMapFunctions[i]].draw(this.visibleMapFunctionsX[i] - 7, this.visibleMapFunctionsY[i] - 7);
}
Expand Down
5 changes: 0 additions & 5 deletions mapview/src/main/java/sig.java

This file was deleted.

5 changes: 5 additions & 0 deletions tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ tasks.register('sig', JavaExec) {
args = ['client/build/libs/client.jar']
}

tasks.register('mapSig', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'lostcity.tools.MapviewSig'
}

tasks.register('removeAnnotations', JavaExec) {
classpath = sourceSets.main.runtimeClasspath
mainClass = 'lostcity.tools.RemoveAnnotations'
Expand Down

0 comments on commit 51cf71e

Please sign in to comment.