Пример #1
1
        public MULT(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode, System.Drawing.Color Color = default(System.Drawing.Color))
        {
            ParentFile = FE;

            byte[] SrcData = ParentFile.GetFileData();

            Offset = SrcOffset;

            _Translation = new Vector2(
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x04)));
            _Rotation = ((short)(Helpers.Read16(SrcData, SrcOffset + 0x08)) / 182.04444444444444f).Clamp(-180, 179);
            _RoomNumber = SrcData[SrcOffset + 0x0A];
            _Unknown2 = SrcData[SrcOffset + 0x0B];

            SrcOffset += 0x0C;

            RenderColor = Color;

            Node = Helpers.CreateTreeNode(string.Format("{0:X6}: {1}", Offset, new Vector2(_Translation.X / 100000, _Translation.Y / 100000)), this, string.Format("{0}", _Translation));
            ParentNode.BackColor = RenderColor;
            ParentNode.Nodes.Add(Node);

            GLID = GL.GenLists(1);
            GL.NewList(GLID, ListMode.Compile);
            Helpers.DrawFramedCube(new Vector3d(15, 15, 15));
            GL.EndList();
        }
Пример #2
0
        public Generic(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode)
        {
            ParentFile = FE;
            Node = ParentNode;

            Offset = SrcOffset;
        }
Пример #3
0
        public LGTV(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode, System.Drawing.Color Color = default(System.Drawing.Color))
        {
            ParentFile = FE;

            byte[] SrcData = ParentFile.GetFileData();

            Offset = SrcOffset;

            _Unknown1 = new Vector3(
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x04)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x08)));
            _Unknown2 = new Vector3(
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x0C)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x10)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x14)));
            _Unknown3 = Helpers.Read32(SrcData, SrcOffset + 0x18);

            SrcOffset += 0x1C;

            RenderColor = Color;

            Node = Helpers.CreateTreeNode(string.Format("{0:X6}", Offset), this, string.Format("{0}\n{1}\n0x{2:X8}", _Unknown1, _Unknown2, _Unknown3));
            ParentNode.BackColor = RenderColor;
            ParentNode.Nodes.Add(Node);
        }
Пример #4
0
        public FilePropertyForm(TreeView treeview, RARC archive)
        {
            InitializeComponent();
            CancelButton        = DiscardButton;
            AcceptButton        = OKButton;
            MRAMRadioButton.Tag = RARC.FileAttribute.PRELOAD_TO_MRAM;
            ARAMRadioButton.Tag = RARC.FileAttribute.PRELOAD_TO_ARAM;
            DVDRadioButton.Tag  = RARC.FileAttribute.LOAD_FROM_DVD;

            ArchiveTreeView         = treeview;
            Archive                 = archive;
            CurrentFile             = Archive[ArchiveTreeView.SelectedNode.FullPath] as RARC.File;
            IDNumericUpDown.Enabled = !Archive.KeepFileIDsSynced;
            CenterToParent();

            for (int i = 0; i < Controls.Count; i++)
            {
                Controls[i].BackColor = Program.ProgramColours.ControlBackColor;
                Controls[i].ForeColor = Program.ProgramColours.TextColour;
            }
            AutoDetectSettingsButton.BackColor = BackColor = Program.ProgramColours.ControlBackColor;
            AutoDetectSettingsButton.ForeColor = ForeColor = NameTextBox.ForeColor = IDNumericUpDown.ForeColor = Program.ProgramColours.TextColour;
            NameTextBox.BackColor   = IDNumericUpDown.BackColor = Program.ProgramColours.WindowColour;
            NameTextBox.BorderColor = IDNumericUpDown.BorderColor = Program.ProgramColours.BorderColour;
            //FileSettingsGroupBox.BackColor = Program.ProgramColours.WindowColour;
        }
Пример #5
0
        public RPPN(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode, System.Drawing.Color Color = default(System.Drawing.Color))
        {
            ParentFile = FE;

            byte[] SrcData = ParentFile.GetFileData();

            Offset = SrcOffset;

            _Unknown = Helpers.Read32(SrcData, SrcOffset);
            _Position = new Vector3(
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x04)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x08)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x0C)));

            SrcOffset += 0x10;

            RenderColor = Color;

            Node = Helpers.CreateTreeNode(string.Format("{0}", _Position), this);
            ParentNode.BackColor = RenderColor;
            ParentNode.Nodes.Add(Node);

            GLID = GL.GenLists(1);
            GL.NewList(GLID, ListMode.Compile);
            Helpers.DrawFramedSphere(new Vector3d(0, 0, 0), 25.0f, 10);
            GL.EndList();
        }
Пример #6
0
        public RenameForm(TreeView treeview, RARC archive)
        {
            InitializeComponent();
            CenterToParent();
            MaximumSize     = new Size(Screen.GetBounds(Location).Width, Height);
            MinimumSize     = Size;
            Archive         = archive;
            ArchiveTreeView = treeview;
            CurrentItem     = Archive[treeview.SelectedNode.FullPath];
            string OGName = CurrentItem.Name;

            Text = string.Format(Strings.RenameWindowTitle, OGName);
            if (!(CurrentItem is RARC.Directory))
            {
                FileInfo fi = new FileInfo(OGName);
                NameTextBox.Text      = Path.GetFileNameWithoutExtension(OGName);
                ExtensionTextBox.Text = fi.Extension;
            }
            else
            {
                ExtensionTextBox.Enabled = false;
                ExtensionLabel.Enabled   = false;
                NameTextBox.Text         = OGName;
            }

            ForeColor               = Program.ProgramColours.TextColour;
            BackColor               = Program.ProgramColours.ControlBackColor;
            OKButton.BackColor      = DiscardButton.BackColor = Program.ProgramColours.ControlBackColor;
            NameTextBox.BackColor   = ExtensionTextBox.BackColor = Program.ProgramColours.WindowColour;
            NameTextBox.ForeColor   = OKButton.ForeColor = DiscardButton.ForeColor = ExtensionTextBox.ForeColor = Program.ProgramColours.TextColour;
            NameTextBox.BorderColor = ExtensionTextBox.BorderColor = Program.ProgramColours.BorderColour;
        }
Пример #7
0
 public DZx(RARC.FileEntry FE, TreeNode TN, ZeldaArc PZA = null)
 {
     Root = TN;
     FileEntry = FE;
     ParentZA = PZA;
     Load();
 }
Пример #8
0
        public static TreeNode[] ToTreeNode(this RARC Arc, int FolderClosedID, ImageList images)
        {
            List <TreeNode> Nodes = new List <TreeNode>();
            TreeNode        Root  = Arc.Root.ToTreeNode(FolderClosedID, images);

            for (int i = 0; i < Root.Nodes.Count; i++)
            {
                Nodes.Add(Root.Nodes[i]);
            }
            return(Nodes.ToArray());
        }
