public static DAT Load(string path) { FileInfo fi = new FileInfo(path); Logger.LogToFile(Logger.LogLevel.Info, "{0}", path); DAT dat = new DAT(); DatMesh D = new DatMesh(); int count; using (BEBinaryReader br = new BEBinaryReader(fi.OpenRead(), Encoding.Default)) { if (br.ReadUInt32() != 0x12 || br.ReadUInt32() != 0x8 || br.ReadUInt32() != 0xFACE || br.ReadUInt32() != 0x2) { Logger.LogToFile(Logger.LogLevel.Error, "{0} isn't a valid DAT file", path); return(null); } while (br.BaseStream.Position < br.BaseStream.Length) { int tag = (int)br.ReadUInt32(); int length = (int)br.ReadUInt32(); switch (tag) { case 54: // 00 00 00 36 D = new DatMesh() { UnknownAttribute = br.ReadUInt16(), // I think this is actually two byte values Name = br.ReadString() }; break; case 23: // 00 00 00 17 : vertex data count = (int)br.ReadUInt32(); for (int i = 0; i < count; i++) { D.Mesh.AddListVertex(br.ReadSingle(), br.ReadSingle(), br.ReadSingle()); } break; case 24: // 00 00 00 18 : UV co-ordinates count = (int)br.ReadUInt32(); for (int i = 0; i < count; i++) { D.Mesh.AddListUV(br.ReadSingle(), br.ReadSingle()); } break; case 53: // 00 00 00 35 : faces count = (int)br.ReadUInt32(); for (int i = 0; i < count; i++) { int faceID = D.Mesh.AddFace(br.ReadUInt16(), br.ReadUInt16(), br.ReadUInt16()); D.Mesh.Faces[faceID].SmoothingGroup = br.ReadUInt16(); br.ReadByte(); // number of edges, 0 and 3 = tri. 4 = quad. } break; case 22: // 00 00 00 16 : material list D.Mesh.Materials.AddRange(br.ReadStrings((int)br.ReadUInt32())); break; case 26: // 00 00 00 1A : face textures count = (int)br.ReadUInt32(); br.ReadBytes(4); // f**k knows what this is for (int i = 0; i < count; i++) { D.Mesh.SetMaterialForFace(i, br.ReadUInt16() - 1); } break; case 0: // EndOfFile D.Mesh.ProcessMesh(); dat.DatMeshes.Add(D); break; default: Logger.LogToFile(Logger.LogLevel.Error, "Unknown DAT tag: {0} ({1:x2})", tag, br.BaseStream.Position); return(null); } } } return(dat); }