Esempio n. 1
0
        public static ResourceNode FindNode(ResourceNode root, string path, bool searchChildren)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(root);
            }

            if (root.Name.Equals(path, StringComparison.OrdinalIgnoreCase))
            {
                return(root);
            }

            if ((path.Contains("/")) && (path.Substring(0, path.IndexOf('/')).Equals(root.Name, StringComparison.OrdinalIgnoreCase)))
            {
                return(root.FindChild(path.Substring(path.IndexOf('/') + 1), searchChildren));
            }

            return(root.FindChild(path, searchChildren));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        private unsafe void Load(int index, int program)
        {
            if (TKContext.CurrentContext == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program);

            Bitmap bmp = null;

            if (_folderWatcher.EnableRaisingEvents && !String.IsNullOrEmpty(_folderWatcher.Path))
            {
                bmp = SearchDirectory(_folderWatcher.Path + Name);
            }

            if (bmp == null && TKContext.CurrentContext._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = TKContext.CurrentContext._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);
                TEX0Node            tNode    = null;

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        Texture.Attach(tNode, _palette);
                        return;
                    }
                    else //Then search the directory
                    {
                        bmp = SearchDirectory(node._origPath);
                    }

                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();
            }

            if (bmp != null)
            {
                Texture.Attach(bmp);
            }
            else
            {
                Texture.Default();
            }
        }
 public override ResourceNode MainTEX0For(ResourceNode brres, int charNum, int costumeNum)
 {
     string path = "Textures(NW4R)/MenSelchrFaceB." + (charNum * 10 + costumeNum + 1).ToString("D3");
     return brres.FindChild(path, false);
 }
Esempio n. 5
0
        /// <summary>
        /// This function finds the new info.pac. It should be called whenever you change the working directory.
        /// It also clears the list of edited ("dirty") strings, and records the current names (for the "restore" button).
        /// </summary>
        public String findInfoFile()
        {
            _index = -1;

            info = info_training = null;
            _currentFile = _currentTrainingFile = null;

            string tempfile = Path.GetTempFileName();
            if (new FileInfo("MiscData[140].msbin").Exists) {
                _currentFile = "MiscData[140].msbin";
                File.Copy("MiscData[140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return "Loaded .\\MiscData[140].msbin";
            } else if (new FileInfo("\\MiscData[140].msbin").Exists) {
                _currentFile = "\\MiscData[140].msbin";
                File.Copy("\\MiscData[140].msbin", tempfile, true);
                info = NodeFactory.FromFile(null, tempfile) as MSBinNode;
                return "Loaded \\MiscData[140].msbin";
            } else {
                string[] infopaths = { "..\\..\\info2\\info.pac", "..\\..\\info2\\info_en.pac", "..\\info.pac" };

                foreach (string relativepath in infopaths) {
                    if (info == null) {
                        string s = Path.GetFullPath(relativepath);
                        if (new FileInfo(s).Exists) {
                            _currentFile = s;
                            File.Copy(s, tempfile, true);
                            info_pac = NodeFactory.FromFile(null, tempfile);
                            info = (MSBinNode)info_pac.FindChild("MiscData[140]", true);
                        }
                    }
                }

                if (info == null) {
                    return "No song list loaded";
                } else {
                    modifiedStringIndices.Clear();
                    copyIntoFileStrings();

                    // info found; try info_training in same directory
                    string trainingpath = _currentFile.Replace("info.pac", "info_training.pac").Replace("info_en.pac", "info_training_en.pac");
                    if (trainingpath != _currentFile && new FileInfo(trainingpath).Exists) {
                        _currentTrainingFile = trainingpath;
                        string tempfile_training = Path.GetTempFileName();
                        File.Copy(trainingpath, tempfile_training, true);
                        info_training_pac = NodeFactory.FromFile(null, tempfile_training);
                        info_training = (MSBinNode)info_training_pac.FindChild("MiscData[140]", true);
                        return "Loaded info.pac and info_training.pac";
                    } else {
                        return "Loaded info.pac";
                    }
                }
            }
        }
Esempio n. 6
0
        private unsafe void Load(int index, int program, PLT0Node palette)
        {
            if (_context == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture(_context, 0, 0);
            Texture.Bind(index, program);

            //ctx._states[String.Format("{0}_TexRef", Name)] = Texture;

            Bitmap   bmp   = null;
            TEX0Node tNode = null;

            if (_context._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = _context._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        if (palette != null)
                        {
                            bmp = tNode.GetImage(0, palette);
                        }
                        else
                        {
                            bmp = tNode.GetImage(0);
                        }
                    }
                    else
                    {
                        //Then search node directory
                        string path = node._origPath;
                        if (path != null)
                        {
                            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                            foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                            {
                                if (file.Name.EndsWith(".tga"))
                                {
                                    Source = file.FullName;
                                    bmp    = TGA.FromFile(file.FullName);
                                    break;
                                }
                                else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif"))
                                {
                                    Source = file.FullName;
                                    bmp    = (Bitmap)Bitmap.FromFile(file.FullName);
                                    break;
                                }
                            }
                        }
                    }
                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();

                if (bmp != null)
                {
                    int w = bmp.Width, h = bmp.Height, size = w * h;

                    Texture._width  = w;
                    Texture._height = h;
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MagFilter, (int)GLTextureFilter.LINEAR);
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MinFilter, (int)GLTextureFilter.NEAREST_MIPMAP_LINEAR);
                    //_context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.BaseLevel, 0);

                    //if (tNode != null)
                    //    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, tNode.LevelOfDetail);
                    //else
                    //    _context.glTexParameter(GLTextureTarget.Texture2D, GLTextureParameter.MaxLevel, 0);

                    BitmapData data = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    try
                    {
                        using (UnsafeBuffer buffer = new UnsafeBuffer(size << 2))
                        {
                            ARGBPixel *sPtr = (ARGBPixel *)data.Scan0;
                            ABGRPixel *dPtr = (ABGRPixel *)buffer.Address;

                            for (int i = 0; i < size; i++)
                            {
                                *dPtr++ = (ABGRPixel)(*sPtr++);
                            }

                            int res = _context.gluBuild2DMipmaps(GLTextureTarget.Texture2D, GLInternalPixelFormat._4, w, h, GLPixelDataFormat.RGBA, GLPixelDataType.UNSIGNED_BYTE, buffer.Address);
                            if (res != 0)
                            {
                            }
                        }
                    }
                    finally
                    {
                        bmp.UnlockBits(data);
                        bmp.Dispose();
                    }
                }
            }
        }
 public override void UpdateDirectory()
 {
     if (File.Exists("../menu2/sc_selcharacter.pac")) {
         string path = "../menu2/sc_selcharacter.pac";
         common5 = null;
         sc_selcharacter = NodeFactory.FromFile(null, path);
         _openFilePath = path;
     } else if (File.Exists("../menu2/sc_selcharacter_en.pac")) {
         string path = "../menu2/sc_selcharacter_en.pac";
         common5 = null;
         sc_selcharacter = NodeFactory.FromFile(null, path);
         _openFilePath = path;
     } else if (File.Exists("../system/common5.pac")) {
         string path = "../system/common5.pac";
         common5 = NodeFactory.FromFile(null, path);
         sc_selcharacter = common5.FindChild("sc_selcharacter_en", false);
         _openFilePath = path;
     } else if (File.Exists("../system/common5_en.pac")) {
         string path = "../system/common5_en.pac";
         common5 = NodeFactory.FromFile(null, path);
         sc_selcharacter = common5.FindChild("sc_selcharacter_en", false);
         _openFilePath = path;
     } else {
         common5 = null;
         sc_selcharacter = null;
     }
     label1.Text = sc_selcharacter != null ? Path.GetFileName(_openFilePath) : "Could not load common5 or sc_selcharacter.";
 }
 public override ResourceNode MainTEX0For(ResourceNode node, int charNum, int costumeNum)
 {
     return node.FindChild("Textures(NW4R)", false).Children[0];
 }
        public static ResourceNode FindNode(ResourceNode root, string path, bool searchChildren)
        {
            if (String.IsNullOrEmpty(path))
                return root;

            if (root.Name.Equals(path, StringComparison.OrdinalIgnoreCase))
                return root;

            if ((path.Contains("/")) && (path.Substring(0, path.IndexOf('/')).Equals(root.Name, StringComparison.OrdinalIgnoreCase)))
                return root.FindChild(path.Substring(path.IndexOf('/') + 1), searchChildren);

            return root.FindChild(path, searchChildren);
        }
