private void AddNewTEX0(object sender, string filename)
        {
            BRRESNode md80 = sc_selmap.FindChild("MiscData[80]", false) as BRRESNode;
            string    dir  = Path.Combine(Path.GetTempPath(), "BrawlStageManager-newimage-" + Guid.NewGuid());

            Directory.CreateDirectory(dir);
            string temp = Path.Combine(dir, GetTexInfoFor(sender).pat0.Texture + Path.GetExtension(filename));

            File.Copy(filename, temp);
            using (TextureConverterDialog dlg = new TextureConverterDialog()) {
                dlg.ImageSource   = temp;
                dlg.InitialFormat =
                    sender == prevbase ? WiiPixelFormat.CMPR
                                        : sender == frontstname ? WiiPixelFormat.I4
                                        : sender == icon ? WiiPixelFormat.CI8
                                        : sender == seriesicon ? WiiPixelFormat.I4
                                        : sender == selmap_mark ? WiiPixelFormat.IA4
                                        : (WiiPixelFormat?)null;
                dlg.InitialSize =
                    sender == prevbase ? prevbaseResizeTo
                                        : sender == frontstname ? frontstnameResizeTo
                                        : sender == selmap_mark ? selmapMarkResizeTo
                                        : null;
                dlg.FormBorderStyle = FormBorderStyle.FixedSingle;
                dlg.ShowInTaskbar   = true;
                if (dlg.ShowDialog(null, md80) == DialogResult.OK)
                {
                    md80.IsDirty = true;                     // do this to be safe
                    UpdateImage();
                }
            }
            Directory.Delete(dir, true);
        }
        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();
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        public void CreateVIS0()
        {
            if (!(_targetModel is MDL0Node))
            {
                return;
            }

            BRRESNode     group = null;
            BRESEntryNode n     = null;

            if ((n = TargetAnimation as BRESEntryNode) != null &&
                (group = n.Parent.Parent as BRRESNode) != null)
            {
                _vis0 = group.CreateResource <VIS0Node>(SelectedCHR0.Name);
                foreach (string s in VIS0Indices.Keys)
                {
                    VIS0EntryNode node = null;
                    if ((node = (VIS0EntryNode)_vis0.FindChild(s, true)) == null && ((MDL0BoneNode)((ResourceNode)_targetModel).FindChildByType(s, true, ResourceType.MDL0Bone)).BoneIndex != 0 && s != "EyeYellowM")
                    {
                        node      = _vis0.CreateEntry();
                        node.Name = s;
                        node.MakeConstant(true);
                    }
                }
            }
        }
Beispiel #5
0
        public BRRESNode NewBrres()
        {
            BRRESNode   node = ((U8FolderNode)_resource).CreateResource <BRRESNode>("NewBrres");
            BaseWrapper res  = this.FindResource(node, true);

            res = res.FindResource(node, false);
            res.EnsureVisible();
            res.TreeView.SelectedNode = res;
            return(node);
        }
