Ejemplo n.º 1
0
        public TRData(string path)
        {
            Path       = path;
            Filesystem = new SortedDictionary <string, PackedFile>();

            // find GLM files in the specified path and subfolders
            string[] foundFiles = System.IO.Directory.GetFiles(path, "*.glm", System.IO.SearchOption.AllDirectories);

            GLMFiles = new List <GLMFile>(foundFiles.Length);
            foreach (string file in foundFiles)
            {
                GLMFile glmFile = new GLMFile(path, file);
                GLMFiles.Add(glmFile);
            }

            // put all the files into a hash for faster access
            foreach (GLMFile glm in GLMFiles)
            {
                foreach (PackedFile file in glm.Files)
                {
                    PackedFile currentFile = null;
                    Filesystem.TryGetValue(file.Filename, out currentFile);

                    if (currentFile != null)
                    {
                        FastConsole.WriteLine(String.Format("Duplicated filename {0} in archives {1} and {2}", file.Filename, currentFile.Parent.Filename, glm.Filename));
                        continue;
                    }

                    Filesystem.Add(file.Filename, file);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: Chunk.cs Proyecto: Sadral/TRRM
        protected bool ReadHeader(BinaryReader reader)
        {
            Header = new ChunkHeader()
            {
                Tag     = reader.ReadBytesAsString(4),
                Size    = reader.ReadUInt32(),
                Version = reader.ReadUInt32(),
                Unknown = reader.ReadUInt32()
            };

            string tag = ChunkUtils.Tag(Type());

            if (Header.Tag != tag)
            {
                FastConsole.WriteLine(String.Format("{0}: Invalid tag.", tag));
                return(false);
            }

            if (Header.Unknown != 0)
            {
                Debugger.Break();
            }

            FastConsole.WriteLine(String.Format("[{0}] Version {1} ", Header.Tag, Header.Version));
            return(true);
        }
Ejemplo n.º 3
0
Archivo: Chunk.cs Proyecto: Sadral/TRRM
 protected void LogInfo(params string[] data)
 {
     for (int i = 0; i < data.Length; i++)
     {
         string tag = ChunkUtils.Tag(Type());
         FastConsole.WriteLine(String.Format("{0}: {1}", tag, data[i]));
     }
 }
Ejemplo n.º 4
0
Archivo: Chunk.cs Proyecto: Sadral/TRRM
        protected bool IsValidVersion(params UInt32[] validVersions)
        {
            for (int i = 0; i < validVersions.Length; i++)
            {
                if (Header.Version == validVersions[i])
                {
                    return(true);
                }
            }

            string tag = ChunkUtils.Tag(Type());

            FastConsole.WriteLine(String.Format("{0}{1}: Invalid version.", tag, "Chunk"));
            return(false);
        }
Ejemplo n.º 5
0
        private bool ReadHeader(BinaryReader reader)
        {
            UInt32 headerOffset = 0;
            string check        = reader.ReadBytesAsString(4, true);

            if (check != "CHNK")
            {
                reader.BaseStream.Seek(-4, SeekOrigin.End);
                headerOffset = reader.ReadUInt32();
            }

            reader.BaseStream.Seek(headerOffset, SeekOrigin.Begin);

            ChunkFileHeader header = new ChunkFileHeader()
            {
                Magic    = reader.ReadBytesAsString(4, true),
                Type     = reader.ReadChar(),
                Unknown1 = reader.ReadChar(),
                Unknown2 = reader.ReadBytesAsString(2)
            };

            if (!header.Valid())
            {
                FastConsole.WriteLine("ChunkFile: Header is not valid.");
                return(false);
            }

            if (header.Type == 'T')
            {
                FastConsole.WriteLine("ChunkFile: Text format not supported.");
                return(false);
            }


            if (headerOffset > 0)
            {
                // GLM Pack File
                FastConsole.WriteLine("This Chunk file is a pack. Use GLMFile class to load it.");
                return(false);
            }

            return(true);
        }
Ejemplo n.º 6
0
Archivo: Chunk.cs Proyecto: Sadral/TRRM
        public static ChunkType PeekNextChunk(BinaryReader reader)
        {
            bool enough = ((reader.BaseStream.Length - reader.BaseStream.Position) >= 4);

            if (!enough)
            {
                return(ChunkType.None);
            }

            string tag = reader.ReadBytesAsString(4);

            reader.BaseStream.Seek(-4, SeekOrigin.Current);
            ChunkType type = ChunkUtils.Type(tag);

            if (type == ChunkType.None)
            {
                FastConsole.WriteLine(String.Format("Next chunk: {0} ({1})", type, tag));
            }
            return(type);
        }
Ejemplo n.º 7
0
        public override bool Load(BinaryReader reader)
        {
            Children = new List <Chunk>();

            Start(reader);
            if (!ReadHeader(reader) || !IsValidVersion(1, 2, 3))
            {
                return(false);
            }

            if (Header.Version == 3)
            {
                Unknown1 = reader.ReadSingle();
                FastConsole.WriteLine("unk1" + Unknown1);
            }

            // Auto Assault hack
            {
                ChunkType nextChunk = ChunkUtils.PeekNextChunk(reader);
                if (nextChunk == ChunkType.None)
                {
                    //UInt32 blockSize = reader.ReadUInt32();
                    UInt32 count = reader.ReadUInt32();
                    for (UInt32 i = 0; i < count; i++)
                    {
                        string shaderName = reader.ReadCString();
                    }
                }
            }

            // bounding box
            BoundingBox = new BBOXChunk();
            Debug.Assert(BoundingBox.Load(reader));
            //cp definitions
            CPDefinitions = new CPDGChunk();
            Debug.Assert(CPDefinitions.Load(reader));

            // R&D
            // Seems RTTI stuff
            //if ( ChunkUtils.PeekNextChunk( reader ) == ChunkType.None )
            {
                UInt32 entryCount = reader.ReadUInt32();
                LogInfo("rtti count: " + entryCount);

                for (UInt32 i = 0; i < entryCount; i++)
                {
                    Int32 entryID = reader.ReadInt32(); // not sure

                    UInt32 subCount = reader.ReadUInt32();
                    LogInfo("rtti entry: id " + entryID + " subentries " + subCount);
                    for (UInt32 j = 0; j < subCount; j++)
                    {
                        string key   = reader.ReadCString();
                        string value = reader.ReadCString();
                        LogInfo("rtti entry: " + key + " : " + value);
                    }
                }
            }

            // skeleton
            Skeleton = new PSKEChunk();
            Debug.Assert(Skeleton.Load(reader));

            Int32 morphCount = reader.ReadInt32();

            for (Int32 i = 0; i < morphCount; i++)
            {
                // TODO gfxMorphWeightArray
                return(false);
                //throw new NotImplementedException();
            }

            Int32 piecesCount = reader.ReadInt32();

            Children = new List <Chunk>();
            for (Int32 i = 0; i < piecesCount; i++)
            {
                ChunkType nextChunk = ChunkUtils.PeekNextChunk(reader);
                Chunk     chunk     = ChunkUtils.Instance(nextChunk);
                Debug.Assert(chunk.Load(reader));
                Children.Add(chunk);
            }

            Int32 shadowsCount = reader.ReadInt32();

            Shadows = new List <Chunk>();
            for (Int32 i = 0; i < shadowsCount; i++)
            {
                ChunkType nextChunk = ChunkUtils.PeekNextChunk(reader);
                Chunk     chunk     = ChunkUtils.Instance(nextChunk);
                Debug.Assert(chunk.Load(reader));
                Shadows.Add(chunk);
            }

            if (Header.Version >= 2)
            {
                // some kind of flag
                bool hasLODHandler = reader.ReadBoolean();
                if (hasLODHandler)
                {
                    // gfxLODHandler
                    // LDAA LDSD
                    ChunkType nextChunk = ChunkUtils.PeekNextChunk(reader);
                    Skip(reader);
                }
            }

            End(reader);
            return(true);
        }