From 4a83f07bddf97c178942d3cae1a25f4268e072fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 7 Apr 2011 11:21:38 +0200 Subject: [PATCH] dftry pseudo-tool, dfhack can recognize 40d again, but the old API class isn't there at all. bees and wax. --- Memory.xml | 66 ++++++++++++++++ README.rst | 3 + Readme.html | 5 +- tools/playground/CMakeLists.txt | 3 + tools/playground/dftry.cpp | 133 ++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+), 1 deletion(-) create mode 100644 tools/playground/dftry.cpp diff --git a/Memory.xml b/Memory.xml index 0d38e6db4..30a38f35b 100644 --- a/Memory.xml +++ b/Memory.xml @@ -1,5 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -146,6 +209,8 @@ + + @@ -487,6 +552,7 @@ + diff --git a/README.rst b/README.rst index a414cd5b6..849262523 100644 --- a/README.rst +++ b/README.rst @@ -132,6 +132,9 @@ Can be used to determine tile properties like temperature. dfprospector ============ Lists all available minerals on the map and how much of them there is. +It has two parameters: +-a processes all tiles, even hidden ones. +-b includes layer rocks into the count. dfreveal ======== diff --git a/Readme.html b/Readme.html index 8e38f6c53..7db99e961 100644 --- a/Readme.html +++ b/Readme.html @@ -471,7 +471,10 @@ You just lost a fortress and gained an adventurer.

dfprospector

-

Lists all available minerals on the map and how much of them there is.

+

Lists all available minerals on the map and how much of them there is. +It has two parameters: +-a processes all tiles, even hidden ones. +-b includes layer rocks into the count.

dfreveal

diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index 029815d66..b44cb9c9b 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -47,6 +47,9 @@ DFHACK_TOOL(dfdigger2 digger2.cpp) # Author: belal DFHACK_TOOL(dffindnameindexes findnameindexes.cpp) +# try things +DFHACK_TOOL(dftry dftry.cpp) + # renamer - change the custom names and professions of creatures, sends keys to # df directly # Author: belal diff --git a/tools/playground/dftry.cpp b/tools/playground/dftry.cpp new file mode 100644 index 000000000..98ae5a288 --- /dev/null +++ b/tools/playground/dftry.cpp @@ -0,0 +1,133 @@ +#include +#include +#include +#include + +using namespace std; + +bool getNumber (string prompt, int & output, int def, bool pdef = true) +{ + cout << prompt; + if(pdef) + cout << ", default=" << def << endl; + while (1) + { + string select; + cout << ">>"; + std::getline(cin, select); + if(select.empty()) + { + output = def; + break; + } + else if( sscanf(select.c_str(), "%d", &output) == 1 ) + { + break; + } + else + { + continue; + } + } + return true; +} + +bool splitvector(const vector & in, vector & out1, vector & out2) +{ + size_t length = in.size(); + if(length > 1) + { + size_t split = length / 2; + out1.clear(); + out2.clear(); + out1.insert(out1.begin(),in.begin(),in.begin() + split); + out2.insert(out2.begin(),in.begin() + split,in.end()); + return true; + } + return false; +} +void printvector (const vector &in) +{ + cout << "[" << endl; + for(int i = 0; i < in.size(); i++) + { + cout << hex << in[i] << endl; + } + cout << "]" << endl; +} + +bool tryvals (DFHack::Context * DF, const vector &in, uint8_t current, uint8_t testing) +{ + DF->Suspend(); + DFHack::Process * p = DF->getProcess(); + for(int i = 0; i < in.size(); i++) + { + p->writeByte(in[i],testing); + } + DF->Resume(); + int result; + while (!getNumber("Is the change good? 0 for no, positive for yes.",result,0)); + DF->Suspend(); + for(int i = 0; i < in.size(); i++) + { + p->writeByte(in[i],current); + } + DF->Resume(); + if(result) + return true; + return false; +} + +bool dotry (DFHack::Context * DF, const vector &in, uint8_t current, uint8_t testing) +{ + vector a, b; + bool found = false; + if(!tryvals(DF,in,current,testing)) + return false; + if(splitvector(in, a,b)) + { + if(dotry(DF, a, current, testing)) + return true; + if(dotry(DF, b, current, testing)) + return true; + return false; + } + return false; +} + +int main() +{ + vector addresses; + vector a1; + vector a2; + vector values; + string line; + + DFHack::ContextManager CM("Memory.xml"); + DFHack::Context * DF = CM.getSingleContext(); + if(!DF) + return 1; + DF->Resume(); + + ifstream fin("siege.txt"); + if(!fin.is_open()) + return 1; + do + { + getline(fin,line); + stringstream input (line); + input << hex; + uint64_t value; + input >> value; + if(value) + { + cout << hex << value << endl; + addresses.push_back(value); + } + } while (!fin.eof()); + int val_current,val_testing; + while (!getNumber("Insert current value",val_current,1)); + while (!getNumber("Insert testing value",val_testing,0)); + dotry(DF, addresses,val_current,val_testing); + return 0; +} \ No newline at end of file