From 9adfb183d6339a53e0b63d8202ca72772afd4916 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 29 May 2017 21:03:50 -0400 Subject: [PATCH] cache: add loaders for archive 0 of world map index --- .../cache/definitions/WorldMapDefinition.java | 44 +++++ .../cache/definitions/WorldMapType0.java | 39 ++++ .../cache/definitions/WorldMapType1.java | 39 ++++ .../cache/definitions/WorldMapType2.java | 35 ++++ .../cache/definitions/WorldMapType3.java | 43 +++++ .../cache/definitions/WorldMapTypeBase.java | 30 +++ .../definitions/loaders/WorldMapLoader.java | 179 ++++++++++++++++++ .../runelite/cache/WorldMapDumperTest.java | 80 ++++++++ 8 files changed, 489 insertions(+) create mode 100644 cache/src/main/java/net/runelite/cache/definitions/WorldMapDefinition.java create mode 100644 cache/src/main/java/net/runelite/cache/definitions/WorldMapType0.java create mode 100644 cache/src/main/java/net/runelite/cache/definitions/WorldMapType1.java create mode 100644 cache/src/main/java/net/runelite/cache/definitions/WorldMapType2.java create mode 100644 cache/src/main/java/net/runelite/cache/definitions/WorldMapType3.java create mode 100644 cache/src/main/java/net/runelite/cache/definitions/WorldMapTypeBase.java create mode 100644 cache/src/main/java/net/runelite/cache/definitions/loaders/WorldMapLoader.java create mode 100644 cache/src/test/java/net/runelite/cache/WorldMapDumperTest.java diff --git a/cache/src/main/java/net/runelite/cache/definitions/WorldMapDefinition.java b/cache/src/main/java/net/runelite/cache/definitions/WorldMapDefinition.java new file mode 100644 index 0000000000..e7e2d68dbc --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/WorldMapDefinition.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions; + +import java.util.List; +import net.runelite.cache.region.Position; + +public class WorldMapDefinition +{ + public String name; + public int field450; + public int field451; + public int fileId; + public int field453; + public int field454; + public int field456; + public boolean field457; + public List field458; + public String safeName; + public Position position; + public int field463; +} diff --git a/cache/src/main/java/net/runelite/cache/definitions/WorldMapType0.java b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType0.java new file mode 100644 index 0000000000..c69c0d873a --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType0.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions; + +public class WorldMapType0 implements WorldMapTypeBase +{ + public int field600; + public int field601; + public int field602; + public int field603; + public int field604; + public int field605; + public int field606; + public int field607; + public int field608; + public int field609; +} diff --git a/cache/src/main/java/net/runelite/cache/definitions/WorldMapType1.java b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType1.java new file mode 100644 index 0000000000..c75e23760b --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType1.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions; + +public class WorldMapType1 implements WorldMapTypeBase +{ + public int field424; + public int field425; + public int field426; + public int field427; + public int field428; + public int field429; + public int field431; + public int field433; + public int field434; + public int field435; +} diff --git a/cache/src/main/java/net/runelite/cache/definitions/WorldMapType2.java b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType2.java new file mode 100644 index 0000000000..6ff63d870d --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType2.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions; + +public class WorldMapType2 implements WorldMapTypeBase +{ + public int field510; + public int field511; + public int field512; + public int field514; + public int field515; + public int field519; +} diff --git a/cache/src/main/java/net/runelite/cache/definitions/WorldMapType3.java b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType3.java new file mode 100644 index 0000000000..d44175864f --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/WorldMapType3.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions; + +public class WorldMapType3 implements WorldMapTypeBase +{ + public int field376; + public int field377; + public int field378; + public int field379; + public int field380; + public int field381; + public int field382; + public int field383; + public int field384; + public int field385; + public int field386; + public int field387; + public int field388; + public int field389; +} diff --git a/cache/src/main/java/net/runelite/cache/definitions/WorldMapTypeBase.java b/cache/src/main/java/net/runelite/cache/definitions/WorldMapTypeBase.java new file mode 100644 index 0000000000..d24d6d63f3 --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/WorldMapTypeBase.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions; + +public interface WorldMapTypeBase +{ + +} diff --git a/cache/src/main/java/net/runelite/cache/definitions/loaders/WorldMapLoader.java b/cache/src/main/java/net/runelite/cache/definitions/loaders/WorldMapLoader.java new file mode 100644 index 0000000000..15ec975d6d --- /dev/null +++ b/cache/src/main/java/net/runelite/cache/definitions/loaders/WorldMapLoader.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache.definitions.loaders; + +import java.util.LinkedList; +import net.runelite.cache.definitions.WorldMapDefinition; +import net.runelite.cache.definitions.WorldMapType0; +import net.runelite.cache.definitions.WorldMapType1; +import net.runelite.cache.definitions.WorldMapType2; +import net.runelite.cache.definitions.WorldMapType3; +import net.runelite.cache.definitions.WorldMapTypeBase; +import net.runelite.cache.io.InputStream; +import net.runelite.cache.region.Position; + +public class WorldMapLoader +{ + public WorldMapDefinition load(byte[] b, int fileId) + { + WorldMapDefinition def = new WorldMapDefinition(); + InputStream in = new InputStream(b); + + def.fileId = fileId; + def.safeName = in.readString(); + def.name = in.readString(); + + int packedPos = in.readInt(); + if (packedPos == -1) + { + def.position = new Position(-1, -1, -1); + } + else + { + int y = packedPos >> 28 & 3; + int x = packedPos >> 14 & 16383; + int z = packedPos & 16383; + def.position = new Position(x, y, z); + } + + def.field450 = in.readInt(); + in.readUnsignedByte(); + def.field457 = in.readUnsignedByte() == 1; + def.field451 = in.readUnsignedByte(); + int var3 = in.readUnsignedByte(); + def.field458 = new LinkedList(); + + for (int var4 = 0; var4 < var3; ++var4) + { + def.field458.add(this.loadType(in)); + } + + return def; + } + + private WorldMapTypeBase loadType(InputStream var1) + { + int var2 = var1.readUnsignedByte(); + // field397 = new class27(1, (byte)0); + // field390 = new class27(2, (byte)1); + // field399 = new class27(3, (byte)2); + // field393 = new class27(0, (byte)3); + WorldMapTypeBase base; + switch (var2) + { + case 0: + // type 1 + base = load1(var1); + break; + case 1: + // type 2 + base = load2(var1); + break; + case 2: + // type 3 + base = load3(var1); + break; + case 3: + // type 0 + base = load0(var1); + break; + default: + throw new IllegalStateException(); + } + return base; + } + + private WorldMapTypeBase load0(InputStream in) + { + WorldMapType0 wm = new WorldMapType0(); + + wm.field606 = in.readUnsignedByte(); + wm.field605 = in.readUnsignedByte(); + wm.field601 = in.readUnsignedShort(); + wm.field602 = in.readUnsignedByte(); + wm.field603 = in.readUnsignedShort(); + wm.field607 = in.readUnsignedByte(); + wm.field604 = in.readUnsignedShort(); + wm.field600 = in.readUnsignedByte(); + wm.field608 = in.readUnsignedShort(); + wm.field609 = in.readUnsignedByte(); + + return wm; + } + + private WorldMapTypeBase load1(InputStream in) + { + WorldMapType1 wm = new WorldMapType1(); + + wm.field434 = in.readUnsignedByte(); + wm.field424 = in.readUnsignedByte(); + wm.field425 = in.readUnsignedShort(); + wm.field426 = in.readUnsignedShort(); + wm.field427 = in.readUnsignedShort(); + wm.field431 = in.readUnsignedShort(); + wm.field429 = in.readUnsignedShort(); + wm.field428 = in.readUnsignedShort(); + wm.field433 = in.readUnsignedShort(); + wm.field435 = in.readUnsignedShort(); + + return wm; + } + + private WorldMapTypeBase load2(InputStream in) + { + WorldMapType2 wm = new WorldMapType2(); + + wm.field519 = in.readUnsignedByte(); + wm.field511 = in.readUnsignedByte(); + wm.field510 = in.readUnsignedShort(); + wm.field512 = in.readUnsignedShort(); + wm.field514 = in.readUnsignedShort(); + wm.field515 = in.readUnsignedShort(); + + return wm; + } + + private WorldMapTypeBase load3(InputStream in) + { + WorldMapType3 wm = new WorldMapType3(); + + wm.field387 = in.readUnsignedByte(); + wm.field377 = in.readUnsignedByte(); + wm.field378 = in.readUnsignedShort(); + wm.field382 = in.readUnsignedByte(); + wm.field376 = in.readUnsignedByte(); + wm.field383 = in.readUnsignedShort(); + wm.field385 = in.readUnsignedByte(); + wm.field379 = in.readUnsignedByte(); + wm.field380 = in.readUnsignedShort(); + wm.field386 = in.readUnsignedByte(); + wm.field388 = in.readUnsignedByte(); + wm.field381 = in.readUnsignedShort(); + wm.field384 = in.readUnsignedByte(); + wm.field389 = in.readUnsignedByte(); + + return wm; + } +} diff --git a/cache/src/test/java/net/runelite/cache/WorldMapDumperTest.java b/cache/src/test/java/net/runelite/cache/WorldMapDumperTest.java new file mode 100644 index 0000000000..1b67b788ea --- /dev/null +++ b/cache/src/test/java/net/runelite/cache/WorldMapDumperTest.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.cache; + +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import net.runelite.cache.definitions.WorldMapDefinition; +import net.runelite.cache.definitions.loaders.WorldMapLoader; +import net.runelite.cache.fs.Archive; +import net.runelite.cache.fs.Index; +import net.runelite.cache.fs.Store; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class WorldMapDumperTest +{ + private static final Logger logger = LoggerFactory.getLogger(WorldMapDumperTest.class); + + @Rule + public TemporaryFolder folder = StoreLocation.getTemporaryFolder(); + + private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); + + @Test + public void extract() throws IOException + { + File base = StoreLocation.LOCATION, + outDir = folder.newFolder(); + + int count = 0; + + try (Store store = new Store(base)) + { + store.load(); + + Index index = store.getIndex(IndexType.WORLDMAP); + Archive archive = index.getArchive(0); // there is also archive 1/2, but their data format is not this + + for (net.runelite.cache.fs.File file : archive.getFiles()) + { + WorldMapLoader loader = new WorldMapLoader(); + WorldMapDefinition def = loader.load(file.getContents(), file.getFileId()); + + Files.write(gson.toJson(def), new File(outDir, file.getFileId() + ".json"), Charset.defaultCharset()); + ++count; + } + } + + logger.info("Dumped {} world map data to {}", count, outDir); + } +}