From e71f41fd42ee7daef17c9e8f71e307d198ca120a Mon Sep 17 00:00:00 2001 From: belal Date: Wed, 17 Feb 2010 18:33:08 -0500 Subject: [PATCH 1/3] 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 387e1e879493b30a41b2210eb16e70086da88957 Mon Sep 17 00:00:00 2001 From: belal Date: Wed, 17 Feb 2010 21:08:54 -0500 Subject: [PATCH 2/3] 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 3ac42b79601dd8c796dcf5edc3d4e2a0fa57fad2 Mon Sep 17 00:00:00 2001 From: belal Date: Thu, 18 Feb 2010 09:27:22 -0500 Subject: [PATCH 3/3] 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