public uint Read(MemoryStream ms) { base.Read(ms, "MODR"); if (size > 0) { long end_chunk = ms.Position + size; while (ms.Position < end_chunk) { doodadrefs.Add(ms.ReadShort()); } } return size; }
public void TestStreamshort() { short obj = 100; using (MemoryStream ms = new MemoryStream()) { ms.WriteShort(obj); ms.Seek(0, SeekOrigin.Begin); short res = ms.ReadShort(); Assert.IsTrue(obj.Equals(res), "Streaming failed!"); } }
public uint Read(MemoryStream ms, long data_offset = 0) { type = (ushort)ms.ReadShort(); flags = (ushort)ms.ReadShort(); heightLevel1 = ms.ReadFloat(); heightLevel2 = ms.ReadFloat(); xOffset = (byte)ms.ReadByte(); yOffset = (byte)ms.ReadByte(); width = (byte)ms.ReadByte(); height = (byte)ms.ReadByte(); mask2_offset = (uint)ms.ReadInt32(); heightMap_offset = (uint)ms.ReadInt32(); long save_point = ms.Position; if (mask2_offset != 0 && height > 0) { ms.Position = data_offset + mask2_offset; mask2 = new List<byte>(sizeof(byte) * height); for (int i = 0; i < height; i++) mask2.Add((byte)ms.ReadByte()); } if (heightMap_offset != 0 && width * height > 0) { ms.Position = data_offset + heightMap_offset; heightMap = new List<float>(width * height); for (int i = 0; i < width * height; i++) heightMap.Add(ms.ReadFloat()); } ms.Position = save_point; return 0; }
public static object Deserialize(this IColumnSpec columnSpec, byte[] rawData) { object data; Type colType; switch (columnSpec.ColumnType) { default: data = Deserialize(columnSpec.ColumnType, rawData); break; case ColumnType.List: colType = columnSpec.CollectionValueType.ToType(); Type typedColl = typeof(ListInitializer<>).MakeGenericType(colType); ICollectionInitializer list = (ICollectionInitializer) Activator.CreateInstance(typedColl); using (MemoryStream ms = new MemoryStream(rawData)) { short nbElem = ms.ReadShort(); while (0 < nbElem) { byte[] elemRawData = ms.ReadShortBytes(); object elem = Deserialize(columnSpec.CollectionValueType, elemRawData); list.Add(elem); } data = list.Collection; } break; case ColumnType.Map: Type keyType = columnSpec.CollectionKeyType.ToType(); colType = columnSpec.CollectionValueType.ToType(); Type typedDic = typeof(DictionaryInitializer<,>).MakeGenericType(keyType, colType); IDictionaryInitializer dic = (IDictionaryInitializer) Activator.CreateInstance(typedDic); using (MemoryStream ms = new MemoryStream(rawData)) { short nbElem = ms.ReadShort(); while (0 < nbElem) { byte[] elemRawKey = ms.ReadShortBytes(); byte[] elemRawValue = ms.ReadShortBytes(); object key = Deserialize(columnSpec.CollectionValueType, elemRawKey); object value = Deserialize(columnSpec.CollectionValueType, elemRawValue); dic.Add(key, value); } data = dic.Collection; } break; case ColumnType.Set: colType = columnSpec.CollectionValueType.ToType(); Type typedSet = typeof(HashSetInitializer<>).MakeGenericType(colType); ICollectionInitializer set = (ICollectionInitializer) Activator.CreateInstance(typedSet); using (MemoryStream ms = new MemoryStream(rawData)) { short nbElem = ms.ReadShort(); while (0 < nbElem--) { byte[] elemRawData = ms.ReadShortBytes(); object elem = Deserialize(columnSpec.CollectionValueType, elemRawData); set.Add(elem); } data = set.Collection; } break; } return data; }
public uint Read(MemoryStream ms) { base.Read(ms, "MOGP"); nameIndex = (uint)ms.ReadInt32(); descriptionIndex = (uint)ms.ReadInt32(); flags = (uint)ms.ReadInt32(); bboxMin.X = ms.ReadFloat(); bboxMin.Y = ms.ReadFloat(); bboxMin.Z = ms.ReadFloat(); bboxMax.X = ms.ReadFloat(); bboxMax.Y = ms.ReadFloat(); bboxMax.Z = ms.ReadFloat(); moprIndex = (ushort)ms.ReadShort(); numMoprItems = (ushort)ms.ReadShort(); numBatchesA = (ushort)ms.ReadShort(); numBatchesB = (ushort)ms.ReadShort(); numBatchesC = (ushort)ms.ReadShort(); ms.Read(fogIndices, 0, fogIndices.Length); liquid = (uint)ms.ReadInt32(); wmoGroupId = (uint)ms.ReadInt32(); ms.Read(unknown, 0, unknown.Length); return size; }
public uint Read(MemoryStream ms) { base.Read(ms, "MOVI"); for (int i = 0; i < size / sizeof(ushort); i++) indices.Add(ms.ReadShort()); return size; }
public M2(mpq.Wrapper mpq_h, string name) { MemoryStream ms = new MemoryStream(mpq_h.GetFile(name)); // read in chunk by chunk ms.Read(id, 0, id.Length); ms.Read(version, 0, id.Length); nameLength = (uint) ms.ReadInt32(); nameOff = (uint)ms.ReadInt32(); flags = (uint)ms.ReadInt32(); ms.Read(pad0, 0, pad0.Length); numVertices = (uint) ms.ReadInt32(); verticesOff = (uint)ms.ReadInt32(); ms.Read(pad1, 0, pad1.Length); numBoundingTriangles = (uint)ms.ReadInt32(); boundingTriangleOff = (uint)ms.ReadInt32(); numBoundingVertices = (uint)ms.ReadInt32(); boundingVerticesOff = (uint)ms.ReadInt32(); numBoundingNormals = (uint)ms.ReadInt32(); boundingNormalsOff = (uint)ms.ReadInt32(); isCollide = numBoundingTriangles > 0; // ignore non collidable M2s if (!isCollide) return; // get M2 model name ms.Position = nameOff; byte[] _b = new byte[nameLength]; ms.Read(_b, 0, (int) nameLength); System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); _m2name = enc.GetString(_b); if (numVertices > 0) { ms.Position = verticesOff; for (int i = 0; i < numVertices; i++) { Vector3 v; v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat(); _vertices.Add(v); } } // get bounding triangles if (numBoundingTriangles > 0) { ms.Position = boundingTriangleOff; for (int i = 0; i < numBoundingTriangles; i++) { // in the file those are 16bit, so read short _boundingIndices.Add(ms.ReadShort()); } } // get bounding vertices if (numBoundingVertices > 0) { ms.Position = boundingVerticesOff; for (int i = 0; i < numBoundingVertices; i++) { Vector3 v; v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat(); _boundingVertices.Add(v); } } // get bounding normals if (numBoundingNormals > 0) { ms.Position = boundingNormalsOff; for (int i = 0; i < numBoundingNormals; i++) { Vector3 v; v.X = ms.ReadFloat(); v.Y = ms.ReadFloat(); v.Z = ms.ReadFloat(); _boundingNormals.Add(v); } } bbox = BoundingBox.CreateFromPoints(_boundingVertices); }
public uint Read(MemoryStream ms) { id = (uint)ms.ReadInt32(); uid = (uint)ms.ReadInt32(); pos.X = ms.ReadFloat(); pos.Y = ms.ReadFloat(); pos.Z = ms.ReadFloat(); rot.X = ms.ReadFloat(); rot.Y = ms.ReadFloat(); rot.Z = ms.ReadFloat(); scale = (ushort)ms.ReadShort(); flags = (ushort)ms.ReadShort(); return 0; }
public uint Read(MemoryStream ms) { id = (uint)ms.ReadInt32(); uid = (uint)ms.ReadInt32(); pos.X = ms.ReadFloat(); pos.Y = ms.ReadFloat(); pos.Z = ms.ReadFloat(); rot.X = ms.ReadFloat(); rot.Y = ms.ReadFloat(); rot.Z = ms.ReadFloat(); bbmin.X = ms.ReadFloat(); bbmin.Y = ms.ReadFloat(); bbmin.Z = ms.ReadFloat(); bbmax.X = ms.ReadFloat(); bbmax.Y = ms.ReadFloat(); bbmax.Z = ms.ReadFloat(); flags = (ushort)ms.ReadShort(); doodadSet = (ushort)ms.ReadShort(); nameSet = (ushort)ms.ReadShort(); padding = (ushort)ms.ReadShort(); if (doodadSet != 0) { int i = 0; } return 0; }
public void Read(MemoryStream ms) { startVertex = (ushort)ms.ReadShort(); numVertices = (ushort)ms.ReadShort(); normal.X = ms.ReadFloat(); normal.Y = ms.ReadFloat(); normal.Z = ms.ReadFloat(); unknown = (uint)ms.ReadInt32(); }
public static object Deserialize(this CqlColumn cqlColumn, byte[] rawData) { //skip parsing and return null value when rawData is null if (rawData == null) return null; object data; Type colType; switch (cqlColumn.CqlType) { default: data = Deserialize(cqlColumn.CqlType, rawData); break; case CqlType.List: if (!cqlColumn.CollectionValueType.HasValue) throw new CqlException("CqlColumn collection type must has its value type set"); colType = cqlColumn.CollectionValueType.Value.ToType(); Type typedColl = typeof(List<>).MakeGenericType(colType); var list = (IList)Activator.CreateInstance(typedColl); using (var ms = new MemoryStream(rawData)) { short nbElem = ms.ReadShort(); for (int i = 0; i < nbElem; i++) { byte[] elemRawData = ms.ReadShortByteArray(); object elem = Deserialize(cqlColumn.CollectionValueType.Value, elemRawData); list.Add(elem); } data = list; } break; case CqlType.Set: if (!cqlColumn.CollectionValueType.HasValue) throw new CqlException("CqlColumn collection type must has its value type set"); colType = cqlColumn.CollectionValueType.Value.ToType(); Type tempListType = typeof(List<>).MakeGenericType(colType); var tempList = (IList)Activator.CreateInstance(tempListType); using (var ms = new MemoryStream(rawData)) { short nbElem = ms.ReadShort(); for (int i = 0; i < nbElem; i++) { byte[] elemRawData = ms.ReadShortByteArray(); object elem = Deserialize(cqlColumn.CollectionValueType.Value, elemRawData); tempList.Add(elem); } Type typedSet = typeof(HashSet<>).MakeGenericType(colType); data = Activator.CreateInstance(typedSet, tempList); } break; case CqlType.Map: if (!cqlColumn.CollectionKeyType.HasValue) throw new CqlException("CqlColumn map type must has its key type set"); if (!cqlColumn.CollectionValueType.HasValue) throw new CqlException("CqlColumn map type must has its value type set"); Type keyType = cqlColumn.CollectionKeyType.Value.ToType(); colType = cqlColumn.CollectionValueType.Value.ToType(); Type typedDic = typeof(Dictionary<,>).MakeGenericType(keyType, colType); var dic = (IDictionary)Activator.CreateInstance(typedDic); using (var ms = new MemoryStream(rawData)) { short nbElem = ms.ReadShort(); for (int i = 0; i < nbElem; i++) { byte[] elemRawKey = ms.ReadShortByteArray(); byte[] elemRawValue = ms.ReadShortByteArray(); object key = Deserialize(cqlColumn.CollectionKeyType.Value, elemRawKey); object value = Deserialize(cqlColumn.CollectionValueType.Value, elemRawValue); dic.Add(key, value); } data = dic; } break; } return data; }