Esempio n. 10
0
        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;
            }
        }
Esempio n. 11
0
        private unsafe void Load(int index, int program, PLT0Node palette)
        {
            if (_context == null)
            {
                return;
            }

            Source = null;

            if (Texture != null)
            {
                Texture.Delete();
            }
            Texture = new GLTexture();
            Texture.Bind(index, program, _context);

            //ctx._states[String.Format("{0}_TexRef", Name)] = Texture;

            Bitmap   bmp   = null;
            TEX0Node tNode = null;

            if (_context._states.ContainsKey("_Node_Refs"))
            {
                List <ResourceNode> nodes    = _context._states["_Node_Refs"] as List <ResourceNode>;
                List <ResourceNode> searched = new List <ResourceNode>(nodes.Count);

                foreach (ResourceNode n in nodes)
                {
                    ResourceNode node = n.RootNode;
                    if (searched.Contains(node))
                    {
                        continue;
                    }
                    searched.Add(node);

                    //Search node itself first
                    if ((tNode = node.FindChild("Textures(NW4R)/" + Name, true) as TEX0Node) != null)
                    {
                        Source = tNode;
                        if (palette != null)
                        {
                            Texture.Attach(tNode, palette);
                        }
                        else
                        {
                            Texture.Attach(tNode);
                        }
                        return;
                    }
                    else
                    {
                        //Then search node directory
                        string path = node._origPath;
                        if (path != null)
                        {
                            DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(path));
                            if (dir.Exists && Name != "<null>")
                            {
                                foreach (FileInfo file in dir.GetFiles(Name + ".*"))
                                {
                                    if (file.Name.EndsWith(".tga"))
                                    {
                                        Source = file.FullName;
                                        bmp    = TGA.FromFile(file.FullName);
                                        break;
                                    }
                                    else if (file.Name.EndsWith(".png") || file.Name.EndsWith(".tiff") || file.Name.EndsWith(".tif"))
                                    {
                                        Source = file.FullName;
                                        bmp    = (Bitmap)Bitmap.FromFile(file.FullName);
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (bmp != null)
                    {
                        break;
                    }
                }
                searched.Clear();

                if (bmp != null)
                {
                    Texture.Attach(bmp);
                }
            }
        }
Esempio n. 12
0
 private static ResourceNode FindStageARC(ResourceNode node)
 {
     foreach (ResourceNode child in node.Children) {
         foreach (ResourceNode child2 in child.Children) {
             if (child2.GetType() == typeof(CollisionNode)) {
                 return child;
             }
         }
     }
     // fallback
     return node.FindChild("2", false);
 }