Exemplo n.º 1
0
        /// <summary>
        /// Reads a file and loads it into the Inspector
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenFile(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new()
            {
                Filter = "All Supported Formats (*.*mdl, *.nj, *.gj, *.*lvl)|*.BFMDL;*.SA1MDL;*.SA2MDL;*.SA2BMDL;*.NJ;*.GJ;*.BFLVL;*.SA1LVL;*.SA2LVL;*.SA2BLVL"
                         + "|Model File (*.*mdl, *.nj, *.gj)|*.BFMDL;*.SA1MDL;*.SA2MDL;*.SA2BMDL;*.NJ;*.GJ"
                         + "|Level File (*.*lvl)|*.BFLVL;*.SA1LVL;*.SA2LVL;*.SA2BLVL"
            };

            if (ofd.ShowDialog() != true)
            {
                return;
            }

            byte[] file = File.ReadAllBytes(ofd.FileName);

            ModelFile mdlFile = ModelFile.Read(file, ofd.FileName);

            if (mdlFile != null)
            {
                loaded = mdlFile;
                Inspector.LoadNewObject(mdlFile);
                return;
            }


            LandTable ltbl = LandTable.ReadFile(file);

            if (ltbl != null)
            {
                loaded = ltbl;

                Inspector.LoadNewObject(ltbl);
                return;
            }
        }
Exemplo n.º 2
0
        public void Load(System.IO.Stream stream)
        {
            CanSave = false;

            using (var reader = new FileReader(stream))
            {
                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:
                        if (chunk.ChunkSize > 0x88)
                        {
                            reader.Seek(chunk.Position + 0x88, System.IO.SeekOrigin.Begin);
                            chunk.FileName = reader.ReadString(Syroot.BinaryData.BinaryStringFormat.ZeroTerminated);
                        }
                        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);
            }
        }
Exemplo n.º 3
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);
        }