public void Restore() { TEX0Node tNode = Node as TEX0Node; PLT0Node pNode = tNode.GetPaletteNode(); if ((tNode.IsDirty) || (tNode.IsBranch)) { if (pNode != null) { pNode.Restore(); } tNode.Restore(); } else { ResourceTree t = Tree; if (t.IsWorkingCopy) { string path = Program.GetFilePath(_relativePath, false); using (ResourceNode oldNode = NodeFactory.FromFile(null, path)) { ResourceNode origNode = oldNode.FindChild(_nodePath, false); if (pNode != null) { ResourceNode origp = ((TEX0Node)origNode).GetPaletteNode(); pNode.ReplaceRaw(origp.WorkingUncompressed.Address, origp.WorkingUncompressed.Length); } tNode.ReplaceRaw(origNode.WorkingUncompressed.Address, origNode.WorkingUncompressed.Length); } } } }
public static void Replace(this TEX0Node tex0, Bitmap bmp, int paletteSize) { FileMap tMap, pMap; if (tex0.HasPalette) { PLT0Node pn = tex0.GetPaletteNode(); tMap = TextureConverter.Get(tex0.Format).EncodeTextureIndexed(bmp, tex0.LevelOfDetail, paletteSize, pn.Format, QuantizationAlgorithm.MedianCut, out pMap); pn.ReplaceRaw(pMap); } else { tMap = TextureConverter.Get(tex0.Format).EncodeTEX0Texture(bmp, tex0.LevelOfDetail); } tex0.ReplaceRaw(tMap); }
/// <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; } } } }
private void btnOkay_Click(object sender, EventArgs e) { TextureConverter format = TextureConverter.Get((WiiPixelFormat)cboFormat.SelectedItem); if (format.IsIndexed) { _textureData = format.EncodeTextureIndexed(_indexed, (int)numLOD.Value, (WiiPaletteFormat)cboPaletteFormat.SelectedItem, out _paletteData); } else { if ((format.RawFormat == WiiPixelFormat.CMPR) && (_cmprBuffer != null)) { _textureData = ((CMPR)format).EncodeTextureCached(_source, (int)numLOD.Value, _cmprBuffer); } else { _textureData = format.EncodeTexture(_source, (int)numLOD.Value); } } if (_parent != null) { _original = _parent.CreateResource <TEX0Node>(Path.GetFileNameWithoutExtension(_imageSource)); if (_paletteData != null) { _originalPalette = _parent.CreateResource <PLT0Node>(_original.Name); _originalPalette.Name = _original.Name; _originalPalette.ReplaceRaw(_paletteData); } _original.ReplaceRaw(_textureData); } else if (_original != null) { if (_originalPalette != null) { if (_paletteData != null) { _originalPalette.ReplaceRaw(_paletteData); } else { _originalPalette.Remove(); _originalPalette.Dispose(); } } else if (_paletteData != null) { if ((_original.Parent == null) || (_original.Parent.Parent == null)) { _paletteData.Dispose(); _paletteData = null; } else { _parent = _original.Parent.Parent as BRESNode; _originalPalette = _parent.CreateResource <PLT0Node>(_original.Name); _originalPalette.Name = _original.Name; _originalPalette.ReplaceRaw(_paletteData); } } _original.ReplaceRaw(_textureData); } DialogResult = DialogResult.OK; Close(); }