protected internal override SoundEffect Read( ContentReader input, SoundEffect existingInstance ) { /* Swap endian - this is one of the very few places requiring this! * Note: This only affects the fmt chunk that's glued into the file. */ bool se = input.platform == 'x'; // Format block length uint formatLength = input.ReadUInt32(); // WaveFormatEx data ushort wFormatTag = Swap(se, input.ReadUInt16()); ushort nChannels = Swap(se, input.ReadUInt16()); uint nSamplesPerSec = Swap(se, input.ReadUInt32()); uint nAvgBytesPerSec = Swap(se, input.ReadUInt32()); ushort nBlockAlign = Swap(se, input.ReadUInt16()); ushort wBitsPerSample = Swap(se, input.ReadUInt16()); /* ushort cbSize =*/ input.ReadUInt16(); // Seek past the rest of this crap (cannot seek though!) input.ReadBytes((int)(formatLength - 18)); // Wavedata byte[] data = input.ReadBytes(input.ReadInt32()); // Loop information int loopStart = input.ReadInt32(); int loopLength = input.ReadInt32(); // Sound duration in milliseconds, unused input.ReadUInt32(); return(new SoundEffect( input.AssetName, data, 0, data.Length, wFormatTag, nChannels, nSamplesPerSec, nAvgBytesPerSec, nBlockAlign, wBitsPerSample, loopStart, loopLength )); }
static int ReadBoneReference(ContentReader reader, uint boneCount) { uint boneId; // Read the bone ID, which may be encoded as either an 8 or 32 bit value. if (boneCount < 255) { boneId = reader.ReadByte(); } else { boneId = reader.ReadUInt32(); } // Print out the bone ID. if (boneId != 0) { Debug.WriteLine("bone #{0}", boneId - 1); return((int)(boneId - 1)); } else { Debug.WriteLine("null"); } return(-1); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint count = input.ReadUInt32(); T[] array = existingInstance; if (array == null) { array = new T[count]; } #if WINRT if (typeof(T).GetTypeInfo().IsValueType) #else if (typeof(T).IsValueType) #endif { for (uint i = 0; i < count; i++) { array[i] = input.ReadObject <T>(elementReader); } } else { for (uint i = 0; i < count; i++) { int readerType = input.Read7BitEncodedInt(); array[i] = readerType > 0 ? input.ReadObject <T>(input.TypeReaders[readerType - 1]) : default(T); } } return(array); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint count = input.ReadUInt32(); T[] array = existingInstance; if (array == null) { array = new T[count]; } if (ReflectionHelpers.IsValueType(typeof(T))) { for (uint i = 0; i < count; i++) { array[i] = input.ReadObject <T>(elementReader); } } else { for (uint i = 0; i < count; i++) { var readerType = input.Read7BitEncodedInt(); array[i] = readerType > 0 ? input.ReadObject <T>(input.TypeReaders[readerType - 1]) : default(T); } } return(array); }
protected internal override SoundEffect Read( ContentReader input, SoundEffect existingInstance ) { // Format block length uint formatLength = input.ReadUInt32(); // WaveFormatEx data ushort wFormatTag = input.ReadUInt16(); ushort nChannels = input.ReadUInt16(); uint nSamplesPerSec = input.ReadUInt32(); uint nAvgBytesPerSec = input.ReadUInt32(); ushort nBlockAlign = input.ReadUInt16(); ushort wBitsPerSample = input.ReadUInt16(); /* ushort cbSize =*/ input.ReadUInt16(); // Seek past the rest of this crap (cannot seek though!) input.ReadBytes((int)(formatLength - 18)); // Wavedata byte[] data = input.ReadBytes(input.ReadInt32()); // Loop information int loopStart = input.ReadInt32(); int loopLength = input.ReadInt32(); // Sound duration in milliseconds, unused input.ReadUInt32(); return(new SoundEffect( input.AssetName, data, 0, data.Length, wFormatTag, nChannels, nSamplesPerSec, nAvgBytesPerSec, nBlockAlign, wBitsPerSample, loopStart, loopLength )); }
protected internal override Color Read(ContentReader input, Color existingInstance) { // There are 4 bytes in the .xnb // 80 80 80 FF that correspond to the values passed from the xml file as FF808080 uint color = input.ReadUInt32(); Color colorObj = new Color(); colorObj.PackedValue = color; return(colorObj); }
protected internal override VertexBuffer Read(ContentReader input, VertexBuffer existingInstance) { var declaration = input.ReadExternalReference <VertexDeclaration>(); var vertexCount = (int)input.ReadUInt32(); var data = input.ReadBytes(vertexCount * declaration.VertexStride); var buffer = new VertexBuffer(input.GraphicsDevice, declaration, vertexCount, BufferUsage.WriteOnly); buffer.SetData(data); return(buffer); }
protected internal override VertexBuffer Read(ContentReader input, VertexBuffer existingInstance) { VertexDeclaration vertexDeclaration = input.ReadRawObject <VertexDeclaration>(); int vertexCount = (int)input.ReadUInt32(); byte[] data = input.ReadBytes(vertexCount * vertexDeclaration.VertexStride); VertexBuffer vertexBuffer = new VertexBuffer(input.GraphicsDevice, vertexDeclaration, vertexCount, BufferUsage.None); vertexBuffer.SetData <byte>(data); return(vertexBuffer); }
protected internal override AlphaTestEffect Read(ContentReader input, AlphaTestEffect existingInstance) { AlphaTestEffect effect = new AlphaTestEffect(input.GraphicsDevice); effect.Texture = input.ReadExternalReference <Texture>() as Texture2D; effect.AlphaFunction = (CompareFunction)input.ReadInt32(); effect.ReferenceAlpha = (int)input.ReadUInt32(); effect.DiffuseColor = input.ReadVector3(); effect.Alpha = input.ReadSingle(); effect.VertexColorEnabled = input.ReadBoolean(); return(effect); }
private static int ReadBoneReference(ContentReader reader, uint boneCount) { uint num = boneCount >= (uint)byte.MaxValue ? reader.ReadUInt32() : (uint)reader.ReadByte(); if ((int)num != 0) { return((int)num - 1); } else { return(-1); } }
protected internal override VertexBuffer Read(ContentReader input, VertexBuffer existingInstance) { var declaration = input.ReadRawObject <VertexDeclaration>(); var vertexCount = (int)input.ReadUInt32(); int dataSize = vertexCount * declaration.VertexStride; byte[] data = input.ContentManager.GetScratchBuffer(dataSize); input.Read(data, 0, dataSize); var buffer = new VertexBuffer(input.GraphicsDevice, declaration, vertexCount, BufferUsage.None); buffer.SetData(data, 0, dataSize); return(buffer); }
protected internal override SoundEffect Read( ContentReader input, SoundEffect existingInstance ) { // Format block length uint formatLength = input.ReadUInt32(); // Wavedata format ushort format = input.ReadUInt16(); // Number of channels ushort channels = input.ReadUInt16(); // Sample rate uint sampleRate = input.ReadUInt32(); // Averate bytes per second, unused input.ReadUInt32(); // Block alignment, needed for MSADPCM ushort blockAlign = input.ReadUInt16(); // Bit depth ushort bitDepth = input.ReadUInt16(); // cbSize, unused input.ReadUInt16(); // Seek past the rest of this crap input.BaseStream.Seek(formatLength - 18, SeekOrigin.Current); // Wavedata byte[] data = input.ReadBytes(input.ReadInt32()); // Loop information uint loopStart = input.ReadUInt32(); uint loopLength = input.ReadUInt32(); // Sound duration in milliseconds, unused input.ReadUInt32(); return(new SoundEffect( input.AssetName, data, sampleRate, channels, loopStart, loopLength, format == 2, (uint)((format == 2) ? (((blockAlign / channels) - 6) * 2) : (bitDepth / 16)) )); }
private static int ReadBoneReference(ContentReader reader, uint boneCount) { uint boneId; // Read the bone ID, which may be encoded as either an 8 or 32 bit value. if (boneCount < 255) { boneId = reader.ReadByte(); } else { boneId = reader.ReadUInt32(); } if (boneId != 0) { return((int)(boneId - 1)); } return(-1); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint num1 = input.ReadUInt32(); T[] objArray = existingInstance ?? new T[(IntPtr)num1]; if (typeof(T).IsValueType) { for (uint index = 0U; index < num1; ++index) { objArray[(IntPtr)index] = input.ReadObject <T>(this.elementReader); } } else { for (uint index = 0U; index < num1; ++index) { int num2 = input.Read7BitEncodedInt(); objArray[(IntPtr)index] = num2 > 0 ? input.ReadObject <T>(input.TypeReaders[num2 - 1]) : default(T); } } return(objArray); }
protected internal override T[] Read(ContentReader input, T[] existingInstance) { uint count = input.ReadUInt32(); T[] array = existingInstance; if (array == null) { array = new T[count]; } if (typeof(T).IsValueType) { for (uint i = 0; i < count; i += 1) { array[i] = input.ReadObject <T>(elementReader); } } else { for (uint i = 0; i < count; i += 1) { int readerType = input.Read7BitEncodedInt(); if (readerType > 0) { array[i] = input.ReadObject <T>( input.TypeReaders[readerType - 1] ); } else { array[i] = default(T); } } } return(array); }
protected internal override Model Read(ContentReader reader, Model existingInstance) { // Read the bone names and transforms. uint boneCount = reader.ReadUInt32(); List <ModelBone> bones = new List <ModelBone>((int)boneCount); for (uint i = 0; i < boneCount; i += 1) { string name = reader.ReadObject <string>(); Matrix matrix = reader.ReadMatrix(); ModelBone bone = new ModelBone { Transform = matrix, Index = (int)i, Name = name }; bones.Add(bone); } // Read the bone hierarchy. for (int i = 0; i < boneCount; i += 1) { ModelBone bone = bones[i]; // Read the parent bone reference. int parentIndex = ReadBoneReference(reader, boneCount); if (parentIndex != -1) { bone.Parent = bones[parentIndex]; } // Read the child bone references. uint childCount = reader.ReadUInt32(); if (childCount != 0) { for (uint j = 0; j < childCount; j += 1) { int childIndex = ReadBoneReference(reader, boneCount); if (childIndex != -1) { bone.AddChild(bones[childIndex]); } } } } List <ModelMesh> meshes = new List <ModelMesh>(); // Read the mesh data. int meshCount = reader.ReadInt32(); for (int i = 0; i < meshCount; i += 1) { string name = reader.ReadObject <string>(); int parentBoneIndex = ReadBoneReference(reader, boneCount); BoundingSphere boundingSphere = reader.ReadBoundingSphere(); // Tag object meshTag = reader.ReadObject <object>(); // Read the mesh part data. int partCount = reader.ReadInt32(); List <ModelMeshPart> parts = new List <ModelMeshPart>(partCount); for (uint j = 0; j < partCount; j += 1) { ModelMeshPart part; if (existingInstance != null) { part = existingInstance.Meshes[i].MeshParts[(int)j]; } else { part = new ModelMeshPart(); } part.VertexOffset = reader.ReadInt32(); part.NumVertices = reader.ReadInt32(); part.StartIndex = reader.ReadInt32(); part.PrimitiveCount = reader.ReadInt32(); // Tag part.Tag = reader.ReadObject <object>(); parts.Add(part); int jj = (int)j; reader.ReadSharedResource <VertexBuffer>( delegate(VertexBuffer v) { parts[jj].VertexBuffer = v; } ); reader.ReadSharedResource <IndexBuffer>( delegate(IndexBuffer v) { parts[jj].IndexBuffer = v; } ); reader.ReadSharedResource <Effect>( delegate(Effect v) { parts[jj].Effect = v; } ); } if (existingInstance != null) { continue; } ModelMesh mesh = new ModelMesh(reader.GraphicsDevice, parts); mesh.Tag = meshTag; mesh.Name = name; mesh.ParentBone = bones[parentBoneIndex]; mesh.ParentBone.AddMesh(mesh); mesh.BoundingSphere = boundingSphere; meshes.Add(mesh); } if (existingInstance != null) { // Read past remaining data and return existing instance ReadBoneReference(reader, boneCount); reader.ReadObject <object>(); return(existingInstance); } // Read the final pieces of model data. int rootBoneIndex = ReadBoneReference(reader, boneCount); Model model = new Model(reader.GraphicsDevice, bones, meshes); model.Root = bones[rootBoneIndex]; model.BuildHierarchy(); // Tag? model.Tag = reader.ReadObject <object>(); return(model); }
protected internal override SoundEffect Read( ContentReader input, SoundEffect existingInstance ) { /* Swap endian - this is one of the very few places requiring this! * Note: This only affects the fmt chunk that's glued into the file. */ bool se = input.platform == 'x'; // Format block length uint formatLength = input.ReadUInt32(); // WaveFormatEx data ushort wFormatTag = Swap(se, input.ReadUInt16()); ushort nChannels = Swap(se, input.ReadUInt16()); uint nSamplesPerSec = Swap(se, input.ReadUInt32()); uint nAvgBytesPerSec = Swap(se, input.ReadUInt32()); ushort nBlockAlign = Swap(se, input.ReadUInt16()); ushort wBitsPerSample = Swap(se, input.ReadUInt16()); byte[] extra = null; if (formatLength > 16) { ushort cbSize = Swap(se, input.ReadUInt16()); if (wFormatTag == 0x166 && cbSize == 34) { // XMA2 has got some nice extra crap. extra = new byte[34]; using (MemoryStream extraStream = new MemoryStream(extra)) using (BinaryWriter extraWriter = new BinaryWriter(extraStream)) { // See FAudio.FAudioXMA2WaveFormatEx for the layout. extraWriter.Write(Swap(se, input.ReadUInt16())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(Swap(se, input.ReadUInt32())); extraWriter.Write(input.ReadByte()); extraWriter.Write(input.ReadByte()); extraWriter.Write(Swap(se, input.ReadUInt16())); } // Is there any crap that needs skipping? Eh whatever. input.ReadBytes((int)(formatLength - 18 - 34)); } else { // Seek past the rest of this crap (cannot seek though!) input.ReadBytes((int)(formatLength - 18)); } } // Wavedata byte[] data = input.ReadBytes(input.ReadInt32()); // Loop information int loopStart = input.ReadInt32(); int loopLength = input.ReadInt32(); // Sound duration in milliseconds, unused input.ReadUInt32(); return(new SoundEffect( input.AssetName, data, 0, data.Length, extra, wFormatTag, nChannels, nSamplesPerSec, nAvgBytesPerSec, nBlockAlign, wBitsPerSample, loopStart, loopLength )); }
protected internal override uint Read(ContentReader input, uint existingInstance) { return(input.ReadUInt32()); }
protected internal override Model Read(ContentReader reader, Model existingInstance) { List <ModelBone> bones = new List <ModelBone>(); uint boneCount = reader.ReadUInt32(); for (uint index = 0U; index < boneCount; ++index) { string str = reader.ReadObject <string>(); Matrix matrix = reader.ReadMatrix(); ModelBone modelBone = new ModelBone() { Transform = matrix, Index = (int)index, Name = str }; bones.Add(modelBone); } for (int index1 = 0; (long)index1 < (long)boneCount; ++index1) { ModelBone modelBone = bones[index1]; int index2 = ModelReader.ReadBoneReference(reader, boneCount); if (index2 != -1) { modelBone.Parent = bones[index2]; } uint num = reader.ReadUInt32(); if ((int)num != 0) { for (uint index3 = 0U; index3 < num; ++index3) { int index4 = ModelReader.ReadBoneReference(reader, boneCount); if (index4 != -1) { modelBone.AddChild(bones[index4]); } } } } List <ModelMesh> meshes = new List <ModelMesh>(); int num1 = reader.ReadInt32(); for (int index1 = 0; index1 < num1; ++index1) { string str = reader.ReadObject <string>(); int index2 = ModelReader.ReadBoneReference(reader, boneCount); BoundingSphere boundingSphere = reader.ReadBoundingSphere(); reader.ReadObject <object>(); int num2 = reader.ReadInt32(); List <ModelMeshPart> parts = new List <ModelMeshPart>(); for (uint index3 = 0U; (long)index3 < (long)num2; ++index3) { ModelMeshPart modelMeshPart = existingInstance == null ? new ModelMeshPart() : ((ReadOnlyCollection <ModelMesh>)existingInstance.Meshes)[index1].MeshParts[(int)index3]; modelMeshPart.VertexOffset = reader.ReadInt32(); modelMeshPart.NumVertices = reader.ReadInt32(); modelMeshPart.StartIndex = reader.ReadInt32(); modelMeshPart.PrimitiveCount = reader.ReadInt32(); modelMeshPart.Tag = reader.ReadObject <object>(); parts.Add(modelMeshPart); int jj = (int)index3; reader.ReadSharedResource <VertexBuffer>((Action <VertexBuffer>)(v => parts[jj].VertexBuffer = v)); reader.ReadSharedResource <IndexBuffer>((Action <IndexBuffer>)(v => parts[jj].IndexBuffer = v)); reader.ReadSharedResource <Effect>((Action <Effect>)(v => parts[jj].Effect = v)); } if (existingInstance == null) { ModelMesh mesh = new ModelMesh(reader.GraphicsDevice, parts); mesh.Name = str; mesh.ParentBone = bones[index2]; mesh.ParentBone.AddMesh(mesh); mesh.BoundingSphere = boundingSphere; meshes.Add(mesh); } } if (existingInstance != null) { ModelReader.ReadBoneReference(reader, boneCount); reader.ReadObject <object>(); return(existingInstance); } else { int index = ModelReader.ReadBoneReference(reader, boneCount); Model model = new Model(reader.GraphicsDevice, bones, meshes); model.Root = bones[index]; model.BuildHierarchy(); model.Tag = reader.ReadObject <object>(); return(model); } }