From f3826abc0c0d91e69518f1372353fe37d970d250 Mon Sep 17 00:00:00 2001 From: PeridexisErrant Date: Mon, 15 Dec 2014 23:11:23 +1100 Subject: [PATCH] cleaning up in needs_porting Removed obsolete plugins. Started hotkeys port. Mostly-finished position port. Corrected dwarfmonitor date display. Documented putontable.lua in readme. --- NEWS | 5 + Readme.rst | 10 + needs_porting/SegmentedFinder.h | 543 -------------- needs_porting/_notes.txt | 43 +- needs_porting/digpattern.cpp | 259 ------- needs_porting/hotkey-notes.lua | 40 + needs_porting/hotkeynotedump.py | 20 - needs_porting/incrementalsearch.cpp | 1064 --------------------------- needs_porting/position.py | 71 -- plugins/dwarfmonitor.cpp | 6 +- scripts/position.lua | 40 + 11 files changed, 111 insertions(+), 1990 deletions(-) delete mode 100644 needs_porting/SegmentedFinder.h delete mode 100644 needs_porting/digpattern.cpp create mode 100644 needs_porting/hotkey-notes.lua delete mode 100644 needs_porting/hotkeynotedump.py delete mode 100644 needs_porting/incrementalsearch.cpp delete mode 100644 needs_porting/position.py create mode 100644 scripts/position.lua diff --git a/NEWS b/NEWS index 1b9ec3f8b..a05e75465 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,14 @@ DFHack Future Internals Fixes + plugins/dwarfmonitor: correct date display (month index, separator) + scripts/putontable: added to the readme New Plugins New Scripts + position: Reports the current date, time, month, and season, plus + some location info. Port/update of position.py Misc Improvements + further work on needs_porting DFHack 0.40.19-r1 Internals: diff --git a/Readme.rst b/Readme.rst index 15933e0f6..52c966742 100644 --- a/Readme.rst +++ b/Readme.rst @@ -2399,6 +2399,16 @@ Example:: multicmd locate-ore iron ; digv +position +======== +Reports the current date, time, month, and season. Location reporting is a +work in progress. + +putontable +========== +Makes item appear on the table, like in adventure mode shops. Arguments: '-a' +or '--all' for all items. + quicksave ========= diff --git a/needs_porting/SegmentedFinder.h b/needs_porting/SegmentedFinder.h deleted file mode 100644 index b3fe5aecf..000000000 --- a/needs_porting/SegmentedFinder.h +++ /dev/null @@ -1,543 +0,0 @@ -#ifndef SEGMENTED_FINDER_H -#define SEGMENTED_FINDER_H -#include -#include -#include - -class SegmentedFinder; -class SegmentFinder -{ - public: - SegmentFinder(DFHack::t_memrange & mr, DFHack::Context * DF, SegmentedFinder * SF) - { - _DF = DF; - mr_ = mr; - valid=false; - if(mr.valid) - { - mr_.buffer = (uint8_t *)malloc (mr_.end - mr_.start); - _SF = SF; - try - { - DF->ReadRaw(mr_.start,(mr_.end - mr_.start),mr_.buffer); - valid = true; - } - catch (DFHack::Error::MemoryAccessDenied &) - { - free(mr_.buffer); - valid = false; - mr.valid = false; // mark the range passed in as bad - cout << "Range 0x" << hex << mr_.start << " - 0x" << mr_.end; - - if (strlen(mr_.name) != 0) - cout << " (" << mr_.name << ")"; - - cout << dec << " not readable." << endl; - cout << "Skipping this range on future scans." << endl; - } - } - } - ~SegmentFinder() - { - if(valid) - free(mr_.buffer); - } - bool isValid() - { - return valid; - } - template - bool Find (needleType needle, const uint8_t increment , vector &newfound, comparator oper) - { - if(!valid) return !newfound.empty(); - //loop - for(uint64_t offset = 0; offset < (mr_.end - mr_.start) - sizeof(hayType); offset += increment) - { - if( oper(_SF,(hayType *)(mr_.buffer + offset), needle) ) - newfound.push_back(mr_.start + offset); - } - return !newfound.empty(); - } - - template < class needleType, class hayType, typename comparator > - uint64_t FindInRange (needleType needle, comparator oper, uint64_t start, uint64_t length) - { - if(!valid) return 0; - uint64_t stopper = min((mr_.end - mr_.start) - sizeof(hayType), (start - mr_.start) - sizeof(hayType) + length); - //loop - for(uint64_t offset = start - mr_.start; offset < stopper; offset +=1) - { - if( oper(_SF,(hayType *)(mr_.buffer + offset), needle) ) - return mr_.start + offset; - } - return 0; - } - - template - bool Filter (needleType needle, vector &found, vector &newfound, comparator oper) - { - if(!valid) return !newfound.empty(); - for( uint64_t i = 0; i < found.size(); i++) - { - if(mr_.isInRange(found[i])) - { - uint64_t corrected = found[i] - mr_.start; - if( oper(_SF,(hayType *)(mr_.buffer + corrected), needle) ) - newfound.push_back(found[i]); - } - } - return !newfound.empty(); - } - private: - friend class SegmentedFinder; - SegmentedFinder * _SF; - DFHack::Context * _DF; - DFHack::t_memrange mr_; - bool valid; -}; - -class SegmentedFinder -{ - public: - SegmentedFinder(vector & ranges, DFHack::Context * DF) - { - _DF = DF; - for(size_t i = 0; i < ranges.size(); i++) - { - segments.push_back(new SegmentFinder(ranges[i], DF, this)); - } - } - ~SegmentedFinder() - { - for(size_t i = 0; i < segments.size(); i++) - { - delete segments[i]; - } - } - SegmentFinder * getSegmentForAddress (uint64_t addr) - { - for(size_t i = 0; i < segments.size(); i++) - { - if(segments[i]->mr_.isInRange(addr)) - { - return segments[i]; - } - } - return 0; - } - template - bool Find (const needleType needle, const uint8_t increment, vector &found, comparator oper) - { - found.clear(); - for(size_t i = 0; i < segments.size(); i++) - { - segments[i]->Find(needle, increment, found, oper); - } - return !(found.empty()); - } - - template < class needleType, class hayType, typename comparator > - uint64_t FindInRange (needleType needle, comparator oper, uint64_t start, uint64_t length) - { - SegmentFinder * sf = getSegmentForAddress(start); - if(sf) - { - return sf->FindInRange(needle, oper, start, length); - } - return 0; - } - - template - bool Filter (const needleType needle, vector &found, comparator oper) - { - vector newfound; - for(size_t i = 0; i < segments.size(); i++) - { - segments[i]->Filter(needle, found, newfound, oper); - } - found.clear(); - found = newfound; - return !(found.empty()); - } - - template - bool Incremental (needleType needle, const uint8_t increment ,vector &found, comparator oper) - { - if(found.empty()) - { - return Find (needle,increment,found,oper); - } - else - { - return Filter (needle,found,oper); - } - } - - template - T * Translate(uint64_t address) - { - for(size_t i = 0; i < segments.size(); i++) - { - if(segments[i]->mr_.isInRange(address)) - { - return (T *) (segments[i]->mr_.buffer + address - segments[i]->mr_.start); - } - } - return 0; - } - - template - T Read(uint64_t address) - { - return *Translate(address); - } - - template - bool Read(uint64_t address, T& target) - { - T * test = Translate(address); - if(test) - { - target = *test; - return true; - } - return false; - } - private: - DFHack::Context * _DF; - vector segments; -}; - -template -bool equalityP (SegmentedFinder* s, T *x, T y) -{ - return (*x) == y; -} - -struct vecTriplet -{ - uint32_t start; - uint32_t finish; - uint32_t alloc_finish; -}; - -template -bool vectorLength (SegmentedFinder* s, vecTriplet *x, Needle &y) -{ - if(x->start <= x->finish && x->finish <= x->alloc_finish) - if((x->finish - x->start) == y) - return true; - return false; -} - -// find a vector of 32bit pointers, where an object pointed to has a string 'y' as the first member -bool vectorString (SegmentedFinder* s, vecTriplet *x, const char *y) -{ - uint32_t object_ptr; - // iterate over vector of pointers - for(uint32_t idx = x->start; idx < x->finish; idx += sizeof(uint32_t)) - { - // deref ptr idx, get ptr to object - if(!s->Read(idx,object_ptr)) - { - return false; - } - // deref ptr to first object, get ptr to string - uint32_t string_ptr; - if(!s->Read(object_ptr,string_ptr)) - return false; - // get string location in our local cache - char * str = s->Translate(string_ptr); - if(!str) - return false; - if(strcmp(y, str) == 0) - return true; - } - return false; -} - -// find a vector of 32bit pointers, where the first object pointed to has a string 'y' as the first member -bool vectorStringFirst (SegmentedFinder* s, vecTriplet *x, const char *y) -{ - uint32_t object_ptr; - uint32_t idx = x->start; - // deref ptr idx, get ptr to object - if(!s->Read(idx,object_ptr)) - { - return false; - } - // deref ptr to first object, get ptr to string - uint32_t string_ptr; - if(!s->Read(object_ptr,string_ptr)) - return false; - // get string location in our local cache - char * str = s->Translate(string_ptr); - if(!str) - return false; - if(strcmp(y, str) == 0) - return true; - return false; -} - -// test if the address is between vector.start and vector.finish -// not very useful alone, but could be a good step to filter some things -bool vectorAddrWithin (SegmentedFinder* s, vecTriplet *x, uint32_t address) -{ - if(address < x->finish && address >= x->start) - return true; - return false; -} - -// test if an object address is within the vector of pointers -// -bool vectorOfPtrWithin (SegmentedFinder* s, vecTriplet *x, uint32_t address) -{ - uint32_t object_ptr; - for(uint32_t idx = x->start; idx < x->finish; idx += sizeof(uint32_t)) - { - if(!s->Read(idx,object_ptr)) - { - return false; - } - if(object_ptr == address) - return true; - } - return false; -} - -bool vectorAll (SegmentedFinder* s, vecTriplet *x, int ) -{ - if(x->start <= x->finish && x->finish <= x->alloc_finish) - { - if(s->getSegmentForAddress(x->start) == s->getSegmentForAddress(x->finish) - && s->getSegmentForAddress(x->finish) == s->getSegmentForAddress(x->alloc_finish)) - return true; - } - return false; -} - -class Bytestreamdata -{ - public: - void * object; - uint32_t length; - uint32_t allocated; - uint32_t n_used; -}; - -class Bytestream -{ -public: - Bytestream(void * obj, uint32_t len, bool alloc = false) - { - d = new Bytestreamdata(); - d->allocated = alloc; - d->object = obj; - d->length = len; - d->n_used = 1; - constant = false; - } - Bytestream() - { - d = new Bytestreamdata(); - d->allocated = false; - d->object = 0; - d->length = 0; - d->n_used = 1; - constant = false; - } - Bytestream( Bytestream & bs) - { - d =bs.d; - d->n_used++; - constant = false; - } - Bytestream( const Bytestream & bs) - { - d =bs.d; - d->n_used++; - constant = true; - } - ~Bytestream() - { - d->n_used --; - if(d->allocated && d->object && d->n_used == 0) - { - free (d->object); - free (d); - } - } - bool Allocate(size_t bytes) - { - if(constant) - return false; - if(d->allocated) - { - d->object = realloc(d->object, bytes); - } - else - { - d->object = malloc( bytes ); - } - - if(d->object) - { - d->allocated = bytes; - return true; - } - else - { - d->allocated = 0; - return false; - } - } - template < class T > - bool insert( T what ) - { - if(constant) - return false; - if(d->length+sizeof(T) >= d->allocated) - Allocate((d->length+sizeof(T)) * 2); - (*(T *)( (uint64_t)d->object + d->length)) = what; - d->length += sizeof(T); - return true; - } - Bytestreamdata * d; - bool constant; -}; -std::ostream& operator<< ( std::ostream& out, Bytestream& bs ) -{ - if(bs.d->object) - { - out << "bytestream " << dec << bs.d->length << "/" << bs.d->allocated << " bytes" << endl; - for(size_t i = 0; i < bs.d->length; i++) - { - out << hex << (int) ((uint8_t *) bs.d->object)[i] << " "; - } - out << endl; - } - else - { - out << "empty bytestresm" << endl; - } - return out; -} - -std::istream& operator>> ( std::istream& out, Bytestream& bs ) -{ - string read; - while(!out.eof()) - { - string tmp; - out >> tmp; - read.append(tmp); - } - cout << read << endl; - bs.d->length = 0; - size_t first = read.find_first_of("\""); - size_t last = read.find_last_of("\""); - size_t start = first + 1; - if(first == read.npos) - { - std::transform(read.begin(), read.end(), read.begin(), (int(*)(int)) tolower); - bs.Allocate(read.size()); // overkill. size / 2 should be good, but this is safe - int state = 0; - char big = 0; - char small = 0; - string::iterator it = read.begin(); - // iterate through string, construct a bytestream out of 00-FF bytes - while(it != read.end()) - { - char reads = *it; - if((reads >='0' && reads <= '9')) - { - if(state == 0) - { - big = reads - '0'; - state = 1; - } - else if(state == 1) - { - small = reads - '0'; - state = 0; - bs.insert(big*16 + small); - } - } - if((reads >= 'a' && reads <= 'f')) - { - if(state == 0) - { - big = reads - 'a' + 10; - state = 1; - } - else if(state == 1) - { - small = reads - 'a' + 10; - state = 0; - bs.insert(big*16 + small); - } - } - it++; - } - // we end in state= 1. should we add or should we trim... or throw errors? - // I decided on adding - if (state == 1) - { - small = 0; - bs.insert(big*16 + small); - } - } - else - { - if(last == first) - { - // only one " - last = read.size(); - } - size_t length = last - start; - // construct bytestream out of stuff between "" - bs.d->length = length; - if(length) - { - // todo: Bytestream should be able to handle this without external code - bs.Allocate(length); - bs.d->length = length; - const char* strstart = read.c_str(); - memcpy(bs.d->object, strstart + start, length); - } - else - { - bs.d->object = 0; - } - } - cout << bs; - return out; -} - -bool findBytestream (SegmentedFinder* s, void *addr, Bytestream compare ) -{ - if(memcmp(addr, compare.d->object, compare.d->length) == 0) - return true; - return false; -} - -bool findString (SegmentedFinder* s, uint32_t *addr, const char * compare ) -{ - // read string pointer, translate to local scheme - char *str = s->Translate(*addr); - // verify - if(!str) - return false; - if(strcmp(str, compare) == 0) - return true; - return false; -} - -bool findStrBuffer (SegmentedFinder* s, uint32_t *addr, const char * compare ) -{ - if(memcmp((const char *)addr, compare, strlen(compare)) == 0) - return true; - return false; -} - -#endif // SEGMENTED_FINDER_H diff --git a/needs_porting/_notes.txt b/needs_porting/_notes.txt index 041e0932d..35a7ef5bf 100644 --- a/needs_porting/_notes.txt +++ b/needs_porting/_notes.txt @@ -1,30 +1,13 @@ -Notes by PeridexisErrant, on the needs_porting scripts and plugins: - -I deleted: - attachtest.py obsolete - digger.cpp less useful than digger2, replaced by autochop - digger2.cpp replaced by digfort - dfstatus.cpp replaced by dfstatus.lua - drawtile.cpp replaced by tiletypes - fix-3708.cpp obsolete, bug fixed in vanilla - lair.cpp replaced by lair - reveal.py replaced by reveal - treedump.py replaced by prospect & autochop - veinlook.cpp replaced by prospect - veinswap.cpp replaced by changevein - - -To investigate further: - creaturemanager.cpp modify skills and labors of creatures, kill creatures, etc; impressive but I suspect most functions implemented elsewhere - digpattern.cpp allows multi-Z designations. Obsolete, or is there more here? - incrementalsearch.cpp linux-only memory stuff; unqualified to judge - SegementedFinder.h more memory stuff - - -To port: - copypaste.cpp high value target - a proof of concept plugin to allow copy-pasting in DF; does both terrain and buildings/constructions - dfbauxtite.cpp changes material of mechanisms to bauxtite (ie magma-safe) - hellhole.cpp instantly creates a hole to the HFS - hotkeynotedump.py outputs a list of hotkeys and names; most useful before keybindings were possible. Trival to port but low value. - itemdesignator.cpp mostly replaced by Falconne's enhanced stocks, but could port the interesting 'set fire to things' function - position.py outputs very detailed time& place info +TODO: + copypaste.cpp + high value target - a proof of concept plugin to allow copy-pasting in DF; does both terrain and buildings/constructions + creaturemanager.cpp + modify skills and labors of creatures, kill creatures, etc; impressive but I suspect most functions implemented elsewhere + dfbauxtite.cpp + changes material of mechanisms to bauxtite (ie magma-safe) + hellhole.cpp + instantly creates a hole to the HFS + +In progress: + hotkey-notes.lua + prints list of hotkeys with name and jump position diff --git a/needs_porting/digpattern.cpp b/needs_porting/digpattern.cpp deleted file mode 100644 index 90d960ba1..000000000 --- a/needs_porting/digpattern.cpp +++ /dev/null @@ -1,259 +0,0 @@ -#include -#include // for memset -#include -#include -#include -#include -#include -#include -using namespace std; - -#include -#include -using namespace MapExtras; -//#include - -void usage(int argc, const char * argv[]) -{ - cout - << "Usage:" << endl - << argv[0] << " [option 1] [option 2] [...]" << endl - << "-q : Suppress \"Press any key to continue\" at program termination" << endl - << "-u : Dig upwards times (default 5)" << endl - << "-d : Dig downwards times (default 5)" << endl - ; -} - -void digat(MapCache * MCache, DFHack::DFCoord xy) -{ - int16_t tt; - tt = MCache->tiletypeAt(xy); - if(!DFHack::isWallTerrain(tt)) - return; - - // found a good tile, dig+unset material - DFHack::t_designation des = MCache->designationAt(xy); - - if(MCache->testCoord(xy)) - { - MCache->clearMaterialAt(xy); - - if(des.bits.dig == DFHack::designation_no) - des.bits.dig = DFHack::designation_default; - MCache->setDesignationAt(xy,des); - } -} - -int strtoint(const string &str) -{ - stringstream ss(str); - int result; - return ss >> result ? result : -1; -} - -typedef struct -{ - int16_t x; - int16_t y; -} pos; - -int main (int argc, const char* argv[]) -{ - // Command line options - bool updown = false; - bool quiet = true; - // let's be more useful when double-clicked on windows - #ifndef LINUX_BUILD - quiet = false; - #endif - int dig_up_n = 5; - int dig_down_n = 5; - - for(int i = 1; i < argc; i++) - { - string arg_cur = argv[i]; - string arg_next = ""; - int arg_next_int = -99999; - /* Check if argv[i+1] is a number >= 0 */ - if (i < argc-1) { - arg_next = argv[i+1]; - arg_next_int = strtoint(arg_next); - if (arg_next != "0" && arg_next_int == 0) { - arg_next_int = -99999; - } - } - if (arg_cur == "-x") - { - updown = true; - } - else if (arg_cur == "-q") - { - quiet = true; - } - else if(arg_cur == "-u" && i < argc-1) - { - if (arg_next_int < 0 || arg_next_int >= 99999) { - usage(argc, argv); - return 1; - } - dig_up_n = arg_next_int; - i++; - } - else if(arg_cur == "-d" && i < argc-1) - { - if (arg_next_int < 0 || arg_next_int >= 99999) { - usage(argc, argv); - return 1; - } - dig_down_n = arg_next_int; - i++; - } - else - { - usage(argc, argv); - return 1; - } - } - - DFHack::ContextManager DFMgr("Memory.xml"); - DFHack::Context * DF; - try - { - DF = DFMgr.getSingleContext(); - DF->Attach(); - } - catch (exception& e) - { - cerr << "Error getting context: " << e.what() << endl; - if (!quiet) - cin.ignore(); - - return 1; - } - - uint32_t x_max,y_max,z_max; - DFHack::Maps * Maps = DF->getMaps(); - DFHack::Gui * Gui = DF->getGui(); - - // init the map - if(!Maps->Start()) - { - cerr << "Can't init map. Make sure you have a map loaded in DF." << endl; - DF->Detach(); - if (!quiet) - cin.ignore(); - - return 1; - } - - int32_t cx, cy, cz; - Maps->getSize(x_max,y_max,z_max); - uint32_t tx_max = x_max * 16; - uint32_t ty_max = y_max * 16; - - Gui->getCursorCoords(cx,cy,cz); - if (cx == -30000) - { - cerr << "Cursor is not active. Point the cursor at the position to dig at." << endl; - DF->Detach(); - if (!quiet) - { - cin.ignore(); - } - return 1; - } - - DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); - if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1) - { - cerr << "I won't dig the borders. That would be cheating!" << endl; - DF->Detach(); - if (!quiet) - { - cin.ignore(); - } - return 1; - } - MapCache * MCache = new MapCache(Maps); - - DFHack::t_designation des = MCache->designationAt(xy); - int16_t tt = MCache->tiletypeAt(xy); - int16_t veinmat = MCache->veinMaterialAt(xy); - - /* - if( veinmat == -1 ) - { - cerr << "This tile is non-vein. Bye :)" << endl; - delete MCache; - DF->Detach(); - if (!quiet) { - cin.ignore(); - } - return 1; - } - */ - printf("Digging at (%d/%d/%d), tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); - - // 1 < xy.x < tx_max - 1 - // 1 < xy.y < ty_max - 1 - // xy.z - - // X____ - // X_XXX - // XXXXX - // __XXX - // __XXX - // _____ - pos map[] = - { - { 0,0 } - , { 0,1 } - , { 0,2 } , { 2,2 }, { 3,2 }, { 4,2 } - , { 0,3 }, { 1,3 }, { 2,3 }, { 3,3 }, { 4,3 } - , { 2,4 }, { 3,4 }, { 4,4 } - // this is mirrored, goes left instead of right - , {-2,2 }, {-3,2 }, {-4,2 } - , {-1,3 }, {-2,3 }, {-3,3 }, {-4,3 } - , {-2,4 }, {-3,4 }, {-4,4 } - }; - - DFHack::DFCoord npos = xy; - - if (dig_up_n > 0) - { - for (int j = 0; j < dig_up_n; j++) - { - for (int i = 0; i < sizeof(map)/sizeof(map[0]); i++) - { - npos=xy; - npos.x += map[i].x; - npos.y -= 4*j + map[i].y; - printf("Digging at (%d/%d/%d)\n", npos.x, npos.y, npos.z); - digat(MCache, npos); - } - } - } - if (dig_down_n > 0) - { - for (int j = 0; j < dig_down_n; j++) - { - for (int i = 0; i < sizeof(map)/sizeof(map[0]); i++) - { - npos=xy; - npos.x += map[i].x; - npos.y += 4*j + map[i].y; - printf("Digging at (%d/%d/%d)\n", npos.x, npos.y, npos.z); - digat(MCache, npos); - } - } - } - - MCache->WriteAll(); - delete MCache; - DF->Detach(); - if (!quiet) { - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - } - return 0; -} diff --git a/needs_porting/hotkey-notes.lua b/needs_porting/hotkey-notes.lua new file mode 100644 index 000000000..a84506512 --- /dev/null +++ b/needs_porting/hotkey-notes.lua @@ -0,0 +1,40 @@ +-- prints info on assigned hotkeys to the console + +local hotkeys = {'F1 ', 'F2 ', 'F3 ', 'F4 ', 'F5 ', 'F6 ', + 'F7 ', 'F8 ', 'F9 ', 'F10', 'F11', 'F12'} + +for i=1, #hotkeys do + local hk = hotkeys[i] + hk = {id=hk} + -- PLACEHOLDER PROPERTIES ONLY! + hk.name = '_name' + hk.x = df.global.window_x + hk.y = df.global.window_y + hk.z = df.global.window_z + + print(hk.id..' '..hk.name..' X= '..hk.x..', Y= '..hk.y..', Z= '..hk.z) +end + +--[[ +# the (very) old Python version... +from context import Context, ContextManager + +cm = ContextManager("Memory.xml") +df = cm.get_single_context() + +df.attach() + +gui = df.gui + +print "Hotkeys" + +hotkeys = gui.read_hotkeys() + +for key in hotkeys: + print "x: %d\ny: %d\tz: %d\ttext: %s" % (key.x, key.y, key.z, key.name) + +df.detach() + +print "Done. Press any key to continue" +raw_input() +]]-- diff --git a/needs_porting/hotkeynotedump.py b/needs_porting/hotkeynotedump.py deleted file mode 100644 index 77cd0b811..000000000 --- a/needs_porting/hotkeynotedump.py +++ /dev/null @@ -1,20 +0,0 @@ -from context import Context, ContextManager - -cm = ContextManager("Memory.xml") -df = cm.get_single_context() - -df.attach() - -gui = df.gui - -print "Hotkeys" - -hotkeys = gui.read_hotkeys() - -for key in hotkeys: - print "x: %d\ny: %d\tz: %d\ttext: %s" % (key.x, key.y, key.z, key.name) - -df.detach() - -print "Done. Press any key to continue" -raw_input() \ No newline at end of file diff --git a/needs_porting/incrementalsearch.cpp b/needs_porting/incrementalsearch.cpp deleted file mode 100644 index e70e09527..000000000 --- a/needs_porting/incrementalsearch.cpp +++ /dev/null @@ -1,1064 +0,0 @@ -// this is an incremental search tool. It only works on Linux. -// here be dragons... and ugly code :P -#include -#include -#include -#include -#include -#include -#include -#include -#include -using namespace std; - -#ifndef LINUX_BUILD - #define WINVER 0x0500 - // this one prevents windows from infecting the global namespace with filth - #define NOMINMAX - #define WIN32_LEAN_AND_MEAN - #include -#endif - -#include -#include "SegmentedFinder.h" - -inline void printRange(DFHack::t_memrange * tpr) -{ - std::cout << std::hex << tpr->start << " - " << tpr->end << "|" << (tpr->read ? "r" : "-") << (tpr->write ? "w" : "-") << (tpr->execute ? "x" : "-") << "|" << tpr->name << std::endl; -} - -/* - * Since the start and/or end of a memory range can change each time we - * detach and re-attach to the DF process, we save the indexes of the - * memory ranges we want to look at, and re-read the ranges each time - * we re-attach. Hopefully we won't encounter any circumstances where - * entire new ranges are added or removed... - */ -bool getRanges(DFHack::Process * p, vector & selected_ranges) -{ - vector ranges; - ranges.clear(); - selected_ranges.clear(); - p->getMemRanges(ranges); - cout << "Which range to search? (default is 1-4)" << endl; - for(size_t i = 0; i< ranges.size();i++) - { - cout << dec << "(" << i << ") "; - printRange(&(ranges[i])); - } - int start, end; - while(1) - { - string select; - cout << ">>"; - std::getline(cin, select); - if(select.empty()) - { - // empty input, assume default. observe the length of the memory - // range vector these are hardcoded values, intended for my - // convenience only - if(p->getDescriptor()->getOS() == DFHack::OS_WINDOWS) - { - start = min(11, (int)ranges.size()); - end = min(14, (int)ranges.size()); - } - else if(p->getDescriptor()->getOS() == DFHack::OS_LINUX) - { - start = min(2, (int)ranges.size()); - end = min(4, (int)ranges.size()); - } - else - { - start = 1; - end = 1; - } - break; - } - // I like the C variants here. much less object clutter - else if(sscanf(select.c_str(), "%d-%d", &start, &end) == 2) - { - start = min(start, (int)ranges.size()); - end = min(end, (int)ranges.size()); - break; - } - else - { - continue; - } - break; - } - cout << "selected ranges:" <>"; - 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 getString (string prompt, string & output) -{ - cout << prompt; - cout << ">>"; - string select; - std::getline(cin, select); - if(select.empty()) - { - return false; - } - else - { - output = select; - return true; - } -} - -bool readRanges(DFHack::Context * DF, vector & selected_ranges, - vector & ranges) -{ - DFHack::Process * p = DF->getProcess(); - - vector new_ranges; - new_ranges.clear(); - p->getMemRanges(new_ranges); - - for (size_t i = 0; i < selected_ranges.size(); i++) - { - int idx = selected_ranges[i]; - - if (ranges.size() == i) - // First time ranges vector has been filled in. - ranges.push_back(new_ranges[idx]); - // If something was wrong with the range on one memory read, - // don't read it again. - else if(ranges[i].valid) - ranges[i] = new_ranges[idx]; - } - - return true; -} - - -template -bool Incremental ( vector &found, const char * what, T& output, - const char *singular = "address", const char *plural = "addresses", bool numberz = false ) -{ - string select; - if(found.empty()) - { - cout << "search ready - insert " << what << ", 'p' for results, 'p #' to limit number of results" << endl; - } - else if( found.size() == 1) - { - cout << "Found single "<< singular <<"!" << endl; - cout << hex << "0x" << found[0] << endl; - } - else - { - cout << "Found " << dec << found.size() << " " << plural <<"." << endl; - } - incremental_more: - cout << ">>"; - std::getline(cin, select); - size_t num = 0; - if( sscanf(select.c_str(),"p %zd", &num) && num > 0) - { - cout << "Found "<< plural <<":" << endl; - for(size_t i = 0; i < min(found.size(), num);i++) - { - cout << hex << "0x" << found[i] << endl; - } - goto incremental_more; - } - else if(select == "p") - { - cout << "Found "<< plural <<":" << endl; - for(size_t i = 0; i < found.size();i++) - { - cout << hex << "0x" << found[i] << endl; - } - goto incremental_more; - } - else if(select == "q") - { - return false; - } - else if(select.empty()) - { - goto incremental_more; - } - else - { - if(numberz) - { - if( sscanf(select.c_str(),"0x%x", &output) == 1 ) - { - //cout << dec << output << endl; - return true; - } - if( sscanf(select.c_str(),"%d", &output) == 1 ) - { - //cout << dec << output << endl; - return true; - } - } - stringstream ss (stringstream::in | stringstream::out); - ss << select; - ss >> output; - cout << output; - if(!ss.fail()) - { - return true; - } - cout << "not a valid value for type: " << what << endl; - goto incremental_more; - } -} - -void FindIntegers(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - - // input / validation of variable size - int size; - do - { - getNumber("Select variable size (1,2,4 bytes)",size, 4); - } while (size != 1 && size != 2 && size != 4); - // input / validation of variable alignment (default is to use the same alignment as size) - int alignment; - do - { - getNumber("Select variable alignment (1,2,4 bytes)",alignment, size); - } while (alignment != 1 && alignment != 2 && alignment != 4); - - uint32_t test1; - vector found; - found.reserve(100); - while(Incremental(found, "integer",test1,"address", "addresses",true)) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - switch(size) - { - case 1: - sf.Incremental(test1,alignment,found, equalityP); - break; - case 2: - sf.Incremental(test1,alignment,found, equalityP); - break; - case 4: - sf.Incremental(test1,alignment,found, equalityP); - break; - } - DF->Detach(); - } -} - -void FindVectorByLength(DFHack::ContextManager & DFMgr, - vector & selected_ranges ) -{ - vector ranges; - - int element_size; - do - { - getNumber("Select searched vector item size in bytes",element_size, 4); - } while (element_size < 1); - - uint32_t length; - vector found; - found.reserve(100); - while (Incremental(found, "vector length",length,"vector","vectors")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - //sf.Incremental(0,4,found,vectorAll); - //sf.Filter(length * element_size,found,vectorLength); - sf.Incremental(length * element_size, 4 , found, vectorLength); - DF->Detach(); - } -} - -void FindVectorByObjectRawname(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - string select; - - while (Incremental(found, "raw name",select,"vector","vectors")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Find(0,4,found, vectorAll); - sf.Filter(select.c_str(),found, vectorString); - DF->Detach(); - } -} - -void FindVectorByFirstObjectRawname(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - string select; - while (Incremental(found, "raw name",select,"vector","vectors")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Find(0,4,found, vectorAll); - sf.Filter(select.c_str(),found, vectorStringFirst); - DF->Detach(); - } -} - -struct VectorSizeFunctor : public binary_function -{ - VectorSizeFunctor(SegmentedFinder & sf):sf_(sf){} - bool operator()( uint64_t lhs, uint64_t rhs) - { - vecTriplet* left = sf_.Translate(lhs); - vecTriplet* right = sf_.Translate(rhs); - return ((left->finish - left->start) < (right->finish - right->start)); - } - SegmentedFinder & sf_; -}; - -void FindVectorByBounds(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - uint32_t select; - while (Incremental(found, "address between vector.start and vector.end",select,"vector","vectors")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Find(0,4,found, vectorAll); - sf.Filter(select,found, vectorAddrWithin); - // sort by size of vector - std::sort(found.begin(), found.end(), VectorSizeFunctor(sf)); - DF->Detach(); - } -} - -void FindPtrVectorsByObjectAddress(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - uint32_t select; - while (Incremental(found, "object address",select,"vector","vectors")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Find(0,4,found, vectorAll); - sf.Filter(select,found, vectorOfPtrWithin); - DF->Detach(); - } -} - -void FindStrBufs(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - string select; - while (Incremental(found,"buffer",select,"buffer","buffers")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Find< const char * ,uint32_t>(select.c_str(),1,found, findStrBuffer); - DF->Detach(); - } -} - - - -void FindStrings(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - string select; - while (Incremental(found,"string",select,"string","strings")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Incremental< const char * ,uint32_t>(select.c_str(),1,found, findString); - DF->Detach(); - } -} - -void FindData(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - vector found; - Bytestream select; - while (Incremental(found,"byte stream",select,"byte stream","byte streams")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - sf.Incremental< Bytestream ,uint32_t>(select,1,found, findBytestream); - DF->Detach(); - } -} - -bool TriggerIncremental ( vector &found ) -{ - string select; - if(found.empty()) - { - cout << "search ready - position the DF cursor and hit enter when ready" << endl; - } - else if( found.size() == 1 ) - { - cout << "Found single coord!" << endl; - cout << hex << "0x" << found[0] << endl; - } - else - { - cout << "Found " << dec << found.size() << " coords." << endl; - } - incremental_more: - cout << ">>"; - std::getline(cin, select); - size_t num = 0; - if( sscanf(select.c_str(),"p %zd", &num) && num > 0) - { - cout << "Found coords:" << endl; - for(size_t i = 0; i < min(found.size(), num);i++) - { - cout << hex << "0x" << found[i] << endl; - } - goto incremental_more; - } - else if(select == "p") - { - cout << "Found coords:" << endl; - for(size_t i = 0; i < found.size();i++) - { - cout << hex << "0x" << found[i] << endl; - } - goto incremental_more; - } - else if(select == "q") - { - return false; - } - else return true; -} - -void FindCoords(DFHack::ContextManager & DFMgr, vector & selected_ranges) -{ - vector found; - vector ranges; - - int size = 4; - do - { - getNumber("Select coord size (2,4 bytes)",size, 4); - } while (size != 2 && size != 4); - while (TriggerIncremental(found)) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - DFHack::Gui * pos = DF->getGui(); - pos->Start(); - int32_t x, y, z; - pos->getCursorCoords(x,y,z); - cout << "Searching for: " << dec << x << ":" << y << ":" << z << endl; - Bytestream select; - if(size == 2) - { - select.insert(x); - select.insert(y); - select.insert(z); - } - else - { - select.insert(x); - select.insert(y); - select.insert(z); - } - cout << select << endl; - SegmentedFinder sf(ranges,DF); - sf.Incremental< Bytestream ,uint32_t>(select,1,found, findBytestream); - DF->Detach(); - } -} - -void PtrTrace(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - - int element_size; - do - { - getNumber("Set search granularity",element_size, 4); - } while (element_size < 1); - - vector found; - set check; // to detect circles - uint32_t select; - while (Incremental(found,"address",select,"addresses","addresses",true)) - { - DFMgr.Refresh(); - found.clear(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - readRanges(DF, selected_ranges, ranges); - SegmentedFinder sf(ranges,DF); - cout <<"Starting: 0x" << hex << select << endl; - while(sf.getSegmentForAddress(select)) - { - sf.Incremental(select,element_size,found, equalityP); - if(found.empty()) - { - cout << "."; - cout.flush(); - select -=element_size; - continue; - } - cout << endl; - cout <<"Object start: 0x" << hex << select << endl; - cout <<"Pointer: 0x" << hex << found[0] << endl; - // make sure we don't go in circles' - if(check.count(select)) - { - break; - } - check.insert(select); - // ascend - select = found[0]; - found.clear(); - } - DF->Detach(); - } -} -/* -{ - vector found; - Bytestream select; - while (Incremental(found,"byte stream",select,"byte stream","byte streams")) - { - DFMgr.Refresh(); - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - SegmentedFinder sf(ranges,DF); - sf.Incremental< Bytestream ,uint32_t>(select,1,found, findBytestream); - DF->Detach(); - } -} -*/ -void DataPtrTrace(DFHack::ContextManager & DFMgr, - vector & selected_ranges) -{ - vector ranges; - int element_size; - do - { - getNumber("Set search granularity",element_size, 4); - } while (element_size < 1); - - vector found; - set check; // to detect circles - uint32_t select; - Bytestream bs_select; - DFHack::Context * DF = DFMgr.getSingleContext(); - DF->Attach(); - DFMgr.Refresh(); - readRanges(DF, selected_ranges, ranges); - found.clear(); - SegmentedFinder sf(ranges,DF); - while(found.empty()) - { - Incremental(found,"byte stream",bs_select,"byte stream","byte streams"); - - sf.Incremental< Bytestream ,uint32_t>(bs_select,1,found, findBytestream); - } - select = found[0]; - - - - - cout <<"Starting: 0x" << hex << select << endl; - while(sf.getSegmentForAddress(select)) - { - sf.Incremental(select,element_size,found, equalityP); - if(found.empty()) - { - cout << "."; - cout.flush(); - select -=element_size; - continue; - } - cout << endl; - cout <<"Object start: 0x" << hex << select << endl; - cout <<"Pointer: 0x" << hex << found[0] << endl; - // make sure we don't go in circles' - if(check.count(select)) - { - break; - } - check.insert(select); - // ascend - select = found[0]; - found.clear(); - } - DF->Detach(); -} - -void printFound(vector &found, const char * what) -{ - cout << what << ":" << endl; - for(size_t i = 0; i < found.size();i++) - { - cout << hex << "0x" << found[i] << endl; - } -} - -void printFoundStrVec(vector &found, const char * what, SegmentedFinder & s) -{ - cout << what << ":" << endl; - for(size_t i = 0; i < found.size();i++) - { - cout << hex << "0x" << found[i] << endl; - cout << "--------------------------" << endl; - vecTriplet * vt = s.Translate(found[i]); - if(vt) - { - int j = 0; - for(uint32_t idx = vt->start; idx < vt->finish; idx += sizeof(uint32_t)) - { - uint32_t object_ptr; - // deref ptr idx, get ptr to object - if(!s.Read(idx,object_ptr)) - { - cout << "BAD!" << endl; - break; - } - // deref ptr to first object, get ptr to string - uint32_t string_ptr; - if(!s.Read(object_ptr,string_ptr)) - { - cout << "BAD!" << endl; - break; - } - // get string location in our local cache - char * str = s.Translate(string_ptr); - if(!str) - { - cout << "BAD!" << endl; - break; - } - cout << dec << j << ":" << hex << "0x" << object_ptr << " : " << str << endl; - j++; - } - } - else - { - cout << "BAD!" << endl; - break; - } - cout << "--------------------------" << endl; - } -} - -// meh -#pragma pack(1) -struct tilecolors -{ - uint16_t fore; - uint16_t back; - uint16_t bright; -}; -#pragma pack() - -void autoSearch(DFHack::Context * DF, vector & selected_ranges) -{ - vector ranges; - vector allVectors; - vector filtVectors; - vector to_filter; - - readRanges(DF, selected_ranges, ranges); - - cout << "stealing memory..." << endl; - SegmentedFinder sf(ranges, DF); - cout << "looking for vectors..." << endl; - sf.Find(0,4,allVectors, vectorAll); -/* - // trim vectors. anything with > 10000 entries is not interesting - for(uint64_t i = 0; i < allVectors.size();i++) - { - vecTriplet* vtrip = sf.Translate(allVectors[i]); - if(vtrip) - { - uint64_t length = (vtrip->finish - vtrip->start) / 4; - if(length < 10000 ) - { - filtVectors.push_back(allVectors[i]); - } - } - } -*/ - filtVectors = allVectors; - cout << "-------------------" << endl; - cout << "!!LANGUAGE TABLES!!" << endl; - cout << "-------------------" << endl; - - uint64_t kulet_vector; - uint64_t word_table_offset; - uint64_t DWARF_vector; - uint64_t DWARF_object; - - // find lang vector (neutral word table) - to_filter = filtVectors; - sf.Filter("ABBEY",to_filter, vectorStringFirst); - uint64_t lang_addr = to_filter[0]; - - // find dwarven language word table - to_filter = filtVectors; - sf.Filter("kulet",to_filter, vectorStringFirst); - kulet_vector = to_filter[0]; - - // find vector of languages - to_filter = filtVectors; - sf.Filter("DWARF",to_filter, vectorStringFirst); - - // verify - for(size_t i = 0; i < to_filter.size(); i++) - { - vecTriplet * vec = sf.Translate(to_filter[i]); - if(((vec->finish - vec->start) / 4) == 4) // verified - { - DWARF_vector = to_filter[i]; - DWARF_object = sf.Read(vec->start); - // compute word table offset from dwarf word table and dwarf language object addresses - word_table_offset = kulet_vector - DWARF_object; - break; - } - } - cout << "translation vector: " << hex << "0x" << DWARF_vector << endl; - cout << "lang vector: " << hex << "0x" << lang_addr << endl; - cout << "word table offset: " << hex << "0x" << word_table_offset << endl; - - cout << "-------------" << endl; - cout << "!!MATERIALS!!" << endl; - cout << "-------------" << endl; - // inorganics vector - to_filter = filtVectors; - //sf.Find(257 * 4,4,to_filter,vectorLength); - sf.Filter("IRON",to_filter, vectorString); - sf.Filter("ONYX",to_filter, vectorString); - sf.Filter("RAW_ADAMANTINE",to_filter, vectorString); - sf.Filter("BLOODSTONE",to_filter, vectorString); - printFound(to_filter,"inorganics"); - - // organics vector - to_filter = filtVectors; - sf.Filter(52 * 4,to_filter,vectorLength); - sf.Filter("MUSHROOM_HELMET_PLUMP",to_filter, vectorStringFirst); - printFound(to_filter,"organics"); - - // new organics vector - to_filter = filtVectors; - sf.Filter("MUSHROOM_HELMET_PLUMP",to_filter, vectorString); - sf.Filter("MEADOW-GRASS",to_filter, vectorString); - sf.Filter("TUNNEL_TUBE",to_filter, vectorString); - sf.Filter("WEED_BLADE",to_filter, vectorString); - sf.Filter("EYEBALL",to_filter, vectorString); - printFound(to_filter,"organics 31.19"); - - // tree vector - to_filter = filtVectors; - sf.Filter(31 * 4,to_filter,vectorLength); - sf.Filter("MANGROVE",to_filter, vectorStringFirst); - printFound(to_filter,"trees"); - - // plant vector - to_filter = filtVectors; - sf.Filter(21 * 4,to_filter,vectorLength); - sf.Filter("MUSHROOM_HELMET_PLUMP",to_filter, vectorStringFirst); - printFound(to_filter,"plants"); - - // color descriptors - //AMBER, 112 - to_filter = filtVectors; - sf.Filter(112 * 4,to_filter,vectorLength); - sf.Filter("AMBER",to_filter, vectorStringFirst); - printFound(to_filter,"color descriptors"); - if(!to_filter.empty()) - { - uint64_t vec = to_filter[0]; - vecTriplet *vtColors = sf.Translate(vec); - uint32_t colorObj = sf.Read(vtColors->start); - cout << "Amber color:" << hex << "0x" << colorObj << endl; - // TODO: find string 'amber', the floats - } - - // all descriptors - //AMBER, 338 - to_filter = filtVectors; - sf.Filter(338 * 4,to_filter,vectorLength); - sf.Filter("AMBER",to_filter, vectorStringFirst); - printFound(to_filter,"all descriptors"); - - // creature type - //ELEPHANT, ?? (demons abound) - to_filter = filtVectors; - //sf.Find(338 * 4,4,to_filter,vectorLength); - sf.Filter("ELEPHANT",to_filter, vectorString); - sf.Filter("CAT",to_filter, vectorString); - sf.Filter("DWARF",to_filter, vectorString); - sf.Filter("WAMBLER_FLUFFY",to_filter, vectorString); - sf.Filter("TOAD",to_filter, vectorString); - sf.Filter("DEMON_1",to_filter, vectorString); - - vector toad_first = to_filter; - vector elephant_first = to_filter; - sf.Filter("TOAD",toad_first, vectorStringFirst); - sf.Filter("ELEPHANT",elephant_first, vectorStringFirst); - printFoundStrVec(toad_first,"toad-first creature types",sf); - printFound(elephant_first,"elephant-first creature types"); - printFound(to_filter,"all creature types"); - - uint64_t to_use = 0; - if(!elephant_first.empty()) - { - to_use = elephant_first[0]; - vecTriplet *vtCretypes = sf.Translate(to_use); - uint32_t elephant = sf.Read(vtCretypes->start); - uint64_t Eoffset; - cout << "Elephant: 0x" << hex << elephant << endl; - cout << "Elephant: rawname = 0x0" << endl; - uint8_t letter_E = 'E'; - Eoffset = sf.FindInRange (letter_E,equalityP, elephant, 0x300 ); - if(Eoffset) - { - cout << "Elephant: big E = 0x" << hex << Eoffset - elephant << endl; - } - Eoffset = sf.FindInRange ("FEMALE",vectorStringFirst, elephant, 0x300 ); - if(Eoffset) - { - cout << "Elephant: caste vector = 0x" << hex << Eoffset - elephant << endl; - } - Eoffset = sf.FindInRange ("SKIN",vectorStringFirst, elephant, 0x2000 ); - if(Eoffset) - { - cout << "Elephant: extract? vector = 0x" << hex << Eoffset - elephant << endl; - } - tilecolors eletc = {7,0,0}; - Bytestream bs_eletc(&eletc, sizeof(tilecolors)); - cout << bs_eletc; - Eoffset = sf.FindInRange (bs_eletc, findBytestream, elephant, 0x300 ); - if(Eoffset) - { - cout << "Elephant: colors = 0x" << hex << Eoffset - elephant << endl; - } - //cout << "Amber color:" << hex << "0x" << colorObj << endl; - // TODO: find string 'amber', the floats - } - if(!toad_first.empty()) - { - to_use = toad_first[0]; - vecTriplet *vtCretypes = sf.Translate(to_use); - uint32_t toad = sf.Read(vtCretypes->start); - uint64_t Eoffset; - cout << "Toad: 0x" << hex << toad << endl; - cout << "Toad: rawname = 0x0" << endl; - Eoffset = sf.FindInRange (0xF9,equalityP, toad, 0x300 ); - if(Eoffset) - { - cout << "Toad: character (not reliable) = 0x" << hex << Eoffset - toad << endl; - } - Eoffset = sf.FindInRange ("FEMALE",vectorStringFirst, toad, 0x300 ); - if(Eoffset) - { - cout << "Toad: caste vector = 0x" << hex << Eoffset - toad << endl; - } - Eoffset = sf.FindInRange ("SKIN",vectorStringFirst, toad, 0x2000 ); - if(Eoffset) - { - cout << "Toad: extract? vector = 0x" << hex << Eoffset - toad << endl; - } - tilecolors toadtc = {2,0,0}; - Bytestream bs_toadc(&toadtc, sizeof(tilecolors)); - Eoffset = sf.FindInRange (bs_toadc, findBytestream, toad, 0x300 ); - if(Eoffset) - { - cout << "Toad: colors = 0x" << hex << Eoffset - toad << endl; - } - } - if(to_use) - { - - } -} - -int main (void) -{ - string select; - DFHack::ContextManager DFMgr("Memory.xml"); - DFHack::Context * DF = DFMgr.getSingleContext(); - try - { - DF->Attach(); - } - catch (exception& e) - { - cerr << e.what() << endl; - #ifndef LINUX_BUILD - cin.ignore(); - #endif - return 1; - } - DFHack::Process * p = DF->getProcess(); - vector selected_ranges; - getRanges(p, selected_ranges); - - string prompt = - "Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n" - " 4=string, 5=automated offset search, 6=vector by address in its array,\n" - " 7=pointer vector by address of an object, 8=vector>first object>string\n" - " 9=string buffers, 10=known data, 11=backpointers, 12=data+backpointers\n" - " 13=coord lookup\n" - " 0= exit\n"; - int mode; - bool finish = 0; - do - { - getNumber(prompt,mode, 1, false); - switch (mode) - { - case 0: - finish = 1; - break; - case 1: - DF->Detach(); - FindIntegers(DFMgr, selected_ranges); - break; - case 2: - DF->Detach(); - FindVectorByLength(DFMgr, selected_ranges); - break; - case 3: - DF->Detach(); - FindVectorByObjectRawname(DFMgr, selected_ranges); - break; - case 4: - DF->Detach(); - FindStrings(DFMgr, selected_ranges); - break; - case 5: - autoSearch(DF,selected_ranges); - break; - case 6: - DF->Detach(); - FindVectorByBounds(DFMgr,selected_ranges); - break; - case 7: - DF->Detach(); - FindPtrVectorsByObjectAddress(DFMgr,selected_ranges); - break; - case 8: - DF->Detach(); - FindVectorByFirstObjectRawname(DFMgr, selected_ranges); - break; - case 9: - DF->Detach(); - FindStrBufs(DFMgr, selected_ranges); - break; - case 10: - DF->Detach(); - FindData(DFMgr, selected_ranges); - break; - case 11: - DF->Detach(); - PtrTrace(DFMgr, selected_ranges); - break; - case 12: - DF->Detach(); - DataPtrTrace(DFMgr, selected_ranges); - break; - case 13: - DF->Detach(); - FindCoords(DFMgr, selected_ranges); - break; - default: - cout << "Unknown function, try again." << endl; - } - } while ( !finish ); - #ifndef LINUX_BUILD - cout << "Done. Press any key to continue" << endl; - cin.ignore(); - #endif - return 0; -} diff --git a/needs_porting/position.py b/needs_porting/position.py deleted file mode 100644 index 122440589..000000000 --- a/needs_porting/position.py +++ /dev/null @@ -1,71 +0,0 @@ -import sys -from pydfhack import ContextManager - -df_cm = ContextManager("Memory.xml") -df = df_cm.get_single_context() - -if not df.attach(): - print "Unable to attach!" - print "Press any key to continue" - - raw_input() - sys.exit(1) - -gui = df.gui - -if gui is not None: - maps = df.maps - world = df.world - - have_maps = maps.start() - world.start() - - gm = world.read_game_mode() - - if gm is not None: - print gm - - date_tuple = (world.read_current_year(), world.read_current_month(), world.read_current_day(), world.read_current_tick()) - - print "Year: %d Month: %d Day: %d Tick: %d" % date_tuple - - v_coords = gui.get_view_coords() - c_coords = gui.get_cursor_coords() - w_coords = (-1, -1, -1) - world_pos_string = "" - - if have_maps is True: - w_coords = maps.getPosition() - - x = (v_coords[0] + w_coords[0]) * 48 - y = (v_coords[1] + w_coords[1]) * 48 - z = (v_coords[2] + w_coords[2]) - - world_pos_string = " world: %d/%d/%d" % (x, y, z) - - print "Map world offset: %d/%d/%d embark squares" % w_coords - - if v_coords != (-1, -1, -1): - print "view coords: %d/%d/%d" % v_coords - - if have_maps is True: - print world_pos_string - - if c_coords != (-1, -1, -1): - print "cursor coords: %d/%d/%d" % c_coords - - if have_maps is True: - print world_pos_string - - window_size = gui.get_window_size() - - if window_size != (-1, -1): - print "window size : %d %d" % window_size -else: - print "cursor and window parameters are unsupported on your version of DF" - -if not df.detach(): - print "Unable to detach!" - -print "Done. Press any key to continue" -raw_input() \ No newline at end of file diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index cda764f54..3cb9d9b23 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -1720,10 +1720,10 @@ struct dwarf_monitor_hook : public df::viewscreen_dwarfmodest int y = 0; ostringstream date_str; - auto month = World::ReadCurrentMonth(); + auto month = World::ReadCurrentMonth() + 1; auto day = World::ReadCurrentDay(); - date_str << "Date:" << World::ReadCurrentYear() << "/" << - ((month < 10) ? "0" : "") << month << "/" << + date_str << "Date:" << World::ReadCurrentYear() << "-" << + ((month < 10) ? "0" : "") << month << "-" << ((day < 10) ? "0" : "") << day; OutputString(COLOR_GREY, x, y, date_str.str()); diff --git a/scripts/position.lua b/scripts/position.lua new file mode 100644 index 000000000..e4521cb69 --- /dev/null +++ b/scripts/position.lua @@ -0,0 +1,40 @@ +--prints current time and position + +local months = { + 'Granite, in early Spring.', + 'Slate, in mid Spring.', + 'Felsite, in late Spring.', + 'Hematite, in early Summer.', + 'Malachite, in mid Summer.', + 'Galena, in late Summer.', + 'Limestone, in early Autumn.', + 'Sandstone, in mid Autumn.', + 'Timber, in late Autumn.', + 'Moonstone, in early Winter.', + 'Opal, in mid Winter.', + 'Obsidian, in late Winter.', +} + +--Fortress mode counts 1200 ticks per day and 403200 per year +--Adventurer mode counts 86400 ticks to a day and 29030400 ticks per year +--Twelve months per year, 28 days to every month, 336 days per year + +local julian_day = math.floor(df.global.cur_year_tick / 1200) + 1 +local month = math.floor(julian_day / 28) + 1 --days and months are 1-indexed +local day = julian_day % 28 + +local time_of_day = math.floor(df.global.cur_year_tick_advmode / 336) +local second = time_of_day % 60 +local minute = (time_of_day / 60) % 60 +local hour = math.floor(time_of_day / 3600) % 24 + +print('Time:') +print(' The time is '..string.format('%02d:%02d:%02d', hour, minute, second)) +print(' The date is '..string.format('%05d-%02d-%02d', df.global.cur_year, month, day)) +print(' It is the month of '..months[month]) + +print('Place:') +print(' Local window is at x='..df.global.window_x + ..' y='..df.global.window_y..' z='..df.global.window_z) + +--TODO: add cursor, regional/embark square co-ords, window size?