Exemple #1
0
        private void btnClean_Click(object sender, EventArgs e)
        {
            ResourceNode group = TargetModel._matGroup;
            ResourceNode mat   = null;

            if (group == null)
            {
                return;
            }

            List <SRT0EntryNode>   badMaterials = new List <SRT0EntryNode>();
            List <SRT0TextureNode> badTextures  = new List <SRT0TextureNode>();

            foreach (SRT0EntryNode entry in SelectedAnimation.Children)
            {
                if ((mat = group.FindChild(entry._name, true)) == null)
                {
                    badMaterials.Add(entry);
                }
                else
                {
                    int count = 0;
                    foreach (SRT0TextureNode tex in entry.Children)
                    {
                        if (((mat = group.FindChild(entry._name, true)) == null) || mat.Children.Count < tex.TextureIndex)
                        {
                            badTextures.Add(tex);
                            count++;
                        }
                        //else
                        //    entry.Keyframes.Clean();
                    }
                    if (count == entry.Children.Count)
                    {
                        badMaterials.Add(entry);
                    }
                }
            }
            int temp0 = badMaterials.Count;
            int temp1 = badTextures.Count;

            foreach (SRT0TextureNode n in badTextures)
            {
                n.Remove();
                n.Dispose();
            }
            foreach (SRT0EntryNode n in badMaterials)
            {
                n.Remove();
                n.Dispose();
            }
            MessageBox.Show(temp0 + " unused material entries and\n" + temp1 + " unused texture entries removed.");
            UpdatePropDisplay();
        }
        private void SavePacMsbn(MSBinNode msbn, string pacPath, string childNodeName)
        {
            string tmpPac  = Path.GetTempFileName();
            string tmpMsbn = Path.GetTempFileName();

            msbn.Export(tmpMsbn);
            File.Copy(pacPath, tmpPac, true);

            using (ResourceNode tmpPacNode = NodeFactory.FromFile(null, tmpPac))
            {
                MSBinNode tmpPacChildNode = tmpPacNode.FindChild(childNodeName, true) as MSBinNode;
                if (tmpPacChildNode == null)
                {
                    throw new Exception("Error saving '" + pacPath
                                        + "': The file does not appear to have a '" + childNodeName +
                                        "'");
                }
                else
                {
                    tmpPacChildNode.Replace(tmpMsbn);
                    tmpPacNode.Merge();
                    tmpPacNode.Export(pacPath);
                }
            }

            File.Delete(tmpPac);
            File.Delete(tmpMsbn);
        }
Exemple #3
0
        public void Restore()
        {
            TEX0Node tNode = Node as TEX0Node;
            PLT0Node pNode = tNode.GetPaletteNode();

            if ((tNode.IsDirty) || (tNode.IsBranch))
            {
                if (pNode != null)
                {
                    pNode.Restore();
                }

                tNode.Restore();
            }
            else
            {
                ResourceTree t = Tree;
                if (t.IsWorkingCopy)
                {
                    string path = Program.GetFilePath(_relativePath, false);
                    using (ResourceNode oldNode = NodeFactory.FromFile(null, path))
                    {
                        ResourceNode origNode = oldNode.FindChild(_nodePath, false);
                        if (pNode != null)
                        {
                            ResourceNode origp = ((TEX0Node)origNode).GetPaletteNode();
                            pNode.ReplaceRaw(origp.WorkingUncompressed.Address, origp.WorkingUncompressed.Length);
                        }
                        tNode.ReplaceRaw(origNode.WorkingUncompressed.Address, origNode.WorkingUncompressed.Length);
                    }
                }
            }
        }
Exemple #4
0
        private void btnClean_Click(object sender, EventArgs e)
        {
            ResourceNode group = _targetModel.FindChild("Bones", false);

            if (group == null)
            {
                return;
            }

            List <CHR0EntryNode> badNodes = new List <CHR0EntryNode>();

            foreach (CHR0EntryNode entry in _selectedAnim.Children)
            {
                if (group.FindChild(entry._name, true) == null)
                {
                    badNodes.Add(entry);
                }
                //else
                //    entry.Keyframes.Clean();
            }

            foreach (CHR0EntryNode n in badNodes)
            {
                n.Remove();
                n.Dispose();
            }

            UpdatePropDisplay();
        }
        public void updateMuMenumain(string msBinPath = null)
        {
            if (DialogResult.OK == MessageBox.Show("Overwrite the current mu_menumain?", "Overwrite File", MessageBoxButtons.OKCancel))
            {
                using (ResourceNode mu_menumain = TempFiles.MakeTempNode(mu_menumain_path)) {
                    IconsToMenumain.Copy(sc_selmap, mu_menumain, BestSSS);
                    if (msBinPath != null)
                    {
                        mu_menumain.FindChild("MiscData[7]", false).Replace(msBinPath);
                    }
                    mu_menumain.Export(mu_menumain_path);
                }

                byte   absent_stage_id = BestSSS[0x1E].Item1;
                int    sss2_count      = BestSSS.sss2.Where(b => b != 0x1E).Count() + 1;
                string warn            = sss2_count <= 39 ? "" : "\nWARNING: screen 2 of the SSS " +
                                         (AutoSSS == null ? "may have " : "has ") +
                                         "more than 39 stages, causing My Music to crash on page 2.";
                var    q      = StageIDMap.Stages.Where(s => s.ID == absent_stage_id);
                string absent = q.Any()
                                        ? q.First().Name
                                        : "STGCUSTOM" + (absent_stage_id - 0x3f).ToString("X2");
                MessageBox.Show("Done. " +
                                (msBinPath != null ? "(Song titles copied too.) " : "") +
                                (AutoSSS == null ? "Without a Custom SSS code, " : "Based on your current SSS code, ") +
                                absent + " will be missing; and Menu will be added to the end of screen 2." + warn);
            }
        }
        private void populate(out Texture tex, string path)
        {
            tex = new Texture()
            {
                tex0 = null,
                ForThisFrameIndex = false,
                pat0 = null,
            };
            if (iconNum == 255)
            {
                return;
            }

            if (PAT0Folder == null)
            {
                return;
            }

            var query = (from n in PAT0Folder.FindChild(path, false).Children[0].Children
                         let p = ((PAT0TextureEntryNode)n)
                                 orderby p.FrameIndex descending
                                 where p != null &&
                                 p.FrameIndex <= iconNum
                                 select p);

            if (query.Any())
            {
                var first = query.First();
                tex.tex0 = TEX0Folder.FindChild(first.Name, false) as TEX0Node;
                tex.ForThisFrameIndex = (first.FrameIndex == iconNum);
                tex.pat0 = tex.ForThisFrameIndex ? first : null;
            }
        }
        /// <summary>
        /// Finds the textures through their PAT0 entries, given an icon number and a ResourceNode
        /// </summary>
        /// <param name="sc_selmap">The sc_selmap *or* Misc Data [80] node.</param>
        /// <param name="iconNum">The icon index (also used in the third part of the Custom SSS code.)</param>
        public TextureContainer(ResourceNode node, int iconNum)
        {
            TEX0Folder = node.FindChild("Misc Data [80]/Textures(NW4R)", false)
                         ?? node.FindChild("Textures(NW4R)", false);
            PAT0Folder = node.FindChild("Misc Data [80]/AnmTexPat(NW4R)", false)
                         ?? node.FindChild("AnmTexPat(NW4R)", false);
            this.iconNum = iconNum;

            populate(out prevbase, "MenSelmapPreview/basebgM");
            populate(out icon, "MenSelmapIcon/iconM");
            populate(out frontstname, "MenSelmapPreview/pasted__stnameM");
            populate(out frontstname_shadow, "MenSelmapPreview/pasted__stnameshadowM");
            populate(out seriesicon, "MenSelmapPreview/lambert113");
            populate(out selmap_mark, "MenSelmapPreview/pasted__stnamelogoM");
            populate(out line, "MenSelmapPreview/base_vertexcolorM1");
        }
