From b1061d0f949dfa8cc6626352926e5abe27c6ec84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 1 Mar 2011 06:59:23 +0100 Subject: [PATCH] Game mode reading, removed some include paths --- data/Memory-ng.xml | 6 ++++-- library/CMakeLists.txt | 2 -- library/include/dfhack/modules/World.h | 11 ++++++++++- library/modules/World.cpp | 18 +++++++++++++++++- tools/supported/position.cpp | 18 ++++++++++++------ 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 822ee87e4..fb4cabaaf 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -907,6 +907,7 @@
+
@@ -2029,11 +2030,12 @@ 0x16dad88
- +
maybe
- fortress = 0, adventure = 1, arena = 0 0xb4a814 +
+ fortress = 0, adventure = 1, arena = 0, menu and legends = 3 0xb4a814 Game mode: 0xb4a818 . fortress = 0, adventure = 1, arena = 4 0xe2e2a2 seems to be a copy of the first one diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index fdf49f8d3..c38297a8c 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -21,8 +21,6 @@ SET( EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/output CACHE PATH "Output direct include_directories (${CMAKE_SOURCE_DIR}/library/include/) include_directories (${CMAKE_SOURCE_DIR}/library/shm/) -include_directories (${CMAKE_SOURCE_DIR}/library/depends/md5/) -include_directories (${CMAKE_SOURCE_DIR}/library/depends/tinyxml/) include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/) include_directories (${CMAKE_SOURCE_DIR}/library/private/) diff --git a/library/include/dfhack/modules/World.h b/library/include/dfhack/modules/World.h index 7834d4719..a24f70573 100644 --- a/library/include/dfhack/modules/World.h +++ b/library/include/dfhack/modules/World.h @@ -15,6 +15,15 @@ namespace DFHack RAINING, SNOWING }; + enum GameMode + { + Unknown = -1, + Fort = 0, + Adventurer, + Blarg, + Flarg, + Arena + }; class DFContextShared; class DFHACK_EXPORT World : public Module { @@ -31,7 +40,7 @@ namespace DFHack uint32_t ReadCurrentDay(); uint8_t ReadCurrentWeather(); void SetCurrentWeather(uint8_t weather); - + int32_t ReadGameMode(); private: struct Private; Private *d; diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 3e1a670de..d7b86caec 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -49,9 +49,11 @@ struct World::Private bool Inited; bool StartedTime; bool StartedWeather; + bool StartedMode; uint32_t year_offset; uint32_t tick_offset; uint32_t weather_offset; + uint32_t gamemode_offset; DFContextShared *d; Process * owner; }; @@ -62,7 +64,7 @@ World::World(DFContextShared * _d) d = new Private; d->d = _d; d->owner = _d->p; - d->Inited = d->StartedTime = d->StartedWeather = false; + d->Inited = d->StartedTime = d->StartedWeather = d->StartedMode = false; OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World"); try @@ -78,6 +80,12 @@ World::World(DFContextShared * _d) d->StartedWeather = true; } catch(Error::All &){}; + try + { + d->gamemode_offset = OG_World->getAddress( "game_mode" ); + d->StartedMode = true; + } + catch(Error::All &){}; d->Inited = true; } @@ -110,6 +118,14 @@ uint32_t World::ReadCurrentTick() return 0; } +int32_t World::ReadGameMode() +{ + if(d->Inited && d->StartedMode) + return d->owner->readDWord(d->gamemode_offset); + return -1; +} + + // FIX'D according to this: /* World::ReadCurrentMonth and World::ReadCurrentDay diff --git a/tools/supported/position.cpp b/tools/supported/position.cpp index a6383e0ef..ffac17969 100644 --- a/tools/supported/position.cpp +++ b/tools/supported/position.cpp @@ -21,6 +21,7 @@ int main (int argc, char** argv) } DFHack::Position * Position = 0; + DFHack::World * World = 0; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; try @@ -28,6 +29,7 @@ int main (int argc, char** argv) DF = DFMgr.getSingleContext(); DF->Attach(); Position = DF->getPosition(); + World = DF->getWorld(); } catch (exception& e) { @@ -37,17 +39,21 @@ int main (int argc, char** argv) #endif return 1; } + if(World) + { + cout << "Game mode " << World->ReadGameMode() << endl; + } if (Position) { - int32_t x,y,z; - int32_t width,height; + int32_t x,y,z; + int32_t width,height; - if(Position->getViewCoords(x,y,z)) + if(Position->getViewCoords(x,y,z)) cout << "view coords: " << x << "/" << y << "/" << z << endl; - if(Position->getCursorCoords(x,y,z)) + if(Position->getCursorCoords(x,y,z)) cout << "cursor coords: " << x << "/" << y << "/" << z << endl; - if(Position->getWindowSize(width,height)) - cout << "window size : " << width << " " << height << endl; + if(Position->getWindowSize(width,height)) + cout << "window size : " << width << " " << height << endl; } else {