From 51cf71e0659a9b2883083f7cc68d703a7a7cf6d9 Mon Sep 17 00:00:00 2001 From: Pazaz Date: Sun, 4 Aug 2024 15:08:23 -0400 Subject: [PATCH] feat(mapview): Showing multi and f2p map zones --- .gitignore | 6 ++ README.md | 6 ++ mapview/src/main/java/mapview.java | 133 +++++++++++++++++++++++++++-- mapview/src/main/java/sig.java | 5 -- tools/build.gradle | 5 ++ 5 files changed, 145 insertions(+), 10 deletions(-) delete mode 100644 mapview/src/main/java/sig.java diff --git a/.gitignore b/.gitignore index 6c05df80..16699c97 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/README.md b/README.md index e7f4805a..e6dcbbf9 100644 --- a/README.md +++ b/README.md @@ -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` diff --git a/mapview/src/main/java/mapview.java b/mapview/src/main/java/mapview.java index 589e9d21..54d28342 100644 --- a/mapview/src/main/java/mapview.java +++ b/mapview/src/main/java/mapview.java @@ -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; @@ -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; @@ -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); @@ -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; @@ -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; @@ -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); } diff --git a/mapview/src/main/java/sig.java b/mapview/src/main/java/sig.java deleted file mode 100644 index 578a6d3d..00000000 --- a/mapview/src/main/java/sig.java +++ /dev/null @@ -1,5 +0,0 @@ -public class sig { - public static final int len = 324757; - - public static final int[] sha = { -84, -71, 57, -4, 22, -94, -89, 99, -64, -76, 60, -108, 66, -91, 74, -108, 44, 38, -127, 44 }; -} \ No newline at end of file diff --git a/tools/build.gradle b/tools/build.gradle index 11efdca1..2d0226bd 100644 --- a/tools/build.gradle +++ b/tools/build.gradle @@ -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'