diff --git a/examples/attachtest.cpp b/examples/attachtest.cpp index 5ead5a7a0..440bbfc5a 100644 --- a/examples/attachtest.cpp +++ b/examples/attachtest.cpp @@ -1,5 +1,5 @@ // Attach test -// attachtest - 100x attach/detach, 100x reads, 100x writes +// attachtest - 1000x suspend/resume #include #include @@ -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; } /* @@ -79,8 +82,8 @@ int main (void) cout << "suspend tests done in " << time_diff << " seconds." << endl; #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); + cout << "Done. Press any key to continue" << endl; + cin.ignore(); #endif return 0; } diff --git a/examples/buildingsdump.cpp b/examples/buildingsdump.cpp index 2b12bac52..4c4a0dc35 100644 --- a/examples/buildingsdump.cpp +++ b/examples/buildingsdump.cpp @@ -8,18 +8,10 @@ #include using namespace std; +#include #include #include #include -/* -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 creaturestypes; 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; } DFHack::memory_info * mem = DF.getMemoryInfo(); @@ -173,9 +172,9 @@ int main (int argc,const char* argv[]) } DF.Detach(); -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif return 0; } diff --git a/examples/catsplosion.cpp b/examples/catsplosion.cpp index 89bb2a15b..f99effb50 100644 --- a/examples/catsplosion.cpp +++ b/examples/catsplosion.cpp @@ -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 #include @@ -9,6 +10,7 @@ #include // for rand() using namespace std; +#include #include #include #include @@ -22,42 +24,54 @@ uint32_t creature_pregnancy_offset; int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature) { - if(string(creaturestypes[creature.type].id) == "CAT") - { - proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1); - return 1; + if(string(creaturestypes[creature.type].id) == "CAT") + { + proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1); + return 1; } - return 0; + return 0; } int main (void) { 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; - } - + } proc = DF.getProcess(); mem = DF.getMemoryInfo(); - creature_pregnancy_offset = mem->getOffset("creature_pregnancy"); + creature_pregnancy_offset = mem->getOffset("creature_pregnancy"); if(!DF.ReadCreatureMatgloss(creaturestypes)) { cerr << "Can't get the creature types." << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif return 1; } - + uint32_t numCreatures; if(!DF.InitReadCreatures(numCreatures)) { cerr << "Can't get creatures" << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif return 1; } - int cats=0; + int cats=0; for(uint32_t i = 0; i < numCreatures; i++) { @@ -66,13 +80,13 @@ int main (void) cats+=fertilizeCat(DF,temp); } - cout << cats << " cats impregnated." << endl; + cout << cats << " cats impregnated." << endl; DF.FinishReadCreatures(); DF.Detach(); #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); + cout << "Done. Press any key to continue" << endl; + cin.ignore(); #endif return 0; } diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index fabc6ee87..723599854 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -6,6 +6,7 @@ #include using namespace std; +#include #include #include #include @@ -152,7 +153,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) { 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; if(creature.name.first_name[0]) { @@ -213,11 +214,11 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) cout <<"Male"; } cout << endl; - - if(creature.pregnancy_timer > 0) - cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. "; - cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate; - cout << endl; + + if(creature.pregnancy_timer > 0) + cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. "; + cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate; + cout << endl; /* //skills @@ -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 + { + DF.Attach(); + } + catch (exception& e) { - cerr << "DF not found" << endl; + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif return 1; } diff --git a/examples/dfitemdump.cpp b/examples/dfitemdump.cpp index 777a62bb7..919eb4940 100644 --- a/examples/dfitemdump.cpp +++ b/examples/dfitemdump.cpp @@ -8,6 +8,7 @@ #include using namespace std; +#include #include #include #include @@ -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 { - 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(); DF.InitViewAndCursor(); matGlosses mat; @@ -280,11 +287,10 @@ int main () } DF.FinishReadItems(); } - DF.FinishReadBuildings(); DF.Detach(); -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif return 0; } diff --git a/examples/expbench.cpp b/examples/expbench.cpp index 272e46021..7d674098b 100644 --- a/examples/expbench.cpp +++ b/examples/expbench.cpp @@ -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; } diff --git a/examples/findnameindexes.cpp b/examples/findnameindexes.cpp index 48ad255bd..5dfbeaf0d 100644 --- a/examples/findnameindexes.cpp +++ b/examples/findnameindexes.cpp @@ -15,22 +15,22 @@ using namespace std; // returns a lower case version of the string string tolower (const string & s) { - string d (s); + string d (s); - transform (d.begin (), d.end (), d.begin (), (int(*)(int)) tolower); - return d; + transform (d.begin (), d.end (), d.begin (), (int(*)(int)) tolower); + return d; } string groupBy2(const string & s) { - string d; - for(int i =2;i>8) & 0x0000FF00) | (x<<24); - return x; + return x; } int main (void) { - 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; } - vector< vector > englishWords; - vector< vector > foreignWords; + + vector< vector > englishWords; + vector< vector > foreignWords; if(!DF.InitReadNameTables(englishWords,foreignWords)) - { - cerr << "Could not get Names" << endl; - return 1; - } - string input; - DF.ForceResume(); + { + cerr << "Could not get Names" << endl; + return 1; + } + string input; + DF.ForceResume(); cout << "\nSelect Name to search or q to Quit" << endl; getline (cin, input); - while(input != "q"){ + while(input != "q"){ for( uint32_t i = 0; i < englishWords.size();i++){ for( uint32_t j = 0;j < englishWords[i].size();j++){ if(englishWords[i][j] != ""){ - uint32_t found = tolower(input).find(tolower(englishWords[i][j])); - if(found != string::npos){ - stringstream value; - value << setfill('0') << setw(8) << hex << endian_swap(j); - cout << englishWords[i][j] << " " << groupBy2(value.str()) << endl; + uint32_t found = tolower(input).find(tolower(englishWords[i][j])); + if(found != string::npos){ + stringstream value; + value << setfill('0') << setw(8) << hex << endian_swap(j); + cout << englishWords[i][j] << " " << groupBy2(value.str()) << endl; } - } - } - } + } + } + } for( uint32_t i = 0; i < foreignWords.size();i++){ for( uint32_t j = 0;j < foreignWords[i].size();j++){ - uint32_t found = tolower(input).find(tolower(foreignWords[i][j])); - if(found != string::npos){ - stringstream value; - value << setfill('0') << setw(8) << hex << endian_swap(j); - cout << foreignWords[i][j] << " " << groupBy2(value.str()) << endl; - } - } - } - DF.Resume(); - getline(cin,input); - } + uint32_t found = tolower(input).find(tolower(foreignWords[i][j])); + if(found != string::npos){ + stringstream value; + value << setfill('0') << setw(8) << hex << endian_swap(j); + cout << foreignWords[i][j] << " " << groupBy2(value.str()) << endl; + } + } + } + DF.Resume(); + getline(cin,input); + } DF.Detach(); - DF.FinishReadNameTables(); + DF.FinishReadNameTables(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/examples/hotkeynotedump.cpp b/examples/hotkeynotedump.cpp index 50e695c07..c23f38d8a 100644 --- a/examples/hotkeynotedump.cpp +++ b/examples/hotkeynotedump.cpp @@ -15,9 +15,16 @@ int main (void) { vector 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; } diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index a4d5ac474..d28fb8e64 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -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 Woods; DF.ReadWoodMatgloss(Woods); diff --git a/examples/position.cpp b/examples/position.cpp index a298cccc0..05bcc4b87 100644 --- a/examples/position.cpp +++ b/examples/position.cpp @@ -13,44 +13,51 @@ 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; + } + + 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 { - 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 - { - cerr << "cursor and window parameters are unsupported on your version of DF" << endl; - } - - if(DF.InitViewSize()) - { - int32_t width,height; - if(DF.getWindowSize(width,height)) - 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; - } + cerr << "cursor and window parameters are unsupported on your version of DF" << endl; + } + + if(DF.InitViewSize()) + { + int32_t width,height; + if(DF.getWindowSize(width,height)) + 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 - cout << "Done. Press any key to continue" << endl; - cin.ignore(); + cout << "Done. Press any key to continue" << endl; + cin.ignore(); #endif return 0; } diff --git a/examples/renamer.cpp b/examples/renamer.cpp index 9a86cfbda..39e501489 100644 --- a/examples/renamer.cpp +++ b/examples/renamer.cpp @@ -24,10 +24,12 @@ void print_bits ( T val, std::ostream& out ) val >>= 1; } } + vector< vector > englishWords; vector< vector > foreignWords; uint32_t numCreatures; vector creaturestypes; + void printDwarves(DFHack::API & DF) { int dwarfCounter = 0; @@ -311,13 +313,19 @@ bool setCursorToCreature(DFHack::API &DF) int main (void) { 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.Suspend(); - + DFHack::memory_info * mem = DF.getMemoryInfo(); if (!DF.ReadCreatureMatgloss(creaturestypes)) diff --git a/examples/settlementdump.cpp b/examples/settlementdump.cpp index 95aa018b0..fdabed6c9 100644 --- a/examples/settlementdump.cpp +++ b/examples/settlementdump.cpp @@ -31,43 +31,55 @@ 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)) { - cerr << "Could not read Settlements" << endl; - return 1; - } - vector< vector > englishWords; - vector< vector > foreignWords; + cerr << "Could not read Settlements" << endl; + return 1; + } + + vector< vector > englishWords; + vector< vector > foreignWords; if(!DF.InitReadNameTables(englishWords,foreignWords)) { cerr << "Can't get name tables" << endl; return 1; } - cout << "Settlements\n"; - /*for(uint32_t i =0;i> std::hex >> addr; } 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(); - DFHack::memory_info* mem = DF.getMemoryInfo(); - const vector * 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; + 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 * 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 cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 549037abd..c39dc2b65 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -307,15 +307,19 @@ main(int argc, char *argv[]) vector< vector > layerassign; vector veinVector; vector IceVeinVector; - - // init the API + DFHack::API DF("Memory.xml"); - pDF = &DF; - // attach - if(!DF.Attach()) + try { - error = "Can't find DF."; - pDF = 0; + DF.Attach(); + pDF = &DF; + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif finish(0); } diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 3b9dafa1a..de0fc3c79 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -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 diff --git a/tools/cleanmap.cpp b/tools/cleanmap.cpp index 5b057ce9a..aca7fc183 100644 --- a/tools/cleanmap.cpp +++ b/tools/cleanmap.cpp @@ -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 diff --git a/tools/dfbauxite.cpp b/tools/dfbauxite.cpp index 9d57c4b91..93a644638 100644 --- a/tools/dfbauxite.cpp +++ b/tools/dfbauxite.cpp @@ -41,14 +41,19 @@ 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)) diff --git a/tools/digger.cpp b/tools/digger.cpp index c347e38dd..d23595c76 100644 --- a/tools/digger.cpp +++ b/tools/digger.cpp @@ -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,31 +327,36 @@ int main (int argc, char** argv) else { DFHack::API DF("Memory.xml"); - if(DF.Attach()) + try { - if (DF.InitMap()) - { - int count = dig(DF, targets, 10, origin[0],origin[1],origin[2], verbose); - cout << count << " targets designated" << endl; + 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, max, origin[0],origin[1],origin[2], verbose); + cout << count << " targets designated" << endl; - if (!DF.Detach()) - { - cerr << "Unable to detach DF process" << endl; - } - } - else + if (!DF.Detach()) { - cerr << "Unable to init map" << endl; + cerr << "Unable to detach DF process" << endl; } } else - { - cerr << "Unable to attach to DF process" << endl; + { + cerr << "Unable to init map" << endl; } } -#ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); -#endif + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif return 0; } diff --git a/tools/incrementalsearch.cpp b/tools/incrementalsearch.cpp index 4b48d6535..50cadefb4 100644 --- a/tools/incrementalsearch.cpp +++ b/tools/incrementalsearch.cpp @@ -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(); diff --git a/tools/itemdesignator.cpp b/tools/itemdesignator.cpp index 50ea365fd..ad51ea00c 100644 --- a/tools/itemdesignator.cpp +++ b/tools/itemdesignator.cpp @@ -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(); diff --git a/tools/magma_create.cpp b/tools/magma_create.cpp index fd64b44dd..d0b40154d 100644 --- a/tools/magma_create.cpp +++ b/tools/magma_create.cpp @@ -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()) diff --git a/tools/prospector.cpp b/tools/prospector.cpp index ec037db4e..d07a7ae23 100644 --- a/tools/prospector.cpp +++ b/tools/prospector.cpp @@ -54,18 +54,29 @@ int main (int argc, const char* argv[]) vector stonetypes; vector< vector > 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; } @@ -172,8 +189,8 @@ int main (int argc, const char* argv[]) } DF.Detach(); #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); + cout << "Done. Press any key to continue" << endl; + cin.ignore(); #endif return 0; } diff --git a/tools/reveal.cpp b/tools/reveal.cpp index 48f3302a3..654252e32 100644 --- a/tools/reveal.cpp +++ b/tools/reveal.cpp @@ -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