Exemple #8
0
 private MSBinNode LoadPacMsbn(string path, string childNodeName)
 {
     using (ResourceNode node = NodeFactory.FromFile(null, path)) {
         var childNode = node.FindChild(childNodeName, true) as MSBinNode;
         if (childNode == null)
         {
             throw new Exception("Node '" + childNodeName + "' not found in '" + path + "'");
         }
         return(childNode);
     }
 }
Exemple #9
0
        public void LoadModel(MDL0Node model)
        {
            model.Populate();
            model.ResetToBindState();

            if (UseExceptions)
            {
                foreach (string texname in TexturesToDisable)
                {
                    ResourceNode textureGroup = model.TextureGroup;
                    if (textureGroup != null)
                    {
                        MDL0TextureNode tex = textureGroup.FindChild(texname, false) as MDL0TextureNode;
                        if (tex != null)
                        {
                            tex.Enabled = false;
                        }
                    }
                }
            }

            modelPanel1.ClearAll();
            modelPanel1.AddTarget((IRenderedObject)model);

            if (UseExceptions && PolygonsToDisable.ContainsKey(_charString))
            {
                foreach (int polygonNum in PolygonsToDisable[_charString])
                {
                    MDL0ObjectNode poly = model.PolygonGroup.FindChild("polygon" + polygonNum, false) as MDL0ObjectNode;
                    if (poly != null)
                    {
                        poly.IsRendering = false;
                    }
                }
            }

            Box     box = model.GetBox();
            Vector3 min = box.Min, max = box.Max;

            if (ZoomOut)
            {
                min._x += 20;
                max._x -= 20;
            }
            modelPanel1.SetCamWithBox(min, max);
        }
