public SSSEditorForm(string gct, string pac)
        {
            InitializeComponent();
            foreach (Control c in tblColorCodeKeys.Controls) {
                c.DoubleClick += (o, e) => {
                    tblColorCodeKeys.Visible = false;
                };
            }
            try {
                Icon = Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetCallingAssembly().Location);
            } catch (Exception e) {
                Console.WriteLine(e.StackTrace);
            }

            tabControl1.SelectedIndexChanged += tabControl1_SelectedIndexChanged;

            sss = gct != null
                ? new CustomSSSCodeset(gct)
                : new CustomSSSCodeset();

            if (pac != null) {
                ReloadIfValidPac(pac);
            } else {
                md80 = new BRRESNode();
                ReloadData();
            }

            FormClosed += (o, e) => TempFiles.DeleteAll();
        }
 private CustomSSSCodeset(CustomSSSCodeset copyfrom, byte[] sss1, byte[] sss2, byte[] sss3)
 {
     this.sss1 = sss1;
     this.sss2 = sss2;
     this.sss3 = sss3;
     this.DataBefore = copyfrom.DataBefore;
     this.DataAfter = copyfrom.DataAfter;
 }
 private CustomSSSCodeset(CustomSSSCodeset copyfrom, byte[] sss1, byte[] sss2, byte[] sss3)
 {
     this.sss1  = sss1;
     this.sss2  = sss2;
     this.sss3  = sss3;
     DataBefore = copyfrom.DataBefore;
     DataAfter  = copyfrom.DataAfter;
 }
        public static void Copy(ResourceNode scSelmap, ResourceNode muMenumain, CustomSSSCodeset sss)
        {
            ResourceNode miscData0 = muMenumain.FindChild("MiscData[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("MiscData[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("BrawlStageManager.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);
        }
Exemple #5
0
        public static List <string> PacFilesBySSSOrder(CustomSSSCodeset sss)
        {
            List <string> list = new List <string>();

            foreach (int stage_id in sss.StageIDsInOrder)
            {
                if (stage_id >= 0x40)
                {
                    list.Add("STGCUSTOM" + (stage_id - 0x3F).ToString("X2") + ".pac");
                }
                else
                {
                    var q = from s in Stages
                            where s.ID == stage_id
                            select s.PacNames;
                    foreach (string[] ss in q)
                    {
                        list.AddRange(ss);
                    }
                }
            }
            return(list);
        }
 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();
     }
 }
 private void pasteAnSSSCodeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (Form f = new Form() { Text = "Custom SSS Code" }) {
         Button ok = new Button() {
             Text = "OK",
             Dock = DockStyle.Bottom,
             DialogResult = System.Windows.Forms.DialogResult.OK
         };
         f.Controls.Add(ok);
         TextBox t = new TextBox() {
             Multiline = true,
             Dock = DockStyle.Fill,
             ScrollBars = ScrollBars.Vertical,
             Font = new System.Drawing.Font("Consolas", 12),
         };
         f.Controls.Add(t);
         if (f.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) {
             sss = new CustomSSSCodeset(t.Lines);
             ReloadData();
         }
     }
 }
        private void openSDCardRootToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var dialog = new FolderBrowserDialog()) {
                if (dialog.ShowDialog() == DialogResult.OK) {
                    CustomSSSCodeset candidateSSS;

                    if (File.Exists(dialog.SelectedPath + "/codes/RSBE01.gct")) {
                        candidateSSS = new CustomSSSCodeset(dialog.SelectedPath + "/codes/RSBE01.gct");
                    } else if (File.Exists(dialog.SelectedPath + "/data/gecko/codes/RSBE01.gct")) {
                        candidateSSS = new CustomSSSCodeset(dialog.SelectedPath + "/data/gecko/codes/RSBE01.gct");
                    } else if (File.Exists(dialog.SelectedPath + "/RSBE01.gct")) {
                        candidateSSS = new CustomSSSCodeset(dialog.SelectedPath + "/RSBE01.gct");
                    } else {
                        MessageBox.Show(this, "Could not find codes/RSBE01.gct or data/gecko/codes/RSBE01.gct.",
                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    string root = null;
                    foreach (string folder in new string[] { "/private/wii/app/RSBE/pf", "/projectm/pf", "/minusery/pf" }) {
                        foreach (string file in new string[] { "/menu2/sc_selmap.pac", "/menu2/sc_selmap_en.pac", "system/common5.pac", "system/common5_en.pac" }) {
                            if (File.Exists(dialog.SelectedPath + folder + "/" + file)) {
                                root = dialog.SelectedPath + folder + "/" + file;
                                break;
                            }
                        }
                    }
                    if (root == null) {
                        MessageBox.Show(this, "Could not find common5 or sc_selmap.",
                            "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    ReloadIfValidPac(root, candidateSSS);
                }
            }
        }
 private void openCodesetgcttxtToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var dialog = new OpenFileDialog()) {
         dialog.Filter = "Ocarina codes (*.gct, *.txt)|*.gct;*.txt";
         dialog.Multiselect = false;
         if (dialog.ShowDialog() == DialogResult.OK) {
             sss = new CustomSSSCodeset(dialog.FileName);
             ReloadData();
         }
     }
 }
Exemple #10
0
 public static List<string> PacFilesBySSSOrder(CustomSSSCodeset sss)
 {
     List<string> list = new List<string>();
     foreach (int stage_id in sss.StageIDsInOrder) {
         if (stage_id >= 0x40) {
             list.Add("STGCUSTOM" + (stage_id - 0x3F).ToString("X2") + ".pac");
         } else {
             var q = from s in Stages
                     where s.ID == stage_id
                     select s.PacNames;
             foreach (string[] ss in q) {
                 list.AddRange(ss);
             }
         }
     }
     return list;
 }
        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;
            }
        }
        public PortraitViewer()
        {
            InitializeComponent();

            #region default sss
            string s = @"Pretty generic custom SSS (based on CEP 5.5)
            * 046B8F5C 7C802378
            * 046B8F64 7C6300AE
            * 040AF618 5460083C
            * 040AF68C 38840002
            * 040AF6AC 5463083C
            * 040AF6C0 88030001
            * 040AF6E8 3860FFFF
            * 040AF59C 3860000C
            * 060B91C8 00000018
            * BFA10014 7CDF3378
            * 7CBE2B78 7C7D1B78
            * 2D05FFFF 418A0014
            * 006B929C 00000027
            * 066B99D8 00000027
            * 00010203 04050709
            * 080A0B0C 0D0E0F10
            * 11141516 1A191217
            * 0618131D 1E1B1C1F
            * 20212223 24252600
            * 006B92A4 00000027
            * 066B9A58 00000027
            * 27282A2B 2C2D2E2F
            * 30313233 34353637
            * 38393A3B 3C3D3E3F
            * 40414243 44454647
            * 48494A4B 4C4D4E00
            * 06407AAC 0000009E
            * 01010202 03030404
            * 05050606 07070808
            * 0909330A 0B0B0C0C
            * 0D0D0E0E 130F1410
            * 15111612 17131814
            * 19151C16 1D171E18
            * 1F19201A 211B221C
            * 231D241E 251F2932
            * 2A332B34 2C352D36
            * 2F373038 3139323A
            * 2E3BFFFF 40204121
            * 42224323 44244525
            * 46264727 48284929
            * 4A2A4B2B 4C2C4D2D
            * 4E2E4F2F 50305131
            * 523D533E 543F5540
            * 56415742 58435944
            * 5A455B46 5C475D48
            * 5E495F4A 604B614C
            * 624D634E 644F0000";
            DefaultSSS = new CustomSSSCodeset(s.Split('\n'));
            #endregion

            _iconNum = -1;
            fileSizeBar.Style = ProgressBarStyle.Continuous;

            foreach (Control child in flowLayoutPanel1.Controls) {
                if (child is ImagePreviewPanel) {
                    (child as ImagePreviewPanel).DragEnter += panel1_DragEnter;
                    (child as ImagePreviewPanel).DragDrop += panel1_DragDrop;
                }
            }

            //UpdateDirectory();
        }
 public void LoadCustomSSS(string file)
 {
     if (File.Exists(file)) {
         ManualSSS = new CustomSSSCodeset(file);
         MessageBox.Show("You will need to quit and restart this program if you want to go back to loading the GCT codeset automatically.");
     }
 }
Exemple #14
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
                    };
                })
            }));
        }