Exemple #1
0
SpeechLoader::SpeechLoader( std::string sPath )
{
	assert( m_sgSpeechLoader == NULL );
	m_sgSpeechLoader = this;

	std::ifstream ifSpeechLoader;

	const std::string sFileName = sPath + "speech.mul";
	Logger::WriteDebug( "\t| -> Speech file: " + sFileName );

	ifSpeechLoader.open( sFileName.c_str(), std::ios::in | std::ios::binary );

	if ( !ifSpeechLoader.is_open() )
	{
		Logger::WriteLine( "\t| -> Warning: Couldn't open Speech file" );
		ifSpeechLoader.close();

		return;
	}

	ifSpeechLoader.seekg( 0, std::ios::end );
	const int filelen = ifSpeechLoader.tellg();
	ifSpeechLoader.seekg( 0, std::ios::beg );

	Uint16 index;
	Uint16 keywordlen;
	char *c_keyword;
	std::string s_keyword = "";

	 while ( ifSpeechLoader.tellg() < filelen )
	//while ( !ifSpeechLoader.eof() )
	{
		ifSpeechLoader.read( (char *)&index, 2 );
		index = SDL_Swap16( index );

		if ( index != 0 )
		{
			m_languages.push_back( m_keywords );
			m_keywords.clear();
		}

		ifSpeechLoader.read( (char *)&keywordlen, 2 );
		keywordlen = SDL_Swap16( keywordlen );
		c_keyword = new char[keywordlen + 1];
		ifSpeechLoader.read( (char *)c_keyword, keywordlen );
		c_keyword[keywordlen] = 0;
		s_keyword = std::string( c_keyword );
		SAFE_DELETE_ARRAY( c_keyword );

		//std::cout << "ID: " << index << " WORD: " << s_keyword << "   len: " << keywordlen << std::endl;
		//Logger::WriteLine( s_keyword.c_str() );

		m_keywords.insert( std::make_pair( s_keyword, index ) );
	}

	ifSpeechLoader.close();
}
Exemple #2
0
// endian-swapping fread that dies if the expected amount cannot be read
size_t efread( void *buffer, size_t size, size_t num, FILE *stream )
{
	size_t num_read = fread(buffer, size, num, stream);
	
	switch (size)
	{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
		case 2:
			for (size_t i = 0; i < num; i++)
				((Uint16 *)buffer)[i] = SDL_Swap16(((Uint16 *)buffer)[i]);
			break;
		case 4:
			for (size_t i = 0; i < num; i++)
				((Uint32 *)buffer)[i] = SDL_Swap32(((Uint32 *)buffer)[i]);
			break;
		case 8:
			for (size_t i = 0; i < num; i++)
				((Uint64 *)buffer)[i] = SDL_Swap64(((Uint64 *)buffer)[i]);
			break;
#endif
		default:
			break;
	}
	
	if (num_read != num)
	{
		fprintf(stderr, "error: An unexpected problem occurred while reading from a file.\n");
		JE_tyrianHalt(1);
	}

	return num_read;
}
Exemple #3
0
/* Byte-swap the pixels in the display image */
static void X11_SwapAllPixels(SDL_Surface *screen)
{
	int x, y;

	switch (screen->format->BytesPerPixel) {
	    case 2: {
		Uint16 *spot;
		for ( y=0; y<screen->h; ++y ) {
			spot = (Uint16 *) ((Uint8 *)screen->pixels +
						y * screen->pitch);
			for ( x=0; x<screen->w; ++x, ++spot ) {
				*spot = SDL_Swap16(*spot);
			}
		}
	    }
	    break;

	    case 4: {
		Uint32 *spot;
		for ( y=0; y<screen->h; ++y ) {
			spot = (Uint32 *) ((Uint8 *)screen->pixels +
						y * screen->pitch);
			for ( x=0; x<screen->w; ++x, ++spot ) {
				*spot = SDL_Swap32(*spot);
			}
		}
	    }
	    break;

	    default:
		/* should never get here */
		break;
	}
}
Exemple #4
0
void swap16 (void *d)
{
	if (bendian)
	{
		*((int16_t *)d) = SDL_Swap16(*((int16_t *)d));
	}
}
Exemple #5
0
inline void Utl_writeShort(Uint16 num,char* data){
	#if NEED_SWAP
		num = SDL_Swap16(num);
	#endif
		data[0] = (num & 0xFF00) >> 8;
		data[1] = (num & 0x00FF) >> 0;
}
Exemple #6
0
bool ScriptEngine::LoadScript(const char* str)
{
	FILE* file = fopen(str, "rb");
	
	if (!file)
	{
		return false;
	}

	fseek(file, 0, SEEK_END);
	AnzUInt ScriptLength = ftell(file);
	rewind(file);
	ScriptBuffer = new AnzUInt8[ScriptLength];
	fread(ScriptBuffer, 1, ScriptLength, file);
	fclose(file);

	HeaderOffset = *(AnzUInt*)(ScriptBuffer);

#if SDL_BYTEORDER != SDL_LIL_ENDIAN
	HeaderOffset = SDL_Swap32(HeaderOffset);
#endif

	Title = std::string((char*)(ScriptBuffer + HeaderOffset + sizeof(HcbHeader)));

	if (HeaderOffset >= ScriptLength)
	{
		delete[] ScriptBuffer;
		ScriptBuffer = nullptr;
		return false;
	}

	HcbHeader *hcbHeader = (HcbHeader*)(ScriptBuffer + HeaderOffset);

#if SDL_BYTEORDER == SDL_LIL_ENDIAN
	EntryOffset = hcbHeader->EntryPoint;
#else
	EntryPoint = SDL_Swap32(hcbHeader->EntryPoint);
#endif

	AnzUShort ResolutionIndex = 1;
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
	ResolutionIndex = hcbHeader->ResolutionIndex;
#else
	ResolutionIndex = SDL_Swap16(hcbHeader->ResolutionIndex);
#endif

	switch (ResolutionIndex)
	{
	case 1: Width = 800;  Height = 600; break;
	case 7: Width = 1024; Height = 640; break;
	default:
		ErrorLog(fvpError, "Unknown resolutionIndex, using[800x600] as default!\n");
		Height = 800;
		Width = 600;
		break;
	}
	ErrorLog(fvpLog, "Script Loaded!");

	return true;
}
Exemple #7
0
int Luola_ReadLE16(SDL_RWops *src,Uint16 *value)
{
    if(SDL_RWread(src, value, 2, 1)==-1) return -1;
    *value = SDL_Swap16(*value);
    return 2;

}
Exemple #8
0
static int voc_check_header(SDL_RWops *src)
{
    /* VOC magic header */
    unsigned char  signature[20];  /* "Creative Voice File\032" */
    unsigned short datablockofs;
 
    SDL_RWseek(src, 0, RW_SEEK_SET);

    if (SDL_RWread(src, signature, sizeof (signature), 1) != 1)
        return(0);

    if (memcmp(signature, "Creative Voice File\032", sizeof (signature)) != 0) {
        Error("Unrecognized file type (not VOC)");
        return(0);
    }

        /* get the offset where the first datablock is located */
    if (SDL_RWread(src, &datablockofs, sizeof (unsigned short), 1) != 1)
        return(0);

    datablockofs = SDL_Swap16(datablockofs);

    if (SDL_RWseek(src, datablockofs, RW_SEEK_SET) != datablockofs)
        return(0);
     
    return(1);  /* success! */
} /* voc_check_header */
Exemple #9
0
Uint16 Network::readWord(int pos)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    return SDL_Swap16((*(Uint16*)(mInBuffer+(pos))));
#else
    return (*(Uint16*)(mInBuffer+(pos)));