Пример #9
0
 public static void FromTreeNode(this RARC Arc, TreeView Root)
 {
     string[] NewFileOrder = new string[Root.Nodes.Count];
     for (int i = 0; i < Root.Nodes.Count; i++)
     {
         if (Arc[Root.Nodes[i].FullPath] is RARC.Directory)
         {
             FromTreeNode(Arc, Root.Nodes[i]);
         }
         NewFileOrder[i] = Root.Nodes[i].Text;
     }
     Arc.Root.SortItemsByOrder(NewFileOrder);
 }
Пример #10
0
        public static void FromTreeNode(RARC Arc, TreeNode TN)
        {
            string[] NewFileOrder = new string[TN.Nodes.Count];
            for (int i = 0; i < TN.Nodes.Count; i++)
            {
                if (Arc[TN.Nodes[i].FullPath] is RARC.Directory)
                {
                    FromTreeNode(Arc, TN.Nodes[i]);
                }

                NewFileOrder[i] = TN.Nodes[i].Text;
            }
            ((RARC.Directory)Arc[TN.FullPath]).SortItemsByOrder(NewFileOrder);
        }
Пример #11
0
        /// <summary>
        /// Loads an archive into a <see cref="VirtualFilesystemDirectory"/>, automatically de-compressing the archive if required.
        /// </summary>
        /// <param name="filePath">Filepath of file to decompress and load.</param>
        /// <returns><see cref="VirtualFilesystemDirectory"/> containing the contents, or null if not an archive.</returns>
        public static VirtualFilesystemDirectory LoadArchive(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                throw new ArgumentNullException("filePath", "Cannot load archive from empty file path!");
            }

            if (!File.Exists(filePath))
            {
                throw new ArgumentException("Cannot load archive from non-existant file!", "filePath");
            }

            MemoryStream decompressedFile = null;

            using (EndianBinaryReader fileReader = new EndianBinaryReader(File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), Endian.Big))
            {
                // Read the first 4 bytes to see if it's a compressed file (Yaz0) or a plain RARC file.
                uint fileMagic = fileReader.ReadUInt32();
                fileReader.BaseStream.Position = 0L; // Reset to the start so that the next thing to read it is at the start like it expects.

                if (fileMagic == 0x59617A30)         // Yaz0
                {
                    Yaz0 yaz0 = new Yaz0();
                    decompressedFile = yaz0.Decode(fileReader);
                }
                else if (fileMagic == 0x52415243) // RARC
                {
                    // Copy the fileReader stream to a new memorystream.
                    decompressedFile = new MemoryStream((int)fileReader.BaseStream.Length);
                    fileReader.BaseStream.CopyTo(decompressedFile);
                    decompressedFile.Position = 0L;
                }
            }

            // Not an archive we know how to handle.
            if (decompressedFile == null)
            {
                return(null);
            }

            // Decompress the archive into the folder. It'll generate a sub-folder with the Archive's ROOT name.
            RARC rarc = new RARC();

            using (EndianBinaryReader reader = new EndianBinaryReader(decompressedFile, Endian.Big))
            {
                return(rarc.ReadFile(reader));
            }
        }
Пример #12
0
        public ZeldaArc(string File, TreeView TV, bool IgnoreModels = false)
        {
            Archive = new RARC(File);
            DZRs    = new List <DZx>();
            DZSs    = new List <DZx>();
            DZBs    = new List <DZB>();
            J3Dxs   = new List <J3Dx>();

            TreeNode NewNode = Helpers.CreateTreeNode(Archive.Filename, null);

            PopulateFileList(NewNode, Archive.Root, IgnoreModels);
            //TV.Nodes[TV.Nodes.Count - 1].Expand();
            //TV.SelectedNode = TV.Nodes[TV.Nodes.Count - 1];
            TV.Nodes.Add(NewNode);

            Filename = File;
        }
Пример #13
0
        public TGDR(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode, System.Drawing.Color Color = default(System.Drawing.Color), ZeldaArc ParentZA = null)
        {
            ParentFile = FE;

            byte[] SrcData = ParentFile.GetFileData();

            Offset = SrcOffset;

            _Name = Helpers.ReadString(SrcData, SrcOffset, 8);
            _Parameters = Helpers.Read32(SrcData, SrcOffset + 8);
            _Position = new Vector3(
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x0C)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x10)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x14)));

            _Unknown1 = Helpers.Read16(SrcData, SrcOffset + 0x18);
            _RotationY = ((short)Helpers.Read16(SrcData, SrcOffset + 0x1A) / 182.04444444444444).Clamp(-180, 179);
            _Unknown2 = Helpers.Read16(SrcData, SrcOffset + 0x1C);

            _Unknown3 = Helpers.Read16(SrcData, SrcOffset + 0x1E);
            _Unknown4 = Helpers.Read32(SrcData, SrcOffset + 0x20);

            SrcOffset += 0x24;

            RenderColor = Color;

            Node = Helpers.CreateTreeNode(string.Format("{0:X6}: {1}", Offset, _Name), this);
            ParentNode.BackColor = RenderColor;
            ParentNode.Nodes.Add(Node);

            GLID = GL.GenLists(1);
            GL.NewList(GLID, ListMode.Compile);

            if (ParentZA != null)
            {
                MatchedModel = ParentZA.J3Dxs.Find(x => x.FileEntry.FileName.StartsWith(_Name));
                MatchedCollision = ParentZA.DZBs.Find(x => x.Name.StartsWith(_Name));
            }

            Helpers.DrawFramedCube(new Vector3d(15, 15, 15));
            GL.EndList();
        }
Пример #14
0
        public MULT(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode, System.Drawing.Color Color = default(System.Drawing.Color))
        {
            ParentFile = FE;

            byte[] SrcData = ParentFile.GetFileData();

            Offset = SrcOffset;

            _HVTranslation = new Vector2(
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset)),
                Helpers.ConvertIEEE754Float(Helpers.Read32(SrcData, SrcOffset + 0x04)));
            _Unknown1 = Helpers.Read16(SrcData, SrcOffset + 0x08);
            _RoomNumber = SrcData[SrcOffset + 0x0A];
            _Unknown2 = SrcData[SrcOffset + 0x0B];

            SrcOffset += 0x0C;

            RenderColor = Color;

            Node = Helpers.CreateTreeNode(string.Format("{0:X6}: {1}", Offset, new Vector2(_HVTranslation.X / 100000, _HVTranslation.Y / 100000)), this, string.Format("{0}", _HVTranslation));
            ParentNode.BackColor = RenderColor;
            ParentNode.Nodes.Add(Node);
        }
