diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index 702591826..e621023a6 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -1105,8 +1105,8 @@ bool API::InitViewAndCursor() { d->window_x_offset = d->offset_descriptor->getAddress("window_x"); - d->window_y_offset = d->offset_descriptor->getAddress("window_x"); - d->window_z_offset = d->offset_descriptor->getAddress("window_x"); + d->window_y_offset = d->offset_descriptor->getAddress("window_y"); + d->window_z_offset = d->offset_descriptor->getAddress("window_z"); d->cursor_xyz_offset = d->offset_descriptor->getAddress("cursor_xyz"); if(d->window_x_offset && d->window_y_offset && d->window_z_offset) { @@ -1119,35 +1119,40 @@ bool API::InitViewAndCursor() } } -void API::getViewCoords (uint32_t &x, uint32_t &y, uint32_t &z) +bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z) { assert(d->cursorWindowInited); - MreadDWord(d->window_x_offset,x); - MreadDWord(d->window_y_offset,y); - MreadDWord(d->window_z_offset,z); + MreadDWord(d->window_x_offset,(uint32_t &)x); + MreadDWord(d->window_y_offset,(uint32_t &)y); + MreadDWord(d->window_z_offset,(uint32_t &)z); + return true; } //FIXME: confine writing of coords to map bounds? -void API::setViewCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z) +bool API::setViewCoords (const int32_t &x, const int32_t &y, const int32_t &z) { assert(d->cursorWindowInited); - MwriteDWord(d->window_x_offset,x); - MwriteDWord(d->window_y_offset,y); - MwriteDWord(d->window_z_offset,z); + MwriteDWord(d->window_x_offset,(uint32_t &)x); + MwriteDWord(d->window_y_offset,(uint32_t &)y); + MwriteDWord(d->window_z_offset,(uint32_t &)z); + return true; } -void API::getCursorCoords (uint32_t &x, uint32_t &y, uint32_t &z) +bool API::getCursorCoords (int32_t &x, int32_t &y, int32_t &z) { assert(d->cursorWindowInited); - uint32_t coords[3]; - Mread(d->cursor_xyz_offset,3*sizeof(uint32_t),(uint8_t *)coords); + int32_t coords[3]; + Mread(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords); x = coords[0]; y = coords[1]; z = coords[2]; + if(x == -30000) return false; + return true; } //FIXME: confine writing of coords to map bounds? -void API::setCursorCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z) +bool API::setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z) { assert(d->cursorWindowInited); - uint32_t coords[3] = {x,y,z}; - Mwrite(d->cursor_xyz_offset,3*sizeof(uint32_t),(uint8_t *)coords); + int32_t coords[3] = {x,y,z}; + Mwrite(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords); + return true; } \ No newline at end of file diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index eebdf6e8f..e7a8ff72b 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -175,11 +175,11 @@ public: bool InitViewAndCursor(); - void getViewCoords (uint32_t &x, uint32_t &y, uint32_t &z); - void setViewCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z); + 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); - void getCursorCoords (uint32_t &x, uint32_t &y, uint32_t &z); - void setCursorCoords (const uint32_t &x, const uint32_t &y, const uint32_t &z); + bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); + bool setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z); }; } // namespace DFHack diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 1051ba6c7..9b1914a93 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -38,6 +38,9 @@ TARGET_LINK_LIBRARIES(dfattachtest dfhack) ADD_EXECUTABLE(dfmaterialtest materialtest.cpp) TARGET_LINK_LIBRARIES(dfmaterialtest dfhack) +# materialtest - just list the first material of each type +ADD_EXECUTABLE(dfposition position.cpp) +TARGET_LINK_LIBRARIES(dfposition dfhack) IF(UNIX) install(TARGETS @@ -50,6 +53,7 @@ dfcreaturedump dfattachtest dfmaterialtest dfbuildingsdump +dfposition RUNTIME DESTINATION bin ) diff --git a/tools/position.cpp b/tools/position.cpp new file mode 100644 index 000000000..850880942 --- /dev/null +++ b/tools/position.cpp @@ -0,0 +1,45 @@ +// Just show some position data + +#include +#include +#include +#include +#include +using namespace std; + +#include +#include + +int main (void) +{ + DFHack::API DF("Memory.xml"); + if(!DF.Attach()) + { + cerr << "DF not found" << endl; + return 1; + } + + if (DF.InitViewAndCursor()) + { + int32_t x,y,z; + if(DF.getViewCoords(x,y,z)) + cout << "view coords: " << x << "/" << y << "/" << z << endl; + if(DF.getCursorCoords(x,y,z)) + cout << "cursor coords: " << x << "/" << y << "/" << z << endl; + } + else + { + cerr << "cursor and window parameters are unsupported on your version of DF" << endl; + } + + if(!DF.Detach()) + { + cerr << "Can't detach from DF" << endl; + return 1; + } + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} \ No newline at end of file