Add "Location" loading, draw on map
This commit is contained in:
@@ -27,15 +27,19 @@
|
||||
* (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.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.runelite.cache.fs.Archive;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.region.Region;
|
||||
import net.runelite.cache.util.XteaKeyManager;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -48,12 +52,15 @@ public class MapDumperTest
|
||||
private static final Logger logger = LoggerFactory.getLogger(MapDumperTest.class);
|
||||
|
||||
private static final int MAX_REGIONS = 32768;
|
||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void dump() throws IOException
|
||||
private final List<Region> regions = new ArrayList<>();
|
||||
|
||||
//@Test
|
||||
public void dumpRaw() throws IOException
|
||||
{
|
||||
File base = StoreLocation.LOCATION,
|
||||
outDir = folder.newFolder();
|
||||
@@ -68,17 +75,19 @@ public class MapDumperTest
|
||||
for (int i = 0; i < MAX_REGIONS; i++)
|
||||
{
|
||||
int[] keys = keyManager.getKeys(i);
|
||||
|
||||
|
||||
int x = i >> 8;
|
||||
int y = i & 0xFF;
|
||||
|
||||
Archive map = index.findArchiveByName("m" + x + "_" + y);
|
||||
Archive land = index.findArchiveByName("l" + x + "_" + y);
|
||||
|
||||
|
||||
assert (map == null) == (land == null);
|
||||
|
||||
if (map == null || land == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assert map.getFiles().size() == 1;
|
||||
assert land.getFiles().size() == 1;
|
||||
@@ -99,10 +108,12 @@ public class MapDumperTest
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.warn("Unable to decompress and load land " + x + "/" + y + " (bad keys?)", ex);
|
||||
logger.info("Unable to decompress and load land " + x + "," + y + " (bad keys?)", ex);
|
||||
continue;
|
||||
}
|
||||
|
||||
logger.info("Decrypted region {} coords {},{}", i, x, y);
|
||||
|
||||
data = land.getFiles().get(0).getContents();
|
||||
|
||||
Files.write(data, new File(outDir, "l" + x + "_" + y + ".dat"));
|
||||
@@ -111,4 +122,79 @@ public class MapDumperTest
|
||||
}
|
||||
}
|
||||
|
||||
private void loadRegions(Store store) throws IOException
|
||||
{
|
||||
Index index = store.getIndex(IndexType.MAPS);
|
||||
XteaKeyManager keyManager = index.getXteaManager();
|
||||
|
||||
for (int i = 0; i < MAX_REGIONS; ++i)
|
||||
{
|
||||
int x = i >> 8;
|
||||
int y = i & 0xFF;
|
||||
|
||||
Archive map = index.findArchiveByName("m" + x + "_" + y);
|
||||
Archive land = index.findArchiveByName("l" + x + "_" + y);
|
||||
|
||||
assert (map == null) == (land == null);
|
||||
|
||||
if (map == null || land == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
assert map.getFiles().size() == 1;
|
||||
assert land.getFiles().size() == 1;
|
||||
|
||||
map.decompressAndLoad(null);
|
||||
|
||||
byte[] data = map.getFiles().get(0).getContents();
|
||||
|
||||
Region region = new Region(i);
|
||||
region.loadTerrain(data);
|
||||
|
||||
int[] keys = keyManager.getKeys(i);
|
||||
if (keys != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
land.decompressAndLoad(keys);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
data = land.getFiles().get(0).getContents();
|
||||
region.loadLocations(data);
|
||||
}
|
||||
|
||||
regions.add(region);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dunpJson() throws IOException
|
||||
{
|
||||
File base = StoreLocation.LOCATION,
|
||||
outDir = folder.newFolder();
|
||||
|
||||
try (Store store = new Store(base))
|
||||
{
|
||||
store.load();
|
||||
|
||||
loadRegions(store);
|
||||
|
||||
for (Region region : regions)
|
||||
{
|
||||
if (region.getLocations().isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Files.write(gson.toJson(region).getBytes(), new File(outDir, region.getBaseX() + "_" + region.getBaseY() + ".json"));
|
||||
}
|
||||
}
|
||||
|
||||
logger.info("Dumped regions to {}", outDir);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.region.Region;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
@@ -51,25 +52,24 @@ public class MapImageDumperTest
|
||||
public void extract() throws IOException
|
||||
{
|
||||
File base = StoreLocation.LOCATION,
|
||||
outFile = folder.newFolder();
|
||||
|
||||
BufferedImage[] images;
|
||||
outDir = folder.newFolder();
|
||||
|
||||
try (Store store = new Store(base))
|
||||
{
|
||||
store.load();
|
||||
|
||||
MapImageDumper dumper = new MapImageDumper(store);
|
||||
images = dumper.buildImages();
|
||||
}
|
||||
dumper.load();
|
||||
|
||||
int i = 0;
|
||||
for (BufferedImage image : images)
|
||||
{
|
||||
File imageFile = new File(outFile, "img-" + i++ + ".png");
|
||||
for (int i = 0; i < Region.Z; ++i)
|
||||
{
|
||||
BufferedImage image = dumper.drawMap(i);
|
||||
|
||||
ImageIO.write(image, "png", imageFile);
|
||||
logger.info("Wrote image {}", imageFile);
|
||||
File imageFile = new File(outDir, "img-" + i + ".png");
|
||||
|
||||
ImageIO.write(image, "png", imageFile);
|
||||
logger.info("Wrote image {}", imageFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,10 @@ public class StoreLocation
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(StoreLocation.class);
|
||||
|
||||
private static final String TMP_DIR = "d:/temp";
|
||||
|
||||
public static File LOCATION;
|
||||
private static File TMP;
|
||||
|
||||
static
|
||||
{
|
||||
@@ -55,11 +58,23 @@ public class StoreLocation
|
||||
|
||||
File tmp = new File("d:/temp");
|
||||
if (tmp.exists() || tmp.mkdir())
|
||||
System.setProperty("java.io.tmpdir", "d:/temp");
|
||||
{
|
||||
System.setProperty("java.io.tmpdir", TMP_DIR);
|
||||
TMP = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
public static TemporaryFolder getTemporaryFolder()
|
||||
{
|
||||
return new TemporaryFolder();
|
||||
return new TemporaryFolder()
|
||||
{
|
||||
@Override
|
||||
public void after()
|
||||
{
|
||||
// don't cleanup if using local tmpdir
|
||||
if (TMP == null)
|
||||
super.after();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user