Exemplo n.º 1
0
        static void ExtractTrm(string trmPath, string basePath = null)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(trmPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(trmPath));
            }

            using DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(trmPath)));
            // First entry is texture DAT
            using DatReader txmDat       = new DatReader(new MemoryStream(dat.GetData(0)));
            using ObjConverter converter = new ObjConverter(txmDat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            // Subsequent entries are train car DATs
            for (int i = 1; i < dat.EntriesCount; ++i)
            {
                using DatReader innerDat = new DatReader(new MemoryStream(dat.GetData(i)));
                // And within each train car DAT are PDBs
                for (int j = 0; j < innerDat.EntriesCount; ++j)
                {
                    using MemoryStream ms = new MemoryStream(innerDat.GetData(j));
                    BinaryReader br  = new BinaryReader(ms);
                    Pdb          pdb = new Pdb();
                    pdb.Read(br);
                    using StreamWriter sw = File.CreateText($"{basePath}.{i}_{j}.obj");
                    sw.WriteLine($"mtllib {mtlName}");
                    sw.WriteLine();

                    converter.ConvertObj(pdb, sw);
                }
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".");
            }
        }
Exemplo n.º 2
0
        static void ExtractMapAnim(string mapAnimPath, string basePath = null)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(mapAnimPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(mapAnimPath));
            }

            using DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(mapAnimPath)));
            // Second entry is texture DAT
            using DatReader txmDat       = new DatReader(new MemoryStream(dat.GetData(1)));
            using ObjConverter converter = new ObjConverter(txmDat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            // First entry is a collection of weird PDBs
            using DatReader pdbDat = new DatReader(new MemoryStream(dat.GetData(0)));
            for (int i = 0; i < pdbDat.EntriesCount; ++i)
            {
                using MemoryStream ms = new MemoryStream(pdbDat.GetData(i));
                // This is a DAT, but we're going to pretend it's a normal PDB
                BinaryReader br  = new BinaryReader(ms);
                Pdb          pdb = new Pdb();
                pdb.Read(br);
                using StreamWriter sw = File.CreateText($"{basePath}.{i}.obj");
                sw.WriteLine($"mtllib {mtlName}");
                sw.WriteLine();

                converter.ConvertObj(pdb, sw);
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".");
            }
        }
Exemplo n.º 3
0
        static void ExtractPdb(string pdbPath, string txmPath, string basePath = null, bool forceDirect = false)
        {
            if (basePath == null)
            {
                basePath = Path.ChangeExtension(pdbPath, null);
            }
            else
            {
                basePath = Path.Combine(basePath, Path.GetFileNameWithoutExtension(pdbPath));
            }

            DatReader dat = new DatReader(Utils.CheckDecompress(File.OpenRead(pdbPath)));

            using DatReader txmDat       = new DatReader(Utils.CheckDecompress(File.OpenRead(txmPath)));
            using ObjConverter converter = new ObjConverter(txmDat);
            string mtlPath = basePath + ".mtl";
            string mtlName = Path.GetFileName(mtlPath);

            for (int i = 0; i < dat.EntriesCount; ++i)
            {
                using MemoryStream ms = new MemoryStream(dat.GetData(i));
                BinaryReader br  = new BinaryReader(ms);
                Pdb          pdb = new Pdb();
                pdb.Read(br);
                using StreamWriter sw = File.CreateText($"{basePath}.{i}.obj");
                sw.WriteLine($"mtllib {mtlName}");
                sw.WriteLine();

                converter.ConvertObj(pdb, sw);
            }

            using (StreamWriter sw = File.CreateText(mtlPath))
            {
                converter.ExportTextures(sw, basePath + ".", forceDirect);
            }
        }