Exemple #1
0
        public PackFile(Stream fileToLoad)
        {
            BinaryReader fileLoader = new BinaryReader(fileToLoad);

            fileToLoad.Seek(0x400, SeekOrigin.Begin);
            int fileCount = fileLoader.ReadInt32();

            int[] fileLocs  = new int[fileCount];
            int[] fileSizes = new int[fileCount];

            fileToLoad.Seek(0, SeekOrigin.Begin);
            for (int i = 0; i < fileCount; i++)
            {
                fileLocs[i] = fileLoader.ReadInt32();
            }

            fileToLoad.Seek(0x200, SeekOrigin.Begin);
            for (int i = 0; i < fileCount; i++)
            {
                fileSizes[i] = fileLoader.ReadInt32();
            }

            fileToLoad.Seek(0x404, SeekOrigin.Begin);
            for (int i = 0; i < fileCount; i++)
            {
                if (fileSizes[i] > 0)
                {
                    byte[]       currentFile = fileLoader.ReadBytes(fileSizes[i]);
                    MemoryStream nblStream   = new MemoryStream(currentFile);
                    RawFile      raw         = new RawFile();
                    raw.fileContents = currentFile;
                    raw.filename     = i > 0 ? "nbl" + i.ToString("d4") + ".nbl" : "table.nbl";
                    NblLoader currentNbl = new NblLoader(nblStream);
                    containedFiles.Add(i, currentNbl);
                    containedRawFiles.Add(i, raw);
                    filenames.Add(raw.filename);
                    nblStream.Close();
                }
            }
        }
