示例#1
0
        public void Load(System.IO.Stream stream)
        {
            CanSave = false;

            using (var reader = new FileReader(stream))
            {
                reader.SetByteOrder(true);

                Text = FileName;
                while (!reader.EndOfStream)
                {
                    ChunkHeader chunk = new ChunkHeader();
                    chunk.Position   = reader.Position;
                    chunk.Identifier = reader.ReadUInt32();
                    uint unk = reader.ReadUInt32();
                    chunk.ChunkSize   = reader.ReadUInt32();
                    chunk.ChunkId     = reader.ReadUInt32();
                    chunk.NextFilePtr = reader.ReadUInt32();
                    chunk.FileSize    = reader.ReadUInt32();
                    uint unk2 = reader.ReadUInt32();
                    uint unk3 = reader.ReadUInt32();
                    Chunks.Add(chunk);

                    var Identifer = chunk.Identifier.Reverse();
                    switch (Identifer)
                    {
                    case ChunkTextureFile:
                        SWUTexture texture = new SWUTexture();
                        reader.SeekBegin(chunk.Position + 72);
                        texture.ImageKey         = "texture";
                        texture.SelectedImageKey = "texture";
                        texture.ReadChunk(reader);
                        chunk.ChunkData = texture;
                        if (chunk.ChunkSize > 244)
                        {
                            reader.Seek(chunk.Position + 244, System.IO.SeekOrigin.Begin);
                            chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
                            texture.Text   = chunk.FileName;
                        }
                        Nodes.Add(texture);
                        break;

                    case ChunkMetaInfo:
                        break;

                    case ChunkAnimInfo:
                        if (chunk.ChunkSize > 0xB0)
                        {
                            reader.Seek(chunk.Position + 0xB0, System.IO.SeekOrigin.Begin);
                            chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
                        }
                        break;

                    case ChunkAnimData:
                        AnimationFile animFile = new AnimationFile();
                        animFile.Read(reader);
                        chunk.ChunkData = animFile;
                        break;

                    case ChunkSkeletonData:
                        SkeletonFile skelFile = new SkeletonFile();
                        skelFile.Read(reader);
                        chunk.ChunkData = skelFile;
                        break;

                    case ChunkModelData:
                        ModelFile modelFile = new ModelFile();
                        modelFile.Read(reader);
                        chunk.ChunkData = modelFile;
                        break;

                    case ChunkMaterialData:
                        MaterialFile matFile = new MaterialFile();
                        matFile.Read(reader);
                        chunk.ChunkData = matFile;
                        break;
                    }

                    reader.Seek(chunk.Position + chunk.ChunkSize, System.IO.SeekOrigin.Begin);
                }

                ReadGPUFile(FilePath);
            }

            TreeHelper.CreateFileDirectory(this);
        }
示例#2
0
        private void ReadGPUFile(string FileName)
        {
            string path = FileName.Replace("cpu", "gpu");

            if (!System.IO.File.Exists(path))
            {
                return;
            }

            int offset = 0;

            //Read the data based on CPU chunk info
            using (var reader = new FileReader(path))
            {
                for (int i = 0; i < Chunks.Count; i++)
                {
                    if (Chunks[i].FileSize != 0 || Chunks[i].FileName != string.Empty || Chunks[i].ChunkData != null)
                    {
                        long pos = reader.Position;

                        var identifer = Chunks[i].Identifier.Reverse();

                        var fileInfo = new FileInfo();

                        //Get CPU chunk data
                        if (Chunks[i].ChunkData != null)
                        {
                            if (Chunks[i].ChunkData is SWUTexture)
                            {
                                SWUTexture texFile = (SWUTexture)Chunks[i].ChunkData;
                                if (Chunks[i].FileSize != 0)
                                {
                                    texFile.ImageData = reader.ReadBytes((int)Chunks[i].FileSize);
                                }

                                continue;
                            }
                            if (Chunks[i].ChunkData is AnimationFile)
                            {
                                AnimationFile animFile = (AnimationFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is SkeletonFile)
                            {
                                SkeletonFile animFile = (SkeletonFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is MaterialFile)
                            {
                                MaterialFile animFile = (MaterialFile)Chunks[i].ChunkData;
                                fileInfo.FileName = animFile.FileName;
                                fileInfo.FileData = animFile.Data;
                            }
                            if (Chunks[i].ChunkData is ModelFile)
                            {
                                ModelFile modelFile = (ModelFile)Chunks[i].ChunkData;
                                fileInfo.FileName = modelFile.FileName;

                                byte[] BufferData = new byte[0];
                                if (Chunks[i].FileSize != 0)
                                {
                                    BufferData = reader.ReadBytes((int)Chunks[i].FileSize);
                                }

                                fileInfo.FileData = Utils.CombineByteArray(modelFile.Data, modelFile.Data2, BufferData);


                                //Don't advance the stream unless the chunk has a pointer
                                if (Chunks[i].NextFilePtr != 0)
                                {
                                    reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                                }
                            }
                        }
                        else //Else get the data from GPU
                        {
                            if (Chunks[i].FileName != string.Empty)
                            {
                                fileInfo.FileName = $"{Chunks[i].FileName}";
                            }
                            else
                            {
                                fileInfo.FileName = $"{i} {Chunks[i].ChunkId} {identifer.ToString("X")}";
                            }

                            if (Chunks[i].FileSize != 0)
                            {
                                fileInfo.FileData = reader.ReadBytes((int)Chunks[i].FileSize);
                            }
                            else
                            {
                                fileInfo.FileData = new byte[0];
                            }
                        }

                        files.Add(fileInfo);

                        //Don't advance the stream unless the chunk has a pointer
                        if (Chunks[i].NextFilePtr != 0)
                        {
                            reader.Seek(pos + Chunks[i].NextFilePtr, System.IO.SeekOrigin.Begin);
                        }
                    }
                }
            }
        }