Beispiel #1
0
        public BasePane GetExternalPane()
        {
            if (hasSearchedParts || LayoutFileName == string.Empty)
            {
                return(null);
            }

            ExternalLayout = layoutFile.PartsManager.TryGetLayout($"{LayoutFileName}.bClyt") as BCLYT;

            if (ExternalLayout == null)
            {
                ExternalLayout = SearchExternalFile();
            }

            if (ExternalLayout == null)
            {
                return(null);
            }

            //Load all the part panes to the lookup table
            foreach (var pane in ExternalLayout.header.PaneLookup)
            {
                if (!layoutFile.PaneLookup.ContainsKey(pane.Key))
                {
                    layoutFile.PaneLookup.Add(pane.Key, pane.Value);
                }
            }

            layoutFile.PartsManager.AddLayout(ExternalLayout.header);

            return(ExternalLayout.header.RootPane);
        }
Beispiel #2
0
        //Get textures if possible from the external parts file
        public void UpdateTextureData(Dictionary <string, STGenericTexture> textures)
        {
            if (hasSearchedParts)
            {
                return;
            }

            if (ExternalLayout == null)
            {
                ExternalLayout = SearchExternalFile();
                if (ExternalLayout == null)
                {
                    return;
                }

                ExternalLayout.header.TextureManager = layoutFile.TextureManager;

                var textureList = ExternalLayout.GetTextures();
                foreach (var tex in textureList)
                {
                    if (!textures.ContainsKey(tex.Key))
                    {
                        textures.Add(tex.Key, tex.Value);
                    }
                }

                textureList.Clear();
            }
        }
Beispiel #3
0
        private void SearchArchive(IArchiveFile archiveFile, ref BCLYT layoutFile)
        {
            layoutFile = null;

            if (archiveFile is SARC)
            {
                if (((SARC)archiveFile).FileLookup.ContainsKey($"blyt/{LayoutFileName}.bclyt"))
                {
                    var entry      = ((SARC)archiveFile).FileLookup[$"blyt/{LayoutFileName}.bclyt"];
                    var openedFile = entry.OpenFile();
                    if (openedFile is BCLYT)
                    {
                        layoutFile           = openedFile as BCLYT;
                        layoutFile.IFileInfo = new IFileInfo();
                        layoutFile.IFileInfo.ArchiveParent = layoutFile.IFileInfo.ArchiveParent;
                        return;
                    }
                }
            }

            foreach (var file in archiveFile.Files)
            {
                if (file.FileName.Contains(".lyarc"))
                {
                    var openedFile = file.OpenFile();
                    if (openedFile is IArchiveFile)
                    {
                        SearchArchive((IArchiveFile)openedFile, ref layoutFile);
                    }
                }
                else if (file.FileName.Contains(LayoutFileName))
                {
                    try
                    {
                        var openedFile = file.OpenFile();
                        if (openedFile is IArchiveFile)
                        {
                            SearchArchive((IArchiveFile)openedFile, ref layoutFile);
                        }
                        else if (openedFile is BCLYT)
                        {
                            Console.WriteLine("Part found! " + file.FileName);

                            layoutFile           = openedFile as BCLYT;
                            layoutFile.IFileInfo = new IFileInfo();
                            layoutFile.IFileInfo.ArchiveParent = layoutFile.IFileInfo.ArchiveParent;
                            return;
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
Beispiel #4
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);
        }
Beispiel #5
0
        private BCLYT SearchExternalFile()
        {
            hasSearchedParts = false;

            var fileFormat = layoutFile.FileInfo;

            string path = FileManager.GetSourcePath(fileFormat);

            //File is outside an archive so check the contents it is in
            if (File.Exists(path))
            {
                string folder = Path.GetDirectoryName(path);
                foreach (var file in Directory.GetFiles(folder))
                {
                    if (file.Contains(LayoutFileName))
                    {
                        if (Utils.GetExtension(file) == ".szs")
                        {
                            var openedFile = STFileLoader.OpenFileFormat(file);
                            if (openedFile == null)
                            {
                                continue;
                            }

                            layoutFile.PartsManager.AddArchive((IArchiveFile)openedFile);
                            BCLYT bclyt = null;
                            SearchArchive((IArchiveFile)openedFile, ref bclyt);
                            if (bclyt != null)
                            {
                                return(bclyt);
                            }
                        }
                        else if (Utils.GetExtension(file) == ".bclan")
                        {
                            try
                            {
                                var openedFile = STFileLoader.OpenFileFormat(file);
                                if (openedFile == null)
                                {
                                    continue;
                                }

                                openedFile.CanSave = false;
                                var bflan = openedFile as BXLAN;
                                layoutFile.PartsManager.AddAnimation(bflan.BxlanHeader);
                            }
                            catch
                            {
                            }
                        }
                        else if (Utils.GetExtension(file) == ".bclyt")
                        {
                            var openedFile = STFileLoader.OpenFileFormat(file);
                            if (openedFile == null)
                            {
                                continue;
                            }

                            openedFile.CanSave   = false;
                            openedFile.IFileInfo = new IFileInfo();
                            openedFile.IFileInfo.ArchiveParent = fileFormat.IFileInfo.ArchiveParent;
                            return((BCLYT)openedFile);
                        }
                    }
                }
            }

            for (int i = 0; i < PluginRuntime.SarcArchives.Count; i++)
            {
                BCLYT bclyt = null;
                SearchArchive(PluginRuntime.SarcArchives[i], ref bclyt);
                if (bclyt != null)
                {
                    return(bclyt);
                }
            }

            return(null);
        }