Esempio n. 1
0
        public static void Archive(string sourceFileName, string destinationFileName)
        {
            bool compress    = false;
            int  alignment   = 16;
            var  farcArchive = new FarcArchive();

            farcArchive.IsCompressed = compress;
            farcArchive.Alignment    = alignment;
            farcArchive.Add(Path.GetFileName(sourceFileName), sourceFileName);
            farcArchive.Save(destinationFileName);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(Properties.Resources.HelpText);
                Console.ReadLine();
                return;
            }

            string sourceFileName      = null;
            string destinationFileName = null;

            bool compress  = false;
            int  alignment = 16;

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];

                if (EqualsAny("-c", "--compress"))
                {
                    compress = true;
                }

                else if (EqualsAny("-a", "--alignment"))
                {
                    alignment = int.Parse(args[++i]);
                }

                else if (sourceFileName == null)
                {
                    sourceFileName = arg;
                }

                else if (destinationFileName == null)
                {
                    destinationFileName = arg;
                }

                bool EqualsAny(params string[] strings) =>
                strings.Contains(arg, StringComparer.OrdinalIgnoreCase);
            }

            if (destinationFileName == null)
            {
                destinationFileName = sourceFileName;
            }

            if (File.GetAttributes(sourceFileName).HasFlag(FileAttributes.Directory))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, "farc");

                var farcArchive = new FarcArchive();
                farcArchive.IsCompressed = compress;
                farcArchive.Alignment    = alignment;

                foreach (var filePath in Directory.EnumerateFiles(sourceFileName))
                {
                    farcArchive.Add(Path.GetFileName(filePath), filePath);
                }

                farcArchive.Save(destinationFileName);
            }

            else if (args[0].EndsWith(".farc", StringComparison.OrdinalIgnoreCase))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, null);

                using (var stream = File.OpenRead(sourceFileName))
                {
                    var farcArchive = FarcArchive.Load <FarcArchive>(stream);

                    Directory.CreateDirectory(destinationFileName);
                    foreach (var fileName in farcArchive)
                    {
                        using (var destination = File.Create(Path.Combine(destinationFileName, fileName)))
                            using (var source = farcArchive.Open(fileName, EntryStreamMode.OriginalStream))
                                source.CopyTo(destination);
                    }
                }
            }
        }
Esempio n. 3
0
        private void fixObjSet()
        {
            string ac_path       = "";
            string ft_path       = "";
            bool   ask_user      = false;
            bool   skip_objset   = false;
            bool   skip_robs     = false;
            bool   skip_ui       = false;
            bool   skip_filecopy = false;
            bool   skip_2d       = false;
            bool   skip_db       = false;
            bool   alt_db        = false;
            bool   skip_movie    = false;

            if (File.Exists("config.txt"))
            {
                StreamReader sr = new StreamReader("config.txt");
                while (sr.Peek() > -1)
                {
                    var line  = sr.ReadLine();
                    var lines = line.Split('=');
                    if (lines[0] == "AC")
                    {
                        ac_path = lines[1];
                    }
                    if (lines[0] == "FT")
                    {
                        ft_path = lines[1];
                    }
                    if (lines[0] == "I_HAVE_CHANGED_THIS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            ask_user = true;
                        }
                    }

                    if (lines[0] == "SKIP_OBJSET")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_objset = true;
                        }
                    }

                    if (lines[0] == "SKIP_ROBS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_robs = true;
                        }
                    }

                    if (lines[0] == "UI_MOD")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_ui = true;
                        }
                    }

                    if (lines[0] == "SKIP_2D")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_2d = true;
                        }
                    }

                    if (lines[0] == "SKIP_FILECOPY")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_filecopy = true;
                        }
                    }

                    if (lines[0] == "SKIP_DB")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_filecopy = true;
                        }
                    }

                    if (lines[0] == "SKIP_MOVIE")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_movie = true;
                        }
                    }

                    if (lines[0] == "ALT_DB")
                    {
                        if (lines[1] == "TRUE")
                        {
                            alt_db = true;
                        }
                    }
                }
                sr.Close();
            }

            string path  = ft_path;
            string path2 = ac_path;

            List <string> files = new List <string>();

            string[] filess = System.IO.Directory.GetFiles(path + @"\objset\", "*hrc.farc", SearchOption.AllDirectories);

            foreach (var i in filess)
            {
                files.Add(i);
            }

            filess = System.IO.Directory.GetFiles(path + @"\objset\", "effchrpv*.farc", SearchOption.AllDirectories);

            foreach (var i in filess)
            {
                files.Add(i);
            }

            foreach (var filePath in files)
            {
                try
                {
                    //if ((!File.Exists(ac_path + @"\2d\" + Path.GetFileNameWithoutExtension(filePath) + ".farc")) && (Path.GetFileNameWithoutExtension(filePath) != "spr_sel_pv"))
                    {
                        Logs.WriteLine("Processing " + Path.GetFileNameWithoutExtension(filePath));

                        var models = new Model();

                        string obj = "";
                        string tex = "";

                        using (var farcArchive = BinaryFile.Load <FarcArchive>(filePath))
                            using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("obj")).First(), EntryStreamMode.MemoryStream))
                            {
                                models.Load(entryStream);
                                obj = farcArchive.Entries.Where(c => c.Contains("obj")).First();
                            }

                        using (var farcArchive = BinaryFile.Load <FarcArchive>(filePath))
                            using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("tex")).First(), EntryStreamMode.MemoryStream))
                            {
                                tex = farcArchive.Entries.Where(c => c.Contains("tex")).First();
                            }

                        foreach (var mesh in models.Meshes)
                        {
                            foreach (var mat in mesh.Materials)
                            {
                                mat.Shader = "ITEM";
                            }
                        }

                        models.Save("temp");
                        var newfarc = new FarcArchive();
                        newfarc.Add(obj, "temp");

                        using (var farcArchive = BinaryFile.Load <FarcArchive>(filePath))
                            using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("tex")).First(), EntryStreamMode.MemoryStream))
                                newfarc.Add(tex, entryStream, false);

                        newfarc.Save(ac_path + "\\" + "objset" + "\\" + Path.GetFileName(filePath));
                    }
                } catch (Exception e)
                {
                    Logs.WriteLine(e.ToString());
                    //Console.WriteLine(e.ToString());
                }
            }
        }
