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>
|
2010-02-25 05:41:57 -07:00
|
|
|
#include <DFMemInfo.h>
|
2009-11-17 08:38:33 -07:00
|
|
|
|
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-02-25 05:41:57 -07:00
|
|
|
string getMaterialType(DFHack::t_item item, const string & itemtype,const matGlosses & mat)
|
|
|
|
{
|
|
|
|
// plant thread seeds
|
|
|
|
if(itemtype == "item_plant" || itemtype == "item_thread" || itemtype == "item_seeds" || itemtype == "item_leaves" )
|
2009-11-17 20:35:43 -07:00
|
|
|
{
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.type >= 0 && item.material.type < mat.plantMat.size())
|
|
|
|
{
|
|
|
|
return mat.plantMat[item.material.type].id;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "some invalid plant material";
|
|
|
|
}
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
else if (itemtype == "item_drink") // drinks must have different offset for materials
|
2009-11-17 20:35:43 -07:00
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
return "Booze or something";
|
2010-01-18 09:44:24 -07:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
// item_skin_raw item_bones item_skull item_fish_raw item_pet item_skin_tanned item_shell
|
|
|
|
else if(itemtype == "item_skin_raw" ||
|
|
|
|
itemtype == "item_skin_tanned" ||
|
|
|
|
itemtype == "item_fish_raw" ||
|
|
|
|
itemtype == "item_pet" ||
|
|
|
|
itemtype == "item_shell" ||
|
|
|
|
itemtype == "item_horn"||
|
|
|
|
itemtype == "item_skull" ||
|
|
|
|
itemtype == "item_bones" ||
|
|
|
|
itemtype == "item_corpse" ||
|
|
|
|
itemtype == "item_meat"
|
|
|
|
)
|
|
|
|
{
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.type >= 0 && item.material.type < mat.creatureMat.size())
|
|
|
|
return mat.creatureMat[item.material.type].id;
|
|
|
|
return "bad material";
|
2010-01-18 09:44:24 -07:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
else if(itemtype == "item_wood")
|
|
|
|
{
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.type >= 0 && item.material.type < mat.woodMat.size())
|
|
|
|
return mat.woodMat[item.material.type].id;
|
|
|
|
return "bad material";
|
2010-01-18 09:44:24 -07:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
else if(itemtype == "item_bar")
|
|
|
|
{
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.type >= 0 && item.material.type < mat.metalMat.size())
|
|
|
|
return mat.metalMat[item.material.type].id;
|
|
|
|
return "bad material";
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Mat_Wood,
|
|
|
|
Mat_Stone,
|
|
|
|
Mat_Metal,
|
|
|
|
Mat_Plant,
|
|
|
|
Mat_Leather = 10,
|
|
|
|
Mat_SilkCloth = 11,
|
|
|
|
Mat_PlantCloth = 12,
|
|
|
|
Mat_GreenGlass = 13,
|
|
|
|
Mat_ClearGlass = 14,
|
|
|
|
Mat_CrystalGlass = 15,
|
|
|
|
Mat_Ice = 17,
|
|
|
|
Mat_Charcoal =18,
|
|
|
|
Mat_Potash = 19,
|
|
|
|
Mat_Ashes = 20,
|
|
|
|
Mat_PearlAsh = 21,
|
|
|
|
Mat_Soap = 24,
|
|
|
|
*/
|
2009-11-17 20:35:43 -07:00
|
|
|
switch (item.material.type)
|
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Wood:
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.woodMat.size())
|
|
|
|
return mat.woodMat[item.material.index].id;
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Stone:
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.stoneMat.size())
|
|
|
|
return mat.stoneMat[item.material.index].id;
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Metal:
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.metalMat.size())
|
|
|
|
return mat.metalMat[item.material.index].id;
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
//case DFHack::Mat_Plant:
|
|
|
|
case DFHack::Mat_PlantCloth:
|
|
|
|
//return mat.plantMat[item.material.index].id;
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.plantMat.size())
|
|
|
|
return string(mat.plantMat[item.material.index].id) + " plant";
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case 3: // bone
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id) + " bone";
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case 25: // fat
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id) + " fat";
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case 23: // tallow
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id) + " tallow";
|
|
|
|
return "bad material";
|
2010-02-25 05:41:57 -07:00
|
|
|
case 9: // shell
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id) + " shell";
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Leather: // really a generic creature material. meat for item_food, leather for item_box...
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id);
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_SilkCloth:
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id) + " silk";
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Soap:
|
2010-03-13 16:36:09 -07:00
|
|
|
if(item.material.index >= 0 && item.material.index < mat.creatureMat.size())
|
|
|
|
return string(mat.creatureMat[item.material.index].id) + " soap";
|
|
|
|
return "bad material";
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_GreenGlass:
|
|
|
|
return "Green Glass";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_ClearGlass:
|
|
|
|
return "Clear Glass";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_CrystalGlass:
|
|
|
|
return "Crystal Glass";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Ice:
|
|
|
|
return "Ice";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Charcoal:
|
|
|
|
return "Charcoal";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
/*case DFHack::Mat_Potash:
|
|
|
|
return "Potash";*/
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_Ashes:
|
|
|
|
return "Ashes";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
case DFHack::Mat_PearlAsh:
|
|
|
|
return "Pearlash";
|
2010-03-13 16:36:09 -07:00
|
|
|
|
2009-11-17 20:35:43 -07:00
|
|
|
default:
|
2010-02-25 05:41:57 -07:00
|
|
|
cout << "unknown material hit: " << item.material.type << " " << item.material.index << " " << itemtype << endl;
|
|
|
|
return "Invalid";
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
return "Invalid";
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
void printItem(DFHack::t_item item, const string & typeString,const matGlosses & mat)
|
|
|
|
{
|
2010-01-18 09:44:24 -07:00
|
|
|
cout << dec << "Item at x:" << item.x << " y:" << item.y << " z:" << item.z << endl;
|
2010-02-25 05:41:57 -07:00
|
|
|
cout << "Type: " << (int) item.type << " " << typeString << " Address: " << hex << item.origin << endl;
|
2010-01-18 09:44:24 -07:00
|
|
|
cout << "Material: ";
|
2010-02-25 05:41:57 -07:00
|
|
|
|
|
|
|
string itemType = getMaterialType(item,typeString,mat);
|
2010-01-18 09:44:24 -07:00
|
|
|
cout << itemType << endl;
|
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
|
|
|
|
|
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-25 05:41:57 -07:00
|
|
|
DFHack::memory_info * mem = DF.getMemoryInfo();
|
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-02-25 05:41:57 -07:00
|
|
|
// vector <string> objecttypes;
|
|
|
|
// DF.getClassIDMapping(objecttypes);
|
2010-02-06 19:55:54 -07:00
|
|
|
|
2010-02-11 14:08:39 -07:00
|
|
|
uint32_t numItems;
|
|
|
|
DF.InitReadItems(numItems);
|
2009-11-17 08:38:33 -07:00
|
|
|
DF.InitViewAndCursor();
|
2010-02-11 14:08:39 -07:00
|
|
|
|
2009-11-17 08:38:33 -07:00
|
|
|
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();
|
2010-02-11 14:08:39 -07:00
|
|
|
//FIXME: why twice?
|
|
|
|
uint32_t numItems;
|
|
|
|
DF.InitReadItems(numItems);
|
2009-11-17 08:38:33 -07:00
|
|
|
if(input == "q")
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2010-02-11 14:08:39 -07:00
|
|
|
|
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;
|
|
|
|
}
|
2010-02-11 14:08:39 -07:00
|
|
|
else if(foundItems.size() == 1)
|
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
string itemtype;
|
|
|
|
mem->resolveClassIDToClassname(foundItems[0].type,itemtype);
|
|
|
|
printItem(foundItems[0], itemtype ,mat);
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
2010-02-11 14:08:39 -07:00
|
|
|
else
|
|
|
|
{
|
2009-11-17 20:35:43 -07:00
|
|
|
cerr << "Please Select which item you want to display\n";
|
2010-02-25 05:41:57 -07:00
|
|
|
string itemtype;
|
2009-12-13 14:03:19 -07:00
|
|
|
for(uint32_t j = 0; j < foundItems.size(); ++j)
|
|
|
|
{
|
2010-02-25 05:41:57 -07:00
|
|
|
mem->resolveClassIDToClassname(foundItems[j].type,itemtype);
|
|
|
|
cerr << j << " " << itemtype << endl;
|
2009-11-17 20:35:43 -07:00
|
|
|
}
|
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;
|
2010-02-11 14:08:39 -07:00
|
|
|
while(value >= foundItems.size())
|
|
|
|
{
|
2009-11-17 20:35:43 -07:00
|
|
|
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
|
|
|
}
|
2010-02-25 05:41:57 -07:00
|
|
|
mem->resolveClassIDToClassname(foundItems[value].type,itemtype);
|
|
|
|
printItem(foundItems[value], itemtype ,mat);
|
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;
|
|
|
|
}
|