public static Model LoadObject(string id)
        {
            Model obj = null;

            LoadingTaskMan.DoLoadingTaskSynchronous($"LOAD_OBJ_{id}", $"Loading object {id}...", progress =>
            {
                if (GameType == GameTypes.DS3 || GameType == GameTypes.BB || GameType == GameTypes.SDT)
                {
                    var chrbnd = BND4.Read(GetInterrootPath($@"obj\{id}.objbnd.dcx"));

                    obj = new Model(progress, id, chrbnd, 0, null, null);
                }
                else if (GameType == GameTypes.DS1)
                {
                    var chrbnd = BND3.Read(GetInterrootPath($@"obj\{id}.objbnd"));

                    obj = new Model(progress, id, chrbnd, 0, null, null);
                }
                else if (GameType == GameTypes.DS1R)
                {
                    var chrbnd = BND4.Read(GetInterrootPath($@"obj\{id}.objbnd.dcx"));

                    obj = new Model(progress, id, chrbnd, 0, null, null);
                }

                Scene.AddModel(obj);

                var texturesToLoad = obj.MainMesh.GetAllTexNamesToLoad();

                LoadingTaskMan.DoLoadingTask($"LOAD_OBJ_{id}_TEX",
                                             "Loading additional object textures...", innerProgress =>
                {
                    if (GameType == GameTypes.DS1)
                    {
                        foreach (var tex in texturesToLoad)
                        {
                            TexturePool.AddTpfFromPath(GetInterrootPath($@"map\tx\{tex}.tpf"));
                        }
                    }
                    else if (GameType == GameTypes.DS3 || GameType == GameTypes.SDT || GameType == GameTypes.BB)
                    {
                        int objGroup      = int.Parse(id.Substring(1)) / 1_0000;
                        string mapDirName = GetInterrootPath($@"map\m{objGroup:D2}");
                        var tpfBnds       = GameDataManager.GetInterrootFiles(mapDirName, "*.tpfbhd");
                        foreach (var t in tpfBnds)
                        {
                            TexturePool.AddSpecificTexturesFromBinder(t, texturesToLoad, directEntryNameMatch: true);
                        }
                    }
                    obj.MainMesh.TextureReloadQueued = true;
                });
            });

            return(obj);
        }
