コード例 #1
0
        public static byte[] Decompress(string file, CompressionType cmp)
        {
            byte[] ret = new byte[0];
            try
            {
                switch (cmp)
                {
                case CompressionType.Uncompressed:
                    ret = File.ReadAllBytes(file);
                    break;

                case CompressionType.Kosinski:
                    ret = Kosinski.Decompress(file);
                    break;

                case CompressionType.KosinskiM:
                    ret = ModuledKosinski.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.Nemesis:
                    ret = Nemesis.Decompress(file);
                    break;

                case CompressionType.Enigma:
                    ret = Enigma.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.SZDD:
                    ret = SZDDComp.SZDDComp.Decompress(file);
                    break;

                case CompressionType.Comper:
                    ret = Comper.Decompress(file);
                    break;

                case CompressionType.KosinskiPlus:
                    ret = KosinskiPlus.Decompress(file);
                    break;

                case CompressionType.KosinskiPlusM:
                    ret = ModuledKosinskiPlus.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("cmp", "Invalid compression type " + cmp + "!");
                }
            }
            catch
            {
                LevelData.Log("Unable to read file \"" + file + "\" with compression " + cmp.ToString() + ":");
                throw;
            }
            return(ret);
        }
コード例 #2
0
ファイル: DataVerifyForm.cs プロジェクト: xfixium/Rika
        /// <summary>
        /// Verify button click
        /// </summary>
        private void btnVerify_Click(object sender, EventArgs e)
        {
            txtResult.Clear();
            int from   = (int)numFrom.Value;
            int to     = (int)numTo.Value;
            int length = to - from;

            byte[] range = GetBytes(from, length, _data);
            try { byte[] result = Nemesis.Decompress(range); txtResult.Text = "Nemesis (" + length + " bytes)"; return; } catch { }
            try  { byte[] result = Enigma.Decompress(range, Endianness.BigEndian); txtResult.Text = "Enigma (" + length + " bytes)"; return; } catch {  }
            try { byte[] result = Kosinski.Decompress(range); txtResult.Text = "Kosinski (" + length + " bytes)"; return; } catch { }
            txtResult.Text = "Not Compressed (" + length + " bytes)";
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: roman-murashov/KENSSharp
        static void Main(string[] args)
        {
            LongOpt[] opts = new[] {
                new LongOpt("help", Argument.No, null, 'h'),
                new LongOpt("compress", Argument.Required, null, 'c'),
                new LongOpt("decompress", Argument.Required, null, 'd'),
                new LongOpt("recompress", Argument.Required, null, 'r'),
                new LongOpt("same-filename", Argument.No, null, 's'),
                new LongOpt("little-endian", Argument.No, null, 'l'),
                new LongOpt("no-size", Argument.No, null, 'n')
            };
            Getopt          getopt       = new Getopt("KensSharp", args, Getopt.digest(opts), opts);
            Mode?           mode         = null;
            CompressionType?type         = null;
            Endianness      endian       = Endianness.BigEndian;
            bool            size         = true;
            bool            samefilename = false;
            int             opt          = getopt.getopt();

            while (opt != -1)
            {
                switch (opt)
                {
                case 'h':
                    ShowHelp();
                    return;

                case 'c':
                    mode = Mode.Compress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 'd':
                    mode = Mode.Decompress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 'r':
                    mode = Mode.Recompress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 's':
                    samefilename = true;
                    break;

                case 'l':
                    endian = Endianness.LittleEndian;
                    break;

                case 'n':
                    size = false;
                    break;
                }
                opt = getopt.getopt();
            }
            if (mode == null || type == null || getopt.Optind + (mode == Mode.Recompress | samefilename ? 0 : 1) >= args.Length)
            {
                ShowHelp();
                return;
            }
            string input = args[getopt.Optind];
            string output;

            if (getopt.Optind + 1 == args.Length)
            {
                output = input;
            }
            else
            {
                output = args[getopt.Optind + 1];
            }
            if (samefilename && input != "-")
            {
                switch (mode)
                {
                case Mode.Compress:
                    switch (type)
                    {
                    case CompressionType.Kosinski:
                        output = Path.ChangeExtension(input, "kos");
                        break;

                    case CompressionType.Enigma:
                        output = Path.ChangeExtension(input, "eni");
                        break;

                    case CompressionType.Nemesis:
                        output = Path.ChangeExtension(input, "nem");
                        break;

                    case CompressionType.Saxman:
                        output = Path.ChangeExtension(input, "sax");
                        break;

                    case CompressionType.KosinskiModuled:
                        output = Path.ChangeExtension(input, "kosm");
                        break;
                    }
                    break;

                case Mode.Decompress:
                    output = Path.ChangeExtension(input, "unc");
                    break;
                }
            }
            byte[] indata  = ReadInput(input);
            byte[] outdata = null;
            switch (mode)
            {
            case Mode.Compress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Compress(indata);
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Compress(indata, endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Compress(indata);
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Compress(indata, size);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Compress(indata, endian);
                    break;
                }
                break;

            case Mode.Decompress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Decompress(indata);
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Decompress(indata, endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Decompress(indata);
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Decompress(indata);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Decompress(indata, endian);
                    break;
                }
                break;

            case Mode.Recompress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Compress(Kosinski.Decompress(indata));
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Compress(Enigma.Decompress(indata, endian), endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Compress(Nemesis.Decompress(indata));
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Compress(Saxman.Decompress(indata), size);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Compress(ModuledKosinski.Decompress(indata, endian), endian);
                    break;
                }
                break;
            }
            WriteOutput(output, outdata);
        }
コード例 #4
0
        private void Execute()
        {
            if (this.compressRadioButton.Checked)
            {
                switch (this.formatListBox.SelectedIndex)
                {
                case 0:     // Kosinski
                    Kosinski.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 1:     // Moduled Kosinski
                    ModuledKosinski.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex);
                    break;

                case 2:     // Enigma
                    Enigma.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex);
                    break;

                case 3:     // Nemesis
                    Nemesis.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 4:     // Saxman (with size)
                    Saxman.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, true);
                    break;

                case 5:     // Saxman (without size)
                    Saxman.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, false);
                    break;

                case 6:     // Comper
                    Comper.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 7:     // Kosinski+
                    KosinskiPlus.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 8:     // Moduled Kosinski+
                    ModuledKosinskiPlus.Compress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;
                }
            }
            else if (this.decompressRadioButton.Checked)
            {
                switch (this.formatListBox.SelectedIndex)
                {
                case 0:     // Kosinski
                    Kosinski.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 1:     // Moduled Kosinski
                    ModuledKosinski.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex);
                    break;

                case 2:     // Enigma
                    Enigma.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (Endianness)this.endiannessComboBox.SelectedIndex);
                    break;

                case 3:     // Nemesis
                    Nemesis.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 4:     // Saxman (with size)
                    Saxman.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 5:     // Saxman (without size)
                    Saxman.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName, (long)this.sizeParameterNumericUpDown.Value);
                    break;

                case 6:     // Comper
                    Comper.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 7:     // Kosinski+
                    KosinskiPlus.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;

                case 8:     // Moduled Kosinski+
                    ModuledKosinskiPlus.Decompress(this.sourceFileSelector.FileName, this.destinationFileSelector.FileName);
                    break;
                }
            }
        }
