Add function to get the current working directory of the DF process, as well as offsets for the relative paths of the current tileset and color file, also created a simple program to dump those three things out

develop
belal 2010-09-12 21:36:31 -04:00
parent 294888f84a
commit 040f8f7b7a
9 changed files with 102 additions and 1 deletions

@ -694,6 +694,8 @@
<Address name="current_cursor_creature" description="A vector? of creatures currently under the cursor."/> <Address name="current_cursor_creature" description="A vector? of creatures currently under the cursor."/>
<Address name="current_menu_state" description="A numeric value that describes the state of the current GUI element (switching between menus will change this)."/> <Address name="current_menu_state" description="A numeric value that describes the state of the current GUI element (switching between menus will change this)."/>
<Address name="view_screen" description="Pointer to the current view screen object (GUI screen)."/> <Address name="view_screen" description="Pointer to the current view screen object (GUI screen)."/>
<Address name="tileset_filename" description="String holding the path to the current tileset file"/>
<Address name="colors_filename" description="String holding the path to the current color file"/>
</Group> </Group>
<Group name="Maps" description="Offsets used by the Maps module."> <Group name="Maps" description="Offsets used by the Maps module.">
<Address name="map_data" description="Pointer to the start of the map structure."/> <Address name="map_data" description="Pointer to the start of the map structure."/>
@ -1452,6 +1454,10 @@
<Group name="World"> <Group name="World">
<Address name="current_weather" value="0x14BCDEE" /> <Address name="current_weather" value="0x14BCDEE" />
</Group> </Group>
<Group name="GUI">
<Address name="tileset_filename" value="0xA95BB0" />
<Address name="colors_filename" value="0xA95F8C" />
</Group>
</Offsets> </Offsets>
</Version> </Version>

@ -929,6 +929,16 @@ string SHMProcess::readClassName (uint32_t vptr)
return raw; 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 // get module index by name and version. bool 0 = error
bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) bool SHMProcess::getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT)
{ {

@ -505,3 +505,12 @@ string NormalProcess::readClassName (uint32_t vptr)
raw.resize(raw.length() - 2);// trim @@ from end raw.resize(raw.length() - 2);// trim @@ from end
return raw; 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));
}

@ -163,6 +163,8 @@ namespace DFHack
virtual VersionInfo *getDescriptor() = 0; virtual VersionInfo *getDescriptor() = 0;
/// get the DF Process ID /// get the DF Process ID
virtual int getPID() = 0; virtual int getPID() = 0;
/// get the DF Process FilePath
virtual std::string getPath() = 0;
/// get module index by name and version. bool 1 = error /// get module index by name and version. bool 1 = error
virtual bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) = 0; virtual bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) = 0;
/// get the SHM start if available /// get the SHM start if available
@ -230,6 +232,7 @@ namespace DFHack
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
VersionInfo *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
std::string getPath();
// get module index by name and version. bool 1 = error // 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;}; bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT) { OUTPUT=0; return false;};
// get the SHM start if available // get the SHM start if available
@ -295,6 +298,7 @@ namespace DFHack
void getMemRanges(std::vector<t_memrange> & ranges ); void getMemRanges(std::vector<t_memrange> & ranges );
VersionInfo *getDescriptor(); VersionInfo *getDescriptor();
int getPID(); int getPID();
std::string getPath();
// get module index by name and version. bool 1 = error // get module index by name and version. bool 1 = error
bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT); bool getModuleIndex (const char * name, const uint32_t version, uint32_t & OUTPUT);
// get the SHM start if available // get the SHM start if available
@ -364,6 +368,7 @@ namespace DFHack
// get the SHM start if available // get the SHM start if available
char * getSHMStart (void){return 0;}; char * getSHMStart (void){return 0;};
bool SetAndWait (uint32_t state){return false;}; bool SetAndWait (uint32_t state){return false;};
std::string getPath() {return std::string()}; //FIXME should be pretty trival
}; };
#endif #endif
} }

@ -28,6 +28,10 @@ namespace DFHack
bool ReadViewScreen(t_viewscreen &); bool ReadViewScreen(t_viewscreen &);
/// read the DF menu state (designation menu ect) /// read the DF menu state (designation menu ect)
uint32_t ReadMenuState(); uint32_t ReadMenuState();
/// read the current tileset file used in DF
string ReadCurrentTileSetFilename();
/// read the current color file used in DF
string ReadCurrentColorsFilename();
private: private:
struct Private; struct Private;

@ -44,6 +44,10 @@ struct Gui::Private
bool ViewScreeInited; bool ViewScreeInited;
uint32_t current_menu_state_offset; uint32_t current_menu_state_offset;
bool MenuStateInited; bool MenuStateInited;
uint32_t tileset_filename_offset;
bool TilesetFilenameInited;
uint32_t colors_filename_offset;
bool ColorsFilenameInited;
DFContextShared *d; DFContextShared *d;
Process * owner; Process * owner;
}; };
@ -73,6 +77,18 @@ Gui::Gui(DFContextShared * _d)
d->ViewScreeInited = true; d->ViewScreeInited = true;
} }
catch(exception &){}; 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; d->Started = true;
} }
@ -129,3 +145,15 @@ bool Gui::ReadViewScreen (t_viewscreen &screen)
} }
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type); 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 "";
}

@ -60,6 +60,13 @@ TARGET_LINK_LIBRARIES(dfcatsplosion dfhack)
ADD_EXECUTABLE(dfcopypaste copypaste.cpp) ADD_EXECUTABLE(dfcopypaste copypaste.cpp)
TARGET_LINK_LIBRARIES(dfcopypaste dfhack) 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 # this needs the C bindings
IF(BUILD_DFHACK_C_BINDINGS) IF(BUILD_DFHACK_C_BINDINGS)
# for trying out some 'stuff' # for trying out some 'stuff'

@ -0,0 +1,32 @@
#include <iostream>
using namespace std;
#include <DFHack.h>
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;
}