Many fixes to DFHack tools and examples

develop
Petr Mrázek 2010-03-26 13:01:46 +01:00
parent 02b7d92135
commit 4d939363b5
24 changed files with 431 additions and 241 deletions

@ -1,5 +1,5 @@
// Attach test
// attachtest - 100x attach/detach, 100x reads, 100x writes
// attachtest - 1000x suspend/resume
#include <iostream>
#include <climits>
@ -21,9 +21,12 @@ int main (void)
DF.Attach();
DF.Detach();
}
catch (DFHack::Error::NoProcess& e)
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
/*

@ -8,18 +8,10 @@
#include <vector>
using namespace std;
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.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
@ -131,9 +123,16 @@ int main (int argc,const char* argv[])
vector<DFHack::t_matgloss> creaturestypes;
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
@ -173,9 +172,9 @@ int main (int argc,const char* argv[])
}
DF.Detach();
#ifndef LINUX_BUILD
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
#endif
return 0;
}

@ -1,6 +1,7 @@
// Catsplosion
// By Zhentar
// This work of evil makes every cat, male or female, grown or kitten, pregnant and due within 2 in-game hours...
// This work of evil makes every cat, male or female, grown or kitten, pregnant
// and due within 2 in-game hours...
#include <iostream>
#include <climits>
@ -9,6 +10,7 @@
#include <stdlib.h> // for rand()
using namespace std;
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
@ -33,13 +35,19 @@ int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature)
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
proc = DF.getProcess();
mem = DF.getMemoryInfo();
creature_pregnancy_offset = mem->getOffset("creature_pregnancy");
@ -47,6 +55,9 @@ int main (void)
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
@ -54,6 +65,9 @@ int main (void)
if(!DF.InitReadCreatures(numCreatures))
{
cerr << "Can't get creatures" << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}

@ -6,6 +6,7 @@
#include <vector>
using namespace std;
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
@ -301,9 +302,16 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}

@ -8,6 +8,7 @@
#include <vector>
using namespace std;
#include <DFError.h>
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
@ -190,14 +191,20 @@ void printItem(DFHack::t_item item, const string & typeString,const matGlosses &
int main ()
{
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
}
catch (exception& e)
{
cerr << "DF not found" << endl;
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
DF.InitViewAndCursor();
matGlosses mat;
@ -280,11 +287,10 @@ int main ()
}
DF.FinishReadItems();
}
DF.FinishReadBuildings();
DF.Detach();
#ifndef LINUX_BUILD
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
#endif
return 0;
}

@ -50,9 +50,16 @@ int main (int numargs, char** args)
DFHack::mapblock40d Block;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}

@ -45,12 +45,20 @@ uint32_t endian_swap(uint32_t x)
int main (void)
{
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
DFHack::API DF("Memory.xml");
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords))

@ -15,9 +15,16 @@ int main (void)
{
vector<DFHack::t_matgloss> creaturestypes;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}

@ -11,11 +11,19 @@ using namespace std;
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
vector <DFHack::t_matgloss> Woods;
DF.ReadWoodMatgloss(Woods);

@ -13,12 +13,19 @@ using namespace std;
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
else
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
if (DF.InitViewAndCursor())
{
int32_t x,y,z;
@ -47,7 +54,7 @@ int main (void)
{
cerr << "Can't detach from DF" << endl;
}
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -24,10 +24,12 @@ void print_bits ( T val, std::ostream& out )
val >>= 1;
}
}
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
uint32_t numCreatures;
vector<DFHack::t_matgloss> creaturestypes;
void printDwarves(DFHack::API & DF)
{
int dwarfCounter = 0;
@ -311,12 +313,18 @@ bool setCursorToCreature(DFHack::API &DF)
int main (void)
{
DFHack::API DF("Memory.xml");
if (!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.Suspend();
DFHack::memory_info * mem = DF.getMemoryInfo();

@ -31,12 +31,20 @@ void printSettlement(DFHack::API & DF, const DFHack::t_settlement & settlement,
int main (int argc,const char* argv[])
{
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
DFHack::API DF("Memory.xml");
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::t_settlement current;
uint32_t numSettlements;
if(!DF.InitReadSettlements(numSettlements))
@ -44,6 +52,7 @@ int main (int argc,const char* argv[])
cerr << "Could not read Settlements" << endl;
return 1;
}
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords))
@ -51,6 +60,7 @@ int main (int argc,const char* argv[])
cerr << "Can't get name tables" << endl;
return 1;
}
cout << "Settlements\n";
/*for(uint32_t i =0;i<numSettlements;i++){
DFHack::t_settlement temp;
@ -58,6 +68,7 @@ int main (int argc,const char* argv[])
printSettlement(DF,temp,englishWords,foreignWords);
}*/
// MSVC claims this is causing the heap to be corrupted, I think it is because the currentSettlement vector only has 1 item in it
cout << "Current Settlement\n";
if(DF.ReadCurrentSettlement(current))
printSettlement(DF,current,englishWords,foreignWords);
@ -65,6 +76,7 @@ int main (int argc,const char* argv[])
DF.FinishReadNameTables();
DF.FinishReadSettlements();
DF.Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -15,11 +15,19 @@ int main (void)
{
string blah;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
cout << "Attached, DF should be suspended now" << endl;
getline(cin, blah);

@ -22,12 +22,19 @@ int main (int numargs, const char ** args)
input >> std::hex >> addr;
}
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
else
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Process* p = DF.getProcess();
DFHack::memory_info* mem = DF.getMemoryInfo();
const vector<string> * names = mem->getClassIDMapping();
@ -46,7 +53,7 @@ int main (int numargs, const char ** args)
cout << "cap 0x" << hex << p->readDWord(addr+0xC) << endl;
#endif
*/
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -308,14 +308,18 @@ main(int argc, char *argv[])
vector<t_vein> veinVector;
vector<t_frozenliquidvein> IceVeinVector;
// init the API
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
pDF = &DF;
// attach
if(!DF.Attach())
}
catch (exception& e)
{
error = "Can't find DF.";
pDF = 0;
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
finish(0);
}

