Accidentally deleted my unpackedSpawnsList.txt and needed to write a packed spawns dumper, so I'd like to share it.
I'm not sure which other revisions use this spawning system so I marked it as 718.
Code:
public static void dumpPackedSpawns() throws IOException {
File dumpFile, packedSpawnsFolder;
File[] packedFiles;
BufferedWriter writer;
dumpFile = new File("data/npcs/unpackedSpawnsList.txt");
if (dumpFile.exists())
dumpFile.delete();
packedSpawnsFolder = new File("data/npcs/packedSpawns/");
packedFiles = packedSpawnsFolder.listFiles();
writer = new BufferedWriter(new FileWriter(dumpFile, false));
for (File file : packedFiles) {
System.out.println("Dumping data for region " + file.getName().split("\\.")[0] + ".");
RandomAccessFile regionFile = new RandomAccessFile(file, "r");
FileChannel regionFileChannel = regionFile.getChannel();
ByteBuffer buffer = regionFileChannel.map(MapMode.READ_ONLY, 0, regionFileChannel.size());
while (buffer.hasRemaining()) {
int npcId = buffer.getShort() & 0xffff;
int plane = buffer.get() & 0xff;
int x = buffer.getShort() & 0xffff;
int y = buffer.getShort() & 0xffff;
boolean hashExtraInformation = buffer.get() == 1;
int mapAreaNameHash = -1;
boolean canBeAttackFromOutOfArea = true;
if (hashExtraInformation) {
mapAreaNameHash = buffer.getInt();
canBeAttackFromOutOfArea = buffer.get() == 1;
}
writer.write( npcId + " - " + x + " " + y + " " + plane);
if (hashExtraInformation)
writer.write(" " + mapAreaNameHash + " " + canBeAttackFromOutOfArea);
writer.newLine();
}
regionFileChannel.close();
regionFile.close();
}
writer.close();
}
Note: This will replace your unpackedSpawnsList.txt if you have one!