2010-04-29 09:00:34 -06:00
|
|
|
/*
|
|
|
|
* dumps vtables, items types and class name for all items in game
|
|
|
|
* best used this way : ./dfitemdump | sort -ug
|
|
|
|
*/
|
|
|
|
#include <stdio.h>
|
2009-11-17 08:38:33 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <sstream>
|
|
|
|
#include <climits>
|
|
|
|
#include <integers.h>
|
|
|
|
#include <vector>
|
|
|
|
using namespace std;
|
|
|
|
|
2010-03-26 06:01:46 -06:00
|
|
|
#include <DFError.h>
|
2009-11-17 08:38:33 -07:00
|
|
|
#include <DFTypes.h>
|
|
|
|
#include <DFHackAPI.h>
|
2010-02-25 05:41:57 -07:00
|
|
|
#include <DFMemInfo.h>
|
2010-04-29 09:00:34 -06:00
|
|
|
#include <DFProcess.h>
|
|
|
|
#include <DFVector.h>
|
|
|
|
#include <modules/Materials.h>
|
2009-11-17 08:38:33 -07:00
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
|
2010-04-29 09:00:34 -06:00
|
|
|
DFHack::Materials * Materials;
|
2010-02-25 05:41:57 -07:00
|
|
|
|
2010-04-30 09:03:48 -06:00
|
|
|
std::string getMatDesc(int32_t typeB, int32_t typeC, int32_t typeD)
|
2010-04-30 08:17:10 -06:00
|
|
|
{
|
|
|
|
if( (typeC<419) || (typeC>618) )
|
|
|
|
{
|
|
|
|
if( (typeC<19) || (typeC>218) )
|
|
|
|
{
|
|
|
|
if(typeC)
|
|
|
|
if(typeC>0x292)
|
|
|
|
return "?";
|
|
|
|
else
|
2010-04-30 09:42:31 -06:00
|
|
|
{
|
|
|
|
if(typeC>=Materials->other.size())
|
|
|
|
return "stuff";
|
|
|
|
else
|
2010-04-30 09:48:19 -06:00
|
|
|
{
|
|
|
|
if(typeD==-1)
|
|
|
|
return std::string(Materials->other[typeC].rawname);
|
|
|
|
else
|
|
|
|
return std::string(Materials->other[typeC].rawname) + " derivate";
|
|
|
|
}
|
2010-04-30 09:42:31 -06:00
|
|
|
}
|
2010-04-30 08:17:10 -06:00
|
|
|
else
|
2010-04-30 09:03:48 -06:00
|
|
|
return Materials->inorganic[typeD].id;
|
2010-04-30 08:17:10 -06:00
|
|
|
}
|
|
|
|
else
|
2010-04-30 09:03:48 -06:00
|
|
|
{
|
|
|
|
if(typeD>=Materials->raceEx.size())
|
|
|
|
return "unknown race";
|
|
|
|
typeC-=19;
|
|
|
|
if((typeC<0) || (typeC>=Materials->raceEx[typeD].extract.size()))
|
|
|
|
{
|
|
|
|
return string(Materials->raceEx[typeD].rawname).append(" extract");
|
|
|
|
}
|
|
|
|
return std::string(Materials->raceEx[typeD].rawname).append(" ").append(Materials->raceEx[typeD].extract[typeC].rawname);
|
|
|
|
}
|
2010-04-30 08:17:10 -06:00
|
|
|
}
|
|
|
|
else
|
2010-04-30 09:03:48 -06:00
|
|
|
{
|
|
|
|
return Materials->organic[typeD].id;
|
|
|
|
}
|
2010-04-30 08:17:10 -06:00
|
|
|
}
|
|
|
|
|
2009-11-17 08:38:33 -07:00
|
|
|
int main ()
|
|
|
|
{
|
2010-04-29 09:00:34 -06:00
|
|
|
DFHack::API DF("Memory.xml");
|
|
|
|
DFHack::Process * p;
|
2010-04-30 03:50:09 -06:00
|
|
|
unsigned int i,j;
|
2010-04-29 09:00:34 -06:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
DF.Attach();
|
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFHack::memory_info * mem = DF.getMemoryInfo();
|
|
|
|
Materials = DF.getMaterials();
|
|
|
|
Materials->ReadAllMaterials();
|
|
|
|
p = DF.getProcess();
|
|
|
|
DFHack::DfVector <uint32_t> p_items (p, p->getDescriptor()->getAddress ("items_vector"));
|
|
|
|
uint32_t size = p_items.size();
|
|
|
|
|
|
|
|
|
2010-04-30 03:50:09 -06:00
|
|
|
printf("type\tvtable\tname\tquality\tdecorate\n");
|
2010-04-29 09:00:34 -06:00
|
|
|
for(i=0;i<size;i++)
|
|
|
|
{
|
|
|
|
uint32_t vtable = p->readDWord(p_items[i]);
|
|
|
|
uint32_t func0 = p->readDWord(vtable);
|
2010-04-30 03:00:18 -06:00
|
|
|
uint64_t funct0 = p->readQuad(func0);
|
|
|
|
uint32_t func1 = p->readDWord(vtable+0x238);
|
|
|
|
uint64_t funct1 = p->readQuad(func1);
|
2010-04-30 03:50:09 -06:00
|
|
|
uint32_t func2 = p->readDWord(vtable+0x288);
|
|
|
|
uint64_t funct2 = p->readQuad(func2);
|
2010-04-30 03:00:18 -06:00
|
|
|
uint32_t type = (funct0>>8)&0xffff;
|
2010-04-30 08:17:10 -06:00
|
|
|
|
|
|
|
uint32_t funcB = p->readDWord(vtable + 4);
|
|
|
|
uint32_t funcC = p->readDWord(vtable + 8);
|
|
|
|
uint32_t funcD = p->readDWord(vtable + 12);
|
|
|
|
uint64_t funcBt = p->readQuad(funcB);
|
|
|
|
uint64_t funcCt = p->readQuad(funcC);
|
|
|
|
uint64_t funcDt = p->readQuad(funcD);
|
|
|
|
int16_t typeB = -1;
|
|
|
|
int16_t typeC = -1;
|
|
|
|
int32_t typeD = -1;
|
2010-04-30 03:00:18 -06:00
|
|
|
uint32_t quality = 0;
|
2010-04-30 03:50:09 -06:00
|
|
|
bool hasDecorations;
|
2010-04-29 09:00:34 -06:00
|
|
|
string desc = p->readClassName(vtable);
|
|
|
|
|
2010-04-30 03:00:18 -06:00
|
|
|
if( (funct0&0xFFFFFFFFFF000000LL) != 0xCCCCC30000000000LL )
|
2010-04-29 09:00:34 -06:00
|
|
|
{
|
2010-04-30 03:00:18 -06:00
|
|
|
if(funct0 == 0xCCCCCCCCCCC3C033LL)
|
2010-04-29 09:00:34 -06:00
|
|
|
type = 0;
|
|
|
|
else
|
2010-04-30 03:50:09 -06:00
|
|
|
printf("bad type function address=%p", (void*)func0);
|
2010-04-29 09:00:34 -06:00
|
|
|
}
|
|
|
|
|
2010-04-30 03:00:18 -06:00
|
|
|
if(funct1 == 0xC300000092818B66LL)
|
|
|
|
quality = p->readWord(p_items[i]+0x92);
|
|
|
|
else if(funct1 == 0xCCCCCCCCCCC3C033)
|
|
|
|
quality = 0;
|
|
|
|
else
|
|
|
|
printf("bad quality function address=%p\n", (void*) func1);
|
|
|
|
|
2010-04-30 03:50:09 -06:00
|
|
|
if(funct2 == 0xCCCCCCCCCCC3C032LL)
|
|
|
|
hasDecorations = false;
|
|
|
|
else if(funct2 == 0xCCCCCCCCCCC301B0)
|
|
|
|
hasDecorations = true;
|
|
|
|
else
|
|
|
|
printf("bad decoration function address=%p\n", (void*) func2);
|
|
|
|
|
2010-04-30 08:17:10 -06:00
|
|
|
if(funcBt == 0xCCCCCCCCC3FFC883LL)
|
|
|
|
typeB = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint64_t funcBtEnd = p->readQuad(funcB+8);
|
|
|
|
if(
|
|
|
|
((funcBt&0xFFFFFFFF0000FFFFLL) == 0x8B6600000000818BLL) &&
|
|
|
|
((funcBtEnd&0xFFFFFFFFFFFF00FFLL) == 0xCCCCCCCCCCC30040LL) )
|
|
|
|
{
|
|
|
|
uint32_t off1 = (funcBt>>16) & 0xffff;
|
|
|
|
uint32_t off2 = (funcBtEnd>>8) & 0xff;
|
|
|
|
uint32_t pt1 = p->readDWord(p_items[i] + off1);
|
|
|
|
typeB = p->readWord(pt1 + off2);
|
|
|
|
}
|
|
|
|
else if((funcBt&0xFFFFFF0000FFFFFFLL)==0xC300000000818B66LL)
|
|
|
|
{
|
|
|
|
uint32_t off1 = (funcBt>>24) & 0xffff;
|
|
|
|
typeB = p->readWord(p_items[i] + off1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("bad typeB func @%p\n", (void*) funcB);
|
|
|
|
}
|
|
|
|
|
2010-04-30 09:06:38 -06:00
|
|
|
if(funcCt == 0xCCCCCCCCC3FFC883LL)
|
|
|
|
typeC = -1;
|
|
|
|
else if( (funcCt&0xFFFFFF0000FFFFFFLL) == 0xC300000000818B66 )
|
2010-04-30 08:17:10 -06:00
|
|
|
{
|
|
|
|
uint32_t off1 = (funcCt>>24)&0xffff;
|
|
|
|
typeC = p->readWord(p_items[i] + off1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("bad typeC func @%p\n", (void*) funcC);
|
|
|
|
|
2010-04-30 09:06:38 -06:00
|
|
|
if(funcDt == 0xCCCCCCCCC3FFC883LL)
|
|
|
|
typeD = -1;
|
|
|
|
else if( (funcDt&0xFFFFFFFF0000FFFFLL) == 0xCCC300000000818BLL )
|
2010-04-30 08:17:10 -06:00
|
|
|
{
|
|
|
|
uint32_t off1 = (funcDt>>16) & 0xffff;
|
|
|
|
typeD = p->readDWord(p_items[i] + off1);
|
|
|
|
}
|
|
|
|
else if ( (funcDt&0xFFFFFF0000FFFFFFLL) == 0xC30000000081BF0FLL )
|
|
|
|
{
|
|
|
|
uint32_t off1 = (funcDt>>24) & 0xffff;
|
|
|
|
typeD = (int16_t) p->readWord(p_items[i] + off1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("bad typeD func @%p\n", (void*) funcD);
|
|
|
|
|
2010-04-30 03:50:09 -06:00
|
|
|
// printf("%p\t%.16LX\t", (void*) func2, funct2);
|
2010-04-30 08:21:09 -06:00
|
|
|
printf("%d\t%p\t%s\t%d\t[%d,%d,%d -> %s]", type, (void*)vtable, desc.c_str(), quality,
|
2010-04-30 09:03:48 -06:00
|
|
|
typeB, typeC, typeD, getMatDesc(typeB, typeC, typeD).c_str());
|
2010-04-30 08:21:09 -06:00
|
|
|
// printf("\t%p\t%.16LX", (void *) funcD, funcDt);
|
2010-04-30 09:08:16 -06:00
|
|
|
if(hasDecorations)
|
2010-04-30 03:50:09 -06:00
|
|
|
{
|
|
|
|
bool sep = false;
|
|
|
|
printf("\tdeco=[");
|
|
|
|
uint32_t decStart = p->readDWord(p_items[i] + 0xAC);
|
|
|
|
uint32_t decEnd = p->readDWord(p_items[i] + 0xB0);
|
|
|
|
if(decStart != decEnd)
|
|
|
|
{
|
|
|
|
for(j=decStart;j<decEnd;j+=4)
|
|
|
|
{
|
|
|
|
uint32_t decoration = p->readDWord(j);
|
|
|
|
uint32_t dvtable = p->readDWord(decoration);
|
|
|
|
string ddesc = p->readClassName(dvtable);
|
|
|
|
uint32_t dtypefunc = p->readDWord(dvtable + 20);
|
|
|
|
uint64_t dtypefunct = p->readQuad(dtypefunc);
|
2010-04-30 08:17:10 -06:00
|
|
|
uint32_t dtypeC = p->readWord(decoration + 0x4);
|
|
|
|
uint32_t dtypeD = p->readDWord(decoration + 0x8);
|
2010-04-30 03:50:09 -06:00
|
|
|
uint32_t dtype = 0;
|
2010-04-30 03:54:08 -06:00
|
|
|
uint32_t dqual = p->readWord(decoration + 20);
|
2010-04-30 03:50:09 -06:00
|
|
|
if( (dtypefunct&0xFFFFFFFFFFFF00FFLL) == 0xCCCCC300000000B8LL)
|
|
|
|
dtype = (dtypefunct>>8)&0xfffffff;
|
|
|
|
else
|
|
|
|
printf("bad decoration type function, address=%p\n", (void*) dtypefunc);
|
|
|
|
if(sep)
|
|
|
|
printf(",");
|
2010-04-30 09:03:48 -06:00
|
|
|
printf("%s[t=%d,q=%d,%s{%d,%d}]", ddesc.c_str(), dtype, dqual, getMatDesc(-1, dtypeC, dtypeD).c_str(), dtypeC, dtypeD);
|
2010-04-30 03:50:09 -06:00
|
|
|
sep = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("]");
|
|
|
|
}
|
|
|
|
printf("\n");
|
2010-04-29 09:00:34 -06:00
|
|
|
}
|
2009-11-17 20:35:43 -07:00
|
|
|
|
2010-04-29 09:00:34 -06:00
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
|
|
|
return 0;
|
2009-11-17 08:38:33 -07:00
|
|
|
}
|