Construction reading
parent
9208354991
commit
85ce3ce1d8
@ -0,0 +1,57 @@
|
|||||||
|
#ifndef CL_MOD_CONSTRUCTIONS
|
||||||
|
#define CL_MOD_CONSTRUCTIONS
|
||||||
|
/*
|
||||||
|
* DF constructions
|
||||||
|
*/
|
||||||
|
#include "Export.h"
|
||||||
|
namespace DFHack
|
||||||
|
{
|
||||||
|
// type of item the construction is made of
|
||||||
|
enum e_construction_base
|
||||||
|
{
|
||||||
|
constr_bar = 0,
|
||||||
|
constr_block = 2,
|
||||||
|
constr_boulder = 4,
|
||||||
|
constr_logs = 5,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct t_construction
|
||||||
|
{
|
||||||
|
//0
|
||||||
|
uint16_t x;
|
||||||
|
uint16_t y;
|
||||||
|
// 4
|
||||||
|
uint16_t z;
|
||||||
|
e_construction_base type :16; // 4 = 'rough'
|
||||||
|
// 8
|
||||||
|
uint16_t unk_8; // = -1 in many cases
|
||||||
|
uint16_t mat_type;
|
||||||
|
// C
|
||||||
|
uint32_t mat_idx;
|
||||||
|
uint16_t unk3;
|
||||||
|
// 10
|
||||||
|
uint16_t unk4;
|
||||||
|
uint16_t unk5;
|
||||||
|
// 14
|
||||||
|
uint32_t unk6;
|
||||||
|
|
||||||
|
// added later by dfhack
|
||||||
|
uint32_t origin;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct APIPrivate;
|
||||||
|
class DFHACK_EXPORT Constructions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Constructions(APIPrivate * d);
|
||||||
|
~Constructions();
|
||||||
|
bool Start(uint32_t & numConstructions);
|
||||||
|
bool Read (const uint32_t index, t_construction & constr);
|
||||||
|
bool Finish();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Private;
|
||||||
|
Private *d;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
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 "DFCommonInternal.h"
|
||||||
|
#include "../private/APIPrivate.h"
|
||||||
|
#include "modules/Translation.h"
|
||||||
|
#include "DFMemInfo.h"
|
||||||
|
#include "DFProcess.h"
|
||||||
|
#include "DFVector.h"
|
||||||
|
#include "DFTypes.h"
|
||||||
|
#include "modules/Constructions.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
struct Constructions::Private
|
||||||
|
{
|
||||||
|
uint32_t construction_vector;
|
||||||
|
// translation
|
||||||
|
DfVector * p_cons;
|
||||||
|
|
||||||
|
APIPrivate *d;
|
||||||
|
bool Inited;
|
||||||
|
bool Started;
|
||||||
|
};
|
||||||
|
|
||||||
|
Constructions::Constructions(APIPrivate * d_)
|
||||||
|
{
|
||||||
|
d = new Private;
|
||||||
|
d->d = d_;
|
||||||
|
d->p_cons = 0;
|
||||||
|
d->Inited = d->Started = false;
|
||||||
|
memory_info * mem = d->d->offset_descriptor;
|
||||||
|
d->construction_vector = mem->getAddress ("construction_vector");
|
||||||
|
d->Inited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Constructions::~Constructions()
|
||||||
|
{
|
||||||
|
if(d->Started)
|
||||||
|
Finish();
|
||||||
|
delete d;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Constructions::Start(uint32_t & numconstructions)
|
||||||
|
{
|
||||||
|
d->p_cons = new DfVector (g_pProcess, d->construction_vector, 4);
|
||||||
|
numconstructions = d->p_cons->getSize();
|
||||||
|
d->Started = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Constructions::Read (const uint32_t index, t_construction & construction)
|
||||||
|
{
|
||||||
|
if(!d->Started) return false;
|
||||||
|
|
||||||
|
// read pointer from vector at position
|
||||||
|
uint32_t temp = * (uint32_t *) d->p_cons->at (index);
|
||||||
|
|
||||||
|
//read construction from memory
|
||||||
|
g_pProcess->read (temp, sizeof (t_construction), (uint8_t *) &construction);
|
||||||
|
|
||||||
|
// transform
|
||||||
|
construction.origin = temp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Constructions::Finish()
|
||||||
|
{
|
||||||
|
if(d->p_cons)
|
||||||
|
{
|
||||||
|
delete d->p_cons;
|
||||||
|
d->p_cons = NULL;
|
||||||
|
}
|
||||||
|
d->Started = false;
|
||||||
|
return true;
|
||||||
|
}
|
@ -0,0 +1,95 @@
|
|||||||
|
// Just show some position data
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <climits>
|
||||||
|
#include <integers.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cstdio>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#include <DFTypes.h>
|
||||||
|
#include <DFHackAPI.h>
|
||||||
|
#include <DFProcess.h>
|
||||||
|
#include <DFMemInfo.h>
|
||||||
|
#include <DFVector.h>
|
||||||
|
#include <DFTypes.h>
|
||||||
|
#include <modules/Materials.h>
|
||||||
|
#include <modules/Position.h>
|
||||||
|
#include <modules/Constructions.h>
|
||||||
|
#include "miscutils.h"
|
||||||
|
|
||||||
|
using namespace DFHack;
|
||||||
|
|
||||||
|
int main (int numargs, const char ** args)
|
||||||
|
{
|
||||||
|
DFHack::API DF("Memory.xml");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DF.Attach();
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
cerr << e.what() << endl;
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
DFHack::Position *Pos = DF.getPosition();
|
||||||
|
|
||||||
|
DFHack::Constructions *Cons = DF.getConstructions();
|
||||||
|
DFHack::Materials *Mats = DF.getMaterials();
|
||||||
|
vector<t_matgloss> inorganics;
|
||||||
|
Mats->ReadInorganicMaterials(inorganics);
|
||||||
|
uint32_t numConstr;
|
||||||
|
Cons->Start(numConstr);
|
||||||
|
|
||||||
|
int32_t cx, cy, cz;
|
||||||
|
Pos->getCursorCoords(cx,cy,cz);
|
||||||
|
if(cx != -30000)
|
||||||
|
{
|
||||||
|
t_construction con;
|
||||||
|
for(uint32_t i = 0; i < numConstr; i++)
|
||||||
|
{
|
||||||
|
Cons->Read(i,con);
|
||||||
|
if(cx == con.x && cy == con.y && cz == con.z)
|
||||||
|
{
|
||||||
|
printf("Construction %d/%d/%d @ 0x%x\n", con.x, con.y, con.z,con.origin);
|
||||||
|
// inorganic stuff - we can recognize that
|
||||||
|
printf("Material: form %d, type %d, index %d\n",con.type, con.mat_type, con.mat_idx);
|
||||||
|
string matstr = "unknown";
|
||||||
|
if(con.mat_type == 0)
|
||||||
|
{
|
||||||
|
matstr = inorganics[con.mat_idx].id;
|
||||||
|
}
|
||||||
|
switch(con.type)
|
||||||
|
{
|
||||||
|
case constr_bar:
|
||||||
|
printf("It is made of %s bars!\n",matstr.c_str());
|
||||||
|
break;
|
||||||
|
case constr_block:
|
||||||
|
printf("It is made of %s blocks!\n",matstr.c_str());
|
||||||
|
break;
|
||||||
|
case constr_boulder:
|
||||||
|
printf("It is made of %s stones!\n",matstr.c_str());
|
||||||
|
break;
|
||||||
|
case constr_logs:
|
||||||
|
printf("It is made of %s logs!\n",matstr.c_str());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("It is made of something we don't know yet! The material is %s.\n",matstr.c_str());
|
||||||
|
}
|
||||||
|
hexdump(DF,con.origin,2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#ifndef LINUX_BUILD
|
||||||
|
cout << "Done. Press any key to continue" << endl;
|
||||||
|
cin.ignore();
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue