Example #1
0
bool CHuffman::readDictionaryNumberfromEnd(const CExeFile& ExeFile)
{        
    const uint32_t bytesToCheck = ExeFile.getExeDataSize()-DICT_SIG_BYTES;

    uint8_t *data_ptr = static_cast<uint8_t*>(ExeFile.getHeaderData())+bytesToCheck;

    for( Uint32 i=0; i<bytesToCheck ; i++ )
    {
        data_ptr--;
        if( memcmp(data_ptr, DICTSIG, DICT_SIG_BYTES) == 0 )
        {
       		uint8_t *dictdata = data_ptr-(DICT_SIZE*sizeof(nodestruct))+DICT_SIG_BYTES;
       		const Uint32 size = DICT_SIZE*sizeof(nodestruct);
       		memcpy(m_nodes, dictdata, size);

            //dumpToExternalFile("dump.huffmann");

       		return true;
        }
    }



    return false;
}
Example #2
0
bool CHuffman::readDictionaryNumber( const CExeFile& ExeFile,
                                     const int dictnum,
                                     const unsigned int dictOffset )
{
    uint8_t dictnumleft = dictnum;

    if( dictOffset == 0) // don't seek to offset
    {
        uint8_t *data_ptr = ExeFile.getRawData();

        for( Uint32 i=0; i<ExeFile.getExeDataSize() ; i++ )
        {
            if( memcmp(data_ptr, DICTSIG, DICT_SIG_BYTES) == 0 )
            {
                if(dictnumleft == 0)
                {
                    uint8_t *dictdata = data_ptr-(DICT_SIZE*sizeof(nodestruct))+DICT_SIG_BYTES;
                    const Uint32 size = DICT_SIZE*sizeof(nodestruct);
                    memcpy(m_nodes, dictdata, size);
                    return true;
                }
                dictnumleft--;
            }
            data_ptr++;
        }
        return false;
    }
    else // Otherwise copy the dictionary normally
    {
        uint8_t *dictdata = (byte*)(ExeFile.getHeaderData())+dictOffset;
        memcpy(reinterpret_cast<char*>(m_nodes), dictdata, DICT_SIZE*sizeof(nodestruct));
        return true;
    }
}
Example #3
0
CHelp::CHelp(CExeFile &ExeFile, const std::string &type) :
mp_TextViewer(NULL)
{
	std::string Text;
	std::string DataDirectory = ExeFile.getDataDirectory();
	char episode = ExeFile.getEpisode();
	
	// Read the Storytext
	if(type == "Game")
	{
		if(episode==1)
		{
			// We suppose that we are using version 131. Maybe it must be extended
			std::string filename = DataDirectory;
			if(DataDirectory != "")
				filename += "/";
			
			filename += "helptext.ck1";
			
			std::ifstream File; OpenGameFileR(File, filename, std::ios::binary);
			
			if(!File) return;
			
			while(!File.eof())
				Text.push_back(File.get());
			
			File.close();
			Text.erase(Text.size()-1);
		}
		else
		{
			// Here the Text file is within the EXE-File
			unsigned long startflag=0, endflag=0;
			unsigned char *text_data = NULL;
			
			
			if(!ExeFile.getHeaderData()) return;
			
			if(episode == 2)
			{
				startflag = 0x15DC0;
				endflag = 0x1659F;
			}
			else // Episode 3
			{
				startflag = 0x17BD0;
				endflag = 0x1839B;
			}
			
			text_data = ExeFile.getRawData();
			
			for(unsigned long i=startflag ; i<endflag ; i++ )
				Text.push_back(text_data[i]);
		}
	}
	else
	{
		std::string filename = "HELPTEXT.CKP";

		std::ifstream File; OpenGameFileR(File, filename, std::ios::binary);

		if(!File) return;

		while(!File.eof())
			Text.push_back(File.get());

		File.close();
		Text.erase(Text.size()-1);
	}

	// Create the Text ViewerBox and stores the text there!
	mp_TextViewer = new CTextViewer(g_pVideoDriver->mp_VideoEngine->getFGLayerSurface(), 0, 8, 320, 160);
	mp_TextViewer->formatText(Text);
}