Пример #15
0
        /// <summary>
        /// Process data in an input file that contains a layout.
        /// </summary>
        /// <param name="filename"></param>
        bool ProcessData(string filename, byte[] inData)
        {
            EndianBinaryReader reader = null;

            // now we need to decide what they just opened
            if (inData == null && filename != "")
            {
                reader = new EndianBinaryReader(File.Open(filename, FileMode.Open), Encoding.GetEncoding(932));
            }
            else
            {
                reader = new EndianBinaryReader(inData);
            }

            string magic = "";

            // we have a Yaz0 compressed file
            if (reader.ReadStringFrom(0, 4) == "Yaz0")
            {
                // we have to close our reader so we can properly read this file as a Yaz0 stream
                reader.Close();

                MemoryStream ms = null;

                if (inData == null)
                {
                    ms = new Yaz0(File.Open(filename, FileMode.Open));
                }
                else
                {
                    ms = new Yaz0(new MemoryStream(inData));
                }

                reader = new EndianBinaryReader(ms);
                magic  = reader.ReadStringFrom(0, 4);
            }
            // we have a LZ compressed file
            else if (reader.ReadByteFrom(0) == 0x11)
            {
                LZ77   lzFile = new LZ77(ref reader);
                byte[] lzData = lzFile.getData();
                // close our current reader to open a new one with our input data
                reader.Close();
                reader = new EndianBinaryReader(lzData);
                magic  = reader.ReadStringFrom(0, 4);
            }
            // no compression
            else
            {
                // it is not yaz0 compressed, so we see the magic
                magic = reader.ReadStringFrom(0, 4);
            }

            // now we have to check our magic to see what kind of file it is
            switch (magic)
            {
            case "darc":
                mArchive = new DARC(ref reader);
                break;

            case "NARC":
                mArchive = new NARC(ref reader);
                break;

            case "SARC":
                mArchive = new SARC(ref reader);
                break;

            case "RARC":
                reader.SetEndianess(Endianess.Big);
                mArchive = new RARC(ref reader);
                break;

            case "U?8-":
                reader.SetEndianess(Endianess.Big);
                mArchive = new U8(ref reader);
                break;

            default:
                MessageBox.Show("Error. Unsupported format with magic: " + magic);
                break;
            }

            string layoutType = "";

            // some files have their string table nullified, which makes the names obfuscated
            // I've only seen this in SARCs from MK7, but there's probably more
            if (mArchive != null)
            {
                if (mArchive.isStringTableObfuscated())
                {
                    MessageBox.Show("This file has obfuscated file names. The editor attempted to find layout files, but cannot supply names.");
                }
            }

            reader.Close();

            if (mArchive == null)
            {
                MessageBox.Show("Format not supported.");
                return(false);
            }

            // the only familiar format with archives in archives is SARC and RARC
            if (mArchive.getType() == ArchiveType.SARC || mArchive.getType() == ArchiveType.RARC)
            {
                List <string> names = mArchive.getArchiveFileNames();

                if (names.Count != 0)
                {
                    DialogResult res = MessageBox.Show("This archive has another archive inside of it.\nDo you wish to choose one of the found archives to select a layout?", "Internal Archive", MessageBoxButtons.YesNo);

                    if (res == DialogResult.Yes)
                    {
                        LayoutChooser archiveChooser = new LayoutChooser();
                        archiveChooser.insertEntries(names);
                        archiveChooser.ShowDialog();

                        // if this worked, we dont need to do anything
                        bool result = ProcessData(archiveChooser.getSelectedFile(), mArchive.getDataByName(archiveChooser.getSelectedFile()));

                        if (result)
                        {
                            return(true);
                        }
                        else
                        {
                            MessageBox.Show("Failed to get the internal file.");
                            return(false);
                        }
                    }
                }
            }

            // get all of our needed files
            mLayoutFiles     = mArchive.getLayoutFiles();
            mLayoutAnimFiles = mArchive.getLayoutAnimations();
            mLayoutImages    = mArchive.getLayoutImages();
            mLayoutControls  = mArchive.getLayoutControls();

            if (mLayoutFiles.Count == 0)
            {
                MessageBox.Show("This file contains no layouts.");
                return(false);
            }

            LayoutChooser layoutChooser = new LayoutChooser();

            layoutChooser.insertEntries(new List <string>(mLayoutFiles.Keys));
            layoutChooser.ShowDialog();

            string selectedFile = layoutChooser.getSelectedFile();

            if (selectedFile == null)
            {
                return(false);
            }

            string[] sections = selectedFile.Split('/');
            mMainRoot = "";

            // remove "lyt" part and the file name
            // this will be our main root of the entire opened file
            for (int i = 0; i < sections.Length - 2; i++)
            {
                mMainRoot += sections[i] + "/";
            }

            if (layoutType == "")
            {
                layoutType = Path.GetExtension(selectedFile);
            }

            // now we have to init a layout reader
            EndianBinaryReader layoutReader = null;

            byte[] data;

            switch (layoutType)
            {
            case ".brlyt":
                data         = mLayoutFiles[selectedFile];
                layoutReader = new EndianBinaryReader(data);
                mMainLayout  = new BRLYT(ref layoutReader);
                layoutReader.Close();
                break;

            case ".bclyt":
                data         = mLayoutFiles[selectedFile];
                layoutReader = new EndianBinaryReader(data);
                mMainLayout  = new BCLYT(ref layoutReader);
                break;

            case ".bflyt":
                data         = mLayoutFiles[selectedFile];
                layoutReader = new EndianBinaryReader(data);
                mMainLayout  = new BFLYT(ref layoutReader);
                break;

            case ".blo":
                data         = mLayoutFiles[selectedFile];
                layoutReader = new EndianBinaryReader(data);

                if (layoutReader.ReadStringFrom(4, 4) == "blo1")
                {
                    mMainLayout = new BLO1(ref layoutReader);
                }
                else
                {
                    mMainLayout = new BLO2(ref layoutReader);
                }
                break;

            default:
                MessageBox.Show("This format is not supported yet.");
                break;
            }

            layoutReader.Close();

            if (mMainLayout == null)
            {
                return(false);
            }

            // set our propertygrid with our LYT object
            mainPropertyGrid.SelectedObject = mMainLayout.getLayoutParams();

            if (mMainLayout.getRootPanel() == null)
            {
                MessageBox.Show("Error, the root pane in this layout is not specified.");
                return(false);
            }

            LayoutBase pane  = null;
            LayoutBase group = null;

            // now we have to grab our root panel, which is different on each console
            // so we have to specifically get the one we want
            // the same applies to our root group
            pane = mMainLayout.getRootPanel();

            // this should be RootPane
            TreeNode n1 = new TreeNode
            {
                Tag  = pane,
                Name = pane.mName,
                Text = pane.mName,
            };

            panelList.Nodes.Add(n1);
            fillNodes(pane.getChildren());

            // now for our groups
            group = mMainLayout.getRootGroup();

            if (group != null)
            {
                TreeNode n1_1 = new TreeNode
                {
                    Tag  = group,
                    Name = group.mName,
                    Text = group.mName,
                };

                panelList.Nodes.Add(n1_1);
                fillNodes(group.getChildren());
            }

            // now for textures and fonts
            // but it is possible for either one to not exist
            if (mMainLayout.containsTextures())
            {
                foreach (string str in mMainLayout.getTextureNames())
                {
                    texturesList.Items.Add(str);
                }
            }

            if (mMainLayout.containsFonts())
            {
                foreach (string str in mMainLayout.getFontNames())
                {
                    fontsList.Items.Add(str);
                }
            }

            // and our materials
            if (mMainLayout.containsMaterials())
            {
                foreach (string str in mMainLayout.getMaterialNames())
                {
                    materialList.Items.Add(str);
                }
            }

            // this draws the border of the layout
            mMainLayout.draw();

            layoutViewer.Refresh();

            return(true);
        }
