2010-04-29 09:00:34 -06:00
|
|
|
/*
|
2011-04-11 14:13:06 -06:00
|
|
|
* Simple, pretty item dump example.
|
2010-04-29 09:00:34 -06:00
|
|
|
*/
|
2010-11-03 03:45:29 -06:00
|
|
|
|
2011-04-11 14:13:06 -06:00
|
|
|
#include <cstdio>
|
2009-11-17 08:38:33 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
2011-04-11 14:13:06 -06:00
|
|
|
#include <cstring>
|
2009-11-17 08:38:33 -07:00
|
|
|
using namespace std;
|
2011-04-13 17:42:03 -06:00
|
|
|
#define DFHACK_WANT_MISCUTILS
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2010-06-04 16:02:02 -06:00
|
|
|
#include <dfhack/DFVector.h>
|
2009-11-17 08:38:33 -07:00
|
|
|
|
2011-05-12 10:30:42 -06:00
|
|
|
int main (int argc, char *argv[])
|
2009-11-17 08:38:33 -07:00
|
|
|
{
|
2011-05-12 10:30:42 -06:00
|
|
|
bool print_refs = false;
|
|
|
|
bool print_hex = false;
|
|
|
|
bool print_acc = false;
|
|
|
|
|
|
|
|
for(int i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
char *arg = argv[i];
|
|
|
|
if (arg[0] != '-')
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (; *arg; arg++) {
|
|
|
|
switch (arg[0]) {
|
|
|
|
case 'r': print_refs = true; break;
|
|
|
|
case 'x': print_hex = true; break;
|
|
|
|
case 'a': print_acc = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-01 18:38:18 -06:00
|
|
|
DFHack::Process * p;
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DFMgr("Memory.xml");
|
|
|
|
DFHack::Context * DF;
|
2010-05-01 18:38:18 -06:00
|
|
|
try
|
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF = DFMgr.getSingleContext();
|
|
|
|
DF->Attach();
|
2010-05-01 18:38:18 -06:00
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
2010-04-29 09:00:34 -06:00
|
|
|
#ifndef LINUX_BUILD
|
2010-05-01 18:38:18 -06:00
|
|
|
cin.ignore();
|
2010-04-29 09:00:34 -06:00
|
|
|
#endif
|
2010-05-01 18:38:18 -06:00
|
|
|
return 1;
|
|
|
|
}
|
2011-04-11 14:13:06 -06:00
|
|
|
DFHack::Materials * Materials = DF->getMaterials();
|
|
|
|
Materials->ReadAllMaterials();
|
2011-04-13 17:42:03 -06:00
|
|
|
|
|
|
|
DFHack::Gui * Gui = DF->getGui();
|
2011-04-11 14:13:06 -06:00
|
|
|
|
|
|
|
DFHack::Items * Items = DF->getItems();
|
|
|
|
Items->Start();
|
2010-05-01 18:38:18 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
DFHack::VersionInfo * mem = DF->getMemoryInfo();
|
2010-05-23 15:06:10 -06:00
|
|
|
p = DF->getProcess();
|
2011-04-13 17:42:03 -06:00
|
|
|
int32_t x,y,z;
|
|
|
|
Gui->getCursorCoords(x,y,z);
|
2011-05-12 10:30:42 -06:00
|
|
|
|
|
|
|
std::vector<uint32_t> p_items;
|
|
|
|
Items->readItemVector(p_items);
|
|
|
|
uint32_t size = p_items.size();
|
|
|
|
|
2011-04-11 14:13:06 -06:00
|
|
|
// FIXME: tools should never be exposed to DFHack internals!
|
2010-10-19 04:07:07 -06:00
|
|
|
DFHack::OffsetGroup* itemGroup = mem->getGroup("Items");
|
2011-05-12 10:30:42 -06:00
|
|
|
uint32_t ref_vector = itemGroup->getOffset("item_ref_vector");
|
2010-05-01 18:38:18 -06:00
|
|
|
|
2011-05-23 13:30:51 -06:00
|
|
|
for(size_t i = 0; i < size; i++)
|
2011-04-11 14:13:06 -06:00
|
|
|
{
|
|
|
|
DFHack::dfh_item itm;
|
|
|
|
memset(&itm, 0, sizeof(DFHack::dfh_item));
|
|
|
|
Items->readItem(p_items[i],itm);
|
2011-05-12 10:30:42 -06:00
|
|
|
|
|
|
|
if (x != -30000
|
|
|
|
&& !(itm.base.x == x && itm.base.y == y && itm.base.z == z
|
|
|
|
&& itm.base.flags.on_ground
|
|
|
|
&& !itm.base.flags.in_chest
|
|
|
|
&& !itm.base.flags.in_inventory
|
|
|
|
&& !itm.base.flags.in_building))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
printf(
|
|
|
|
"%5d: %08x %6d %08x (%d,%d,%d) #%08x [%d] *%d %s - %s\n",
|
|
|
|
i, itm.origin, itm.id, itm.base.flags.whole,
|
|
|
|
itm.base.x, itm.base.y, itm.base.z,
|
|
|
|
itm.base.vtable,
|
|
|
|
itm.wear_level,
|
|
|
|
itm.quantity,
|
2011-10-24 20:48:06 -06:00
|
|
|
Items->getItemClass(itm).c_str(),
|
2011-05-12 10:30:42 -06:00
|
|
|
Items->getItemDescription(itm, Materials).c_str()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (print_hex)
|
|
|
|
hexdump(DF,p_items[i],0x300);
|
|
|
|
|
|
|
|
if (print_acc)
|
|
|
|
cout << Items->dumpAccessors(itm) << endl;
|
|
|
|
|
|
|
|
if (print_refs) {
|
|
|
|
DFHack::DfVector<uint32_t> p_refs(p, itm.origin + ref_vector);
|
2011-05-23 13:30:51 -06:00
|
|
|
for (size_t j = 0; j < p_refs.size(); j++) {
|
2011-05-12 10:30:42 -06:00
|
|
|
uint32_t vptr = p->readDWord(p_refs[j]);
|
|
|
|
uint32_t val = p->readDWord(p_refs[j]+4);
|
|
|
|
printf("\t-> %d \t%s\n", int(val), p->readClassName(vptr).c_str());
|
2011-04-13 17:42:03 -06:00
|
|
|
}
|
|
|
|
}
|
2011-04-11 14:13:06 -06:00
|
|
|
}
|
2010-04-29 09:00:34 -06:00
|
|
|
#ifndef LINUX_BUILD
|
2010-05-01 18:38:18 -06:00
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
2010-04-29 09:00:34 -06:00
|
|
|
#endif
|
2010-05-01 18:38:18 -06:00
|
|
|
return 0;
|
2009-11-17 08:38:33 -07:00
|
|
|
}
|