diff --git a/core/src/com/riiablo/attributes/StatListWriter.java b/core/src/com/riiablo/attributes/StatListWriter.java index 99863f4b..b436eb3a 100644 --- a/core/src/com/riiablo/attributes/StatListWriter.java +++ b/core/src/com/riiablo/attributes/StatListWriter.java @@ -59,8 +59,9 @@ public class StatListWriter { bits.write15u(Stat.NONE, Stat.BITS); } - public void write(Attributes attrs, BitOutput bits) { - throw new UnsupportedOperationException(); // TODO: character saves + public void write(Attributes attrs, BitOutput bits, boolean cs) { + final StatList stats = attrs.base(); + write(stats.get(0), bits, cs); } public void write(Attributes attrs, BitOutput bits, int flags, int maxLists) { diff --git a/core/test/com/riiablo/attributes/StatListWriterTest.java b/core/test/com/riiablo/attributes/StatListWriterTest.java index 95ace41b..f1392bc5 100644 --- a/core/test/com/riiablo/attributes/StatListWriterTest.java +++ b/core/test/com/riiablo/attributes/StatListWriterTest.java @@ -2,6 +2,7 @@ package com.riiablo.attributes; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; +import java.util.Arrays; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -57,17 +58,22 @@ public class StatListWriterTest { StatListReader reader = new StatListReader(); final Attributes attrs = Attributes.aggregateAttributes(); reader.read(attrs, bitInput, flags, NUM_ITEM_LISTS); - System.out.println(ByteBufUtil.prettyHexDump(in.buffer(), 0, in.buffer().readerIndex())); + final String firstHexDump = ByteBufUtil.prettyHexDump(in.buffer(), 0, in.buffer().readerIndex()); + System.out.println(firstHexDump); ByteOutput out = ByteOutput.wrap(Unpooled.buffer(length, length)); BitOutput bitOutput = out.unalign().writeRaw(data[offset], bitOffset); - System.out.printf("cache=%02x %d%n", data[offset], bitOffset); StatListWriter writer = new StatListWriter(); writer.write(attrs, bitOutput, flags, NUM_ITEM_LISTS); bitOutput.flush(); System.out.println(ByteBufUtil.prettyHexDump(out.buffer())); - Assert.assertTrue(ByteBufUtil.equals(in.buffer(), 0, out.buffer(), 0, in.buffer().readerIndex())); + boolean equal = ByteBufUtil.equals(in.buffer(), 0, out.buffer(), 0, in.buffer().readerIndex()); + if (!equal) { + System.out.println("Expected:"); + System.out.println(firstHexDump); + } + Assert.assertTrue(equal); } @Test @@ -134,4 +140,33 @@ public class StatListWriterTest { public void Vampire_Gaze() { testItem(Gdx.files.internal("test/Vampire Gaze.d2i").readBytes(), 197, -1, FLAG_MAGIC); } + + private void testCharacter(byte[] data, int bytesToSkip, int length) { + ByteInput in = ByteInput.wrap(Unpooled.wrappedBuffer(data, bytesToSkip, length)); + BitInput bitInput = in.skipBytes(2).unalign(); // skip signature + StatListReader reader = new StatListReader(); + final Attributes attrs = Attributes.aggregateAttributes(); + reader.read(attrs, bitInput, true); + final String firstHexDump = ByteBufUtil.prettyHexDump(in.buffer(), 0, in.buffer().readerIndex()); + System.out.println(firstHexDump); + + ByteOutput out = ByteOutput.wrap(Unpooled.buffer(length, length)); + BitOutput bitOutput = out.writeBytes(Arrays.copyOfRange(data, bytesToSkip, bytesToSkip + 2)).unalign(); + StatListWriter writer = new StatListWriter(); + writer.write(attrs, bitOutput, true); + bitOutput.flush(); + System.out.println(ByteBufUtil.prettyHexDump(out.buffer())); + + boolean equal = ByteBufUtil.equals(in.buffer(), 0, out.buffer(), 0, in.buffer().readerIndex()); + if (!equal) { + System.out.println("Expected:"); + System.out.println(firstHexDump); + } + Assert.assertTrue(equal); + } + + @Test + public void Tirant() { + testCharacter(Gdx.files.internal("test/Tirant.d2s").readBytes(), 0x2fd, 0x33); + } } \ No newline at end of file