Pass in byte[] to all definition loaders, not InputStream
This commit is contained in:
@@ -68,7 +68,7 @@ public class ItemDumper
|
|||||||
|
|
||||||
for (net.runelite.cache.fs.File f : archive.getFiles())
|
for (net.runelite.cache.fs.File f : archive.getFiles())
|
||||||
{
|
{
|
||||||
ItemDefinition def = loader.load(f.getFileId(), new InputStream(f.getContents()));
|
ItemDefinition def = loader.load(f.getFileId(), f.getContents());
|
||||||
items.add(def);
|
items.add(def);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ public class MapImageDumper
|
|||||||
byte[] contents = file.getContents();
|
byte[] contents = file.getContents();
|
||||||
|
|
||||||
SpriteLoader loader = new SpriteLoader();
|
SpriteLoader loader = new SpriteLoader();
|
||||||
SpriteDefinition[] sprites = loader.load(a.getArchiveId(), new InputStream(contents));
|
SpriteDefinition[] sprites = loader.load(a.getArchiveId(), contents);
|
||||||
|
|
||||||
for (SpriteDefinition sprite : sprites)
|
for (SpriteDefinition sprite : sprites)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public class NpcDumper
|
|||||||
|
|
||||||
for (net.runelite.cache.fs.File f : archive.getFiles())
|
for (net.runelite.cache.fs.File f : archive.getFiles())
|
||||||
{
|
{
|
||||||
NpcDefinition npc = loader.load(f.getFileId(), new InputStream(f.getContents()));
|
NpcDefinition npc = loader.load(f.getFileId(), f.getContents());
|
||||||
npcs.add(npc);
|
npcs.add(npc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,19 +34,20 @@ public class ItemLoader
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(ItemLoader.class);
|
private static final Logger logger = LoggerFactory.getLogger(ItemLoader.class);
|
||||||
|
|
||||||
public ItemDefinition load(int id, InputStream stream)
|
public ItemDefinition load(int id, byte[] b)
|
||||||
{
|
{
|
||||||
ItemDefinition def = new ItemDefinition(id);
|
ItemDefinition def = new ItemDefinition(id);
|
||||||
|
InputStream is = new InputStream(b);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int opcode = stream.readUnsignedByte();
|
int opcode = is.readUnsignedByte();
|
||||||
if (opcode == 0)
|
if (opcode == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.decodeValues(opcode, def, stream);
|
this.decodeValues(opcode, def, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ import net.runelite.cache.io.InputStream;
|
|||||||
|
|
||||||
public class ModelLoader
|
public class ModelLoader
|
||||||
{
|
{
|
||||||
public ModelDefinition load(int modelId, byte[] var1)
|
public ModelDefinition load(int modelId, byte[] b)
|
||||||
{
|
{
|
||||||
ModelDefinition def = new ModelDefinition();
|
ModelDefinition def = new ModelDefinition();
|
||||||
def.id = modelId;
|
def.id = modelId;
|
||||||
|
|
||||||
if (var1[var1.length - 1] == -1 && var1[var1.length - 2] == -1)
|
if (b[b.length - 1] == -1 && b[b.length - 2] == -1)
|
||||||
{
|
{
|
||||||
this.load1(def, var1);
|
this.load1(def, b);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
this.load2(def, var1);
|
this.load2(def, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
def.computeNormals();
|
def.computeNormals();
|
||||||
|
|||||||
@@ -33,19 +33,20 @@ public class NpcLoader
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(NpcLoader.class);
|
private static final Logger logger = LoggerFactory.getLogger(NpcLoader.class);
|
||||||
|
|
||||||
public NpcDefinition load(int id, InputStream stream)
|
public NpcDefinition load(int id, byte[] b)
|
||||||
{
|
{
|
||||||
NpcDefinition def = new NpcDefinition(id);
|
NpcDefinition def = new NpcDefinition(id);
|
||||||
|
InputStream is = new InputStream(b);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int opcode = stream.readUnsignedByte();
|
int opcode = is.readUnsignedByte();
|
||||||
if (opcode == 0)
|
if (opcode == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.decodeValues(opcode, def, stream);
|
this.decodeValues(opcode, def, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|||||||
@@ -33,19 +33,20 @@ public class SequenceLoader
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SequenceLoader.class);
|
private static final Logger logger = LoggerFactory.getLogger(SequenceLoader.class);
|
||||||
|
|
||||||
public SequenceDefinition load(int id, InputStream stream)
|
public SequenceDefinition load(int id, byte[] b)
|
||||||
{
|
{
|
||||||
SequenceDefinition def = new SequenceDefinition(id);
|
SequenceDefinition def = new SequenceDefinition(id);
|
||||||
|
InputStream is = new InputStream(b);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int opcode = stream.readUnsignedByte();
|
int opcode = is.readUnsignedByte();
|
||||||
if (opcode == 0)
|
if (opcode == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.decodeValues(opcode, def, stream);
|
this.decodeValues(opcode, def, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|||||||
@@ -33,20 +33,21 @@ public class SpotAnimLoader
|
|||||||
{
|
{
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SpotAnimLoader.class);
|
private static final Logger logger = LoggerFactory.getLogger(SpotAnimLoader.class);
|
||||||
|
|
||||||
public SpotAnimDefinition load(int id, InputStream stream)
|
public SpotAnimDefinition load(int id, byte[] b)
|
||||||
{
|
{
|
||||||
SpotAnimDefinition def = new SpotAnimDefinition();
|
SpotAnimDefinition def = new SpotAnimDefinition();
|
||||||
|
InputStream is = new InputStream(b);
|
||||||
def.id = id;
|
def.id = id;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
int opcode = stream.readUnsignedByte();
|
int opcode = is.readUnsignedByte();
|
||||||
if (opcode == 0)
|
if (opcode == 0)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.decodeValues(opcode, def, stream);
|
this.decodeValues(opcode, def, is);
|
||||||
}
|
}
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|||||||
@@ -33,22 +33,24 @@ public class SpriteLoader
|
|||||||
public static final int FLAG_VERTICAL = 0b01;
|
public static final int FLAG_VERTICAL = 0b01;
|
||||||
public static final int FLAG_ALPHA = 0b10;
|
public static final int FLAG_ALPHA = 0b10;
|
||||||
|
|
||||||
public SpriteDefinition[] load(int id, InputStream stream)
|
public SpriteDefinition[] load(int id, byte[] b)
|
||||||
{
|
{
|
||||||
stream.setOffset(stream.getLength() - 2);
|
InputStream is = new InputStream(b);
|
||||||
int spriteCount = stream.readUnsignedShort();
|
|
||||||
|
is.setOffset(is.getLength() - 2);
|
||||||
|
int spriteCount = is.readUnsignedShort();
|
||||||
|
|
||||||
SpriteDefinition[] sprites = new SpriteDefinition[spriteCount];
|
SpriteDefinition[] sprites = new SpriteDefinition[spriteCount];
|
||||||
|
|
||||||
// 2 for size
|
// 2 for size
|
||||||
// 5 for width, height, palette length
|
// 5 for width, height, palette length
|
||||||
// + 8 bytes per sprite for offset x/y, width, and height
|
// + 8 bytes per sprite for offset x/y, width, and height
|
||||||
stream.setOffset(stream.getLength() - 7 - spriteCount * 8);
|
is.setOffset(is.getLength() - 7 - spriteCount * 8);
|
||||||
|
|
||||||
// max width and height
|
// max width and height
|
||||||
int width = stream.readUnsignedShort();
|
int width = is.readUnsignedShort();
|
||||||
int height = stream.readUnsignedShort();
|
int height = is.readUnsignedShort();
|
||||||
int paletteLength = stream.readUnsignedByte() + 1;
|
int paletteLength = is.readUnsignedByte() + 1;
|
||||||
|
|
||||||
for (int i = 0; i < spriteCount; ++i)
|
for (int i = 0; i < spriteCount; ++i)
|
||||||
{
|
{
|
||||||
@@ -61,31 +63,31 @@ public class SpriteLoader
|
|||||||
|
|
||||||
for (int i = 0; i < spriteCount; ++i)
|
for (int i = 0; i < spriteCount; ++i)
|
||||||
{
|
{
|
||||||
sprites[i].setOffsetX(stream.readUnsignedShort());
|
sprites[i].setOffsetX(is.readUnsignedShort());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < spriteCount; ++i)
|
for (int i = 0; i < spriteCount; ++i)
|
||||||
{
|
{
|
||||||
sprites[i].setOffsetY(stream.readUnsignedShort());
|
sprites[i].setOffsetY(is.readUnsignedShort());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < spriteCount; ++i)
|
for (int i = 0; i < spriteCount; ++i)
|
||||||
{
|
{
|
||||||
sprites[i].setWidth(stream.readUnsignedShort());
|
sprites[i].setWidth(is.readUnsignedShort());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < spriteCount; ++i)
|
for (int i = 0; i < spriteCount; ++i)
|
||||||
{
|
{
|
||||||
sprites[i].setHeight(stream.readUnsignedShort());
|
sprites[i].setHeight(is.readUnsignedShort());
|
||||||
}
|
}
|
||||||
|
|
||||||
// same as above + 3 bytes for each palette entry, except for the first one (which is transparent)
|
// same as above + 3 bytes for each palette entry, except for the first one (which is transparent)
|
||||||
stream.setOffset(stream.getLength() - 7 - spriteCount * 8 - (paletteLength - 1) * 3);
|
is.setOffset(is.getLength() - 7 - spriteCount * 8 - (paletteLength - 1) * 3);
|
||||||
int[] palette = new int[paletteLength];
|
int[] palette = new int[paletteLength];
|
||||||
|
|
||||||
for (int i = 1; i < paletteLength; ++i)
|
for (int i = 1; i < paletteLength; ++i)
|
||||||
{
|
{
|
||||||
palette[i] = stream.read24BitInt();
|
palette[i] = is.read24BitInt();
|
||||||
|
|
||||||
if (palette[i] == 0)
|
if (palette[i] == 0)
|
||||||
{
|
{
|
||||||
@@ -93,7 +95,7 @@ public class SpriteLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream.setOffset(0);
|
is.setOffset(0);
|
||||||
|
|
||||||
for (int i = 0; i < spriteCount; ++i)
|
for (int i = 0; i < spriteCount; ++i)
|
||||||
{
|
{
|
||||||
@@ -104,14 +106,14 @@ public class SpriteLoader
|
|||||||
byte[] pixelPaletteIndicies = new byte[dimension];
|
byte[] pixelPaletteIndicies = new byte[dimension];
|
||||||
byte[] pixelAlphas = new byte[dimension];
|
byte[] pixelAlphas = new byte[dimension];
|
||||||
|
|
||||||
int flags = stream.readUnsignedByte();
|
int flags = is.readUnsignedByte();
|
||||||
|
|
||||||
if ((flags & FLAG_VERTICAL) == 0)
|
if ((flags & FLAG_VERTICAL) == 0)
|
||||||
{
|
{
|
||||||
// read horizontally
|
// read horizontally
|
||||||
for (int j = 0; j < dimension; ++j)
|
for (int j = 0; j < dimension; ++j)
|
||||||
{
|
{
|
||||||
pixelPaletteIndicies[j] = stream.readByte();
|
pixelPaletteIndicies[j] = is.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -121,7 +123,7 @@ public class SpriteLoader
|
|||||||
{
|
{
|
||||||
for (int k = 0; k < spriteHeight; ++k)
|
for (int k = 0; k < spriteHeight; ++k)
|
||||||
{
|
{
|
||||||
pixelPaletteIndicies[spriteWidth * k + j] = stream.readByte();
|
pixelPaletteIndicies[spriteWidth * k + j] = is.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +136,7 @@ public class SpriteLoader
|
|||||||
// read horizontally
|
// read horizontally
|
||||||
for (int j = 0; j < dimension; ++j)
|
for (int j = 0; j < dimension; ++j)
|
||||||
{
|
{
|
||||||
pixelAlphas[j] = stream.readByte();
|
pixelAlphas[j] = is.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -144,7 +146,7 @@ public class SpriteLoader
|
|||||||
{
|
{
|
||||||
for (int k = 0; k < spriteHeight; ++k)
|
for (int k = 0; k < spriteHeight; ++k)
|
||||||
{
|
{
|
||||||
pixelAlphas[spriteWidth * k + j] = stream.readByte();
|
pixelAlphas[spriteWidth * k + j] = is.readByte();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class SequenceDumper
|
|||||||
for (File file : archive.getFiles())
|
for (File file : archive.getFiles())
|
||||||
{
|
{
|
||||||
SequenceLoader loader = new SequenceLoader();
|
SequenceLoader loader = new SequenceLoader();
|
||||||
SequenceDefinition seq = loader.load(file.getFileId(), new InputStream(file.getContents()));
|
SequenceDefinition seq = loader.load(file.getFileId(), file.getContents());
|
||||||
|
|
||||||
Files.write(gson.toJson(seq), new java.io.File(outDir, file.getFileId() + ".json"), Charset.defaultCharset());
|
Files.write(gson.toJson(seq), new java.io.File(outDir, file.getFileId() + ".json"), Charset.defaultCharset());
|
||||||
++count;
|
++count;
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class SpriteDumperTest
|
|||||||
byte[] contents = file.getContents();
|
byte[] contents = file.getContents();
|
||||||
|
|
||||||
SpriteLoader loader = new SpriteLoader();
|
SpriteLoader loader = new SpriteLoader();
|
||||||
SpriteDefinition[] sprites = loader.load(a.getArchiveId(), new InputStream(contents));
|
SpriteDefinition[] sprites = loader.load(a.getArchiveId(), contents);
|
||||||
|
|
||||||
for (SpriteDefinition def : sprites)
|
for (SpriteDefinition def : sprites)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user