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

            ExternalLayout = layoutFile.PartsManager.TryGetLayout($"{LayoutFileName}.bflyt") as BFLYT;

            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);
        }
Exemple #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();
            }
        }
Exemple #3
0
        private void SearchArchive(IArchiveFile archiveFile, ref BFLYT layoutFile)
        {
            layoutFile = null;

            if (archiveFile is SARC)
            {
                if (((SARC)archiveFile).FileLookup.ContainsKey($"blyt/{LayoutFileName}.bflyt"))
                {
                    var entry      = ((SARC)archiveFile).FileLookup[$"blyt/{LayoutFileName}.bflyt"];
                    var openedFile = entry.OpenFile();
                    if (openedFile is BFLYT)
                    {
                        layoutFile           = openedFile as BFLYT;
                        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 BFLYT)
                        {
                            Console.WriteLine("Part found! " + file.FileName);

                            layoutFile           = openedFile as BFLYT;
                            layoutFile.IFileInfo = new IFileInfo();
                            layoutFile.IFileInfo.ArchiveParent = layoutFile.IFileInfo.ArchiveParent;
                            return;
                        }
                    }
                    catch
                    {
                    }
                }
            }
        }
Exemple #4
0
        public List <BFLYT> GetLayouts()
        {
            List <BFLYT> animations = new List <BFLYT>();

            if (IFileInfo.ArchiveParent != null)
            {
                foreach (var file in IFileInfo.ArchiveParent.Files)
                {
                    if (Utils.GetExtension(file.FileName) == ".bflyt")
                    {
                        BFLYT bflyt = (BFLYT)file.OpenFile();
                        animations.Add(bflyt);
                    }
                }
            }
            return(animations);
        }
