research into buildings, building hexdump tool

develop
Petr Mrázek 2009-11-04 01:01:55 +00:00
parent 45695d7a69
commit d3b62a7672
21 changed files with 175 additions and 4 deletions

@ -0,0 +1,5 @@
FF - retractable
00 - west
01 - east
02 - north
03 - south

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

@ -541,6 +541,7 @@ bool DFHackAPIImpl::ReadBuilding(const uint32_t &index, t_building & building)
// transform
int32_t type = -1;
offset_descriptor->resolveClassId(temp, type);
building.origin = temp;
building.vtable = bld_40d.vtable;
building.x1 = bld_40d.x1;
building.x2 = bld_40d.x2;
@ -709,3 +710,8 @@ bool DFHackAPIImpl::isAttached()
{
return dm != NULL;
}
void DFHackAPIImpl::ReadRaw (const uint32_t &offset, const uint32_t &size, uint8_t *target)
{
Mread(offset, size, target);
}

@ -159,6 +159,8 @@ public:
virtual uint32_t InitReadCreatures() = 0;
virtual bool ReadCreature(const uint32_t &index, t_creature & furball) = 0;
virtual void FinishReadCreatures() = 0;
virtual void ReadRaw (const uint32_t &offset, const uint32_t &size, uint8_t *target) = 0;
};
#ifdef BUILD_DFHACK_LIB
@ -305,6 +307,8 @@ public:
uint32_t InitReadCreatures();
bool ReadCreature(const uint32_t &index, t_creature & furball);
void FinishReadCreatures();
void ReadRaw (const uint32_t &offset, const uint32_t &size, uint8_t *target);
};
#endif

@ -352,7 +352,10 @@ extern "C"
{
self->FinishReadCreatures();
}
DFHACKAPI void DFHackAPI_ReadRaw (DFHackAPIHandle self, const uint32_t &offset, const uint32_t &size, uint8_t *target)
{
self->ReadRaw(offset, size, target);
}
#ifdef __cplusplus
}
#endif

@ -134,6 +134,7 @@ extern "C"
DFHACKAPI bool DFHackAPI_ReadCreature (DFHackAPIHandle self, const uint32_t *index, t_creature * furball);
DFHACKAPI void DFHackAPI_FinishReadCreatures (DFHackAPIHandle self);
DFHACKAPI void DFHackAPI_ReadRaw (DFHackAPIHandle self, const uint32_t &offset, const uint32_t &size, uint8_t *target);
#ifdef __cplusplus
}
#endif // __cplusplus
@ -472,7 +473,10 @@ public:
DFHackAPI_FinishReadCreatures (handle);
}
inline void ReadRaw(const uint32_t &offset, const uint32_t &size, uint8_t *target)
{
DFHackAPI_ReadRaw(handle, offset, size, target);
}
};
#endif // __cplusplus

@ -157,7 +157,7 @@ bool ProcessManager::findProcessess()
cmdline_path = dir_name + "cmdline";
ifstream ifs ( cmdline_path.c_str() , ifstream::in );
getline(ifs,cmdline);
if (cmdline.find("dwarfort.exe") != string::npos || cmdline.find("Dwarf Fortress.exe") != string::npos)
if (cmdline.find("dwarfort-w.exe") != string::npos || cmdline.find("dwarfort.exe") != string::npos || cmdline.find("Dwarf Fortress.exe") != string::npos)
{
// put executable name and path together
exe_link = target_name;

@ -105,6 +105,7 @@ struct t_building_df40d
//cooked
struct t_building
{
uint32_t origin;
uint32_t vtable;
uint32_t x1;

@ -25,6 +25,11 @@ TARGET_LINK_LIBRARIES(dfcleanmap dfhack)
ADD_EXECUTABLE(dfcreaturedump creaturedump.cpp)
TARGET_LINK_LIBRARIES(dfcreaturedump dfhack)
# buildingsdump - dump buildings and their raw data filtered by type
ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp)
TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack)
# attachtest - 100x attach/detach, 100x reads, 100x writes
ADD_EXECUTABLE(dfattachtest attachtest.cpp)
TARGET_LINK_LIBRARIES(dfattachtest dfhack)

@ -0,0 +1,143 @@
// Creature dump
#include <iostream>
#include <iomanip>
#include <climits>
#include <integers.h>
#include <vector>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
/*
oh. fsck it. I'll do the hexdump now and add the things I found in a research/ folder
groups of four bytes, 4 per line
1 space between bytes
2 between groups
offset from the object start on the left
and length set from command line
default 256
*/
/*
address = absolute address of dump start
length = length in lines. 1 line = 16 bytes
*/
void hexdump (DFHackAPI& DF, uint32_t address, uint32_t length)
{
char *buf = new char[length * 16];
DF.ReadRaw(address, length * 16, (uint8_t *) buf);
for (int i = 0; i < length; i++)
{
// leading offset
cout << "0x" << hex << setw(4) << i*16 << " ";
// groups
for(int j = 0; j < 4; j++)
{
// bytes
for(int k = 0; k < 4; k++)
{
int idx = i * 16 + j * 4 + k;
cout << hex << setw(2) << int(static_cast<unsigned char>(buf[idx])) << " ";
}
cout << " ";
}
cout << endl;
}
delete buf;
}
void interleave_hex (DFHackAPI& DF, vector < uint32_t > & addresses, uint32_t length)
{
vector <char * > bufs;
for(int counter = 0; counter < addresses.size(); counter ++)
{
char * buf = new char[length * 16];
DF.ReadRaw(addresses[counter], length * 16, (uint8_t *) buf);
bufs.push_back(buf);
}
cout << setfill('0');
// output a header
cout << " ";
for (int obj = 0; obj < addresses.size(); obj++)
{
cout << "0x" << hex << setw(9) << addresses[obj] << " ";
}
cout << endl;
for(int offs = 0 ; offs < length * 16; offs += 4)
{
if((!(offs % 16)) && offs != 0)
{
cout << endl;
}
cout << "0x" << hex << setw(4) << offs << " ";
for (int object = 0; object < bufs.size(); object++)
{
// bytes
for(int k = 0; k < 4; k++)
{
uint8_t data = bufs[object][offs + k];
cout << hex << setw(2) << int(static_cast<unsigned char>(data)) << " ";
}
cout << " ";
}
cout << endl;
}
for(int counter = 0; counter < addresses.size(); counter ++)
{
delete bufs[counter];
}
}
template <typename T>
void print_bits ( T val, std::ostream& out )
{
T n_bits = sizeof ( val ) * CHAR_BIT;
for ( unsigned i = 0; i < n_bits; ++i ) {
out<< !!( val & 1 ) << " ";
val >>= 1;
}
}
int main (int argc,const char* argv[])
{
if (argc != 2) return 1;
vector<t_matgloss> creaturestypes;
DFHackAPI *pDF = CreateDFHackAPI("Memory.xml");
DFHackAPI &DF = *pDF;
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
vector <string> buildingtypes;
uint32_t numBuildings = DF.InitReadBuildings(buildingtypes);
vector < uint32_t > addresses;
for(uint32_t i = 0; i < numBuildings; i++)
{
t_building temp;
DF.ReadBuilding(i, temp);
if(buildingtypes[temp.type] == argv[1])
{
//cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl;
//hexdump(DF, temp.origin, 16);
addresses.push_back(temp.origin);
}
}
interleave_hex(DF,addresses,16);
DF.FinishReadBuildings();
DF.Detach();
delete pDF;
cout << "Done. Press any key to continue" << endl;
cin.ignore();
return 0;
}