Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private MSBinNode LoadPacMsbn(string path, string childNodeName)
        {
            using (ResourceNode node = NodeFactory.FromFile(null, path))
            {
                MSBinNode childNode = node.FindChild(childNodeName, true) as MSBinNode;
                if (childNode == null)
                {
                    throw new Exception("Node '" + childNodeName + "' not found in '" + path + "'");
                }

                return(childNode);
            }
        }
Esempio n. 3
0
        public MSBinNode NewMSBin()
        {
            MSBinNode node = new MSBinNode {
                FileType = ARCFileType.MiscData
            };

            _resource.AddChild(node);

            BaseWrapper w = FindResource(node, false);

            w.EnsureVisible();
            w.TreeView.SelectedNode = w;
            return(node);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
0
        public override ResourceNode Duplicate()
        {
            if (_resource._parent == null)
            {
                return(null);
            }
            _resource.Rebuild();
            MSBinNode newNode  = NodeFactory.FromAddress(null, _resource.WorkingUncompressed.Address, _resource.WorkingUncompressed.Length) as MSBinNode;
            int       newIndex = _resource.Index + 1;

            _resource._parent.InsertChild(newNode, true, newIndex);
            newNode.Populate();
            newNode.FileType      = ((MSBinNode)_resource).FileType;
            newNode.FileIndex     = ((MSBinNode)_resource).FileIndex;
            newNode.RedirectIndex = ((MSBinNode)_resource).RedirectIndex;
            newNode.Name          = _resource.Name;
            return(newNode);
        }
Esempio n. 6
0
 public void PrepareTRNG()
 {
     trngPath = FindFile(TRNG_PATHS);
     trngMsbn = LoadPacMsbn(trngPath, "Misc Data [140]");
 }
Esempio n. 7
0
 public void PrepareINFO()
 {
     infoPath = FindFile(INFO_PATHS);
     infoMsbn = LoadPacMsbn(infoPath, "Misc Data [140]");
 }
Esempio n. 8
0
 public void PrepareMUM()
 {
     mumPath = FindFile(MUM_PATHS);
     mumMsbn = LoadPacMsbn(mumPath, "Misc Data [7]");
 }
Esempio n. 9
0
        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>
        /// 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");
                }
            }
        }
Esempio n. 11
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
                    };
                })
            }));
        }
Esempio n. 12
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");
                    }
                }
            }
        }