From fb937f00c87df83b7740cd2c53c1813ea04e1d4e Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 21 May 2015 22:35:05 -0700 Subject: [PATCH] Update Decompression Signed is now handled properly; shared bit behavior should be much more apparent --- pk3DS/Subforms/OWSE.cs | 1 - pk3DS/Tools/Scripts.cs | 22 ++++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pk3DS/Subforms/OWSE.cs b/pk3DS/Subforms/OWSE.cs index fb51702..4fdc971 100644 --- a/pk3DS/Subforms/OWSE.cs +++ b/pk3DS/Subforms/OWSE.cs @@ -140,7 +140,6 @@ private void getScriptData() byte[] compressed = ScriptData.Skip(start).ToArray(); string c = Util.getHexString(compressed); - compressed = File.ReadAllBytes("raw.bin"); byte[] decompressed = Scripts.decompressScript(compressed); string d = Util.getHexString(decompressed); diff --git a/pk3DS/Tools/Scripts.cs b/pk3DS/Tools/Scripts.cs index ec98013..75f6f3d 100644 --- a/pk3DS/Tools/Scripts.cs +++ b/pk3DS/Tools/Scripts.cs @@ -36,28 +36,26 @@ internal static byte[] decompressScript(byte[] data) if (compressedBytes.Length > 1 && (compressedBytes[1] >> 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 cmd = (compressedBytes[0] & 0x3 << 14) | (compressedBytes[1] & 0x7F << 7) | compressedBytes[2]; // 16 Bits total + bw.Write(BitConverter.GetBytes(cmd), 0, 2); - int deviation = -((val & 0x3F) >> 1); - bw.Write(BitConverter.GetBytes(deviation), 0, 2); + int deviation = ((val & 0x3F) - 0x40) >> 2; // Lowest 2 bits have already been used for the command + bw.Write(BitConverter.GetBytes(deviation), 0, 2); // 16 Bits } 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 cmd = ((compressedBytes[0] << 7) | compressedBytes[1]); + bw.Write(BitConverter.GetBytes(cmd), 0, 1); // 8 Bits Total - int deviation = ((val & 0x3F) >> 1) - 0x40; - bw.Write(BitConverter.GetBytes(deviation), 0, 3); + int deviation = ((val & 0x3F) - 0x40) >> 1; // Lowest bit has already been used for the command + bw.Write(BitConverter.GetBytes(deviation), 0, 3); // 24 Bits } else { // 4 Byte Signed Parameter - int deviation = ((val & 0x3F) >> 1) - 0x40; - bw.Write(BitConverter.GetBytes(deviation), 0, 4); + int deviation = ((val & 0x3F) - 0x40) >> 0; // No bits have already been used; no command + bw.Write(BitConverter.GetBytes(deviation), 0, 4); // 32 Bits } } else if ((val >> 7) > 0) // Manybit