Exemplo n.º 1
0
Loader::LoaderVersion Loader::checkFile(std::string f) {
    BinaryFile file;
    if (file.open(f.c_str()) != 0)
        return TR_UNKNOWN;

    uint32_t start = file.readU32();
    switch (start) {
        case 0x00000020:
            return TR_1;

        case 0x0000002D:
            return TR_2;

        case 0xFF080038:
        case 0xFF180038:
            return TR_3;

        case 0xFFFFFFF0: // bogus
        case 0x00345254: // "TR4\0"
            return TR_4;
    }

    Log::get(LOG_ERROR) << "Unknown TR level version: \"" << start << "\"" << Log::endl;

    return TR_UNKNOWN;
}
Exemplo n.º 2
0
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
    char read_signature[32];

    file.ReadRawData(read_signature, signature_length);

    // Signatur überprüfen
    if(memcmp(read_signature, signature, signature_length) != 0)
    {
        // unterscheiden sich! --> raus
        LOG.lprintf("Error: File is not in a valid format! File path: %s\n", file.getFilePath().c_str());
        return false;
    }

    // Programmversion überspringen
    file.Seek(8, SEEK_CUR);

    // Version überprüfen
    unsigned short read_version = file.ReadUnsignedShort();
    if(read_version != version)
    {
        // anderes Dateiformat --> raus
        LOG.lprintf("Warning: File has an old version and cannot be used (version: %u; expected: %u, file path: %s)!\n", read_version, version, file.getFilePath().c_str());
        return false;
    }

    return true;
}
Exemplo n.º 3
0
void MapReader1700::read_platforms(CMap& map, BinaryFile& mapfile, bool fPreview)
{
    map.clearPlatforms();

    //Load moving platforms
    map.iNumPlatforms = (short)mapfile.read_i32();
    map.platforms = new MovingPlatform*[map.iNumPlatforms];

    for (short iPlatform = 0; iPlatform < map.iNumPlatforms; iPlatform++) {
        short iWidth = (short)mapfile.read_i32();
        short iHeight = (short)mapfile.read_i32();

        TilesetTile ** tiles = new TilesetTile*[iWidth];
        MapTile ** types = new MapTile*[iWidth];

        read_platform_tiles(map, mapfile, iWidth, iHeight, tiles, types);

        short iDrawLayer = 2;
        //printf("Layer: %d\n", iDrawLayer);

        short iPathType = 0;
        //printf("PathType: %d\n", iPathType);

        MovingPlatformPath* path = NULL;
        path = read_platform_path_details(mapfile, iPathType, fPreview);
        if (!path)
            continue;

        MovingPlatform * platform = new MovingPlatform(tiles, types, iWidth, iHeight, iDrawLayer, path, fPreview);
        map.platforms[iPlatform] = platform;
        map.platformdrawlayer[iDrawLayer].push_back(platform);
    }
}
Exemplo n.º 4
0
    void index(const tstring& sDir)
    {
        IndexWriterPtr pIndexWriter = m_pIndex->acquireWriter();

        DirectoryIterator di(sDir, false);
        while(di.hasNext())
        {
            const File& f = di.next();
            if(f.isFile())
            {
                BinaryFile bf;
                bf.open(f.getPath().c_str(), BinaryFile::READ);
                if(bf.isFileOpen())
                {
                    size_t nRead = (size_t)bf.getLength();
                    if (nRead > 0)
                    {
                        DocumentPtr pDoc = new Document(pIndexWriter->getDocSchema());
                        pDoc->addField(0, f.getPath().c_str());
                        char* buf = new char[nRead + 1];
                        bf.read(buf, nRead);
                        buf[nRead] = 0;
                        pDoc->addField(1, buf, nRead, false);
                        delete[] buf;
                        
                        pIndexWriter->addDocument(pDoc);
                    }
                }
            }
        }
        docPool.commit();
        pIndexWriter->close();
    }
Exemplo n.º 5
0
ExpressionValue expFuncRead(const std::vector<ExpressionValue>& parameters)
{
	ExpressionValue result;
	T buffer;

	if (parameters[0].isString() == false || (parameters.size() >= 2 && parameters[1].isInt() == false))
	{
		Logger::queueError(Logger::Error,L"Invalid parameter");
		return result;
	}

	std::wstring fileName = getFullPathName(parameters[0].strValue);
	u64 pos = parameters.size() >= 2 ? parameters[1].intValue : 0;

	BinaryFile file;
	if (file.open(fileName,BinaryFile::Read) == false)
	{
		Logger::queueError(Logger::Error,L"Could not open %s",fileName);
		return result;
	}

	file.setPos((long)pos);

	if (file.read(&buffer,sizeof(T)) == sizeof(T))
	{
		result.type = ExpressionValueType::Integer;
		result.intValue = (u64) buffer;
	}

	return result;
}
Exemplo n.º 6
0
BaseFile* FileInterface::OpenFile(const char* szFilename, EFileType eType, EFileFlags eFlags)
{
	switch(eType)
	{
	case BINARY_FILE:
		{
			BinaryFile* pFile = new BinaryFile;
			if(pFile)
			{
				GEN_RESULT res = pFile->Open(szFilename, eFlags);
				if(RESULT_OK == res)
				{
					return (BaseFile*)pFile;
				}
			}
		}
		break;
	case TEXT_FILE:
		{
			//TODO:
		}
		break;
	default:
		break;
	}

	return NULL;
}
Exemplo n.º 7
0
void MapReader1700::read_warp_locations(CMap& map, BinaryFile& mapfile)
{
    for (unsigned short j = 0; j < MAPHEIGHT; j++) {
        for (unsigned short i = 0; i < MAPWIDTH; i++) {
            TileType iType = (TileType)mapfile.read_i32();

            if (iType >= 0 && iType < NUMTILETYPES) {
                map.mapdatatop[i][j].iType = iType;
                map.mapdatatop[i][j].iFlags = g_iTileTypeConversion[iType];
            } else {
                map.mapdatatop[i][j].iType = tile_nonsolid;
                map.mapdatatop[i][j].iFlags = tile_flag_nonsolid;
            }

            map.warpdata[i][j].direction = (WarpEnterDirection)mapfile.read_i32();
            map.warpdata[i][j].connection = (short)mapfile.read_i32();
            map.warpdata[i][j].id = (short)mapfile.read_i32();

            for (short sType = 0; sType < 6; sType += 5)
                map.nospawn[sType][i][j] = mapfile.read_i32() == 0 ? false : true;

            //Copy player no spawn areas into team no spawn areas
            for (short sType = 1; sType < 5; sType++)
                map.nospawn[sType][i][j] = map.nospawn[0][i][j];

        }
    }
}
Exemplo n.º 8
0
/*==============================================================================
 * FUNCTION:        LoaderTest::testPentiumLoad
 * OVERVIEW:        Test loading the pentium (Solaris) hello world program
 *============================================================================*/
void LoaderTest::testPentiumLoad ()
{
    std::ostringstream ost;

    // Load Pentium hello world
    BinaryFileFactory bff;
    BinaryFile* pBF = bff.Load(HELLO_PENTIUM);
    CPPUNIT_ASSERT(pBF != NULL);
    int n;
    SectionInfo* si;
    n = pBF->GetNumSections();
    ost << "Number of sections = " << std::dec << n << "\r\n\t";
    si = pBF->GetSectionInfo(1);
    ost << si->pSectionName << "\t";
    si = pBF->GetSectionInfo(n-1);
    ost << si->pSectionName;
    pBF->UnLoad();
    // Note: the string below needs to have embedded tabs. Edit with caution!
    // (And slightly different string to the sparc test, e.g. rel vs rela)
    std::string expected("Number of sections = 34\r\n\t"
                         ".interp	.strtab");


    CPPUNIT_ASSERT_EQUAL(expected, ost.str());
    bff.UnLoad();
}
Exemplo n.º 9
0
ExpressionValue expFuncRead(const std::wstring& funcName, const std::vector<ExpressionValue>& parameters)
{
	const std::wstring* fileName;
	u64 pos;

	GET_PARAM(parameters,0,fileName);
	GET_OPTIONAL_PARAM(parameters,1,pos,0);

	std::wstring fullName = getFullPathName(*fileName);

	BinaryFile file;
	if (file.open(fullName,BinaryFile::Read) == false)
	{
		Logger::queueError(Logger::Error,L"Could not open %s",fileName);
		return ExpressionValue();
	}

	file.setPos((long)pos);

	T buffer;
	if (file.read(&buffer,sizeof(T)) != sizeof(T))
		return ExpressionValue();

	return ExpressionValue((u64) buffer);
}
Exemplo n.º 10
0
/*==============================================================================
 * FUNCTION:        LoaderTest::testPalmLoad
 * OVERVIEW:        Test loading the Palm 68328 Starter.prc program
 *============================================================================*/
void LoaderTest::testPalmLoad ()
{
    std::ostringstream ost;

    // Load Palm Starter.prc
    BinaryFileFactory bff;
    BinaryFile* pBF = bff.Load(STARTER_PALM);
    CPPUNIT_ASSERT(pBF != NULL);
    int n;
    SectionInfo* si;
    n = pBF->GetNumSections();
    ost << "Number of sections = " << std::dec << n << "\r\n";
    for (int i=0; i < n; i++)
        {
            si = pBF->GetSectionInfo(i);
            ost << si->pSectionName << "\t";
        }
    pBF->UnLoad();
    // Note: the string below needs to have embedded tabs. Edit with caution!
    std::string expected("Number of sections = 8\r\n"
                         "code1	MBAR1000	tFRM1000	Talt1001	"
                         "data0	code0	tAIN1000	tver1000	");
    CPPUNIT_ASSERT_EQUAL(expected, ost.str());
    bff.UnLoad();
}
Exemplo n.º 11
0
void MapReader1800::read_tiles(CMap& map, BinaryFile& mapfile)
{
    //2. load map data

    unsigned short i, j, k;
    for (j = 0; j < MAPHEIGHT; j++) {
        for (i = 0; i < MAPWIDTH; i++) {
            for (k = 0; k < MAPLAYERS; k++) {
                TilesetTile * tile = &map.mapdata[i][j][k];
                tile->iID = mapfile.read_i8();
                tile->iCol = mapfile.read_i8();
                tile->iRow = mapfile.read_i8();

                if (tile->iID >= 0) {
                    if (tile->iID > iMaxTilesetID)
                        tile->iID = 0;

                    //Make sure the column and row we read in is within the bounds of the tileset
                    if (tile->iCol < 0 || tile->iCol >= tilesetwidths[tile->iID])
                        tile->iCol = 0;

                    if (tile->iRow < 0 || tile->iRow >= tilesetheights[tile->iID])
                        tile->iRow = 0;

                    //Convert tileset ids into the current game's tileset's ids
                    tile->iID = translationid[tile->iID];
                }
            }

            map.objectdata[i][j].iType = mapfile.read_i8();
            map.objectdata[i][j].fHidden = mapfile.read_bool();
        }
    }
}
Exemplo n.º 12
0
/**
 *
 *  @author OLiver
 */
bool SavedFile::ValidateFile(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
    char read_signature[32];

    file.ReadRawData(read_signature, signature_length);

    // Signatur überprüfen
    if(memcmp(read_signature, signature, signature_length))
    {
        // unterscheiden sich! --> raus
        LOG.lprintf("SavedFile::Load: ERROR: Not a valid file!\n");
        return false;
    }

    // Programmversion überspringen
    file.Seek(8, SEEK_CUR);

    // Version überprüfen
    unsigned short read_version = file.ReadUnsignedShort();
    if(read_version != version)
    {
        // anderes Dateiformat --> raus
        LOG.lprintf("SavedFile::Load: ERROR: Old file version (version: %u; expected: %u)!\n", read_version, version);
        return false;
    }

    return true;
}
Exemplo n.º 13
0
void MapReader1802::read_eyecandy(CMap& map, BinaryFile& mapfile)
{
    //Read in eyecandy to use
    //For all layers if the map format supports it
    map.eyecandy[0] = (short)mapfile.read_i32();
    map.eyecandy[1] = (short)mapfile.read_i32();
    map.eyecandy[2] = (short)mapfile.read_i32();
}
Exemplo n.º 14
0
/**
 *  schreibt die GlobalGameSettings in die Datei.
 *
 *  @author OLiver
 */
void SavedFile::WriteGGS(BinaryFile& file)
{
    Serializer ser;
    ggs.Serialize(&ser);

    file.WriteUnsignedInt(ser.GetLength());
    file.WriteRawData(ser.GetData(), ser.GetLength());
}
Exemplo n.º 15
0
void XMLDocumentWrapper::printToFile(std::string& sFile)
{
    ostringstream os;
    print(os);
    BinaryFile bf;
    bf.open(sFile, BinaryFile::CREATE);
    bf.write(os.str().c_str(), os.str().length());
}
Exemplo n.º 16
0
/**
 *  liest die GlobalGameSettings aus der Datei.
 *
 *  @author OLiver
 */
void SavedFile::ReadGGS(BinaryFile& file)
{
    unsigned length = file.ReadUnsignedInt();
    boost::interprocess::unique_ptr<unsigned char, Deleter<unsigned char[]> > buffer(new unsigned char[length]);

    file.ReadRawData(buffer.get(), length);
    Serializer ser(buffer.get(), length);

    ggs.Deserialize(ser);
}
Exemplo n.º 17
0
/*==============================================================================
 * FUNCTION:		RtlTest::testIsCompare
 * OVERVIEW:		Test the isCompare function
 *============================================================================*/
void RtlTest::testIsCompare ()
{
  BinaryFileFactory bff;
  BinaryFile *pBF = bff.Load(SWITCH_SPARC);
  CPPUNIT_ASSERT(pBF != 0);
  CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_SPARC);
  Prog* prog = new Prog;
  FrontEnd *pFE = new SparcFrontEnd(pBF, prog, &bff);
  prog->setFrontEnd(pFE);

  // Decode second instruction: "sub		%i0, 2, %o1"
  int iReg;
  Exp* eOperand = NULL;
  DecodeResult inst = pFE->decodeInstruction(0x10910);
  CPPUNIT_ASSERT(inst.rtl != NULL);
  CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == false);

  // Decode fifth instruction: "cmp		%o1, 5"
  inst = pFE->decodeInstruction(0x1091c);
  CPPUNIT_ASSERT(inst.rtl != NULL);
  CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == true);
  CPPUNIT_ASSERT_EQUAL(9, iReg);
  std::string expected("5");
  std::ostringstream ost1;
  eOperand->print(ost1);
  std::string actual(ost1.str());
  CPPUNIT_ASSERT_EQUAL(expected, actual);

  pBF->UnLoad();
  delete pBF;
  delete pFE;
  pBF = bff.Load(SWITCH_PENT);
  CPPUNIT_ASSERT(pBF != 0);
  CPPUNIT_ASSERT(pBF->GetMachine() == MACHINE_PENTIUM);
  pFE = new PentiumFrontEnd(pBF, prog, &bff);
  prog->setFrontEnd(pFE);

  // Decode fifth instruction: "cmp	$0x5,%eax"
  inst = pFE->decodeInstruction(0x80488fb);
  CPPUNIT_ASSERT(inst.rtl != NULL);
  CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == true);
  CPPUNIT_ASSERT_EQUAL(24, iReg);
  std::ostringstream ost2;
  eOperand->print(ost2);
  actual = ost2.str();
  CPPUNIT_ASSERT_EQUAL(expected, actual);

  // Decode instruction: "add		$0x4,%esp"
  inst = pFE->decodeInstruction(0x804890c);
  CPPUNIT_ASSERT(inst.rtl != NULL);
  CPPUNIT_ASSERT(inst.rtl->isCompare(iReg, eOperand) == false);
  pBF->UnLoad();
  delete pFE;
}
Exemplo n.º 18
0
void MapReader1800::read_switchable_blocks(CMap& map, BinaryFile& mapfile)
{
    //Read switch block state data
    int iNumSwitchBlockData = mapfile.read_i32();
    for (short iBlock = 0; iBlock < iNumSwitchBlockData; iBlock++) {
        short iCol = mapfile.read_i8();
        short iRow = mapfile.read_i8();

        map.objectdata[iCol][iRow].iSettings[0] = mapfile.read_i8();
    }
}
Exemplo n.º 19
0
void MapReader1800::read_items(CMap& map, BinaryFile& mapfile)
{
    //Load map items (like carryable spikes and springs)
    map.iNumMapItems = mapfile.read_i32();

    for (short j = 0; j < map.iNumMapItems; j++) {
        map.mapitems[j].itype = mapfile.read_i32();
        map.mapitems[j].ix = mapfile.read_i32();
        map.mapitems[j].iy = mapfile.read_i32();
    }
}
Exemplo n.º 20
0
/**
 *
 *  @author OLiver
 */
void SavedFile::WriteVersion(BinaryFile& file, unsigned int signature_length, const char* signature, unsigned short version)
{
    // Signatur schreiben
    file.WriteRawData(signature, signature_length);

    // Version vom Programm reinschreiben (mal 0 mit reinschreiben, damits ne runde 8 ergibt!)
    file.WriteRawData(GetWindowRevision(), 8);

    // Version des Save-Formats
    file.WriteUnsignedShort(version);
}
Exemplo n.º 21
0
/**
 *  liest die GlobalGameSettings aus der Datei.
 *
 *  @author OLiver
 */
void SavedFile::ReadGGS(BinaryFile& file)
{
    unsigned length = file.ReadUnsignedInt();
    unsigned char* buffer = new unsigned char[length];

    file.ReadRawData(buffer, length);
    Serializer ser(buffer, length);

    ggs.Deserialize(&ser);

    delete[] buffer;
}
Exemplo n.º 22
0
/**
 *
 *  @author OLiver
 */
bool Savegame::Save(const std::string& filename)
{
    BinaryFile file;

    if(!file.Open(filename, OFM_WRITE))
        return false;

    bool ret = Save(file);

    file.Close();

    return ret;
}
Exemplo n.º 23
0
/**
 *
 *  @author OLiver
 */
bool Savegame::Load(const std::string& filePath, const bool load_players, const bool load_sgd)
{
    BinaryFile file;

    if(!file.Open(filePath, OFM_READ))
        return false;

    bool ret = Load(file, load_players, load_sgd);

    file.Close();

    return ret;
}
Exemplo n.º 24
0
void MapReader1800::read_extra_tiledata(CMap& map, BinaryFile& mapfile)
{
    int iNumExtendedDataBlocks = mapfile.read_i32();

    for (short iBlock = 0; iBlock < iNumExtendedDataBlocks; iBlock++) {
        short iCol = mapfile.read_i8();
        short iRow = mapfile.read_i8();

        short iNumSettings = mapfile.read_i8();
        for (short iSetting = 0; iSetting < iNumSettings; iSetting++)
            map.objectdata[iCol][iRow].iSettings[iSetting] = mapfile.read_i8();
    }
}
Exemplo n.º 25
0
static PlankResult plonk_BinaryFileInternal_BinaryFileQueue_NextFuntion (PlankMulitFileReaderRef p)
{
    if (! p->currentFile)
        p->currentFile = pl_File_CreateAndInit();
    
    BinaryFileQueue& queue = *static_cast<BinaryFileQueue*> (p->source);
    BinaryFile binaryFile = queue.pop();
    
    pl_File_DeInit (p->currentFile);
    binaryFile.disownPeer (p->currentFile);
    
    return PlankResult_OK;
}
string TrecDocumentProcessorTestCase::writeTestFile(const string& sFileName, 
                                                      const char* szFileContent)
{
    std::string sPath = getTestOutputPath();
    sPath += "/" + sFileName;
    
    BinaryFile bf;
    bf.open(sPath, BinaryFile::CREATE);
    bf.write(szFileContent, strlen(szFileContent));
    bf.close();

    return sPath;
}
Exemplo n.º 27
0
void MapReader1800::read_gamemode_settings(CMap& map, BinaryFile& mapfile)
{
    //read mode item locations like flags and race goals
    map.iNumRaceGoals = (short)mapfile.read_i32();
    for (unsigned short j = 0; j < map.iNumRaceGoals; j++) {
        map.racegoallocations[j].x = (short)mapfile.read_i32();
        map.racegoallocations[j].y = (short)mapfile.read_i32();
    }

    map.iNumFlagBases = (short)mapfile.read_i32();
    for (unsigned short j = 0; j < map.iNumFlagBases; j++) {
        map.flagbaselocations[j].x = (short)mapfile.read_i32();
        map.flagbaselocations[j].y = (short)mapfile.read_i32();
    }
}
Exemplo n.º 28
0
void BinaryFileTestCase::testLargeFileSeekAndRead()
{
#ifdef TEST_LARGE_FILE
	tstring str = TestHelper::getTestDataPath(_T("BinaryFileTestLargeFile"), false);
	BinaryFile bf;
	bf.open(str.c_str(), BinaryFile::READ);
	CPPUNIT_ASSERT( bf.isFileOpen() );
	int64_t nPos = 1000000000;//1 GB
	nPos <<= 4;//16 GB
	int64_t nData = 123456789;
	bf.seek(nPos);
	bf.read(&nData,sizeof(int64_t));
	CPPUNIT_ASSERT_EQUAL(nData,(int64_t)123456789);
#endif
}
Exemplo n.º 29
0
void SavedFile::ReadPlayerData(BinaryFile& file)
{
    for(std::vector<Player>::iterator it = players.begin(); it != players.end(); ++it)
    {
        it->ps = file.ReadUnsignedInt();

        if(it->ps != PS_LOCKED)
        {
            it->name = file.ReadShortString();
            it->nation = Nation(file.ReadUnsignedChar());
            it->color = file.ReadUnsignedInt();
            it->team = file.ReadUnsignedChar();
        }
    }
}
Exemplo n.º 30
0
/**
 *
 *  @author OLiver
 */
void SavedFile::WritePlayerData(BinaryFile& file)
{
    // Spielerdaten
    for(unsigned char i = 0; i < player_count; ++i)
    {
        file.WriteUnsignedInt(players[i].ps);

        if(players[i].ps != PS_LOCKED)
        {
            file.WriteShortString(players[i].name);
            file.WriteUnsignedChar(players[i].nation);
            file.WriteUnsignedChar(players[i].color);
            file.WriteUnsignedChar(players[i].team);
        }
    }
}