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 zcmb<-^>JflWMqH=W(H;k5bps81A_?z14Dr#M8y1g^(S>3=AO5 z3gQYdfaPzi(KQ4!U&l+D?7N`?)>i9+53_2)#dkmY;tinDVAR^U%tA^9%?O|N`$i@ zVOE322gL_W2o&DhFb*{QA0hEUVGc@1Fd+~>55|GU$$m8c4>W!$5+4+2QAm7{dCW)- z0`Wm%0#l;Iz`*b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3L-$t4MFM+Ef`$F^@>u{^y0BC)Qflb@pp3ciT8JN3w8~O4{>zzagAq)k54JikIzWV zOUX%Ph=+tQ%(t0l7G`?ssU`6R$?+u_rFq$UNfiw7E|GqYzMjq~D;gnd7abfBtMyQp zEFvU8%k 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;