Construction reading

develop
Petr Mrázek 2010-04-10 00:24:41 +02:00
parent 9208354991
commit 85ce3ce1d8
12 changed files with 310 additions and 192 deletions

@ -14,6 +14,8 @@
#include "modules/Translation.h"
#include "modules/Vegetation.h"
#include "modules/Gui.h"
#include "modules/Buildings.h"
#include "modules/Constructions.h"
using namespace DFHack;
@ -27,6 +29,8 @@ APIPrivate::APIPrivate()
materials = 0;
translation = 0;
vegetation = 0;
buildings = 0;
constructions = 0;
}
APIPrivate::~APIPrivate()
@ -38,6 +42,8 @@ APIPrivate::~APIPrivate()
if(materials) delete materials;
if(translation) delete translation;
if(vegetation) delete vegetation;
if(buildings) delete buildings;
if(constructions) delete constructions;
}
bool APIPrivate::InitReadNames()

@ -40,6 +40,7 @@ modules/Position.cpp
modules/Translation.cpp
modules/Vegetation.cpp
modules/Buildings.cpp
modules/Constructions.cpp
)
SET(PROJECT_HDRS_LINUX

@ -43,6 +43,7 @@ distribution.
#include "modules/Translation.h"
#include "modules/Vegetation.h"
#include "modules/Buildings.h"
#include "modules/Constructions.h"
using namespace DFHack;
@ -225,6 +226,13 @@ Buildings * API::getBuildings()
return d->buildings;
}
Constructions * API::getConstructions()
{
if(!d->constructions)
d->constructions = new Constructions(d);
return d->constructions;
}
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
@ -285,58 +293,6 @@ void API::FinishReadEffects()
d->effectsInited = false;
}
//TODO: maybe do construction reading differently - this could go slow with many of them.
// returns number of constructions, prepares a vector, returns total number of constructions
bool API::InitReadConstructions(uint32_t & numconstructions)
{
int constructions = 0;
try
{
constructions = d->offset_descriptor->getAddress ("constructions");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->p_cons = new DfVector (d->p,constructions, 4);
d->constructionsInited = true;
numconstructions = d->p_cons->getSize();
return true;
}
bool API::ReadConstruction (const int32_t index, t_construction & construction)
{
if(!d->constructionsInited) return false;
t_construction_df40d c_40d;
// 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_df40d), (uint8_t *) &c_40d);
// transform
construction.x = c_40d.x;
construction.y = c_40d.y;
construction.z = c_40d.z;
construction.material = c_40d.material;
return true;
}
void API::FinishReadConstructions()
{
if(d->p_cons)
{
delete d->p_cons;
d->p_cons = NULL;
}
d->constructionsInited = false;
}
*/
/*
bool API::InitReadNotes( uint32_t &numnotes )

@ -51,6 +51,7 @@ namespace DFHack
class Translation;
class Vegetation;
class Buildings;
class Constructions;
class DFHACK_EXPORT API
{
@ -88,26 +89,33 @@ namespace DFHack
void ReadRaw (const uint32_t offset, const uint32_t size, uint8_t *target);
void WriteRaw (const uint32_t offset, const uint32_t size, uint8_t *source);
// get the creatures module
Creatures * getCreatures();
// get the maps module
Maps * getMaps();
// get the gui module
Gui * getGui();
// get the position module
Position * getPosition();
// get the materials module
Materials * getMaterials();
// get the translation module
Translation * getTranslation();
// get the vegetation module
Vegetation * getVegetation();
// get the buildings module
Buildings * getBuildings();
/*
* Constructions (costructed walls, floors, ramps, etc...)
*/
/*
/// start reading constructions. numconstructions is an output - total constructions present
bool InitReadConstructions( uint32_t & numconstructions );
/// read a construiction at index
bool ReadConstruction(const int32_t index, t_construction & construction);
/// cleanup after reading constructions
void FinishReadConstructions();
*/
// get the constructions module
Constructions * getConstructions();
/*
* Effects like mist, dragonfire or dust
*/

@ -34,7 +34,7 @@ namespace DFHack
struct t_matglossPair
{
int16_t type;
int16_t index;
int32_t index;
};
// DF effects, by darius from the bay12 forum
@ -76,32 +76,6 @@ struct t_effect_df40d //size 40
uint8_t isHidden;
};
// raw
struct t_construction_df40d
{
int16_t x;
int16_t y;
// 4
int16_t z;
int16_t unk1;
// 8
int16_t unk2;
t_matglossPair material; // C points to the index part
// int16_t mat_type;
// int16_t mat_idx;
};
// cooked
struct t_construction
{
uint16_t x;
uint16_t y;
uint16_t z;
t_matglossPair material;
// int16_t mat_type;
// int16_t mat_idx;
};
/*
dword vtable;
int minx;

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

@ -41,6 +41,7 @@ namespace DFHack
class ProcessEnumerator;
class Process;
class Vegetation;
class Constructions;
class memory_info;
struct t_name;
class APIPrivate
@ -73,6 +74,7 @@ namespace DFHack
Translation * translation;
Vegetation * vegetation;
Buildings * buildings;
Constructions * constructions;
/*
uint32_t item_material_offset;
@ -92,24 +94,7 @@ namespace DFHack
uint32_t dwarf_lang_table_offset;
bool constructionsInited;
bool buildingsInited;
bool effectsInited;
bool vegetationInited;
bool itemsInited;
bool notesInited;
bool hotkeyInited;
bool settlementsInited;
bool nameTablesInited;
uint32_t tree_offset;
DfVector *p_cons;
DfVector *p_bld;
DfVector *p_effect;
DfVector *p_veg;
DfVector *p_itm;
DfVector *p_notes;
DfVector *p_settlements;

@ -13,6 +13,10 @@ TARGET_LINK_LIBRARIES(dfattachtest dfhack)
ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp)
TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack)
# constructiondump - dump constructions!
ADD_EXECUTABLE(dfconstructiondump construction_dump.cpp)
TARGET_LINK_LIBRARIES(dfconstructiondump dfhack)
# a benchmark program, reads the map 1000x
ADD_EXECUTABLE(dfexpbench expbench.cpp)
TARGET_LINK_LIBRARIES(dfexpbench dfhack)

@ -109,6 +109,7 @@ int main (int argc,const char* argv[])
string typestr;
mem->resolveClassIDToClassname(temp.type, typestr);
printf("Address 0x%x, type %d (%s), %d/%d/%d\n",temp.origin, temp.type, typestr.c_str(), temp.x1,temp.y1,temp.z);
printf("Material %d %d\n", temp.material.type, temp.material.index);
hexdump(DF,temp.origin,120);
}
}

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

@ -16,23 +16,15 @@ using namespace std;
#include <DFMemInfo.h>
#include <DFVector.h>
#include <DFTypes.h>
#include <modules/Vegetation.h>
#include <modules/Materials.h>
#include <modules/Position.h>
#include <modules/Maps.h>
#include <modules/Constructions.h>
#include "miscutils.h"
using namespace DFHack;
char shades[10] = {'#','$','O','=','+','|','-','^','.',' '};
int main (int numargs, const char ** args)
{
uint32_t addr;
uint32_t x_max,y_max,z_max;
vector<t_vein> veinVector;
vector<t_frozenliquidvein> IceVeinVector;
vector<t_spattervein> splatter;
DFHack::API DF("Memory.xml");
try
{
@ -47,89 +39,30 @@ int main (int numargs, const char ** args)
return 1;
}
DFHack::Maps *Maps =DF.getMaps();
DFHack::Position *Pos =DF.getPosition();
// init the map
if(!Maps->Start())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DFHack::Position *Pos = DF.getPosition();
DFHack::Constructions *Cons = DF.getConstructions();
uint32_t numConstr;
Cons->Start(numConstr);
int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max);
Pos->getCursorCoords(cx,cy,cz);
if(cx == -30000)
{
// walk the map
for(uint32_t x = 0; x< x_max;x++) for(uint32_t y = 0; y< y_max;y++) for(uint32_t z = 0; z< z_max;z++)
{
if(Maps->isValidBlock(x,y,z))
{
// look for splater veins
Maps->ReadVeins(x,y,z,veinVector,IceVeinVector,splatter);
if(splatter.size())
{
printf("Block %d/%d/%d\n",x,y,z);
for(int i = 0; i < splatter.size(); i++)
{
printf("Splatter %d\nmat1: %d\nunknown: %d\nmat2: %d\nmat3: %d\n",i,splatter[i].mat1,splatter[i].unk1,splatter[i].mat2,splatter[i].mat3);
for(uint32_t yyy = 0; yyy < 16; yyy++)
{
cout << "|";
for(uint32_t xxx = 0; xxx < 16; xxx++)
{
uint8_t intensity = splatter[i].intensity[xxx][yyy];
cout << shades[9 - (intensity / 28)];
}
cout << "|" << endl;
}
hexdump(DF, splatter[i].address_of,20);
cout << endl;
}
}
}
}
}
else
if(cx != -30000)
{
uint32_t bx,by,bz;
bx = cx / 16;
by = cy / 16;
bz = cz;
// look for splater veins
Maps->ReadVeins(bx,by,bz,veinVector,IceVeinVector,splatter);
if(splatter.size())
t_construction con;
for(uint32_t i = 0; i < numConstr; i++)
{
printf("Block %d/%d/%d\n",bx,by,bz);
for(int i = 0; i < splatter.size(); i++)
Cons->Read(i,con);
if(cx == con.x && cy == con.y && cz == con.z)
{
printf("Splatter %d\nmat1: %d\nunknown: %d\nmat2: %d\nmat3: %d\n",i,splatter[i].mat1,splatter[i].unk1,splatter[i].mat2,splatter[i].mat3);
for(uint32_t y = 0; y < 16; y++)
printf("Construction %d/%d/%d @ 0x%x - Material %d %d\n", con.x, con.y, con.z,con.origin, con.mat_type, con.mat_idx);
printf("Material form: %d ", con.type);
if(con.type == 4)
{
cout << "|";
for(uint32_t x = 0; x < 16; x++)
{
uint8_t intensity = splatter[i].intensity[x][y];
if(intensity)
{
cout << "#";
}
else
{
cout << " ";
}
}
cout << "|" << endl;
printf("It is rough.");
}
hexdump(DF, splatter[i].address_of,20);
cout << endl;
printf("\n");
hexdump(DF,con.origin,2);
}
}
}