Exemplo n.º 1
0
        public override ResourceNode Duplicate()
        {
            PAT0EntryNode dup = ((PAT0Node)_resource.Parent).CreateEntry(_resource.Index + 1);

            dup.Name = _resource.Name;
            dup.RemoveChild(dup.Children[0]);

            foreach (PAT0TextureNode pt in _resource.Children)
            {
                PAT0TextureNode ptd = new PAT0TextureNode(pt._texFlags, pt.Index);
                dup.AddChild(ptd);
                ptd.Children.Clear();
                foreach (PAT0TextureEntryNode pte in pt.Children)
                {
                    ptd.AddChild(new PAT0TextureEntryNode());
                    if (ptd.Children.Last() is PAT0TextureEntryNode pted)
                    {
                        pted.FrameIndex = pte.FrameIndex;
                        pted.Texture    = pte.Texture;
                        pted.Palette    = pte.Palette;
                        pted.Name       = pte.Name;
                    }
                }
            }

            return(dup);
        }
Exemplo n.º 2
0
        public string MenSelmapMarkUsageReport()
        {
            Dictionary <string, int> dict = new Dictionary <string, int>();
            string pathToPAT0TextureNode  = "MiscData[80]/AnmTexPat(NW4R)/MenSelmapPreview/pasted__stnamelogoM";
            var    look = sc_selmap.FindChild(pathToPAT0TextureNode, false).Children[0];

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

            string        pathToTextures = "MiscData[80]/Textures(NW4R)";
            ResourceNode  textures       = sc_selmap.FindChild(pathToTextures, false);
            List <string> marks          = (from c in textures.Children
                                            where c.Name.Contains("MenSelmapMark")
                                            select c.Name).ToList();

            var q = from c in
                    (from c in tn.Children
                     where c is PAT0TextureEntryNode
                     select(PAT0TextureEntryNode) c)
                    where marks.Contains(c.Texture)
                    group c by c.Texture into g
                    let count = g.Count()
                                let stageID                     = BestSSS.StageForIcon((int)g.First().FrameIndex)
                                                        let one = StageIDMap.PacBasenameForStageID(stageID)
                                                                  orderby count, g.Key
                select new { count, g.Key, one };
            StringBuilder sb = new StringBuilder();

            foreach (var line in q)
            {
                sb.AppendLine(line.Key + ": " +
                              (line.count == 1 ? line.one : line.count.ToString()));
                marks.Remove(line.Key);
            }

            foreach (var name in marks)
            {
                sb.AppendLine(name + ": NOT USED");
            }
            return(sb.ToString());
        }
Exemplo n.º 3
0
        public override ResourceNode Duplicate()
        {
            PAT0TextureNode ptd = new PAT0TextureNode(((PAT0TextureNode)_resource)._texFlags,
                                                      ((PAT0TextureNode)_resource).Index + 1);

            _resource.Parent.AddChild(ptd);
            ptd.Children.Clear();
            foreach (PAT0TextureEntryNode pte in _resource.Children)
            {
                ptd.AddChild(new PAT0TextureEntryNode());
                if (ptd.Children.Last() is PAT0TextureEntryNode pted)
                {
                    pted.FrameIndex = pte.FrameIndex;
                    pted.Texture    = pte.Texture;
                    pted.Palette    = pte.Palette;
                    pted.Name       = pte.Name;
                }
            }

            return(ptd);
        }
Exemplo n.º 4
0
        public void NewEntry()
        {
            PAT0TextureNode n = (PAT0TextureNode)_resource;

            n.CreateEntry();
        }
Exemplo n.º 5
0
        /// <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;
                    }
                }
            }
        }
