/// <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); }
/// <summary> /// Creates a root node containing everything from the given file /// </summary> public static JMXStructure Create(IJMXFile File) { JMXStructure root = new JMXStructure(File.Format); // Create nodes if (File is JMXVRES_0109 jmxvres_0109) { root.Childs.Add(new JMXAttribute("Header", jmxvres_0109.Header, false)); // Pointers root.Childs.Add(new JMXAttribute("Pointer.Material", jmxvres_0109.PointerMaterial, false)); root.Childs.Add(new JMXAttribute("Pointer.Mesh", jmxvres_0109.PointerMesh, false)); root.Childs.Add(new JMXAttribute("Pointer.Skeleton", jmxvres_0109.PointerSkeleton, false)); root.Childs.Add(new JMXAttribute("Pointer.Animation", jmxvres_0109.PointerAnimation, false)); root.Childs.Add(new JMXAttribute("Pointer.MeshGroup", jmxvres_0109.PointerMeshGroup, false)); root.Childs.Add(new JMXAttribute("Pointer.AnimationGroup", jmxvres_0109.PointerAnimationGroup, false)); root.Childs.Add(new JMXAttribute("Pointer.SoundEffect", jmxvres_0109.PointerSoundEffect, false)); root.Childs.Add(new JMXAttribute("Pointer.BoundingBox", jmxvres_0109.PointerBoundingBox, false)); // Flags root.Childs.Add(new JMXAttribute("Flags.UInt01", jmxvres_0109.FlagUInt01)); root.Childs.Add(new JMXAttribute("Flags.UInt02", jmxvres_0109.FlagUInt02)); root.Childs.Add(new JMXAttribute("Flags.UInt03", jmxvres_0109.FlagUInt03)); root.Childs.Add(new JMXAttribute("Flags.UInt04", jmxvres_0109.FlagUInt04)); root.Childs.Add(new JMXAttribute("Flags.UInt05", jmxvres_0109.FlagUInt05)); // Details root.Childs.Add(new JMXOption("ResourceType", jmxvres_0109.ResourceType, GetValues <object>(typeof(ResourceType)))); root.Childs.Add(new JMXAttribute("Name", jmxvres_0109.Name)); var nodeLevel1 = new JMXStructure("UnkByteArray01"); for (int i = 0; i < jmxvres_0109.UnkByteArray01.Length; i++) { nodeLevel1.Childs.Add(new JMXAttribute("[" + i + "]", jmxvres_0109.UnkByteArray01[i])); } root.Childs.Add(nodeLevel1); // Pointer.BoundingBox root.Childs.Add(new JMXAttribute("RootMesh", jmxvres_0109.RootMesh)); nodeLevel1 = new JMXStructure("BoundingBox01"); for (int i = 0; i < jmxvres_0109.BoundingBox01.Length; i++) { nodeLevel1.Childs.Add(new JMXAttribute("[" + i + "]", jmxvres_0109.BoundingBox01[i])); } root.Childs.Add(nodeLevel1); nodeLevel1 = new JMXStructure("BoundingBox02"); for (int i = 0; i < jmxvres_0109.BoundingBox02.Length; i++) { nodeLevel1.Childs.Add(new JMXAttribute("[" + i + "]", jmxvres_0109.BoundingBox02[i])); } root.Childs.Add(nodeLevel1); nodeLevel1 = new JMXStructure("ExtraBoundingData", typeof(byte)); for (int i = 0; i < jmxvres_0109.ExtraBoundingData.Length; i++) { nodeLevel1.Childs.Add(new JMXAttribute("[" + i + "]", jmxvres_0109.ExtraBoundingData[i])); } root.Childs.Add(nodeLevel1); // Pointer.Material nodeLevel1 = new JMXStructure("Materials", typeof(JMXVRES_0109.Material)); for (int i = 0; i < jmxvres_0109.Materials.Count; i++) { var nodeClassLevel1 = new JMXStructure("[" + i + "]"); nodeClassLevel1.Childs.Add(new JMXAttribute("Index", jmxvres_0109.Materials[i].Index)); nodeClassLevel1.Childs.Add(new JMXAttribute("Path", jmxvres_0109.Materials[i].Path)); nodeLevel1.Childs.Add(nodeClassLevel1); } root.Childs.Add(nodeLevel1); // Pointer.Mesh nodeLevel1 = new JMXStructure("Meshes", typeof(JMXVRES_0109.Mesh)); for (int i = 0; i < jmxvres_0109.Meshes.Count; i++) { var nodeClassLevel1 = new JMXStructure("[" + i + "]"); nodeClassLevel1.Childs.Add(new JMXAttribute("Path", jmxvres_0109.Meshes[i].Path)); nodeClassLevel1.Childs.Add(new JMXAttribute("UnkUInt01", jmxvres_0109.Meshes[i].UnkUInt01)); nodeLevel1.Childs.Add(nodeClassLevel1); } root.Childs.Add(nodeLevel1); // Pointer.Animation root.Childs.Add(new JMXAttribute("UnkUInt01", jmxvres_0109.UnkUInt01)); root.Childs.Add(new JMXAttribute("UnkUInt02", jmxvres_0109.UnkUInt02)); nodeLevel1 = new JMXStructure("Animations", typeof(JMXVRES_0109.Animation)); for (int i = 0; i < jmxvres_0109.Animations.Count; i++) { var nodeClassLevel1 = new JMXStructure("[" + i + "]"); nodeClassLevel1.Childs.Add(new JMXAttribute("Path", jmxvres_0109.Animations[i].Path)); nodeLevel1.Childs.Add(nodeClassLevel1); } root.Childs.Add(nodeLevel1); // Pointer.Skeleton nodeLevel1 = new JMXStructure("Skeletons", typeof(JMXVRES_0109.Skeleton)); for (int i = 0; i < jmxvres_0109.Skeletons.Count; i++) { var nodeClassLevel1 = new JMXStructure("[" + i + "]"); nodeClassLevel1.Childs.Add(new JMXAttribute("Path", jmxvres_0109.Skeletons[i].Path)); nodeClassLevel1.Childs.Add(new JMXAttribute("ExtraBone", jmxvres_0109.Skeletons[i].ExtraBone)); nodeLevel1.Childs.Add(nodeClassLevel1); } root.Childs.Add(nodeLevel1); // Pointer.MeshGroup nodeLevel1 = new JMXStructure("MeshGroups", typeof(JMXVRES_0109.MeshGroup)); for (int i = 0; i < jmxvres_0109.MeshGroups.Count; i++) { var nodeClassLevel1 = new JMXStructure("[" + i + "]"); nodeClassLevel1.Childs.Add(new JMXAttribute("Name", jmxvres_0109.MeshGroups[i].Name)); var nodeLevel2 = new JMXStructure("FileIndexes", typeof(uint)); nodeClassLevel1.Childs.Add(nodeLevel2); for (int j = 0; j < jmxvres_0109.MeshGroups[i].FileIndexes.Length; j++) { nodeLevel2.Childs.Add(new JMXAttribute("[" + j + "]", jmxvres_0109.MeshGroups[i].FileIndexes[j])); } nodeLevel1.Childs.Add(nodeClassLevel1); } root.Childs.Add(nodeLevel1); // Pointer.AnimationGroup nodeLevel1 = new JMXStructure("AnimationGroups", typeof(JMXVRES_0109.AnimationGroup)); for (int i = 0; i < jmxvres_0109.AnimationGroups.Count; i++) { var nodeClassLevel1 = new JMXStructure("[" + i + "]"); nodeClassLevel1.Childs.Add(new JMXAttribute("Name", jmxvres_0109.AnimationGroups[i].Name)); var nodeLevel2 = new JMXStructure("Entries", typeof(JMXVRES_0109.AnimationGroup.Entry)); nodeClassLevel1.Childs.Add(nodeLevel2); for (int j = 0; j < jmxvres_0109.AnimationGroups[i].Entries.Count; j++) { var nodeClassLevel2 = new JMXStructure("[" + j + "]"); nodeClassLevel2.Childs.Add(new JMXOption("Type", jmxvres_0109.AnimationGroups[i].Entries[j].Type, GetValues <object>(typeof(ResourceAnimationType)))); nodeClassLevel2.Childs.Add(new JMXAttribute("FileIndex", jmxvres_0109.AnimationGroups[i].Entries[j].FileIndex)); var nodeLevel3 = new JMXStructure("Events", typeof(JMXVRES_0109.AnimationGroup.Entry.Event)); nodeClassLevel2.Childs.Add(nodeLevel3); for (int k = 0; k < jmxvres_0109.AnimationGroups[i].Entries[j].Events.Count; k++) { var nodeClassLevel3 = new JMXStructure("[" + k + "]"); nodeClassLevel3.Childs.Add(new JMXAttribute("KeyTime", jmxvres_0109.AnimationGroups[i].Entries[j].Events[k].KeyTime)); nodeClassLevel3.Childs.Add(new JMXAttribute("Type", jmxvres_0109.AnimationGroups[i].Entries[j].Events[k].Type)); nodeClassLevel3.Childs.Add(new JMXAttribute("UnkUInt01", jmxvres_0109.AnimationGroups[i].Entries[j].Events[k].UnkUInt01)); nodeClassLevel3.Childs.Add(new JMXAttribute("UnkUInt02", jmxvres_0109.AnimationGroups[i].Entries[j].Events[k].UnkUInt02)); nodeLevel3.Childs.Add(nodeClassLevel3); } nodeClassLevel2.Childs.Add(new JMXAttribute("WalkingLength", jmxvres_0109.AnimationGroups[i].Entries[j].WalkingLength)); nodeLevel3 = new JMXStructure("WalkPoints", typeof(JMXVRES_0109.AnimationGroup.Entry.Point)); nodeClassLevel2.Childs.Add(nodeLevel3); for (int k = 0; k < jmxvres_0109.AnimationGroups[i].Entries[j].WalkPoints.Count; k++) { var nodeClassLevel3 = new JMXStructure("[" + k + "]"); nodeClassLevel3.Childs.Add(new JMXAttribute("X", jmxvres_0109.AnimationGroups[i].Entries[j].WalkPoints[k].X)); nodeClassLevel3.Childs.Add(new JMXAttribute("Y", jmxvres_0109.AnimationGroups[i].Entries[j].WalkPoints[k].Y)); nodeLevel3.Childs.Add(nodeClassLevel3); } nodeLevel2.Childs.Add(nodeClassLevel2); } nodeLevel1.Childs.Add(nodeClassLevel1); } root.Childs.Add(nodeLevel1); // Pointer.SoundEffect nodeLevel1 = new JMXStructure("SoundEffectUndecodedBytes"); for (int i = 0; i < jmxvres_0109.SoundEffectUndecodedBytes.Length; i++) { nodeLevel1.Childs.Add(new JMXAttribute("[" + i + "]", jmxvres_0109.SoundEffectUndecodedBytes[i])); } root.Childs.Add(nodeLevel1); return(root); } return(null); }