public static (byte[] comp, byte[] decomp) DecompressFull(ByteArrayStream source, int outputSize) { var startAddress = source.Address; var dataSourceOffset = source.Word(); var dataSource = source.Branch(source.Address + dataSourceOffset); var output = new ByteArrayStream(outputSize); byte command; while ((command = source.Byte()) != 0x00) { if ((command & 0x0f) != 0) { var length = command & 0x0f; dataSource.CopyTo(output, length); } if ((command & 0xf0) != 0) { var length = ((command & 0xf0) >> 4) + 2; var address = output.Address - source.Byte() - 1; if (address < 0) { throw new IndexOutOfRangeException($"{nameof(address)} cannot be less than 0"); } output.Branch(address).CopyTo(output, length); } } var comp = source.GetBytes(dataSource.Address - startAddress, startAddress); var decomp = output.GetBytes(output.Address, 0); return(comp, decomp); }