Ejemplo n.º 1
0
unsigned long TTFFontManager::read(FT_Stream		  stream,
								   unsigned long   offset,
								   unsigned char*  buffer,
								   unsigned long   count )
{
	DataStream* dstream = (DataStream*)stream->descriptor.pointer;
	dstream->Seek(offset, GEM_STREAM_START);
	return dstream->Read(buffer, count);
}
Ejemplo n.º 2
0
char* FileBasedAGSDebugger::GetNextMessage()
{
    DataStream *in = Common::File::OpenFileRead("dbgsend.tmp");
    if (in == NULL)
    {
        // check again, because the editor might have deleted the file in the meantime
        return NULL;
    }
    int fileSize = in->GetLength();
    char *msg = (char*)malloc(fileSize + 1);
    in->Read(msg, fileSize);
    delete in;
    unlink("dbgsend.tmp");
    msg[fileSize] = 0;
    return msg;
}
Ejemplo n.º 3
0
	bool WavDecoder::Init()
	{
        DataStream* ds = m_ds;
        
		::memset(&m_format,0,sizeof(m_format));

        //LOG_DEBUG("init");
		
		/// read shunks
		while (!ds->Eof())
		{
			Byte chunk_name[4];
			if (ds->Read(chunk_name,4)!=4) break;
			UInt32 chunk_size = 0;
			if (ds->Read(reinterpret_cast<Byte*>(&chunk_size),4)!=4) break;
			
			//// "fmt "
			if (::strncmp(reinterpret_cast<const char*>(chunk_name),"fmt ",4)==0) 
			{
                //LOG_DEBUG("found chunk 'fmt '");

				if (chunk_size<16) return false;
				if (ds->Read(reinterpret_cast<Byte*>(&m_format),sizeof(m_format))!=sizeof(m_format)) return false;
				//endian_fix(&m_format);
				/// uncompressed PCM
				if (m_format.compression_code!=1) return false;
				if (m_format.num_channels!=1 && m_format.num_channels!=2) return false;
				if (m_format.bits_per_sample!=8 && m_format.bits_per_sample!=16) return false;
				if (m_format.num_channels == 1) {
					if (m_format.bits_per_sample==8)
						m_type = SAMPLE_TYPE_MONO_8;
					else if (m_format.bits_per_sample==16)
						m_type = SAMPLE_TYPE_MONO_16;
				} else if (m_format.num_channels == 2) {
					if (m_format.bits_per_sample==8)
						m_type = SAMPLE_TYPE_STEREO_8;
					else if (m_format.bits_per_sample==16)
						m_type = SAMPLE_TYPE_STEREO_16;
				}
				m_freq = m_format.sample_rate;
                assert(chunk_size>=UInt32(sizeof(m_format)));
				m_ds->Seek(chunk_size-UInt32(sizeof(m_format)),F_SEEK_CURRENT);
			} 
			/// "data"
			else if (::strncmp(reinterpret_cast<const char*>(chunk_name),"data",4)==0) 
			{
                //LOG_DEBUG("found chunk 'data'");
				m_samples+=chunk_size/m_format.block_align;
                assert(chunk_size<=std::numeric_limits<Int32>::max());
				m_ds->Seek(chunk_size,F_SEEK_CURRENT);
			}
			/// another
			else
			{
				LOG_DEBUG("skip shunk '"<<chunk_name[0]<<chunk_name[1]<<chunk_name[2]<<chunk_name[3]<<"' "<< chunk_size << " bytes");
                assert(chunk_size<=std::numeric_limits<Int32>::max());
				m_ds->Seek(chunk_size,F_SEEK_CURRENT);
			}
		}
		m_ds->Seek(4+4+4,F_SEEK_BEGIN);
		m_unreaded = 0;
		return m_samples!=0 && m_type!=SAMPLE_TYPE_UNKNOWN && m_freq!=0;
	}
Ejemplo n.º 4
0
 void LoadBuffer() {
     size = strm->Read(buffer,size);
     readed = 0;
     if (size==0 && strm->Eof())
         eof = true;
 }
Ejemplo n.º 5
0
void start_playback()
{
    DataStream *in = Common::File::OpenFileRead(replayfile);
    if (in != NULL) {
        char buffer [100];
        in->Read(buffer, 12);
        buffer[12] = 0;
        if (strcmp (buffer, "AGSRecording") != 0) {
            Display("ERROR: Invalid recorded data file");
            play.playback = 0;
        }
        else {
            fgetstring_limit (buffer, in, 12);
            if (buffer[0] != '2') 
                quit("!Replay file is from an old version of AGS");
            if (strcmp (buffer, "2.55.553") < 0)
                quit("!Replay file was recorded with an older incompatible version");

            if (strcmp (buffer, ACI_VERSION_TEXT)) {
                // Disable text as speech while displaying the warning message
                // This happens if the user's graphics card does BGR order 16-bit colour
                int oldalways = game.options[OPT_ALWAYSSPCH];
                game.options[OPT_ALWAYSSPCH] = 0;
                play.playback = 0;
                Display("Warning! replay is from a different version of AGS (%s) - it may not work properly.", buffer);
                play.playback = 1;
                srand (play.randseed);
                play.gamestep = 0;
                game.options[OPT_ALWAYSSPCH] = oldalways;
            }

            int replayver = in->ReadInt32();

            if ((replayver < 1) || (replayver > 3))
                quit("!Unsupported Replay file version");

            if (replayver >= 2) {
                fgetstring_limit (buffer, in, 99);
                int uid = in->ReadInt32 ();
                if ((strcmp (buffer, game.gamename) != 0) || (uid != game.uniqueid)) {
                    char msg[150];
                    sprintf (msg, "!This replay is meant for the game '%s' and will not work correctly with this game.", buffer);
                    delete in;
                    quit (msg);
                }
                // skip the total time
                in->ReadInt32 ();
                // replay description, maybe we'll use this later
                fgetstring_limit (buffer, in, 99);
            }

            play.randseed = in->ReadInt32();
            int flen = in->GetLength() - in->GetPosition ();
            if (replayver >= 3) {
                flen = in->ReadInt32() * sizeof(short);
            }
            recordbuffer = (short*)malloc (flen);
            in->Read(recordbuffer, flen);
            srand (play.randseed);
            recbuffersize = flen / sizeof(short);
            recsize = 0;
            disable_mgetgraphpos = 1;
            replay_time = 0;
            replay_last_second = loopcounter;
            if (replayver >= 3) {
                int issave = in->ReadInt32();
                if (issave) {
                    if (restore_game_data (in, replayfile))
                        quit("!Error running replay... could be incorrect game version");
                    replay_last_second = loopcounter;
                }
            }
            delete in;
        }
    }
    else // file not found
        play.playback = 0;
}
Ejemplo n.º 6
0
	static size_t ghl_ogg_read_func  (void *ptr, size_t size, size_t nmemb, void *datasource) 
	{
		DataStream* ds = reinterpret_cast<DataStream*>(datasource);
		if (!ds) return 0;
		return ds->Read(reinterpret_cast<Byte*>(ptr),size*nmemb);
	}