From 86577d4f8a2a956acea4d36483e81cd13d7a4fda Mon Sep 17 00:00:00 2001 From: Matthew Cline Date: Wed, 20 Jul 2011 18:26:52 -0700 Subject: [PATCH] Notes module Gets a vector of pointers to note structs --- Memory.xml | 6 ++ library/CMakeLists.txt | 2 + library/Core.cpp | 1 + library/include/dfhack/Core.h | 4 + library/include/dfhack/Types.h | 11 --- library/include/dfhack/modules/Notes.h | 71 +++++++++++++++++ library/modules/Notes.cpp | 102 +++++++++++++++++++++++++ library/private/ModuleFactory.h | 1 + plugins/CMakeLists.txt | 3 +- plugins/notes.cpp | 80 +++++++++++++++++++ 10 files changed, 269 insertions(+), 12 deletions(-) create mode 100644 library/include/dfhack/modules/Notes.h create mode 100644 library/modules/Notes.cpp create mode 100644 plugins/notes.cpp diff --git a/Memory.xml b/Memory.xml index 2904ce038..b662e7676 100644 --- a/Memory.xml +++ b/Memory.xml @@ -1073,6 +1073,9 @@ + +
+ @@ -3142,6 +3145,9 @@
+ +
+ diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 6e4fb586c..b890715e8 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -45,6 +45,7 @@ include/dfhack/modules/Gui.h include/dfhack/modules/Items.h include/dfhack/modules/Maps.h include/dfhack/modules/Materials.h +include/dfhack/modules/Notes.h include/dfhack/modules/Translation.h include/dfhack/modules/Vegetation.h include/dfhack/modules/Vermin.h @@ -75,6 +76,7 @@ modules/Gui.cpp modules/Items.cpp modules/Maps.cpp modules/Materials.cpp +modules/Notes.cpp modules/Translation.cpp modules/Vegetation.cpp modules/Vermin.cpp diff --git a/library/Core.cpp b/library/Core.cpp index d3dcb1038..33ee910d4 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -596,3 +596,4 @@ MODULE_GETTER(Vegetation); MODULE_GETTER(Buildings); MODULE_GETTER(Constructions); MODULE_GETTER(Vermin); +MODULE_GETTER(Notes); diff --git a/library/include/dfhack/Core.h b/library/include/dfhack/Core.h index 26342446c..8ca16714f 100644 --- a/library/include/dfhack/Core.h +++ b/library/include/dfhack/Core.h @@ -49,6 +49,7 @@ namespace DFHack class Buildings; class Constructions; class Vermin; + class Notes; class VersionInfo; class VersionInfoFactory; class PluginManager; @@ -107,6 +108,8 @@ namespace DFHack Constructions * getConstructions(); /// get the vermin module Vermin * getVermin(); + /// get the notes module + Notes * getNotes(); /// sets the current hotkey command bool setHotkeyCmd( std::string cmd ); /// removes the hotkey command and gives it to the caller thread @@ -147,6 +150,7 @@ namespace DFHack Buildings * pBuildings; Constructions * pConstructions; Vermin * pVermin; + Notes * pNotes; } s_mods; std::vector allModules; DFHack::PluginManager * plug_mgr; diff --git a/library/include/dfhack/Types.h b/library/include/dfhack/Types.h index 65246c115..5dc92f749 100644 --- a/library/include/dfhack/Types.h +++ b/library/include/dfhack/Types.h @@ -109,17 +109,6 @@ struct t_effect_df40d //size 40 //#pragma pack(push,4) -struct t_note -{ - char symbol; - uint16_t foreground; - uint16_t background; - char name[128]; - uint16_t x; - uint16_t y; - uint16_t z; -}; - struct t_name { char first_name[128]; diff --git a/library/include/dfhack/modules/Notes.h b/library/include/dfhack/modules/Notes.h new file mode 100644 index 000000000..bb95cd5d8 --- /dev/null +++ b/library/include/dfhack/modules/Notes.h @@ -0,0 +1,71 @@ +#pragma once +#ifndef CL_MOD_NOTES +#define CL_MOD_NOTES +/** + * \defgroup grp_notes In game notes (and routes) + * @ingroup grp_notes + */ +#include "dfhack/Export.h" +#include "dfhack/Module.h" + +#include +#include + +#ifdef __cplusplus +namespace DFHack +{ +#endif + /** + * Game's structure for a note. + * \ingroup grp_notes + */ + struct t_note + { + // First note created has id 0, second has id 1, etc. Not affected + // by lower id notes being deleted. + uint32_t id; + + uint8_t symbol; + uint8_t unk1; + uint16_t foreground; + uint16_t background; + uint16_t unk2; + + std::string name; + std::string text; + + uint16_t x; + uint16_t y; + uint16_t z; + + // Is there more? + }; + +#ifdef __cplusplus + + /** + * The notes module - allows reading DF in-game notes + * \ingroup grp_modules + * \ingroup grp_notes + */ + class DFHACK_EXPORT Notes : public Module + { + public: + Notes(); + ~Notes(); + + bool Finish(); + + // Returns NULL if there's no notes yet. + std::vector* getNotes(); + + private: + struct Private; + Private *d; + + }; + +} +#endif // __cplusplus + +#endif diff --git a/library/modules/Notes.cpp b/library/modules/Notes.cpp new file mode 100644 index 000000000..aeb7902ef --- /dev/null +++ b/library/modules/Notes.cpp @@ -0,0 +1,102 @@ +/* +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 +#include +#include +using namespace std; + +#include "dfhack/VersionInfo.h" +#include "dfhack/Types.h" +#include "dfhack/Error.h" +#include "dfhack/Process.h" +#include "ModuleFactory.h" +#include "dfhack/Core.h" +#include "dfhack/modules/Notes.h" +using namespace DFHack; + +struct Notes::Private +{ + uint32_t notes_vector; + Process * owner; + bool Inited; + bool Started; +}; + +Module* DFHack::createNotes() +{ + return new Notes(); +} + +Notes::Notes() +{ + Core & c = Core::getInstance(); + + d = new Private; + d->owner = c.p; + d->Inited = d->Started = false; + VersionInfo * mem = c.vinfo; + d->Inited = true; + try + { + OffsetGroup * OG_Notes = mem->getGroup("Notes"); + + d->notes_vector = OG_Notes->getAddress("vector"); + } + catch(DFHack::Error::AllMemdef &e) + { + c.con << "Notes not available... " << e.what() << endl; + d->Inited = false; + } +} + +Notes::~Notes() +{ + delete d; +} + +std::vector* Notes::getNotes() +{ + if (!d->Inited) + { + Core & c = Core::getInstance(); + c.con << "Notes not available... " << endl; + return NULL; + } + + uint32_t ptr = d->notes_vector; + + if ( *( (uint32_t*) ptr) == 0) + // Notes vector not set up yet. + return NULL; + + return (std::vector*) ptr; +} + +bool Notes::Finish() +{ + return true; +} diff --git a/library/private/ModuleFactory.h b/library/private/ModuleFactory.h index cd1ef73a2..8a795c0d6 100644 --- a/library/private/ModuleFactory.h +++ b/library/private/ModuleFactory.h @@ -42,5 +42,6 @@ namespace DFHack Module* createConstructions(); Module* createMaps(); Module* createVermin(); + Module* createNotes(); } #endif diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 477dd57ea..beb842584 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -120,4 +120,5 @@ DFHACK_PLUGIN(cleanmap cleanmap.cpp) DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(vdig vdig.cpp) DFHACK_PLUGIN(colonies colonies.cpp) -DFHACK_PLUGIN(itemhacks itemhacks.cpp) \ No newline at end of file +DFHACK_PLUGIN(itemhacks itemhacks.cpp) +DFHACK_PLUGIN(notes notes.cpp) diff --git a/plugins/notes.cpp b/plugins/notes.cpp new file mode 100644 index 000000000..989d3a348 --- /dev/null +++ b/plugins/notes.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include +#include + +using std::vector; +using std::string; +using namespace DFHack; + +DFhackCExport command_result df_notes (Core * c, vector & parameters); + +DFhackCExport const char * plugin_name ( void ) +{ + return "notes"; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("dumpnotes", + "Dumps in-game notes", + df_notes)); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +DFhackCExport command_result df_notes (Core * c, vector & parameters) +{ + Console & con = c->con; + c->Suspend(); + + DFHack::Notes * note_mod = c->getNotes(); + std::vector* note_list = note_mod->getNotes(); + + if (note_list == NULL) + { + con << "No notes yet." << std::endl; + c->Resume(); + return CR_OK; + } + + if (note_list->empty()) + { + con << "All notes deleted." << std::endl; + c->Resume(); + return CR_OK; + } + + + for (size_t i = 0; i < note_list->size(); i++) + { + t_note* note = (*note_list)[i]; + + con.print("Note at: %d/%d/%d\n", note->x, note->y, note->z); + con.print("Note id: %d\n", note->id); + con.print("Note symbol: '%c'\n", note->symbol); + + if (note->name.length() > 0) + con << "Note name: " << (note->name) << std::endl; + if (note->text.length() > 0) + con << "Note text: " << (note->text) << std::endl; + + if (note->unk1 != 0) + con.print("unk1: %x\n", note->unk1); + if (note->unk2 != 0) + con.print("unk2: %x\n", note->unk2); + + con << std::endl; + } + + c->Resume(); + return CR_OK; +}