From e71f41fd42ee7daef17c9e8f71e307d198ca120a Mon Sep 17 00:00:00 2001 From: belal Date: Wed, 17 Feb 2010 18:33:08 -0500 Subject: [PATCH 01/16] test commit of notes-windows d17 Signed-off-by: belal --- examples/CMakeLists.txt | 5 +++ library/DFHackAPI.cpp | 57 ++++++++++++++++++++++++- library/DFHackAPI.h | 4 ++ library/DFProcessEnumerator-windows.cpp | 6 +-- library/DFTypes.h | 11 +++++ output/Memory.xml | 6 +++ 6 files changed, 85 insertions(+), 4 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e5e133580..9aa1cec5f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -42,6 +42,11 @@ TARGET_LINK_LIBRARIES(dfitemdump dfhack) ADD_EXECUTABLE(dfdigger digger.cpp) TARGET_LINK_LIBRARIES(dfdigger dfhack) +# hotkeynotedump - dumps the hotkeys and notes for the loaded map +# Author: belal +ADD_EXECUTABLE(dfhotkeynotedump hotkeynotedump.cpp) +TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack) + IF(UNIX) # veinlook - look at the map... sort of ADD_EXECUTABLE(dfveinlook veinlook.cpp) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index ecab52de3..8540dc879 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -83,6 +83,11 @@ public: uint32_t item_material_offset; + uint32_t note_foreground_offset; + uint32_t note_background_offset; + uint32_t note_name_offset; + uint32_t note_xyz_offset; + uint32_t dwarf_lang_table_offset; ProcessEnumerator* pm; @@ -98,6 +103,7 @@ public: bool cursorWindowInited; bool viewSizeInited; bool itemsInited; + bool notesInited; bool nameTablesInited; @@ -107,6 +113,7 @@ public: DfVector *p_bld; DfVector *p_veg; DfVector *p_itm; + DfVector *p_notes; }; API::API (const string path_to_xml) @@ -122,6 +129,7 @@ API::API (const string path_to_xml) d->cursorWindowInited = false; d->viewSizeInited = false; d->itemsInited = false; + d->notesInited = false; d->pm = NULL; } @@ -853,7 +861,47 @@ bool API::InitReadCreatures( uint32_t &numcreatures ) return false; } } - +bool API::InitReadNotes( uint32_t &numnotes ) +{ + memory_info * minfo = d->offset_descriptor; + int notes = d->offset_descriptor->getAddress ("notes"); + d->note_foreground_offset = minfo->getOffset ("note_foreground"); + d->note_background_offset = minfo->getOffset ("note_background"); + d->note_name_offset = minfo->getOffset ("note_name"); + d->note_xyz_offset = minfo->getOffset ("note_xyz"); + + if (notes + && d->note_foreground_offset + && d->note_background_offset + && d->note_name_offset + && d->note_xyz_offset + ) + { + d->p_notes = new DfVector (d->p->readVector (notes, 4)); + //InitReadNameTables(); + d->notesInited = true; + numnotes = d->p_notes->getSize(); + return true; + } + else + { + d->notesInited = false; + numnotes = 0; + return false; + } +} +bool API::ReadNote (const int32_t &index, t_note & note) +{ + assert (d->notesInited); + // read pointer from vector at position + uint32_t temp = * (uint32_t *) d->p_notes->at (index); + note.symbol = g_pProcess->readByte(temp); + note.foreground = g_pProcess->readWord(temp + d->note_foreground_offset); + note.background = g_pProcess->readWord(temp + d->note_background_offset); + d->p->readSTLString (temp + d->note_name_offset, note.name, 128); + g_pProcess->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) ¬e.x); + return true; +} // returns index of creature actually read or -1 if no creature can be found int32_t API::ReadCreatureInBox (int32_t index, t_creature & furball, const uint16_t &x1, const uint16_t &y1, const uint16_t &z1, @@ -1087,6 +1135,13 @@ void API::FinishReadCreatures() d->creaturesInited = false; //FinishReadNameTables(); } +void API::FinishReadNotes() +{ + delete d->p_notes; + d->p_notes = NULL; + d->notesInited = false; + //FinishReadNameTables(); +} bool API::Attach() { diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index 21e3999cc..5f3dce912 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -171,6 +171,10 @@ namespace DFHack void WriteRaw (const uint32_t &offset, const uint32_t &size, uint8_t *source); bool InitViewAndCursor(); + + bool InitReadNotes( uint32_t & numnotes ); + bool ReadNote(const int32_t &index, t_note & note); + void FinishReadNotes(); bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); bool setViewCoords (const int32_t &x, const int32_t &y, const int32_t &z); diff --git a/library/DFProcessEnumerator-windows.cpp b/library/DFProcessEnumerator-windows.cpp index ac11d2ea2..19491c279 100644 --- a/library/DFProcessEnumerator-windows.cpp +++ b/library/DFProcessEnumerator-windows.cpp @@ -77,7 +77,7 @@ bool ProcessEnumerator::findProcessess() } else { - delete p; +//FIXME delete p; p = 0; } } @@ -102,7 +102,7 @@ bool ProcessEnumerator::findProcessess() } else { - delete q; + //FIXME delete q; q = 0; } } @@ -134,7 +134,7 @@ void ProcessEnumerator::purge() { for(uint32_t i = 0;i < d->processes.size();i++) { - delete d->processes[i]; + //FIXME delete d->processes[i]; } d->processes.clear(); } diff --git a/library/DFTypes.h b/library/DFTypes.h index 08d49d624..61a05720b 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -753,5 +753,16 @@ struct t_viewscreen //There is more info in these objects, but I don't know what it is yet }; +struct t_note +{ + char symbol; + uint16_t foreground; + uint16_t background; + char name[128]; + uint16_t x; + uint16_t y; + uint16_t z; +}; + }// namespace DFHack #endif // TYPES_H_INCLUDED diff --git a/output/Memory.xml b/output/Memory.xml index f9bfd9c11..188c1501a 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1114,6 +1114,12 @@
0x014243C4
0x0178C994
+
0x014240A4
+ 0x2 + 0x4 + 0x8 + 0x24 + From 42a12ffaec27a03dc95b84f9c83a327c377015a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 18 Feb 2010 02:10:39 +0100 Subject: [PATCH 02/16] Veinlook now goes to map edges API change: isValidBlock now checks for map boundaries API change: added getBlockPtr. It returns a DF pointer to a block. --- examples/veinlook.cpp | 25 +++++++++++++++---------- library/DFHackAPI.cpp | 9 +++++++++ library/DFHackAPI.h | 4 ++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index a77f284c1..87832944c 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -272,11 +272,12 @@ main(int argc, char *argv[]) finish(0); } + // FIXME: could fail on small forts int cursorX = x_max/2 - 1; int cursorY = y_max/2 - 1; int cursorZ = z_max/2 - 1; - // FIXME: could fail on small forts + int vein = 0; // walk the map! @@ -318,13 +319,15 @@ main(int argc, char *argv[]) cursorY = max(cursorY, 0); cursorZ = max(cursorZ, 0); - cursorX = min(cursorX, x_max - 3); - cursorY = min(cursorY, y_max - 3); - cursorZ = min(cursorZ, z_max - 3); + cursorX = min(cursorX, x_max - 1); + cursorY = min(cursorY, y_max - 1); + cursorZ = min(cursorZ, z_max - 1); DF.Suspend(); - for(int i = 0; i < 3; i++) - for(int j = 0; j < 3; j++) + for(int i = -1; i <= 1; i++) + { + for(int j = -1; j <= 1; j++) + { if(DF.isValidBlock(cursorX+i,cursorY+j,cursorZ)) { // read data @@ -338,22 +341,24 @@ main(int argc, char *argv[]) color = pickColor(tiletypes[x][y]); if(designations[x][y].bits.hidden) { - puttile(x+i*16,y+j*16,tiletypes[x][y], color); + puttile(x+(i+1)*16,y+(j+1)*16,tiletypes[x][y], color); } else { attron(A_STANDOUT); - puttile(x+i*16,y+j*16,tiletypes[x][y], color); + puttile(x+(i+1)*16,y+(j+1)*16,tiletypes[x][y], color); attroff(A_STANDOUT); } } } - if(i == 1 && j == 1) + if(i == 0 && j == 0) { veinVector.clear(); DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector); } } + } + } gotoxy(0,48); cprintf("arrow keys, PGUP, PGDN = navigate"); gotoxy(0,49); @@ -361,7 +366,7 @@ main(int argc, char *argv[]) gotoxy(0,50); if(vein == veinVector.size()) vein = veinVector.size() - 1; if(vein < -1) vein = -1; - cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX + 1,x_max,cursorY + 1,y_max,cursorZ + 1,z_max,vein+1,veinVector.size()); + cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX+1,x_max,cursorY+1,y_max,cursorZ,z_max,vein+1,veinVector.size()); if(!veinVector.empty()) { if(vein != -1 && vein < veinVector.size()) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index ecab52de3..4b66cd5e4 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -207,9 +207,18 @@ bool API::DestroyMap() bool API::isValidBlock (uint32_t x, uint32_t y, uint32_t z) { + if (x < 0 || x >= d->x_block_count || y < 0 || y >= d->y_block_count || z < 0 || z >= d->z_block_count) + return false; return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z] != 0; } +uint32_t API::getBlockPtr (uint32_t x, uint32_t y, uint32_t z) +{ + if (x < 0 || x >= d->x_block_count || y < 0 || y >= d->y_block_count || z < 0 || z >= d->z_block_count) + return 0; + return d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z]; +} + // 256 * sizeof(uint16_t) bool API::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, uint16_t *buffer) { diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index 21e3999cc..aebce4590 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -128,6 +128,10 @@ namespace DFHack * Return false/0 on failure, buffer allocated by client app, 256 items long */ bool isValidBlock(uint32_t blockx, uint32_t blocky, uint32_t blockz); + /** + * Get the address of a block or 0 if block is not valid + */ + uint32_t getBlockPtr (uint32_t x, uint32_t y, uint32_t z); bool ReadTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t) bool WriteTileTypes(uint32_t blockx, uint32_t blocky, uint32_t blockz, uint16_t *buffer); // 256 * sizeof(uint16_t) From 387e1e879493b30a41b2210eb16e70086da88957 Mon Sep 17 00:00:00 2001 From: belal Date: Wed, 17 Feb 2010 21:08:54 -0500 Subject: [PATCH 03/16] Finish up code for hotkeys and notes, just need to find offsets for linux versions and windows < d17 Signed-off-by: belal --- library/DFHackAPI.cpp | 40 +++++++++++++++++++++++++++++++++++++++- library/DFHackAPI.h | 3 +++ library/DFTypes.h | 10 ++++++++++ output/Memory.xml | 5 +++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 8540dc879..602f90e60 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -87,7 +87,11 @@ public: uint32_t note_background_offset; uint32_t note_name_offset; uint32_t note_xyz_offset; - + uint32_t hotkey_start; + uint32_t hotkey_mode_offset; + uint32_t hotkey_xyz_offset; + uint32_t hotkey_size; + uint32_t dwarf_lang_table_offset; ProcessEnumerator* pm; @@ -104,6 +108,7 @@ public: bool viewSizeInited; bool itemsInited; bool notesInited; + bool hotkeyInited; bool nameTablesInited; @@ -130,6 +135,7 @@ API::API (const string path_to_xml) d->viewSizeInited = false; d->itemsInited = false; d->notesInited = false; + d->hotkeyInited = false; d->pm = NULL; } @@ -902,6 +908,38 @@ bool API::ReadNote (const int32_t &index, t_note & note) g_pProcess->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) ¬e.x); return true; } +bool API::InitReadHotkeys( ) +{ + memory_info * minfo = d->offset_descriptor; + d->hotkey_start = minfo->getAddress("hotkey_start"); + d->hotkey_mode_offset = minfo->getOffset ("hotkey_mode"); + d->hotkey_xyz_offset = minfo->getOffset("hotkey_xyz"); + d->hotkey_size = minfo->getHexValue("hotkey_size"); + + if (d->hotkey_start && d->hotkey_mode_offset && d->hotkey_size) + { + d->hotkeyInited = true; + return true; + } + else + { + d->hotkeyInited = false; + return false; + } +} +bool API::ReadHotkeys(t_hotkey hotkeys[]) +{ + assert (d->hotkeyInited); + uint32_t currHotkey = d->hotkey_start; + for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) + { + d->p->readSTLString(currHotkey,hotkeys[i].name,10); + hotkeys[i].mode = g_pProcess->readWord(currHotkey+d->hotkey_mode_offset); + g_pProcess->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x); + currHotkey+=d->hotkey_size; + } + return true; +} // returns index of creature actually read or -1 if no creature can be found int32_t API::ReadCreatureInBox (int32_t index, t_creature & furball, const uint16_t &x1, const uint16_t &y1, const uint16_t &z1, diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index 5f3dce912..ce7ef8dac 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -175,6 +175,9 @@ namespace DFHack bool InitReadNotes( uint32_t & numnotes ); bool ReadNote(const int32_t &index, t_note & note); void FinishReadNotes(); + + bool InitReadHotkeys( ); + bool ReadHotkeys(t_hotkey hotkeys[]); bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); bool setViewCoords (const int32_t &x, const int32_t &y, const int32_t &z); diff --git a/library/DFTypes.h b/library/DFTypes.h index 61a05720b..717c82180 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -764,5 +764,15 @@ struct t_note uint16_t z; }; +#define NUM_HOTKEYS 16 +struct t_hotkey +{ + char name[10]; + int16_t mode; + int32_t x; + int32_t y; + int32_t z; +}; + }// namespace DFHack #endif // TYPES_H_INCLUDED diff --git a/output/Memory.xml b/output/Memory.xml index 188c1501a..5c1d2a8e8 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1120,6 +1120,11 @@ 0x8 0x24 +
0x14240DC
+ 0x1C + 0x20 + 0x2C + From a0a50b9498f78b2fa73ba48274878f3dda174265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 18 Feb 2010 04:03:30 +0100 Subject: [PATCH 04/16] Added some more ignore rules --- .gitignore | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..10760875f --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# linux backup files +*~ + +# compiled binaries +output/* + +# this one is important, track it +!output/Memory.xml + +# a file generated by cmake +library/config.h + +# any build folders +build*/ + +#except for the real one +!build/ + +#ignore Kdevelop stuff +.kdev4 From 3ac42b79601dd8c796dcf5edc3d4e2a0fa57fad2 Mon Sep 17 00:00:00 2001 From: belal Date: Thu, 18 Feb 2010 09:27:22 -0500 Subject: [PATCH 05/16] Add missing hotkeynotedump.cpp, thanks peterix Signed-off-by: belal --- examples/hotkeynotedump.cpp | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/hotkeynotedump.cpp diff --git a/examples/hotkeynotedump.cpp b/examples/hotkeynotedump.cpp new file mode 100644 index 000000000..cda81ab34 --- /dev/null +++ b/examples/hotkeynotedump.cpp @@ -0,0 +1,61 @@ +// Hotkey and Note Dump + +#include +#include +#include +#include +using namespace std; + +#include +#include +#include + + +int main (void) +{ + vector creaturestypes; + DFHack::API DF("Memory.xml"); + if(!DF.Attach()) + { + cerr << "DF not found" << endl; + return 1; + } + + DFHack::memory_info mem = DF.getMemoryInfo(); + // get stone matgloss mapping + uint32_t numNotes; + if(!DF.InitReadNotes(numNotes)) + { + cerr << "Can't get notes" << endl; + return 1; + } + if(!DF.InitReadHotkeys()) + { + cerr << "Can't get hotkeys" << endl; + return 1; + } + cout << "Notes" << endl; + for(uint32_t i = 0; i < numNotes; i++) + { + DFHack::t_note temp; + DF.ReadNote(i,temp); + cout << "x: " << temp.x << "\ty: " << temp.y << "\tz: " << temp.z << + "\tsymbol: " << temp.symbol << "\tfg: " << temp.foreground << "\tbg: " << temp.background << + "\ttext: " << temp.name << endl; + } + cout << "Hotkeys" << endl; + DFHack::t_hotkey hotkeys[NUM_HOTKEYS]; + DF.ReadHotkeys(hotkeys); + for(uint32_t i =0;i< NUM_HOTKEYS;i++) + { + cout << "x: " << hotkeys[i].x << "\ty: " << hotkeys[i].y << "\tz: " << hotkeys[i].z << + "\ttext: " << hotkeys[i].name << endl; + } + DF.FinishReadNotes(); + DF.Detach(); + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} \ No newline at end of file From 6b92ea274d2a399f647f93f6acde4c5ffc9e606b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 18 Feb 2010 17:58:25 +0100 Subject: [PATCH 06/16] Veinlook shows material of mineral veins --- examples/veinlook.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 87832944c..5e81803c4 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -407,6 +407,8 @@ main(int argc, char *argv[]) } } } + gotoxy(0,52); + cprintf("%s",stonetypes[veinVector[vein].type].name); } gotoxy(0,51); cprintf("%s, address 0x%x",str.c_str(),veinVector[vein].address_of); From e9e1d2b8b9ff6e8ea83b89bee3d02cad5b672dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 18 Feb 2010 18:06:32 +0100 Subject: [PATCH 07/16] Tabs to spaces --- examples/hotkeynotedump.cpp | 60 +++++++++---------- library/DFHackAPI.cpp | 76 ++++++++++++------------- library/DFHackAPI.h | 10 ++-- library/DFProcessEnumerator-windows.cpp | 4 +- library/DFTypes.h | 22 +++---- 5 files changed, 86 insertions(+), 86 deletions(-) diff --git a/examples/hotkeynotedump.cpp b/examples/hotkeynotedump.cpp index cda81ab34..9685e33d5 100644 --- a/examples/hotkeynotedump.cpp +++ b/examples/hotkeynotedump.cpp @@ -1,5 +1,5 @@ // Hotkey and Note Dump - +// Or Hot Keynote Dump? :P #include #include #include @@ -21,38 +21,38 @@ int main (void) return 1; } - DFHack::memory_info mem = DF.getMemoryInfo(); + DFHack::memory_info mem = DF.getMemoryInfo(); // get stone matgloss mapping - uint32_t numNotes; - if(!DF.InitReadNotes(numNotes)) - { - cerr << "Can't get notes" << endl; - return 1; - } - if(!DF.InitReadHotkeys()) - { - cerr << "Can't get hotkeys" << endl; - return 1; - } - cout << "Notes" << endl; + uint32_t numNotes; + if(!DF.InitReadNotes(numNotes)) + { + cerr << "Can't get notes" << endl; + return 1; + } + if(!DF.InitReadHotkeys()) + { + cerr << "Can't get hotkeys" << endl; + return 1; + } + cout << "Notes" << endl; for(uint32_t i = 0; i < numNotes; i++) { - DFHack::t_note temp; - DF.ReadNote(i,temp); - cout << "x: " << temp.x << "\ty: " << temp.y << "\tz: " << temp.z << - "\tsymbol: " << temp.symbol << "\tfg: " << temp.foreground << "\tbg: " << temp.background << - "\ttext: " << temp.name << endl; - } - cout << "Hotkeys" << endl; - DFHack::t_hotkey hotkeys[NUM_HOTKEYS]; - DF.ReadHotkeys(hotkeys); - for(uint32_t i =0;i< NUM_HOTKEYS;i++) - { - cout << "x: " << hotkeys[i].x << "\ty: " << hotkeys[i].y << "\tz: " << hotkeys[i].z << - "\ttext: " << hotkeys[i].name << endl; - } - DF.FinishReadNotes(); - DF.Detach(); + DFHack::t_note temp; + DF.ReadNote(i,temp); + cout << "x: " << temp.x << "\ty: " << temp.y << "\tz: " << temp.z << + "\tsymbol: " << temp.symbol << "\tfg: " << temp.foreground << "\tbg: " << temp.background << + "\ttext: " << temp.name << endl; + } + cout << "Hotkeys" << endl; + DFHack::t_hotkey hotkeys[NUM_HOTKEYS]; + DF.ReadHotkeys(hotkeys); + for(uint32_t i =0;i< NUM_HOTKEYS;i++) + { + cout << "x: " << hotkeys[i].x << "\ty: " << hotkeys[i].y << "\tz: " << hotkeys[i].z << + "\ttext: " << hotkeys[i].name << endl; + } + DF.FinishReadNotes(); + DF.Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 3594773dd..18334c2db 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -83,14 +83,14 @@ public: uint32_t item_material_offset; - uint32_t note_foreground_offset; - uint32_t note_background_offset; - uint32_t note_name_offset; - uint32_t note_xyz_offset; - uint32_t hotkey_start; - uint32_t hotkey_mode_offset; - uint32_t hotkey_xyz_offset; - uint32_t hotkey_size; + uint32_t note_foreground_offset; + uint32_t note_background_offset; + uint32_t note_name_offset; + uint32_t note_xyz_offset; + uint32_t hotkey_start; + uint32_t hotkey_mode_offset; + uint32_t hotkey_xyz_offset; + uint32_t hotkey_size; uint32_t dwarf_lang_table_offset; @@ -107,8 +107,8 @@ public: bool cursorWindowInited; bool viewSizeInited; bool itemsInited; - bool notesInited; - bool hotkeyInited; + bool notesInited; + bool hotkeyInited; bool nameTablesInited; @@ -118,7 +118,7 @@ public: DfVector *p_bld; DfVector *p_veg; DfVector *p_itm; - DfVector *p_notes; + DfVector *p_notes; }; API::API (const string path_to_xml) @@ -134,8 +134,8 @@ API::API (const string path_to_xml) d->cursorWindowInited = false; d->viewSizeInited = false; d->itemsInited = false; - d->notesInited = false; - d->hotkeyInited = false; + d->notesInited = false; + d->hotkeyInited = false; d->pm = NULL; } @@ -860,7 +860,7 @@ bool API::InitReadCreatures( uint32_t &numcreatures ) && d->creature_labors_offset && d->creature_happiness_offset && d->creature_traits_offset - // && d->creature_likes_offset + // && d->creature_likes_offset ) { d->p_cre = new DfVector (d->p->readVector (creatures, 4)); @@ -881,9 +881,9 @@ bool API::InitReadNotes( uint32_t &numnotes ) memory_info * minfo = d->offset_descriptor; int notes = d->offset_descriptor->getAddress ("notes"); d->note_foreground_offset = minfo->getOffset ("note_foreground"); - d->note_background_offset = minfo->getOffset ("note_background"); - d->note_name_offset = minfo->getOffset ("note_name"); - d->note_xyz_offset = minfo->getOffset ("note_xyz"); + d->note_background_offset = minfo->getOffset ("note_background"); + d->note_name_offset = minfo->getOffset ("note_name"); + d->note_xyz_offset = minfo->getOffset ("note_xyz"); if (notes && d->note_foreground_offset @@ -910,25 +910,25 @@ bool API::ReadNote (const int32_t &index, t_note & note) assert (d->notesInited); // read pointer from vector at position uint32_t temp = * (uint32_t *) d->p_notes->at (index); - note.symbol = g_pProcess->readByte(temp); - note.foreground = g_pProcess->readWord(temp + d->note_foreground_offset); - note.background = g_pProcess->readWord(temp + d->note_background_offset); - d->p->readSTLString (temp + d->note_name_offset, note.name, 128); - g_pProcess->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) ¬e.x); - return true; + note.symbol = g_pProcess->readByte(temp); + note.foreground = g_pProcess->readWord(temp + d->note_foreground_offset); + note.background = g_pProcess->readWord(temp + d->note_background_offset); + d->p->readSTLString (temp + d->note_name_offset, note.name, 128); + g_pProcess->read (temp + d->note_xyz_offset, 3*sizeof (uint16_t), (uint8_t *) ¬e.x); + return true; } bool API::InitReadHotkeys( ) { memory_info * minfo = d->offset_descriptor; - d->hotkey_start = minfo->getAddress("hotkey_start"); + d->hotkey_start = minfo->getAddress("hotkey_start"); d->hotkey_mode_offset = minfo->getOffset ("hotkey_mode"); - d->hotkey_xyz_offset = minfo->getOffset("hotkey_xyz"); - d->hotkey_size = minfo->getHexValue("hotkey_size"); - + d->hotkey_xyz_offset = minfo->getOffset("hotkey_xyz"); + d->hotkey_size = minfo->getHexValue("hotkey_size"); + if (d->hotkey_start && d->hotkey_mode_offset && d->hotkey_size) { - d->hotkeyInited = true; - return true; + d->hotkeyInited = true; + return true; } else { @@ -939,15 +939,15 @@ bool API::InitReadHotkeys( ) bool API::ReadHotkeys(t_hotkey hotkeys[]) { assert (d->hotkeyInited); - uint32_t currHotkey = d->hotkey_start; - for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) - { - d->p->readSTLString(currHotkey,hotkeys[i].name,10); - hotkeys[i].mode = g_pProcess->readWord(currHotkey+d->hotkey_mode_offset); - g_pProcess->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x); - currHotkey+=d->hotkey_size; - } - return true; + uint32_t currHotkey = d->hotkey_start; + for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) + { + d->p->readSTLString(currHotkey,hotkeys[i].name,10); + hotkeys[i].mode = g_pProcess->readWord(currHotkey+d->hotkey_mode_offset); + g_pProcess->read (currHotkey + d->hotkey_xyz_offset, 3*sizeof (int32_t), (uint8_t *) &hotkeys[i].x); + currHotkey+=d->hotkey_size; + } + return true; } // returns index of creature actually read or -1 if no creature can be found int32_t API::ReadCreatureInBox (int32_t index, t_creature & furball, diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index 7601d17d7..f41647261 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -176,12 +176,12 @@ namespace DFHack bool InitViewAndCursor(); - bool InitReadNotes( uint32_t & numnotes ); - bool ReadNote(const int32_t &index, t_note & note); - void FinishReadNotes(); + bool InitReadNotes( uint32_t & numnotes ); + bool ReadNote(const int32_t &index, t_note & note); + void FinishReadNotes(); - bool InitReadHotkeys( ); - bool ReadHotkeys(t_hotkey hotkeys[]); + bool InitReadHotkeys( ); + bool ReadHotkeys(t_hotkey hotkeys[]); bool getViewCoords (int32_t &x, int32_t &y, int32_t &z); bool setViewCoords (const int32_t &x, const int32_t &y, const int32_t &z); diff --git a/library/DFProcessEnumerator-windows.cpp b/library/DFProcessEnumerator-windows.cpp index 19491c279..f08aec558 100644 --- a/library/DFProcessEnumerator-windows.cpp +++ b/library/DFProcessEnumerator-windows.cpp @@ -73,7 +73,7 @@ bool ProcessEnumerator::findProcessess() if(p->isIdentified()) { d->processes.push_back(p); - return true; + return true; } else { @@ -103,7 +103,7 @@ bool ProcessEnumerator::findProcessess() else { //FIXME delete q; - q = 0; + q = 0; } } if(d->processes.size()) diff --git a/library/DFTypes.h b/library/DFTypes.h index 717c82180..50e36d898 100644 --- a/library/DFTypes.h +++ b/library/DFTypes.h @@ -756,22 +756,22 @@ struct t_viewscreen struct t_note { char symbol; - uint16_t foreground; - uint16_t background; - char name[128]; - uint16_t x; - uint16_t y; - uint16_t z; + uint16_t foreground; + uint16_t background; + char name[128]; + uint16_t x; + uint16_t y; + uint16_t z; }; #define NUM_HOTKEYS 16 struct t_hotkey { - char name[10]; - int16_t mode; - int32_t x; - int32_t y; - int32_t z; + char name[10]; + int16_t mode; + int32_t x; + int32_t y; + int32_t z; }; }// namespace DFHack From 1c64010b8092b28b0b2c3b4447ba1e625f946c91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 18 Feb 2010 20:16:05 +0100 Subject: [PATCH 08/16] Missed one glitch in the merge --- examples/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 203f3aa5b..058d5014c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -58,7 +58,6 @@ dfattachtest dfbuildingsdump dfcreaturedump dfitemdump -dfdigger dfexpbench dfmaterialtest dfposition From da19d92f1655db5e3a711e50524cb0532b365b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 18 Feb 2010 21:28:28 +0100 Subject: [PATCH 09/16] Asserts into IFs --- library/DFHackAPI.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 18334c2db..1739b20e1 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -907,7 +907,8 @@ bool API::InitReadNotes( uint32_t &numnotes ) } bool API::ReadNote (const int32_t &index, t_note & note) { - assert (d->notesInited); + if(!d->notesInited) + return false; // read pointer from vector at position uint32_t temp = * (uint32_t *) d->p_notes->at (index); note.symbol = g_pProcess->readByte(temp); @@ -938,7 +939,8 @@ bool API::InitReadHotkeys( ) } bool API::ReadHotkeys(t_hotkey hotkeys[]) { - assert (d->hotkeyInited); + if (!d->hotkeyInited) + return false; uint32_t currHotkey = d->hotkey_start; for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) { From 7ce8935aef007985536952f6824d47c22f78420d Mon Sep 17 00:00:00 2001 From: belal Date: Thu, 18 Feb 2010 15:29:45 -0500 Subject: [PATCH 10/16] Add offsets for versions d9-d17 for windows and linux, windows has been tested, linux has not, but it should be right unless I screwed something up Signed-off-by: belal --- library/integers.h | 2 +- output/Memory.xml | 47 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/library/integers.h b/library/integers.h index a9270330c..6cc2396c4 100644 --- a/library/integers.h +++ b/library/integers.h @@ -13,4 +13,4 @@ You can turn off the include by defining SKIP_DFHACK_STDINT #else #include "stdint_win.h" #endif -#endif +#endif diff --git a/output/Memory.xml b/output/Memory.xml index 5c1d2a8e8..ad3601644 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -800,6 +800,18 @@
0xcdc3dc
0xcdc3b8
0x1676f14
+ +
0x012FDBAC
+ 0x2 + 0x4 + 0x8 + 0x24 + +
0x012FDBE4
+ 0x1C + 0x20 + 0x2C + @@ -811,6 +823,9 @@
0xcdf5a0
0xd0d64c
0xd0d628
+ +
0x013E853C
+
0x013E8574
@@ -1114,16 +1129,8 @@
0x014243C4
0x0178C994
-
0x014240A4
- 0x2 - 0x4 - 0x8 - 0x24 - -
0x14240DC
- 0x1C - 0x20 - 0x2C +
0x014240A4
+
0x014240DC
@@ -1513,6 +1520,17 @@
0x9374E88
0xC +
0x09332C98
+ 0x2 + 0x4 + 0x8 + 0xC + +
0x0931EA8C
+ 0x4 + 0x8 + 0x14 + @@ -1614,6 +1632,8 @@
0x88073d4
0x9510050
+ +
0x092AB244
@@ -1654,6 +1674,10 @@
0x08F97A84
+ +
0x08F41644
+
0x08F4166C
+
@@ -1911,6 +1935,9 @@
0x878caa4
0x8f4e940
+
0x08F4E7C4
+
0x08F4E7EC
+ From f71fef9ef5703d00a74fd338790fd6ee64b57eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 19 Feb 2010 02:48:03 +0100 Subject: [PATCH 11/16] Process::readClassName implemented --- examples/veinlook.cpp | 49 ++++++++++++++++++++++++------- library/DFProcess-linux-SHM.cpp | 10 +++++++ library/DFProcess-linux-wine.cpp | 9 ++++++ library/DFProcess-linux.cpp | 10 +++++++ library/DFProcess-windows-SHM.cpp | 9 ++++++ library/DFProcess-windows.cpp | 9 ++++++ library/DFProcess.h | 8 +++++ 7 files changed, 94 insertions(+), 10 deletions(-) diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 5e81803c4..4e138cad1 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -16,6 +16,7 @@ using namespace DFHack; #include string error; +API * pDF = 0; static void finish(int sig); @@ -185,9 +186,21 @@ int pickColor(int tiletype) string getGCCClassName (Process * p, uint32_t vptr) { - int typeinfo = p->readDWord(vptr - 4); - int typestring = p->readDWord(typeinfo + 4); - return p->readCString(typestring); + int typeinfo = p->readDWord(vptr - 0x4); + int typestring = p->readDWord(typeinfo + 0x4); + string raw = p->readCString(typestring); + size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers + size_t end = raw.length(); + return raw.substr(start,end-start - 2); // trim the 'st' from the end +} + +string getMSVCClassName (Process * p, uint32_t vptr) +{ + int rtti = p->readDWord(vptr - 0x4); + int typeinfo = p->readDWord(rtti + 0xC); + string raw = p->readCString(typeinfo + 0xC); // skips the .?AV + raw.resize(raw.length() - 4);// trim st@@ from end + return raw; } main(int argc, char *argv[]) @@ -241,17 +254,23 @@ main(int argc, char *argv[]) // init the API DFHack::API DF("Memory.xml"); - + pDF = &DF; // attach if(!DF.Attach()) { error = "Can't find DF."; + pDF = 0; finish(0); } Process* p = DF.getProcess(); // init the map - DF.InitMap(); + if(!DF.InitMap()) + { + error = "Can't find a map to look at."; + pDF = 0; + finish(0); + } DF.getSize(x_max_a,y_max_a,z_max_a); x_max = x_max_a; @@ -262,6 +281,7 @@ main(int argc, char *argv[]) if(!DF.ReadStoneMatgloss(stonetypes)) { error = "Can't read stone types."; + pDF = 0; finish(0); } @@ -269,6 +289,7 @@ main(int argc, char *argv[]) if(!DF.ReadGeology( layerassign )) { error = "Can't read local geology."; + pDF = 0; finish(0); } @@ -283,6 +304,7 @@ main(int argc, char *argv[]) // walk the map! for (;;) { + DF.Resume(); int c = getch(); /* refresh, accept single keystroke of input */ clrscr(); /* process the command keystroke */ @@ -371,8 +393,10 @@ main(int argc, char *argv[]) { if(vein != -1 && vein < veinVector.size()) { - string str = getGCCClassName(p, veinVector[vein].vtable); - if(str == "34block_square_event_frozen_liquidst") + //string str = getGCCClassName(p, veinVector[vein].vtable); + string className = p->readClassName(veinVector[vein].vtable); + //string str = "34block_square_event_frozen_liquidst"; + if(className == "block_square_event_frozen_liquid") { t_frozenliquidvein frozen; uint32_t size = sizeof(t_frozenliquidvein); @@ -391,7 +415,7 @@ main(int argc, char *argv[]) } } } - else if (str == "28block_square_event_mineralst") + else if (className == "block_square_event_mineral") { //iterate through vein rows for(uint32_t j = 0;j<16;j++) @@ -411,17 +435,22 @@ main(int argc, char *argv[]) cprintf("%s",stonetypes[veinVector[vein].type].name); } gotoxy(0,51); - cprintf("%s, address 0x%x",str.c_str(),veinVector[vein].address_of); + cprintf("%s, address 0x%x",className.c_str(),veinVector[vein].address_of); } } - DF.Resume(); wrefresh(stdscr); } + pDF = 0; finish(0); } static void finish(int sig) { + // ugly + if(pDF) + { + pDF->Detach(); + } endwin(); if(!error.empty()) { diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index 3c729f790..5821e129c 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -636,4 +636,14 @@ void SHMProcess::writeSTLString(const uint32_t address, const std::string writeS full_barrier ((shm_write_small *)d->my_shm)->pingpong = DFPP_WRITE_STL_STRING; d->waitWhile(DFPP_WRITE_STL_STRING); +} + +string SHMProcess::readClassName (uint32_t vptr) +{ + int typeinfo = readDWord(vptr - 0x4); + int typestring = readDWord(typeinfo + 0x4); + string raw = readCString(typestring); + size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers + size_t end = raw.length(); + return raw.substr(start,end-start - 2); // trim the 'st' from the end } \ No newline at end of file diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index 24cc71cc8..f4b6d670e 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -581,4 +581,13 @@ const string WineProcess::readSTLString (uint32_t offset) string ret = temp; delete temp; return ret; +} + +string WineProcess::readClassName (uint32_t vptr) +{ + int rtti = readDWord(vptr - 0x4); + int typeinfo = readDWord(rtti + 0xC); + string raw = readCString(typeinfo + 0xC); // skips the .?AV + raw.resize(raw.length() - 4);// trim st@@ from end + return raw; } \ No newline at end of file diff --git a/library/DFProcess-linux.cpp b/library/DFProcess-linux.cpp index 5bda864a6..7801520ba 100644 --- a/library/DFProcess-linux.cpp +++ b/library/DFProcess-linux.cpp @@ -526,4 +526,14 @@ const string NormalProcess::readSTLString (uint32_t offset) string ret(temp); delete temp; return ret; +} + +string NormalProcess::readClassName (uint32_t vptr) +{ + int typeinfo = readDWord(vptr - 0x4); + int typestring = readDWord(typeinfo + 0x4); + string raw = readCString(typestring); + size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers + size_t end = raw.length(); + return raw.substr(start,end-start - 2); // trim the 'st' from the end } \ No newline at end of file diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index bccca900c..ec10171dd 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -723,4 +723,13 @@ void SHMProcess::writeSTLString(const uint32_t address, const std::string writeS full_barrier ((shm_write_small *)d->my_shm)->pingpong = DFPP_WRITE_STL_STRING; d->waitWhile(DFPP_WRITE_STL_STRING); +} + +string SHMProcess::readClassName (uint32_t vptr) +{ + int rtti = readDWord(vptr - 0x4); + int typeinfo = readDWord(rtti + 0xC); + string raw = readCString(typeinfo + 0xC); // skips the .?AV + raw.resize(raw.length() - 4);// trim st@@ from end + return raw; } \ No newline at end of file diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index f1780f474..21b4a5b67 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -463,4 +463,13 @@ const string NormalProcess::readSTLString (uint32_t offset) string ret = temp; delete temp; return ret; +} + +string NormalProcess::readClassName (uint32_t vptr) +{ + int rtti = readDWord(vptr - 0x4); + int typeinfo = readDWord(rtti + 0xC); + string raw = readCString(typeinfo + 0xC); // skips the .?AV + raw.resize(raw.length() - 4);// trim st@@ from end + return raw; } \ No newline at end of file diff --git a/library/DFProcess.h b/library/DFProcess.h index 19acbbecd..a48f0d7b3 100644 --- a/library/DFProcess.h +++ b/library/DFProcess.h @@ -96,6 +96,8 @@ namespace DFHack virtual void writeSTLString(const uint32_t address, const std::string writeString) = 0; // read a vector from memory virtual DfVector readVector (uint32_t offset, uint32_t item_size) = 0; + // get class name of an object with rtti/type info + virtual string readClassName(uint32_t vptr) = 0; virtual const std::string readCString (uint32_t offset) = 0; @@ -152,6 +154,8 @@ namespace DFHack void writeSTLString(const uint32_t address, const std::string writeString){}; // read a vector from memory DfVector readVector (uint32_t offset, uint32_t item_size); + // get class name of an object with rtti/type info + string readClassName(uint32_t vptr); const std::string readCString (uint32_t offset); @@ -203,6 +207,8 @@ namespace DFHack void writeSTLString(const uint32_t address, const std::string writeString); // read a vector from memory DfVector readVector (uint32_t offset, uint32_t item_size); + // get class name of an object with rtti/type info + string readClassName(uint32_t vptr); const std::string readCString (uint32_t offset); @@ -254,6 +260,8 @@ namespace DFHack void writeSTLString(const uint32_t address, const std::string writeString){}; // read a vector from memory DfVector readVector (uint32_t offset, uint32_t item_size); + // get class name of an object with rtti/type info + string readClassName(uint32_t vptr); const std::string readCString (uint32_t offset); From 544e37f183c10e623c614607f6b203e87aeb4740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 19 Feb 2010 03:37:16 +0100 Subject: [PATCH 12/16] ForceResume DF on exit of veinlook --- examples/veinlook.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index 4e138cad1..a8ee0bd87 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -449,6 +449,7 @@ static void finish(int sig) // ugly if(pDF) { + pDF->ForceResume(); pDF->Detach(); } endwin(); From a679b26f94220fc1ea9c96147f869f8f9b5f7732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 19 Feb 2010 03:58:40 +0100 Subject: [PATCH 13/16] Fix note address on Linux --- output/Memory.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/output/Memory.xml b/output/Memory.xml index ad3601644..91c4d9e71 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1520,7 +1520,8 @@
0x9374E88
0xC -
0x09332C98
+ +
0x0931EA64
0x2 0x4 0x8 From e31f5a297327fd4cd299901981d93cd6dd780453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 19 Feb 2010 05:28:54 +0100 Subject: [PATCH 14/16] Less SHM terminal spam --- shmserver/shms-proto.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shmserver/shms-proto.cpp b/shmserver/shms-proto.cpp index 25b5810c9..ded5a4959 100644 --- a/shmserver/shms-proto.cpp +++ b/shmserver/shms-proto.cpp @@ -158,7 +158,7 @@ void SHM_Act (void) case DFPP_CL_ERROR: case DFPP_RUNNING: - fprintf(stderr, "no. of waits: %d\n", numwaits); + //fprintf(stderr, "no. of waits: %d\n", numwaits); //MessageBox(0,"Broke out of loop properly","FUN", MB_OK); break; From c827cb6dfc1ee7acaf82f369ae2c3be0900f6e76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 19 Feb 2010 12:37:51 +0100 Subject: [PATCH 15/16] Reduce chaos in precompiled SHM libs --- {shmserver => precompiled/linux}/df-hacked | 3 +-- precompiled/{ => linux}/libdfconnect.so | Bin precompiled/{ => windows}/SDL.dll | Bin shmserver/dfconnect.so | Bin 12100 -> 0 bytes 4 files changed, 1 insertion(+), 2 deletions(-) rename {shmserver => precompiled/linux}/df-hacked (89%) rename precompiled/{ => linux}/libdfconnect.so (100%) rename precompiled/{ => windows}/SDL.dll (100%) delete mode 100755 shmserver/dfconnect.so diff --git a/shmserver/df-hacked b/precompiled/linux/df-hacked similarity index 89% rename from shmserver/df-hacked rename to precompiled/linux/df-hacked index bf56b33e2..f9c3a3351 100755 --- a/shmserver/df-hacked +++ b/precompiled/linux/df-hacked @@ -9,6 +9,5 @@ if [ $? -eq 0 ]; then mv libs/libSDL* unused_libs/ fi export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"./libs" # Update library search path. -export LD_PRELOAD="./libs/dfconnect.so" # Hack DF! +export LD_PRELOAD="./libs/libdfconnect.so" # Hack DF! ./dwarfort.exe $* # Go, go, go! :) - diff --git a/precompiled/libdfconnect.so b/precompiled/linux/libdfconnect.so similarity index 100% rename from precompiled/libdfconnect.so rename to precompiled/linux/libdfconnect.so diff --git a/precompiled/SDL.dll b/precompiled/windows/SDL.dll similarity index 100% rename from precompiled/SDL.dll rename to precompiled/windows/SDL.dll diff --git a/shmserver/dfconnect.so b/shmserver/dfconnect.so deleted file mode 100755 index ee1579718e289fc9840a34cebd427f5df61230f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12100 zcmeHNe{ht?dEPr6LIwe{Dq~|4`)n(&JT_NJRzSGK7U%~*EHDAd#t{4Cba&ESIo+M_ zz7xWOr^p{7I$y5Q1llm;v_tFuk+g1O2bv}&ozRFz!<2SBV0YA7o>3h_PqAv_6sN>? zxjxVCx2I2s>&Z;}r}pN(cb|RVeRsdzclZ0T@9(yEcDP(Fp;MVC6GT%LLN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+O5iCtE$5waU#ozfacC_i`a4Q+umq<|Ft5WIH}^G%oU8Yb9hm(&3G9qZ zJI(s`cr(uKC&11)yYs+YFHDTHn*feF@Y}%7xVFo{&N#gHft_)6{|W50_Yts8?B5-Z zJ^CKtH4aSqM&hNjad}-O@?Ky*yD%|MPXv-?%0w8OFMz6c~}WSp$%8Oo z=W5~WTmxzbtpzpI^RIz_jr@Cve@*=R0{^JqK>dbh(e@->6ncH18mNb(x5qcE?=&9o z=-AobWpu6I(AmyG4W{Bo*dGf<5xA&ESYK^qb@OT;j_-^_z%aw<*gjv+pfK8=+O~e{ z=GHk8jVgArrDZl+Z%)YKtbk#9rGb>67A+}XXkOg`68^I@<$AL^42gwuD1 Date: Sat, 20 Feb 2010 01:12:55 +0100 Subject: [PATCH 16/16] Added block dump function to veinlook --- examples/veinlook.cpp | 89 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 16 deletions(-) diff --git a/examples/veinlook.cpp b/examples/veinlook.cpp index a8ee0bd87..7084f1092 100644 --- a/examples/veinlook.cpp +++ b/examples/veinlook.cpp @@ -1,7 +1,9 @@ #include #include // for memset #include +#include #include +#include #include #include using namespace std; @@ -182,27 +184,52 @@ int pickColor(int tiletype) case FIRE: return COLOR_RED; } -} -string getGCCClassName (Process * p, uint32_t vptr) -{ - int typeinfo = p->readDWord(vptr - 0x4); - int typestring = p->readDWord(typeinfo + 0x4); - string raw = p->readCString(typestring); - size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers - size_t end = raw.length(); - return raw.substr(start,end-start - 2); // trim the 'st' from the end } -string getMSVCClassName (Process * p, uint32_t vptr) +/* +address = absolute address of dump start +length = length in bytes +*/ +void hexdump (DFHack::API& DF, uint32_t address, uint32_t length, int filenum) { - int rtti = p->readDWord(vptr - 0x4); - int typeinfo = p->readDWord(rtti + 0xC); - string raw = p->readCString(typeinfo + 0xC); // skips the .?AV - raw.resize(raw.length() - 4);// trim st@@ from end - return raw; + uint32_t reallength; + uint32_t lines; + lines = (length / 16) + 1; + reallength = lines * 16; + char *buf = new char[reallength]; + ofstream myfile; + + string name = "hexdump"; + name += filenum; + name+= ".txt"; + + myfile.open (name.c_str()); + + DF.ReadRaw(address, reallength, (uint8_t *) buf); + for (int i = 0; i < lines; i++) + { + // leading offset + myfile << "0x" << hex << setw(4) << i*16 << " "; + // groups + for(int j = 0; j < 4; j++) + { + // bytes + for(int k = 0; k < 4; k++) + { + int idx = i * 16 + j * 4 + k; + + myfile << hex << setw(2) << int(static_cast(buf[idx])) << " "; + } + myfile << " "; + } + myfile << endl; + } + delete buf; + myfile.close(); } + main(int argc, char *argv[]) { /* initialize your non-curses data structures here */ @@ -299,11 +326,16 @@ main(int argc, char *argv[]) int cursorZ = z_max/2 - 1; - + bool dig = false; + bool dump = false; int vein = 0; + int filenum = 0; + uint32_t blockaddr = 0; // walk the map! for (;;) { + dig = false; + dump = false; DF.Resume(); int c = getch(); /* refresh, accept single keystroke of input */ clrscr(); @@ -331,6 +363,12 @@ main(int argc, char *argv[]) case '+': vein ++; break; + case 'd': + dig = true; + break; + case 'o': + dump = true; + break; case '-': vein --; break; @@ -359,6 +397,14 @@ main(int argc, char *argv[]) { for(int y = 0; y < 16; y++) { + if(dig) + { + if(tileTypeTable[tiletypes[x][y]].c == WALL && tileTypeTable[tiletypes[x][y]].m == VEIN + || tileTypeTable[tiletypes[x][y]].c == TREE_OK || tileTypeTable[tiletypes[x][y]].c == TREE_DEAD) + { + designations[x][y].bits.dig = designation_default; + } + } int color = COLOR_BLACK; color = pickColor(tiletypes[x][y]); if(designations[x][y].bits.hidden) @@ -373,8 +419,17 @@ main(int argc, char *argv[]) } } } + if(i == 0 && j == 0) { + blockaddr = DF.getBlockPtr(cursorX+i,cursorY+j,cursorZ); + if(dump) + { + hexdump(DF,blockaddr,0x1DB8,filenum); + filenum++; + } + if(dig) + DF.WriteDesignations(cursorX+i,cursorY+j,cursorZ, (uint32_t *) designations); veinVector.clear(); DF.ReadVeins(cursorX+i,cursorY+j,cursorZ,veinVector); } @@ -438,6 +493,8 @@ main(int argc, char *argv[]) cprintf("%s, address 0x%x",className.c_str(),veinVector[vein].address_of); } } + gotoxy (0,53); + cprintf("block address 0x%x",blockaddr); wrefresh(stdscr); } pDF = 0;