Esempio n. 1
0
            public Z64File ToFile(Z64Game game)
            {
                if (!Valid())
                {
                    return(new Z64File(null, -1, -1, -1, false));
                }

                if (!Exist())
                {
                    return(Z64File.DeletedFile(VRomStart, RomStart, VRomEnd - VRomStart));
                }

                int len = GetSize();

                byte[] data = new byte[len];
                Buffer.BlockCopy(game.Rom.RawRom, RomStart, data, 0, len);

                int romEnd = RomStart + data.Length;

                if (Compressed())
                {
                    data = Yaz0.Decompress(data);
                }

                return(new Z64File(data, VRomStart, RomStart, romEnd, Compressed()));
            }
Esempio n. 2
0
        public void Load(string filename)
        {
            FileInfo = new FileInfo(filename);

            using (var br = new BinaryReaderX(FileInfo.OpenRead()))
            {
                _sarc = new SARC(new MemoryStream(Yaz0.Decompress(new MemoryStream(br.ReadBytes((int)FileInfo.Length)), ByteOrder.BigEndian)));
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            String file = args[0];

            byte[] uncompressed = Yaz0.Decompress(file);
            String output       = Path.GetDirectoryName(file) + "test.notyaz0";

            File.WriteAllBytes(output, uncompressed);
        }
Esempio n. 4
0
        private void ImportDlcVillager()
        {
            if (_villager.Data.VillagerId < 0xE0EC || _villager.Data.VillagerId > 0xE0FF)
            {
                MessageBox.Show("You must set your villager to one of the DLC villagers before importing!", "DLC Villager Import Info");
                return;
            }

            using (var openFileDialog = new OpenFileDialog {
                Filter = "Yaz0 compressed file|*.yaz0"
            })
            {
                if (openFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                byte[] villagerData = null;
                try
                {
                    villagerData = System.IO.File.ReadAllBytes(openFileDialog.FileName);
                }
                catch
                {
                    MessageBox.Show("An error occurred while importing the DLC villager info.\nPlease try again!",
                                    "DLC Villager Import Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    if (villagerData != null)
                    {
                        _villager.ImportDlcVillager(villagerData, (_villager.Data.VillagerId - 0xEC) & 0xFF);

                        // Decompress Yaz0 data and set accordingly
                        var decompressedData = Yaz0.Decompress(villagerData);
                        _villager.Name             = new AcString(decompressedData.Skip(1).Take(6).ToArray(), _saveFile.SaveType).Trim();
                        _villager.Data.Catchphrase = new AcString(decompressedData.Skip(7).Take(4).ToArray(), _saveFile.SaveType).Trim();
                        _shirtEditor.Item          = new Item((ushort)(0x2400 | decompressedData[0xE]));
                        _villager.Data.Personality = decompressedData[0xD];

                        // Update controls to reflect changes
                        _nameBox.Text                 = _villager.Name;
                        _catchphraseBox.Text          = _villager.Data.Catchphrase;
                        _personalityBox.SelectedIndex = _villager.Data.Personality;

                        MessageBox.Show("DLC Villager import was succsessful!", "DLC Villager Import Info",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
Esempio n. 5
0
        private void decompressYaz0ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                using (var ofd = new OpenFileDialog())
                {
                    if (ofd.ShowDialog(this) != DialogResult.OK)
                    {
                        return;
                    }

                    using (var stream = ofd.OpenFile())
                        using (var outputStream = new MemoryStream())
                        {
                            Yaz0.Decompress(stream, outputStream);

                            using (var sfd = new SaveFileDialog())
                            {
                                sfd.FileName = ofd.FileName;

                                if (sfd.ShowDialog(this) != DialogResult.OK)
                                {
                                    return;
                                }

                                using (var outputFile = sfd.OpenFile())
                                {
                                    outputStream.Seek(0, SeekOrigin.Begin);
                                    outputStream.CopyTo(outputFile);
                                }
                            }
                        }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 6
0
        static void Test(byte[] bytes, Method method)
        {
            var bytes2 = new byte[bytes.Length];

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

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

            case Method.Yay0:
                bytes2 = Yay0.Decompress(new MemoryStream(Yay0.Compress(new MemoryStream(bytes))));
                Assert.IsTrue(bytes.SequenceEqual(bytes2));
                break;
            }
        }
Esempio n. 7
0
        public static void Decompress(object sender, EventArgs e)
        {
            var tsi = sender as ToolStripMenuItem;

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

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

                        case Compression.Nintendo:
                            outFs.Write(Nintendo.Decompress(openFile));
                            break;

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

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

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

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

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

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

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

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

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

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

                        case Compression.LZECD:
                            outFs.Write(LZECD.Decompress(openFile));
                            break;

                        case Compression.LZ10VLE:
                            outFs.Write(LZSSVLE.Decompress(openFile));
                            break;

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

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

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

            MessageBox.Show($"Successfully decompressed {Path.GetFileName(openFile.Name)}.", tsi.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
        }