Exemple #10
0
        private void updateMumenumainToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string mu_menumain_path = null;

            string[] lookIn = { "../../menu2/mu_menumain.pac",
                                "../../menu2/mu_menumain_en.pac",
                                "../../../pfmenu2/mu_menumain.pac",
                                "../../../pfmenu2/mu_menumain_en.pac" };
            foreach (string path in lookIn)
            {
                if (File.Exists(path))
                {
                    mu_menumain_path = path;
                    break;
                }
            }
            if (mu_menumain_path == null)
            {
                MessageBox.Show("mu_menumain / mu_menumain_en not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (DialogResult.OK == MessageBox.Show("Overwrite the current mu_menumain?", "Overwrite File", MessageBoxButtons.OKCancel))
            {
                string tempfile = Path.GetTempFileName();
                string infotmp  = Path.GetTempFileName();
                songPanel1.ExportMSBin(infotmp);
                File.Copy(mu_menumain_path, tempfile, true);

                ResourceNode mu_menumain = NodeFactory.FromFile(null, tempfile);
                MSBinNode    m7          = mu_menumain.FindChild("Misc Data [7]", false) as MSBinNode;
                if (m7 == null)
                {
                    MessageBox.Show(this.ParentForm, "The mu_menumain file does not appear to have a Misc Data [7].",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    m7.Replace(infotmp);
                    mu_menumain.Merge();
                    mu_menumain.Export(mu_menumain_path);
                }

                File.Delete(tempfile);
                File.Delete(infotmp);
            }
        }
Exemple #11
0
 public void UpdateSSSStockIcons()
 {
     if (common5 == null)
     {
         MessageBox.Show(this.FindForm(), "common5.pac is not loaded - can't update automatically.\n" +
                         "After saving sc_selcharacter.pac,  update the icons manually by replacing sc_selmap's " +
                         "MiscData[40] with sc_selcharacter's MiscData[90].", "Cannot perform operation",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         ResourceNode css_stockicons = sc_selcharacter.FindChild("MiscData[90]", false);
         string       tempFile       = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".brres";
         css_stockicons.Export(tempFile);
         ResourceNode sss_stockicons = common5.FindChild("sc_selmap_en/MiscData[40]", false);
         sss_stockicons.Replace(tempFile);
         try {
             File.Delete(tempFile);
         } catch (Exception) { }
     }
 }
Exemple #12
0
        private void ReloadIfValidPac(string file, CustomSSSCodeset sssIfOtherFileValid = null)
        {
            ResourceNode node      = NodeFactory.FromFile(null, file);
            ResourceNode p1icon    = node.FindChild("MenSelmapCursorPly.1", true);
            BRRESNode    candidate = (p1icon != null) ? p1icon.Parent.Parent as BRRESNode : null;

            if (candidate == null)
            {
                MessageBox.Show(this, "No SSS icons were found in the selected file.",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (md80 != null)
                {
                    md80.Dispose();
                }
                md80 = candidate;
                sss  = sssIfOtherFileValid ?? sss;
                ReloadData();
            }
        }
Exemple #13
0
 public override void UpdateDirectory()
 {
     if (File.Exists("../menu2/sc_selcharacter.pac"))
     {
         string path = "../menu2/sc_selcharacter.pac";
         common5         = null;
         sc_selcharacter = NodeFactory.FromFile(null, path);
         _openFilePath   = path;
     }
     else if (File.Exists("../menu2/sc_selcharacter_en.pac"))
     {
         string path = "../menu2/sc_selcharacter_en.pac";
         common5         = null;
         sc_selcharacter = NodeFactory.FromFile(null, path);
         _openFilePath   = path;
     }
     else if (File.Exists("../system/common5.pac"))
     {
         string path = "../system/common5.pac";
         common5         = NodeFactory.FromFile(null, path);
         sc_selcharacter = common5.FindChild("sc_selcharacter_en", false);
         _openFilePath   = path;
     }
     else if (File.Exists("../system/common5_en.pac"))
     {
         string path = "../system/common5_en.pac";
         common5         = NodeFactory.FromFile(null, path);
         sc_selcharacter = common5.FindChild("sc_selcharacter_en", false);
         _openFilePath   = path;
     }
     else
     {
         common5         = null;
         sc_selcharacter = null;
     }
     label1.Text = sc_selcharacter != null?Path.GetFileName(_openFilePath) : "Could not load common5 or sc_selcharacter.";
 }
        public override ResourceNode MainTEX0For(ResourceNode brres, int charNum, int costumeNum)
        {
            string path = "Textures(NW4R)/InfStc." + (charNum == 37 || charNum == 19 || charNum == 34 || charNum == 40 || charNum == 46 ? (charNum * 50 + (costumeNum <= 12 ? costumeNum + 1 : costumeNum)).ToString("D4") : (charNum * 50 + (costumeNum + 1)).ToString("D4"));

            return(brres.FindChild(path, true));
        }
        public void Replace(object sender, string filename)
        {
            var ig = StringComparison.CurrentCultureIgnoreCase;

            if (filename.EndsWith(".tex0", ig))
            {
                TEX0Node tex0 = GetTexInfoFor(sender).tex0;
                if (tex0 == null)
                {
                    return;
                }
                tex0.Replace(filename);
                tex0.IsDirty = true;
                UpdateImage();
            }
            else if (filename.EndsWith(".brres", ig))
            {
                using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
                    TEX0Node tex0;
                    if (node is TEX0Node)
                    {
                        tex0 = (TEX0Node)node;
                    }
                    else
                    {
                        tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
                    }
                    string tempFile = TempFiles.Create(".png");
                    tex0.Export(tempFile);
                    Replace(sender, tempFile);                     // call self with new file
                }
            }
            else
            {
                TEX0Node tex0 = GetTexInfoFor(sender).tex0;
                if (tex0 == null)
                {
                    AddNewTEX0(sender, filename);
                    return;
                }
                else if (useTextureConverter)
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                        dlg.ImageSource = filename;
                        dlg.InitialSize =
                            sender == prevbase ? prevbaseResizeTo
                                                        : sender == frontstname ? frontstnameResizeTo
                                                        : sender == selmap_mark ? selmapMarkResizeTo
                                                        : null;
                        dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
                        dlg.ShowInTaskbar   = true;
                        if (dlg.ShowDialog(null, tex0) == DialogResult.OK)
                        {
                            tex0.IsDirty = true;
                            UpdateImage();
                        }
                    }
                }
                else
                {
                    Bitmap bmp = new Bitmap(filename);
                    if (sender == prevbase && prevbaseResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, prevbaseResizeTo.Value);
                    }
                    else if (sender == frontstname && frontstnameResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, frontstnameResizeTo.Value);
                    }
                    else if (sender == selmap_mark && selmapMarkResizeTo != null)
                    {
                        bmp = BitmapUtilities.Resize(bmp, selmapMarkResizeTo.Value);
                    }
                    if (sender == selmap_mark)
                    {
                        ReplaceSelmapMark(bmp, tex0, false);
                    }
                    else
                    {
                        int colorCount = BitmapUtilities.CountColors(bmp, 256).Align(16);
                        tex0.Replace(bmp, colorCount);
                    }
                    tex0.IsDirty = true;
                    UpdateImage();
                }
            }
        }
