Merge git://github.com/peterix/dfhack

develop
rampaging-poet 2011-11-03 01:04:34 -07:00
commit df3e11d1e4
11 changed files with 166 additions and 121 deletions

@ -25,7 +25,7 @@ set(DF_VERSION_MINOR "31")
set(DF_VERSION_PATCH "25")
set(DF_VERSION "${DF_VERSION_MAJOR}.${DF_VERSION_MINOR}.${DF_VERSION_PATCH}")
set(DFHACK_RELEASE "7c")
set(DFHACK_RELEASE "7d")
## where to install things (after the build is done, classic 'make install' or package structure)
# the dfhack libraries will be installed here:

@ -40,6 +40,7 @@ using namespace std;
#include "dfhack/VersionInfoFactory.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/Error.h"
#include <string.h>
using namespace DFHack;
Process::Process(VersionInfoFactory * known_versions)
@ -54,8 +55,11 @@ Process::Process(VersionInfoFactory * known_versions)
my_descriptor = 0;
md5wrapper md5;
uint32_t length;
uint8_t first_kb [1024];
memset(first_kb, 0, sizeof(first_kb));
// get hash of the running DF process
string hash = md5.getHashFromFile(exe_link_name);
string hash = md5.getHashFromFile(exe_link_name, length, (char *) first_kb);
// create linux process, add it to the vector
VersionInfo * vinfo = known_versions->getVersionInfoByMD5(hash);
if(vinfo)
@ -71,6 +75,29 @@ Process::Process(VersionInfoFactory * known_versions)
cerr << "File: " << exe_link_name << endl;
cerr << "MD5: " << hash << endl;
cerr << "working dir: " << wd << endl;
cerr << "length:" << length << endl;
cerr << "1KB hexdump follows:" << endl;
for(int i = 0; i < 64; i++)
{
fprintf(stderr, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
first_kb[i*16],
first_kb[i*16+1],
first_kb[i*16+2],
first_kb[i*16+3],
first_kb[i*16+4],
first_kb[i*16+5],
first_kb[i*16+6],
first_kb[i*16+7],
first_kb[i*16+8],
first_kb[i*16+9],
first_kb[i*16+10],
first_kb[i*16+11],
first_kb[i*16+12],
first_kb[i*16+13],
first_kb[i*16+14],
first_kb[i*16+15]
);
}
free(wd);
}
}