Esempio n. 4
0
        private void doRobConvert()
        {
            string ac_path   = "";
            string ft_path   = "";
            string fs_path   = "";
            string ct_path   = "";
            bool   ask_user  = false;
            bool   skip_robs = false;

            if (File.Exists("config.txt"))
            {
                StreamReader sr = new StreamReader("config.txt");
                while (sr.Peek() > -1)
                {
                    var line  = sr.ReadLine();
                    var lines = line.Split('=');
                    if (lines[0] == "AC")
                    {
                        ac_path = lines[1];
                    }
                    if (lines[0] == "FT")
                    {
                        ft_path = lines[1];
                    }
                    if (lines[0] == "FS")
                    {
                        fs_path = lines[1];
                    }
                    if (lines[0] == "CT")
                    {
                        ct_path = lines[1];
                    }
                    if (lines[0] == "I_HAVE_CHANGED_THIS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            ask_user = true;
                        }
                    }
                    if (lines[0] == "SKIP_ROBS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_robs = true;
                        }
                    }
                }
                sr.Close();
            }
            if ((ask_user) && (!skip_robs))
            {
                Logs.WriteLine("Rob Retarget Start");
                string[] filespl = System.IO.Directory.GetFiles(ft_path + @"\rob\", "*.farc", SearchOption.AllDirectories);
                string[] filesfs = { };
                string[] filesct = { };
                if (fs_path != "")
                {
                    filesfs = System.IO.Directory.GetFiles(fs_path + @"\rob\", "*.farc", SearchOption.AllDirectories);
                }
                if (ct_path != "")
                {
                    filesct = System.IO.Directory.GetFiles(ct_path + @"\rob\", "*.farc", SearchOption.AllDirectories);
                }
                string[] files = filespl.Concat(filesfs).ToArray().Concat(filesct).ToArray();


                var BoneDatabaseFT   = new BoneDatabase();
                var BoneDatabaseAC   = new BoneDatabase();
                var MotionDatabaseFT = new MotionDatabase();
                var MotionDatabaseAC = new MotionDatabase();

                BoneDatabaseFT.Load(ft_path + "\\bone_data.bin");
                BoneDatabaseAC.Load(ac_path + "\\bone_data.bin");

                using (var farcArchive = BinaryFile.Load <FarcArchive>(ac_path + "\\rob\\mot_db.farc"))
                    using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                        MotionDatabaseAC.Load(entryStream);

                using (var farcArchive = BinaryFile.Load <FarcArchive>(ft_path + "\\rob\\mot_db.farc"))
                    using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                        MotionDatabaseFT.Load(entryStream);

                var SkeletonEntryAC = BoneDatabaseAC.Skeletons[0];
                var SkeletonEntryFT = BoneDatabaseFT.Skeletons[0];

                foreach (var filePath in files)
                {
                    var motionset = new MotionSet();
                    if (!File.Exists(ac_path + "\\rob\\" + Path.GetFileName(filePath)))
                    {
                        if (!filePath.Contains("db"))
                        {
                            Logs.WriteLine("Processing " + Path.GetFileNameWithoutExtension(filePath));

                            string farcpath = filePath;

                            using (var farcArchive = BinaryFile.Load <FarcArchive>(farcpath))
                                using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                                    motionset.Load(entryStream, SkeletonEntryFT, MotionDatabaseFT);
                            {
                                motionset.Save("temp", SkeletonEntryAC, MotionDatabaseAC);
                                //motionset.Dispose();


                                FarcArchive newfarc = new FarcArchive();
                                newfarc.Add(Path.GetFileNameWithoutExtension(filePath) + ".bin", "temp");
                                newfarc.Save(ac_path + "\\rob\\" + Path.GetFileName(filePath));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        private void do2DConvert()
        {
            string ac_path   = "";
            string ft_path   = "";
            string fs_path   = "";
            string ct_path   = "";
            bool   ask_user  = false;
            bool   skip_robs = false;

            if (File.Exists("config.txt"))
            {
                StreamReader sr = new StreamReader("config.txt");
                while (sr.Peek() > -1)
                {
                    var line  = sr.ReadLine();
                    var lines = line.Split('=');
                    if (lines[0] == "AC")
                    {
                        ac_path = lines[1];
                    }
                    if (lines[0] == "FT")
                    {
                        ft_path = lines[1];
                    }
                    if (lines[0] == "FS")
                    {
                        fs_path = lines[1];
                    }
                    if (lines[0] == "CT")
                    {
                        ct_path = lines[1];
                    }
                    if (lines[0] == "I_HAVE_CHANGED_THIS")
                    {
                        if (lines[1] == "TRUE")
                        {
                            ask_user = true;
                        }
                    }
                    if (lines[0] == "SKIP_2D")
                    {
                        if (lines[1] == "TRUE")
                        {
                            skip_robs = true;
                        }
                    }
                }
                sr.Close();
            }

            if ((ask_user) && (!skip_robs))
            {
                Logs.WriteLine("Sel2D Start");
                string[] filespl = System.IO.Directory.GetFiles(ft_path + @"\2d\", "spr_sel_pv*.farc", SearchOption.AllDirectories);
                string[] filesfs = { };
                string[] filesct = { };
                if (fs_path != "")
                {
                    filesfs = System.IO.Directory.GetFiles(fs_path + @"\2d\", "spr_sel_pv*.farc", SearchOption.AllDirectories);
                }
                if (ct_path != "")
                {
                    filesct = System.IO.Directory.GetFiles(ct_path + @"\2d\", "spr_sel_pv*.farc", SearchOption.AllDirectories);
                }
                string[] files = filespl.Concat(filesfs).ToArray().Concat(filesct).ToArray();


                foreach (var filePath in files)
                {
                    if ((!File.Exists(ac_path + @"\2d\" + Path.GetFileNameWithoutExtension(filePath) + ".farc")) && (Path.GetFileNameWithoutExtension(filePath) != "spr_sel_pv"))
                    {
                        Logs.WriteLine("Processing " + Path.GetFileNameWithoutExtension(filePath));
                        string farcpath = filePath;

                        var spriteset = new SpriteSet();

                        using (var farcArchive = BinaryFile.Load <FarcArchive>(farcpath))
                            using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
                                spriteset.Load(entryStream);

                        foreach (var i in spriteset.Sprites)
                        {
                            i.Field01 = 0x0000000D;
                        }


                        spriteset.Save("temp");

                        FarcArchive newfarc = new FarcArchive();
                        newfarc.Add(Path.GetFileNameWithoutExtension(filePath) + ".bin", "temp");
                        newfarc.Save(ac_path + "\\2d\\" + Path.GetFileName(filePath));
                    }
                    //newfarc.Dispose();
                }
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
#if !DEBUG
            if (args.Length < 1)
            {
                Console.WriteLine("FARC Pack");
                Console.WriteLine("=========");
                Console.WriteLine("Packer/unpacker for .FARC files.\n");
                Console.WriteLine("Usage:");
                Console.WriteLine("    FarcPack [options] [source] [destination]");
                Console.WriteLine("    Source can be either FARC or directory.");
                Console.WriteLine("    Destination can be left empty.\n");
                Console.WriteLine("Options:");
                Console.WriteLine("    -a, -alignment         Set alignment for output FARC.");
                Console.WriteLine("                           16 by default.\n");
                Console.WriteLine("    -c, --compress         Compress files in output FARC.");
                Console.WriteLine("                           Disabled by default.");
                Console.ReadLine();
                return;
            }
#endif
            string sourcePath      = null;
            string destinationPath = null;

            bool compress  = false;
            uint alignment = 16;

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];

                Func <string, string, bool> compare = (a, b) => arg.Equals(a, StringComparison.OrdinalIgnoreCase) || arg.Equals(b, StringComparison.OrdinalIgnoreCase);
                alignment = compare("-a", "-alignment") ? uint.Parse(args[++i]) : alignment;

                compress = compare("-c", "-compress") || compress;

                if (sourcePath == null && !compare("-c", "-compress") && !compare("-a", "-alignment"))
                {
                    sourcePath = arg;
                }


                else if (destinationPath == null && !compare("-c", "-compress") && !compare("-a", "-alignment"))
                {
                    destinationPath = arg;
                }
            }

#if DEBUG
            sourcePath = @"C:\Users\waelw.WAELS-PC\Desktop\farc\vr_cmn";
#endif

            if (sourcePath == null)
            {
                throw new ArgumentException("You must provide a source.", nameof(sourcePath));
            }

            var serial = new BinarySerializer();

            if (sourcePath.EndsWith(".farc", StringComparison.OrdinalIgnoreCase))
            {
                destinationPath = destinationPath ?? Path.ChangeExtension(sourcePath, null);
#if USE_NEW
                var archive = new FarcArchiveBin();
                using (var file = File.Open(sourcePath, FileMode.Open))
                {
                    archive = serial.Deserialize <FarcArchiveBin>(file);
                    archive.Unpack(destinationPath);
                }
#else
                var archive = new FarcArchive();
                archive.Load(sourcePath);

                using (Stream source = File.OpenRead(sourcePath))
                {
                    foreach (var entry in archive)
                    {
                        using (Stream entrySource = new SubStream(source, entry.Position, entry.Length))
                            using (Stream destination = File.Create(Path.Combine(destinationPath, entry.FileName)))
                            {
                                if (archive.IsEncrypted)
                                {
                                    using (AesManaged aes = new AesManaged
                                    {
                                        KeySize = 128,
                                        Key = FarcArchive.FarcEncryptionKeyBytes,
                                        BlockSize = 128,
                                        Mode = CipherMode.ECB,
                                        Padding = PaddingMode.Zeros,
                                        IV = new byte[16],
                                    })
                                        using (CryptoStream cryptoStream = new CryptoStream(
                                                   entrySource,
                                                   aes.CreateDecryptor(),
                                                   CryptoStreamMode.Read))
                                        {
                                            if (archive.IsCompressed && entry.Length != entry.CompressedLength)
                                            {
                                                using (GZipStream gzipStream = new GZipStream(cryptoStream, CompressionMode.Decompress))
                                                {
                                                    gzipStream.CopyTo(destination);
                                                }
                                            }

                                            else
                                            {
                                                cryptoStream.CopyTo(destination);
                                            }
                                        }
                                }

                                else if (archive.IsCompressed && entry.Length != entry.CompressedLength)
                                {
                                    using (GZipStream gzipStream = new GZipStream(entrySource, CompressionMode.Decompress))
                                    {
                                        gzipStream.CopyTo(destination);
                                    }
                                }

                                else
                                {
                                    entrySource.CopyTo(destination);
                                }
                            }
                    }
                }
#endif
            }

            else if (File.GetAttributes(sourcePath).HasFlag(FileAttributes.Directory))
            {
#if USE_NEW
                var archive = new FarcArchiveBin();
                archive.Alignment = (int)alignment;
#else
                var archive = new FarcArchive();
                archive.Alignment = alignment;
#endif
                archive.IsCompressed = compress;
#if DEBUG
                archive.Alignment = 64;
#endif
                destinationPath = destinationPath ?? sourcePath + ".farc";

                foreach (string fileName in Directory.GetFiles(sourcePath))
                {
#if USE_NEW
                    archive.Add(new FarcEntryBin(fileName));
#else
                    archive.Add(new FarcEntry
                    {
                        FileName = Path.GetFileName(fileName),
                        FilePath = new FileInfo(fileName)
                    });
#endif
                }

#if USE_NEW
                archive.Flush();
                using (var save = File.Create(destinationPath))
                {
                    serial.Serialize(save, archive);
                }
#else
                archive.Save(destinationPath);
#endif
            }
        }
Esempio n. 7
0
        private static void Main(string[] args)
        {
            const string path = @"D:\QuickBMS\dt_anim\mot_PV007.bin";

            //const string path = @"D:\QuickBMS\f_anim\mot_PV626.bin";
            //const string path = @"D:\QuickBMS\f_anim\mot_PV626_tst.bin";
            using (var file = new FileStream(path, FileMode.Open))
            {
                var serializer = new BinarySerializer();
                //var motFile = serializer.Deserialize<MotFile>(file);
                var motFile = MotFile.Deserialize(file, false);
                Console.WriteLine(motFile.GetMotData(0, 0).FrameCount);
                //const string savePath = @"D:\QuickBMS\f_anim\mot_PV056.bin";
                const string SavePath = @"D:\QuickBMS\modify_mot\mot_PV007.bin";
                //const string SavePath = @"D:\QuickBMS\modify_mot\mot_PV007.xml";

                /*
                 * using (var save = new FileStream(SavePath, FileMode.Create))
                 * {
                 *  var doc = new XmlDocument();
                 *  var root = doc.CreateElement("animation");
                 *  var wrapper = doc.CreateElement("ikAnim");
                 *  foreach (var value in motFile.Animations[0].Data[24].Values)
                 *  {
                 *      var element = doc.CreateElement("axis");
                 *      element.InnerText = $"(X={value.Value},Y=0.0,Z=0.0)";
                 *
                 *  }
                 *  var leftHand = motFile.Animations[0].Data[24];
                 *  var leftHand1 = motFile.Animations[0].Data[24];
                 *  var leftHand2 = motFile.Animations[0].Data[24];
                 *
                 *  for (var index = 0; index < leftHand.FrameCount; index++)
                 *  {
                 *      var element = doc.CreateElement("axis");
                 *      var frame = doc.CreateElement("frame");
                 *      frame.InnerText = $"{leftHand.Frames[index]}";
                 *      element.InnerText = $"(X={leftHand.Values[index].Value},Y={leftHand1.Values[index].Value},Z={leftHand2.Values[index].Value})";
                 *
                 *      wrapper.AppendChild(frame);
                 *      wrapper.AppendChild(element);
                 *  }
                 *  root.AppendChild(wrapper);
                 *  doc.AppendChild(root);
                 *  doc.Save(save);
                 * }
                 */
                Console.WriteLine(motFile.GetMotData(0, 0).FrameCount);
                var archive = new FarcArchive
                {
                    new FarcEntry
                    {
                        FileName = Path.GetFileName(SavePath),
                        FilePath = new FileInfo(SavePath)
                    }
                };

                var farcDirectory = @"D:\Emulators\RPSC3\dev_hdd0\game\NPJB00134\USRDIR\rom\rob\" + Path.ChangeExtension(archive[0].FileName, ".farc");
                //var farcDirectory = @"D:\Emulators\RPSC3\dev_hdd0\disc\BLJM60527\PS3_GAME\USRDIR\rom\rob" + Path.ChangeExtension(archive[0].FileName, ".farc");
                archive.Save(farcDirectory);
            }
        }
Esempio n. 8
0
        public void GenerateObjSet(string filePath, Model stgpv, ObjectDatabase objdb, TextureDatabase texturedb, StageDatabase staged, string acpath, divamodgen divamods, bool doProcess = true, bool debug = false)
        {
            /*
             * var stgpv = new Model();
             * var textures = new MikuMikuLibrary.Textures.TextureSet();
             * var texdb = new TextureDatabase();
             *
             * using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath))
             * using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txi")).First(), EntryStreamMode.MemoryStream))
             *  texdb.Load(entryStream);
             *
             * if (debug)
             * {
             *  string farcpath = acpath + "\\rom\\objset\\" + Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + ".farc";
             *
             *  using (var farcArchive = BinaryFile.Load<FarcArchive>(farcpath))
             *  using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("tex")).First(), EntryStreamMode.MemoryStream))
             *      textures.Load(entryStream);
             *
             * }
             * else
             * {
             *  using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath))
             *  using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txd")).First(), EntryStreamMode.MemoryStream))
             *      textures.Load(entryStream);
             *
             *  using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath))
             *  using (var entryStream = farcArchive.Open(farcArchive.Entries.First(), EntryStreamMode.MemoryStream))
             *      stgpv.Load(entryStream, textures, texdb);
             * }
             *
             */

            if (Path.GetFileNameWithoutExtension(filePath).Contains("effpv"))
            {
                filePath = Path.GetDirectoryName(filePath) + "\\" + Path.GetFileNameWithoutExtension(filePath).Replace("effpv", "stgpv") + "hrc2.farc";
            }

            var texdb = new TextureDatabase();

            //using (var farcArchive = BinaryFile.Load<FarcArchive>(filePath))
            //using (var entryStream = farcArchive.Open(farcArchive.Entries.Where(c => c.Contains("txi")).First(), EntryStreamMode.MemoryStream))
            //   texdb.Load(entryStream);

            var objentry = new ObjectEntry();

            objentry.ArchiveFileName = Path.GetFileName(filePath).Replace("stgpv0", "stgpv8");
            objentry.FileName        = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_obj.bin";
            objentry.Id              = FindUnusedID(objdb);
            objentry.Name            = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8").ToUpper();
            objentry.TextureFileName = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_tex.bin";

            int ground_id = -1;

            ushort counter = 1;

            foreach (var meshes in stgpv.Meshes)
            {
                meshes.SubMeshes.RemoveAll(x => x.Vertices == null || x.Vertices.Length == 0);
                meshes.Name = meshes.Name.Replace("STGPV0", "STGPV8");
                meshes.Name = meshes.Name.Replace("EFFPV", "STGPV");

                if (Path.GetFileName(filePath).Contains("hrc"))
                {
                    int pvid = int.Parse(Path.GetFileName(filePath).Substring(5, 3));

                    if (pvid < 200)
                    {
                        pvid = pvid + 800;
                    }

                    {
                        var check2 = divamods.Divamods.Where(c => c.pvid == pvid).FirstOrDefault();
                        if (check2 == null)
                        {
                            divamods.Divamods.Add(new pdaconversion.divamods(pvid));
                            Logs.WriteLine("objset: Created new PV at id " + pvid);
                            check2 = divamods.Divamods.Where(c => c.pvid == pvid).First();
                        }
                        check2.item_pv.Add(meshes.Name);
                        Logs.WriteLine("objset: Added item_pv for PV at id " + pvid + "," + meshes.Name);
                    }

                    if (pvid >= 800)
                    {
                        var check2 = divamods.Divamods.Where(c => c.pvid == (pvid - 100)).FirstOrDefault();
                        if (check2 == null)
                        {
                            divamods.Divamods.Add(new pdaconversion.divamods(pvid - 100));
                            Logs.WriteLine("objset: Created new PV at id " + (pvid - 100));
                            check2 = divamods.Divamods.Where(c => c.pvid == (pvid - 100)).First();
                        }
                        check2.item_pv.Add(meshes.Name);
                        Logs.WriteLine("objset: Added item_pv for PV at id " + (pvid - 100) + "," + meshes.Name);
                    }
                }

                var meshentry = new MeshEntry();
                meshes.Id      = counter;
                meshentry.Id   = (ushort)meshes.Id;
                meshentry.Name = meshes.Name;

                if (meshes.Name.Contains("GND"))
                {
                    ground_id = meshes.Id;
                }

                objentry.Meshes.Add(meshentry);

                if (doProcess)
                {
                    if (!debug)
                    {
                        /*
                         * foreach (var submeshes in meshes.SubMeshes)
                         * {
                         *  foreach (var indexTable in submeshes.IndexTables)
                         *  {
                         *      ushort[] triangleStrip = Stripifier.Stripify(indexTable.Indices);
                         *      if (triangleStrip != null)
                         *      {
                         *          indexTable.PrimitiveType = PrimitiveType.TriangleStrip;
                         *          indexTable.Indices = triangleStrip;
                         *      }
                         *  }
                         * }
                         */
                    }

                    //foreach (var textures in M)

                    foreach (var material in meshes.Materials)
                    {
                        if ((Path.GetFileName(filePath).Contains("hrc2")) || (Path.GetFileName(filePath).Contains("hrc")))
                        {
                            material.Shader         = "ITEM";
                            material.IsAlphaEnabled = false;
                            //material.Field00 = 0x00000001;
                            //material.Field02 = 0x00000A80;

                            //material.Diffuse.Field00 = 0x00000000;
                            //material.Diffuse.Field01 = 0x016400E1;
                            //material.Diffuse.Field02 = 0x000000F1;

                            MikuMikuLibrary.Misc.Color asdf = new MikuMikuLibrary.Misc.Color(0, 0, 0, 0);

                            material.SpecularColor = asdf;

                            //material.AmbientColor = asdf;
                            //material.EmissionColor = asdf;
                            //material.SpecularColor = asdf;

                            //material.Shininess = 1;

                            //material.Diffuse.Field00 = 0x00000000;
                            //material.Diffuse.Field01 = 0x002400E0;
                            //material.Diffuse.Field02 = 0x000000F1;

                            if (material.Ambient.TextureId == 1509989155)
                            {
                                material.Ambient.TextureId = -1;
                            }
                            if (material.Normal.TextureId == 1509989155)
                            {
                                material.Normal.TextureId = -1;
                            }
                            if (material.Specular.TextureId == 1509989155)
                            {
                                material.Specular.TextureId = -1;
                                material.SpecularColor      = asdf;
                            }
                            //else { material.Field00 = 0x0000002D; }

                            /*
                             *
                             * // this blacken the screen on STAGE SHADER
                             * material.Specular.Field01 = 0x002418C3;
                             * material.Specular.Field02 = 0x000000F3;
                             * material.Specular.Field05 = 1;
                             * material.Specular.Field06 = 1;
                             * material.Specular.Field11 = 1;
                             * material.Specular.Field16 = 1;
                             * material.Specular.Field21 = 1;
                             *
                             *
                             * material.Specular.TextureId = -1;
                             * material.Specular.Field01 = 0x00000000;
                             * material.Specular.Field02 = 0x000000F0;
                             * material.Specular.Field05 = 1;
                             * material.Specular.Field06 = 0;
                             * material.Specular.Field11 = 0;
                             * material.Specular.Field16 = 0;
                             * material.Specular.Field21 = 0;
                             *
                             * material.Reflection.TextureId = -1;
                             * material.Reflection.Field01 = 0x00000000;
                             * material.Reflection.Field02 = 0x000000F0;
                             * material.Reflection.Field05 = 1;
                             * material.Reflection.Field06 = 0;
                             * material.Reflection.Field11 = 0;
                             * material.Reflection.Field16 = 0;
                             * material.Reflection.Field21 = 0;
                             */

                            if (material.Reflection.TextureId == 1509989155)
                            {
                                material.Reflection.TextureId = -1;
                            }
                            if (material.ToonCurve.TextureId == 1509989155)
                            {
                                material.ToonCurve.TextureId = -1;
                            }
                            if (material.SpecularPower.TextureId == 1509989155)
                            {
                                material.SpecularPower.TextureId = -1;
                            }
                            if (material.Texture08.TextureId == 1509989155)
                            {
                                material.Texture08.TextureId = -1;
                            }
                        }
                        else
                        {
                            material.Shader = "BLINN";
                            //material.Field00 = 0x0000000D;
                            //material.Field02 = 0x00000A80;

                            MikuMikuLibrary.Misc.Color asdf = new MikuMikuLibrary.Misc.Color(0, 0, 0, 0);

                            //material.AmbientColor = asdf;
                            //material.EmissionColor = asdf;
                            //material.Shininess = 1;
                            //material.Diffuse.Field00 = 0x00000230;
                            //material.Diffuse.Field02 = 0x002418C3;

                            if (material.Ambient.TextureId == 1509989155)
                            {
                                material.Ambient.TextureId = -1;
                            }
                            if (material.Normal.TextureId == 1509989155)
                            {
                                material.Normal.TextureId = -1;
                            }
                            if (material.Specular.TextureId == 1509989155)
                            {
                                material.Specular.TextureId = -1;
                                material.SpecularColor      = asdf;
                            }
                            //else { material.Field00 = 0x0000002D; }

                            /*
                             *
                             * // this blacken the screen on STAGE SHADER
                             * material.Specular.Field01 = 0x002418C3;
                             * material.Specular.Field02 = 0x000000F3;
                             * material.Specular.Field05 = 1;
                             * material.Specular.Field06 = 1;
                             * material.Specular.Field11 = 1;
                             * material.Specular.Field16 = 1;
                             * material.Specular.Field21 = 1;
                             *
                             */

                            /*
                             * material.Specular.TextureId = -1;
                             * material.Specular.Field01 = 0x00000000;
                             * material.Specular.Field02 = 0x000000F0;
                             * material.Specular.Field05 = 5;
                             * material.Specular.Field06 = 0;
                             * material.Specular.Field11 = 0;
                             * material.Specular.Field16 = 0;
                             * material.Specular.Field21 = 0;
                             *
                             *
                             * material.Normal.Field01 = 0x00000000;
                             * material.Normal.Field02 = 0x000000F0;
                             * material.Normal.Field05 = 5;
                             * material.Normal.Field06 = 0;
                             * material.Normal.Field11 = 0;
                             * material.Normal.Field16 = 0;
                             * material.Normal.Field21 = 0;
                             *
                             *
                             * material.ToonCurve.TextureId = -1;
                             * material.ToonCurve.Field01 = 0x00000000;
                             * material.ToonCurve.Field02 = 0x000000F0;
                             * material.ToonCurve.Field05 = 5;
                             * material.ToonCurve.Field06 = 0;
                             * material.ToonCurve.Field11 = 0;
                             * material.ToonCurve.Field16 = 0;
                             * material.ToonCurve.Field21 = 0;
                             */

                            if (material.Reflection.TextureId == 1509989155)
                            {
                                material.Reflection.TextureId = -1;
                            }
                            if (material.ToonCurve.TextureId == 1509989155)
                            {
                                material.ToonCurve.TextureId = -1;
                            }
                            if (material.SpecularPower.TextureId == 1509989155)
                            {
                                material.SpecularPower.TextureId = -1;
                            }
                            if (material.Texture08.TextureId == 1509989155)
                            {
                                material.Texture08.TextureId = -1;
                            }
                        }
                    }
                }
                counter++;
            }

            stgpv.TextureSet.Format = BinaryFormat.DT;
            stgpv.Format            = BinaryFormat.DT;



            if (doProcess)
            {
                stgpv.Save("temp\\" + Path.GetFileNameWithoutExtension(filePath) + "_obj.bin", null, texturedb, null);
            }
            objdb.Objects.Add(objentry);

            if (Path.GetFileNameWithoutExtension(filePath).Count() == 8)
            {
                StageEntry stage = new StageEntry();
                stage.Id                  = FindUnusedID(staged);
                stage.Name                = Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8").ToUpper();
                stage.ObjectGroundId      = (short)ground_id;
                stage.ObjectGroundIdFlag  = (short)objentry.Id;
                stage.ObjectId3           = -1;
                stage.ObjectIdFlag3       = -1;
                stage.ObjectId5           = -1;
                stage.ObjectIdFlag5       = -1;
                stage.ObjectId7           = -1;
                stage.ObjectIdFlag7       = -1;
                stage.RingRectangleX      = -8;
                stage.RingRectangleY      = -8;
                stage.RingRectangleWidth  = 16;
                stage.RingRectangleHeight = 16;
                stage.RingRingHeight      = 0;
                stage.RingOutHeight       = -1000;
                stage.Field00             = 1;
                stage.Field11             = -1;
                stage.Field02             = -1;

                stage.LensFlareScaleX = -1;
                stage.LensFlareScaleY = -1;
                stage.LensFlareScaleZ = -1;

                stage.ObjectSkyId         = -1;
                stage.ObjectSkyIdFlag     = -1;
                stage.ObjectReflectId     = -1;
                stage.ObjectReflectIdFlag = -1;

                stage.CollisionFilePath = @"rom/STGTST_COLI.000.bin";

                stage.ObjectId1    = (short)objentry.Id;
                stage.StageEffect1 = StageEntry.StageEffect.Empty;
                stage.Auth3dName   = "EFF" + stage.Name;
                staged.Stages.Add(stage);
            }

            if (doProcess)
            {
                var newfarc = new FarcArchive();
                newfarc.Add(Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_obj.bin", "temp\\" + Path.GetFileNameWithoutExtension(filePath) + "_obj.bin");
                newfarc.Add(Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + "_tex.bin", "temp\\" + Path.GetFileNameWithoutExtension(filePath) + "_tex.bin");
                newfarc.Alignment    = 16;
                newfarc.IsCompressed = false;
                newfarc.Save(acpath + "\\rom\\objset\\" + Path.GetFileNameWithoutExtension(filePath).Replace("stgpv0", "stgpv8") + ".farc");
            }
        }
Esempio n. 9
0
        public static void Compress(string sourceFileName, string destinationFileName)
        {
            bool compress  = false;
            int  alignment = 16;

            if (destinationFileName == null)
            {
                destinationFileName = sourceFileName;
            }

            if (File.GetAttributes(sourceFileName).HasFlag(FileAttributes.Directory))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, "farc");

                var farcArchive = new FarcArchive();
                farcArchive.IsCompressed = compress;
                farcArchive.Alignment    = alignment;

                foreach (var filePath in Directory.EnumerateFiles(sourceFileName))
                {
                    farcArchive.Add(Path.GetFileName(filePath), filePath);
                }

                farcArchive.Save(destinationFileName);
            }

            else if (sourceFileName.EndsWith(".farc", StringComparison.OrdinalIgnoreCase))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, null);

                using (var stream = File.OpenRead(sourceFileName))
                {
                    var farcArchive = FarcArchive.Load <FarcArchive>(stream);

                    Directory.CreateDirectory(destinationFileName);
                    foreach (var fileName in farcArchive)
                    {
                        using (var destination = File.Create(Path.Combine(destinationFileName, fileName)))
                            using (var source = farcArchive.Open(fileName, EntryStreamMode.OriginalStream))
                                source.CopyTo(destination);
                    }
                }
            }
            else if (sourceFileName.EndsWith(".bak", StringComparison.OrdinalIgnoreCase))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, null);

                using (var stream = File.OpenRead(sourceFileName))
                {
                    var farcArchive = FarcArchive.Load <FarcArchive>(stream);

                    Directory.CreateDirectory(destinationFileName);
                    foreach (var fileName in farcArchive)
                    {
                        using (var destination = File.Create(Path.Combine(destinationFileName, fileName)))
                            using (var source = farcArchive.Open(fileName, EntryStreamMode.OriginalStream))
                                source.CopyTo(destination);
                    }
                }
            }
        }
Esempio n. 10
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine(Properties.Resources.HelpText);
                Console.ReadLine();
                return;
            }

            string sourceFileName      = null;
            string destinationFileName = null;

            foreach (var arg in args)
            {
                if (sourceFileName == null)
                {
                    sourceFileName = arg;
                }

                else if (destinationFileName == null)
                {
                    destinationFileName = arg;
                }
            }

            if (destinationFileName == null)
            {
                destinationFileName = sourceFileName;
            }

            if (File.GetAttributes(sourceFileName).HasFlag(FileAttributes.Directory))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, "farc");

                var farcArchive = new FarcArchive();
                foreach (var filePath in Directory.EnumerateFiles(sourceFileName))
                {
                    farcArchive.Add(Path.GetFileName(filePath), filePath);
                }

                farcArchive.Save(destinationFileName);
            }

            else if (args[0].EndsWith(".farc", StringComparison.OrdinalIgnoreCase))
            {
                destinationFileName = Path.ChangeExtension(destinationFileName, null);

                using (var stream = File.OpenRead(sourceFileName))
                {
                    var farcArchive = FarcArchive.Load <FarcArchive>(stream);

                    Directory.CreateDirectory(destinationFileName);
                    foreach (var fileName in farcArchive)
                    {
                        using (var destination = File.Create(Path.Combine(destinationFileName, fileName)))
                            using (var source = farcArchive.Open(fileName, EntryStreamMode.OriginalStream))
                                source.CopyTo(destination);
                    }
                }
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("FARC Pack");
                Console.WriteLine("=========");
                Console.WriteLine("Packer/unpacker for .FARC files.\n");
                Console.WriteLine("Usage:");
                Console.WriteLine("    FarcPack [options] [source] [destination]");
                Console.WriteLine("    Source can be either FARC or directory.");
                Console.WriteLine("    Destination can be left empty.\n");
                Console.WriteLine("Options:");
                Console.WriteLine("    -a, -alignment         Set alignment for output FARC.");
                Console.WriteLine("                           16 by default.\n");
                Console.WriteLine("    -c, --compress         Compress files in output FARC.");
                Console.WriteLine("                           Disabled by default.");
                Console.ReadLine();
                return;
            }

            string sourcePath      = null;
            string destinationPath = null;

            bool compress  = false;
            uint alignment = 16;

            for (int i = 0; i < args.Length; i++)
            {
                string arg = args[i];

                if (arg.Equals("-a", StringComparison.OrdinalIgnoreCase) ||
                    arg.Equals("-alignment", StringComparison.OrdinalIgnoreCase))
                {
                    alignment = uint.Parse(args[++i]);
                }

                else if (arg.Equals("-c", StringComparison.OrdinalIgnoreCase) ||
                         arg.Equals("-compress", StringComparison.OrdinalIgnoreCase))
                {
                    compress = true;
                }

                else if (sourcePath == null)
                {
                    sourcePath = arg;
                }

                else if (destinationPath == null)
                {
                    destinationPath = arg;
                }
            }

            if (sourcePath == null)
            {
                throw new ArgumentException("You must provide a source.", nameof(sourcePath));
            }

            if (sourcePath.EndsWith(".farc", StringComparison.OrdinalIgnoreCase))
            {
                FarcArchive archive = new FarcArchive();
                archive.Load(sourcePath);

                if (destinationPath == null)
                {
                    destinationPath = Path.ChangeExtension(sourcePath, null);
                }

                Directory.CreateDirectory(destinationPath);

                using (Stream source = File.OpenRead(sourcePath))
                {
                    foreach (FarcEntry entry in archive)
                    {
                        using (Stream entrySource = new SubStream(source, entry.Position, entry.Length))
                            using (Stream destination = File.Create(Path.Combine(destinationPath, entry.FileName)))
                            {
                                if (archive.IsEncrypted)
                                {
                                    using (AesManaged aes = new AesManaged
                                    {
                                        KeySize = 128,
                                        Key = FarcArchive.FarcEncryptionKeyBytes,
                                        BlockSize = 128,
                                        Mode = CipherMode.ECB,
                                        Padding = PaddingMode.Zeros,
                                        IV = new byte[16],
                                    })
                                        using (CryptoStream cryptoStream = new CryptoStream(
                                                   entrySource,
                                                   aes.CreateDecryptor(),
                                                   CryptoStreamMode.Read))
                                        {
                                            if (archive.IsCompressed && entry.Length != entry.CompressedLength)
                                            {
                                                using (GZipStream gzipStream = new GZipStream(cryptoStream, CompressionMode.Decompress))
                                                {
                                                    gzipStream.CopyTo(destination);
                                                }
                                            }

                                            else
                                            {
                                                cryptoStream.CopyTo(destination);
                                            }
                                        }
                                }

                                else if (archive.IsCompressed && entry.Length != entry.CompressedLength)
                                {
                                    using (GZipStream gzipStream = new GZipStream(entrySource, CompressionMode.Decompress))
                                    {
                                        gzipStream.CopyTo(destination);
                                    }
                                }

                                else
                                {
                                    entrySource.CopyTo(destination);
                                }
                            }
                    }
                }
            }

            else if (File.GetAttributes(sourcePath).HasFlag(FileAttributes.Directory))
            {
                FarcArchive archive = new FarcArchive();
                archive.Alignment    = alignment;
                archive.IsCompressed = compress;

                if (destinationPath == null)
                {
                    destinationPath = sourcePath + ".farc";
                }

                foreach (string fileName in Directory.GetFiles(sourcePath))
                {
                    archive.Add(new FarcEntry
                    {
                        FileName = Path.GetFileName(fileName),
                        FilePath = new FileInfo(fileName)
                    });
                }

                archive.Save(destinationPath);
            }
        }