diff --git a/dfhack/DFHackAPI.cpp b/dfhack/DFHackAPI.cpp index a1dbeddad..b85d9663f 100644 --- a/dfhack/DFHackAPI.cpp +++ b/dfhack/DFHackAPI.cpp @@ -397,41 +397,6 @@ void API::FinishReadSettlements() d->settlementsInited = false; } - -bool API::InitReadHotkeys( ) -{ - try - { - 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"); - - d->hotkeyInited = true; - return true; - } - catch (Error::MissingMemoryDefinition&) - { - d->hotkeyInited = false; - throw; - } -} -bool API::ReadHotkeys(t_hotkey hotkeys[]) -{ - if (!d->hotkeyInited) return false; - 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; -} - - bool API::getItemIndexesInBox(vector &indexes, const uint16_t x1, const uint16_t y1, const uint16_t z1, const uint16_t x2, const uint16_t y2, const uint16_t z2) diff --git a/dfhack/modules/Position.cpp b/dfhack/modules/Position.cpp index 849f1013e..c4e56b37d 100644 --- a/dfhack/modules/Position.cpp +++ b/dfhack/modules/Position.cpp @@ -40,9 +40,15 @@ struct Position::Private uint32_t cursor_xyz_offset; uint32_t window_dims_offset; + uint32_t hotkey_start; + uint32_t hotkey_mode_offset; + uint32_t hotkey_xyz_offset; + uint32_t hotkey_size; + APIPrivate *d; bool Inited; bool Started; + bool StartedHotkeys; //uint32_t biome_stuffs; //vector v_geology[eBiomeCount]; }; @@ -51,36 +57,47 @@ Position::Position(APIPrivate * d_) { d = new Private; d->d = d_; - d->Inited = d->Started = false; - memory_info * mem = d->d->offset_descriptor; - d->window_x_offset = mem->getAddress ("window_x"); - d->window_y_offset = mem->getAddress ("window_y"); - d->window_z_offset = mem->getAddress ("window_z"); - d->cursor_xyz_offset = mem->getAddress ("cursor_xyz"); - d->window_dims_offset = mem->getAddress ("window_dims"); - d->Inited = d->Started = true; + d->Inited = true; + d->StartedHotkeys = d->Started = false; + memory_info * mem; + try + { + mem = d->d->offset_descriptor; + d->window_x_offset = mem->getAddress ("window_x"); + d->window_y_offset = mem->getAddress ("window_y"); + d->window_z_offset = mem->getAddress ("window_z"); + d->cursor_xyz_offset = mem->getAddress ("cursor_xyz"); + d->window_dims_offset = mem->getAddress ("window_dims"); + d->Started = true; + + d->hotkey_start = mem->getAddress("hotkey_start"); + d->hotkey_mode_offset = mem->getOffset ("hotkey_mode"); + d->hotkey_xyz_offset = mem->getOffset("hotkey_xyz"); + d->hotkey_size = mem->getHexValue("hotkey_size"); + d->StartedHotkeys = true; + } + catch(exception &){}; } Position::~Position() { delete d; } -/* -bool Position::InitViewAndCursor() + +bool Position::ReadHotkeys(t_hotkey hotkeys[]) { - try - { - - d->Inited = true; - return true; - } - catch (Error::MissingMemoryDefinition&) + if (!d->StartedHotkeys) return false; + uint32_t currHotkey = d->hotkey_start; + for(uint32_t i = 0 ; i < NUM_HOTKEYS ;i++) { - d->cursorWindowInited = false; - throw; + g_pProcess->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; } -*/ + bool Position::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { if (!d->Inited) return false; diff --git a/dfhack/private/APIPrivate.h b/dfhack/private/APIPrivate.h index 9f9781847..645b8396d 100644 --- a/dfhack/private/APIPrivate.h +++ b/dfhack/private/APIPrivate.h @@ -83,10 +83,6 @@ namespace DFHack 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 settlement_name_offset; uint32_t settlement_world_xy_offset; diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 155e4ec5c..a00ac1662 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -44,8 +44,8 @@ TARGET_LINK_LIBRARIES(dfsuspend dfhack) # hotkeynotedump - dumps the hotkeys and notes for the loaded map # Author: belal -# ADD_EXECUTABLE(dfhotkeynotedump hotkeynotedump.cpp) -# TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack) +ADD_EXECUTABLE(dfhotkeynotedump hotkeynotedump.cpp) +TARGET_LINK_LIBRARIES(dfhotkeynotedump dfhack) # findnameindexes # Author: belal diff --git a/examples/hotkeynotedump.cpp b/examples/hotkeynotedump.cpp index c23f38d8a..e195dbfa1 100644 --- a/examples/hotkeynotedump.cpp +++ b/examples/hotkeynotedump.cpp @@ -9,11 +9,11 @@ using namespace std; #include #include #include +#include int main (void) { - vector creaturestypes; DFHack::API DF("Memory.xml"); try { @@ -29,18 +29,17 @@ int main (void) } DFHack::memory_info * mem = DF.getMemoryInfo(); + DFHack::Position * Pos = DF.getPosition(); // 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++) { @@ -50,15 +49,16 @@ int main (void) "\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); + Pos->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.FinishReadNotes(); DF.Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; diff --git a/output/Memory.xml b/output/Memory.xml index 2535a8e59..a35627451 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -3181,6 +3181,12 @@ map_data_1b60_offset 0x1B9c :( + Hotkeys + ======= +
0x01476ecc
+ 0x1C + 0x20 + 0x2C