From 4cfc12b52b120688f7a32ad770743507460336a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 3 Apr 2011 00:15:47 +0200 Subject: [PATCH] Engravings module. --- Memory.xml | 32 ++++-- library/CMakeLists.txt | 2 + library/DFContext.cpp | 1 + library/include/DFHack.h | 1 + library/include/dfhack/DFContext.h | 4 + library/include/dfhack/modules/Engravings.h | 72 ++++++++++++ library/modules/Engravings.cpp | 115 ++++++++++++++++++++ library/private/ContextShared.h | 2 + library/private/ModuleFactory.h | 1 + tools/examples/CMakeLists.txt | 3 + tools/examples/engravingdump.cpp | 78 +++++++++++++ 11 files changed, 304 insertions(+), 7 deletions(-) create mode 100644 library/include/dfhack/modules/Engravings.h create mode 100644 library/modules/Engravings.cpp create mode 100644 tools/examples/engravingdump.cpp diff --git a/Memory.xml b/Memory.xml index da19ec4fa..dc596906b 100644 --- a/Memory.xml +++ b/Memory.xml @@ -891,6 +891,9 @@
+ +
+
@@ -2155,7 +2158,11 @@ - Engravings: 0x16B0A78 + + +
+ + .-"""-. ' \ @@ -2694,7 +2701,6 @@
-
@@ -2746,6 +2752,7 @@ one of those: 0x944c3c8 0x944c3d4 +
@@ -2770,7 +2777,7 @@ --> - +
@@ -2785,7 +2792,6 @@
-
@@ -2804,9 +2810,21 @@ - - Engravings: 0x93f7918 - there are some possibly related vectors right next to it. + + +
+ there are some possibly related vectors right next to it. + + + + +
+
+
+
+
+ + diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 91ce62058..a04766405 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -42,6 +42,7 @@ include/dfhack/extra/MapExtras.h include/dfhack/modules/Buildings.h include/dfhack/modules/Constructions.h include/dfhack/modules/Creatures.h +include/dfhack/modules/Engravings.h include/dfhack/modules/Gui.h include/dfhack/modules/Items.h include/dfhack/modules/Maps.h @@ -92,6 +93,7 @@ depends/tinyxml/tinyxmlparser.cpp modules/Buildings.cpp modules/Constructions.cpp modules/Creatures.cpp +modules/Engravings.cpp modules/Gui.cpp modules/Items.cpp modules/Maps.cpp diff --git a/library/DFContext.cpp b/library/DFContext.cpp index 4c56185da..3dc6df74a 100644 --- a/library/DFContext.cpp +++ b/library/DFContext.cpp @@ -155,6 +155,7 @@ TYPE * Context::get##TYPE() \ } MODULE_GETTER(Creatures); +MODULE_GETTER(Engravings); MODULE_GETTER(Maps); MODULE_GETTER(Gui); MODULE_GETTER(WindowIO); diff --git a/library/include/DFHack.h b/library/include/DFHack.h index 3bd1bbeda..2cebc31a5 100644 --- a/library/include/DFHack.h +++ b/library/include/DFHack.h @@ -29,6 +29,7 @@ // DFHack modules #include "dfhack/modules/Buildings.h" +#include "dfhack/modules/Engravings.h" #include "dfhack/modules/Materials.h" #include "dfhack/modules/Constructions.h" #include "dfhack/modules/Creatures.h" diff --git a/library/include/dfhack/DFContext.h b/library/include/dfhack/DFContext.h index 32a3f1f8b..c7f8e53b1 100644 --- a/library/include/dfhack/DFContext.h +++ b/library/include/dfhack/DFContext.h @@ -29,6 +29,7 @@ distribution. namespace DFHack { class Creatures; + class Engravings; class Maps; class Gui; class World; @@ -84,6 +85,9 @@ namespace DFHack /// get the creatures module Creatures * getCreatures(); + /// get the engravings module + Engravings * getEngravings(); + /// get the maps module Maps * getMaps(); diff --git a/library/include/dfhack/modules/Engravings.h b/library/include/dfhack/modules/Engravings.h new file mode 100644 index 000000000..c0bd82f1c --- /dev/null +++ b/library/include/dfhack/modules/Engravings.h @@ -0,0 +1,72 @@ +#ifndef CL_MOD_ENGRAVINGS +#define CL_MOD_ENGRAVINGS +/* +* DF engravings +*/ +#include "dfhack/DFExport.h" +#include "dfhack/DFModule.h" + +/** + * \defgroup grp_engraving Engraving module parts + * @ingroup grp_modules + */ +namespace DFHack +{ + /** + * type the engraving is made of + * \ingroup grp_engraving + */ + struct t_engraving + { + //0 + int32_t artistIdx; /*!< Index of the artist in some global vector */ + // 4 + int32_t unknownIdx; + // 8 + uint32_t quality; // from 0 to 5 + // C + uint16_t x; /*!< X coordinate */ + uint16_t y; /*!< Y coordinate */ + // 10 + uint16_t z; /*!< Z coordinate */ + uint16_t padding; /*!< Could be used for hiding values. */ + // 14 + uint32_t flags; // 0x20 = hide symbol + // 18 + uint32_t display_character; // really? 4 bytes for that? + // 1C + uint32_t type; // possibly an enum, decides what vectors to use for imagery + // 20 + uint32_t subtype_idx; // index in a vector kind of deal related to previous value + }; + /** + * structure for holding a DF engraving + * \ingroup grp_engraving + */ + struct dfh_engraving + { + t_engraving s; + uint32_t origin; + }; + class DFContextShared; + /** + * The Engravings module - allows reading engravings :D + * \ingroup grp_modules + * \ingroup grp_engraving + */ + class DFHACK_EXPORT Engravings : public Module + { + public: + Engravings(DFContextShared * d); + ~Engravings(); + bool Start(uint32_t & numEngravings); + bool Read (const uint32_t index, dfh_engraving & engr); + bool Write (const dfh_engraving & engr); + bool Finish(); + + private: + struct Private; + Private *d; + }; +} +#endif diff --git a/library/modules/Engravings.cpp b/library/modules/Engravings.cpp new file mode 100644 index 000000000..fab318dc0 --- /dev/null +++ b/library/modules/Engravings.cpp @@ -0,0 +1,115 @@ +/* +www.sourceforge.net/projects/dfhack +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "Internal.h" +#include "ContextShared.h" + +#include "dfhack/VersionInfo.h" +#include "dfhack/DFProcess.h" +#include "dfhack/DFVector.h" +#include "dfhack/DFTypes.h" +#include "dfhack/modules/Engravings.h" +#include "ModuleFactory.h" + +using namespace DFHack; + +struct Engravings::Private +{ + uint32_t engraving_vector; + // translation + DfVector * p_engr; + + DFContextShared *d; + Process * owner; + bool Inited; + bool Started; +}; + +Module* DFHack::createEngravings(DFContextShared * d) +{ + return new Engravings(d); +} + +Engravings::Engravings(DFContextShared * d_) +{ + d = new Private; + d->d = d_; + d->owner = d_->p; + d->p_engr = 0; + d->Inited = d->Started = false; + VersionInfo * mem = d->d->offset_descriptor; + d->engraving_vector = mem->getGroup("Engravings")->getAddress ("vector"); + d->Inited = true; +} + +Engravings::~Engravings() +{ + if(d->Started) + Finish(); + delete d; +} + +bool Engravings::Start(uint32_t & numengravings) +{ + d->p_engr = new DfVector (d->owner, d->engraving_vector); + numengravings = d->p_engr->size(); + d->Started = true; + return true; +} + + +bool Engravings::Read (const uint32_t index, dfh_engraving & engraving) +{ + if(!d->Started) return false; + + // read pointer from vector at position + uint32_t temp = d->p_engr->at (index); + + //read construction from memory + d->owner->read (temp, sizeof (t_engraving), (uint8_t *) &(engraving.s)); + + // transform + engraving.origin = temp; + return true; +} + +bool Engravings::Write (const dfh_engraving & engraving) +{ + if(!d->Started) return false; + //write engraving to memory + d->owner->write (engraving.origin, sizeof (t_engraving), (uint8_t *) &(engraving.s)); + return true; +} + +bool Engravings::Finish() +{ + if(d->p_engr) + { + delete d->p_engr; + d->p_engr = NULL; + } + d->Started = false; + return true; +} + diff --git a/library/private/ContextShared.h b/library/private/ContextShared.h index 18b9ea798..e9485e013 100644 --- a/library/private/ContextShared.h +++ b/library/private/ContextShared.h @@ -34,6 +34,7 @@ namespace DFHack class Module; class Creatures; + class Engravings; class Maps; class Gui; class World; @@ -74,6 +75,7 @@ namespace DFHack struct { Creatures * pCreatures; + Engravings * pEngravings; Maps * pMaps; Gui * pPosition; // blerp Gui * pGui; diff --git a/library/private/ModuleFactory.h b/library/private/ModuleFactory.h index be6be3799..309a4d86a 100644 --- a/library/private/ModuleFactory.h +++ b/library/private/ModuleFactory.h @@ -30,6 +30,7 @@ namespace DFHack class Module; class DFContextShared; Module* createCreatures(DFContextShared * d); + Module* createEngravings(DFContextShared * d); Module* createGui(DFContextShared * d); Module* createWindowIO(DFContextShared * d); Module* createWorld(DFContextShared * d); diff --git a/tools/examples/CMakeLists.txt b/tools/examples/CMakeLists.txt index 81c14bb23..b126a493c 100644 --- a/tools/examples/CMakeLists.txt +++ b/tools/examples/CMakeLists.txt @@ -18,6 +18,9 @@ ENDIF() # buildingsdump - dump buildings and their raw data filtered by type DFHACK_TOOL(dfbuildingsdump buildingsdump.cpp) +# constructiondump - dump engravings! +DFHACK_TOOL(dfengravingdump engravingdump.cpp) + # constructiondump - dump constructions! DFHACK_TOOL(dfconstructiondump construction_dump.cpp) diff --git a/tools/examples/engravingdump.cpp b/tools/examples/engravingdump.cpp new file mode 100644 index 000000000..1b003bbc7 --- /dev/null +++ b/tools/examples/engravingdump.cpp @@ -0,0 +1,78 @@ +// Just show some position data + +#include +#include +#include +#include +#include +#include +#include +#include + +#define DFHACK_WANT_MISCUTILS +#include +using namespace DFHack; + +int main (int numargs, const char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context* DF; + try + { + DF = DFMgr.getSingleContext(); + DF->Attach(); + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + DFHack::Gui *Gui = DF->getGui(); + + DFHack::Engravings *Cons = DF->getEngravings(); + uint32_t numEngr; + Cons->Start(numEngr); + + int32_t cx, cy, cz; + Gui->getCursorCoords(cx,cy,cz); + if(cx != -30000) + { + dfh_engraving engraved; + t_engraving &data = engraved.s; + for(uint32_t i = 0; i < numEngr; i++) + { + Cons->Read(i,engraved); + if(cx == data.x && cy == data.y && cz == data.z) + { + printf("Engraving %d/%d/%d @ 0x%x\n", data.x, data.y, data.z, engraved.origin); + // inorganic stuff - we can recognize that + printf("type %d, index %d, character %c\n",data.type, data.subtype_idx, data.display_character); + hexdump(DF,engraved.origin,2); + } + } + } + else + { + dfh_engraving engraved; + t_engraving &data = engraved.s; + for(uint32_t i = 0; i < numEngr; i++) + { + Cons->Read(i,engraved); + { + printf("Engraving %d/%d/%d @ 0x%x\n", data.x, data.y, data.z, engraved.origin); + // inorganic stuff - we can recognize that + printf("type %d, index %d, character %c\n",data.type, data.subtype_idx, data.display_character); + hexdump(DF,engraved.origin,2); + } + } + } + #ifndef LINUX_BUILD + cout << "Done. Press any key to continue" << endl; + cin.ignore(); + #endif + return 0; +}