コード例 #5
0
 public static void CompressionThenDecompressionRoundtrips(byte[] input, byte[] ignored)
 {
     byte[] compressed   = Kosinski.Compress(input);
     byte[] decompressed = Kosinski.Decompress(compressed);
     Assert.Equal(input, decompressed);
 }
コード例 #6
0
        public void Load()
        {
            mArtTiles = Kosinski.Decompress(@"C:\Users\Ted\Documents\Programming\Open Source\S2\art\kosinski\EHZ_HTZ.bin");

            byte[] pal0 = File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\art\palettes\SonicAndTails.bin");
            byte[] pal1 = File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\art\palettes\EHZ.bin");
            mArtPalette = new byte[pal0.Length + pal1.Length];
            Array.Copy(pal0, 0, mArtPalette, 0, pal0.Length);
            Array.Copy(pal1, 0, mArtPalette, pal0.Length, pal1.Length);

            byte[] layout = Kosinski.Decompress(@"C:\Users\Ted\Documents\Programming\Open Source\S2\level\layout\EHZ_1.bin");
            for (int y = 0; y < mHeight; y++)
            {
                for (int x = 0; x < mWidth; x++)
                {
                    mFGLayoutTiles[x, y] = layout[256 * y + x];
                }
            }

            byte[] blockMappings = Kosinski.Decompress(@"C:\Users\Ted\Documents\Programming\Open Source\S2\mappings\128x128\EHZ_HTZ.bin");
            for (int i = 0; i < 256; i++)
            {
                mLayoutBlocks.Add(new LayoutBlock(blockMappings, i * 128));
            }

            blockMappings = Kosinski.Decompress(@"C:\Users\Ted\Documents\Programming\Open Source\S2\mappings\16x16\EHZ.bin");
            for (int i = 0; i < 500; i++)
            {
                mTileBlocks.Add(new TileBlock(blockMappings, i * 8));
            }

            mCollisionArray1 = (sbyte[])(Array)File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\collision\Collision array 1.bin");
            mCollisionArray2 = (sbyte[])(Array)File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\collision\Collision array 2.bin");

            mPrimaryCollisionIndicies   = Kosinski.Decompress(@"C:\Users\Ted\Documents\Programming\Open Source\S2\collision\EHZ and HTZ primary 16x16 collision index.bin");
            mSecondaryCollisionIndicies = Kosinski.Decompress(@"C:\Users\Ted\Documents\Programming\Open Source\S2\collision\EHZ and HTZ secondary 16x16 collision index.bin");
            for (int i = 0; i < mTileBlocks.Count; i++)
            {
                mTileBlocks[i].SetCollision(mPrimaryCollisionIndicies[i], mSecondaryCollisionIndicies[i]);
            }

            mCurveMapping = (sbyte[])(Array)File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\collision\Curve and resistance mapping.bin");

            mObjects = File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\level\objects\EHZ_1.bin");
            mRings   = File.ReadAllBytes(@"C:\Users\Ted\Documents\Programming\Open Source\S2\level\rings\EHZ_1.bin");

            FileStream   fs = new FileStream(@"C:\Users\Ted\Documents\programming\Projects\Games\S2HD\assets\levels\ehz1\objects.dat", FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);

            // Objects
            List <object> objects = new List <object>();

            // Player start
            // objects.Add(new { Id = 1, Subtype = 0, X = 0x0060, Y = 0x028F, Respawn = false, Xflip = false, Yflip = false });

            for (int i = 0; i < mObjects.Length; i += 6)
            {
                short x       = BitConverter.ToInt16(new byte[] { mObjects[i + 1], mObjects[i + 0] }, 0);
                short y       = BitConverter.ToInt16(new byte[] { mObjects[i + 3], (byte)(mObjects[i + 2] & 0x0F) }, 0);
                byte  id      = mObjects[i + 4];
                byte  subtype = mObjects[i + 5];
                bool  respawn = ((mObjects[i + 2] & 0x80) == 0);
                bool  yflip   = ((mObjects[i + 2] & 0x40) != 0);
                bool  xflip   = ((mObjects[i + 2] & 0x20) != 0);

                objects.Add(new { Id = (int)id, Subtype = (int)subtype, X = (int)x, Y = (int)y, Respawn = respawn, Xflip = xflip, Yflip = yflip });
            }

            for (int i = 0; i < mRings.Length; i += 4)
            {
                short x = BitConverter.ToInt16(new byte[] { mRings[i + 1], mRings[i + 0] }, 0);
                if (x == -1)
                {
                    break;
                }
                short y      = BitConverter.ToInt16(new byte[] { mRings[i + 3], (byte)(mRings[i + 2] & 0x0F) }, 0);
                int   t      = mRings[i + 2] >> 4;
                bool  column = ((t & 8) != 0);
                int   c      = (t & 7) + 1;

                for (int j = 0; j < c; j++)
                {
                    objects.Add(new { Id = 37, Subtype = 0, X = (int)x, Y = (int)y, Respawn = false, Xflip = false, Yflip = false });

                    if (column)
                    {
                        y += 24;
                    }
                    else
                    {
                        x += 24;
                    }
                }
            }

            int[] swapIdA = new int[] { 3, 6, 13, 17, 24, 28, 37, 38, 54, 65, 73, 75, 92, 121, 157 };
            int[] swapIdB = new int[] { 38, 131, 19, 128, 130, 129, 16, 17, 49, 48, 132, 64, 66, 18, 65 };

            foreach (dynamic obj in objects)
            {
                int id = 0;
                for (int i = 0; i < swapIdA.Length; i++)
                {
                    if (obj.Id == swapIdA[i])
                    {
                        id = swapIdB[i];
                    }
                }

                if (id == 0)
                {
                    continue;
                }

                bw.Write(id);
                bw.Write((int)obj.Subtype);

                int flags = 0;
                if (obj.Xflip)
                {
                    flags |= 1;
                }
                if (obj.Yflip)
                {
                    flags |= 2;
                }
                if (obj.Respawn)
                {
                    flags |= 4;
                }

                bw.Write(flags);
                bw.Write((int)obj.X);
                bw.Write((int)obj.Y);
            }

            bw.Close();
            fs.Close();
        }