Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string filename = ofd.FileName;

                BFLYT lyt = new BFLYT(ref filename);
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
 public void LoadLayout(BFLYT bflyt)
 {
     activeLayout = bflyt;
     editor.AddContextMenu("Convert to BFLYT", TextCompiled);
     editor.FillEditor(bflyt.ConvertToString());
 }