Beispiel #6
0
        public static void ColorSmashImport(BRRESNode b)
        {
            if (!CanRunColorSmash || b == null)
            {
                return;
            }

            using (NumericInputForm frm = new NumericInputForm())
            {
                if (Program.OpenFiles("Portable Network Graphics|*.png", out string[] fileNames) > 0 &&
 public void exportAll(string folder)
 {
     if (sc_selmap != null)
     {
         BRRESNode bres = sc_selmap.FindChild("MiscData[80]", false) as BRRESNode;
         if (bres != null)
         {
             bres.ExportToFolder(folder, ".png");
         }
     }
 }
Beispiel #8
0
        public void ImportBrres()
        {
            if (Program.OpenFile(FileFilters.BRES, out string path) > 0)
            {
                BRRESNode node = NodeFactory.FromFile(null, path) as BRRESNode;
                ((U8FolderNode)_resource).AddChild(node);

                BaseWrapper w = FindResource(node, true);
                w.EnsureVisible();
                w.TreeView.SelectedNode = w;
            }
        }
Beispiel #9
0
        public BRRESNode NewBRES()
        {
            BRRESNode node = new BRRESNode {
                FileType = ARCFileType.MiscData
            };

            _resource.AddChild(node);

            BaseWrapper w = FindResource(node, false);

            w.EnsureVisible();
            w.TreeView.SelectedNode = w;
            return(node);
        }
Beispiel #10
0
        public override ResourceNode Duplicate()
        {
            if (_resource._parent == null)
            {
                return(null);
            }
            _resource.Rebuild();
            BRRESNode newNode = NodeFactory.FromAddress(null, _resource.WorkingUncompressed.Address, _resource.WorkingUncompressed.Length) as BRRESNode;

            _resource._parent.InsertChild(newNode, true, _resource.Index + 1);
            newNode.Populate();
            newNode.FileType      = ((BRRESNode)_resource).FileType;
            newNode.FileIndex     = ((BRRESNode)_resource).FileIndex;
            newNode.GroupID       = ((BRRESNode)_resource).GroupID;
            newNode.RedirectIndex = ((BRRESNode)_resource).RedirectIndex;
            newNode.Compression   = ((BRRESNode)_resource).Compression;
            newNode.Name          = _resource.Name;
            return(newNode);
        }
Beispiel #11
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();
            }
        }
        public bool AddMenSelmapMark(string path, bool ask)
        {
            string tmp = null;

            if (path.EndsWith(".tex0", StringComparison.InvariantCultureIgnoreCase))
            {
                tmp = TempFiles.Create(".png");
                NodeFactory.FromFile(null, path).Export(tmp);
            }
            Bitmap bitmap = new Bitmap(tmp ?? path);

            if (BitmapUtilities.HasSolidCorners(bitmap))
            {
                bitmap = BitmapUtilities.AlphaSwap(bitmap);
            }
            string name = Path.GetFileNameWithoutExtension(path);

            if (ask)
            {
                using (var nameDialog = new AskNameDialog(bitmap)) {
                    nameDialog.Text = name;
                    if (nameDialog.ShowDialog() != DialogResult.OK)
                    {
                        return(false);
                    }
                    else
                    {
                        name = nameDialog.NameText;
                    }
                }
            }
            BRRESNode bres = sc_selmap.FindChild("MiscData[80]", false) as BRRESNode;
            TEX0Node  tex0 = bres.CreateResource <TEX0Node>(name);

            ReplaceSelmapMark(bitmap, tex0, true);
            return(true);
        }
Beispiel #13
0
        public static void ColorSmashTex0(int paletteCount)
        {
            // If this was selected via keycode when it's invalid, return without error
            if (!CanRunColorSmash || MainForm.Instance.resourceTree.SelectedNodes.Count <= 1)
            {
                return;
            }

            // Clear the directories. If they aren't empty, the implementation WILL NOT work
            ClearDirectories();

            // Throw error if color smash directory isn't empty
            if (InputDir.GetFiles().Length > 0 || OutputDir.GetFiles().Length > 0)
            {
                MessageBox.Show(
                    "One or more files exist in the required Color Smash folder. Please delete these nodes manually and try again",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClearDirectories();
                return;
            }

            List <TEX0Node>          textureList = new List <TEX0Node>();
            Dictionary <int, string> names       = new Dictionary <int, string>();
            BRRESNode b = (((TEX0Wrapper)MainForm.Instance.resourceTree.SelectedNodes[0]).Resource as TEX0Node)?
                          .BRESNode;

            if (b == null)
            {
                MessageBox.Show(
                    "The BRRES could not be found. Color Smashing is only supported for TEX0 nodes in BRRES groups",
                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClearDirectories();
                return;
            }

            int  index          = int.MaxValue;
            bool detectPalettes = paletteCount <= 0;

            if (detectPalettes)
            {
                paletteCount = 0;
            }

            foreach (TreeNode n in MainForm.Instance.resourceTree.SelectedNodes)
            {
                // If this was selected via keycode when it's invalid, return without error
                if (!(n is TEX0Wrapper))
                {
                    ClearDirectories();
                    return;
                }

                if (((TEX0Wrapper)n).Resource is TEX0Node t)
                {
                    if (t.BRESNode != b)
                    {
                        MessageBox.Show("Color Smash is only supported for nodes in the same BRRES", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        ClearDirectories();
                        return;
                    }

                    textureList.Add(t);
                    int placement = t.Parent.Children.IndexOf(t);
                    names.Add(placement, t.Name);
                    if (placement < index)
                    {
                        index = placement;
                    }

                    t.Export($"{InputDir.FullName}\\{placement:D5}.png");

                    if (detectPalettes && paletteCount < 256)
                    {
                        if (!t.HasPalette || t.GetPaletteNode() == null)
                        {
                            paletteCount = 256;
                        }
                        else if (t.HasPalette && t.GetPaletteNode() != null &&
                                 t.GetPaletteNode().Palette.Entries.Length > paletteCount)
                        {
                            paletteCount = (short)Math.Min(t.GetPaletteNode().Palette.Entries.Length, 256);
                        }
                    }
                }
            }

            if (index == int.MaxValue)
            {
                MessageBox.Show("Could not properly get the index of the images", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                ClearDirectories();
                return;
            }

            if (detectPalettes && paletteCount == 0)
            {
                paletteCount = 256;
            }

            foreach (TEX0Node t in textureList)
            {
                t.Remove(true);
            }

            ColorSmasher(paletteCount, b, index, names);
        }
Beispiel #14
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();
     }
 }
Beispiel #15
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);
            }
        }
