/// <summary>
        /// Creates and loads the JMX file
        /// </summary>
        private IJMXFile LoadJMXFile(string Path)
        {
            // Instance to be created and returned as result
            IJMXFile file = null;

            using (FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader br = new BinaryReader(fs))
                {
                    // Read file type and create format
                    var header = new string(br.ReadChars(12));
                    switch (header)
                    {
                    case "JMXVRES 0109":
                        file = new JMXVRES_0109();
                        break;

                    default:
                        throw new FileFormatException("JMX Header not found! File not supported.");
                    }
                    // Load it
                    fs.Seek(0, SeekOrigin.Begin);
                    file.Load(fs);
                }
            }
            return(file);
        }
Exemplo n.º 2
0
        public override object GetClassFrom(JMXStructure Structure)
        {
            JMXVRES_0109 file = new JMXVRES_0109();

            // Unknown flags
            file.Flag01 = (int)((JMXAttribute)Structure.Childs[0]).Value;
            file.Flag02 = (int)((JMXAttribute)Structure.Childs[1]).Value;
            file.Flag03 = (int)((JMXAttribute)Structure.Childs[2]).Value;
            file.Flag04 = (int)((JMXAttribute)Structure.Childs[3]).Value;
            file.Flag05 = (int)((JMXAttribute)Structure.Childs[4]).Value;

            // Object info
            file.ObjectInfo = (ObjectGeneralInfo)((ObjectGeneralInfoVM)Structure.Childs[5]).GetClass();

            // Reserved
            file.UnkBuffer = ((JMXStructure)Structure.Childs[6]).GetChildList <byte>().ToArray();

            // FileOffset.Collision
            file.CollisionMesh      = (string)((JMXAttribute)Structure.Childs[7]).Value;
            file.CollisionBox01     = (BoundingBoxF)((BoundingBoxVM)Structure.Childs[8]).GetClass();
            file.CollisionBox02     = (BoundingBoxF)((BoundingBoxVM)Structure.Childs[9]).GetClass();
            file.UseCollisionMatrix = (bool)((JMXAttribute)Structure.Childs[10]).Value;
            file.CollisionMatrix    = (Matrix4x4)((Matrix4x4VM)Structure.Childs[11]).GetClass();

            // FileOffset.Material
            file.MaterialSet = ((JMXStructure)Structure.Childs[12]).GetChildList <PrimMtrlSet>();

            // FileOffset.Mesh
            file.MeshSet = ((JMXStructure)Structure.Childs[13]).GetChildList <PrimMesh>();

            // FileOffset.Animation
            file.AnimationTypeVersion    = (uint)((JMXAttribute)Structure.Childs[14]).Value;
            file.AnimationTypeUserDefine = (uint)((JMXAttribute)Structure.Childs[15]).Value;
            file.AnimationSet            = ((JMXStructure)Structure.Childs[16]).GetChildList <PrimAnimation>();

            // FileOffset.Skeleton
            file.HasSkeleton    = (bool)((JMXAttribute)Structure.Childs[17]).Value;
            file.SkeletonPath   = (string)((JMXAttribute)Structure.Childs[18]).Value;
            file.AttachmentBone = (string)((JMXAttribute)Structure.Childs[19]).Value;

            // FileOffset.MeshGroups
            file.MeshGroups = ((JMXStructure)Structure.Childs[20]).GetChildList <PrimMeshGroup>();

            // FileOffset.AnimationGroup
            file.AnimationGroups = ((JMXStructure)Structure.Childs[21]).GetChildList <PrimAniGroup>();

            // FileOffset.ModPalette
            file.SystemModSets = ((JMXStructure)Structure.Childs[22]).GetChildList <ModDataSet>();
            file.AniModSets    = ((JMXStructure)Structure.Childs[23]).GetChildList <ModDataSet>();

            // Extra
            file.ResourceAttachable = (ResAttachable)((ResAttachableVM)Structure.Childs[24]).GetClass();

            return(file);
        }
