private MMDX ReadMMDXChunk(BlizzHeader chunk, BinaryReader bin) { //List of M2 filenames, but are still named after MDXs internally. Have to rename! var m2FilesChunk = bin.ReadBytes((int)chunk.Size); MMDX mmdx = new MMDX(); var str = new StringBuilder(); List <uint> offsets = new List <uint>(); for (var i = 0; i < m2FilesChunk.Length; i++) { if (m2FilesChunk[i] == '\0') { m2Files.Add(str.ToString()); offsets.Add((uint)(i - str.ToString().Length)); str = new StringBuilder(); } else { str.Append((char)m2FilesChunk[i]); } } mmdx.filenames = m2Files.ToArray(); mmdx.offsets = offsets.ToArray(); return(mmdx); }
public MCSE ReadMCSESubChunk(BlizzHeader subchunk, BinaryReader subbin) { MCSE sechunk = new MCSE(); sechunk.raw = subbin.ReadBytes((int)subchunk.Size); return(sechunk); }
private void ReadMWMOChunk(BinaryReader bin, BlizzHeader chunk) { var wmoFilesChunk = bin.ReadBytes((int)chunk.Size); var str = new StringBuilder(); for (var i = 0; i < wmoFilesChunk.Length; i++) { if (wmoFilesChunk[i] == '\0') { if (str.Length > 1) { if (!CASC.FileExists(str.ToString())) { Console.WriteLine("WMO file does not exist!!! {0}", str.ToString()); new WoWFormatLib.Utils.MissingFile(str.ToString()); } } str = new StringBuilder(); } else { str.Append((char)wmoFilesChunk[i]); } } }
private MWMO ReadMWMOChunk(BlizzHeader chunk, BinaryReader bin) { //List of WMO filenames var wmoFilesChunk = bin.ReadBytes((int)chunk.Size); MWMO mwmo = new MWMO(); var str = new StringBuilder(); List <uint> offsets = new List <uint>(); for (int i = 0; i < wmoFilesChunk.Length; i++) { if (wmoFilesChunk[i] == '\0') { wmoFiles.Add(str.ToString()); offsets.Add((uint)(i - str.ToString().Length)); str = new StringBuilder(); } else { str.Append((char)wmoFilesChunk[i]); } } mwmo.offsets = offsets.ToArray(); mwmo.filenames = wmoFiles.ToArray(); return(mwmo); }
private void ReadTEX(string filename, Stream tex) { var bin = new BinaryReader(tex); BlizzHeader chunk; long position = 0; while (position < tex.Length) { tex.Position = position; chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32()); chunk.Flip(); position = tex.Position + chunk.Size; switch (chunk.ToString()) { case "TXVR": ReadTXVRChunk(bin); continue; case "TXFN": ReadTXFNChunk(bin, chunk); continue; case "TXBT": case "TXMD": continue; default: throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename)); } } }
private void ReadTXFNChunk(BinaryReader bin, BlizzHeader chunk) { //List of BLP filenames var blpFilesChunk = bin.ReadBytes((int)chunk.Size); var str = new StringBuilder(); for (var i = 0; i < blpFilesChunk.Length; i++) { if (blpFilesChunk[i] == '\0') { if (str.Length > 1) { str.Replace("..", "."); str.Append(".blp"); //Filenames in TEX dont have have BLP extensions if (!CASC.FileExists(str.ToString())) { new WoWFormatLib.Utils.MissingFile(str.ToString()); } } str = new StringBuilder(); } else { str.Append((char)blpFilesChunk[i]); } } }
private void ReadWDL(string filename, Stream wdl) { var bin = new BinaryReader(wdl); BlizzHeader chunk; long position = 0; while (position < wdl.Length) { wdl.Position = position; chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32()); chunk.Flip(); position = wdl.Position + chunk.Size; switch (chunk.ToString()) { case "MVER": ReadMVERChunk(bin); continue; case "MWMO": ReadMWMOChunk(bin, chunk); continue; case "MWID": case "MODF": case "MAOF": //contains MARE and MAHO subchunks case "MARE": case "MAOC": //New in WoD case "MAHO": continue; default: throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename)); } } }
public MTEX ReadMTEXChunk(BlizzHeader chunk, BinaryReader bin) { MTEX txchunk = new MTEX(); //List of BLP filenames var blpFilesChunk = bin.ReadBytes((int)chunk.Size); var str = new StringBuilder(); for (var i = 0; i < blpFilesChunk.Length; i++) { if (blpFilesChunk[i] == '\0') { blpFiles.Add(str.ToString()); if (!CASC.FileExists(str.ToString())) { Console.WriteLine("BLP file does not exist!!! {0}", str.ToString()); new WoWFormatLib.Utils.MissingFile(str.ToString()); } str = new StringBuilder(); } else { str.Append((char)blpFilesChunk[i]); } } txchunk.filenames = blpFiles.ToArray(); return(txchunk); }
private void ReadMAINChunk(BinaryReader bin, BlizzHeader chunk, String filename) { if (chunk.Size != 4096 * 8) { throw new Exception("MAIN size is wrong! (" + chunk.Size.ToString() + ")"); } for (var x = 0; x < 64; x++) { for (var y = 0; y < 64; y++) { var flags = bin.ReadUInt32(); var unused = bin.ReadUInt32(); if (flags == 1) { //ADT exists //var adtreader = new ADTReader(); //var adtfilename = filename.Replace(".WDT", "_" + y + "_" + x + ".adt"); //blizz flips these //adtreader.LoadADT(adtfilename); int[] xy = new int[] { y, x }; tiles.Add(xy); } } } }
public MOGI[] ReadMOGIChunk(BlizzHeader chunk, BinaryReader bin, uint num) { var groupInfo = new MOGI[num]; for (var i = 0; i < num; i++) { groupInfo[i] = bin.Read <MOGI>(); } return(groupInfo); }
public MCNK ReadMCNKChunk(BlizzHeader chunk, BinaryReader bin) { //256 of these chunks per file MCNK mapchunk = new MCNK(); mapchunk.header = bin.Read <MCNKheader>(); MemoryStream stream = new MemoryStream(bin.ReadBytes((int)chunk.Size - 128)); var subbin = new BinaryReader(stream); BlizzHeader subchunk; long subpos = 0; while (subpos < stream.Length) { subbin.BaseStream.Position = subpos; subchunk = new BlizzHeader(subbin.ReadChars(4), subbin.ReadUInt32()); subchunk.Flip(); subpos = stream.Position + subchunk.Size; switch (subchunk.ToString()) { case "MCVT": mapchunk.vertices = ReadMCVTSubChunk(subchunk, subbin); break; case "MCCV": mapchunk.vertexShading = ReadMCCVSubChunk(subchunk, subbin); break; case "MCNR": mapchunk.normals = ReadMCNRSubChunk(subchunk, subbin); break; case "MCSE": mapchunk.soundEmitters = ReadMCSESubChunk(subchunk, subbin); break; case "MCBB": mapchunk.blendBatches = ReadMCBBSubChunk(subchunk, subbin); break; case "MCLQ": case "MCLV": continue; default: throw new Exception(String.Format("Found unknown header at offset {1} \"{0}\" while we should've already read them all!", subchunk.ToString(), subpos.ToString())); } } return(mapchunk); }
private void ReadObjFile(string filename, Stream adtObjStream, ref BlizzHeader chunk) { var bin = new BinaryReader(adtObjStream); long position = 0; adtfile.objects = new Obj(); while (position < adtObjStream.Length) { adtObjStream.Position = position; chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32()); chunk.Flip(); position = adtObjStream.Position + chunk.Size; if (chunk.Is("MVER")) { if (bin.ReadUInt32() != 18) { throw new Exception("Unsupported ADT version!"); } continue; } if (chunk.Is("MMDX")) { adtfile.objects.m2Names = ReadMMDXChunk(chunk, bin); continue; } if (chunk.Is("MMID")) { adtfile.objects.m2NameOffsets = ReadMMIDChunk(chunk, bin); continue; } if (chunk.Is("MWMO")) { adtfile.objects.wmoNames = ReadMWMOChunk(chunk, bin); continue; } if (chunk.Is("MWID")) { adtfile.objects.wmoNameOffsets = readMWIDChunk(chunk, bin); continue; } if (chunk.Is("MDDF")) { adtfile.objects.models = ReadMWIDChunk(chunk, bin); continue; } if (chunk.Is("MODF")) { adtfile.objects.worldModels = ReadMODFChunk(chunk, bin); continue; } if (chunk.Is("MCNK")) { continue; } // Only has MCRD and other useless things nobody cares about! throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename)); } }
public MCVT ReadMCVTSubChunk(BlizzHeader chunk, BinaryReader bin) { MCVT vtchunk = new MCVT(); vtchunk.vertices = new float[145]; for (int i = 0; i < 145; i++) { vtchunk.vertices[i] = bin.ReadSingle(); } return(vtchunk); }
public MCBB[] ReadMCBBSubChunk(BlizzHeader subchunk, BinaryReader subbin) { var count = subchunk.Size / 20; MCBB[] bbchunk = new MCBB[count]; for (int i = 0; i < count; i++) { bbchunk[i] = subbin.Read <MCBB>(); } return(bbchunk); }
private MOMT[] ReadMOMTChunk(BlizzHeader chunk, BinaryReader bin, uint num) { var materials = new MOMT[num]; //Console.WriteLine(num + " materials!"); for (var i = 0; i < num; i++) { materials[i] = bin.Read <MOMT>(); bin.ReadBytes(16); } return(materials); }
private MOBA[] ReadMOBAChunk(BlizzHeader subchunk, BinaryReader subbin) { var numBatches = subchunk.Size / 24; //24 bytes per MOBA //Console.WriteLine(numBatches + " batches!"); var batches = new MOBA[numBatches]; for (var i = 0; i < numBatches; i++) { batches[i] = subbin.Read <MOBA>(); } return(batches); }
public MOVT[] ReadMOVTChunk(BlizzHeader chunk, BinaryReader bin) { var numVerts = chunk.Size / (sizeof(float) * 3); //Console.WriteLine(numVerts + " vertices!"); var vertices = new MOVT[numVerts]; for (var i = 0; i < numVerts; i++) { vertices[i].vector = bin.Read <Vector3>(); } return(vertices); }
public MONR[] ReadMONRChunk(BlizzHeader chunk, BinaryReader bin) { var numNormals = chunk.Size / (sizeof(float) * 3); //Console.WriteLine(numNormals + " normals!"); var normals = new MONR[numNormals]; for (var i = 0; i < numNormals; i++) { normals[i].normal = bin.Read <Vector3>(); } return(normals); }
private MOVI[] ReadMOVIChunk(BlizzHeader chunk, BinaryReader bin) { var numIndices = chunk.Size / sizeof(ushort); //Console.WriteLine(numIndices + " indices!"); var indices = new MOVI[numIndices]; for (var i = 0; i < numIndices; i++) { indices[i].indice = bin.ReadUInt16(); } return(indices); }
private MOPY[] ReadMOPYChunk(BlizzHeader subchunk, BinaryReader subbin) { var numMaterials = subchunk.Size / 2; //Console.WriteLine(numMaterials + " material infos!"); var materials = new MOPY[numMaterials]; for (var i = 0; i < numMaterials; i++) { materials[i] = subbin.Read <MOPY>(); } return(materials); }
private MOTV[] ReadMOTVChunk(BlizzHeader subchunk, BinaryReader subbin) { var numCoords = subchunk.Size / (sizeof(float) * 2); //Console.WriteLine(numCoords + " texturecords!"); var textureCoords = new MOTV[numCoords]; for (var i = 0; i < numCoords; i++) { textureCoords[i].X = subbin.ReadSingle(); textureCoords[i].Y = subbin.ReadSingle(); } return(textureCoords); }
private MWID readMWIDChunk(BlizzHeader chunk, BinaryReader bin) { var count = chunk.Size / 4; MWID mwid = new MWID(); mwid.offsets = new uint[count]; for (int i = 0; i < count; i++) { mwid.offsets[i] = bin.ReadUInt32(); } return(mwid); }
public MCLY[] ReadMCLYSubChunk(BlizzHeader chunk, BinaryReader bin) { var count = chunk.Size / 16; MCLY[] mclychunks = new MCLY[count]; for (int i = 0; i < count; i++) { mclychunks[i].textureId = bin.ReadUInt32(); mclychunks[i].flags = (mclyFlags)bin.ReadUInt32(); mclychunks[i].offsetInMCAL = bin.ReadUInt32(); mclychunks[i].effectId = bin.ReadInt32(); } return(mclychunks); }
public MCNR ReadMCNRSubChunk(BlizzHeader chunk, BinaryReader bin) { MCNR nrchunk = new MCNR(); nrchunk.normal_0 = new short[145]; nrchunk.normal_1 = new short[145]; nrchunk.normal_2 = new short[145]; for (int i = 0; i < 145; i++) { nrchunk.normal_0[i] = bin.ReadSByte(); nrchunk.normal_1[i] = bin.ReadSByte(); nrchunk.normal_2[i] = bin.ReadSByte(); } return(nrchunk); }
private MODF ReadMODFChunk(BlizzHeader chunk, BinaryReader bin) { MODF modf = new MODF(); var count = chunk.Size / 64; //64 bytes per entry? // Console.WriteLine(count + " MODF entries!"); modf.entries = new MODFEntry[count]; for (int i = 0; i < count; i++) { modf.entries[i] = bin.Read <MODFEntry>(); } return(modf); }
public MOHD ReadMOHDChunk(BlizzHeader chunk, BinaryReader bin, string filename) { //Header for the map object. 64 bytes. // var MOHDChunk = bin.ReadBytes((int)chunk.Size); var header = new MOHD(); header.nMaterials = bin.ReadUInt32(); header.nGroups = bin.ReadUInt32(); header.nPortals = bin.ReadUInt32(); header.nLights = bin.ReadUInt32(); header.nModels = bin.ReadUInt32(); //Console.WriteLine(" " + nGroups.ToString() + " group(s)"); return(header); }
private MDDF ReadMWIDChunk(BlizzHeader chunk, BinaryReader bin) { MDDF mddf = new MDDF(); var count = chunk.Size / 36; //36 bytes per entry? // Console.WriteLine(count + " MDDF entries!"); mddf.entries = new MDDFEntry[count]; for (int i = 0; i < count; i++) { mddf.entries[i] = bin.Read <MDDFEntry>(); } return(mddf); }
public MCCV ReadMCCVSubChunk(BlizzHeader chunk, BinaryReader bin) { MCCV vtchunk = new MCCV(); vtchunk.red = new byte[145]; vtchunk.green = new byte[145]; vtchunk.blue = new byte[145]; vtchunk.alpha = new byte[145]; for (int i = 0; i < 145; i++) { vtchunk.red[i] = bin.ReadByte(); vtchunk.green[i] = bin.ReadByte(); vtchunk.blue[i] = bin.ReadByte(); vtchunk.alpha[i] = bin.ReadByte(); } return(vtchunk); }
private MODD[] ReadMODDChunk(BlizzHeader chunk, BinaryReader bin) { var numDoodads = chunk.Size / 40; var doodads = new MODD[numDoodads]; for (var i = 0; i < numDoodads; i++) { var raw_offset = bin.ReadBytes(3); doodads[i].offset = (uint)(raw_offset[0] | raw_offset[1] << 8 | raw_offset[2] << 16); doodads[i].flags = bin.ReadByte(); doodads[i].position = bin.Read <Vector3>(); doodads[i].rotation = bin.Read <Quaternion>(); doodads[i].scale = bin.ReadSingle(); doodads[i].color = bin.ReadBytes(4); } return(doodads); }
private void ReadTexFile(string filename, Stream adtTexStream, ref BlizzHeader chunk) { var bin = new BinaryReader(adtTexStream); long position = 0; int MCNKi = 0; adtfile.texChunks = new TexMCNK[16 * 16]; while (position < adtTexStream.Length) { adtTexStream.Position = position; chunk = new BlizzHeader(bin.ReadChars(4), bin.ReadUInt32()); chunk.Flip(); position = adtTexStream.Position + chunk.Size; if (chunk.Is("MVER")) { if (bin.ReadUInt32() != 18) { throw new Exception("Unsupported ADT version!"); } continue; } if (chunk.Is("MAMP")) { continue; } if (chunk.Is("MTEX")) { adtfile.textures = ReadMTEXChunk(chunk, bin); continue; } if (chunk.Is("MCNK")) { adtfile.texChunks[MCNKi] = ReadTexMCNKChunk(chunk, bin); MCNKi++; continue; } if (chunk.Is("MTXP")) { continue; } throw new Exception(String.Format("{2} Found unknown header at offset {1} \"{0}\" while we should've already read them all!", chunk.ToString(), position.ToString(), filename)); } }