diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index f331c10d2..127266adb 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -694,6 +694,8 @@
+
+
@@ -1452,6 +1454,10 @@
+ +
+
+ diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index 8e8e3c1f5..20b33a9db 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -637,4 +637,4 @@ string WineProcess::readClassName (uint32_t vptr) string raw = readCString(typeinfo + 0xC); // skips the .?AV raw.resize(raw.length() - 2);// trim @@ from end return raw; -} +} \ No newline at end of file diff --git a/library/DFProcess-windows-SHM.cpp b/library/DFProcess-windows-SHM.cpp index 9742ceeca..7941f8c73 100644 --- a/library/DFProcess-windows-SHM.cpp +++ b/library/DFProcess-windows-SHM.cpp @@ -929,6 +929,16 @@ string SHMProcess::readClassName (uint32_t vptr) return raw; } +string SHMProcess::getPath() +{ + HMODULE hmod; + DWORD junk; + char String[255]; + HANDLE hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, d->process_ID ); //get the handle from the process ID + EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk); //get the module from the handle + GetModuleFileNameEx(hProcess,hmod,String,sizeof(String)); //get the filename from the module + return(string(String)); +} // get module index by name and version. bool 0 = error bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index a658b49a7..697558c5b 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -505,3 +505,12 @@ string NormalProcess::readClassName (uint32_t vptr) raw.resize(raw.length() - 2);// trim @@ from end return raw; } +string NormalProcess::getPath() +{ + HMODULE hmod; + DWORD junk; + char String[255]; + EnumProcessModules(d->my_handle, &hmod, 1 * sizeof(HMODULE), &junk); //get the module from the handle + GetModuleFileNameEx(d->my_handle,hmod,String,sizeof(String)); //get the filename from the module + return(string(String)); +} \ No newline at end of file diff --git a/library/include/dfhack/DFProcess.h b/library/include/dfhack/DFProcess.h index 282e1b95f..8918c1584 100644 --- a/library/include/dfhack/DFProcess.h +++ b/library/include/dfhack/DFProcess.h @@ -163,6 +163,8 @@ namespace DFHack virtual VersionInfo *getDescriptor() = 0; /// get the DF Process ID virtual int getPID() = 0; + /// get the DF Process FilePath + virtual std::string getPath() = 0; /// get module index by name and version. bool 1 = error virtual bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) = 0; /// get the SHM start if available @@ -230,6 +232,7 @@ namespace DFHack void getMemRanges(std::vector & ranges ); VersionInfo *getDescriptor(); int getPID(); + std::string getPath(); // get module index by name and version. bool 1 = error bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;}; // get the SHM start if available @@ -295,6 +298,7 @@ namespace DFHack void getMemRanges(std::vector & ranges ); VersionInfo *getDescriptor(); int getPID(); + std::string getPath(); // get module index by name and version. bool 1 = error bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT); // get the SHM start if available @@ -364,6 +368,7 @@ namespace DFHack // get the SHM start if available char * getSHMStart (void){return 0;}; bool SetAndWait (uint32_t state){return false;}; + std::string getPath() {return std::string()}; //FIXME should be pretty trival }; #endif } diff --git a/library/include/dfhack/modules/Gui.h b/library/include/dfhack/modules/Gui.h index 6ac91f35c..64cf06d97 100644 --- a/library/include/dfhack/modules/Gui.h +++ b/library/include/dfhack/modules/Gui.h @@ -28,6 +28,10 @@ namespace DFHack bool ReadViewScreen(t_viewscreen &); /// read the DF menu state (designation menu ect) uint32_t ReadMenuState(); + /// read the current tileset file used in DF + string ReadCurrentTileSetFilename(); + /// read the current color file used in DF + string ReadCurrentColorsFilename(); private: struct Private; diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 177a00467..15b5a0959 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -44,6 +44,10 @@ struct Gui::Private bool ViewScreeInited; uint32_t current_menu_state_offset; bool MenuStateInited; + uint32_t tileset_filename_offset; + bool TilesetFilenameInited; + uint32_t colors_filename_offset; + bool ColorsFilenameInited; DFContextShared *d; Process * owner; }; @@ -73,6 +77,18 @@ Gui::Gui(DFContextShared * _d) d->ViewScreeInited = true; } catch(exception &){}; + try + { + d->tileset_filename_offset = OG_Gui->getAddress ("tileset_filename"); + d->TilesetFilenameInited = true; + } + catch(exception &){}; + try + { + d->colors_filename_offset = OG_Gui->getAddress ("colors_filename"); + d->ColorsFilenameInited = true; + } + catch(exception &){}; d->Started = true; } @@ -129,3 +145,15 @@ bool Gui::ReadViewScreen (t_viewscreen &screen) } return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type); } +string Gui::ReadCurrentTileSetFilename() +{ + if(d->TilesetFilenameInited) + return(d->owner->readCString(d->tileset_filename_offset)); + return ""; +} +string Gui::ReadCurrentColorsFilename() +{ + if(d->ColorsFilenameInited) + return(d->owner->readCString(d->colors_filename_offset)); + return ""; +} \ No newline at end of file diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index ab21e3c2d..f21d9170c 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -60,6 +60,13 @@ TARGET_LINK_LIBRARIES(dfcatsplosion dfhack) ADD_EXECUTABLE(dfcopypaste copypaste.cpp) TARGET_LINK_LIBRARIES(dfcopypaste dfhack) +# paths +# Author: belal +# dumps the current path to the DF exe, as well as the relative paths to the +# current tileset and color files +ADD_EXECUTABLE(dfpaths paths.cpp) +TARGET_LINK_LIBRARIES(dfpaths dfhack) + # this needs the C bindings IF(BUILD_DFHACK_C_BINDINGS) # for trying out some 'stuff' diff --git a/tools/playground/paths.cpp b/tools/playground/paths.cpp new file mode 100644 index 000000000..5ae3cd37a --- /dev/null +++ b/tools/playground/paths.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +#include +using namespace DFHack; + +int main () +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); + try + { + DF->Attach(); + } + catch (exception& e) + { + cerr << e.what() << endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + DFHack::Process * Process = DF->getProcess(); + DFHack::Gui * gui = DF->getGui(); + cout << Process->getPath() << endl; + cout << gui->ReadCurrentTileSetFilename() << "\n" << gui->ReadCurrentColorsFilename() << endl; + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +} \ No newline at end of file