예제 #1
0
        private void WriteTitleToLZ(string filename, int id)
        {
            DrawString2(storyList.Stories[id].Title);

            Graphics g3 = Graphics.FromImage(title_output);

            for (int i = 0; i < 7; i++)
            {
                var sRect = new Rectangle(i * 32, 0, 32, 16);
                var dRect = new Rectangle(0, i * 16, 32, 16);
                g3.DrawImage(title, dRect, sRect, GraphicsUnit.Pixel);
            }

            Color[] palette  = new Color[16];
            int     palIndex = 14;

            LoadPalFile("obj.pal");
            for (int j = 0; j < palette.Length; j++)
            {
                palette[j] = PALfilePalette[j + 16 * palIndex];
            }

            byte[] raw      = GBAGraphics.ToGBARaw(title_output, palette, GraphicsMode.Tile4bit);
            byte[] lzcomped = LZ77.Compress(raw);

            File.WriteAllBytes(filename, lzcomped);
        }
예제 #2
0
        void Core_Insert(
            Palette palette,
            byte[] graphics,
            TSA_Array tsa = null)
        {
            Core.SuspendUpdate();
            try
            {
                byte[] data_palette = palette.ToBytes(Palette_CheckBox.Checked);
                byte[] data_tileset = Tileset_CheckBox.Checked ? LZ77.Compress(graphics) : graphics;
                byte[] data_tsa     = null;

                List <Tuple <string, Pointer, int> > repoints = new List <Tuple <string, Pointer, int> >();
                repoints.Add(Tuple.Create("Palette", Palette_PointerBox.Value, data_palette.Length));
                repoints.Add(Tuple.Create("Tileset", Tileset_PointerBox.Value, data_tileset.Length));
                if (tsa != null)
                {
                    data_tsa = tsa.ToBytes(TSA_CheckBox.Checked, TSA_FlipRows_CheckBox.Checked);
                    repoints.Add(Tuple.Create("TSA", TSA_PointerBox.Value, data_tsa.Length));
                }

                bool cancel = Prompt.ShowRepointDialog(this, "Repoint Graphics",
                                                       "The image and palette to insert might need to be repointed.",
                                                       "Image at " + Tileset_PointerBox.Value + " - ", repoints.ToArray());
                if (cancel)
                {
                    return;
                }

                Core.WriteData(this,
                               Palette_PointerBox.Value,
                               data_palette,
                               "Palette at " + Palette_PointerBox.Value + " changed");

                Core.WriteData(this,
                               Tileset_PointerBox.Value,
                               data_tileset,
                               "Tileset at " + Tileset_PointerBox.Value + " changed");

                if (tsa != null)
                {
                    Core.WriteData(this,
                                   TSA_PointerBox.Value,
                                   data_tsa,
                                   "TSA Array at " + TSA_PointerBox.Value + " changed");
                }
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert image.", ex);
            }
            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #3
0
파일: LZ77Tests.cs 프로젝트: przpl/CryptZip
        public void Compress3_Compresses_Compressed()
        {
            var lz77   = new LZ77();
            var input  = new MemoryStream(new byte[] { 1, 2, 3 });
            var output = new MemoryStream();

            byte[] excpected = { 16, 9, 0, 0, 0, 0, 128, 0, 0, 0, 128, 0, 0, 0, 96 };
            lz77.Compress(input, output);
            byte[] result = output.ToArray();
            CollectionAssert.AreEqual(excpected, result);
        }
예제 #4
0
파일: LZ77Tests.cs 프로젝트: przpl/CryptZip
        public void Compress2_Compresses_Compressed()
        {
            var lz77   = new LZ77();
            var input  = new MemoryStream(new byte[] { 5, 2, 5, 8, 1, 10, 2, 4, 6, 9, 2, 3, 5, 8, 1, 1, 2, 1, 1, 1, 1, 8, 0, 1, 12 });
            var output = new MemoryStream();

            byte[] excpected = { 16, 9, 0, 0, 0, 2, 128, 0, 0, 0, 128, 0, 128, 33, 0, 0, 0, 0, 16, 0, 0, 0, 80, 0, 40, 4, 16, 0, 0, 0, 12, 0, 0, 0, 9, 0, 9, 0, 129, 128, 5, 0, 192, 64, 3, 192, 32, 32, 0, 32, 48, 128, 0, 0, 0, 0, 0, 152, 4, 48 };
            lz77.Compress(input, output);
            byte[] result = output.ToArray();
            CollectionAssert.AreEqual(excpected, result);
        }
예제 #5
0
파일: LZ77Tests.cs 프로젝트: przpl/CryptZip
        public void Compress_Compresses_Compressed()
        {
            var lz77   = new LZ77();
            var input  = new MemoryStream(new byte[] { 2, 5, 7, 1, 8, 2, 5, 2, 0, 2, 5, 1, 6, 8, 9, 2, 1 });
            var output = new MemoryStream();

            byte[] excpected = { 16, 9, 0, 0, 0, 1, 0, 0, 0, 1, 64, 0, 0, 0, 224, 0, 0, 0, 16, 0, 0, 0, 64, 0, 40, 8, 8, 0, 0, 0, 0, 0, 18, 2, 1, 0, 0, 0, 3, 0, 4, 128, 66, 64, 3, 192, 32, 32 };
            lz77.Compress(input, output);
            byte[] result = output.ToArray();
            CollectionAssert.AreEqual(excpected, result);
        }
예제 #6
0
파일: LZTests.cs 프로젝트: wabberz/Kuriimu
        static void Test(byte[] bytes, Method method)
        {
            byte[] bytes2 = new byte[bytes.Length];

            switch (method)
            {
            case Method.LZ10:
                bytes2 = LZ10.Decompress(new MemoryStream(LZ10.Compress(new MemoryStream(bytes))), bytes.Length);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ11:
                bytes2 = LZ11.Decompress(new MemoryStream(LZ11.Compress(new MemoryStream(bytes))), bytes.Length);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ40:
                bytes2 = LZ40.Decompress(new MemoryStream(LZ40.Compress(new MemoryStream(bytes))), bytes.Length);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ77:
                bytes2 = LZ77.Decompress(new MemoryStream(LZ77.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.RevLZ77:
                bytes2 = RevLZ77.Decompress(new MemoryStream(RevLZ77.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZ4:
                bytes2 = LZ4.Decompress(new MemoryStream(LZ4.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZECD:
                bytes2 = LZECD.Decompress(new MemoryStream(LZECD.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.LZOvl:
                bytes2 = LZOvl.Decompress(new MemoryStream(LZOvl.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;

            case Method.MIO0:
                bytes2 = MIO0.Decompress(new MemoryStream(MIO0.Compress(new MemoryStream(bytes), ByteOrder.LittleEndian)), ByteOrder.LittleEndian);
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;
            }
        }
예제 #7
0
        public byte[] GetTSAandTerrain(bool compressed)
        {
            List <byte> tsa = new List <byte>();

            foreach (MapTile tile in Tiles)
            {
                tsa.AddRange(tile.ToBytes());
            }
            byte[] result = new byte[tsa.Count + Terrain.Length];
            Array.Copy(tsa.ToArray(), result, tsa.Count);
            Array.Copy(Terrain, 0, result, tsa.Count, Terrain.Length);
            return(compressed ? LZ77.Compress(result) : result);
        }
예제 #8
0
        public override async Task WriteResponseBodyAsync(OutputFormatterWriteContext context)
        {
            var response = context.HttpContext.Response;

            if (!(context.Object is EamuseXrpcData data))
            {
                throw new ArgumentNullException("Input EamuseXrpcData is null");
            }

            (byte[] rawData, string compAlgo) = await Task.Run(() =>
            {
                byte[] resData;
                if (data.Encoding != null)
                {
                    resData = new KBinXML(data.Document, data.Encoding).Bytes;
                }
                else
                {
                    resData = new KBinXML(data.Document).Bytes;
                }

                string algo = "none";

                byte[] compressed = LZ77.Compress(resData, 32);
                if (compressed.Length < resData.Length)
                {
                    resData = compressed;
                    algo    = "lz77";
                }
                compressed = null;

                if (data.EamuseInfo != null)
                {
                    RC4.ApplyEAmuseInfo(data.EamuseInfo, resData);
                }

                return(resData, algo);
            });

            if (data.EamuseInfo != null)
            {
                response.Headers.Add("X-Eamuse-Info", data.EamuseInfo);
            }

            response.Headers.Add("X-Compress", compAlgo);

            response.ContentType   = "application/octet-stream";
            response.ContentLength = rawData.Length;

            await response.Body.WriteAsync(rawData, 0, rawData.Length);
        }
예제 #9
0
        private void WriteData_Click(object sender, EventArgs e)
        {
            Pointer address = Write_AddressBox.Value;

            byte[] data = (Write_LZ77CheckBox.Checked) ?
                          LZ77.Compress(Write_HexBox.Value) : Write_HexBox.Value;

            if (address == 0)
            {
                return;
            }
            Accessed.Add(Tuple.Create(true, address, data));
            Core.WriteData(this, address, data);
        }
예제 #10
0
        void Core_InsertLargeMap(string filepath)
        {
            try
            {
                Palette palette = Core.FindPaletteFile(filepath);

                CurrentLargeMap = new WorldMap_FE8_Large(filepath, palette);
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the large world map image.", ex); return;
            }

            byte[] data_palette = Palette.Merge(CurrentLargeMap.Palettes).ToBytes(false);
            byte[] data_tileset = CurrentLargeMap.Graphics.ToBytes(false);
            byte[] data_tsa     = LZ77.Compress(CurrentLargeMap.GetPaletteMap());

            Core.SuspendUpdate();

            bool cancel = Prompt.ShowRepointDialog(this, "Repoint Large World Map",
                                                   "The different parts of this image may need to be repointed upon insertion.",
                                                   CurrentEntry("Large"), new Tuple <string, Pointer, int>[] {
                Tuple.Create("Palette", Core.GetPointer("Large World Map Palette"), data_palette.Length),
                Tuple.Create("Tileset", Core.GetPointer("Large World Map Tileset"), data_tileset.Length),
                Tuple.Create("TSA", Core.GetPointer("Large World Map TSA"), data_tsa.Length)
            });

            if (cancel)
            {
                return;
            }

            Core.WriteData(this,
                           Core.GetPointer("Large World Map Palette"),
                           data_palette,
                           CurrentEntry("Large") + "Palette changed");

            Core.WriteData(this,
                           Core.GetPointer("Large World Map Tileset"),
                           data_tileset,
                           CurrentEntry("Large") + "Graphics changed");

            Core.WriteData(this,
                           Core.GetPointer("Large World Map TSA"),
                           data_tsa,
                           CurrentEntry("Large") + "TSA changed");

            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #11
0
        public void Core_Write()
        {
            if (Current[Entry_NumBox.Value].IsAffineSprite())
            {
                while (Affine_Index_NumBox.Value >= Current.Affines.Count)
                {
                    Current.Affines.Add(new OAM_Affine());
                }
            }

            Core.SuspendUpdate();
            try
            {
                byte[] data;

                if (Compressed < 0)
                {
                    data = Current.ToBytes();
                }
                else // its in a compressed OAM data block
                {
                    data = Core.ReadData(Address, 0);
                    byte[] oam = Current.ToBytes();
                    Array.Copy(oam, 0, data, Compressed, oam.Length);
                    data = LZ77.Compress(data);
                }
                Pointer address = Core.FindData(Address.ToBytes(), 4);
                bool    cancel  = Prompt.ShowRepointDialog(this, "Repoint OAM Data",
                                                           "The OAM data to insert might need to be repointed.", Entry,
                                                           new Tuple <string, Pointer, int>[] { Tuple.Create("OAM Data", Address, data.Length) },
                                                           new Pointer[] { address });
                if (cancel)
                {
                    return;
                }

                Address = Core.ReadPointer(address);

                Core.WriteData(this,
                               Address, data,
                               Entry + "OAM changed");
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the OAM data.", ex);
            }
            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #12
0
        public Byte[] ToBytes()
        {
            byte[] result = new byte[2 + WidthTiles * HeightTiles * 2];
            result[0] = WidthTiles;
            result[1] = HeightTiles;
            int x = 0;
            int y = 0;

            for (int i = 2; i < result.Length; i += 2)
            {
                result[i]     = (byte)((Layout[x, y] << 2) & 0xFF);
                result[i + 1] = (byte)(Layout[x, y] >> 6);
                x++;
                if (x % WidthTiles == 0)
                {
                    x = 0; y++;
                }
            }
            return(LZ77.Compress(result));
        }
예제 #13
0
        void Core_WriteSmallMap(string path)
        {
            try
            {
                CurrentSmallMap = new WorldMap_FE6_Small(path);
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the image.", ex); return;
            }

            byte[] data_palette = CurrentSmallMap.Colors.ToBytes(true);
            byte[] data_tileset = LZ77.Compress(CurrentSmallMap.ToBytes());

            Core.SuspendUpdate();

            bool cancel = Prompt.ShowRepointDialog(this, "Repoint Small World Map",
                                                   "The different parts of this image may need to be repointed upon insertion.",
                                                   CurrentEntry(true), new Tuple <string, Pointer, int>[] {
                Tuple.Create("Palette", Core.GetPointer("Small World Map Palette"), data_palette.Length),
                Tuple.Create("Tileset", Core.GetPointer("Small World Map Tileset"), data_tileset.Length)
            });

            if (cancel)
            {
                return;
            }

            Core.WriteData(this,
                           Core.GetPointer("Small World Map Palette"),
                           data_palette,
                           CurrentEntry(true) + "Palette changed");

            Core.WriteData(this,
                           Core.GetPointer("Small World Map Tileset"),
                           data_tileset,
                           CurrentEntry(true) + "Tileset changed");

            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #14
0
        public static Tuple <uint, uint> Compress(Stream inStream, Stream outStream)
        {
            var crc         = Crc32.InitCrc();
            var count       = 0u;
            var bitOut      = new BitStream.BitWriter(outStream);
            var lookupPair  = Huffman.HuffmanTree.StaticTree.GetLookupTable(287);
            var codeTable   = lookupPair.Item1;
            var lengthTable = lookupPair.Item2;

            while (true)
            {
                var buffer = new byte[(1 << 16) - 1];
                var size   = 0;
                int delta;
                while ((delta = inStream.Read(buffer, size, (1 << 16) - 1 - size)) > 0)
                {
                    size += delta;
                }
                if (size == 0)
                {
                    break;
                }
                count += (uint)size;  // TODO is it guarantees to be correct after overflow (modulo 1 << 32)?
                for (var i = 0; i < size; i++)
                {
                    Crc32.NextCrc(ref crc, buffer[i]);
                }
                var lzCompressed = LZ77.Compress(buffer, size);
                bitOut.WriteBits(2, 3);
                for (var i = 0; i < size; i++)
                {
                    bitOut.WriteBits(codeTable[lzCompressed[i]], lengthTable[lzCompressed[i]]);
                }
                bitOut.WriteBits(codeTable[256], lengthTable[256]);
            }
            bitOut.WriteBits(3, 3);
            bitOut.WriteBits(codeTable[256], lengthTable[256]);
            bitOut.Flush();
            Crc32.FinishCrc(ref crc);
            return(new Tuple <uint, uint>(crc, count));
        }
예제 #15
0
        void Core_WriteLargeMap(string path)
        {
            try
            {
                CurrentLargeMap = new WorldMap_FE6_Large(new Bitmap(path));
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the image.", ex); return;
            }

            Core.SuspendUpdate();

            Core.WriteData(this,
                           LargeMap_PalettePointerBox.Value,
                           CurrentLargeMap.Graphics[0].Colors.ToBytes(true),
                           CurrentEntry(true) + "Palette changed");

            Core.WriteData(this,
                           LargeMap_TL_GraphicsPointerBox.Value,
                           LZ77.Compress(CurrentLargeMap.Graphics[0].ToBytes()),
                           CurrentEntry(true) + "Graphics (TL) changed");
            Core.WriteData(this,
                           LargeMap_TR_GraphicsPointerBox.Value,
                           LZ77.Compress(CurrentLargeMap.Graphics[1].ToBytes()),
                           CurrentEntry(true) + "Graphics (TR) changed");
            Core.WriteData(this,
                           LargeMap_BL_GraphicsPointerBox.Value,
                           LZ77.Compress(CurrentLargeMap.Graphics[2].ToBytes()),
                           CurrentEntry(true) + "Graphics (BL) changed");
            Core.WriteData(this,
                           LargeMap_BR_GraphicsPointerBox.Value,
                           LZ77.Compress(CurrentLargeMap.Graphics[3].ToBytes()),
                           CurrentEntry(true) + "Graphics (BR) changed");

            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #16
0
        void Core_Insert(Portrait insert)
        {
            Core.SuspendUpdate();
            try
            {
                int header = ((Core.CurrentROM is FE8 ||
                               (Core.CurrentROM is FE7 && Core.CurrentROM.Version == GameVersion.JAP)) ? 4 : 0);
                byte[] data_main    = insert.Sprites[Portrait.MAIN].Sheet.ToBytes(false);
                byte[] data_chibi   = null;
                byte[] data_mouth   = null;
                byte[] data_palette = new byte[Palette.LENGTH];
                Array.Copy(insert.Colors.ToBytes(false), data_palette, insert.Colors.Count * 2);

                var repoints = new List <Tuple <string, Pointer, int> >();
                var writepos = new List <Pointer>();

                repoints.Add(Tuple.Create("Palette", (Pointer)Current["Palette"], data_palette.Length));
                writepos.Add(Current.GetAddress(Current.EntryIndex, "Palette"));

                if (IsGenericClassCard)
                {
                    data_main = LZ77.Compress(data_main);

                    repoints.Add(Tuple.Create("Card", (Pointer)Current["Card"], header + data_main.Length));
                    writepos.Add(Current.GetAddress(Current.EntryIndex, "Card"));
                }
                else
                {
                    data_chibi = insert.Sprites[Portrait.CHIBI].Sheet.ToBytes(false);
                    data_mouth = insert.Sprites[Portrait.MOUTH].Sheet.ToBytes(false);

                    if (Core.CurrentROM is FE6 ||
                        (Core.CurrentROM is FE7 && Core.CurrentROM.Version != GameVersion.JAP))
                    {
                        data_main = LZ77.Compress(data_main);
                    }

                    repoints.Add(Tuple.Create("Face", (Pointer)Current["Face"], header + data_main.Length));
                    writepos.Add(Current.GetAddress(Current.EntryIndex, "Face"));

                    if (!(Core.CurrentROM is FE6))
                    {
                        repoints.Add(Tuple.Create("Mouth", (Pointer)Current["Mouth"], data_mouth.Length));
                        writepos.Add(Current.GetAddress(Current.EntryIndex, "Mouth"));

                        data_chibi = LZ77.Compress(data_chibi);
                    }
                    repoints.Add(Tuple.Create("Chibi", (Pointer)Current["Chibi"], data_chibi.Length));
                    writepos.Add(Current.GetAddress(Current.EntryIndex, "Chibi"));
                }

                bool cancel = Prompt.ShowRepointDialog(this, "Repoint Portrait",
                                                       "The portrait to insert might need some of its parts to be repointed.",
                                                       CurrentEntry, repoints.ToArray(), writepos.ToArray());
                if (cancel)
                {
                    return;
                }

                Core.WriteData(this,
                               (Pointer)Current["Palette"],
                               data_palette,
                               CurrentEntry + "Palette changed");

                if (IsGenericClassCard)
                {
                    Core.WriteData(this,
                                   (Pointer)Current["Card"],
                                   data_main,
                                   CurrentEntry + "Image changed");
                }
                else
                {
                    Core.WriteData(this,
                                   (Pointer)Current["Face"] + header,
                                   data_main,
                                   CurrentEntry + "Main image changed");

                    Core.WriteData(this,
                                   (Pointer)Current["Chibi"],
                                   data_chibi,
                                   CurrentEntry + "Chibi image changed");

                    if (!(Program.Core.CurrentROM is FE6))
                    {
                        Core.WriteData(this,
                                       (Pointer)Current["Mouth"],
                                       data_mouth,
                                       CurrentEntry + "Mouth image changed");
                    }
                }
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the image.", ex);
            }
            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #17
0
    public static byte[] CompressStr(string data)
    {
        LZ77 lz = new LZ77();

        return(lz.Compress(Encoding.Default.GetBytes(data), 50));
    }
예제 #18
0
        void Core_Insert(Background insert)
        {
            Core.SuspendUpdate();
            try
            {
                bool compressed = (CurrentType == BackgroundType.Battle);

                byte[] data_palette = Palette.Merge(insert.Palettes).ToBytes(compressed);
                byte[] data_tileset = insert.Graphics.ToBytes(false); // is compressed below
                byte[] data_tsa     = insert.Tiling.ToBytes(compressed, !compressed);

                var repoints = new List <Tuple <string, Pointer, int> >();
                var writepos = new List <Pointer>();

                List <byte[]> strips = new List <byte[]>();
                if (CurrentType == BackgroundType.Screen &&
                    (Core.CurrentROM is FE8 ||
                     (Core.CurrentROM is FE7 &&
                      Core.CurrentROM.Version != GameVersion.JAP &&
                      (byte)Current["Strips"] == 0x01)))
                {
                    byte[] buffer = new byte[32 * 2 * GBA.Tile.LENGTH];
                    for (int i = 0; i < 10; i++)
                    {
                        Array.Copy(data_tileset, i * buffer.Length, buffer, 0, Math.Min(data_tileset.Length - i * buffer.Length, buffer.Length));
                        strips.Add(LZ77.Compress(buffer));

                        repoints.Add(Tuple.Create("Tileset " + i, Core.ReadPointer((Pointer)Current["Tileset"] + i * 4), strips[i].Length));
                        writepos.Add(Current.GetAddress(Current.EntryIndex, "Tileset") + i * 4);
                    }
                }
                else
                {
                    data_tileset = LZ77.Compress(data_tileset);

                    repoints.Add(Tuple.Create("Tileset", (Pointer)Current["Tileset"], data_tileset.Length));
                    writepos.Add(Current.GetAddress(Current.EntryIndex, "Tileset"));
                }
                repoints.Add(Tuple.Create("Palette", (Pointer)Current["Palette"], data_palette.Length));
                writepos.Add(Current.GetAddress(Current.EntryIndex, "Palette"));

                repoints.Add(Tuple.Create("TSA", (Pointer)Current["TSA"], data_tsa.Length));
                writepos.Add(Current.GetAddress(Current.EntryIndex, "TSA"));

                bool cancel = Prompt.ShowRepointDialog(this, "Repoint Background",
                                                       "The background to insert may need some of its parts to be repointed.",
                                                       CurrentEntry, repoints.ToArray(), writepos.ToArray());
                if (cancel)
                {
                    return;
                }

                if (CurrentType == BackgroundType.Screen && (Core.CurrentROM is FE8 ||
                                                             (Core.CurrentROM is FE7 && Core.ReadByte(Current.Address) == 0x01)))
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Core.WriteData(this,
                                       Core.ReadPointer((Pointer)Current["Tileset"] + i * 4),
                                       strips[i],
                                       CurrentEntry + "Tileset " + i + " changed");
                    }
                }   // write graphics in 32x2 strips
                else
                {
                    Core.WriteData(this,
                                   (Pointer)Current["Tileset"],
                                   data_tileset,
                                   CurrentEntry + "Tileset changed");
                }

                Core.WriteData(this,
                               (Pointer)Current["Palette"],
                               data_palette,
                               CurrentEntry + "Palette changed");

                Core.WriteData(this,
                               (Pointer)Current["TSA"],
                               data_tsa,
                               CurrentEntry + "TSA changed");
            }
            catch (Exception ex)
            {
                Program.ShowError("Could not insert the background.", ex);
            }
            Core.ResumeUpdate();
            Core.PerformUpdate();
        }
예제 #19
0
        public static void Compress(object sender, EventArgs e)
        {
            var tsi = sender as ToolStripMenuItem;

            if (!Shared.PrepareFiles("Open a decompressed " + tsi?.Tag + "file...", "Save your compressed file...", ".decomp", out var openFile, out var saveFile, true))
            {
                return;
            }

            try
            {
                using (openFile)
                    using (var outFs = new BinaryWriterX(saveFile))
                        switch (tsi?.Tag)
                        {
                        case Compression.L5LZ10:
                            outFs.Write(Level5.Compress(openFile, Level5.Method.LZ10));
                            break;

                        case Compression.L5Huff4:
                            outFs.Write(Level5.Compress(openFile, Level5.Method.Huffman4Bit));
                            break;

                        case Compression.L5Huff8:
                            outFs.Write(Level5.Compress(openFile, Level5.Method.Huffman8Bit));
                            break;

                        case Compression.L5RLE:
                            outFs.Write(Level5.Compress(openFile, Level5.Method.RLE));
                            break;

                        case Compression.NLZ10:
                            outFs.Write(Nintendo.Compress(openFile, Nintendo.Method.LZ10));
                            break;

                        case Compression.NLZ11:
                            outFs.Write(Nintendo.Compress(openFile, Nintendo.Method.LZ11));
                            break;

                        case Compression.NLZ60:
                            outFs.Write(Nintendo.Compress(openFile, Nintendo.Method.LZ60));
                            break;

                        case Compression.NHuff4:
                            outFs.Write(Nintendo.Compress(openFile, Nintendo.Method.Huff4));
                            break;

                        case Compression.NHuff8:
                            outFs.Write(Nintendo.Compress(openFile, Nintendo.Method.Huff8));
                            break;

                        case Compression.NRLE:
                            outFs.Write(Nintendo.Compress(openFile, Nintendo.Method.RLE));
                            break;

                        case Compression.LZ77:
                            outFs.Write(LZ77.Compress(openFile));
                            break;

                        case Compression.RevLZ77:
                            outFs.Write(RevLZ77.Compress(openFile));
                            break;

                        case Compression.LZOvl:
                            outFs.Write(LZOvl.Compress(openFile));
                            break;

                        case Compression.LZ4:
                            outFs.Write(Kontract.Compression.LZ4.Compress(openFile));
                            break;

                        case Compression.MIO0LE:
                            outFs.Write(MIO0.Compress(openFile, ByteOrder.LittleEndian));
                            break;

                        case Compression.MIO0BE:
                            outFs.Write(MIO0.Compress(openFile, ByteOrder.BigEndian));
                            break;

                        case Compression.Yay0LE:
                            outFs.Write(Yay0.Compress(openFile, ByteOrder.LittleEndian));
                            break;

                        case Compression.Yay0BE:
                            outFs.Write(Yay0.Compress(openFile, ByteOrder.BigEndian));
                            break;

                        case Compression.Yaz0LE:
                            outFs.Write(Yaz0.Compress(openFile, ByteOrder.LittleEndian));
                            break;

                        case Compression.Yaz0BE:
                            outFs.Write(Yaz0.Compress(openFile, ByteOrder.BigEndian));
                            break;

                        case Compression.GZip:
                            outFs.Write(GZip.Compress(openFile));
                            break;

                        case Compression.ZLib:
                            outFs.Write(ZLib.Compress(openFile));
                            break;

                        case Compression.PSVSpikeChun:
                            outFs.Write(PSVSpikeChun.Compress(openFile));
                            break;
                        }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), tsi?.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show($"Successfully compressed {Path.GetFileName(openFile.Name)}.", tsi.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #20
0
 public void InsertLZ77CompressedData(int offset, byte[] data, int index, int length)
 {
     byte[] compressedData = LZ77.Compress(data, index, length);
     this.InsertData(offset, compressedData);
 }
예제 #21
-4
파일: lz77.cs 프로젝트: gitPhate/lz77-kit
 public static byte[] CompressStr(string data)
 {
     LZ77 lz = new LZ77();
     return lz.Compress(Encoding.Default.GetBytes(data), 50);
 }