Exemple #2
0
        public static bool parseScripts = true; //Because you don't always want to parse script files.

        public static PsuFile FromRaw(string filename, byte[] rawData, byte[] inHeader, int[] ptrs, int baseAddr, bool bigEndian = false)
        {
            if (filename.EndsWith("xvr"))
            {
                return(new XvrTextureFile(inHeader, rawData, filename));
            }
            else if (filename.EndsWith(".uvr"))
            {
                return(new UvrTextureFile(inHeader, rawData, filename));
            }
            else if (filename.EndsWith(".gim") && GimSharp.GimTexture.Is(rawData))
            {
                return(new GimTextureFile(inHeader, rawData, filename));
            }
            else if (filename.Contains("Weapon.bin") || filename.Contains("General.bin") || filename.Contains("Other.bin"))
            {
                return(new Psp2TextFile(filename, rawData));
            }
            else if (filename.Equals("itemObjectDrop.xnr"))
            {
                return(new ObjectDropFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Equals("filelist.rel"))
            {
                return(new QuestListFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.EndsWith("filelist.rel"))
            {
                return(new ListFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Equals("itemEnemyDrop.xnr"))
            {
                return(new EnemyDropFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.StartsWith("set_r") && filename.EndsWith(".rel"))
            {
                return(new SetFile(filename, rawData, inHeader, ptrs, baseAddr, bigEndian));
            }
            else if (filename.EndsWith(".xnt"))
            {
                return(new XntFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (parseScripts && (filename.Contains("script.bin") || filename.Contains("Tutor.bin")))
            {
                return(new ScriptFile(filename, rawData, bigEndian));
            }
            else if ((filename.EndsWith(".k") || filename.Contains(".bin")) && BitConverter.ToInt32(rawData, 0) == rawData.Length && new string(ASCIIEncoding.ASCII.GetChars(rawData, 0, 4)) != "RIPC")
            {
                return(new TextFile(filename, rawData));
            }
            else if (filename.Contains("item00ValueData"))
            {
                return(new ItemPriceFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemTechParam") && !filename.Contains("EnemyB"))
            {
                return(new ItemTechParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemBulletParam") && !filename.Contains("MagAt"))
            {
                return(new ItemBulletParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.StartsWith("Think") && filename.EndsWith("Dragon.xnr"))
            {
                return(new ThinkDragonFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemSkillParam"))
            {
                return(new ItemSkillParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemLineUnitParam"))
            {
                return(new ItemUnitParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains(".nbl") || ASCIIEncoding.ASCII.GetString(rawData, 0, 4) == "NMLL")
            {
                NblLoader toReturn = new NblLoader(new MemoryStream(rawData));
                toReturn.filename = filename;
                return(toReturn);
            }
            else if (ASCIIEncoding.ASCII.GetString(rawData, 0, 3) == "AFS")
            {
                AfsLoader toReturn = new AfsLoader(filename, new MemoryStream(rawData));
            }
            else if (new Regex("enemy.._...._r.\\.(xnr|rel|unr)").IsMatch(filename))
            {
                return(new EnemyLayoutFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemWeaponParam"))
            {
                return(new WeaponParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemCommonInfo.xnr"))
            {
                return(new CommonInfoFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.StartsWith("EnemyLevelBaseParam."))
            {
                return(new EnemyLevelParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Equals("itemSuitParam.xnr") || filename.Equals("itemPartsParam.xnr"))
            {
                return(new ItemSuitParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.EndsWith(".nom"))
            {
                return(new NomFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Contains("itemBulletParam_27MagAt"))
            {
                return(new RmagBulletParamFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (filename.Equals("partsinfo.xnr"))
            {
                return(new PartsInfoFile(filename, rawData, inHeader, ptrs, baseAddr));
            }
            else if (inHeader != null && ASCIIEncoding.ASCII.GetString(inHeader, 0, 4) == "NXIF" || ASCIIEncoding.ASCII.GetString(inHeader, 0, 4) == "NUIF" || ASCIIEncoding.ASCII.GetString(inHeader, 0, 4) == "NSIF")
            {
                return(new PointeredFile(filename, rawData, inHeader, ptrs, baseAddr, false));
            }
            else if (inHeader != null && ASCIIEncoding.ASCII.GetString(inHeader, 0, 4) == "NYIF")
            {
                return(new PointeredFile(filename, rawData, inHeader, ptrs, baseAddr, true));
            }
            return(new UnpointeredFile(filename, rawData, inHeader));
        }
Exemple #3
0
 private void textureCatalogueToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
     {
         Dictionary <string, Dictionary <string, TextureEntry> > textureEntries = new Dictionary <string, Dictionary <string, TextureEntry> >();
         foreach (string file in Directory.EnumerateFiles(folderBrowserDialog1.SelectedPath))
         {
             MD5 md5 = MD5.Create();
             using (Stream s = new FileStream(file, FileMode.Open))
             {
                 byte[] identifier = new byte[4];
                 s.Read(identifier, 0, 4);
                 s.Seek(0, SeekOrigin.Begin);
                 if (identifier.SequenceEqual(new byte[] { 0x4E, 0x4D, 0x4C, 0x4C }))
                 {
                     NblLoader nbl = new NblLoader(s);
                     if (nbl.chunks.Count > 1)
                     {
                         //This means there's a TMLL...
                         foreach (RawFile raw in nbl.chunks[1].fileContents)
                         {
                             byte[] fileMd5   = md5.ComputeHash(raw.fileContents);
                             string md5String = BitConverter.ToString(fileMd5).Replace("-", "");
                             if (!textureEntries.ContainsKey(raw.filename))
                             {
                                 textureEntries[raw.filename] = new Dictionary <string, TextureEntry>();
                             }
                             if (!textureEntries[raw.filename].ContainsKey(md5String))
                             {
                                 TextureEntry entry = new TextureEntry();
                                 entry.fileContents = raw;
                                 textureEntries[raw.filename][md5String] = entry;
                             }
                             if (!textureEntries[raw.filename][md5String].containingFiles.Contains(Path.GetFileName(file)))
                             {
                                 textureEntries[raw.filename][md5String].containingFiles.Add(Path.GetFileName(file));
                             }
                         }
                     }
                 }
             }
         }
         foreach (var ent in textureEntries)
         {
             if (ent.Value.Values.Count > 1)
             {
                 Console.Out.WriteLine("Texture: " + ent.Key);
                 foreach (var val in ent.Value)
                 {
                     Directory.CreateDirectory(folderBrowserDialog1.SelectedPath + "\\categorized\\conflicted\\" + ent.Key + "\\" + val.Key);
                     using (Stream outStream = new FileStream(folderBrowserDialog1.SelectedPath + "\\categorized\\conflicted\\" + ent.Key + "\\" + val.Key + "\\" + val.Value.fileContents.filename, FileMode.Create))
                     {
                         val.Value.fileContents.WriteToStream(outStream);
                     }
                     XvrTextureFile xvr = new XvrTextureFile(val.Value.fileContents.subHeader, val.Value.fileContents.fileContents, val.Value.fileContents.filename);
                     xvr.mipMaps[0].Save(folderBrowserDialog1.SelectedPath + "\\categorized\\conflicted\\" + ent.Key + "\\" + val.Key + "\\" + val.Value.fileContents.filename.Replace(".xvr", ".png"));
                     Console.Out.WriteLine("\t" + val.Key + ": " + string.Join(", ", val.Value.containingFiles));
                 }
                 Console.Out.WriteLine();
             }
             else
             {
                 string  hash = ent.Value.Keys.First();
                 RawFile raw  = ent.Value[hash].fileContents;
                 Directory.CreateDirectory(folderBrowserDialog1.SelectedPath + "\\categorized\\" + ent.Key);
                 using (Stream outStream = new FileStream(folderBrowserDialog1.SelectedPath + "\\categorized\\" + ent.Key + "\\" + raw.filename, FileMode.Create))
                 {
                     raw.WriteToStream(outStream);
                 }
                 XvrTextureFile xvr = new XvrTextureFile(raw.subHeader, raw.fileContents, raw.filename);
                 xvr.mipMaps[0].Save(folderBrowserDialog1.SelectedPath + "\\categorized\\" + ent.Key + "\\" + raw.filename.Replace(".xvr", ".png"));
             }
         }
     }
 }
Exemple #4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                byte[] formatName = new byte[4];
                using (Stream stream = openFileDialog1.OpenFile())
                {
                    stream.Read(formatName, 0, 4);
                }
                splitContainer1.Panel2.Controls.Clear();
                string identifier = new string(Encoding.ASCII.GetChars(formatName, 0, 4));
                if (identifier == "NMLL" || identifier == "NMLB")
                {
                    treeView1.Nodes.Clear();
                    loadedAfs     = null;
                    loadedMiniAfs = null;
                    using (Stream stream = openFileDialog1.OpenFile())
                    {
                        loadedNbl = new NblLoader(stream);
                        //listBox1.Items.Clear();
                        //for (int i = 0; i < loadedNbl.filenames.Length; i++)
                        //{
                        //listBox1.Items.Add(loadedNbl.filenames[i]);
                        //}
                        addChildFiles(treeView1.Nodes, loadedNbl);

                        /*
                         * treeView1.Nodes.Add("NMLL chunk");
                         * for (int i = 0; i < loadedNbl.nmllFiles.Length; i++)
                         * {
                         *  TreeNode temp = new TreeNode(loadedNbl.nmllFiles[i].fileName);
                         *  if (temp.Text.Contains(".nbl"))
                         *      addNblFiles(temp, (NblLoader)loadedNbl.nmllFiles[i].actualFile);
                         *  treeView1.Nodes[0].Nodes.Add(temp);
                         *
                         * }
                         * if (loadedNbl.tmllFiles != null && loadedNbl.tmllFiles.Length > 0)
                         * {
                         *  treeView1.Nodes.Add("TMLL chunk");
                         *  for (int i = 0; i < loadedNbl.tmllFiles.Length; i++)
                         *  {
                         *      treeView1.Nodes[1].Nodes.Add(loadedNbl.tmllFiles[i].fileName);
                         *  }
                         * }*/
                        checkBox1.Checked = loadedNbl.isCompressed;
                    }
                }
                if (new string(Encoding.ASCII.GetChars(formatName, 0, 4)) == "AFS\0")
                {
                    treeView1.Nodes.Clear();
                    loadedNbl     = null;
                    loadedMiniAfs = null;
                    using (Stream stream = openFileDialog1.OpenFile())
                    {
                        loadedAfs = new AfsLoader(stream);
                        splitContainer1.Panel2.Controls.Clear();
                        //listBox1.Items.Clear();

                        /*TextBox txtBox = new TextBox();
                         * splitContainer1.Panel2.Controls.Add(txtBox);
                         * txtBox.Dock = DockStyle.Fill;
                         * txtBox.Multiline = true;
                         * txtBox.ScrollBars = ScrollBars.Vertical;*/

                        //for (int i = 0; i < loadedAfs.fileCount; i++)
                        //{

                        /*txtBox.Text += "\r\n" + loadedAfs.afsList[i].fileName + "\t\t" + loadedAfs.afsList[i].location.ToString("X8") + " " + loadedAfs.afsList[i].fileSize.ToString("X8") + "\t\t" + loadedAfs.afsList[i].year + "-" + loadedAfs.afsList[i].month + "-" + loadedAfs.afsList[i].day + " "
                         + loadedAfs.afsList[i].hour.ToString("D2") + ":" + loadedAfs.afsList[i].minute.ToString("D2") + ":" + loadedAfs.afsList[i].second.ToString("D2") + "\t" + loadedAfs.afsList[i].garbageInt.ToString("X8");*/
                        //  listBox1.Items.Add(loadedAfs.afsList[i].fileName);

                        /*TreeNode temp = new TreeNode(loadedAfs.afsList[i].fileName);
                         * if (loadedAfs.subPaths[i] != null)
                         *  addAfsFiles(temp, loadedAfs.subPaths[i]);
                         * else if (loadedAfs.nblContents[i] != null)
                         *  addNblFiles(temp, loadedAfs.nblContents[i]);
                         * treeView1.Nodes.Add(temp);*/
                        //}

                        addChildFiles(treeView1.Nodes, loadedAfs);
                    }
                }
                if (BitConverter.ToInt16(formatName, 0) == 0x50AF)
                {
                    treeView1.Nodes.Clear();
                    loadedAfs = null;
                    loadedNbl = null;
                    using (Stream stream = openFileDialog1.OpenFile())
                    {
                        loadedMiniAfs = new MiniAfsLoader(stream);
                        splitContainer1.Panel2.Controls.Clear();
                        //listBox1.Items.Clear();

                        /*TextBox txtBox = new TextBox();
                         * splitContainer1.Panel2.Controls.Add(txtBox);
                         * txtBox.Dock = DockStyle.Fill;
                         * txtBox.Multiline = true;
                         * txtBox.ScrollBars = ScrollBars.Vertical;*/

                        //for (int i = 0; i < loadedAfs.fileCount; i++)
                        //{

                        /*txtBox.Text += "\r\n" + loadedAfs.afsList[i].fileName + "\t\t" + loadedAfs.afsList[i].location.ToString("X8") + " " + loadedAfs.afsList[i].fileSize.ToString("X8") + "\t\t" + loadedAfs.afsList[i].year + "-" + loadedAfs.afsList[i].month + "-" + loadedAfs.afsList[i].day + " "
                         + loadedAfs.afsList[i].hour.ToString("D2") + ":" + loadedAfs.afsList[i].minute.ToString("D2") + ":" + loadedAfs.afsList[i].second.ToString("D2") + "\t" + loadedAfs.afsList[i].garbageInt.ToString("X8");*/
                        //  listBox1.Items.Add(loadedAfs.afsList[i].fileName);

                        /*TreeNode temp = new TreeNode(loadedAfs.afsList[i].fileName);
                         * if (loadedAfs.subPaths[i] != null)
                         *  addAfsFiles(temp, loadedAfs.subPaths[i]);
                         * else if (loadedAfs.nblContents[i] != null)
                         *  addNblFiles(temp, loadedAfs.nblContents[i]);
                         * treeView1.Nodes.Add(temp);*/
                        //}

                        addChildFiles(treeView1.Nodes, loadedMiniAfs);
                    }
                }
            }
        }