public static ExtractedM2 Process(string basePath, MapId mapId, string path) { basePath = Path.Combine(basePath, mapId.ToString()); var filePath = Path.Combine(basePath, path); filePath = Path.ChangeExtension(filePath, ".m2x"); if (!File.Exists(filePath)) { throw new FileNotFoundException("Extracted M2 file not found: {0}", filePath); } var m2 = new ExtractedM2(); using(var file = File.OpenRead(filePath)) using(var br = new BinaryReader(file)) { var type = br.ReadString(); if (type != fileType) { br.Close(); throw new InvalidDataException(string.Format("M2x file in invalid format: {0}", filePath)); } m2.Extents = br.ReadBoundingBox(); m2.BoundingVertices = br.ReadVector3List(); m2.BoundingTriangles = br.ReadIndex3List(); br.Close(); } return m2; }
public static ExtractedWMO Process(string basePath, MapId mapId, string path) { basePath = Path.Combine(basePath, mapId.ToString()); var filePath = Path.Combine(basePath, path); filePath = Path.ChangeExtension(filePath, ".wmo"); if (!File.Exists(filePath)) { throw new FileNotFoundException("Extracted M2 file not found: {0}", filePath); } var wmo = new ExtractedWMO(); using (var file = File.OpenRead(filePath)) using (var br = new BinaryReader(file)) { var type = br.ReadString(); if (type != fileType) { br.Close(); throw new InvalidDataException(string.Format("WMO file in invalid format: {0}", filePath)); } wmo.Extents = br.ReadBoundingBox(); wmo.WMOId = br.ReadUInt32(); ReadWMODoodadDefs(br, wmo); ReadWMOGroups(br, wmo); } return wmo; }
static void ReadHeader(BinaryReader br, M2Model model) { var header = model.Header = new ModelHeader(); header.Magic = br.ReadUInt32(); header.Version = br.ReadUInt32(); header.NameLength = br.ReadInt32(); header.NameOffset = br.ReadInt32(); header.GlobalModelFlags = (GlobalModelFlags) br.ReadUInt32(); br.ReadOffsetLocation(ref header.GlobalSequences); br.ReadOffsetLocation(ref header.Animations); br.ReadOffsetLocation(ref header.AnimationLookup); br.ReadOffsetLocation(ref header.Bones); br.ReadOffsetLocation(ref header.KeyBoneLookup); br.ReadOffsetLocation(ref header.Vertices); header.ViewCount = br.ReadUInt32(); br.ReadOffsetLocation(ref header.Colors); br.ReadOffsetLocation(ref header.Textures); br.ReadOffsetLocation(ref header.Transparency); br.ReadOffsetLocation(ref header.UVAnimation); br.ReadOffsetLocation(ref header.TexReplace); br.ReadOffsetLocation(ref header.RenderFlags); br.ReadOffsetLocation(ref header.BoneLookupTable); br.ReadOffsetLocation(ref header.TexLookup); br.ReadOffsetLocation(ref header.TexUnits); br.ReadOffsetLocation(ref header.TransLookup); br.ReadOffsetLocation(ref header.UVAnimLookup); header.VertexBox = br.ReadBoundingBox(); header.VertexRadius = br.ReadSingle(); header.BoundingBox = br.ReadBoundingBox(); header.BoundingRadius = br.ReadSingle(); br.ReadOffsetLocation(ref header.BoundingTriangles); br.ReadOffsetLocation(ref header.BoundingVertices); br.ReadOffsetLocation(ref header.BoundingNormals); br.ReadOffsetLocation(ref header.Attachments); br.ReadOffsetLocation(ref header.AttachLookup); br.ReadOffsetLocation(ref header.Events); br.ReadOffsetLocation(ref header.Lights); br.ReadOffsetLocation(ref header.Cameras); br.ReadOffsetLocation(ref header.CameraLookup); br.ReadOffsetLocation(ref header.RibbonEmitters); br.ReadOffsetLocation(ref header.ParticleEmitters); if (header.HasUnknownFinalPart) { br.ReadOffsetLocation(ref header.OptionalUnk); } br.BaseStream.Position = model.Header.NameOffset; //model.Name = Encoding.UTF8.GetString(br.ReadBytes(model.Header.NameLength)); model.Name = br.ReadCString(); }
public static WMOSubGroup ReadBuildingGroup(BinaryReader reader) { var group = new WMOSubGroup { Bounds = reader.ReadBoundingBox() }; Vector3[] vertices; var numVerts = reader.ReadUInt16(); if (numVerts > 0) { vertices = new Vector3[numVerts]; for (var i = 0; i < numVerts; i++) { vertices[i] = reader.ReadVector3(); } } else { vertices = null; } group.Vertices = vertices; group.Tree = ReadBSPTree(reader); return group; }
public static WMO ReadBuilding(BinaryReader reader) { var building = new WMO { Bounds = reader.ReadBoundingBox(), RotationModelY = reader.ReadSingle(), WorldPos = reader.ReadVector3() }; WMOSubGroup[] groups; var numGroups = reader.ReadUInt16(); if (numGroups > 0) { groups = new WMOSubGroup[numGroups]; for (var i = 0; i < numGroups; i++) { groups[i] = ReadBuildingGroup(reader); } } else { groups = null; } building.BuildingGroups = groups; return building; }
static void ReadMODF(BinaryReader fileReader, WDT wdt) { var type = fileReader.ReadUInt32(); var size = fileReader.ReadUInt32(); var endPos = fileReader.BaseStream.Position + size; while (fileReader.BaseStream.Position < endPos) { var objectDef = new MapObjectDefinition(); var nameIndex = fileReader.ReadInt32(); // 4 bytes objectDef.FilePath = wdt.WmoFiles[nameIndex]; objectDef.UniqueId = fileReader.ReadUInt32(); // 4 bytes objectDef.Position = fileReader.ReadVector3(); // 12 bytes objectDef.OrientationA = fileReader.ReadSingle(); // 4 Bytes objectDef.OrientationB = fileReader.ReadSingle(); // 4 Bytes objectDef.OrientationC = fileReader.ReadSingle(); // 4 Bytes objectDef.Extents = fileReader.ReadBoundingBox(); // 12*2 bytes objectDef.Flags = fileReader.ReadUInt16(); // 2 bytes objectDef.DoodadSetId = fileReader.ReadUInt16(); // 2 bytes objectDef.NameSet = fileReader.ReadUInt16(); // 2 bytes fileReader.ReadUInt16(); // padding wdt.WmoDefinitions.Add(objectDef); } }
private static void ReadWMODoodadDefs(BinaryReader br, ExtractedWMO wmo) { var numSets = br.ReadInt32(); var setList = new List<Dictionary<int, ExtractedWMOM2Definition>>(numSets); for (var i = 0; i < numSets; i++) { var numDefs = br.ReadInt32(); var defDict = new Dictionary<int, ExtractedWMOM2Definition>(numDefs); for (var j = 0; j < numDefs; j++) { var key = br.ReadInt32(); var def = new ExtractedWMOM2Definition { FilePath = br.ReadString(), Position = br.ReadVector3(), Extents = br.ReadBoundingBox(), WMOToModel = br.ReadMatrix(), ModeltoWMO = br.ReadMatrix() }; defDict.Add(key, def); } setList.Add(defDict); } wmo.WMOM2Defs = setList; }
private static void ReadModels(BinaryReader br, TreeReference<Model> tree) { var numModels = br.ReadInt32(); for (var i = 0; i < numModels; i++) { var bounds = br.ReadBoundingBox(); Vector3[] vertices; var numVertices = br.ReadInt32(); if (numVertices > 0) { vertices = new Vector3[numVertices]; for (var j = 0; j < numVertices; j++) { vertices[j] = br.ReadVector3(); } } else { vertices = null; } Index3[] indices; var numIndices = br.ReadInt32(); if (numIndices > 0) { indices = new Index3[numIndices]; for (var j = 0; j < numIndices; j++) { indices[j] = br.ReadIndex3(); } } else { indices = null; } var model = new Model { Bounds = bounds, Vertices = vertices, Triangles = indices }; tree.Tree.Insert(model); } }
private static void ReadWMOGroups(BinaryReader br, ExtractedWMO wmo) { var groupCount = br.ReadInt32(); var groupList = new List<ExtractedWMOGroup>(groupCount); for (int i = 0; i < groupCount; i++) { var group = new ExtractedWMOGroup(); group.Flags = (WMOGroupFlags) br.ReadUInt32(); group.Bounds = br.ReadBoundingBox(); group.GroupId = br.ReadUInt32(); group.ModelRefs = br.ReadInt32List(); group.HasLiquid = br.ReadBoolean(); if (group.HasLiquid) { ReadWMOGroupLiquidInfo(br, group); } group.WmoVertices = br.ReadVector3List(); ReadBSPTree(br, group); groupList.Add(group); } wmo.Groups = groupList; }
private static BuildingGroup ReadBuildingGroup(BinaryReader br) { var group = new BuildingGroup { Bounds = br.ReadBoundingBox() }; Vector3[] vertices; var numVerts = br.ReadInt32(); if (numVerts > 0) { vertices = new Vector3[numVerts]; for (var j = 0; j < numVerts; j++) { vertices[j] = br.ReadVector3(); } } else { vertices = null; } group.Vertices = vertices; group.Tree = ReadBSPTree(br); return group; }
private static void ReadBuildings(BinaryReader br, TreeReference<Building> tree) { var numBuildings = br.ReadInt32(); for (var i = 0; i < numBuildings; i++) { var bounds = br.ReadBoundingBox(); var invRot = br.ReadSingle(); var matrix = Matrix.CreateRotationY(((-1.0f*(invRot - 90)))*RadiansPerDegree); var center = br.ReadVector3(); BuildingGroup[] groups; var numGroups = br.ReadInt32(); if (numGroups > 0) { groups = new BuildingGroup[numGroups]; for (var j = 0; j < numGroups; j++) { groups[j] = ReadBuildingGroup(br); } } else { groups = null; } var building = new Building { Bounds = bounds, Center = center, InverseRotation = matrix, BuildingGroups = groups }; tree.Tree.Insert(building); } }
static void ReadMOGI(BinaryReader br, WMORoot wmo) { wmo.GroupInformation = new GroupInformation[wmo.Header.GroupCount]; for (int i = 0; i < wmo.GroupInformation.Length; i++) { var g = new GroupInformation { Flags = (WMOGroupFlags)br.ReadUInt32(), BoundingBox = br.ReadBoundingBox(), NameIndex = br.ReadInt32() }; wmo.GroupInformation[i] = g; } }
private static void ReadWMODefs(BinaryReader br, ExtractedADT adt) { var count = br.ReadInt32(); var wmoDefList = new List<ExtractedWMODefinition>(count); for (var i = 0; i < count; i++) { var def = new ExtractedWMODefinition { UniqueId = br.ReadUInt32(), FilePath = br.ReadString(), Extents = br.ReadBoundingBox(), Position = br.ReadVector3(), DoodadSetId = br.ReadUInt16(), WorldToWMO = br.ReadMatrix(), WMOToWorld = br.ReadMatrix() }; wmoDefList.Add(def); } adt.WMODefs = wmoDefList; }
private static void ReadMapM2Defs(BinaryReader br, ExtractedADT adt) { var count = br.ReadInt32(); var m2DefList = new List<ExtractedMapM2Definition>(count); for (var i = 0; i < count; i++) { var def = new ExtractedMapM2Definition { UniqueId = br.ReadUInt32(), FilePath = br.ReadString(), Extents = br.ReadBoundingBox(), Position = br.ReadVector3(), WorldToModel = br.ReadMatrix(), ModelToWorld = br.ReadMatrix() }; m2DefList.Add(def); } adt.M2Defs = m2DefList; }