Fix cleartask tool, should now work everywhere, doesn't use magic constants.

develop
Petr Mrázek 2011-05-08 11:21:52 +02:00
parent 7829e12e85
commit 63ae4e3738
1 changed files with 13 additions and 9 deletions

@ -18,6 +18,7 @@ int main ()
unsigned int i; unsigned int i;
DFHack::ContextManager DFMgr("Memory.xml"); DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF; DFHack::Context * DF;
DFHack::Items * Items;
try try
{ {
DF = DFMgr.getSingleContext(); DF = DFMgr.getSingleContext();
@ -36,11 +37,13 @@ int main ()
uint32_t item_vec_offset = 0; uint32_t item_vec_offset = 0;
try try
{ {
item_vec_offset = p->getDescriptor()->getAddress ("items_vector"); Items = DF->getItems();
DFHack::OffsetGroup* itemGroup = p->getDescriptor()->getGroup("Items");
item_vec_offset = itemGroup->getAddress("items_vector");
} }
catch(DFHack::Error::AllMemdef & e) catch(DFHack::Error::All & e)
{ {
cerr << "missing offset for the item vector, exiting :(" << endl; cerr << "Fatal error, exiting :(" << endl << e.what() << endl;
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cin.ignore(); cin.ignore();
#endif #endif
@ -53,12 +56,13 @@ int main ()
int numtasked = 0; int numtasked = 0;
for (i=0;i<size;i++) for (i=0;i<size;i++)
{ {
DFHack::t_itemflags flags; DFHack::dfh_item temp;
flags.whole = p->readDWord(p_items[i] + 0x0C); Items->readItem(p_items[i],temp);
DFHack::t_itemflags & flags = temp.base.flags;
if (flags.in_job) if (flags.in_job)
{ {
flags.in_job = 0; flags.in_job = 0;
p->writeDWord(p_items[i] + 0x0C, flags.whole); Items->writeItem(temp);
numtasked++; numtasked++;
} }
} }