commit
b87d7e7f2a
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue