示例#1
0
/*
address = absolute address of dump start
length = length in lines. 1 line = 16 bytes
*/
void hexdump (DFHack::API& DF, uint32_t address, uint32_t length)
{
    char *buf = new char[length * 16];
    
    DF.ReadRaw(address, length * 16, (uint8_t *) buf);
    for (int i = 0; i < length; i++)
    {
        // leading offset
        cout << "0x" << hex << setw(4) << i*16 << " ";
        // groups
        for(int j = 0; j < 4; j++)
        {
            // bytes
            for(int k = 0; k < 4; k++)
            {
                int idx = i * 16 + j * 4 + k;
                
                cout << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " ";
            }
            cout << " ";
        }
        cout << endl;
    }
    delete buf;
}
示例#2
0
void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement, const vector< vector<string> > &englishWords, const vector< vector<string> > &foreignWords)
{
    cout << "First name: " << settlement.name.first_name << endl <<  "Nickname: " << settlement.name.nickname << endl;
    cout << settlement.name.words[0] << " " << settlement.name.words[1] << " " << settlement.name.words[2] << " "
    << settlement.name.words[3] << " " << settlement.name.words[4] << " " << settlement.name.words[5] << " "
    << settlement.name.words[6] << " " << settlement.name.words[7] << endl;
    cout << settlement.name.parts_of_speech[0] << " " << settlement.name.parts_of_speech[1] << " " << settlement.name.parts_of_speech[2] << " "
    << settlement.name.parts_of_speech[3] << " " << settlement.name.parts_of_speech[4] << " " << settlement.name.parts_of_speech[5] << " "
    << settlement.name.parts_of_speech[6] << " " << settlement.name.parts_of_speech[7] << endl;

    printf("Origin: 0x%x\n",settlement.origin);
    
    string genericName = DF.TranslateName(settlement.name,englishWords,foreignWords,true);
    string dwarfName = DF.TranslateName(settlement.name,englishWords,foreignWords,false);
    cout << dwarfName << " " << genericName << " " << "world x: " << settlement.world_x << " world y: " << settlement.world_y 
        << " local_x: " << settlement.local_x1 << " local_y: " << settlement.local_y1 << " size: " << settlement.local_x2 - settlement.local_x1 << " by " << settlement.local_y2 - settlement.local_y1 << "\n";
}
示例#3
0
void interleave_hex (DFHack::API& DF, vector < uint32_t > & addresses, uint32_t length)
{
    vector <char * > bufs;
    
    for(int counter = 0; counter < addresses.size(); counter ++)
    {
        char * buf = new char[length * 16];
        DF.ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
        bufs.push_back(buf);
    }
    cout << setfill('0');

    // output a header
    cout << "line offset ";
    for (int obj = 0; obj < addresses.size(); obj++)
    {
        cout << "0x" << hex << setw(9) << addresses[obj] << "  ";
    }
    cout << endl;
    
    for(int offs = 0 ; offs < length * 16; offs += 4)
    {
        if((!(offs % 16)) && offs != 0)
        {
            cout << endl;
        }
        cout << setfill(' ');
        cout << dec << setw(4) << offs/4 << " ";
        cout << setfill('0');
        cout << "0x" << hex << setw(4) << offs << " ";
        for (int object = 0; object < bufs.size(); object++)
        {
            // bytes
            for(int k = 0; k < 4; k++)
            {
                uint8_t data = bufs[object][offs + k];
                cout << hex << setw(2) << int(static_cast<unsigned char>(data)) << " ";
            }
            cout << " ";
        }
        cout << endl;
    }
    for(int counter = 0; counter < addresses.size(); counter ++)
    {
        delete bufs[counter];
    }
}
示例#4
0
int main (int argc,const char* argv[])
{
    DFHack::API DF ("Memory.xml");
    if(!DF.Attach())
    {
        cerr << "DF not found" << endl;
        return 1;
    }
    DFHack::t_settlement current;
    uint32_t numSettlements;
    if(!DF.InitReadSettlements(numSettlements))
    {
		cerr << "Could not read Settlements" << endl;
		return 1;
	}
	vector< vector<string> > englishWords;
	vector< vector<string> > foreignWords;
    if(!DF.InitReadNameTables(englishWords,foreignWords))
    {
        cerr << "Can't get name tables" << endl;
        return 1;
    }
	cout << "Settlements\n";
	/*for(uint32_t i =0;i<numSettlements;i++){
		DFHack::t_settlement temp;
		DF.ReadSettlement(i,temp);
		printSettlement(DF,temp,englishWords,foreignWords);
	}*/
	// MSVC claims this is causing the heap to be corrupted, I think it is because the currentSettlement vector only has 1 item in it
	cout << "Current Settlement\n";
	if(DF.ReadCurrentSettlement(current))
		printSettlement(DF,current,englishWords,foreignWords);

	DF.FinishReadNameTables();
	DF.FinishReadSettlements();
	DF.Detach();
	#ifndef LINUX_BUILD
    cout << "Done. Press any key to continue" << endl;
    cin.ignore();
    #endif
	return 0;
}
示例#5
0
/*
address = absolute address of dump start
length = length in bytes
*/
void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum)
{
    uint32_t reallength;
    uint32_t lines;
    lines = (length / 16) + 1;
    reallength = lines * 16;
    char *buf = new char[reallength];
    ofstream myfile;

    stringstream ss;
    ss << "hexdump" << filenum << ".txt";
    string name = ss.str();

    myfile.open (name.c_str());

    DF.ReadRaw(address, reallength, (uint8_t *) buf);
    for (int i = 0; i < lines; i++)
    {
        // leading offset
        myfile << "0x" << hex << setw(4) << i*16 << " ";
        // groups
        for(int j = 0; j < 4; j++)
        {
            // bytes
            for(int k = 0; k < 4; k++)
            {
                int idx = i * 16 + j * 4 + k;

                myfile << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " ";
            }
            myfile << " ";
        }
        myfile << endl;
    }
    delete buf;
    myfile.close();
}
示例#6
0
void Extractor::LoadCellData(DFHack::API & DF,
                       vector< vector <uint16_t> >& layerassign,
                       Cell* TargetCell,
                       map<uint64_t, DFHack::t_construction> & constructions,
                       map<uint64_t, DFHack::t_tree_desc> & vegetation,
                       map<uint64_t, DFHack::t_building> & buildings, // FIXME: this is wrong for buildings. they can overlap
                       CellCoordinates NewCellCoordinates)
{
    uint16_t tiletypes[16][16];
    DFHack::t_designation designations[16][16];
    DFHack::t_occupancy occupancies[16][16];
    uint8_t regionoffsets[16];
    int16_t basemat [16][16];
    int16_t veinmat [16][16];
    DFHack::t_matglossPair constmat [16][16];
    vector <t_vein> veins;

    DF.ReadTileTypes(NewCellCoordinates.X, NewCellCoordinates.Y, NewCellCoordinates.Z, (uint16_t *) tiletypes);
    DF.ReadDesignations(NewCellCoordinates.X, NewCellCoordinates.Y, NewCellCoordinates.Z, (uint32_t *) designations);
    DF.ReadOccupancy(NewCellCoordinates.X, NewCellCoordinates.Y, NewCellCoordinates.Z, (uint32_t *) occupancies);
    DF.ReadRegionOffsets(NewCellCoordinates.X, NewCellCoordinates.Y, NewCellCoordinates.Z, regionoffsets);

    memset(basemat, -1, sizeof(basemat));
    memset(veinmat, -1, sizeof(veinmat));
    memset(constmat, -1, sizeof(constmat));
    veins.clear();
    DF.ReadVeins(NewCellCoordinates.X, NewCellCoordinates.Y, NewCellCoordinates.Z, veins);

    // get the materials, buildings, trees
    for(uint32_t xx = 0; xx < 16; xx++)
    {
        for (uint32_t yy = 0; yy < 16; yy++)
        {
            // base rock layers
            basemat[xx][yy] = layerassign[regionoffsets[designations[xx][yy].bits.biome]][designations[xx][yy].bits.geolayer_index];

            // veins
            for(int i = 0; i < veins.size();i++)
            {
                // and the bit array with a one-bit mask, check if the bit is set
                bool set = ((1 << xx) & veins[i].assignment[yy]) >> xx;
                if(set)
                {
                    // store matgloss
                    veinmat[xx][yy] = veins[i].type;
                }
            }

            // constructions
            uint64_t coord =  (uint64_t)NewCellCoordinates.Z + ((uint64_t)(NewCellCoordinates.Y *16 + yy) << 16) + ((uint64_t)(NewCellCoordinates.X *16 + xx) << 32);
            if(constructions.count(coord))
            {
                // store matgloss
                constmat[xx][yy] = constructions[coord].material;
            }

            // plants
            if(vegetation.count(coord))
            {
                DFHack::t_tree_desc t = vegetation[coord];
                DFHack::TileClass Type = (DFHack::TileClass) DFHack::getVegetationType(tiletypes[xx][yy]);

                if (t.material.type == Mat_Wood)
                {
                    int16_t TreeTypeID = ResolveMatGlossPair(t.material);

                    bool isAlive = false;

                    switch(Type)
                    {
                        case DFHack::TREE_DEAD:
                        case DFHack::SAPLING_DEAD:
                        case DFHack::SHRUB_DEAD:
                            isAlive = false;
                            break;

                        case DFHack::TREE_OK:
                        case DFHack::SAPLING_OK:
                        case DFHack::SHRUB_OK:
                            isAlive = true;
                            break;
                    }

                    GAME->SpawnTree(MapCoordinates(t.x, t.y, t.z), TreeTypeID, isAlive);
                }
            }

            // buildings, FIXME: doesn't work with overlapping buildings
            if(buildings.count(coord))
            {
                DFHack::t_building b = buildings[coord];

                for(uint32_t i = 0; i < DATA->getNumBuildings(); i++)
                {
                    if (DATA->getBuildingData(i)->getMatgloss() == b.type)
                    {
                        int16_t MaterialID = ResolveMatGlossPair(b.material);
                        Building* NewBuilding = new Building(MapCoordinates(b.x1, b.y1, b.z), b.x2 - b.x1, b.y2 - b.y1, MaterialID, i);
                        TargetCell->addBuilding(NewBuilding);
                    }
                }
            }
        }
    }

    CubeCoordinates Coordinates;

    for (Coordinates.X = 0; Coordinates.X < CELLEDGESIZE; Coordinates.X += 1)
    {
        for (Coordinates.Y = 0; Coordinates.Y < CELLEDGESIZE; Coordinates.Y += 1)
        {
            DFHack::t_designation Designations = designations[Coordinates.X][Coordinates.Y];
            uint16_t TileType = tiletypes[Coordinates.X][Coordinates.Y];
            DFHack::t_occupancy Ocupancies = occupancies[Coordinates.X][Coordinates.Y];

            int16_t TileShapeID = TileShapePicker[TileType];
            int16_t TileSurfaceID = TileSurfacePicker[TileType];
            int16_t TileMaterialID = PickMaterial(TileType, basemat[Coordinates.X][Coordinates.Y], veinmat[Coordinates.X][Coordinates.Y], constmat[Coordinates.X][Coordinates.Y], Ocupancies);

            TargetCell->setCubeShape(Coordinates, TileShapeID);
            TargetCell->setCubeSurface(Coordinates, TileSurfaceID);
            TargetCell->setCubeMaterial(Coordinates, TileMaterialID);

            TargetCell->setCubeHidden(Coordinates, Designations.bits.hidden);
            TargetCell->setCubeSubTerranean(Coordinates, Designations.bits.subterranean);
            TargetCell->setCubeSkyView(Coordinates, Designations.bits.skyview);
            TargetCell->setCubeSunLit(Coordinates, Designations.bits.light);

            if(Designations.bits.flow_size)
            {
                TargetCell->setLiquid(Coordinates, Designations.bits.liquid_type, Designations.bits.flow_size);
            }
            //TargetCube->setVisible(true);
        }
    }
}
示例#7
0
void Extractor::InitilizeTilePicker(DFHack::API & DF)
{
    for(int i = 0; i < 600; ++i)  // Exact number of possible DF tile types isn't know
    {
        TileShapePicker[i] = -1;
        TileSurfacePicker[i] = -1;
        TileMaterialPicker[i] = -1;
        TileMaterialClassPicker[i] = -1;
    }

    // Index the Shape, Surface and Material values of each tile
    for(uint32_t i = 0; i < DATA->getNumTileGroups(); ++i)
    {
        for(uint32_t j = 0; j < DATA->getTileGroupData(i)->TileValues.size(); ++j)
        {
            int Tile = DATA->getTileGroupData(i)->TileValues[j];

            TileShapePicker[Tile] = DATA->getTileGroupData(i)->TileShapeID[j];
            TileSurfacePicker[Tile] = DATA->getTileGroupData(i)->SurfaceTypeID[j];

            TileMaterialPicker[Tile] = DATA->getTileGroupData(i)->getMaterialID();
            TileMaterialClassPicker[Tile] = DATA->getTileGroupData(i)->getMaterialClassID();
        }
    }

    // FIXME: move to .h, so that it can be saved/loaded
    vector<t_matgloss> stonetypes;
    vector<t_matgloss> metaltypes;
    vector<t_matgloss> woodtypes;
    vector<t_matgloss> planttypes;

    DF.ReadStoneMatgloss(stonetypes);
    DF.ReadPlantMatgloss(metaltypes);  // HACK, DF ReadPlantMatgloss and ReadMetalMatgloss are reversed
    DF.ReadWoodMatgloss(woodtypes);
    DF.ReadMetalMatgloss(planttypes);

    int16_t uninitialized = -1;

    uint32_t NumStoneMats = stonetypes.size();
    for(uint32_t i = 0; i < NumStoneMats; i++)
    {
        bool Matchfound = false;
        for(uint32_t j = 0; j < DATA->getNumMaterials(); ++j)
        {
            if(DATA->getMaterialClassData(DATA->getMaterialData(j)->getMaterialClass())->getMatGlossIndex() == Mat_Stone)
            {
                if(DATA->getMaterialData(j)->getMatGloss() == stonetypes[i].id)
                {
                    StoneMatGloss.push_back(j);
                    Matchfound = true;
                    break;
                }
            }
        }
        if(!Matchfound)
        {
            StoneMatGloss.push_back(uninitialized);
        }
    }

    uint32_t NumMetalMats = metaltypes.size();
    for(uint32_t i = 0; i < NumMetalMats; i++)
    {
        bool Matchfound = false;
        for(uint32_t j = 0; j < DATA->getNumMaterials(); ++j)
        {
            if(DATA->getMaterialClassData(DATA->getMaterialData(j)->getMaterialClass())->getMatGlossIndex() == Mat_Metal)
            {
                if(DATA->getMaterialData(j)->getMatGloss() == metaltypes[i].id)
                {
                    MetalMatGloss.push_back(j);
                    Matchfound = true;
                    break;
                }
            }
        }
        if(!Matchfound)
        {
            MetalMatGloss.push_back(uninitialized);
        }
    }


    uint32_t NumTreeMats = woodtypes.size();
    for(uint32_t i = 0; i < NumTreeMats; i++)
    {
        bool Matchfound = false;
        for(uint32_t j = 0; j < DATA->getNumTrees(); ++j)
        {
            if(DATA->getTreeData(j)->getMatgloss() == woodtypes[i].id)
            {
                WoodMatGloss.push_back(j);
                Matchfound = true;
                break;
            }
        }
        if(!Matchfound)
        {
            WoodMatGloss.push_back(uninitialized);
        }
    }
}