Пример #16
0
            public FileChunk(RARC.FileEntry FE, ref int SrcOffset, TreeNode ParentNode, ZeldaArc ParentZA = null)
            {
                byte[] SrcData = FE.GetFileData();

                Tag = Helpers.ReadString(SrcData, SrcOffset, 4);
                Elements = Helpers.Read32(SrcData, SrcOffset + 4);
                Offset = Helpers.Read32(SrcData, SrcOffset + 8);

                Data = new object[Elements];

                TreeNode NewNode = Helpers.CreateTreeNode(Tag, this, string.Format("Offset: {0:X6}\n{1} elements", Offset, Elements));

                int ReadOffset = (int)Offset;
                for (int i = 0; i < Elements; i++)
                {
                    switch (Tag)
                    {
                        /* Typically in DZR */
                        case "ACTR": Data[i] = new ACTR(FE, ref ReadOffset, NewNode, System.Drawing.Color.GreenYellow, ParentZA); continue;
                        case "TGOB": Data[i] = new ACTR(FE, ref ReadOffset, NewNode, System.Drawing.Color.GreenYellow, ParentZA); continue;
                        case "PLYR": Data[i] = new ACTR(FE, ref ReadOffset, NewNode, System.Drawing.Color.Orange); continue;
                        case "PPNT":    /* Found in DmSpot0's Stage DZS for some reason... */
                        case "RPPN": Data[i] = new RPPN(FE, ref ReadOffset, NewNode, System.Drawing.Color.LightSkyBlue); continue;
                        case "SHIP": Data[i] = new SHIP(FE, ref ReadOffset, NewNode, System.Drawing.Color.BlueViolet); continue;
                        case "TGDR":
                        case "DOOR":
                        case "Door": Data[i] = new TGDR(FE, ref ReadOffset, NewNode, System.Drawing.Color.HotPink, ParentZA); continue;
                        case "LGTV": Data[i] = new LGTV(FE, ref ReadOffset, NewNode, System.Drawing.Color.DarkGray); continue;  /* ????? */

                        /* Typically in DZS */
                        case "MULT": Data[i] = new MULT(FE, ref ReadOffset, NewNode, System.Drawing.Color.LightGray); continue;
                        case "TRES": Data[i] = new TRES(FE, ref ReadOffset, NewNode, System.Drawing.Color.SaddleBrown); continue;
                        //case "EnvR": Data[i] = new EnvRChunk(FE, ref ReadOffset, NewNode, System.Drawing.Color.DarkSlateGray); continue;
                    }

                    switch (Tag.Substring(0, 3))
                    {
                        case "ACT": Data[i] = new ACTR(FE, ref ReadOffset, NewNode, System.Drawing.Color.GreenYellow, ParentZA); break;
                        case "PLY": Data[i] = new ACTR(FE, ref ReadOffset, NewNode, System.Drawing.Color.Orange); break;
                        case "SCO": Data[i] = new TGDR(FE, ref ReadOffset, NewNode, System.Drawing.Color.Yellow, ParentZA); break;
                        case "TRE": Data[i] = new TRES(FE, ref ReadOffset, NewNode, System.Drawing.Color.SaddleBrown); break;
                        default: Data[i] = new Generic(FE, ref ReadOffset, NewNode); NewNode.Tag = Data[i]; break;
                    }
                }

                ParentNode.Nodes.Add(NewNode);

                SrcOffset += 12;
            }
 public RARCViewer(RARC Archive)
 {
     this.Archive = Archive;
     Root         = Archive.ToFileSystem();
     InitializeComponent();
 }
