Example #1
0
        static void Main(string[] args)
        {
            const string basePath = @"D:\Program Files (x86)\Steam\steamapps\common\DARK SOULS III\Game";

            const string actionSetupPath = "Res/TaeToWeaponKind.yml";

            TAEAnalyzerData analyzerData = new YamlDotNet.Serialization.Deserializer().Deserialize <TAEAnalyzerData>(new System.IO.StreamReader(actionSetupPath));

            var reader = new BND4Reader(System.IO.Path.Combine(basePath, "chr/c0000.anibnd.dcx"));


            const int jumpTableEventType = 0;

            const int attackEventType = 1;

            int[] comboBehSubIds = new[] { 4, 116 };

            var taeTemplate = TAE.Template.ReadXMLFile(@"Res/TAE.Template.DS3.xml");

            var jumpTableEventTemplate = taeTemplate[21][jumpTableEventType];
            var attackEventTemplate    = taeTemplate[21][attackEventType];

            var analyzedWeapons = analyzerData.weapons.Select(weaponKvp => (kvp: weaponKvp, taeFileHeader: reader.Files
                                                                            // get all TAE headers
                                                                            .Where(header => header.Name.EndsWith("tae"))
                                                                            .Single(header => System.IO.Path.GetFileName(header.Name) == $"a{weaponKvp.Key}.tae")))
                                  .Select(weaponData => (weaponData: weaponData, fileContents: reader.ReadFile(weaponData.taeFileHeader)))
                                  .Where(weaponData => TAE.Is(weaponData.fileContents))
                                  .Select((weaponData) => (kvp: weaponData.weaponData.kvp, weaponTae: TAE.Read(weaponData.fileContents)))
                                  .SelectMany(myTuple => analyzerData.animKind.Select(animKindKvp => (weaponKindKvp: myTuple.kvp, animKindKvp: animKindKvp, weaponTae: myTuple.weaponTae)))
                                  .SelectMany(myTuple =>
            {
                var attackTimings = myTuple.weaponTae.Animations.Select(anim => {
                    bool didFind = myTuple.animKindKvp.Value.TryGetDetails(myTuple.animKindKvp.Key, anim, out string details);

                    return(found: didFind, myTuple: myTuple, anim, details);
                })
                                    .Where(d => d.found)
                                    .Select(anim => (anim, events: anim.anim.Events.Where(taeEvent => taeEvent.Type == attackEventType || taeEvent.Type == jumpTableEventType)))
                                    .Where(events => events.events.Any())
                                    .Select(anim => anim.events.Aggregate(new AttackInfo(), (attackInfo, taeEvent) =>
                {
                    attackInfo.anim    = anim.anim.anim;
                    attackInfo.details = anim.anim.details;
                    if (taeEvent.Type == attackEventType)
                    {
                        taeEvent.ApplyTemplate(false, attackEventTemplate);
                        if (taeEvent.Parameters["Unk04"].Equals(0))
                        {
                            attackInfo.Attacks.Add((attackStart: taeEvent.StartTime, attackEnd: taeEvent.EndTime));
                        }
                    }
Example #2
0
        public static void Unpack(this BND4Reader bnd, string sourceName, string targetDir, IProgress <float> progress)
        {
            Directory.CreateDirectory(targetDir);
            var xws = new XmlWriterSettings();

            xws.Indent = true;
            var xw = XmlWriter.Create($"{targetDir}\\_yabber-bnd4.xml", xws);

            xw.WriteStartElement("bnd4");

            xw.WriteElementString("filename", sourceName);
            xw.WriteElementString("compression", bnd.Compression.ToString());
            xw.WriteElementString("version", bnd.Version);
            xw.WriteElementString("format", bnd.Format.ToString());
            xw.WriteElementString("bigendian", bnd.BigEndian.ToString());
            xw.WriteElementString("bitbigendian", bnd.BitBigEndian.ToString());
            xw.WriteElementString("unicode", bnd.Unicode.ToString());
            xw.WriteElementString("extended", $"0x{bnd.Extended:X2}");
            xw.WriteElementString("unk04", bnd.Unk04.ToString());
            xw.WriteElementString("unk05", bnd.Unk05.ToString());
            YBinder.WriteBinderFiles(bnd, xw, targetDir, progress);
            xw.WriteEndElement();
            xw.Close();
        }
Example #3
0
        private static bool UnpackFile(string sourceFile, IProgress <float> progress)
        {
            string sourceDir = Path.GetDirectoryName(sourceFile);
            string filename  = Path.GetFileName(sourceFile);
            string targetDir = $"{sourceDir}\\{filename.Replace('.', '-')}";

            if (File.Exists(targetDir))
            {
                targetDir += "-ybr";
            }

            if (DCX.Is(sourceFile))
            {
                Console.WriteLine($"Decompressing DCX: {filename}...");
                byte[] bytes = DCX.Decompress(sourceFile, out DCX.Type compression);
                if (BND3.Is(bytes))
                {
                    Console.WriteLine($"Unpacking BND3: {filename}...");
                    using (var bnd = new BND3Reader(bytes))
                    {
                        bnd.Compression = compression;
                        bnd.Unpack(filename, targetDir, progress);
                    }
                }
                else if (BND4.Is(bytes))
                {
                    Console.WriteLine($"Unpacking BND4: {filename}...");
                    using (var bnd = new BND4Reader(bytes))
                    {
                        bnd.Compression = compression;
                        bnd.Unpack(filename, targetDir, progress);
                    }
                }
                else if (FFXDLSE.Is(bytes))
                {
                    Console.WriteLine($"Unpacking FFX: {filename}...");
                    var ffx = FFXDLSE.Read(bytes);
                    ffx.Compression = compression;
                    ffx.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".fmg.dcx"))
                {
                    Console.WriteLine($"Unpacking FMG: {filename}...");
                    FMG fmg = FMG.Read(bytes);
                    fmg.Compression = compression;
                    fmg.Unpack(sourceFile);
                }
                else if (GPARAM.Is(bytes))
                {
                    Console.WriteLine($"Unpacking GPARAM: {filename}...");
                    GPARAM gparam = GPARAM.Read(bytes);
                    gparam.Compression = compression;
                    gparam.Unpack(sourceFile);
                }
                else if (TPF.Is(bytes))
                {
                    Console.WriteLine($"Unpacking TPF: {filename}...");
                    TPF tpf = TPF.Read(bytes);
                    tpf.Compression = compression;
                    tpf.Unpack(filename, targetDir, progress);
                }
                else
                {
                    Console.WriteLine($"File format not recognized: {filename}");
                    return(true);
                }
            }
            else
            {
                if (BND3.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking BND3: {filename}...");
                    using (var bnd = new BND3Reader(sourceFile))
                    {
                        bnd.Unpack(filename, targetDir, progress);
                    }
                }
                else if (BND4.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking BND4: {filename}...");
                    using (var bnd = new BND4Reader(sourceFile))
                    {
                        bnd.Unpack(filename, targetDir, progress);
                    }
                }
                else if (BXF3.IsBHD(sourceFile))
                {
                    string bdtExtension = Path.GetExtension(filename).Replace("bhd", "bdt");
                    string bdtFilename  = $"{Path.GetFileNameWithoutExtension(filename)}{bdtExtension}";
                    string bdtPath      = $"{sourceDir}\\{bdtFilename}";
                    if (File.Exists(bdtPath))
                    {
                        Console.WriteLine($"Unpacking BXF3: {filename}...");
                        using (var bxf = new BXF3Reader(sourceFile, bdtPath))
                        {
                            bxf.Unpack(filename, bdtFilename, targetDir, progress);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"BDT not found for BHD: {filename}");
                        return(true);
                    }
                }
                else if (BXF4.IsBHD(sourceFile))
                {
                    string bdtExtension = Path.GetExtension(filename).Replace("bhd", "bdt");
                    string bdtFilename  = $"{Path.GetFileNameWithoutExtension(filename)}{bdtExtension}";
                    string bdtPath      = $"{sourceDir}\\{bdtFilename}";
                    if (File.Exists(bdtPath))
                    {
                        Console.WriteLine($"Unpacking BXF4: {filename}...");
                        using (var bxf = new BXF4Reader(sourceFile, bdtPath))
                        {
                            bxf.Unpack(filename, bdtFilename, targetDir, progress);
                        }
                    }
                    else
                    {
                        Console.WriteLine($"BDT not found for BHD: {filename}");
                        return(true);
                    }
                }
                else if (FFXDLSE.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking FFX: {filename}...");
                    var ffx = FFXDLSE.Read(sourceFile);
                    ffx.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".ffx.xml") || sourceFile.EndsWith(".ffx.dcx.xml"))
                {
                    Console.WriteLine($"Repacking FFX: {filename}...");
                    YFFX.Repack(sourceFile);
                }
                else if (sourceFile.EndsWith(".fmg"))
                {
                    Console.WriteLine($"Unpacking FMG: {filename}...");
                    FMG fmg = FMG.Read(sourceFile);
                    fmg.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".fmg.xml") || sourceFile.EndsWith(".fmg.dcx.xml"))
                {
                    Console.WriteLine($"Repacking FMG: {filename}...");
                    YFMG.Repack(sourceFile);
                }
                else if (GPARAM.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking GPARAM: {filename}...");
                    GPARAM gparam = GPARAM.Read(sourceFile);
                    gparam.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".gparam.xml") || sourceFile.EndsWith(".gparam.dcx.xml") ||
                         sourceFile.EndsWith(".fltparam.xml") || sourceFile.EndsWith(".fltparam.dcx.xml"))
                {
                    Console.WriteLine($"Repacking GPARAM: {filename}...");
                    YGPARAM.Repack(sourceFile);
                }
                else if (sourceFile.EndsWith(".luagnl"))
                {
                    Console.WriteLine($"Unpacking LUAGNL: {filename}...");
                    LUAGNL gnl = LUAGNL.Read(sourceFile);
                    gnl.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".luagnl.xml"))
                {
                    Console.WriteLine($"Repacking LUAGNL: {filename}...");
                    YLUAGNL.Repack(sourceFile);
                }
                else if (LUAINFO.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking LUAINFO: {filename}...");
                    LUAINFO info = LUAINFO.Read(sourceFile);
                    info.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".luainfo.xml"))
                {
                    Console.WriteLine($"Repacking LUAINFO: {filename}...");
                    YLUAINFO.Repack(sourceFile);
                }
                else if (TPF.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking TPF: {filename}...");
                    TPF tpf = TPF.Read(sourceFile);
                    tpf.Unpack(filename, targetDir, progress);
                }
                else if (Zero3.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking 000: {filename}...");
                    Zero3 z3 = Zero3.Read(sourceFile);
                    z3.Unpack(targetDir);
                }
                else
                {
                    Console.WriteLine($"File format not recognized: {filename}");
                    return(true);
                }
            }
            return(false);
        }