Exemple #5
0
        public void Read(FileReader reader, BFLYT bflyt)
        {
            PaneLookup.Clear();
            LayoutInfo   = new LYT1();
            TextureList  = new TXL1();
            MaterialList = new MAT1();
            FontList     = new FNL1();
            RootPane     = new PAN1();
            RootGroup    = new GRP1();
            UserData     = new USD1();
            FileInfo     = bflyt;

            reader.SetByteOrder(true);
            reader.ReadSignature(4, Magic);
            ByteOrderMark = reader.ReadUInt16();
            reader.CheckByteOrderMark(ByteOrderMark);
            HeaderSize = reader.ReadUInt16();
            Version    = reader.ReadUInt32();
            SetVersionInfo();
            uint   FileSize     = reader.ReadUInt32();
            ushort sectionCount = reader.ReadUInt16();

            reader.ReadUInt16(); //Padding

            IsBigEndian = reader.ByteOrder == Syroot.BinaryData.ByteOrder.BigEndian;

            if (!IsBigEndian)
            {
                if (VersionMajor == 3)
                {
                    TextureManager.Platform = TextureManager.PlatformType.ThreeDS;
                }
                else
                {
                    TextureManager.Platform = TextureManager.PlatformType.Switch;
                }
            }
            else
            {
                TextureManager.Platform = TextureManager.PlatformType.WiiU;
            }

            TextureManager.LayoutFile = this;

            bool setRoot      = false;
            bool setGroupRoot = false;

            BasePane currentPane = null;
            BasePane parentPane  = null;

            BasePane currentGroupPane = null;
            BasePane parentGroupPane  = null;

            reader.SeekBegin(HeaderSize);
            for (int i = 0; i < sectionCount; i++)
            {
                long pos = reader.Position;

                string Signature   = reader.ReadString(4, Encoding.ASCII);
                uint   SectionSize = reader.ReadUInt32();

                SectionCommon section = new SectionCommon(Signature);
                switch (Signature)
                {
                case "lyt1":
                    LayoutInfo = new LYT1(reader);
                    break;

                case "txl1":
                    TextureList = new TXL1(reader, this);
                    break;

                case "fnl1":
                    FontList = new FNL1(reader, this);
                    break;

                case "mat1":
                    MaterialList = new MAT1(reader, this);
                    break;

                case "pan1":
                    var panel = new PAN1(reader, this);
                    AddPaneToTable(panel);
                    if (!setRoot)
                    {
                        RootPane = panel;
                        setRoot  = true;
                    }

                    SetPane(panel, parentPane);
                    currentPane = panel;
                    break;

                case "pic1":
                    var picturePanel = new PIC1(reader, this);
                    AddPaneToTable(picturePanel);

                    SetPane(picturePanel, parentPane);
                    currentPane = picturePanel;
                    break;

                case "txt1":
                    var textPanel = new TXT1(reader, this);
                    AddPaneToTable(textPanel);

                    SetPane(textPanel, parentPane);
                    currentPane = textPanel;
                    break;

                case "bnd1":
                    var boundsPanel = new BND1(reader, this);
                    AddPaneToTable(boundsPanel);

                    SetPane(boundsPanel, parentPane);
                    currentPane = boundsPanel;
                    break;

                case "prt1":
                    var partsPanel = new PRT1(reader, this);
                    AddPaneToTable(partsPanel);

                    SetPane(partsPanel, parentPane);
                    currentPane = partsPanel;
                    break;

                case "wnd1":
                    var windowPanel = new WND1(reader, this);
                    AddPaneToTable(windowPanel);

                    SetPane(windowPanel, parentPane);
                    currentPane = windowPanel;
                    break;

                case "scr1":
                    var scissorPane = new SCR1(reader, this);
                    AddPaneToTable(scissorPane);

                    SetPane(scissorPane, parentPane);
                    currentPane = scissorPane;
                    break;

                case "ali1":
                    var alignmentPane = new ALI1(reader, this);
                    AddPaneToTable(alignmentPane);

                    SetPane(alignmentPane, parentPane);
                    currentPane = alignmentPane;
                    break;

                case "pas1":
                    if (currentPane != null)
                    {
                        parentPane = currentPane;
                    }
                    break;

                case "pae1":
                    if (parentPane != null)
                    {
                        currentPane = parentPane;
                    }
                    parentPane = currentPane.Parent;
                    break;

                case "grp1":
                    var groupPanel = new GRP1(reader, this);

                    if (!setGroupRoot)
                    {
                        RootGroup    = groupPanel;
                        setGroupRoot = true;
                    }

                    SetPane(groupPanel, parentGroupPane);
                    currentGroupPane = groupPanel;
                    break;

                case "grs1":
                    if (currentGroupPane != null)
                    {
                        parentGroupPane = currentGroupPane;
                    }
                    break;

                case "gre1":
                    currentGroupPane = parentGroupPane;
                    parentGroupPane  = currentGroupPane.Parent;
                    break;

                /*   case "cnt1":
                 *     Container = new CNT1(reader, this);
                 *     break;*/
                case "usd1":
                    long dataPos = reader.Position;

                    if (currentPane != null)
                    {
                        ((PAN1)currentPane).UserData = new USD1(reader, this);

                        reader.SeekBegin(dataPos);
                        ((PAN1)currentPane).UserData.Data = reader.ReadBytes((int)SectionSize - 8);
                    }
                    else
                    {
                        //User data before panes
                        UserData = new USD1(reader, this);

                        reader.SeekBegin(dataPos);
                        UserData.Data = reader.ReadBytes((int)SectionSize - 8);
                    }
                    break;

                //If the section is not supported store the raw bytes
                default:
                    section.Data = reader.ReadBytes((int)SectionSize - 8);
                    UnknownSections.Add(section);
                    Console.WriteLine("Unknown section!" + Signature);
                    break;
                }

                section.SectionSize = SectionSize;
                reader.SeekBegin(pos + SectionSize);
            }
        }
Exemple #6
0
        private BFLYT 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);
                            BFLYT bflyt = null;
                            SearchArchive((IArchiveFile)openedFile, ref bflyt);
                            if (bflyt != null)
                            {
                                return(bflyt);
                            }
                        }
                        else if (Utils.GetExtension(file) == ".bflan")
                        {
                            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) == ".bflyt")
                        {
                            var openedFile = STFileLoader.OpenFileFormat(file);
                            if (openedFile == null)
                            {
                                continue;
                            }

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

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

            return(null);
        }