Пример #18
0
        static void Main(string[] OpenWith)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (Settings.Default.IsNeedUpgrade)
            {
                Settings.Default.Upgrade();
                Settings.Default.IsNeedUpgrade = false;
                Settings.Default.Save();
            }

            if (OpenWith.Length > 1)
            {
                if ((OpenWith[0].Equals("--script") || OpenWith[0].Equals("-ss")))
                {
                    AttachConsole(ATTACH_PARENT_PROCESS);
                    List <string> Parameters = new List <string>();
                    for (int i = 2; i < OpenWith.Length; i++)
                    {
                        Parameters.Add(OpenWith[i]);
                    }
                    RunScript(OpenWith[1], Parameters.ToArray());
                    return;
                }
                if ((OpenWith[0].Equals("--pack") || OpenWith[0].Equals("-p")) && File.GetAttributes(OpenWith[OpenWith.Length - 1]) == FileAttributes.Directory)
                {
                    RARC Archive = new RARC();
                    Archive.Import(OpenWith[OpenWith.Length - 1]);
                    DirectoryInfo di     = new DirectoryInfo(OpenWith[OpenWith.Length - 1]);
                    string        output = Path.Combine(di.Parent.FullName, di.Name + ".arc");
                    Archive.Save(output);
                    if (OpenWith.Any(S => S.Equals("--yaz0") || S.Equals("-yz")))
                    {
                        YAZ0.Compress(output, OpenWith.Any(S => S.Equals("--fast") || S.Equals("-f")));
                    }
                    else if (OpenWith.Any(S => S.Equals("--yay0") || S.Equals("-yy")))
                    {
                        YAY0.Compress(output);
                    }
                    return;
                }
                else if ((OpenWith[0].Equals("--unpack") || OpenWith[0].Equals("-u")) && File.GetAttributes(OpenWith[OpenWith.Length - 1]) == FileAttributes.Normal)
                {
                    bool   IsYaz0  = YAZ0.Check(OpenWith[OpenWith.Length - 1]);
                    bool   IsYay0  = YAY0.Check(OpenWith[OpenWith.Length - 1]);
                    RARC   Archive = IsYaz0 ? new RARC(YAZ0.DecompressToMemoryStream(OpenWith[OpenWith.Length - 1]), OpenWith[OpenWith.Length - 1]) : (IsYay0 ? new RARC(YAY0.DecompressToMemoryStream(OpenWith[OpenWith.Length - 1]), OpenWith[OpenWith.Length - 1]) : new RARC(OpenWith[OpenWith.Length - 1]));
                    string output  = new FileInfo(Archive.FileName).Directory.FullName;
                    Archive.Export(output, OpenWith.Any(S => S.Equals("--overwrite") || S.Equals("-o")));
                    return;
                }

                for (int i = 0; i < OpenWith.Length; i++)
                {
                    if ((OpenWith[i].Equals("--lang") || OpenWith[i].Equals("-l")) && OpenWith.Length == i + 2)
                    {
                        Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(OpenWith[i + 1]);
                    }
                }
            }
            //Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("ja");

            if (OpenWith.Length == 0)
            {
                OpenWith = new string[1] {
                    null
                }
            }
            ;
            Application.Run(new MainForm(OpenWith[0]));
            return;
        }
        private void OpenFile()
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                IsBMGLoaded = false;

                IsBMCLoaded = false;

                if (Yaz0.IsYaz0Compressed(openFileDialog1.FileName))
                {
                    MessageBox.Show("Archive is compressed. Please decompress it.");

                    return;
                }

                RARC archive = new RARC(openFileDialog1.FileName);

                int numRARCNodes = archive.Nodes.Count();

                if (numRARCNodes < 0)
                    return;

                foreach (RARC.FileEntry entry in archive.Nodes[0].Entries)
                {
                    if (entry.Name.EndsWith(".bmg"))
                    {
                        TextBankBMG = entry;

                        TextBankClass = new BMG_New(new EndianBinaryReader(entry.Data, Endian.Big));

                        if (TextBankClass.IsWindWaker == false)
                        {
                            MessageBox.Show("The BMG file in this archive is not from The Wind Waker. BMG files from other games are not supported at this time.");

                            return;
                        }

                        ArcFilePath = openFileDialog1.FileName;

                        saveFileDialog1.InitialDirectory = ArcFilePath;

                        IsBMGLoaded = true;

                        MessageList = TextBankClass.GetMessageList();

                        saveToolStripMenuItem.Enabled = true;
                        AddToolStrip.Enabled = true;
                        deleteToolStripMenuItem.Enabled = true;
                        proofreadToolStripMenuItem.Enabled = true;
                        searchBoxBackPanel.Controls[0].Enabled = true;
                        SearchButton.Enabled = true;
                        textOpt.Enabled = true;
                        idOpt.Enabled = true;

                        LoadMainUI();
                    }

                    if (entry.Name.EndsWith(".bmc"))
                    {
                        TextColorBMC = entry;
                        IsBMCLoaded = true;
                        textColorsToolStripMenuItem.Enabled = true;

                        ColorClass = new BMCParser(new EndianBinaryReader(entry.Data, Endian.Big));

                        ColorList = ColorClass.GetColorList();
                    }
                }

                if (!IsBMGLoaded && IsBMCLoaded)
                    MessageBox.Show("Archive does not contain a text bank (.bmg).");

                if (IsBMGLoaded && !IsBMCLoaded)
                    MessageBox.Show("Archive does not contain a text color file (.bmc).");

                if (!IsBMGLoaded && !IsBMCLoaded)
                    MessageBox.Show("Archive does not contain a text bank (.bmg) or a text color file (.bmc).");
            }

            return;
        }
Пример #20
0
 public DZB(RARC.FileEntry FE, TreeNode TN)
 {
     Root = TN;
     Name = FE.FileName;
     Load(FE.GetFileData());
 }
