From 1dc2227ee2efc6db159a4dc493707a24c235bdf5 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 21 May 2015 15:28:19 -0700 Subject: [PATCH] Finish Decompressor May have an issue with endianness of commands (ie, command writing first vs parameter). Will test thoroughly later. --- pk3DS/Tools/Scripts.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pk3DS/Tools/Scripts.cs b/pk3DS/Tools/Scripts.cs index 3f96bb6..1d8de24 100644 --- a/pk3DS/Tools/Scripts.cs +++ b/pk3DS/Tools/Scripts.cs @@ -27,8 +27,6 @@ internal static byte[] decompressScript(byte[] data) val = br.ReadByte(); raw.Add(val); } } - - byte[] compressedBytes = raw.ToArray(); // Interpret the bytecode @@ -41,22 +39,22 @@ internal static byte[] decompressScript(byte[] data) if ((second >> 7) > 0) // Many-bits-required command { // 2 Byte Signed Parameter + // Process Many-bits instructional + // there can only be 1 manybit based on max CMD value restriction; simple. + int cmd = (compressedBytes[1] & 0x7F << 7) | compressedBytes[2]; + bw.Write(BitConverter.GetBytes((ushort)cmd), 0, 2); + int deviation = ((val >> 1) & 0x3F) - 0x40; bw.Write(BitConverter.GetBytes(deviation), 0, 2); - - // Process Many-bits instructional - { - // there can only be 1 manybit based on max CMD value restriction; simple. - int cmd = (compressedBytes[0] & 0x7F << 7) | compressedBytes[1]; - bw.Write(BitConverter.GetBytes((ushort)cmd), 0, 2); - } } else if ((val >> 7) > 0) { // 3 Byte Signed Parameter + // Process Many-bits instructional + bw.Write((byte)(((val & 0x1) << 7) | compressedBytes[1])); // bottom bit is sent to low byte as the 8th bit + int deviation = ((val >> 1) & 0x3F) - 0x40; bw.Write(BitConverter.GetBytes(deviation), 0, 3); - bw.Write((byte)(((val & 0x1) << 7) | compressedBytes[1])); // bottom bit is sent to low byte as the 8th bit } else {