Exemplo n.º 3
0
 public JMXVRESVM(JMXVRES_0109 JMXFile) : base(JMXFile.Format, true)
 {
     AddChildFormats();
     CreateNodes(JMXFile);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Converts the structure into a JMXFile.
        /// This method only work with a root JMXStructure
        /// </summary>
        public IJMXFile ToJMXFile()
        {
            // Read format
            string header = (string)((JMXAttribute)Childs[0]).Value;

            if (header == JMXVRES_0109.FileHeader)
            {
                JMXVRES_0109 file = new JMXVRES_0109();
                file.Header = header;
                // Pointers will be calculated in the process
                // Flags
                file.FlagUInt01 = (uint)((JMXAttribute)Childs[9]).Value;
                file.FlagUInt02 = (uint)((JMXAttribute)Childs[10]).Value;
                file.FlagUInt03 = (uint)((JMXAttribute)Childs[11]).Value;
                file.FlagUInt04 = (uint)((JMXAttribute)Childs[12]).Value;
                file.FlagUInt05 = (uint)((JMXAttribute)Childs[13]).Value;
                // Details
                file.ResourceType = (ResourceType)((JMXOption)Childs[14]).Value;
                file.Name         = (string)((JMXAttribute)Childs[15]).Value;
                var nodeChilds = ((JMXStructure)Childs[16]).Childs;
                file.UnkByteArray01 = new byte[nodeChilds.Count];
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    file.UnkByteArray01[i] = (byte)((JMXAttribute)nodeChilds[i]).Value;
                }

                // Pointer.BoundingBox
                file.RootMesh      = (string)((JMXAttribute)Childs[17]).Value;
                nodeChilds         = ((JMXStructure)Childs[18]).Childs;
                file.BoundingBox01 = new float[nodeChilds.Count];
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    file.BoundingBox01[i] = (float)((JMXAttribute)nodeChilds[i]).Value;
                }
                nodeChilds         = ((JMXStructure)Childs[19]).Childs;
                file.BoundingBox02 = new float[nodeChilds.Count];
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    file.BoundingBox02[i] = (float)((JMXAttribute)nodeChilds[i]).Value;
                }
                nodeChilds             = ((JMXStructure)Childs[20]).Childs;
                file.ExtraBoundingData = new byte[nodeChilds.Count];
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    file.ExtraBoundingData[i] = (byte)((JMXAttribute)nodeChilds[i]).Value;
                }

                // Pointer.Material
                nodeChilds     = ((JMXStructure)Childs[21]).Childs;
                file.Materials = new List <JMXVRES_0109.Material>(nodeChilds.Count);
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    // Create
                    var material = new JMXVRES_0109.Material();
                    file.Materials.Add(material);
                    // Copy
                    var nodeClass = ((JMXStructure)nodeChilds[i]).Childs;
                    material.Index = (uint)((JMXAttribute)nodeClass[0]).Value;
                    material.Path  = (string)((JMXAttribute)nodeClass[1]).Value;
                }

                // Pointer.Mesh
                nodeChilds  = ((JMXStructure)Childs[22]).Childs;
                file.Meshes = new List <JMXVRES_0109.Mesh>(nodeChilds.Count);
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    // Create
                    var mesh = new JMXVRES_0109.Mesh();
                    file.Meshes.Add(mesh);
                    // Copy
                    var nodeClass = ((JMXStructure)nodeChilds[i]).Childs;
                    mesh.Path      = (string)((JMXAttribute)nodeClass[0]).Value;
                    mesh.UnkUInt01 = (uint)((JMXAttribute)nodeClass[1]).Value;
                }

                // Pointer.Animation
                file.UnkUInt01  = (uint)((JMXAttribute)Childs[23]).Value;
                file.UnkUInt02  = (uint)((JMXAttribute)Childs[24]).Value;
                nodeChilds      = ((JMXStructure)Childs[25]).Childs;
                file.Animations = new List <JMXVRES_0109.Animation>(nodeChilds.Count);
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    // Create
                    var animation = new JMXVRES_0109.Animation();
                    file.Animations.Add(animation);
                    // Copy
                    var nodeClass = ((JMXStructure)nodeChilds[i]).Childs;
                    animation.Path = (string)((JMXAttribute)nodeClass[0]).Value;
                }

                // Pointer.Skeleton
                nodeChilds     = ((JMXStructure)Childs[26]).Childs;
                file.Skeletons = new List <JMXVRES_0109.Skeleton>(nodeChilds.Count);
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    // Create
                    var skeleton = new JMXVRES_0109.Skeleton();
                    file.Skeletons.Add(skeleton);
                    // Copy
                    var nodeClass = ((JMXStructure)nodeChilds[i]).Childs;
                    skeleton.Path      = (string)((JMXAttribute)nodeClass[0]).Value;
                    skeleton.ExtraBone = (string)((JMXAttribute)nodeClass[1]).Value;
                }

                // Pointer.MeshGroup
                nodeChilds      = ((JMXStructure)Childs[27]).Childs;
                file.MeshGroups = new List <JMXVRES_0109.MeshGroup>(nodeChilds.Count);
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    // Create
                    var meshGroup = new JMXVRES_0109.MeshGroup();
                    file.MeshGroups.Add(meshGroup);
                    // Copy
                    var nodeClass = ((JMXStructure)nodeChilds[i]).Childs;
                    meshGroup.Name = (string)((JMXAttribute)nodeClass[0]).Value;
                    var _nodeChilds = ((JMXStructure)nodeClass[1]).Childs;
                    meshGroup.FileIndexes = new uint[_nodeChilds.Count];
                    for (int j = 0; j < _nodeChilds.Count; j++)
                    {
                        meshGroup.FileIndexes[j] = (uint)((JMXAttribute)_nodeChilds[j]).Value;
                    }
                }

                // Pointer.AnimationGroups
                nodeChilds           = ((JMXStructure)Childs[28]).Childs;
                file.AnimationGroups = new List <JMXVRES_0109.AnimationGroup>(nodeChilds.Count);
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    // Create
                    var animationGroup = new JMXVRES_0109.AnimationGroup();
                    file.AnimationGroups.Add(animationGroup);
                    // Copy
                    var nodeClass = ((JMXStructure)nodeChilds[i]).Childs;
                    animationGroup.Name = (string)((JMXAttribute)nodeClass[0]).Value;
                    var _nodeChilds = ((JMXStructure)nodeClass[1]).Childs;
                    animationGroup.Entries = new List <JMXVRES_0109.AnimationGroup.Entry>();;
                    for (int j = 0; j < _nodeChilds.Count; j++)
                    {
                        // Create
                        var entry = new JMXVRES_0109.AnimationGroup.Entry();
                        animationGroup.Entries.Add(entry);
                        // Copy
                        var _nodeClass = ((JMXStructure)_nodeChilds[j]).Childs;
                        entry.Type      = (ResourceAnimationType)((JMXOption)_nodeClass[0]).Value;
                        entry.FileIndex = (uint)((JMXAttribute)_nodeClass[1]).Value;
                        var __nodeChilds = ((JMXStructure)_nodeClass[2]).Childs;
                        entry.Events = new List <JMXVRES_0109.AnimationGroup.Entry.Event>();
                        for (int k = 0; k < __nodeChilds.Count; k++)
                        {
                            // Create
                            var _event = new JMXVRES_0109.AnimationGroup.Entry.Event();
                            entry.Events.Add(_event);
                            // Copy
                            var __nodeClass = ((JMXStructure)__nodeChilds[k]).Childs;
                            _event.KeyTime   = (uint)((JMXAttribute)__nodeClass[0]).Value;
                            _event.Type      = (uint)((JMXAttribute)__nodeClass[1]).Value;
                            _event.UnkUInt01 = (uint)((JMXAttribute)__nodeClass[2]).Value;
                            _event.UnkUInt02 = (uint)((JMXAttribute)__nodeClass[3]).Value;
                        }
                        entry.WalkingLength = (float)((JMXAttribute)_nodeClass[3]).Value;
                        __nodeChilds        = ((JMXStructure)_nodeClass[4]).Childs;
                        entry.WalkPoints    = new List <JMXVRES_0109.AnimationGroup.Entry.Point>();
                        for (int k = 0; k < __nodeChilds.Count; k++)
                        {
                            // Create
                            var point = new JMXVRES_0109.AnimationGroup.Entry.Point();
                            entry.WalkPoints.Add(point);
                            // Copy
                            var __nodeClass = ((JMXStructure)__nodeChilds[k]).Childs;
                            point.X = (float)((JMXAttribute)__nodeClass[0]).Value;
                            point.Y = (float)((JMXAttribute)__nodeClass[1]).Value;
                        }
                    }
                }

                // Pointer.SoundEffect
                nodeChilds = ((JMXStructure)Childs[29]).Childs;
                file.SoundEffectUndecodedBytes = new byte[nodeChilds.Count];
                for (int i = 0; i < nodeChilds.Count; i++)
                {
                    file.SoundEffectUndecodedBytes[i] = (byte)((JMXAttribute)nodeChilds[i]).Value;
                }

                // Return result
                return(file);
            }
            return(null);
        }