Beispiel #16
0
        public static void ColorSmashTex0(object sender, EventArgs e)
        {
            // If this was selected via keycode when it's invalid, return without error
            if (!CanRunColorSmash || MainForm.Instance.resourceTree.SelectedNodes.Count <= 1)
            {
                return;
            }

            DirectoryInfo inputDir  = Directory.CreateDirectory(Program.AppPath + "\\cs\\");
            DirectoryInfo outputDir = Directory.CreateDirectory(Program.AppPath + "\\cs\\out\\");

            try
            {
                // Clear the directories. If they aren't empty, the implementation WILL NOT work
                foreach (FileInfo f in outputDir.GetFiles())
                {
                    try
                    {
                        f.Delete();
                    }
                    catch
                    {
                        // ignored
                    }
                }

                foreach (FileInfo f in inputDir.GetFiles())
                {
                    try
                    {
                        f.Delete();
                    }
                    catch
                    {
                        // ignored
                    }
                }

                // Throw error if color smash directory isn't empty
                if (inputDir.GetFiles().Length > 0 || outputDir.GetFiles().Length > 0)
                {
                    MessageBox.Show(
                        "One or more files exist in the required Color Smash folder. Please delete these nodes manually and try again",
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                short                    paletteCount = 0;
                List <TEX0Node>          textureList  = new List <TEX0Node>();
                Dictionary <int, string> names        = new Dictionary <int, string>();
                BRRESNode                b            = (((TEX0Wrapper)MainForm.Instance.resourceTree.SelectedNodes[0]).Resource as TEX0Node)?
                                                        .BRESNode;
                if (b == null)
                {
                    MessageBox.Show(
                        "The BRRES could not be found. Color Smashing is only supported for TEX0 nodes in BRRES groups",
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int index = int.MaxValue;
                foreach (TreeNode n in MainForm.Instance.resourceTree.SelectedNodes)
                {
                    // If this was selected via keycode when it's invalid, return without error
                    if (!(n is TEX0Wrapper))
                    {
                        return;
                    }

                    if (((TEX0Wrapper)n).Resource is TEX0Node t)
                    {
                        if (t.BRESNode != b)
                        {
                            MessageBox.Show("Color Smash is only supported for nodes in the same BRRES", "Error",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        textureList.Add(t);
                        int placement = t.Parent.Children.IndexOf(t);
                        names.Add(placement, t.Name);
                        if (placement < index)
                        {
                            index = placement;
                        }

                        t.Export($"{inputDir.FullName}\\{placement:D5}.png");

                        if (paletteCount < 256)
                        {
                            if (!t.HasPalette || t.GetPaletteNode() == null)
                            {
                                paletteCount = 256;
                            }
                            else if (t.HasPalette && t.GetPaletteNode() != null &&
                                     t.GetPaletteNode().Palette.Entries.Length > paletteCount)
                            {
                                paletteCount = (short)Math.Min(t.GetPaletteNode().Palette.Entries.Length, 256);
                            }
                        }
                    }
                }

                if (index == int.MaxValue)
                {
                    MessageBox.Show("Could not properly get the index of the images", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (paletteCount == 0)
                {
                    paletteCount = 256;
                }

                foreach (TEX0Node t in textureList)
                {
                    if (t.HasPalette && t.GetPaletteNode() != null)
                    {
                        t.GetPaletteNode().Remove();
                    }

                    t.Remove();
                }

                Process cSmash = Process.Start(new ProcessStartInfo
                {
                    FileName    = Program.AppPath + "\\color_smash.exe",
                    WindowStyle = ProcessWindowStyle.Hidden,
                    Arguments   = $"-c RGB5A3 -n {paletteCount}"
                });
                cSmash?.WaitForExit();

                textureList = new List <TEX0Node>();
                int           count    = 0;
                BRESGroupNode texGroup = b.GetOrCreateFolder <TEX0Node>();
                foreach (FileInfo f in outputDir.GetFiles())
                {
                    FileInfo f2 = new FileInfo($"{inputDir.FullName}\\{f.Name}");
                    int      i  = int.Parse(f.Name.Substring(0, f.Name.IndexOf(".", StringComparison.Ordinal)));
                    using (TextureConverterDialog dlg = new TextureConverterDialog())
                    {
                        dlg.ImageSource = f.FullName;
                        dlg.ChkImportPalette.Checked = true;
                        dlg.Automatic      = true;
                        dlg.StartingFormat = WiiPixelFormat.CI8;

                        if (dlg.ShowDialog(MainForm.Instance, b) != DialogResult.OK)
                        {
                            continue;
                        }

                        TEX0Node t = dlg.TEX0TextureNode;
                        t.Name = names[i];
                        textureList.Add(t);
                        dlg.Dispose();
                        t.OriginalPath = "";
                        if (texGroup.Children.Count > count + 1)
                        {
                            texGroup.RemoveChild(t);
                            texGroup.InsertChild(t, false, index + count);
                        }
                        count++;
                    }

                    f2.Delete();
                }

                if (textureList.Count > 0)
                {
                    textureList.Remove(textureList.Last());
                    foreach (TEX0Node t in textureList)
                    {
                        t.SharesData = true;
                    }
                }

                if (inputDir.GetFiles().Length > 0)
                {
                    MessageBox.Show(
                        "One or more files threw an error. Please ensure all relevant textures can be Color Smashed together.",
                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    foreach (FileInfo f in inputDir.GetFiles())
                    {
                        int i = int.Parse(f.Name.Substring(0, f.Name.IndexOf(".", StringComparison.Ordinal)));
                        using (TextureConverterDialog dlg = new TextureConverterDialog())
                        {
                            dlg.ImageSource = f.FullName;
                            dlg.Automatic   = true;

                            if (dlg.ShowDialog(MainForm.Instance, b) != DialogResult.OK)
                            {
                                continue;
                            }

                            TEX0Node t = dlg.TEX0TextureNode;
                            t.Name = names[i];

                            dlg.Dispose();
                            t.OriginalPath = "";
                            if (texGroup.Children.Count > count + 1)
                            {
                                texGroup.RemoveChild(t);
                                texGroup.InsertChild(t, false, index + count);
                            }
                            count++;
                        }
                    }
                }
            }
            finally
            {
                foreach (FileInfo f in outputDir.GetFiles())
                {
                    try
                    {
                        f.Delete();
                    }
                    catch
                    {
                        // ignored
                    }
                }

                try
                {
                    outputDir.Delete();
                }
                catch
                {
                    // ignored
                }

                foreach (FileInfo f in inputDir.GetFiles())
                {
                    try
                    {
                        f.Delete();
                    }
                    catch
                    {
                        // ignored
                    }
                }

                try
                {
                    inputDir.Delete();
                }
                catch
                {
                    // ignored
                }
            }
        }