2011-12-31 04:48:42 -07:00
|
|
|
#include "Core.h"
|
|
|
|
#include <Export.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <modules/Items.h>
|
|
|
|
#include <modules/Gui.h>
|
2011-07-20 02:41:13 -06:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <string.h>
|
2011-07-24 22:35:50 -06:00
|
|
|
#include <stdio.h> // sprintf()
|
2011-07-20 02:41:13 -06:00
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
using std::string;
|
|
|
|
using namespace DFHack;
|
|
|
|
|
2011-07-24 22:35:50 -06:00
|
|
|
//////////////////////
|
|
|
|
// START item choosers
|
|
|
|
//////////////////////
|
2012-01-26 21:54:26 -07:00
|
|
|
/*
|
2011-07-24 22:35:50 -06:00
|
|
|
class item_chooser
|
|
|
|
{
|
|
|
|
public:
|
2012-01-26 21:54:26 -07:00
|
|
|
item_chooser(Core* _c) : c(_c)
|
2011-07-24 22:35:50 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool doPrint(DFHack::dfh_item *itm) = 0;
|
|
|
|
|
|
|
|
virtual void postPrint(DFHack::dfh_item *itm)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Core *c;
|
|
|
|
};
|
|
|
|
|
|
|
|
class choose_all : public item_chooser
|
|
|
|
{
|
|
|
|
public:
|
2012-01-26 21:54:26 -07:00
|
|
|
choose_all(Core* _c) : item_chooser(_c)
|
2011-07-24 22:35:50 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool doPrint(DFHack::dfh_item *itm)
|
|
|
|
{
|
|
|
|
return (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class choose_unknown : public item_chooser
|
|
|
|
{
|
|
|
|
public:
|
2012-01-26 21:54:26 -07:00
|
|
|
choose_unknown(Core* _c) : item_chooser(_c)
|
2011-07-24 22:35:50 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool doPrint(DFHack::dfh_item *itm)
|
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
if (itm->origin->unk1.size() > 0)
|
2011-07-24 22:35:50 -06:00
|
|
|
return true;
|
|
|
|
|
2011-10-26 14:18:13 -06:00
|
|
|
std::vector<std::pair<std::string, int32_t> > refs;
|
|
|
|
if (Items->unknownRefs(itm->origin, refs))
|
2011-07-24 22:35:50 -06:00
|
|
|
return true;
|
|
|
|
|
2011-10-26 14:18:13 -06:00
|
|
|
t_itemflags &f = itm->origin->flags;
|
2011-07-24 22:35:50 -06:00
|
|
|
|
2012-01-26 21:54:26 -07:00
|
|
|
return (f.unk1 || f.unk2 || f.unk3 || f.unk4 ||
|
2011-07-24 22:35:50 -06:00
|
|
|
f.unk6 || f.unk7 ||
|
|
|
|
f.unk10 || f.unk11);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void postPrint(DFHack::dfh_item *itm)
|
|
|
|
{
|
|
|
|
std::vector<std::string> flags;
|
|
|
|
|
2011-10-26 14:18:13 -06:00
|
|
|
t_itemflags &f = itm->origin->flags;
|
2011-07-24 22:35:50 -06:00
|
|
|
|
2011-10-26 14:18:13 -06:00
|
|
|
if (itm->origin->unk1.size() > 0)
|
|
|
|
c->con.print(" vec1: %p\n", itm->origin->unk1[0]);
|
2011-07-24 22:35:50 -06:00
|
|
|
|
2011-10-26 14:18:13 -06:00
|
|
|
std::vector<std::pair<std::string, int32_t> > refs;
|
|
|
|
if (Items->unknownRefs(itm->origin, refs))
|
2011-07-24 22:35:50 -06:00
|
|
|
{
|
|
|
|
c->con.print(" refs: ");
|
|
|
|
for (size_t i = 0; i < refs.size(); i++)
|
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
c->con.print("%s: %d", refs[i].first.c_str(), refs[i].second);
|
2011-07-24 22:35:50 -06:00
|
|
|
if ( (i + 1) < refs.size() )
|
|
|
|
c->con.print(", ");
|
|
|
|
}
|
|
|
|
c->con.print("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f.unk1) flags.push_back("unk1");
|
|
|
|
if (f.unk2) flags.push_back("unk2");
|
|
|
|
if (f.unk3) flags.push_back("unk3");
|
|
|
|
if (f.unk4) flags.push_back("unk4");
|
2011-09-21 05:47:12 -06:00
|
|
|
//if (f.unk5) flags.push_back("unk5");
|
2011-07-24 22:35:50 -06:00
|
|
|
if (f.unk6) flags.push_back("unk6");
|
|
|
|
if (f.unk7) flags.push_back("unk7");
|
|
|
|
if (f.unk8) flags.push_back("unk8");
|
|
|
|
if (f.unk9) flags.push_back("unk9");
|
|
|
|
if (f.unk10) flags.push_back("unk10");
|
|
|
|
if (f.unk11) flags.push_back("unk11");
|
|
|
|
|
|
|
|
if (flags.size() > 0)
|
|
|
|
{
|
|
|
|
c->con.print(" flags: ");
|
|
|
|
for (size_t i = 0; i < flags.size(); i++)
|
|
|
|
{
|
|
|
|
c->con.print("%s", flags[i].c_str());
|
|
|
|
if ( (i + 1) < flags.size() )
|
|
|
|
c->con.print(", ");
|
|
|
|
}
|
|
|
|
c->con.print("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class choose_cursor : public item_chooser
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
choose_cursor(Core* _c, ::Items* _Items, int32_t _x, int32_t _y, int32_t _z)
|
|
|
|
: item_chooser(_c, _Items), x(_x), y(_y), z(_z)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool doPrint(DFHack::dfh_item *itm)
|
|
|
|
{
|
2011-10-26 14:18:13 -06:00
|
|
|
return (itm->origin->x == x && itm->origin->y == y && itm->origin->z == z
|
|
|
|
&& itm->origin->flags.on_ground
|
|
|
|
&& !itm->origin->flags.in_chest
|
|
|
|
&& !itm->origin->flags.in_inventory
|
|
|
|
&& !itm->origin->flags.in_building);
|
2011-07-24 22:35:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int32_t x, y, z;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////
|
|
|
|
// END item choosers
|
|
|
|
//////////////////////
|
|
|
|
|
2011-07-20 02:41:13 -06:00
|
|
|
DFhackCExport command_result df_dumpitems (Core * c, vector <string> & parameters);
|
|
|
|
|
|
|
|
DFhackCExport const char * plugin_name ( void )
|
|
|
|
{
|
|
|
|
return "itemhacks";
|
|
|
|
}
|
|
|
|
|
2011-07-24 22:35:50 -06:00
|
|
|
DFhackCExport command_result plugin_init ( Core * c,
|
|
|
|
std::vector <PluginCommand> &commands)
|
2011-07-20 02:41:13 -06:00
|
|
|
{
|
|
|
|
commands.clear();
|
2011-07-24 22:35:50 -06:00
|
|
|
commands.push_back(PluginCommand("dumpitems",
|
|
|
|
"Dump items\
|
|
|
|
\n Options:\
|
|
|
|
\n unkown: Dump items that have anything unknown set",
|
|
|
|
df_dumpitems));
|
2011-07-20 02:41:13 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown ( Core * c )
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result df_dumpitems (Core * c, vector <string> & parameters)
|
|
|
|
{
|
|
|
|
c->Suspend();
|
|
|
|
DFHack::Materials * Materials = c->getMaterials();
|
|
|
|
Materials->ReadAllMaterials();
|
|
|
|
|
|
|
|
DFHack::Gui * Gui = c->getGui();
|
|
|
|
|
|
|
|
DFHack::Items * Items = c->getItems();
|
|
|
|
Items->Start();
|
|
|
|
|
|
|
|
int32_t x,y,z;
|
|
|
|
Gui->getCursorCoords(x,y,z);
|
|
|
|
|
2011-10-24 20:48:06 -06:00
|
|
|
std::vector<df_item *> p_items;
|
2011-07-20 02:41:13 -06:00
|
|
|
Items->readItemVector(p_items);
|
|
|
|
uint32_t size = p_items.size();
|
|
|
|
|
2011-07-24 22:35:50 -06:00
|
|
|
item_chooser *chooser = NULL;
|
|
|
|
|
|
|
|
if (x != -30000)
|
|
|
|
chooser = new choose_cursor(c, Items, x, y, z);
|
|
|
|
else if (parameters.size() == 0)
|
|
|
|
chooser = new choose_all(c, Items);
|
|
|
|
else if (parameters[0] == "unknown")
|
|
|
|
chooser = new choose_unknown(c, Items);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
c->con.printerr("Invalid option: %s\n", parameters[0].c_str());
|
|
|
|
Items->Finish();
|
|
|
|
c->Resume();
|
|
|
|
return CR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2011-07-20 02:41:13 -06:00
|
|
|
for(size_t i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
DFHack::dfh_item itm;
|
|
|
|
memset(&itm, 0, sizeof(DFHack::dfh_item));
|
2011-10-26 14:18:13 -06:00
|
|
|
Items->copyItem(p_items[i],itm);
|
2011-07-20 02:41:13 -06:00
|
|
|
|
2011-07-24 22:35:50 -06:00
|
|
|
if (!chooser->doPrint(&itm))
|
2011-07-20 02:41:13 -06:00
|
|
|
continue;
|
|
|
|
|
2011-07-24 22:35:50 -06:00
|
|
|
// Print something useful, instead of (-30000,-30000,-30000), if
|
|
|
|
// the item isn't on the ground.
|
|
|
|
char location[80];
|
2011-10-26 14:18:13 -06:00
|
|
|
if (itm.origin->flags.in_chest)
|
2011-07-24 22:35:50 -06:00
|
|
|
sprintf(location, "chest");
|
2011-10-26 14:18:13 -06:00
|
|
|
else if (itm.origin->flags.in_inventory)
|
2011-07-24 22:35:50 -06:00
|
|
|
sprintf(location, "inventory");
|
2011-10-26 14:18:13 -06:00
|
|
|
else if (itm.origin->flags.in_building)
|
2011-07-24 22:35:50 -06:00
|
|
|
sprintf(location, "building");
|
|
|
|
else
|
2011-10-26 14:18:13 -06:00
|
|
|
sprintf(location, "%d,%d,%d", itm.origin->x, itm.origin->y,
|
|
|
|
itm.origin->z);
|
2011-10-25 05:30:41 -06:00
|
|
|
std::string descr;
|
|
|
|
string name1,name2,name0;
|
2011-10-26 14:18:13 -06:00
|
|
|
itm.origin->getItemDescription(&name0, 0);
|
|
|
|
itm.origin->getItemDescription(&name1, 1);
|
|
|
|
itm.origin->getItemDescription(&name2, 2);
|
2011-07-20 02:41:13 -06:00
|
|
|
c->con.print(
|
2011-07-24 22:35:50 -06:00
|
|
|
"%5d: addr:0x%08x %6d %08x (%s) vptr:0x%08x [%d]\n"
|
2011-10-25 05:30:41 -06:00
|
|
|
" %s\n"
|
|
|
|
" %s\n"
|
2011-10-24 21:31:37 -06:00
|
|
|
" %s\n",
|
2011-10-26 14:18:13 -06:00
|
|
|
i, itm.origin, itm.origin->id, itm.origin->flags.whole,
|
2011-07-24 22:35:50 -06:00
|
|
|
location,
|
2011-10-26 14:18:13 -06:00
|
|
|
((t_virtual *)itm.origin)->vptr,
|
2011-07-20 02:41:13 -06:00
|
|
|
itm.wear_level,
|
2011-10-25 05:30:41 -06:00
|
|
|
name0.c_str(),// stacked
|
|
|
|
name1.c_str(),// singular
|
|
|
|
name2.c_str() // plural
|
2011-07-20 02:41:13 -06:00
|
|
|
);
|
2011-07-24 22:35:50 -06:00
|
|
|
chooser->postPrint(&itm);
|
2011-07-20 02:41:13 -06:00
|
|
|
/*
|
|
|
|
if (print_hex)
|
|
|
|
hexdump(DF,p_items[i],0x300);
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
if (print_acc)
|
|
|
|
c->con << Items->dumpAccessors(itm) << endl;
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
if (print_refs) {
|
|
|
|
DFHack::DfVector<uint32_t> p_refs(p, itm.origin + ref_vector);
|
|
|
|
for (size_t j = 0; j < p_refs.size(); j++) {
|
|
|
|
uint32_t vptr = p->readDWord(p_refs[j]);
|
|
|
|
uint32_t val = p->readDWord(p_refs[j]+4);
|
|
|
|
c->con.print("\t-> %d \t%s\n", int(val), p->readClassName(vptr).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2012-01-26 21:54:26 -07:00
|
|
|
/*
|
2011-07-20 02:41:13 -06:00
|
|
|
}
|
|
|
|
c->Resume();
|
2011-07-24 22:35:50 -06:00
|
|
|
|
|
|
|
Items->Finish();
|
|
|
|
delete chooser;
|
|
|
|
|
2011-07-20 02:41:13 -06:00
|
|
|
return CR_OK;
|
|
|
|
}
|
2012-01-26 21:54:26 -07:00
|
|
|
*/
|