2009-11-03 18:01:55 -07:00
|
|
|
// Creature dump
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
2009-11-05 18:04:17 -07:00
|
|
|
#include <sstream>
|
2009-11-03 18:01:55 -07:00
|
|
|
#include <climits>
|
|
|
|
#include <vector>
|
2010-06-04 16:02:02 -06:00
|
|
|
#include <stdio.h>
|
|
|
|
//using namespace std;
|
2009-11-03 18:01:55 -07:00
|
|
|
|
2010-06-04 16:02:02 -06:00
|
|
|
#define DFHACK_WANT_MISCUTILS
|
2010-05-25 22:48:23 -06:00
|
|
|
#include <DFHack.h>
|
2009-11-03 18:01:55 -07:00
|
|
|
|
|
|
|
int main (int argc,const char* argv[])
|
|
|
|
{
|
2010-04-09 07:16:14 -06:00
|
|
|
int lines = 16;
|
|
|
|
int mode = 0;
|
2009-11-05 18:04:17 -07:00
|
|
|
if (argc < 2 || argc > 3)
|
|
|
|
{
|
2010-04-09 07:16:14 -06:00
|
|
|
/*
|
2009-11-05 18:04:17 -07:00
|
|
|
cout << "usage:" << endl;
|
|
|
|
cout << argv[0] << " object_name [number of lines]" << endl;
|
2010-03-26 06:38:49 -06:00
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cout << "Done. Press any key to continue" << endl;
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2009-11-05 18:04:17 -07:00
|
|
|
return 0;
|
2010-04-09 07:16:14 -06:00
|
|
|
*/
|
2009-11-05 18:04:17 -07:00
|
|
|
}
|
2010-04-09 07:16:14 -06:00
|
|
|
else if(argc == 3)
|
2009-11-05 18:04:17 -07:00
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::string s = argv[2]; //blah. I don't care
|
|
|
|
std::istringstream ins; // Declare an input string stream.
|
2009-11-05 18:04:17 -07:00
|
|
|
ins.str(s); // Specify string to read.
|
|
|
|
ins >> lines; // Reads the integers from the string.
|
2010-04-09 07:16:14 -06:00
|
|
|
mode = 1;
|
2009-11-05 18:04:17 -07:00
|
|
|
}
|
|
|
|
|
2010-06-04 16:02:02 -06:00
|
|
|
std::map <uint32_t, std::string> custom_workshop_types;
|
2009-11-03 18:01:55 -07:00
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DFMgr ("Memory.xml");
|
|
|
|
DFHack::Context *DF;
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
|
|
|
{
|
2010-05-23 15:06:10 -06:00
|
|
|
DF = DFMgr.getSingleContext();
|
|
|
|
DF->Attach();
|
2010-03-26 06:01:46 -06:00
|
|
|
}
|
2010-06-04 16:02:02 -06:00
|
|
|
catch (std::exception& e)
|
2009-11-03 18:01:55 -07:00
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cerr << e.what() << std::endl;
|
2010-03-26 06:01:46 -06:00
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2009-11-03 18:01:55 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2010-04-12 16:03:29 -06:00
|
|
|
|
2010-08-20 06:10:05 -06:00
|
|
|
DFHack::VersionInfo * mem = DF->getMemoryInfo();
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::Buildings * Bld = DF->getBuildings();
|
2011-03-18 04:38:37 -06:00
|
|
|
DFHack::Gui * Gui = DF->getGui();
|
2010-02-11 14:08:39 -07:00
|
|
|
|
|
|
|
uint32_t numBuildings;
|
2010-04-09 06:44:00 -06:00
|
|
|
if(Bld->Start(numBuildings))
|
2009-11-03 18:01:55 -07:00
|
|
|
{
|
2010-04-12 16:03:29 -06:00
|
|
|
Bld->ReadCustomWorkshopTypes(custom_workshop_types);
|
2010-04-09 07:16:14 -06:00
|
|
|
if(mode)
|
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cout << numBuildings << std::endl;
|
|
|
|
std::vector < uint32_t > addresses;
|
2010-04-09 07:16:14 -06:00
|
|
|
for(uint32_t i = 0; i < numBuildings; i++)
|
|
|
|
{
|
|
|
|
DFHack::t_building temp;
|
|
|
|
Bld->Read(i, temp);
|
|
|
|
if(temp.type != 0xFFFFFFFF) // check if type isn't invalid
|
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::string typestr;
|
2010-04-09 07:16:14 -06:00
|
|
|
mem->resolveClassIDToClassname(temp.type, typestr);
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cout << typestr << std::endl;
|
2010-04-09 07:16:14 -06:00
|
|
|
if(typestr == argv[1])
|
|
|
|
{
|
|
|
|
//cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl;
|
|
|
|
//hexdump(DF, temp.origin, 16);
|
|
|
|
addresses.push_back(temp.origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// couldn't translate type, print out the vtable
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cout << "unknown vtable: " << temp.vtable << std::endl;
|
2010-04-09 07:16:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
interleave_hex(DF,addresses,lines / 4);
|
|
|
|
}
|
|
|
|
else // mode
|
2009-11-03 18:01:55 -07:00
|
|
|
{
|
2010-04-09 07:16:14 -06:00
|
|
|
int32_t x,y,z;
|
2011-03-18 04:38:37 -06:00
|
|
|
Gui->getCursorCoords(x,y,z);
|
2010-04-09 07:16:14 -06:00
|
|
|
if(x != -30000)
|
2010-02-09 17:20:15 -07:00
|
|
|
{
|
2010-04-09 07:16:14 -06:00
|
|
|
for(uint32_t i = 0; i < numBuildings; i++)
|
2010-02-11 14:08:39 -07:00
|
|
|
{
|
2010-04-09 07:16:14 -06:00
|
|
|
DFHack::t_building temp;
|
|
|
|
Bld->Read(i, temp);
|
2010-05-23 15:06:10 -06:00
|
|
|
if( (uint32_t)x >= temp.x1
|
|
|
|
&& (uint32_t)x <= temp.x2
|
|
|
|
&& (uint32_t)y >= temp.y1
|
|
|
|
&& (uint32_t)y <= temp.y2
|
|
|
|
&& (uint32_t)z == temp.z
|
|
|
|
)
|
2010-04-09 07:16:14 -06:00
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::string typestr;
|
2010-04-09 07:16:14 -06:00
|
|
|
mem->resolveClassIDToClassname(temp.type, typestr);
|
|
|
|
printf("Address 0x%x, type %d (%s), %d/%d/%d\n",temp.origin, temp.type, typestr.c_str(), temp.x1,temp.y1,temp.z);
|
2010-04-09 16:24:41 -06:00
|
|
|
printf("Material %d %d\n", temp.material.type, temp.material.index);
|
2010-04-12 16:03:29 -06:00
|
|
|
int32_t custom;
|
|
|
|
if((custom = Bld->GetCustomWorkshopType(temp)) != -1)
|
|
|
|
{
|
|
|
|
printf("Custom workshop type %s (%d)\n",custom_workshop_types[custom].c_str(),custom);
|
|
|
|
}
|
2010-04-09 07:16:14 -06:00
|
|
|
hexdump(DF,temp.origin,120);
|
|
|
|
}
|
2010-02-11 14:08:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cout << numBuildings << std::endl;
|
2010-04-09 07:16:14 -06:00
|
|
|
for(uint32_t i = 0; i < numBuildings; i++)
|
|
|
|
{
|
|
|
|
DFHack::t_building temp;
|
|
|
|
Bld->Read(i, temp);
|
2010-06-04 16:02:02 -06:00
|
|
|
std::string typestr;
|
2010-04-09 07:16:14 -06:00
|
|
|
mem->resolveClassIDToClassname(temp.type, typestr);
|
|
|
|
printf("Address 0x%x, type %d (%s), %d/%d/%d\n",temp.origin, temp.type, typestr.c_str(), temp.x1,temp.y1,temp.z);
|
|
|
|
}
|
2010-02-09 17:20:15 -07:00
|
|
|
}
|
|
|
|
}
|
2010-04-09 06:44:00 -06:00
|
|
|
Bld->Finish();
|
2010-02-11 14:08:39 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cerr << "buildings not supported for this DF version" << std::endl;
|
2009-11-03 18:01:55 -07:00
|
|
|
}
|
2010-02-11 14:08:39 -07:00
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DF->Detach();
|
2010-03-26 06:01:46 -06:00
|
|
|
#ifndef LINUX_BUILD
|
2010-06-04 16:02:02 -06:00
|
|
|
std::cout << "Done. Press any key to continue" << std::endl;
|
2010-03-26 06:01:46 -06:00
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2009-11-03 18:01:55 -07:00
|
|
|
return 0;
|
2009-12-13 14:03:19 -07:00
|
|
|
}
|