Esempio n. 1
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         BinaryReader binaryReader      = new BinaryReader(stream);
         bool         flag              = binaryReader.ReadBoolean();
         int          channelsCount     = binaryReader.ReadInt32();
         int          samplingFrequency = binaryReader.ReadInt32();
         int          bytesCount        = binaryReader.ReadInt32();
         if (flag)
         {
             MemoryStream memoryStream = new MemoryStream();
             using (StreamingSource streamingSource = Ogg.Stream(stream))
             {
                 streamingSource.CopyTo(memoryStream);
                 if (memoryStream.Length > int.MaxValue)
                 {
                     throw new InvalidOperationException("Audio data too long.");
                 }
                 memoryStream.Position = 0L;
                 return(new SoundBuffer(memoryStream, (int)memoryStream.Length, channelsCount, samplingFrequency));
             }
         }
         return(new SoundBuffer(stream, bytesCount, channelsCount, samplingFrequency));
     }
     throw new NotSupportedException();
 }
Esempio n. 2
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         return(new BinaryReader(stream).ReadString());
     }
     throw new NotSupportedException();
 }
Esempio n. 3
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         return(ReadImage(stream));
     }
     throw new NotSupportedException();
 }
Esempio n. 4
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         SoundFileFormat format = SoundData.DetermineFileFormat(stream);
         return(SoundData.Stream(stream.Duplicate(), format));
     }
     throw new NotSupportedException();
 }
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         return(ReadBitmapFont(stream));
     }
     InitializeBitmapFont(stream, (BitmapFont)existingObject);
     return(existingObject);
 }
Esempio n. 6
0
 public static void LoadContent(ContentDescription contentDescription)
 {
     if (contentDescription.Stream != null)
     {
         IContentReader contentReader = GetContentReader(contentDescription.TypeName);
         ContentStream  stream        = PrepareContentStream(contentDescription);
         contentDescription.Content = contentReader.Read(stream, contentDescription.Content);
         return;
     }
     throw new InvalidOperationException("Cannot load manually added content item. Item must have been disposed and accessed again.");
 }
Esempio n. 7
0
        public object Read(ContentStream stream, object existingObject)
        {
            if (existingObject == null)
            {
                return(ReadTexture(stream));
            }
            Texture2D texture2D = (Texture2D)existingObject;

            stream.Position += 12L;
            LoadTextureData(stream, texture2D, keepSourceImageInTag: false);
            return(texture2D);
        }
Esempio n. 8
0
        public object Read(ContentStream stream, object existingObject)
        {
            bool      keepSourceVertexDataInTags = new BinaryReader(stream).ReadBoolean();
            ModelData modelData = ModelDataContentReader.ReadModelData(stream);

            if (existingObject == null)
            {
                return(Model.Load(modelData, keepSourceVertexDataInTags));
            }
            Model obj = (Model)existingObject;

            obj.Initialize(modelData, keepSourceVertexDataInTags);
            return(obj);
        }
Esempio n. 9
0
 public object Read(ContentStream stream, object existingObject)
 {
     if (existingObject == null)
     {
         BinaryReader  binaryReader     = new BinaryReader(stream);
         string        vertexShaderCode = binaryReader.ReadString();
         string        pixelShaderCode  = binaryReader.ReadString();
         int           num   = binaryReader.ReadInt32();
         ShaderMacro[] array = new ShaderMacro[num];
         for (int i = 0; i < num; i++)
         {
             string name  = binaryReader.ReadString();
             string value = binaryReader.ReadString();
             array[i] = new ShaderMacro(name, value);
         }
         return(new Shader(vertexShaderCode, pixelShaderCode, array));
     }
     throw new NotSupportedException();
 }
Esempio n. 10
0
        public ContentStream Duplicate()
        {
            ContentStream contentStream = new ContentStream();

            contentStream.m_streamFactory = m_streamFactory;
            contentStream.m_data          = m_data;
            if (m_data != null)
            {
                contentStream.m_stream = new PadStream(new MemoryStream(m_data, writable: false));
            }
            else
            {
                contentStream.m_stream = new PadStream(m_streamFactory());
            }
            contentStream.m_stream.Position = m_stream.Position;
            contentStream.m_start           = m_start;
            contentStream.m_length          = m_length;
            contentStream.Pad = Pad;
            return(contentStream);
        }
Esempio n. 11
0
 public static void AddPackage(Func <Stream> streamFactory, byte[] tocPad = null, byte[] contentPad = null)
 {
     lock (m_lock)
     {
         if (!m_isInitialized)
         {
             m_isInitialized      = true;
             Display.DeviceReset += Display_DeviceReset;
         }
         ContentStream contentStream = new ContentStream(streamFactory);
         using (BinaryReader binaryReader = new BinaryReader(contentStream, Encoding.UTF8, leaveOpen: true))
         {
             byte[] array = new byte[4];
             if (binaryReader.Read(array, 0, array.Length) != array.Length || array[0] != 80 || array[1] != 75 || array[2] != 50 || array[3] != 0)
             {
                 throw new InvalidOperationException("Invalid package header.");
             }
             contentStream.Pad = tocPad;
             long num  = binaryReader.ReadInt64();
             int  num2 = binaryReader.ReadInt32();
             for (int i = 0; i < num2; i++)
             {
                 string name       = binaryReader.ReadString();
                 string typeName   = binaryReader.ReadString();
                 long   position   = binaryReader.ReadInt64() + num;
                 long   bytesCount = binaryReader.ReadInt64();
                 SetContentDescription(name, new ContentDescription
                 {
                     TypeName   = typeName,
                     Stream     = contentStream,
                     Position   = position,
                     BytesCount = bytesCount
                 });
             }
             contentStream.Pad = contentPad;
         }
     }
 }