2009-11-17 08:38:33 -07:00
|
|
|
// Item dump
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <climits>
|
|
|
|
#include <integers.h>
|
|
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <DFTypes.h>
|
|
|
|
#include <DFHackAPI.h>
|
|
|
|
|
2009-11-17 20:35:43 -07:00
|
|
|
struct matGlosses
|
|
|
|
{
|
2009-12-12 17:47:58 -07:00
|
|
|
vector<DFHack::t_matgloss> plantMat;
|
|
|
|
vector<DFHack::t_matgloss> woodMat;
|
|
|
|
vector<DFHack::t_matgloss> stoneMat;
|
|
|
|
vector<DFHack::t_matgloss> metalMat;
|
|
|
|
vector<DFHack::t_matgloss> creatureMat;
|
2009-11-17 20:35:43 -07:00
|
|
|
};
|
|
|
|
|
2010-01-18 09:44:24 -07:00
|
|
|
string getMaterialType(DFHack::t_item item, const vector<string> & buildingTypes,const matGlosses & mat){
|
|
|
|
if(item.type == 85 || item.type == 113 || item.type == 117) // item_plant or item_thread or item_seeds
|
2009-11-17 20:35:43 -07:00
|
|
|
{
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.plantMat[item.material.type].id));
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
2010-01-18 09:44:24 -07:00
|
|
|
else if(item.type == 109 || item.type == 114 || item.type == 115 || item.type == 116 || item.type==128 || item.type == 129|| item.type == 130|| item.type == 131) // item_skin_raw item_bones item_skill item_fish_raw item_pet item_skin_tanned item_shell
|
2009-11-17 20:35:43 -07:00
|
|
|
{
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.creatureMat[item.material.type].id));
|
|
|
|
}
|
|
|
|
else if(item.type == 124){ //wood
|
|
|
|
return(string(mat.woodMat[item.material.type].id));
|
|
|
|
}
|
|
|
|
else if(item.type == 118){ //blocks
|
|
|
|
return(string(mat.metalMat[item.material.index].id));
|
|
|
|
}
|
|
|
|
else if(item.type == 86){ // item_glob I don't know what those are in game, just ignore them
|
|
|
|
return(string(""));
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
switch (item.material.type)
|
|
|
|
{
|
|
|
|
case 0:
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.woodMat[item.material.index].id));
|
2009-11-17 20:35:43 -07:00
|
|
|
break;
|
|
|
|
case 1:
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.stoneMat[item.material.index].id));
|
2009-11-17 20:35:43 -07:00
|
|
|
break;
|
|
|
|
case 2:
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.metalMat[item.material.index].id));
|
2009-11-17 20:35:43 -07:00
|
|
|
break;
|
|
|
|
case 12: // don't ask me why this has such a large jump, maybe this is not actually the matType for plants, but they all have this set to 12
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.plantMat[item.material.index].id));
|
2009-11-17 20:35:43 -07:00
|
|
|
break;
|
2010-01-18 09:44:24 -07:00
|
|
|
case 3:
|
|
|
|
case 9:
|
|
|
|
case 10:
|
|
|
|
case 11:
|
2009-11-17 20:35:43 -07:00
|
|
|
case 121:
|
2010-01-18 09:44:24 -07:00
|
|
|
return(string(mat.creatureMat[item.material.index].id));
|
2009-11-17 20:35:43 -07:00
|
|
|
break;
|
|
|
|
default:
|
2010-01-18 09:44:24 -07:00
|
|
|
//DF.setCursorCoords(item.x,item.y,item.z);
|
|
|
|
return(string(""));
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-01-18 09:44:24 -07:00
|
|
|
void printItem(DFHack::t_item item, const vector<string> & buildingTypes,const matGlosses & mat){
|
|
|
|
cout << dec << "Item at x:" << item.x << " y:" << item.y << " z:" << item.z << endl;
|
|
|
|
cout << "Type: " << (int) item.type << " " << buildingTypes[item.type] << " Address: " << hex << item.origin << endl;
|
|
|
|
cout << "Material: ";
|
2009-11-17 20:35:43 -07:00
|
|
|
|
2010-01-18 09:44:24 -07:00
|
|
|
string itemType = getMaterialType(item,buildingTypes,mat);
|
|
|
|
cout << itemType << endl;
|
|
|
|
}
|
2009-11-17 08:38:33 -07:00
|
|
|
int main ()
|
|
|
|
{
|
2010-01-18 09:44:24 -07:00
|
|
|
|
2009-11-17 08:38:33 -07:00
|
|
|
DFHack::API DF ("Memory.xml");
|
2010-01-18 09:44:24 -07:00
|
|
|
|
2009-11-17 08:38:33 -07:00
|
|
|
if(!DF.Attach())
|
|
|
|
{
|
|
|
|
cerr << "DF not found" << endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2010-02-06 19:55:54 -07:00
|
|
|
DF.Suspend();
|
2010-01-18 09:44:24 -07:00
|
|
|
DF.InitViewAndCursor();
|
2009-11-17 20:35:43 -07:00
|
|
|
matGlosses mat;
|
|
|
|
DF.ReadPlantMatgloss(mat.plantMat);
|
|
|
|
DF.ReadWoodMatgloss(mat.woodMat);
|
|
|
|
DF.ReadStoneMatgloss(mat.stoneMat);
|
|
|
|
DF.ReadMetalMatgloss(mat.metalMat);
|
|
|
|
DF.ReadCreatureMatgloss(mat.creatureMat);
|
2010-01-18 09:44:24 -07:00
|
|
|
DF.ForceResume();
|
2009-11-17 20:35:43 -07:00
|
|
|
|
2009-11-17 08:38:33 -07:00
|
|
|
vector <string> buildingtypes;
|
2009-12-31 18:49:32 -07:00
|
|
|
DF.InitReadBuildings(buildingtypes);
|
2010-01-18 09:44:24 -07:00
|
|
|
uint32_t numItems = DF.InitReadItems();
|
2010-02-06 19:55:54 -07:00
|
|
|
/*
|
2010-01-18 09:44:24 -07:00
|
|
|
map< string, map<string,vector<uint32_t> > > count;
|
|
|
|
for(uint32_t i=0; i< numItems; i++){
|
|
|
|
DFHack::t_item temp;
|
|
|
|
DF.ReadItem(i,temp);
|
|
|
|
// cout << int(temp.type) << endl;
|
|
|
|
count[buildingtypes[temp.type]][getMaterialType(temp,buildingtypes,mat)].push_back(i);
|
|
|
|
}
|
2010-02-06 19:55:54 -07:00
|
|
|
*/
|
|
|
|
|
2009-11-17 08:38:33 -07:00
|
|
|
DF.InitViewAndCursor();
|
|
|
|
cout << "q to quit, anything else to look up items at that location\n";
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
string input;
|
2009-12-31 18:49:32 -07:00
|
|
|
DF.ForceResume();
|
2009-11-17 08:38:33 -07:00
|
|
|
getline (cin, input);
|
|
|
|
DF.Suspend();
|
|
|
|
uint32_t numItems = DF.InitReadItems();
|
|
|
|
if(input == "q")
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2009-11-17 20:35:43 -07:00
|
|
|
// else if(next == 'c'){
|
|
|
|
// cerr << "clearing similarity" << endl;
|
|
|
|
// similarity.clear();
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else if(next == 'p'){
|
|
|
|
// vector<bool> same(similarity[0].size(),true);
|
|
|
|
// for(int k =0; k < similarity.size(); k++){
|
|
|
|
// for(int j =0; j < similarity.size(); j++){
|
|
|
|
// if(k != j){
|
|
|
|
// for(int l =0; l < similarity[k].size(); l++){
|
|
|
|
// if(similarity[k][l] != similarity[j][l]){
|
|
|
|
// same[l] = false;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// for(int itr =0; itr < same.size(); itr++){
|
|
|
|
// if(same[itr] == true && similarity[0][itr] != 0){
|
|
|
|
// cout << hex << itr << " " << hex << (int)similarity[0][itr] << endl;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// continue;
|
|
|
|
// }
|
2009-11-17 08:38:33 -07:00
|
|
|
int32_t x,y,z;
|
|
|
|
DF.getCursorCoords(x,y,z);
|
2009-12-12 17:47:58 -07:00
|
|
|
vector <DFHack::t_item> foundItems;
|
2009-11-17 08:38:33 -07:00
|
|
|
for(uint32_t i = 0; i < numItems; i++)
|
|
|
|
{
|
2009-12-12 17:47:58 -07:00
|
|
|
DFHack::t_item temp;
|
2009-11-17 08:38:33 -07:00
|
|
|
DF.ReadItem(i, temp);
|
|
|
|
if(temp.x == x && temp.y == y && temp.z == z)
|
|
|
|
{
|
2009-11-17 20:35:43 -07:00
|
|
|
foundItems.push_back(temp);
|
|
|
|
//cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(foundItems.size() == 0){
|
|
|
|
cerr << "No Items at x:" << x << " y:" << y << " z:" << z << endl;
|
|
|
|
}
|
|
|
|
else if(foundItems.size() == 1){
|
|
|
|
printItem(foundItems[0], buildingtypes,mat);
|
|
|
|
// similarity.push_back(foundItems[0].bytes);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
cerr << "Please Select which item you want to display\n";
|
2009-12-13 14:03:19 -07:00
|
|
|
for(uint32_t j = 0; j < foundItems.size(); ++j)
|
|
|
|
{
|
2009-11-17 20:35:43 -07:00
|
|
|
cerr << j << " " << buildingtypes[foundItems[j].type] << endl;
|
|
|
|
}
|
2009-12-13 14:03:19 -07:00
|
|
|
uint32_t value;
|
2009-11-17 20:35:43 -07:00
|
|
|
string input2;
|
|
|
|
stringstream ss;
|
|
|
|
getline(cin, input2);
|
|
|
|
ss.str(input2);
|
|
|
|
ss >> value;
|
|
|
|
while(value >= foundItems.size()){
|
|
|
|
cerr << "invalid choice, please try again" << endl;
|
|
|
|
input2.clear();
|
|
|
|
ss.clear();
|
|
|
|
getline (cin, input2);
|
|
|
|
ss.str(input2);
|
|
|
|
ss >> value;
|
2009-11-17 08:38:33 -07:00
|
|
|
}
|
2009-11-17 20:35:43 -07:00
|
|
|
printItem(foundItems[value], buildingtypes,mat);
|
|
|
|
// similarity.push_back(foundItems[value].bytes);
|
2009-11-17 08:38:33 -07:00
|
|
|
}
|
|
|
|
DF.FinishReadItems();
|
2010-01-18 09:44:24 -07:00
|
|
|
}
|
2009-11-17 08:38:33 -07:00
|
|
|
DF.FinishReadBuildings();
|
|
|
|
DF.Detach();
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|