示例#2
0
        public static void AddInterrootTPFFolder(string folderPath, bool dcx = false, bool directDdsFetches = false)
        {
            var tpfs = GameDataManager.GetInterrootFiles(folderPath, dcx ? "*.tpf.dcx" : "*.tpf");

            foreach (var t in tpfs)
            {
                string shortName = Utils.GetShortIngameFileName(t).ToLower();
                if (directDdsFetches)
                {
                    foreach (var tex in TPF.Read(t).Textures)
                    {
                        AddFetchDDS(tex.Bytes, tex.Name);
                    }
                }
                else
                {
                    AddFetchTPF(TPF.Read(File.ReadAllBytes(t)), shortName);
                }
            }
        }
        public static Model LoadCharacter(string id)
        {
            Model chr = null;

            LoadingTaskMan.DoLoadingTaskSynchronous($"LOAD_CHR_{id}", $"Loading character {id}...", progress =>
            {
                if (GameType == GameTypes.DS3 || GameType == GameTypes.SDT)
                {
                    var chrbnd          = BND4.Read(GetInterrootPath($@"chr\{id}.chrbnd.dcx"));
                    IBinder texbnd      = null;
                    IBinder extraTexbnd = null;
                    IBinder anibnd      = null;

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.texbnd.dcx")))
                    {
                        texbnd = BND4.Read(GetInterrootPath($@"chr\{id}.texbnd.dcx"));
                    }

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.texbnd.dcx")))
                    {
                        extraTexbnd = BND4.Read(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.texbnd.dcx"));
                    }

                    if (GameType == GameTypes.SDT)
                    {
                        if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.anibnd.dcx.2010")))
                        {
                            anibnd = BND4.Read(GetInterrootPath($@"chr\{id}.anibnd.dcx.2010"));
                        }
                    }
                    else
                    {
                        if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.anibnd.dcx")))
                        {
                            anibnd = BND4.Read(GetInterrootPath($@"chr\{id}.anibnd.dcx"));
                        }
                    }

                    chr = new Model(progress, id, chrbnd, 0, anibnd, texbnd,
                                    ignoreStaticTransforms: true, additionalTexbnd: extraTexbnd);
                }
                else if (GameType == GameTypes.DS1)
                {
                    var chrbnd          = BND3.Read(GetInterrootPath($@"chr\{id}.chrbnd"));
                    IBinder anibnd      = null;
                    IBinder texbnd      = null;
                    IBinder extraTexbnd = null;

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.anibnd")))
                    {
                        anibnd = BND3.Read(GetInterrootPath($@"chr\{id}.anibnd"));
                    }

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.chrbnd")))
                    {
                        extraTexbnd = BND3.Read(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.chrbnd"));
                    }

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.chrtpfbdt")))
                    {
                        var chrtpfbhd = chrbnd.Files.FirstOrDefault(fi => fi.Name.ToLower().EndsWith(".chrtpfbhd"));

                        if (chrtpfbhd != null)
                        {
                            texbnd = BXF3.Read(chrtpfbhd.Bytes, GetInterrootPath($@"chr\{id}.chrtpfbdt"));
                        }
                    }

                    chr = new Model(progress, id, chrbnd, 0, anibnd, texbnd,
                                    possibleLooseTpfFolder: $@"chr\{id}\",
                                    ignoreStaticTransforms: true, additionalTexbnd: extraTexbnd);
                }
                else if (GameType == GameTypes.DS1R)
                {
                    var chrbnd          = BND3.Read(GetInterrootPath($@"chr\{id}.chrbnd.dcx"));
                    IBinder anibnd      = null;
                    IBinder texbnd      = null;
                    IBinder extraTexbnd = null;

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.anibnd.dcx.2010")))
                    {
                        anibnd = BND3.Read(GetInterrootPath($@"chr\{id}.anibnd.dcx.2010"));
                    }
                    else if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.anibnd.dcx")))
                    {
                        anibnd = BND3.Read(GetInterrootPath($@"chr\{id}.anibnd.dcx"));
                    }

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.chrbnd.dcx")))
                    {
                        extraTexbnd = BND3.Read(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.chrbnd.dcx"));
                    }

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.chrtpfbdt")))
                    {
                        var chrtpfbhd = chrbnd.Files.FirstOrDefault(fi => fi.Name.ToLower().EndsWith(".chrtpfbhd"));

                        if (chrtpfbhd != null)
                        {
                            texbnd = BXF3.Read(chrtpfbhd.Bytes, GetInterrootPath($@"chr\{id}.chrtpfbdt"));
                        }
                    }

                    chr = new Model(progress, id, chrbnd, 0, anibnd, texbnd,
                                    possibleLooseTpfFolder: $@"chr\{id}\",
                                    ignoreStaticTransforms: true, additionalTexbnd: extraTexbnd);
                }
                else if (GameType == GameTypes.BB)
                {
                    var chrbnd          = BND4.Read(GetInterrootPath($@"chr\{id}.chrbnd.dcx"));
                    IBinder anibnd      = null;
                    IBinder extraTexbnd = null;

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id}.anibnd.dcx")))
                    {
                        anibnd = BND4.Read(GetInterrootPath($@"chr\{id}.anibnd.dcx"));
                    }

                    if (System.IO.File.Exists(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.chrbnd.dcx")))
                    {
                        extraTexbnd = BND4.Read(GetInterrootPath($@"chr\{id.Substring(0, 4)}9.chrbnd.dcx"));
                    }

                    chr = new Model(progress, id, chrbnd, 0, anibnd, texbnd: null,
                                    additionalTpfNames: new List <string> {
                        GetInterrootPath($@"chr\{id}_2.tpf.dcx")
                    },
                                    possibleLooseTpfFolder: $@"chr\{id}\",
                                    ignoreStaticTransforms: true, additionalTexbnd: extraTexbnd);
                }

                Scene.AddModel(chr);
            });

            if (id == "c0000")
            {
                chr.IS_PLAYER = true;

                LoadingTaskMan.DoLoadingTask("c0000_ANIBNDs",
                                             "Loading additional player ANIBNDs...", progress =>
                {
                    string[] anibnds = GameDataManager.GetInterrootFiles($@"chr",
                                                                         GameType == GameTypes.DS1 ? "c0000_*.anibnd" : "c0000_*.anibnd.dcx")
                                       .OrderBy(fn =>
                    {
                        var fnCheck = fn.ToLower();
                        if (fnCheck.Contains("lo"))
                        {
                            return(0);
                        }
                        else if (fnCheck.Contains("md"))
                        {
                            return(1);
                        }
                        else if (fnCheck.Contains("hi"))
                        {
                            return(2);
                        }
                        else
                        {
                            return(3);
                        }
                    }).ToArray();

                    for (int i = 0; i < anibnds.Length; i++)
                    {
                        IBinder anibnd = null;

                        string anibndName = anibnds[i];

                        if ((GameType == GameTypes.SDT || GameType == GameTypes.DS1R) && System.IO.File.Exists(anibnds[i] + ".2010"))
                        {
                            anibndName = anibnds[i] + ".2010";
                        }

                        if (BND3.Is(anibndName))
                        {
                            anibnd = BND3.Read(anibndName);
                        }
                        else
                        {
                            anibnd = BND4.Read(anibndName);
                        }

                        chr.AnimContainer.LoadAdditionalANIBND(anibnd, null);

                        progress.Report(1.0 * i / anibnds.Length);
                    }

                    progress.Report(1);

                    Scene.EnableModelDrawing2();
                });
            }
            else
            {
                var additionalAnibnds = GameDataManager.GetInterrootFiles($@"chr", $"{id}_*.anibnd*");

                if (additionalAnibnds.Count > 0)
                {
                    LoadingTaskMan.DoLoadingTask($"{id}_ANIBNDs",
                                                 "Loading additional character ANIBNDs...", progress =>
                    {
                        for (int i = 0; i < additionalAnibnds.Count; i++)
                        {
                            IBinder anibnd = null;

                            string anibndName = additionalAnibnds[i];

                            if ((GameType == GameTypes.SDT || GameType == GameTypes.DS1R) && System.IO.File.Exists(additionalAnibnds[i] + ".2010"))
                            {
                                anibndName = additionalAnibnds[i] + ".2010";
                            }

                            if (BND3.Is(anibndName))
                            {
                                anibnd = BND3.Read(anibndName);
                            }
                            else
                            {
                                anibnd = BND4.Read(anibndName);
                            }

                            chr.AnimContainer.LoadAdditionalANIBND(anibnd, null);

                            progress.Report(1.0 * i / additionalAnibnds.Count);
                        }

                        Scene.EnableModelDrawing2();
                    });
                }
            }

            return(chr);
        }