Пример #21
0
        static void RunScript(string Filename, string[] parameters)
        {
            Console.WriteLine("Loading {0}...", Filename);
            string[] Lines = File.ReadAllLines(Filename);
            Console.WriteLine("Script Loaded.");
            Thread.Sleep(100);
            RARC   CurrentArchive = null;
            string ErrorMessage   = "";

            for (int i = 0; i < Lines.Length; i++)
            {
                if (Lines[i].StartsWith("//") || string.IsNullOrWhiteSpace(Lines[i]))
                {
                    continue;
                }
                string   Line   = string.Format(Lines[i], parameters);
                string[] Params = Line.Split(' ');
                Console.WriteLine("Executing Line {1}: \"{0}\"", Lines[i], i);
                switch (Params[0])
                {
                case "new":     //new
                    if (CurrentArchive is null)
                    {
                        CurrentArchive         = new RARC();
                        CurrentArchive["Root"] = null;
                        Console.WriteLine("New Archive Created Successfully");
                    }
                    else
                    {
                        ErrorMessage = string.Format("Could not create a new archive:\n\tAn archive is already loaded in memory!");
                        goto Error;
                    }
                    break;

                case "open":     //open <filepath>
                    if (CurrentArchive is null)
                    {
                        if (Params.Length < 2)
                        {
                            ErrorMessage = string.Format("Incomplete Syntax - Expected\nopen <filepath>");
                            goto Error;
                        }
                        if (!File.Exists(Params[1]))
                        {
                            ErrorMessage = string.Format("File {0} could not be found", Params[1]);
                            goto Error;
                        }
                        bool IsYaz0 = YAZ0.Check(Params[1]);
                        bool IsYay0 = YAY0.Check(Params[1]);
                        CurrentArchive = IsYaz0 ? new RARC(YAZ0.DecompressToMemoryStream(Params[1]), Params[1]) : (IsYay0 ? new RARC(YAY0.DecompressToMemoryStream(Params[1]), Params[1]) : new RARC(Params[1]));
                        Console.WriteLine("Archive opened successfully!");
                    }
                    else
                    {
                        ErrorMessage = string.Format("Could not open the archive:\n\tAn archive is already loaded in memory!");
                        goto Error;
                    }
                    break;

                case "save":     //save [filepath]
                    if (CurrentArchive is null)
                    {
                        ErrorMessage = string.Format("Save Failed! No Archive Loaded");
                        goto Error;
                    }
                    CurrentArchive.Save(Params.Length == 1 ? CurrentArchive.FileName : Params[1]);
                    Console.WriteLine("Archive saved successfully!");
                    break;

                case "compress":     //compress <filepath> [-yz|-yy|-yzf]
                    if (Params.Length < 3)
                    {
                        ErrorMessage = string.Format("Incomplete Syntax - Expected\ncompress <filepath> [-yz|-yy|-yzf]");
                        goto Error;
                    }
                    if (!File.Exists(Params[1]))
                    {
                        ErrorMessage = string.Format("File {0} could not be found", Params[1]);
                        goto Error;
                    }
                    switch (Params[2])
                    {
                    case "-yz":
                    case "-yzf":
                        Console.WriteLine("Compressing, please wait... {0}");
                        YAZ0.Compress(Params[1], Params[2].Contains("f"));
                        break;

                    case "-yy":
                        Console.WriteLine("Compressing, please wait... {0}");
                        YAY0.Compress(Params[1]);
                        break;

                    default:
                        ErrorMessage = string.Format("Encoding mode {0} doesn't exist", Params[1]);
                        goto Error;
                    }

                    Console.WriteLine("Compress complete!");
                    break;

                case "replace":
                case "add":     //add <filepath> <archivepath>
                    string func = Params[0].Equals("replace") ? "replaced" : "added";
                    if (Params.Length < 3)
                    {
                        ErrorMessage = string.Format("Incomplete Syntax - Expected\n{0} <filepath> <archivepath>", Params[0]);
                        goto Error;
                    }
                    if (CurrentArchive is null)
                    {
                        ErrorMessage = string.Format("Add failed! No archive loaded");
                        goto Error;
                    }
                    if (!File.Exists(Params[1]) && !Directory.Exists(Params[1]))
                    {
                        ErrorMessage = string.Format("File or Directory {0} could not be found", Params[1]);
                        goto Error;
                    }
                    if (CurrentArchive.ItemExists(Params[1]))
                    {
                        if (Params[0].Equals("replace"))
                        {
                            CurrentArchive[Params[1]] = null;
                        }
                        else
                        {
                            ErrorMessage = string.Format("An item already exists at {0}", Params[1]);
                            goto Error;
                        }
                    }
                    if (File.GetAttributes(Params[1]) == FileAttributes.Directory)
                    {
                        CurrentArchive[Params[2]] = new RARC.Directory(Params[1], CurrentArchive);
                        Console.WriteLine("Folder {0} {1} successfully", Params[1], func);
                    }
                    else
                    {
                        CurrentArchive[Params[2]] = new RARC.File(Params[1]);
                        Console.WriteLine("File {0} {1} successfully", Params[1], func);
                    }
                    break;

                case "delete":     //delete <archivepath>
                    if (Params.Length < 2)
                    {
                        ErrorMessage = string.Format("Incomplete Syntax - Expected\ndelete <archivepath>");
                        goto Error;
                    }
                    if (CurrentArchive is null)
                    {
                        ErrorMessage = string.Format("Delete failed! No archive loaded");
                        goto Error;
                    }
                    if (!CurrentArchive.ItemExists(Params[1]))
                    {
                        ErrorMessage = string.Format("Can't delete the non-existant item {0}", Params[1]);
                        goto Error;
                    }

                    CurrentArchive[Params[1]] = null;
                    Console.WriteLine("Deleted {0} successfully", Params[1]);
                    break;

                case "rename":
                case "move":     //move <archivepath> <archivepath>
                    func = Params[0].Equals("rename") ? "Renamed" : "Moved";
                    if (Params.Length < 3)
                    {
                        ErrorMessage = string.Format("Incomplete Syntax - Expected\n{0} <archivepath> <archivepath>", Params[0]);
                        goto Error;
                    }
                    if (CurrentArchive is null)
                    {
                        ErrorMessage = string.Format("{0} failed! No archive loaded", Params[0]);
                        goto Error;
                    }
                    if (!CurrentArchive.ItemExists(Params[1]))
                    {
                        ErrorMessage = string.Format("Can't {1} a non-existant item {0}", Params[1], func);
                        goto Error;
                    }
                    if (CurrentArchive.ItemExists(Params[2]))
                    {
                        ErrorMessage = string.Format("An item already exists at {0}", Params[1]);
                        goto Error;
                    }

                    CurrentArchive.MoveItem(Params[1], Params[2]);
                    Console.WriteLine("{2} {0} to {1} successfully", Params[1], Params[2], func);
                    break;

                case "extract":     //extract <archivepath> <filepath> [-o]
                    if (Params.Length < 3)
                    {
                        ErrorMessage = string.Format("Incomplete Syntax - Expected\nextract <archivepath> <filepath>");
                        goto Error;
                    }
                    if (CurrentArchive is null)
                    {
                        ErrorMessage = string.Format("Extract failed! No archive loaded");
                        goto Error;
                    }
                    if (!CurrentArchive.ItemExists(Params[1]))
                    {
                        ErrorMessage = string.Format("Can't extract the non-existant item {0}", Params[1]);
                        goto Error;
                    }
                    if (CurrentArchive[Params[1]] is RARC.File efile)
                    {
                        if (File.Exists(Params[2]) && !Params.Contains("-o"))
                        {
                            ErrorMessage = string.Format("There is already a file on your system at {0}, consider adding the -o parameter if you want to overwrite it", Params[2]);
                            goto Error;
                        }
                        efile.Save(Params[2]);
                    }
                    else if (CurrentArchive[Params[1]] is RARC.Directory edir)
                    {
                        if (Directory.Exists(Params[2]) && !Params.Contains("-o"))
                        {
                            ErrorMessage = string.Format("There is already a file on your system at {0}, consider adding the -o parameter if you want to overwrite it", Params[2]);
                            goto Error;
                        }
                        edir.Export(Params[2]);
                    }
                    break;

                case "edit":     //edit <archivepath> <Parameter[]>
                    if (Params.Length < 3)
                    {
                        ErrorMessage = string.Format("Incomplete Syntax - Expected\nedit <archivepath> <parameter[]>\nParameters include:\n-id <new id>\n-setcompressed <-yz>\n-loadmain\n-loadaux\n-loaddvd\n-auto");
                        goto Error;
                    }
                    if (CurrentArchive is null)
                    {
                        ErrorMessage = string.Format("Edit failed! No archive loaded");
                        goto Error;
                    }
                    object getitem = CurrentArchive[Params[1]];
                    if (getitem is RARC.Directory)
                    {
                        ErrorMessage = string.Format("Edit failed! Cannot change properties of folders!");
                        goto Error;
                    }
                    if (getitem is RARC.File file)
                    {
                        bool mram = true, aram = false, dvd = false, compressed = false, compressedyaz0 = false;
                        for (int x = 2; x < Params.Length; x++)
                        {
                            switch (Params[x])
                            {
                            case "-id":
                                if (CurrentArchive.KeepFileIDsSynced)
                                {
                                    ErrorMessage = string.Format("Edit failed! Cannot change File ID because the Archive is set to Automatically calculate file ID's", Params[x]);
                                    goto Error;
                                }
                                if (short.TryParse(Params[++x], out short newid))
                                {
                                    file.ID = newid;
                                }
                                else
                                {
                                    ErrorMessage = string.Format("Edit failed! Could not parse {0} as a int16 (short)", Params[x]);
                                    goto Error;
                                }
                                break;

                            case "-setcompressed":
                                if (x + 1 != Params.Length - 1 && Params[x + 1].Equals("-yz"))
                                {
                                    compressedyaz0 = true;
                                }
                                compressed = true;
                                break;

                            case "-loadmain":
                                mram = true;
                                aram = false;
                                dvd  = false;
                                break;

                            case "-loadaux":
                                mram = false;
                                aram = true;
                                dvd  = false;
                                break;

                            case "loaddvd":
                                mram = false;
                                aram = false;
                                dvd  = true;
                                break;

                            case "auto":
                                if (file.FileData[0] == 0x59 && file.FileData[1] == 0x61 && file.FileData[2] == 0x7A && file.FileData[3] == 0x30)
                                {
                                    compressed     = true;
                                    compressedyaz0 = true;
                                }
                                if (file.Name.Contains(".rel"))
                                {
                                    mram = false;
                                    aram = true;
                                    dvd  = false;
                                }
                                else
                                {
                                    mram = true;
                                    aram = false;
                                    dvd  = false;
                                }
                                if (!CurrentArchive.KeepFileIDsSynced && file.ID == -1)
                                {
                                    file.ID = CurrentArchive.NextFreeFileID;
                                }
                                break;

                            default:
                                ErrorMessage = string.Format("Edit failed! Unknown file property {0}", Params[x]);
                                goto Error;
                            }
                        }
                        RARC.FileAttribute loadattribute = mram ? RARC.FileAttribute.PRELOAD_TO_MRAM : (aram ? RARC.FileAttribute.PRELOAD_TO_ARAM : (dvd ? RARC.FileAttribute.LOAD_FROM_DVD : 0));
                        file.FileSettings = RARC.FileAttribute.FILE | (compressed ? RARC.FileAttribute.COMPRESSED : 0) | loadattribute | (compressedyaz0 ? RARC.FileAttribute.YAZ0_COMPRESSED : 0);
                    }
                    break;

                default:
                    ErrorMessage = string.Format("Invalid Command {0}", Params[0]);
                    goto Error;
                }
                Console.WriteLine();
            }

            return;

Error:
            Console.WriteLine(ErrorMessage);
            Thread.Sleep(1000);
            return;
        }
