Notes module

Gets a vector of pointers to note structs
develop
Matthew Cline 2011-07-20 18:26:52 -07:00
parent bde3616015
commit 86577d4f8a
10 changed files with 269 additions and 12 deletions

@ -1073,6 +1073,9 @@
</Group> </Group>
</Group> </Group>
</Group> </Group>
<Group name="Notes" description="In-game notes">
<Address name="vector"/>
</Group>
</Offsets> </Offsets>
</Base> </Base>
@ -3142,6 +3145,9 @@
<Group name="Vegetation"> <Group name="Vegetation">
<Address name="vector" value="0x940bd70" /> <Address name="vector" value="0x940bd70" />
</Group> </Group>
<Group name="Notes">
<Address name="vector" value="0x93f635c"/>
</Group>
</Offsets> </Offsets>
</Version> </Version>
</DFHack> </DFHack>

@ -45,6 +45,7 @@ include/dfhack/modules/Gui.h
include/dfhack/modules/Items.h include/dfhack/modules/Items.h
include/dfhack/modules/Maps.h include/dfhack/modules/Maps.h
include/dfhack/modules/Materials.h include/dfhack/modules/Materials.h
include/dfhack/modules/Notes.h
include/dfhack/modules/Translation.h include/dfhack/modules/Translation.h
include/dfhack/modules/Vegetation.h include/dfhack/modules/Vegetation.h
include/dfhack/modules/Vermin.h include/dfhack/modules/Vermin.h
@ -75,6 +76,7 @@ modules/Gui.cpp
modules/Items.cpp modules/Items.cpp
modules/Maps.cpp modules/Maps.cpp
modules/Materials.cpp modules/Materials.cpp
modules/Notes.cpp
modules/Translation.cpp modules/Translation.cpp
modules/Vegetation.cpp modules/Vegetation.cpp
modules/Vermin.cpp modules/Vermin.cpp

@ -596,3 +596,4 @@ MODULE_GETTER(Vegetation);
MODULE_GETTER(Buildings); MODULE_GETTER(Buildings);
MODULE_GETTER(Constructions); MODULE_GETTER(Constructions);
MODULE_GETTER(Vermin); MODULE_GETTER(Vermin);
MODULE_GETTER(Notes);

@ -49,6 +49,7 @@ namespace DFHack
class Buildings; class Buildings;
class Constructions; class Constructions;
class Vermin; class Vermin;
class Notes;
class VersionInfo; class VersionInfo;
class VersionInfoFactory; class VersionInfoFactory;
class PluginManager; class PluginManager;
@ -107,6 +108,8 @@ namespace DFHack
Constructions * getConstructions(); Constructions * getConstructions();
/// get the vermin module /// get the vermin module
Vermin * getVermin(); Vermin * getVermin();
/// get the notes module
Notes * getNotes();
/// sets the current hotkey command /// sets the current hotkey command
bool setHotkeyCmd( std::string cmd ); bool setHotkeyCmd( std::string cmd );
/// removes the hotkey command and gives it to the caller thread /// removes the hotkey command and gives it to the caller thread
@ -147,6 +150,7 @@ namespace DFHack
Buildings * pBuildings; Buildings * pBuildings;
Constructions * pConstructions; Constructions * pConstructions;
Vermin * pVermin; Vermin * pVermin;
Notes * pNotes;
} s_mods; } s_mods;
std::vector <Module *> allModules; std::vector <Module *> allModules;
DFHack::PluginManager * plug_mgr; DFHack::PluginManager * plug_mgr;

@ -109,17 +109,6 @@ struct t_effect_df40d //size 40
//#pragma pack(push,4) //#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 struct t_name
{ {
char first_name[128]; char first_name[128];

@ -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 <vector>
#include <string>
#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<t_note*>* getNotes();
private:
struct Private;
Private *d;
};
}
#endif // __cplusplus
#endif

@ -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 <string>
#include <vector>
#include <map>
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<t_note*>* 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<t_note*>*) ptr;
}
bool Notes::Finish()
{
return true;
}

@ -42,5 +42,6 @@ namespace DFHack
Module* createConstructions(); Module* createConstructions();
Module* createMaps(); Module* createMaps();
Module* createVermin(); Module* createVermin();
Module* createNotes();
} }
#endif #endif

@ -120,4 +120,5 @@ DFHACK_PLUGIN(cleanmap cleanmap.cpp)
DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(weather weather.cpp)
DFHACK_PLUGIN(vdig vdig.cpp) DFHACK_PLUGIN(vdig vdig.cpp)
DFHACK_PLUGIN(colonies colonies.cpp) DFHACK_PLUGIN(colonies colonies.cpp)
DFHACK_PLUGIN(itemhacks itemhacks.cpp) DFHACK_PLUGIN(itemhacks itemhacks.cpp)
DFHACK_PLUGIN(notes notes.cpp)

@ -0,0 +1,80 @@
#include <dfhack/Core.h>
#include <dfhack/Console.h>
#include <dfhack/Export.h>
#include <dfhack/PluginManager.h>
#include <vector>
#include <string>
#include <dfhack/modules/Notes.h>
using std::vector;
using std::string;
using namespace DFHack;
DFhackCExport command_result df_notes (Core * c, vector <string> & parameters);
DFhackCExport const char * plugin_name ( void )
{
return "notes";
}
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &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 <string> & parameters)
{
Console & con = c->con;
c->Suspend();
DFHack::Notes * note_mod = c->getNotes();
std::vector<t_note*>* 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;
}