Engravings module.

develop
Petr Mrázek 2011-04-03 00:15:47 +02:00
parent 68b13d6bf0
commit 4cfc12b52b
11 changed files with 304 additions and 7 deletions

@ -891,6 +891,9 @@
<Address name="vector"/>
<Offset name="sizeof"/>
</Group>
<Group name="Engravings">
<Address name="vector"/>
</Group>
<Group name="Translations">
<Address name="language_vector"/>
<Address name="translation_vector"/>
@ -2155,7 +2158,11 @@
<Version name="v0.31.25 SDL" os="windows" base="v0.31.24 SDL">
<PETimeStamp value="0x4D90764F" />
<MD5 value="6ada05fc94785b53efe6aa5728b3756b" />
Engravings: 0x16B0A78
<Offsets>
<Group name="Engravings">
<Address name="vector" value="0x16B0A78"/>
</Group>
</Offsets>
</Version>
.-"""-.
' \
@ -2694,7 +2701,6 @@
</Group>
<Group name="Constructions" valid="true">
<Address name="vector" value="0x93f7984" />
<Offset name="sizeof"/>
</Group>
<Group name="Position">
<Address name="cursor_xyz" value="0x8c3dfc0" />
@ -2746,6 +2752,7 @@
one of those:
0x944c3c8
0x944c3d4
<Address name="other" value="0x9450c54" />
<Group name="creature">
<Offset name="tile_color" value="0x38" />
<Offset name="extract_vector" value="0x1f74" />
@ -2770,7 +2777,7 @@
-->
</Group>
<Group name="descriptors">
<Group name="descriptors" valid="true">
<Address name="colors_vector" value="0x94506c8 0x93cdff4" />
<Address name="all_colors_vector" value="0x94506E0 0x93ce00c" />
</Group>
@ -2785,7 +2792,6 @@
<Address name="vector" value="0x940bed0" />
</Group>
<Group name="World">
<Address name="control_mode" value="0x8c3dff0" />
<Address name="game_mode" value="0x8c3e000" />
<Address name="current_weather" value="0x936e248" valid="false" />
@ -2804,9 +2810,21 @@
</Version>
<Version name="v0.31.25 linux" os="linux" base="v0.31.24 linux">
<MD5 value="fc15065c4d1977ca019c6dad220413d1" />
<Offsets valid="false" />
Engravings: 0x93f7918
<Offsets>
<Group name="Engravings">
<Address name="vector" value="0x93f77b8"/>
there are some possibly related vectors right next to it.
</Group>
<Group name="string" valid="true" />
<Group name="vector" valid="true" />
<Group name="Position" valid="true">
<Address name="cursor_xyz" value="0x8c3de60"/>
<Address name="window_dims" value="0x8c3e4c8" />
<Address name="window_x" value="0x8dfaa98" />
<Address name="window_y" value="0x8dfaa9c" />
<Address name="window_z" value="0x8dfaaa0" />
</Group>
</Offsets>
</Version>
</DFHack>

@ -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

@ -155,6 +155,7 @@ TYPE * Context::get##TYPE() \
}
MODULE_GETTER(Creatures);
MODULE_GETTER(Engravings);
MODULE_GETTER(Maps);
MODULE_GETTER(Gui);
MODULE_GETTER(WindowIO);

@ -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"

@ -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();

@ -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

@ -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 <uint32_t> * 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 <uint32_t> (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;
}

@ -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;

@ -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);

@ -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)

@ -0,0 +1,78 @@
// Just show some position data
#include <iostream>
#include <iomanip>
#include <climits>
#include <vector>
#include <sstream>
#include <ctime>
#include <cstdio>
#include <stdio.h>
#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>
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;
}