@ -268,7 +268,9 @@ bool API::InitMap()
uint32_t x_array_loc = g_pProcess->readDWord (map_offset);
if (!x_array_loc)
{
throw Error::NoMapLoaded();
return false;
// FIXME: only throw this due to programmer error, in the other map functions
//throw Error::NoMapLoaded();
}
// get the size

@ -15,13 +15,30 @@ int main (void)
uint32_t bytes_read = 0;
DFHack::occupancies40d occupancies;
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
DFHack::API DF("Memory.xml");
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.InitMap();
// init the map
if(!DF.InitMap())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.getSize(x_max,y_max,z_max);
// walk the map

@ -41,15 +41,20 @@ int main ()
int items;
int found = 0, converted = 0;
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
DFHack::API DF("Memory.xml");
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.Suspend();
// Find out which material is bauxite
if(!DF.ReadStoneMatgloss(stoneMat))
{

@ -299,7 +299,7 @@ int main (int argc, char** argv)
string s_targets;
string s_origin;
bool verbose;
int max;
int max = 10;
argstream as(argc,argv);
as >>option('v',"verbose",verbose,"Active verbose mode")
@ -327,11 +327,21 @@ int main (int argc, char** argv)
else
{
DFHack::API DF("Memory.xml");
if(DF.Attach())
try
{
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
if (DF.InitMap())
{
int count = dig(DF, targets, 10, origin[0],origin[1],origin[2], verbose);
int count = dig(DF, targets, max, origin[0],origin[1],origin[2], verbose);
cout << count << " targets designated" << endl;
if (!DF.Detach())
@ -344,14 +354,9 @@ int main (int argc, char** argv)
cerr << "Unable to init map" << endl;
}
}
else
{
cerr << "Unable to attach to DF process" << endl;
}
}
#ifndef LINUX_BUILD
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
#endif
return 0;
}

@ -100,9 +100,16 @@ int main (void)
{
string select;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Process * p = DF.getProcess();

@ -194,9 +194,16 @@ int main ()
<< "Like set on fire all MICROCLINE item_stone..." << endl
<< "Some unusual combinations might be untested and cause the program to crash..."<< endl
<< "so, watch your step and backup your fort" << endl;
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::memory_info *mem = DF.getMemoryInfo();

@ -15,12 +15,19 @@ int main (void)
DFHack::designations40d designations;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
DF.Attach();
}
catch (exception& e)
{
cerr << "DF not found" << endl;
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.InitMap();
if (DF.InitViewAndCursor())

@ -54,18 +54,29 @@ int main (int argc, const char* argv[])
vector<DFHack::t_matgloss> stonetypes;
vector< vector <uint16_t> > layerassign;
// init the API
DFHack::API DF("Memory.xml");
// attach
if(!DF.Attach())
try
{
DF.Attach();
}
catch (exception& e)
{
cerr << "DF not found" << endl;
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
// init the map
DF.InitMap();
if(!DF.InitMap())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.getSize(x_max,y_max,z_max);
// get stone matgloss mapping
@ -73,6 +84,9 @@ int main (int argc, const char* argv[])
{
//DF.DestroyMap();
cerr << "Can't get the materials." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
@ -80,6 +94,9 @@ int main (int argc, const char* argv[])
if(!DF.ReadGeology( layerassign ))
{
cerr << "Can't get region geology." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}

@ -14,12 +14,29 @@ int main (void)
DFHack::designations40d designations;
DFHack::API DF("Memory.xml");
if(!DF.Attach())
try
{
cerr << "DF not found" << endl;
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.InitMap();
// init the map
if(!DF.InitMap())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.getSize(x_max,y_max,z_max);
// walk the map