@ -108,12 +108,13 @@ std::string md5wrapper::getHashFromString(std::string text)
* (based on Ronald L. Rivest's code
* from RFC1321 "The MD5 Message-Digest Algorithm")
*/
std::string md5wrapper::getHashFromFile(std::string filename)
std::string md5wrapper::getHashFromFile(std::string filename, uint32_t & length, char * first_kb)
{
FILE *file;
MD5_CTX context;
int len;
int saved = 0;
unsigned char buffer[1024], digest[16];
//open file
@ -121,7 +122,7 @@ std::string md5wrapper::getHashFromFile(std::string filename)
{
return "file unreadable.";
}
length = 0;
//init md5
md5->MD5Init (&context);
@ -130,6 +131,12 @@ std::string md5wrapper::getHashFromFile(std::string filename)
{
errno = 0;
len = fread (buffer, 1, 1024, file);
if(saved < 1024 && first_kb)
{
memcpy(first_kb + saved, buffer, std::min (len, 1024 - saved));
saved += len;
}
length += len;
if(len != 1024)
{
int err = ferror(file);

@ -22,6 +22,7 @@
//basic includes
#include <string>
#include <stdint.h>
//forwards
class MD5;
@ -61,7 +62,7 @@ class md5wrapper
* a file specified in "filename" and
* returns it as string
*/
std::string getHashFromFile(std::string filename);
std::string getHashFromFile(const std::string filename, uint32_t & length, char * first_kb = NULL);
};

@ -199,18 +199,6 @@ namespace DFHack
/// a 16x16 array of the original tile types
int16_t tiles[16][16];
};
/**
* \ingroup grp_maps
*/
enum e_matter_state
{
state_solid,
state_liquid,
state_gas,
state_powder,
state_paste,
state_pressed
};
/**
* a 'spattervein' defines what coverings the individual map tiles have (snow, blood, etc)
* bitmap of intensity with matrial type

@ -39,10 +39,29 @@ distribution.
namespace DFHack
{
typedef int32_t t_materialIndex;
typedef int16_t t_materialType, t_itemType, t_itemSubtype;
struct t_syndrome
{
// it's lonely here...
};
/**
* \ingroup grp_materials
*/
enum e_matter_state
{
state_solid,
state_liquid,
state_gas,
state_powder,
state_paste,
state_pressed,
NUM_MATTER_STATES
};
/**
* \ingroup grp_materials
*/
enum material_flags
{
MATERIAL_BONE = 0,
@ -135,6 +154,9 @@ namespace DFHack
MATERIAL_UNK78,
MATERIAL_UNK79,
};
/**
* \ingroup grp_materials
*/
enum inorganic_flags
{
INORGANIC_LAVA = 0,
@ -173,7 +195,10 @@ namespace DFHack
INORGANIC_UNK30,
INORGANIC_UNK31,
};
//Environment locations:
/**
* Environment locations
* \ingroup grp_materials
*/
enum environment_location
{
ENV_SOIL,
@ -185,7 +210,10 @@ namespace DFHack
ENV_IGNEOUS_EXTRUSIVE,
ENV_ALLUVIAL,
};
//Inclusion types:
/**
* Inclusion types
* \ingroup grp_materials
*/
enum inclusion_type
{
INCLUSION_NONE, // maybe
@ -194,7 +222,11 @@ namespace DFHack
INCLUSION_CLUSTER_SMALL,
INCLUSION_CLUSTER_ONE,
};
/// Research by Quietust
/**
* The reversed generic material struct
* Research by Quietust
* \ingroup grp_materials
*/
struct df_material
{
std::string Material_ID;
@ -212,24 +244,9 @@ namespace DFHack
int32_t SOLID_DENSITY;
int32_t LIQUID_DENSITY;
int32_t MOLAR_MASS;
int32_t STATE_COLOR_SOLID; // (color token index)
int32_t STATE_COLOR_LIQUID; // (color token index)
int32_t STATE_COLOR_GAS; // (color token index)
int32_t STATE_COLOR_POWDER; // (color token index)
int32_t STATE_COLOR_PASTE; // (color token index)
int32_t STATE_COLOR_PRESSED;// (color token index)
std::string STATE_NAME_SOLID;
std::string STATE_NAME_LIQUID;
std::string STATE_NAME_GAS;
std::string STATE_NAME_POWDER;
std::string STATE_NAME_PASTE;
std::string STATE_NAME_PRESSED;
std::string STATE_ADJ_SOLID;
std::string STATE_ADJ_LIQUID;
std::string STATE_ADJ_GAS;
std::string STATE_ADJ_POWDER;
std::string STATE_ADJ_PASTE;
std::string STATE_ADJ_PRESSED;
int32_t state_color[NUM_MATTER_STATES]; // color token indexes
std::string state_name[NUM_MATTER_STATES];
std::string state_adj[NUM_MATTER_STATES];
int32_t ABSORPTION;
int32_t BENDING_YIELD;
int32_t SHEAR_YIELD;
@ -252,9 +269,9 @@ namespace DFHack
int32_t MAX_EDGE;
int32_t MATERIAL_VALUE;
BitArray <material_flags> mat_flags;
int16_t EXTRACT_STORAGE;// (item type)
int16_t BUTCHER_SPECIAL_type;// (item type)
int16_t BUTCHER_SPECIAL_subtype;// (item subtype)
t_itemType EXTRACT_STORAGE;
t_itemType BUTCHER_SPECIAL_type;
t_itemSubtype BUTCHER_SPECIAL_subtype;
//int16_t padding; // added by compiler
std::string MEAT_NAME_1st_parm; // (adj)
std::string MEAT_NAME_2nd_parm;
@ -292,12 +309,24 @@ namespace DFHack
int32_t SOAP_LEVEL;
std::string PREFIX;
// etc...
bool isGem()
{
return mat_flags.is_set(MATERIAL_IS_GEM);
};
bool isStone()
{
return mat_flags.is_set(MATERIAL_IS_STONE);
};
};
/// Research by Quietust
struct df_inorganic_base
/**
* The reversed inorganic material struct
* Research by Quietust
* \ingroup grp_materials
*/
struct df_inorganic_type
{
std::string Inorganic_ID;
std::string ID;
BitArray<inorganic_flags> inorg_flags;
std::vector <uint32_t> empty1;
std::vector <int16_t> METAL_ORE_matID; // Vector of indexes of metals produced when ore is smelted
@ -314,8 +343,16 @@ namespace DFHack
std::vector <int16_t> ENVIRONMENT_inclusion_type;
std::vector <int8_t> ENVIRONMENT_prob;
int32_t unknown_in_2;
df_material mat;
bool isOre()
{
if(!METAL_ORE_matID.empty())
return true;
if(!THREAD_METAL_matID.empty())
return true;
return false;
}
};
struct df_inorganic_material:public df_inorganic_base, public df_material {};
/**
* A copy of the game's material data.
* \ingroup grp_materials
@ -641,9 +678,6 @@ namespace DFHack
} tilecolor;
};
typedef int32_t t_materialIndex;
typedef int16_t t_materialType, t_itemType, t_itemSubtype;
/**
* this structure describes what are things made of in the DF world
* \ingroup grp_materials
@ -691,14 +725,10 @@ namespace DFHack
GRIME
};
std::vector<df_inorganic_material*>* df_inorganic;
std::vector<t_matglossInorganic> inorganic;
std::vector<df_inorganic_type*>* df_inorganic;
std::vector<df_plant_type*>* df_organic;
std::vector<t_matgloss> organic;
std::vector<df_plant_type*>* df_trees;
std::vector<t_matgloss> tree;
std::vector<df_plant_type*>* df_plants;
std::vector<t_matgloss> plant;
std::vector<t_matgloss> race;
std::vector<t_creaturetype> raceEx;
@ -706,10 +736,11 @@ namespace DFHack
std::vector<t_matglossOther> other;
std::vector<t_matgloss> alldesc;
bool ReadInorganicMaterials (void);
bool ReadOrganicMaterials (void);
bool ReadWoodMaterials (void);
bool ReadPlantMaterials (void);
bool CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic);
bool CopyOrganicMaterials (std::vector<t_matgloss> & organic);
bool CopyWoodMaterials (std::vector<t_matgloss> & tree);
bool CopyPlantMaterials (std::vector<t_matgloss> & plant);
bool ReadCreatureTypes (void);
bool ReadCreatureTypesEx (void);
bool ReadDescriptorColors(void);

@ -126,7 +126,7 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector<t_matgloss> & nam
return true;
}
bool Materials::ReadInorganicMaterials (void)
bool Materials::CopyInorganicMaterials (std::vector<t_matglossInorganic> & inorganic)
{
Process * p = d->owner;
if(!df_inorganic)
@ -136,41 +136,41 @@ bool Materials::ReadInorganicMaterials (void)
inorganic.reserve (size);
for (uint32_t i = 0; i < size;i++)
{
df_inorganic_material * orig = df_inorganic->at(i);
df_inorganic_type * orig = df_inorganic->at(i);
t_matglossInorganic mat;
mat.id = orig->Inorganic_ID;
mat.name = orig->STONE_NAME;
mat.id = orig->ID;
mat.name = orig->mat.STONE_NAME;
mat.ore_types = orig->METAL_ORE_matID;
mat.ore_chances = orig->METAL_ORE_prob;
mat.strand_types = orig->THREAD_METAL_matID;
mat.strand_chances = orig->THREAD_METAL_prob;
mat.value = orig->MATERIAL_VALUE;
mat.wall_tile = orig->TILE;
mat.boulder_tile = orig->ITEM_SYMBOL;
mat.bright = orig->BASIC_COLOR_bright;
mat.fore = orig->BASIC_COLOR_foreground;
mat.is_gem = orig->mat_flags.is_set(MATERIAL_IS_GEM);
mat.value = orig->mat.MATERIAL_VALUE;
mat.wall_tile = orig->mat.TILE;
mat.boulder_tile = orig->mat.ITEM_SYMBOL;
mat.bright = orig->mat.BASIC_COLOR_bright;
mat.fore = orig->mat.BASIC_COLOR_foreground;
mat.is_gem = orig->mat.mat_flags.is_set(MATERIAL_IS_GEM);
inorganic.push_back(mat);
}
return true;
}
bool Materials::ReadOrganicMaterials (void)
bool Materials::CopyOrganicMaterials (std::vector<t_matgloss> & organic)
{
if(df_organic)
return ReadNamesOnly(d->owner, (uint32_t) df_organic, organic );
else return false;
}
bool Materials::ReadWoodMaterials (void)
bool Materials::CopyWoodMaterials (std::vector<t_matgloss> & tree)
{
if(df_trees)
return ReadNamesOnly(d->owner, (uint32_t) df_trees, tree );
else return false;
}
bool Materials::ReadPlantMaterials (void)
bool Materials::CopyPlantMaterials (std::vector<t_matgloss> & plant)
{
if(df_plants)
return ReadNamesOnly(d->owner, (uint32_t) df_plants, plant );
@ -353,10 +353,6 @@ bool Materials::ReadCreatureTypesEx (void)
bool Materials::ReadAllMaterials(void)
{
bool ok = true;
ok &= this->ReadInorganicMaterials();
ok &= this->ReadOrganicMaterials();
ok &= this->ReadWoodMaterials();
ok &= this->ReadPlantMaterials();
ok &= this->ReadCreatureTypes();
ok &= this->ReadCreatureTypesEx();
ok &= this->ReadDescriptorColors();
@ -385,7 +381,7 @@ std::string Materials::getDescription(const t_material & mat)
if(mat.material<0)
return "any inorganic";
else
return this->inorganic[mat.material].id;
return this->df_inorganic->at(mat.material)->ID;
}
if(mat.material<0)
return "any";
@ -404,8 +400,8 @@ std::string Materials::getDescription(const t_material & mat)
else
if(mat.index<0)
return "any inorganic";
else if (mat.index < inorganic.size())
return this->inorganic[mat.index].id;
else if (mat.index < df_inorganic->size())
return this->df_inorganic->at(mat.index)->ID;
else
return "INDEX OUT OF BOUNDS!";
}
@ -424,7 +420,7 @@ std::string Materials::getDescription(const t_material & mat)
}
else
{
return this->organic[mat.index].id;
return this->df_organic->at(mat.material)->ID;
}
return out;
}

@ -148,8 +148,22 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
type == Items::FOOD
)
{
c->con.print("Confiscating a dropped foodstuff/pet vermin: \t");
confiscate = true;
if(dump_scattered)
{
c->con.print("Dumping a dropped item: \t");
dump = true;
}
else
{
c->con.print("Confiscating a dropped item: \t");
}
}
else if(dump_scattered)
{
c->con.print("Confiscating and dumping litter: \t");
confiscate = true;
dump = true;
}
}
else if (item->getWear() >= wear_dump_level)
@ -158,12 +172,6 @@ DFhackCExport command_result df_cleanowned (Core * c, vector <string> & paramete
confiscate = true;
dump = true;
}
else if (dump_scattered && item->flags.on_ground)
{
c->con.print("Confiscating and dumping litter: \t");
confiscate = true;
dump = true;
}
else if (confiscate_all)
{
c->con.print("Confiscating: \t");

@ -103,7 +103,8 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
DFHack::Materials *Materials = c->getMaterials();
DFHack::VersionInfo* mem = c->vinfo;
DFHack::Maps *Maps = c->getMaps();
bool hasmats = Materials->ReadInorganicMaterials();
std::vector<t_matglossInorganic> inorganic;
bool hasmats = Materials->CopyInorganicMaterials(inorganic);
if(!Maps->Start())
{
@ -199,9 +200,9 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
{
con << "Layer material: " << dec << base_rock;
if(hasmats)
con << " / " << Materials->inorganic[base_rock].id
con << " / " << inorganic[base_rock].id
<< " / "
<< Materials->inorganic[base_rock].name
<< inorganic[base_rock].name
<< endl;
else
con << endl;
@ -211,9 +212,9 @@ DFhackCExport command_result df_probe (Core * c, vector <string> & parameters)
{
con << "Vein material (final): " << dec << vein_rock;
if(hasmats)
con << " / " << Materials->inorganic[vein_rock].id
con << " / " << inorganic[vein_rock].id
<< " / "
<< Materials->inorganic[vein_rock].name
<< inorganic[vein_rock].name
<< endl;
else
con << endl;

@ -88,8 +88,8 @@ struct compare_pair_second
// printMats() accepts a vector of pointers to t_matgloss so that it can
// deal t_matgloss and all subclasses.
void printMats(DFHack::Console & con, MatMap &mat,
std::vector<DFHack::t_matgloss*> &materials)
template <typename T>
void printMats(DFHack::Console & con, MatMap &mat, std::vector<T*> &materials)
{
unsigned int total = 0;
MatSorter sorting_vector;
@ -108,8 +108,8 @@ void printMats(DFHack::Console & con, MatMap &mat,
<< materials.size() << endl;
continue;
}
DFHack::t_matgloss* mat = materials[it->first];
con << std::setw(25) << mat->id << " : "
T* mat = materials[it->first];
con << std::setw(25) << mat->ID << " : "
<< std::setw(9) << it->second.count;
if(it->second.lower_z != it->second.upper_z)
con <<" Z:" << std::setw(4) << it->second.lower_z << ".." << it->second.upper_z << std::endl;
@ -121,14 +121,6 @@ void printMats(DFHack::Console & con, MatMap &mat,
con << ">>> TOTAL = " << total << std::endl << std::endl;
}
void printMats(DFHack::Console & con, MatMap &mat,
std::vector<DFHack::t_matgloss> &materials)
{
std::vector<DFHack::t_matgloss*> ptr_vec;
TO_PTR_VEC(materials, ptr_vec);
printMats(con, mat, ptr_vec);
}
void printVeins(DFHack::Console & con, MatMap &mat_map,
DFHack::Materials* mats)
{
@ -138,27 +130,24 @@ void printVeins(DFHack::Console & con, MatMap &mat_map,
for (MatMap::const_iterator it = mat_map.begin(); it != mat_map.end(); ++it)
{
DFHack::t_matglossInorganic &gloss = mats->inorganic[it->first];
DFHack::df_inorganic_type *gloss = mats->df_inorganic->at(it->first);
if (gloss.isGem())
if (gloss->mat.isGem())
gems[it->first] = it->second;
else if (gloss.isOre())
else if (gloss->isOre())
ores[it->first] = it->second;
else
rest[it->first] = it->second;
}
std::vector<DFHack::t_matgloss*> ptr_vec;
TO_PTR_VEC(mats->inorganic, ptr_vec);
con << "Ores:" << std::endl;
printMats(con, ores, ptr_vec);
printMats(con, ores, *mats->df_inorganic);
con << "Gems:" << std::endl;
printMats(con, gems, ptr_vec);
printMats(con, gems, *mats->df_inorganic);
con << "Other vein stone:" << std::endl;
printMats(con, rest, ptr_vec);
printMats(con, rest, *mats->df_inorganic);
}
DFhackCExport command_result prospector (Core * c, vector <string> & parameters);
@ -217,13 +206,13 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
MapExtras::MapCache map(maps);
DFHack::Materials *mats = c->getMaterials();
if (!mats->ReadInorganicMaterials())
if (!mats->df_inorganic)
{
con << "Unable to read inorganic material definitons!" << std::endl;
c->Resume();
return CR_FAILURE;
}
if (showPlants && !mats->ReadOrganicMaterials())
if (showPlants && !mats->df_organic)
{
con << "Unable to read organic material definitons; plants won't be listed!" << std::endl;
showPlants = false;
@ -423,20 +412,17 @@ DFhackCExport command_result prospector (DFHack::Core * c, vector <string> & par
con << std::setw(25) << DFHack::TileMaterialString[it->first] << " : " << it->second.count << std::endl;
}
std::vector<t_matgloss*> ptr_vec;
TO_PTR_VEC(mats->inorganic, ptr_vec);
con << std::endl << "Layer materials:" << std::endl;
printMats(con, layerMats, ptr_vec);
printMats(con, layerMats, *mats->df_inorganic);
printVeins(con, veinMats, mats);
if (showPlants)
{
con << "Shrubs:" << std::endl;
printMats(con, plantMats, mats->organic);
printMats(con, plantMats, *mats->df_organic);
con << "Wood in trees:" << std::endl;
printMats(con, treeMats, mats->organic);
printMats(con, treeMats, *mats->df_organic);
}
if (hasAquifer)

@ -103,8 +103,8 @@ DFhackCExport DFHack::command_result df_seedwatch(DFHack::Core* pCore, std::vect
core.Suspend();
DFHack::Materials& materialsModule = *core.getMaterials();
materialsModule.ReadOrganicMaterials();
std::vector<DFHack::t_matgloss>& organics = materialsModule.organic;
std::vector<DFHack::t_matgloss> organics;
materialsModule.CopyOrganicMaterials(organics);
std::map<std::string, t_materialIndex> materialsReverser;
for(std::size_t i = 0; i < organics.size(); ++i)