Пример #22
0
        private void Save()
        {
            SoundPlayer Patience = new SoundPlayer();

            Console.WriteLine();
            FileInfo fi = new FileInfo(Filename);

            if (File.Exists(Filename) && fi.IsFileLocked())
            {
                Console.WriteLine("The chosen file cannot be accessed. The file has not been modified, and your changes have not been saved.");
                goto SaveFailed;
            }
            if (Program.CanPlaySfx(Program.WaitSfx))
            {
                Patience.SoundLocation = Program.WaitSfx;
                Patience.Load();
                Patience.PlayLooping();
            }
            if (CameraListBox.SelectedIndex != -1)
            {
                ((CameraPanelBase)MainSplitContainer.Panel2.Controls[0]).UnLoadCamera(Cameras[CameraListBox.SelectedIndex]);
            }

            if (Settings.Default.IsEnforceCompress)
            {
                AdvancedSave();
            }
            if (File.Exists(Filename) && fi.IsFileLocked())
            {
                Console.WriteLine("The chosen file cannot be accessed. The file has not been modified, and your changes have not been saved.");
                goto SaveFailed;
            }
            switch (fi.Extension)
            {
            case ".bcam":
                Console.WriteLine("Saving as a Binary Camera file:");
                FileStream fs = new FileStream(Filename, FileMode.Create);
                Cameras.Save(fs);
                fs.Close();
                break;

            case ".arc":
            case ".rarc":
                if (!File.Exists(Filename))
                {
                    MessageBox.Show("The output archive does not exist. Your changes have not been saved.");
                    goto SaveFailed;
                }
                Console.WriteLine("Loading the target Archive:");
                RARC Archive = YAZ0.Check(Filename) ? new RARC(YAZ0.DecompressToMemoryStream(Filename)) : new RARC(Filename);
                Console.WriteLine("Archive Loaded. Looking for the .bcam to replace...");

                string FinalPath = new string[] { Archive.GetItemKeyFromNoCase("Camera/CameraParam.bcam"), Archive.GetItemKeyFromNoCase("ActorInfo/CameraParam.bcam") }.FirstOrDefault(s => !string.IsNullOrEmpty(s));
                if (FinalPath is null)
                {
                    Console.WriteLine("Error finding a bcam");
                    DialogResult dr = MessageBox.Show("The archive has no .bcam to replace.\nWould you like to create one?", "Missing .bcam", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    Console.WriteLine($"MessageBox Response: {dr.ToString()}");
                    if (dr != DialogResult.Yes)
                    {
                        Console.WriteLine("The chosen file has not been modified, and your changes have not been saved.");
                        goto SaveFailed;
                    }
                    FinalPath = "Camera/CameraParam.bcam";
                }
                Console.WriteLine(FinalPath is null ? "Injecting..." : ".bcam found. Saving...");
                MemoryStream ms = new MemoryStream();
                Cameras.Save(ms);
                Archive[FinalPath] = new RARC.File(((RARC.File)Archive[FinalPath]).Name, ms);

                Console.WriteLine(".bcam saved into the archive.");
                Console.WriteLine("Saving the archive...");
                Archive.Save(Filename);
                if (Settings.Default.IsUseYAZ0)
                {
                    Stopwatch Watch = new Stopwatch();
                    long      UncompressedFilesize = File.ReadAllBytes(Filename).Length;
                    double    ETA = UncompressedFilesize * Settings.Default.ElapsedTimeStrong;
                    Watch.Start();
                    Yaz0BackgroundWorker.RunWorkerAsync(Filename);

                    EnabledContents(this, false);
                    while (Yaz0BackgroundWorker.IsBusy)
                    {
                        Console.Write($"\rYaz0 Encoding: ({Watch.Elapsed.ToString("mm\\:ss\\.fff")} Elapsed, {TimeSpan.FromMilliseconds(ETA).ToString("mm\\:ss\\.fff")} Estimated)");
                        Application.DoEvents();
                    }
                    Watch.Stop();
                    Settings.Default.ElapsedTimeStrong = (double)Watch.ElapsedMilliseconds / (double)UncompressedFilesize;
                    Console.WriteLine("\nYaz0 Encoding Complete!");
                    EnabledContents(this, true);
                }
                break;
            }
            Console.WriteLine("Save Complete!");
            Console.WriteLine("Current time of Save: " + DateTime.Now.ToString("h:mm tt"));
            Program.IsUnsavedChanges = false;
            Console.WriteLine();

            Patience.Stop();
            if (Program.CanPlaySfx(Program.SuccessSfx))
            {
                Patience.SoundLocation = Program.SuccessSfx;
                Patience.Load();
                Patience.Play();
            }
            return;

SaveFailed:
            Patience.Stop();
            if (Program.CanPlaySfx(Program.FailureSfx))
            {
                Patience.SoundLocation = Program.FailureSfx;
                Patience.Load();
                Patience.Play();
            }
            return;
        }
Пример #23
0
 public RARCViewer(RARC Archive)
 {
     this.Archive = Archive;
     Root = Archive.ToFileSystem();
     InitializeComponent();
 }
        public void LoadFromArc(string fileName)
        {
            string tempFileName = "";

            using (FileStream yaz0TestStream = new FileStream(fileName, FileMode.Open))
            {

                EndianBinaryReader yaz0TestReader = new EndianBinaryReader(yaz0TestStream, Endian.Big);

                string yaz0Test = yaz0TestReader.ReadString(4);

                if (yaz0Test == "Yaz0")
                {
                    byte[] uncompressedArc = DecodeYaz0(yaz0TestReader);

                    yaz0TestReader.Close();

                    fileName = Path.GetTempFileName();

                    tempFileName = fileName;

                    FileInfo info = new FileInfo(fileName);

                    info.Attributes = FileAttributes.Temporary;

                    using (FileStream tempStream = new FileStream(fileName, FileMode.Open))
                    {
                        EndianBinaryWriter tempWriter = new EndianBinaryWriter(tempStream, Endian.Big);

                        tempWriter.Write(uncompressedArc);

                        tempWriter.Flush();

                        tempWriter.Close();
                    }
                }
            }

            RARC loadedArc = new RARC(fileName);

            if (File.Exists(tempFileName))
            {
                File.Delete(tempFileName);
            }

            FilesFromArc = new List<FileData>();

            for (int i = 0; i < loadedArc.Nodes.Count(); i++)
            {
                for (int j = 0; j < loadedArc.Nodes[i].Entries.Count(); j++)
                {
                    if (loadedArc.Nodes[i].Entries[j].Data != null)
                    {
                        FileData file = new FileData();

                        file.Name = loadedArc.Nodes[i].Entries[j].Name;

                        file.Data = loadedArc.Nodes[i].Entries[j].Data;

                        FilesFromArc.Add(file);
                    }
                }
            }

            foreach (FileData file in FilesFromArc)
            {
                if (file.Name.Contains(".dzb"))
                {
                    using (EndianBinaryReader reader = new EndianBinaryReader(file.Data, Endian.Big))
                    {

                        Collision = new CollisionMesh();

                        Collision.Load(reader);
                    }
                }

                if (file.Name.Contains(".dzs") || file.Name.Contains(".dzr"))
                {
                    using (EndianBinaryReader reader = new EndianBinaryReader(file.Data, Endian.Big))
                    {
                        Read(reader);
                    }
                }

                if (file.Name.Contains(".bdl") || file.Name.Contains(".bmd"))
                {
                    //Not implemented
                }
            }
        }
Пример #25
0
        public void Open(string file)
        {
            CameraListBox.SelectedIndex = -1;
            Filename = file;
            SoundPlayer Patience = new SoundPlayer();

            if (File.Exists(Filename) && new FileInfo(file).IsFileLocked())
            {
                Console.WriteLine("The chosen file cannot be accessed. The file has not been modified, and your changes have not been saved.");
                goto OpenFailed;
            }
            if (Program.CanPlaySfx(Program.WaitSfx))
            {
                Patience.SoundLocation = Program.WaitSfx;
                Patience.Load();
                Patience.PlayLooping();
            }
            switch (new FileInfo(file).Extension)
            {
            case ".bcam":
                Console.WriteLine("Loading as a Binary Camera file:");
                FileStream fs = new FileStream(file, FileMode.Open);
                Cameras = new BCAM(fs);
                fs.Close();
                Console.WriteLine("Load Complete!");
                break;

            case ".arc":
            case ".rarc":
                Console.WriteLine("Loading as an Archive:");
                RARC Archive = YAZ0.Check(file) ? new RARC(new MemoryStream(YAZ0.Decompress(File.ReadAllBytes(file)))) : new RARC(file);
                Console.WriteLine("Archive Loaded. Looking for the .bcam...");
                string CameraParamPath = Archive.GetItemKeyFromNoCase("Camera/CameraParam.bcam");
                if (CameraParamPath == null)
                {
                    CameraParamPath = Archive.GetItemKeyFromNoCase("ActorInfo/CameraParam.bcam");
                    if (CameraParamPath == null)
                    {
                        Console.WriteLine("Load Failed! No BCAM was found inside the archive!\n(Maybe it was in the wrong place?)");
                        goto OpenFailed;
                    }
                }
                Console.WriteLine(".bcam found.");
                Cameras = new BCAM(new MemoryStream(((RARC.File)Archive[CameraParamPath]).FileData));
                Console.WriteLine("Load Complete!");
                break;
            }

            Console.WriteLine();

            Console.WriteLine("Writing the Camera List:");

            CameraListBox.Enabled = false;
            CameraListBox.Items.Clear();
            for (int i = 0; i < Cameras.EntryCount; i++)
            {
                CameraListBox.Items.Add(Cameras[i].GetTranslatedName());
                Console.Write($"\r{Math.Min((int)(((float)(i + 1) / (float)CameraListBox.Items.Count) * 100), 100)}%          ");
            }
            Console.WriteLine("Complete");

            if (Cameras.EntryCount > 0)
            {
                CameraListBox.SelectedIndex = 0;
            }
            CameraListBox.Enabled                 = true;
            SaveToolStripMenuItem.Enabled         = true;
            SaveAsToolStripMenuItem.Enabled       = true;
            ExportPresetToolStripMenuItem.Enabled = true;
            Program.IsUnsavedChanges              = false;

            Patience.Stop();
            if (Program.CanPlaySfx(Program.SuccessSfx))
            {
                Patience.SoundLocation = Program.SuccessSfx;
                Patience.Load();
                Patience.Play();
            }
            return;

OpenFailed:
            Patience.Stop();
            if (Program.CanPlaySfx(Program.FailureSfx))
            {
                Patience.SoundLocation = Program.FailureSfx;
                Patience.Load();
                Patience.Play();
            }
        }