Exemple #16
0
        private void copyStockIconsToResultScreenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string stgResult_path          = null;
            string singlePlayerStocks_path = null;

            //Check for files
            if (File.Exists("../stage/melee/STGRESULT.pac"))
            {
                string pathResult = "../stage/melee/STGRESULT.pac";
                stgResult_path = pathResult;
            }
            if (File.Exists("../menu/common/StockFaceTex.brres"))
            {
                string path = "../menu/common/StockFaceTex.brres";
                singlePlayerStocks_path = path;
            }
            //Send error if files are missing
            if (stgResult_path == null)
            {
                MessageBox.Show("STGRESULT not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (singlePlayerStocks_path == null)
            {
                MessageBox.Show("StockFaceTex.brres not found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            //Confirm you want to merge files
            else if (DialogResult.OK == MessageBox.Show("Overwrite the current STGRESULT?", "Overwrite File", MessageBoxButtons.OKCancel))
            {
                //Generate temp files
                string tempFile        = Path.GetTempFileName();
                string stockFaceTextmp = Path.GetTempFileName();

                //Copy files into a temp file that is to be overwritten
                File.Copy(stgResult_path, tempFile, true);
                File.Copy(singlePlayerStocks_path, stockFaceTextmp, true);

                //Search for STGRESULT.pac/2.pac/Misc Data [120]
                ResourceNode stgResult        = NodeFactory.FromFile(null, stgResult_path);
                ARCNode      resultStocks     = stgResult.FindChild("2", true) as ARCNode;
                BRRESNode    resultStockIcons = resultStocks.FindChild("Misc Data [120]", true) as BRRESNode;

                //Send error if files are missing
                if (resultStocks == null)
                {
                    MessageBox.Show(this.ParentForm, "The STGRESULT file does not appear to have a 2.pac.",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (resultStockIcons == null)
                {
                    MessageBox.Show(this.ParentForm, "The 2.pac file does not appear to have a Misc Data [120].",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //Replace STGRESULT.pac/2.pac/Misc Data [120] with StockFaceTex.brres
                    resultStockIcons.Replace(stockFaceTextmp);
                    //Merge the files
                    stgResult.Merge();
                    //Export STGRESULT.pac
                    stgResult.Export(stgResult_path);
                }
                //Delete generated temp files
                File.Delete(stockFaceTextmp);
                File.Delete(tempFile);
            }
        }
        public void Replace(string filename, bool useTextureConverter)
        {
            if (Texture == null)
            {
                return;
            }

            var ig = StringComparison.CurrentCultureIgnoreCase;

            if (filename.EndsWith(".tex0", ig) || filename.EndsWith(".brres", ig))
            {
                using (ResourceNode node = NodeFactory.FromFile(null, filename)) {
                    TEX0Node tex0;
                    if (node is TEX0Node)
                    {
                        tex0 = (TEX0Node)node;
                    }
                    else
                    {
                        tex0 = (TEX0Node)node.FindChild("Textures(NW4R)", false).Children[0];
                    }
                    string tempFile = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".png";
                    tex0.Export(tempFile);
                    Replace(tempFile, useTextureConverter);                     // call self with new file
                    File.Delete(tempFile);
                }
            }
            else
            {
                if (useTextureConverter)
                {
                    using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                        dlg.ImageSource = filename;
                        if (dlg.ShowDialog(null, Texture) == DialogResult.OK)
                        {
                            if (OnUpdate != null)
                            {
                                OnUpdate(this);
                            }
                        }
                    }
                }
                else
                {
                    if (Texture.Format == WiiPixelFormat.CMPR)
                    {
                        Bitmap              bitmap      = new Bitmap(filename);
                        UnsafeBuffer        buffer      = TextureConverter.CMPR.GeneratePreview(bitmap);
                        BrawlLib.IO.FileMap textureData = TextureConverter.CMPR.EncodeTEX0TextureCached(bitmap, Texture.LevelOfDetail, buffer);
                        Texture.ReplaceRaw(textureData);
                    }
                    else
                    {
                        Texture.Replace(filename);
                    }
                    if (OnUpdate != null)
                    {
                        OnUpdate(this);
                    }
                }
            }
        }
Exemple #18
0
 public override ResourceNode MainTEX0For(ResourceNode node, int charNum, int costumeNum)
 {
     return(node.FindChild("Textures(NW4R)", false).Children[0]);
 }
Exemple #19
0
        public static void Copy(ResourceNode scSelmap, ResourceNode muMenumain, CustomSSSCodeset sss)
        {
            ResourceNode                miscData0 = muMenumain.FindChild("Misc Data [0]", false);
            List <ResourceNode>         chrToKeep = miscData0.FindChild("AnmChr(NW4R)", false).Children;
            Dictionary <string, string> tempFiles = new Dictionary <string, string>(chrToKeep.Count);

            foreach (ResourceNode n in chrToKeep)
            {
                string file = TempFiles.Create(".chr0");
                tempFiles.Add(n.Name, file);
                n.Export(file);
            }

            ResourceNode miscData80 = scSelmap.FindChild("Misc Data [80]", false);

            miscData0.ReplaceRaw(miscData80.WorkingSource.Address, miscData80.WorkingSource.Length);
            miscData0.SignalPropertyChange();

            List <ResourceNode> chrToReplace = miscData0.FindChild("AnmChr(NW4R)", false).Children;

            foreach (ResourceNode n in chrToReplace)
            {
                string file = tempFiles[n.Name];
                n.Replace(file);
            }

            string       xx_png = TempFiles.Create(".png");
            ResourceNode xx     = miscData0.FindChild("Textures(NW4R)/MenSelmapIcon.XX", false);
            bool         found  = false;

            if (xx != null)
            {
                xx.Export(xx_png);
                found = true;
            }
            else
            {
                Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BrawlCrate.StageManager.XX.png");
                if (stream != null)
                {
                    Image.FromStream(stream).Save(xx_png);
                    found = true;
                }
            }

            if (found)
            {
                foreach (ResourceNode tex in miscData0.FindChild("Textures(NW4R)", false).Children)
                {
                    byte icon_id;
                    if (tex.Name.StartsWith("MenSelmapIcon.") && byte.TryParse(tex.Name.Substring(14, 2), out icon_id))
                    {
                        byte stage_id = sss.StageForIcon(icon_id);
                        if (icon_id != 100 && (stage_id == 0x25 || stage_id > 0x33))
                        {
                            tex.Replace(xx_png);
                        }
                    }
                }
            }

            File.Delete(xx_png);
        }
        public void UpdateDirectory()
        {
            Console.WriteLine(System.Environment.CurrentDirectory);
            if (sc_selmap != null)
            {
                sc_selmap.Dispose();
            }
            if (common5 != null)
            {
                common5.Dispose();
            }
            _openFilePath       = null;
            fileSizeBar.Maximum = 1214283;
            if (File.Exists("../../menu2/sc_selmap.pac"))
            {
                common5       = null;
                sc_selmap     = TempFiles.MakeTempNode("../../menu2/sc_selmap.pac");
                _openFilePath = "../../menu2/sc_selmap.pac";
            }
            else if (File.Exists("../../menu2/sc_selmap_en.pac"))
            {
                common5       = null;
                sc_selmap     = TempFiles.MakeTempNode("../../menu2/sc_selmap_en.pac");
                _openFilePath = "../../menu2/sc_selmap_en.pac";
            }
            else if (File.Exists("../../system/common5.pac"))
            {
                common5       = TempFiles.MakeTempNode("../../system/common5.pac");
                sc_selmap     = common5.FindChild("sc_selmap_en", false);
                _openFilePath = "../../system/common5.pac";
            }
            else if (File.Exists("../../system/common5_en.pac"))
            {
                common5       = TempFiles.MakeTempNode("../../system/common5_en.pac");
                sc_selmap     = common5.FindChild("sc_selmap_en", false);
                _openFilePath = "../../system/common5_en.pac";
            }
            else
            {
                common5     = null;
                sc_selmap   = null;
                label1.Text = "Could not load sc_selmap(_en) or common5(_en).";
            }
            if (_openFilePath != null)
            {
                updateFileSize();
                TEX0Node tex0 = sc_selmap.FindChild("MiscData[80]/Textures(NW4R)/MenSelmapFrontBg", false) as TEX0Node;
                if (tex0 != null)
                {
                    scribble = tex0.GetImage(0);
                }
                FindMuMenumain();
            }
            else
            {
                fileSizeBar.Value  = 0;
                fileSizeLabel.Text = "";
            }

            // Find and load GCT, if it exists
            AutoSSS = null;
            DirectoryInfo directory = new DirectoryInfo(Environment.CurrentDirectory);

            while (directory != null)
            {
                Console.WriteLine(directory);
                if (File.Exists(directory.FullName + "/data/gecko/codes/RSBE01.gct"))
                {
                    AutoSSS = new CustomSSSCodeset(File.ReadAllBytes(directory.FullName + "/data/gecko/codes/RSBE01.gct"));
                    break;
                }
                else if (File.Exists(directory.FullName + "/codes/RSBE01.gct"))
                {
                    AutoSSS = new CustomSSSCodeset(File.ReadAllBytes(directory.FullName + "/codes/RSBE01.gct"));
                    break;
                }
                directory = directory.Parent;
            }
        }
        private unsafe void Load()
        {
            if (_context == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture(_context, 0, 0);
            Texture.Bind();

            //ctx._states[String.Format("{0}_TexRef", Name)] = Texture;

            Bitmap   bmp   = null;
            TEX0Node tNode = null;

            if (_context._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = _context._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        bmp    = tNode.GetImage(0);
                    }
                    else
                    {
                        //Then search node directory
                        string path = node._origPath;
                        if (path != null)
                        {
                            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                            foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                            {
                                if (file.Name.EndsWith(".tga"))
                                {
                                    Source = file.FullName;
                                    bmp    = TGA.FromFile(file.FullName);
                                    break;
                                }
                                else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif"))
                                {
                                    Source = file.FullName;
                                    bmp    = (Bitmap)Bitmap.FromFile(file.FullName);
                                    break;
                                }
                            }
                        }
                    }
                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();

                if (bmp != null)
                {
                    int w = bmp.Width, h = bmp.Height, size = w * h;

                    Texture._width  = w;
                    Texture._height = h;
                    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureMagFilter.LINEAR);
                    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureMinFilter.NEAREST_MIPMAP_LINEAR);
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0);

                    //if (tNode != null)
                    //    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, tNode.LevelOfDetail);
                    //else
                    //    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, 0);

                    BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    try
                    {
                        using (UnsafeBuffer buffer = new UnsafeBuffer(size << 2))
                        {
                            ARGBPixel *sPtr = (ARGBPixel *)data.Scan0;
                            ABGRPixel *dPtr = (ABGRPixel *)buffer.Address;

                            for (int i = 0; i < size; i++)
                            {
                                *dPtr++ = (ABGRPixel)(*sPtr++);
                            }

                            int res = _context.gluBuild2DMipmaps(GLTextureTarget.Texture2D, GLInternalPixelFormat._4, w, h, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, buffer.Address);
                            if (res != 0)
                            {
                            }
                        }
                    }
                    finally
                    {
                        bmp.UnlockBits(data);
                        bmp.Dispose();
                    }
                }
            }
        }
        /// <summary>
        /// This function finds the new info.pac and common2.pac. It should be called whenever you change the working directory.
        /// It also clears the list of edited ("dirty") strings, and records the current names (for the "restore" button).
        /// </summary>
        public String findInfoFile()
        {
            _index = -1;

            info              = info_training = null;
            _currentFile      = _currentTrainingFile = null;
            common2_titledata = new List <SongIndexEntry>(0);

            string tempfile = Path.GetTempFileName();

            string[] sndBgmTitleDataPaths = { "..\\..\\system\\common2.pac", "..\\..\\system\\common2_en.pac", "..\\common2.pac" };
            foreach (string relativepath in sndBgmTitleDataPaths)
            {
                string s = Path.GetFullPath(relativepath);
                if (new FileInfo(s).Exists)
                {
                    File.Copy(s, tempfile, true);
                    using (var node = NodeFactory.FromFile(null, tempfile)) {
                        foreach (ResourceNode child in node.Children)
                        {
                            if (child is Common2MiscDataNode)
                            {
                                SndBgmTitleDataNode sndBgmTitleData = child.Children.FirstOrDefault() as SndBgmTitleDataNode;
                                if (sndBgmTitleData != null)
                                {
                                    common2_titledata = sndBgmTitleData.Children.Select(n => new SongIndexEntry()
                                    {
                                        ID    = (ushort)((SndBgmTitleEntryNode)n).ID,
                                        Index = ((SndBgmTitleEntryNode)n).SongTitleIndex
                                    }).ToList();
                                    break;
                                }
                            }
                        }
                    }
                }
                if (common2_titledata.Count > 0)
                {
                    break;
                }
            }

            if (common2_titledata.Count == 0)
            {
                common2_titledata = SongIDMap.Songs.Where(s => s.InfoPacIndex != null).Select(s => new SongIndexEntry()
                {
                    ID    = s.ID,
                    Index = s.InfoPacIndex ?? 0
                }).ToList();
            }

            tempfile = Path.GetTempFileName();
            if (new FileInfo("Misc Data [140].msbin").Exists)
            {
                _currentFile = "Misc Data [140].msbin";
                File.Copy("Misc Data [140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return("Loaded .\\Misc Data [140].msbin");
            }
            else if (new FileInfo("\\Misc Data [140].msbin").Exists)
            {
                _currentFile = "\\Misc Data [140].msbin";
                File.Copy("\\Misc Data [140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return("Loaded \\Misc Data [140].msbin");
            }
            else
            {
                string[] infopaths = { "..\\..\\info2\\info.pac", "..\\..\\info2\\info_en.pac", "..\\info.pac" };

                foreach (string relativepath in infopaths)
                {
                    if (info == null)
                    {
                        string s = Path.GetFullPath(relativepath);
                        if (new FileInfo(s).Exists)
                        {
                            _currentFile = s;
                            File.Copy(s, tempfile, true);
                            info_pac = NodeFactory.FromFile(null, tempfile);
                            info     = (MSBinNode)info_pac.FindChild("Misc Data [140]", true);
                        }
                    }
                }

                if (info == null)
                {
                    return("No song list loaded");
                }
                else
                {
                    modifiedStringIndices.Clear();
                    copyIntoFileStrings();

                    // info found; try info_training in same directory
                    string trainingpath = _currentFile.Replace("info.pac", "info_training.pac").Replace("info_en.pac", "info_training_en.pac");
                    if (trainingpath != _currentFile && new FileInfo(trainingpath).Exists)
                    {
                        _currentTrainingFile = trainingpath;
                        string tempfile_training = Path.GetTempFileName();
                        File.Copy(trainingpath, tempfile_training, true);
                        info_training_pac = NodeFactory.FromFile(null, tempfile_training);
                        info_training     = (MSBinNode)info_training_pac.FindChild("Misc Data [140]", true);
                        if (info._strings.Count != info_training._strings.Count)
                        {
                            MessageBox.Show("info.pac and info_training.pac have different Misc Data [140] lengths. Ignoring info_training.pac.");
                            info_training     = null;
                            info_training_pac = null;
                        }
                    }
                    return(info_training != null ? "Loaded info.pac and info_training.pac" : "Loaded info.pac");
                }
            }
        }
Exemple #23
0
        /// <summary>
        /// This function finds the new info.pac. It should be called whenever you change the working directory.
        /// It also clears the list of edited ("dirty") strings, and records the current names (for the "restore" button).
        /// </summary>
        public String findInfoFile()
        {
            _index = -1;

            info         = info_training = null;
            _currentFile = _currentTrainingFile = null;

            string tempfile = Path.GetTempFileName();

            if (new FileInfo("MiscData[140].msbin").Exists)
            {
                _currentFile = "MiscData[140].msbin";
                File.Copy("MiscData[140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return("Loaded .\\MiscData[140].msbin");
            }
            else if (new FileInfo("\\MiscData[140].msbin").Exists)
            {
                _currentFile = "\\MiscData[140].msbin";
                File.Copy("\\MiscData[140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return("Loaded \\MiscData[140].msbin");
            }
            else
            {
                string[] infopaths = { "..\\..\\info2\\info.pac", "..\\..\\info2\\info_en.pac", "..\\info.pac" };

                foreach (string relativepath in infopaths)
                {
                    if (info == null)
                    {
                        string s = Path.GetFullPath(relativepath);
                        if (new FileInfo(s).Exists)
                        {
                            _currentFile = s;
                            File.Copy(s, tempfile, true);
                            info_pac = NodeFactory.FromFile(null, tempfile);
                            info     = (MSBinNode)info_pac.FindChild("MiscData[140]", true);
                        }
                    }
                }

                if (info == null)
                {
                    return("No song list loaded");
                }
                else
                {
                    modifiedStringIndices.Clear();
                    copyIntoFileStrings();

                    // info found; try info_training in same directory
                    string trainingpath = _currentFile.Replace("info.pac", "info_training.pac").Replace("info_en.pac", "info_training_en.pac");
                    if (trainingpath != _currentFile && new FileInfo(trainingpath).Exists)
                    {
                        _currentTrainingFile = trainingpath;
                        string tempfile_training = Path.GetTempFileName();
                        File.Copy(trainingpath, tempfile_training, true);
                        info_training_pac = NodeFactory.FromFile(null, tempfile_training);
                        info_training     = (MSBinNode)info_training_pac.FindChild("MiscData[140]", true);
                        return("Loaded info.pac and info_training.pac");
                    }
                    else
                    {
                        return("Loaded info.pac");
                    }
                }
            }
        }
        public void copyIconsToSelcharacter2()
        {
            string fileToSaveTo = null;

            ResourceNode s2 = null;

            if (common5 != null)
            {
                s2 = common5.FindChild("sc_selcharacter2_en", false);
            }
            else if (sc_selmap != null)
            {
                if (File.Exists("../../menu2/sc_selcharacter2.pac"))
                {
                    fileToSaveTo = "../../menu2/sc_selcharacter2.pac";
                    s2           = TempFiles.MakeTempNode(fileToSaveTo);
                }
                else if (File.Exists("../../menu2/sc_selcharacter2_en.pac"))
                {
                    fileToSaveTo = "../../menu2/sc_selcharacter2_en.pac";
                    s2           = TempFiles.MakeTempNode(fileToSaveTo);
                }
            }

            if (s2 == null)
            {
                return;
            }

            ResourceNode md0  = s2.FindChild("MenuRule_en/ModelData[0]", false);
            MSBinNode    md1  = s2.FindChild("MenuRule_en/MiscData[1]", false) as MSBinNode;
            ResourceNode md80 = sc_selmap.FindChild("MiscData[80]", false);

            if (md0 == null || md80 == null)
            {
                return;
            }

            Image[] icons        = new Image[41];
            Image[] frontstnames = new Image[41];
            for (int i = 1; i < 60; i++)
            {
                if (i == 32)
                {
                    i = 50;
                }
                int    sssPos     = StageIDMap.sssPositionForSelcharacter2Icon(i);
                string nameSelmap = BestSSS[sssPos].Item2.ToString("D2");
                icons[sssPos]        = ((md80.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelmap, false) as TEX0Node).GetImage(0));
                frontstnames[sssPos] = ((md80.FindChild("Textures(NW4R)/MenSelmapFrontStname." + nameSelmap, false) as TEX0Node).GetImage(0));
            }

            var d = new RandomSelectEditNamesDialog(md1._strings, icons, frontstnames);

            d.Message = "When finished, press OK to continue.";
            if (d.ShowDialog() == DialogResult.OK)
            {
                for (int i = 0; i < md1._strings.Count; i++)
                {
                    md1._strings[i] = d[i].ToString();
                }
            }
            else
            {
                return;
            }

            using (ProgressWindow w = new ProgressWindow()
            {
                CanCancel = false
            }) {
                w.Begin(0, 60, 0);
                for (int i = 1; i < 60; i++)
                {
                    if (i == 32)
                    {
                        i = 50;
                    }

                    int      sssPos            = StageIDMap.sssPositionForSelcharacter2Icon(i);
                    string   tempFile1         = TempFiles.Create(".tex0");
                    string   tempFile2         = TempFiles.Create(".plt0");
                    string   nameSelcharacter2 = i.ToString("D2");
                    string   nameSelmap        = BestSSS[sssPos].Item2.ToString("D2");
                    TEX0Node iconFrom          = md80.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelmap, false) as TEX0Node;
                    TEX0Node iconTo            = md0.FindChild("Textures(NW4R)/MenSelmapIcon." + nameSelcharacter2, false) as TEX0Node;
                    var      palFrom           = md80.FindChild("Palettes(NW4R)/MenSelmapIcon." + nameSelmap, false);
                    var      palTo             = md0.FindChild("Palettes(NW4R)/MenSelmapIcon." + nameSelcharacter2, false);
                    if (iconFrom != null && iconTo != null && palFrom != null && palTo != null)
                    {
                        iconFrom.Export(tempFile1);
                        iconTo.Replace(tempFile1);
                        palFrom.Export(tempFile2);
                        palTo.Replace(tempFile2);
                    }

                    TEX0Node prevbase    = md80.FindChild("Textures(NW4R)/MenSelmapPrevbase." + nameSelmap, false) as TEX0Node;
                    TEX0Node stageswitch = md0.FindChild("Textures(NW4R)/MenStageSwitch." + nameSelcharacter2, false) as TEX0Node;
                    if (prevbase != null && stageswitch != null)
                    {
                        Bitmap thumbnail = new Bitmap(112, 56);
                        using (Graphics g = Graphics.FromImage(thumbnail)) {
                            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                            g.DrawImage(prevbase.GetImage(0), 0, -28, 112, 112);
                        }
                        stageswitch.Replace(thumbnail);
                    }

                    w.Update(i);
                }
            }

            if (fileToSaveTo != null)
            {
                s2.Export(fileToSaveTo);
            }
        }
        /// <summary>
        /// Adds PAT0 entries for each stage to the given PAT0TextureNode.
        /// </summary>
        /// <param name="pathToPAT0TextureNode">Path relative to sc_selmap_en</param>
        /// <param name="defaultName">The texture name to be used for new PAT0 entries. If null, the name will be taken from the first entry, with the number at the end replaced with the icon number.</param>
        public void AddPAT0(string pathToPAT0TextureNode, string defaultName = null)
        {
            var look = sc_selmap.FindChild(pathToPAT0TextureNode, false).Children[0];

            if (!(look is PAT0TextureNode))
            {
                throw new FormatException(look.Name);
            }

            bool icon = look.Parent.Name == "iconM";

            PAT0TextureNode tn = look as PAT0TextureNode;

            List <PAT0TextureEntryNode> childrenList = (from c in tn.Children
                                                        where c is PAT0TextureEntryNode
                                                        select(PAT0TextureEntryNode) c).ToList();

            if ((from c in childrenList where c.FrameIndex >= 40 && c.FrameIndex < 50 select c).Count() >= 10)
            {
                MessageBox.Show("Skipping " + pathToPAT0TextureNode.Substring(pathToPAT0TextureNode.LastIndexOf('/') + 1) +
                                " - mappings for icon numbers 40-49 already exist.");
                return;
            }

            string texToCopyName = null;
            List <Tuple <string, float> > entries = new List <Tuple <string, float> >();

            foreach (var entry in childrenList)
            {
                if (entry.Texture == null)
                {
                    MessageBox.Show("BrawlLib cannot read PAT0 texture name(s) from " + pathToPAT0TextureNode);
                    return;
                }
                entries.Add(new Tuple <string, float>(entry.Texture, entry.FrameIndex));
                if (entry.FrameIndex == 1)
                {
                    texToCopyName = entry.Texture;
                }
                if (entry.FrameIndex != 0)
                {
                    tn.RemoveChild(entry);
                }
            }

            string basename = (from e in entries
                               where e.Item1.Contains('.')
                               select e.Item1).First();

            basename = basename.Substring(0, basename.LastIndexOf('.'));

            Func <int, string> getTexStringByIconNumber = iconNum => {
                if (iconNum < 32 || (iconNum >= 50 && iconNum < 60) || iconNum == 80)
                {
                    string previousTexture = null;
                    foreach (var entry in entries)
                    {
                        if (entry.Item2 > iconNum)
                        {
                            break;
                        }
                        previousTexture = entry.Item1;
                    }
                    return(previousTexture);
                }
                else
                {
                    return(defaultName ?? basename + "." + iconNum.ToString("D2"));
                }
            };

            for (int i = 1; i <= 80; i++)
            {
                string texname = getTexStringByIconNumber(i);
                var    entry   = new PAT0TextureEntryNode();
                tn.AddChild(entry);
                entry.FrameIndex = i;
                entry.Texture    = texname;
                if (icon)
                {
                    entry.Palette = entry.Texture;
                }
            }

            var moreThan79query = from e in entries
                                  where e.Item2 > 80
                                  orderby e.Item2 ascending
                                  select e;

            foreach (var tuple in moreThan79query)
            {
                var entry = new PAT0TextureEntryNode();
                tn.AddChild(entry);
                entry.FrameIndex = tuple.Item2;
                entry.Texture    = tuple.Item1;
                if (icon)
                {
                    entry.Palette = entry.Texture;
                }
            }

            ResourceNode brres = tn;

            while (brres != null && !(brres is BRRESNode))
            {
                brres = brres.Parent;
            }

            if (brres != null)
            {
                var      folder    = brres.FindChild("Textures(NW4R)", false);
                TEX0Node texToCopy = texToCopyName == null
                                        ? null
                                        : folder.FindChild(texToCopyName, false) as TEX0Node;
                PLT0Node pltToCopy = texToCopyName == null
                                        ? null
                                        : brres.FindChild("Palettes(NW4R)", false).FindChild(texToCopyName, false) as PLT0Node;

                foreach (ResourceNode c in tn.Children)
                {
                    PAT0TextureEntryNode p = c as PAT0TextureEntryNode;
                    if (p == null)
                    {
                        continue;
                    }

                    var texture = folder.FindChild(p.Texture, false);
                    if (texture == null)
                    {
                        if (texToCopy != null)
                        {
                            TEX0Node tex0 = ((BRRESNode)brres).CreateResource <TEX0Node>(p.Texture);
                            tex0.ReplaceRaw(texToCopy.WorkingUncompressed.Address, texToCopy.WorkingUncompressed.Length);
                        }
                        if (pltToCopy != null)
                        {
                            PLT0Node plt0 = ((BRRESNode)brres).CreateResource <PLT0Node>(p.Texture);
                            plt0.ReplaceRaw(pltToCopy.WorkingUncompressed.Address, pltToCopy.WorkingUncompressed.Length);
                        }
                    }
                    else if (texture.Index == 1)
                    {
                        texToCopy = texture as TEX0Node;
                    }
                }
            }
        }
Exemple #26
0
        public override ResourceNode MainTEX0For(ResourceNode brres, int charNum, int costumeNum)
        {
            string path = "Textures(NW4R)/MenSelchrFaceB." + (charNum * 10 + (costumeNum <= 12 ? costumeNum + 1 : costumeNum)).ToString("D3");

            return(brres.FindChild(path, false));
        }
Exemple #27
0
        private ActionResult Generate(string csv, string gctPath, ResourceNode sc_selmap, string relpath, ResourceNode info_pac, ResourceNode common2, string brstmPath)
        {
            Func <string, List <string> > split = s => {
                List <string> list    = new List <string>();
                StringBuilder current = new StringBuilder();
                bool          inQuote = false;
                foreach (char c in s)
                {
                    if (c == '"')
                    {
                        inQuote = !inQuote;
                    }
                    else if (c == ',' && !inQuote)
                    {
                        list.Add(current.ToString());
                        current.Clear();
                    }
                    else
                    {
                        current.Append(c);
                    }
                }
                list.Add(current.ToString());
                return(list);
            };

            List <CEPStage> stages    = new List <CEPStage>();
            IList <string>  firstLine = null;

            foreach (string line in System.IO.File.ReadAllLines(csv, Encoding.UTF8))
            {
                if (firstLine == null)
                {
                    firstLine = split(line);
                }
                else
                {
                    CEPStage s = new CEPStage();
                    int      i = 0;
                    foreach (string cell in split(line))
                    {
                        if (cell != "")
                        {
                            var prop = typeof(CEPStage).GetProperty(firstLine[i]);
                            if (prop?.PropertyType == typeof(bool))
                            {
                                prop.SetValue(s, bool.Parse(cell));
                            }
                            else
                            {
                                prop?.SetValue(s, cell);
                            }
                        }
                        i++;
                    }
                    stages.Add(s);
                }
            }

            byte[] gct = System.IO.File.ReadAllBytes(gctPath);
            var    sss = new BrawlManagerLib.CustomSSSCodeset(gct);

            foreach (CEPStage s in stages)
            {
                try {
                    string relname = StageIDMap.RelNameForPac(s.Filename, true);
                    using (var stream = new FileStream(Path.Combine(relpath, relname), FileMode.Open, FileAccess.Read)) {
                        stream.Seek(3, SeekOrigin.Begin);
                        s.ModuleBase = RelNames[stream.ReadByte()];
                    }
                } catch (FileNotFoundException) { }

                if (s.Alternate)
                {
                    continue;
                }
                int iconId          = sss.IconForStage(s.Stage.ID);
                TextureContainer tc = new TextureContainer(sc_selmap, iconId);
                if (tc.icon_tex0 != null)
                {
                    using (MemoryStream ms = new MemoryStream()) {
                        using (Bitmap b = tc.icon_tex0.GetImage(0)) {
                            b.Save(ms, ImageFormat.Png);
                            s.PngIcon = ms.ToArray();
                        }
                    }
                }
            }

            MSBinNode info = (MSBinNode)info_pac.FindChild("MiscData[140]", true);
            var       common2_titledata = new List <SongNameBar.SongIndexEntry>(0);

            foreach (ResourceNode child in common2.Children)
            {
                if (child is Common2MiscDataNode)
                {
                    SndBgmTitleDataNode sndBgmTitleData = child.Children.FirstOrDefault() as SndBgmTitleDataNode;
                    if (sndBgmTitleData != null)
                    {
                        common2_titledata = sndBgmTitleData.Children.Select(n => new SongNameBar.SongIndexEntry()
                        {
                            ID    = (ushort)((SndBgmTitleEntryNode)n).ID,
                            Index = ((SndBgmTitleEntryNode)n).SongTitleIndex
                        }).ToList();
                        break;
                    }
                }
            }

            List <string> brstms = Directory.EnumerateFiles(brstmPath)
                                   .Select(s => Path.GetFileNameWithoutExtension(s)).ToList();

            var sdsl = new StageDependentSongLoader(gct);

            foreach (CEPStage stage in stages)
            {
                Song song = sdsl.GetSong(stage.Stage.ID);
                if (song != null)
                {
                    stage.SongFilename = song.Filename;
                    stage.SongTitle    = info._strings[common2_titledata.Where(c => c.ID == song.ID).Select(c => c.Index).First()];
                    //brstms.RemoveAll(s => s == song.Filename);
                }
            }

            var expStages = stages.Where(s => s.Filename.Contains("CUSTOM"));

            return(View(new MainModel {
                Stages = stages.Except(expStages).Concat(expStages).ToList(),
                Songs = brstms.Select(b => {
                    var song = SongIDMap.Songs.SingleOrDefault(s => s.Filename == b);
                    return new CEPSong {
                        SongFilename = b,
                        SongTitle = info._strings[(
                                                      from c in common2_titledata
                                                      where c.ID == song.ID
                                                      select c.Index
                                                      ).SingleOrDefault()],
                        OriginalSongTitle = b.StartsWith("0000") ? null : song.DefaultName
                    };
                })
            }));
        }