#endif
}
		uint16_t host16(uint16_t number)
		{
			#if SDL_BYTEORDER == SDL_LIL_ENDIAN
				return SDL_Swap16(number);
			#else
				return number;
			#endif
		}
Exemple #11
0
uint16_t Network::readWord(int pos)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    return SDL_Swap16((*(uint16_t*)(mInBuffer + (pos))));
#else
    return (*reinterpret_cast<uint16_t*>(mInBuffer + (pos)));
#endif
}
Exemple #12
0
int File::read( Uint16 *n, int count ) {
  int ret = read( n, sizeof( Uint16 ), count );
  if( SDL_BYTEORDER	!= SCOURGE_BYTE_ORDER ) {
    for( int i = 0; i < count; i++ ) {
      *( n + i ) = SDL_Swap16( *( n + i ) );
    }
  }
  return ret;
}
Exemple #13
0
inline Uint16 Utl_readShort(char* data){
	Uint16 num;
	num =	(data[0] << 8) + 
			(data[1] << 0);
	#if NEED_SWAP
		num = SDL_Swap16(num);
	#endif
	return num;
}
Exemple #14
0
void MessageOut::writeInt16(Sint16 value)
{
    expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    Sint16 swap=SDL_Swap16(value);
    memcpy(mData + mPos, &swap, sizeof(Sint16));
#else
    memcpy(mData + mPos, &value, sizeof(Sint16));
#endif
    mPos += 2;
}
Exemple #15
0
int File::write( Uint16 *n, int count ) {
  // always save as big endian
  if( SDL_BYTEORDER	!= SCOURGE_BYTE_ORDER ) {
    for( int i = 0; i < count; i++ ) {
      tmp16 [ i ] = SDL_Swap16( *( n + i ) );
    }
    return write( tmp16, sizeof( Uint16 ), count );
  } else {
    return write( n, sizeof( Uint16 ), count );
  }
}
Exemple #16
0
void s32tos16x(void *dp, Sint32 *lp, Sint32 c)
{
  Sint16 *sp=(Sint16 *)(dp);
  Sint32 l;
  while (c--)
    {
      l=(*lp++)>>(32-16-GUARD_BITS);
      if (l > 32767) l=32767;
      else if (l<-32768) l=-32768;
      *sp++ = SDL_Swap16((Sint16)(l));
    }
}
Exemple #17
0
bool __fastcall SystemCall(ScriptObject *stack)
{
	stack->ScriptPos++;
	AnzUInt16 hcbCall = *(AnzUInt16*)(stack->Buffer + stack->ScriptPos);

#if SDL_BYTEORDER != SDL_LIL_ENDIAN
	hcbCall = SDL_Swap16(hcbCall);
#endif
	(*ScriptEngine::SystemCallPool[hcbCall])(stack);

	stack->ScriptPos += 2;
	return true;
}
Exemple #18
0
void swap_buf16_if_need(Uint8 src_endian,Uint16* buf,Uint32 size)
{
    int i;
#ifdef WORDS_BIGENDIAN
    Uint8  my_endian=1;
#else
    Uint8  my_endian=0;
#endif
    if (my_endian!=src_endian) {
	for (i=0;i<size;i++)
	    SDL_Swap16(buf[i]);
    }
}
Exemple #19
0
void MessageOut::writeInt16(int16_t value)
{
    DEBUGLOG("writeInt16: " + toString(static_cast<int>(value)));
    expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    int16_t swap = SDL_Swap16(value);
    memcpy(mData + mPos, &swap, sizeof(int16_t));
#else
    memcpy(mData + mPos, &value, sizeof(int16_t));
#endif
    mPos += 2;
    PacketCounters::incOutBytes(2);
}
Exemple #20
0
int MessageIn::readInt16()
{
    int value = -1;
    if (mPos + 2 <= mLength)
    {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        value = SDL_Swap16(*(Sint16*)(mData + mPos));
#else
        value = (*(Sint16*)(mData + mPos));
#endif
    }
    mPos += 2;
    return value;
}
Exemple #21
0
void MessageOut::writeInt16(const int16_t value, const char *const str)
{
    expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    int16_t swap = SDL_Swap16(value);
    memcpy(mData + static_cast<size_t>(mPos), &swap, sizeof(int16_t));
#else
    memcpy(mData + static_cast<size_t>(mPos), &value, sizeof(int16_t));
#endif
    DEBUGLOG2("writeInt16: " + toStringPrint(static_cast<unsigned int>(
        static_cast<uint16_t>(value))),
        mPos, str);
    mPos += 2;
    PacketCounters::incOutBytes(2);
}
void MessageOut::writeInt16(const int16_t value, const char *const str)
{
    DEBUGLOG2("writeInt16: " + toStringPrint(CAST_U32(
        CAST_U16(value))),
        mPos, str);
    expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    int16_t swap = SDL_Swap16(value);
    memcpy(mData + CAST_SIZE(mPos), &swap, sizeof(int16_t));
#else
    memcpy(mData + CAST_SIZE(mPos), &value, sizeof(int16_t));
#endif
    mPos += 2;
    PacketCounters::incOutBytes(2);
}
Exemple #23
0
uint16_t MessageIn::readId()
{
    int16_t value = -1;
    if (mPos + 2 <= mLength)
    {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        int16_t swap;
        memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
        value = SDL_Swap16(swap);
#else
        memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
#endif
    }
    return value;
}
Exemple #24
0
uint16_t MessageIn::readInt16()
{
    uint16_t value = 0;
    if (mPos + 2 <= mLength)
    {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        uint16_t swap;
        memcpy(&swap, mData + mPos, sizeof(uint16_t));
        value = SDL_Swap16(swap);
#else
        memcpy(&value, mData + mPos, sizeof(uint16_t));
#endif
    }
    mPos += 2;
    return value;
}
Exemple #25
0
void MessageOut::writeInt16(Sint16 value)
{
#ifdef TMWSERV_SUPPORT
    expand(mPos + 2);
    uint16_t t = ENET_HOST_TO_NET_16(value);
    memcpy(mData + mPos, &t, 2);
#else
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
    (*(Sint16 *)(mData + mPos)) = SDL_Swap16(value);
#else
    (*(Sint16 *)(mData + mPos)) = value;
#endif
    mNetwork->mOutSize += 2;
#endif // TMWSERV_SUPPORT
    mPos += 2;
}
Exemple #26
0
//pushGlobal(i16 num) 0x0F
bool __fastcall PushGlobal(ScriptObject *stack)
{
	stack->ScriptPos++;

	AnzUInt16 hcbTemp = *(AnzUInt16*)(stack->Buffer + stack->ScriptPos);
	
	#if SDL_BYTEORDER != SDL_LIL_ENDIAN
	hcbTemp = SDL_Swap16(hcbTemp);
	#endif

	//使用search key
	stack->CurStackFrame++;
	stack->LocalStack[stack->CurStackFrame] = *(ScriptEngine::GetHandle()->GlobalVar[hcbTemp]);
	stack->ScriptPos += 2;
	return true;
}
Exemple #27
0
bool __fastcall PopGlobal(ScriptObject *stack)
{
	stack->ScriptPos++;
	AnzUInt16 hcbIndex = *(AnzUInt16*)(stack->Buffer + stack->ScriptPos);
	
	#if SDL_BYTEORDER != SDL_LIL_ENDIAN
	hcbIndex = SDL_Swap16(hcbIndex);
	#endif

	ScriptEngine::GetHandle()->GlobalVar.Set(hcbIndex,
		stack->LocalStack[stack->CurStackFrame]);
	stack->LocalStack[stack->CurStackFrame].Relase();
	stack->CurStackFrame--;
	stack->ScriptPos +=2;
	return true;
}
Exemple #28
0
inline Uint16 NetUtl_recvShort(TCPsocket* sock){
	Uint16 num;
	int size;
	int total_size = 0;

	while((total_size < sizeof(num)) && 
		((size = SDLNet_TCP_Recv(*sock,&num,sizeof(num))) > 0)){
		total_size += size;
	}


	#if NEED_SWAP
		num = SDL_Swap16(num);
	#endif
	return num;
}
Exemple #29
0
uint16_t MessageIn::readId() const
{
    int16_t value = -1;
    if (mPos + 2 <= mLength)
    {
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
        int16_t swap;
        memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int16_t));
        value = SDL_Swap16(swap);
#else  // SDL_BYTEORDER == SDL_BIG_ENDIAN

        memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int16_t));
#endif  // SDL_BYTEORDER == SDL_BIG_ENDIAN
    }
    return value;
}
static __inline__ void UNICODE_strcpy(Uint16 *dst, const Uint16 *src, int swap)
{
	if ( swap ) {
		while ( *src ) {
			*dst = SDL_Swap16(*src);
			++src;
			++dst;
		}
		*dst = '\0';
	} else {
		while ( *src ) {
			*dst = *src;
			++src;
			++dst;
		}
		*dst = '\0';
	}
}