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 // Attach test
// attachtest - 100x attach/detach, 100x reads, 100x writes // attachtest - 1000x suspend/resume
#include <iostream> #include <iostream>
#include <climits> #include <climits>
@ -21,9 +21,12 @@ int main (void)
DF.Attach(); DF.Attach();
DF.Detach(); DF.Detach();
} }
catch (DFHack::Error::NoProcess& e) catch (exception& e)
{ {
cerr << e.what() << endl; cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1; return 1;
} }
/* /*
@ -79,8 +82,8 @@ int main (void)
cout << "suspend tests done in " << time_diff << " seconds." << endl; cout << "suspend tests done in " << time_diff << " seconds." << endl;
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif #endif
return 0; return 0;
} }

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

@ -1,6 +1,7 @@
// Catsplosion // Catsplosion
// By Zhentar // 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 <iostream>
#include <climits> #include <climits>
@ -9,6 +10,7 @@
#include <stdlib.h> // for rand() #include <stdlib.h> // for rand()
using namespace std; using namespace std;
#include <DFError.h>
#include <DFTypes.h> #include <DFTypes.h>
#include <DFHackAPI.h> #include <DFHackAPI.h>
#include <DFMemInfo.h> #include <DFMemInfo.h>
@ -22,42 +24,54 @@ uint32_t creature_pregnancy_offset;
int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature) int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature)
{ {
if(string(creaturestypes[creature.type].id) == "CAT") if(string(creaturestypes[creature.type].id) == "CAT")
{ {
proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1); proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1);
return 1; return 1;
} }
return 0; return 0;
} }
int main (void) int main (void)
{ {
DFHack::API DF("Memory.xml"); 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; return 1;
} }
proc = DF.getProcess(); proc = DF.getProcess();
mem = DF.getMemoryInfo(); mem = DF.getMemoryInfo();
creature_pregnancy_offset = mem->getOffset("creature_pregnancy"); creature_pregnancy_offset = mem->getOffset("creature_pregnancy");
if(!DF.ReadCreatureMatgloss(creaturestypes)) if(!DF.ReadCreatureMatgloss(creaturestypes))
{ {
cerr << "Can't get the creature types." << endl; cerr << "Can't get the creature types." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1; return 1;
} }
uint32_t numCreatures; uint32_t numCreatures;
if(!DF.InitReadCreatures(numCreatures)) if(!DF.InitReadCreatures(numCreatures))
{ {
cerr << "Can't get creatures" << endl; cerr << "Can't get creatures" << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1; return 1;
} }
int cats=0; int cats=0;
for(uint32_t i = 0; i < numCreatures; i++) for(uint32_t i = 0; i < numCreatures; i++)
{ {
@ -66,13 +80,13 @@ int main (void)
cats+=fertilizeCat(DF,temp); cats+=fertilizeCat(DF,temp);
} }
cout << cats << " cats impregnated." << endl; cout << cats << " cats impregnated." << endl;
DF.FinishReadCreatures(); DF.FinishReadCreatures();
DF.Detach(); DF.Detach();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif #endif
return 0; return 0;
} }

@ -6,6 +6,7 @@
#include <vector> #include <vector>
using namespace std; using namespace std;
#include <DFError.h>
#include <DFTypes.h> #include <DFTypes.h>
#include <DFHackAPI.h> #include <DFHackAPI.h>
#include <DFMemInfo.h> #include <DFMemInfo.h>
@ -152,7 +153,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{ {
if(string(creaturestypes[creature.type].id) == "DWARF") if(string(creaturestypes[creature.type].id) == "DWARF")
{ {
cout << "address: " << hex << creature.origin << dec << " creature type: " << creaturestypes[creature.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl; cout << "address: " << hex << creature.origin << dec << " creature type: " << creaturestypes[creature.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
bool addendl = false; bool addendl = false;
if(creature.name.first_name[0]) if(creature.name.first_name[0])
{ {
@ -213,11 +214,11 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout <<"Male"; cout <<"Male";
} }
cout << endl; cout << endl;
if(creature.pregnancy_timer > 0) if(creature.pregnancy_timer > 0)
cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. "; cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate; cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate;
cout << endl; cout << endl;
/* /*
//skills //skills
@ -301,9 +302,16 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
int main (void) int main (void)
{ {
DFHack::API DF("Memory.xml"); 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; return 1;
} }

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

@ -50,9 +50,16 @@ int main (int numargs, char** args)
DFHack::mapblock40d Block; DFHack::mapblock40d Block;
DFHack::API DF("Memory.xml"); 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; return 1;
} }

@ -15,22 +15,22 @@ using namespace std;
// returns a lower case version of the string // returns a lower case version of the string
string tolower (const string & s) string tolower (const string & s)
{ {
string d (s); string d (s);
transform (d.begin (), d.end (), d.begin (), (int(*)(int)) tolower); transform (d.begin (), d.end (), d.begin (), (int(*)(int)) tolower);
return d; return d;
} }
string groupBy2(const string & s) string groupBy2(const string & s)
{ {
string d; string d;
for(int i =2;i<s.length();i++){ for(int i =2;i<s.length();i++){
if(i%2==0) if(i%2==0)
{ {
d+= s.substr(i-2,2) + " "; d+= s.substr(i-2,2) + " ";
} }
} }
d+=s.substr(s.length()-2,2); d+=s.substr(s.length()-2,2);
return(d); return(d);
} }
uint32_t endian_swap(uint32_t x) uint32_t endian_swap(uint32_t x)
@ -39,57 +39,65 @@ uint32_t endian_swap(uint32_t x)
((x<<8) & 0x00FF0000) | ((x<<8) & 0x00FF0000) |
((x>>8) & 0x0000FF00) | ((x>>8) & 0x0000FF00) |
(x<<24); (x<<24);
return x; return x;
} }
int main (void) int main (void)
{ {
DFHack::API DF ("Memory.xml"); 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; return 1;
} }
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords; vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
if(!DF.InitReadNameTables(englishWords,foreignWords)) if(!DF.InitReadNameTables(englishWords,foreignWords))
{ {
cerr << "Could not get Names" << endl; cerr << "Could not get Names" << endl;
return 1; return 1;
} }
string input; string input;
DF.ForceResume(); DF.ForceResume();
cout << "\nSelect Name to search or q to Quit" << endl; cout << "\nSelect Name to search or q to Quit" << endl;
getline (cin, input); getline (cin, input);
while(input != "q"){ while(input != "q"){
for( uint32_t i = 0; i < englishWords.size();i++){ for( uint32_t i = 0; i < englishWords.size();i++){
for( uint32_t j = 0;j < englishWords[i].size();j++){ for( uint32_t j = 0;j < englishWords[i].size();j++){
if(englishWords[i][j] != ""){ if(englishWords[i][j] != ""){
uint32_t found = tolower(input).find(tolower(englishWords[i][j])); uint32_t found = tolower(input).find(tolower(englishWords[i][j]));
if(found != string::npos){ if(found != string::npos){
stringstream value; stringstream value;
value << setfill('0') << setw(8) << hex << endian_swap(j); value << setfill('0') << setw(8) << hex << endian_swap(j);
cout << englishWords[i][j] << " " << groupBy2(value.str()) << endl; cout << englishWords[i][j] << " " << groupBy2(value.str()) << endl;
} }
} }
} }
} }
for( uint32_t i = 0; i < foreignWords.size();i++){ for( uint32_t i = 0; i < foreignWords.size();i++){
for( uint32_t j = 0;j < foreignWords[i].size();j++){ for( uint32_t j = 0;j < foreignWords[i].size();j++){
uint32_t found = tolower(input).find(tolower(foreignWords[i][j])); uint32_t found = tolower(input).find(tolower(foreignWords[i][j]));
if(found != string::npos){ if(found != string::npos){
stringstream value; stringstream value;
value << setfill('0') << setw(8) << hex << endian_swap(j); value << setfill('0') << setw(8) << hex << endian_swap(j);
cout << foreignWords[i][j] << " " << groupBy2(value.str()) << endl; cout << foreignWords[i][j] << " " << groupBy2(value.str()) << endl;
} }
} }
} }
DF.Resume(); DF.Resume();
getline(cin,input); getline(cin,input);
} }
DF.Detach(); DF.Detach();
DF.FinishReadNameTables(); DF.FinishReadNameTables();
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();

@ -15,9 +15,16 @@ int main (void)
{ {
vector<DFHack::t_matgloss> creaturestypes; vector<DFHack::t_matgloss> creaturestypes;
DFHack::API DF("Memory.xml"); 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; return 1;
} }

@ -11,11 +11,19 @@ using namespace std;
int main (void) int main (void)
{ {
DFHack::API DF("Memory.xml"); 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; return 1;
} }
vector <DFHack::t_matgloss> Woods; vector <DFHack::t_matgloss> Woods;
DF.ReadWoodMatgloss(Woods); DF.ReadWoodMatgloss(Woods);

@ -13,44 +13,51 @@ using namespace std;
int main (void) int main (void)
{ {
DFHack::API DF("Memory.xml"); 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;
}
if (DF.InitViewAndCursor())
{
int32_t x,y,z;
if(DF.getViewCoords(x,y,z))
cout << "view coords: " << x << "/" << y << "/" << z << endl;
if(DF.getCursorCoords(x,y,z))
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
} }
else else
{ {
if (DF.InitViewAndCursor()) cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
{ }
int32_t x,y,z;
if(DF.getViewCoords(x,y,z)) if(DF.InitViewSize())
cout << "view coords: " << x << "/" << y << "/" << z << endl; {
if(DF.getCursorCoords(x,y,z)) int32_t width,height;
cout << "cursor coords: " << x << "/" << y << "/" << z << endl; if(DF.getWindowSize(width,height))
} cout << "window size : " << width << " " << height << endl;
else }
{ else
cerr << "cursor and window parameters are unsupported on your version of DF" << endl; {
} cerr << "view size is unsupported on your version of DF" << endl;
}
if(DF.InitViewSize())
{ if(!DF.Detach())
int32_t width,height; {
if(DF.getWindowSize(width,height)) cerr << "Can't detach from DF" << endl;
cout << "window size : " << width << " " << height << endl;
}
else
{
cerr << "view size is unsupported on your version of DF" << endl;
}
if(!DF.Detach())
{
cerr << "Can't detach from DF" << endl;
}
} }
#ifndef LINUX_BUILD #ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl; cout << "Done. Press any key to continue" << endl;
cin.ignore(); cin.ignore();
#endif #endif
return 0; return 0;
} }

@ -24,10 +24,12 @@ void print_bits ( T val, std::ostream& out )
val >>= 1; val >>= 1;
} }
} }
vector< vector<string> > englishWords; vector< vector<string> > englishWords;
vector< vector<string> > foreignWords; vector< vector<string> > foreignWords;
uint32_t numCreatures; uint32_t numCreatures;
vector<DFHack::t_matgloss> creaturestypes; vector<DFHack::t_matgloss> creaturestypes;
void printDwarves(DFHack::API & DF) void printDwarves(DFHack::API & DF)
{ {
int dwarfCounter = 0; int dwarfCounter = 0;
@ -311,13 +313,19 @@ bool setCursorToCreature(DFHack::API &DF)
int main (void) int main (void)
{ {
DFHack::API DF("Memory.xml"); 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; return 1;
} }
DF.Suspend();
DFHack::memory_info * mem = DF.getMemoryInfo(); DFHack::memory_info * mem = DF.getMemoryInfo();
if (!DF.ReadCreatureMatgloss(creaturestypes)) if (!DF.ReadCreatureMatgloss(creaturestypes))

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

@ -15,11 +15,19 @@ int main (void)
{ {
string blah; string blah;
DFHack::API DF("Memory.xml"); 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; return 1;
} }
cout << "Attached, DF should be suspended now" << endl; cout << "Attached, DF should be suspended now" << endl;
getline(cin, blah); getline(cin, blah);

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

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

@ -268,7 +268,9 @@ bool API::InitMap()
uint32_t x_array_loc = g_pProcess->readDWord (map_offset); uint32_t x_array_loc = g_pProcess->readDWord (map_offset);
if (!x_array_loc) 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 // get the size

@ -15,13 +15,30 @@ int main (void)
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
DFHack::occupancies40d occupancies; DFHack::occupancies40d occupancies;
DFHack::API DF ("Memory.xml"); 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; 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); DF.getSize(x_max,y_max,z_max);
// walk the map // walk the map

@ -41,14 +41,19 @@ int main ()
int items; int items;
int found = 0, converted = 0; int found = 0, converted = 0;
DFHack::API DF ("Memory.xml"); 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; return 1;
} }
DF.Suspend();
// Find out which material is bauxite // Find out which material is bauxite
if(!DF.ReadStoneMatgloss(stoneMat)) if(!DF.ReadStoneMatgloss(stoneMat))

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

@ -100,9 +100,16 @@ int main (void)
{ {
string select; string select;
DFHack::API DF("Memory.xml"); 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; return 1;
} }
DFHack::Process * p = DF.getProcess(); DFHack::Process * p = DF.getProcess();

@ -194,9 +194,16 @@ int main ()
<< "Like set on fire all MICROCLINE item_stone..." << endl << "Like set on fire all MICROCLINE item_stone..." << endl
<< "Some unusual combinations might be untested and cause the program to crash..."<< endl << "Some unusual combinations might be untested and cause the program to crash..."<< endl
<< "so, watch your step and backup your fort" << 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; return 1;
} }
DFHack::memory_info *mem = DF.getMemoryInfo(); DFHack::memory_info *mem = DF.getMemoryInfo();

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

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

@ -14,12 +14,29 @@ int main (void)
DFHack::designations40d designations; DFHack::designations40d designations;
DFHack::API DF("Memory.xml"); 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; 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); DF.getSize(x_max,y_max,z_max);
// walk the map // walk the map