Exemplo n.º 6
0
        public PAT0Node GeneratePAT0(bool force)
        {
            if (Parent == null)
            {
                return(null);
            }

            if (_resource.Parent is BRESGroupNode && _resource.Parent.Parent != null &&
                _resource.Parent.Parent is BRRESNode)
            {
                // Check if this is part of a sequence
                if (Regex.Match(_resource.Name, @"(\.\d+)?$").Success&& _resource.Name.LastIndexOf(".") > 0 &&
                    _resource.Name.LastIndexOf(".") <= _resource.Name.Length && int.TryParse(
                        _resource.Name.Substring(_resource.Name.LastIndexOf(".") + 1,
                                                 _resource.Name.Length - (_resource.Name.LastIndexOf(".") + 1)), out int n))
                {
                    //Console.WriteLine(_resource.Name.Substring(0, _resource.Name.LastIndexOf(".")) + " is part of a sequence");
                    //Console.WriteLine(_resource.Name.Substring(_resource.Name.LastIndexOf(".") + 1, _resource.Name.Length - (_resource.Name.LastIndexOf(".") + 1)));
                    // Determine the name to match
                    string          matchName    = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")) + ".";
                    BRESGroupNode   paletteGroup = ((BRRESNode)_resource.Parent.Parent).GetFolder <PLT0Node>();
                    List <string>   textureList  = new List <string>();
                    List <PLT0Node> paletteList  = new List <PLT0Node>();
                    int             highestNum   = -1;
                    bool            isStock      = false;
                    bool            isStockEx    = false;
                    if (matchName.Equals("InfStc.", StringComparison.OrdinalIgnoreCase))
                    {
                        isStock = true;
                        if (_resource.Name.Length >= 11)
                        {
                            isStockEx = true;
                        }
                    }

                    foreach (TEX0Node tx0 in _resource.Parent.Children)
                    {
                        if (tx0.Name.StartsWith(matchName) && tx0.Name.LastIndexOf(".") > 0 &&
                            tx0.Name.LastIndexOf(".") <= tx0.Name.Length &&
                            int.TryParse(
                                tx0.Name.Substring(tx0.Name.LastIndexOf(".") + 1,
                                                   tx0.Name.Length - (tx0.Name.LastIndexOf(".") + 1)), out int n2) && n2 >= 0 &&
                            !textureList.Contains(tx0.Name))
                        {
                            if (isStock)
                            {
                                if (isStockEx && tx0.Name.Length < 11)
                                {
                                    continue;
                                }
                            }

                            // Add the matching texture to the texture list for the PAT0
                            textureList.Add(tx0.Name);
                            // Determine the highest number used
                            if (n2 > highestNum)
                            {
                                highestNum = n2;
                            }

                            Console.WriteLine(tx0.Name);
                            Console.WriteLine(tx0.HasPalette);
                            if (tx0.HasPalette)
                            {
                                paletteList.Add(tx0.GetPaletteNode());
                            }
                            else
                            {
                                paletteList.Add(null);
                            }
                        }
                    }

                    if (textureList.Count <= 0)
                    {
                        return(null);
                    }

                    PAT0Node newPat0 = new PAT0Node
                    {
                        Name = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")).Equals("InfStc")
                            ? "InfStockface_TopN__0"
                            : _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")),
                        _numFrames = highestNum + 1
                    };
                    PAT0EntryNode pat0Entry = new PAT0EntryNode();
                    newPat0.AddChild(pat0Entry);
                    pat0Entry.Name = _resource.Name.Substring(0, _resource.Name.LastIndexOf(".")).Equals("InfStc")
                        ? "lambert87"
                        : _resource.Name.Substring(0, _resource.Name.LastIndexOf("."));
                    PAT0TextureNode pat0Tex = new PAT0TextureNode((PAT0Flags)7, 0);
                    pat0Entry.AddChild(pat0Tex);
                    if (((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>() != null &&
                        ((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>().FindChildrenByName(newPat0.Name)
                        .Length > 0)
                    {
                        if (force)
                        {
                            while (((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                   .FindChildrenByName(newPat0.Name).Length > 0)
                            {
                                ((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                .FindChildrenByName(newPat0.Name)[0].Remove();
                            }
                        }
                        else
                        {
                            DialogResult d = MessageBox.Show(
                                "Would you like to replace the currently existing \"" + newPat0.Name +
                                "\" PAT0 animation?", "PAT0 Generator", MessageBoxButtons.YesNoCancel);
                            if (d == DialogResult.Cancel || d == DialogResult.Abort)
                            {
                                return(null);
                            }

                            if (d == DialogResult.Yes)
                            {
                                while (((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                       .FindChildrenByName(newPat0.Name).Length >
                                       0)
                                {
                                    ((BRRESNode)_resource.Parent.Parent).GetFolder <PAT0Node>()
                                    .FindChildrenByName(newPat0.Name)[0].Remove();
                                }
                            }
                        }
                    }

                    if (isStock && !isStockEx && !textureList.Contains("InfStc.000"))
                    {
                        textureList.Add("InfStc.000");
                        paletteList.Add(null);
                    }
                    else if (isStock && isStockEx && !textureList.Contains("InfStc.0000"))
                    {
                        textureList.Add("InfStc.0000");
                        paletteList.Add(null);
                    }

                    //foreach(string s in textureList)
                    for (int i = 0; i < textureList.Count; ++i)
                    {
                        string s = textureList[i];
                        if (float.TryParse(s.Substring(s.LastIndexOf(".") + 1, s.Length - (s.LastIndexOf(".") + 1)),
                                           out float fr))
                        {
                            PAT0TextureEntryNode pat0texEntry = new PAT0TextureEntryNode();
                            pat0Tex.AddChild(pat0texEntry);
                            pat0texEntry.Name   = s;
                            pat0texEntry._frame = fr;
                            if (paletteList[i] != null)
                            {
                                pat0Tex.HasPalette = true;
                                pat0texEntry._plt  = paletteList[i].Name;
                            }
                            else if ((s == "InfStc.000" || s == "InfStc.0000") && pat0Tex.HasPalette)
                            {
                                pat0texEntry._plt = s;
                            }

                            if (fr == 0)
                            {
                                PAT0TextureEntryNode pat0texEntryFinal = new PAT0TextureEntryNode();
                                pat0Tex.AddChild(pat0texEntryFinal);
                                pat0texEntryFinal.Name   = s;
                                pat0texEntryFinal._frame = highestNum + 1;
                                if (paletteList[i] != null)
                                {
                                    pat0Tex.HasPalette        = true;
                                    pat0texEntryFinal.Palette = paletteList[i].Name;
                                }
                                else if ((s == "InfStc.000" || s == "InfStc.0000") && pat0Tex.HasPalette)
                                {
                                    pat0texEntryFinal._plt = s;
                                }
                            }
                        }

                        //newPat0.AddChild
                    }

                    pat0Tex._children = pat0Tex._children.OrderBy(o => ((PAT0TextureEntryNode)o)._frame).ToList();
                    if (isStock && !isStockEx && newPat0.FrameCount < 501)
                    {
                        newPat0.FrameCount = 501;
                    }
                    else if (isStockEx && newPat0.FrameCount < 9201)
                    {
                        newPat0.FrameCount = 9201;
                    }

                    ((BRRESNode)_resource.Parent.Parent).GetOrCreateFolder <PAT0Node>().AddChild(newPat0);
                    if (!force)
                    {
                        MainForm.Instance.TargetResource(newPat0);
                    }

                    return(newPat0);
                }
                else
                {
                    PAT0Node newPat0 = new PAT0Node
                    {
                        Name       = _resource.Name,
                        _numFrames = 1
                    };
                    PAT0EntryNode pat0Entry = new PAT0EntryNode();
                    newPat0.AddChild(pat0Entry);
                    pat0Entry.Name = _resource.Name;
                    PAT0TextureNode pat0Tex = new PAT0TextureNode((PAT0Flags)7, 0);
                    pat0Entry.AddChild(pat0Tex);
                    PAT0TextureEntryNode pat0texEntry = new PAT0TextureEntryNode();
                    pat0Tex.AddChild(pat0texEntry);
                    pat0texEntry.Name   = _resource.Name;
                    pat0texEntry._frame = 0;
                    if (((TEX0Node)_resource).HasPalette)
                    {
                        pat0Tex.HasPalette   = true;
                        pat0texEntry.Palette = ((TEX0Node)_resource).GetPaletteNode().Name;
                    }

                    ((BRRESNode)_resource.Parent.Parent).GetOrCreateFolder <PAT0Node>().AddChild(newPat0);
                    MainForm.Instance.TargetResource(newPat0);
                    return(newPat0);
                }
            }

            return(null);
        }