示例#1
0
        private void populate(out Texture tex, string path)
        {
            tex = new Texture()
            {
                tex0 = null,
                ForThisFrameIndex = false,
                pat0 = null,
            };
            if (iconNum == 255)
            {
                return;
            }

            if (PAT0Folder == null)
            {
                return;
            }

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

            if (query.Any())
            {
                PAT0TextureEntryNode first = query.First();
                tex.tex0 = TEX0Folder.FindChild(first.Name, false) as TEX0Node;
                tex.ForThisFrameIndex = first.FrameIndex == iconNum;
                tex.pat0 = tex.ForThisFrameIndex ? first : null;
            }
        }
示例#2
0
        internal unsafe void TexChanged(object sender, EventArgs e)
        {
            MDL0MaterialRefNode mr = TargetTexRef;
            PAT0TextureNode     node;

            if (mr == null || _updating)
            {
                return;
            }

            if (SelectedAnimation != null && CurrentFrame > 0)
            {
                node = SelectedAnimation.FindChild(mr._parent.Name + "/Texture" + mr.Index, true) as PAT0TextureNode;

                if (node != null)
                {
                    PAT0TextureEntryNode tex = node.GetEntry(CurrentFrame - 1);
                    if (tex == null)
                    {
                        if (!String.IsNullOrEmpty(texBox.Text) || !String.IsNullOrEmpty(pltBox.Text))
                        {
                            tex        = new PAT0TextureEntryNode();
                            tex._frame = CurrentFrame - 1;
                            if (node.Children.Count > 0)
                            {
                                node.InsertChild(tex, true, node.GetPrevious(CurrentFrame - 1).Index + 1);
                            }
                            else
                            {
                                node.AddChild(tex, true);
                            }
                            tex.Texture = texBox.Text;
                            tex.Palette = pltBox.Text;
                        }
                    }
                    else
                    {
                        if (!String.IsNullOrEmpty(texBox.Text) || !String.IsNullOrEmpty(pltBox.Text))
                        {
                            tex.Texture = texBox.Text;
                            tex.Palette = pltBox.Text;
                        }
                        else
                        {
                            tex.Remove();
                        }
                    }
                }
            }

            TargetModel.ApplyPAT(SelectedAnimation, CurrentFrame);
            ResetTexture();
            ResetPalette();
            _mainWindow.ModelPanel.Invalidate();
        }
示例#3
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;
                    }
                }
            }
        }
示例#4
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);
        }