Buildings - names, type offsets and other stuff could be wrong

develop
Petr Mrázek 2010-04-09 14:44:00 +02:00
parent 75e36a59ba
commit fb01ecf6c9
15 changed files with 138 additions and 197 deletions

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

@ -42,6 +42,7 @@ distribution.
#include "modules/Creatures.h"
#include "modules/Translation.h"
#include "modules/Vegetation.h"
#include "modules/Buildings.h"
using namespace DFHack;
@ -217,66 +218,15 @@ Vegetation * API::getVegetation()
return d->vegetation;
}
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
bool API::InitReadBuildings ( uint32_t& numbuildings )
{
int buildings = 0;
try
{
buildings = d->offset_descriptor->getAddress ("buildings");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->buildingsInited = true;
d->p_bld = new DfVector (d->p,buildings, 4);
numbuildings = d->p_bld->getSize();
return true;
}
// read one building
bool API::ReadBuilding (const int32_t index, t_building & building)
Buildings * API::getBuildings()
{
if(!d->buildingsInited) return false;
t_building_df40d bld_40d;
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_bld->at (index);
//d->p_bld->read(index,(uint8_t *)&temp);
//read building from memory
g_pProcess->read (temp, sizeof (t_building_df40d), (uint8_t *) &bld_40d);
// transform
int32_t type = -1;
d->offset_descriptor->resolveObjectToClassID (temp, type);
building.origin = temp;
building.vtable = bld_40d.vtable;
building.x1 = bld_40d.x1;
building.x2 = bld_40d.x2;
building.y1 = bld_40d.y1;
building.y2 = bld_40d.y2;
building.z = bld_40d.z;
building.material = bld_40d.material;
building.type = type;
return true;
if(!d->buildings)
d->buildings = new Buildings(d);
return d->buildings;
}
void API::FinishReadBuildings()
{
if(d->p_bld)
{
delete d->p_bld;
d->p_bld = NULL;
}
d->buildingsInited = false;
}
/*
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
bool API::InitReadEffects ( uint32_t & numeffects )
{

@ -837,7 +837,7 @@ string SHMProcess::readClassName (uint32_t vptr)
string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length();
return raw.substr(start,end-start - 2); // trim the 'st' from the end
return raw.substr(start,end-start);
}
// get module index by name and version. bool 0 = error

@ -576,6 +576,6 @@ string WineProcess::readClassName (uint32_t vptr)
int rtti = readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}

@ -530,5 +530,5 @@ string NormalProcess::readClassName (uint32_t vptr)
string raw = readCString(typestring);
size_t start = raw.find_first_of("abcdefghijklmnopqrstuvwxyz");// trim numbers
size_t end = raw.length();
return raw.substr(start,end-start - 2); // trim the 'st' from the end
return raw.substr(start,end-start);
}

@ -894,7 +894,7 @@ string SHMProcess::readClassName (uint32_t vptr)
int rtti = readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}

@ -463,6 +463,6 @@ string NormalProcess::readClassName (uint32_t vptr)
int rtti = readDWord(vptr - 0x4);
int typeinfo = readDWord(rtti + 0xC);
string raw = readCString(typeinfo + 0xC); // skips the .?AV
raw.resize(raw.length() - 4);// trim st@@ from end
raw.resize(raw.length() - 2);// trim @@ from end
return raw;
}

@ -50,6 +50,7 @@ namespace DFHack
class Materials;
class Translation;
class Vegetation;
class Buildings;
class DFHACK_EXPORT API
{
@ -94,6 +95,7 @@ namespace DFHack
Materials * getMaterials();
Translation * getTranslation();
Vegetation * getVegetation();
Buildings * getBuildings();
/*
* Constructions (costructed walls, floors, ramps, etc...)
@ -106,14 +108,6 @@ namespace DFHack
/// cleanup after reading constructions
void FinishReadConstructions();
*/
/*
* Buildings - also includes zones and stockpiles
*/
/*
bool InitReadBuildings ( uint32_t & numbuildings );
bool ReadBuilding(const int32_t index, t_building & building);
void FinishReadBuildings();
*/
/*
* Effects like mist, dragonfire or dust
*/

@ -117,117 +117,6 @@ struct t_construction
word type; // NOTE: the actual field is in a different place
*/
//raw
struct t_building_df40d
{
uint32_t vtable;
uint32_t x1;
uint32_t y1;
uint32_t centerx;
uint32_t x2;
uint32_t y2;
uint32_t centery;
uint32_t z;
uint32_t height;
t_matglossPair material;
// not complete
};
//cooked
struct t_building
{
uint32_t origin;
uint32_t vtable;
uint32_t x1;
uint32_t y1;
uint32_t x2;
uint32_t y2;
uint32_t z;
t_matglossPair material;
uint32_t type;
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
};
/*
case 10:
ret += "leather";
break;
case 11:
ret += "silk cloth";
break;
case 12:
ret += "plant thread cloth";
break;
case 13: // green glass
ret += "green glass";
break;
case 14: // clear glass
ret += "clear glass";
break;
case 15: // crystal glass
ret += "crystal glass";
break;
case 17:
ret += "ice";
break;
case 18:
ret += "charcoal";
break;
case 19:
ret += "potash";
break;
case 20:
ret += "ashes";
break;
case 21:
ret += "pearlash";
break;
case 24:
ret += "soap";
break;
*/
enum MatglossType
{
Mat_Wood,
Mat_Stone,
Mat_Metal,
Mat_Plant,
Mat_Leather = 10,
Mat_SilkCloth = 11,
Mat_PlantCloth = 12,
Mat_GreenGlass = 13,
Mat_ClearGlass = 14,
Mat_CrystalGlass = 15,
Mat_Ice = 17,
Mat_Charcoal =18,
Mat_Potash = 20,
Mat_Ashes = 20,
Mat_PearlAsh = 21,
Mat_Soap = 24
//NUM_MATGLOSS_TYPES
};
enum BiomeOffset
{
eNorthWest,
eNorth,
eNorthEast,
eWest,
eHere,
eEast,
eSouthWest,
eSouth,
eSouthEast,
eBiomeCount
};
//#pragma pack(push,4)
struct t_name
{

@ -39,6 +39,20 @@ namespace DFHack
uint32_t address_of; // this is NOT part of the DF vein, but an address of the vein as seen by DFhack.
};
enum BiomeOffset
{
eNorthWest,
eNorth,
eNorthEast,
eWest,
eHere,
eEast,
eSouthWest,
eSouth,
eSouthEast,
eBiomeCount
};
enum e_traffic
{
traffic_normal,

@ -376,17 +376,17 @@ try_again:
// store it in the vector
splatter.push_back (sv);
}
else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquid")
else if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquidst")
{
off.vein_ice_vptr = type;
goto try_again;
}
else if(g_pProcess->readClassName(type) == "block_square_event_mineral")
else if(g_pProcess->readClassName(type) == "block_square_event_mineralst")
{
off.vein_mineral_vptr = type;
goto try_again;
}
else if(g_pProcess->readClassName(type) == "block_square_event_material_spatter")
else if(g_pProcess->readClassName(type) == "block_square_event_material_spatterst")
{
off.vein_spatter_vptr = type;
goto try_again;

@ -37,6 +37,7 @@ namespace DFHack
class Maps;
class Creatures;
class Translation;
class Buildings;
class ProcessEnumerator;
class Process;
class Vegetation;
@ -71,6 +72,7 @@ namespace DFHack
Materials * materials;
Translation * translation;
Vegetation * vegetation;
Buildings * buildings;
/*
uint32_t item_material_offset;

@ -10,8 +10,8 @@ ADD_EXECUTABLE(dfattachtest attachtest.cpp)
TARGET_LINK_LIBRARIES(dfattachtest dfhack)
# buildingsdump - dump buildings and their raw data filtered by type
#ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp)
#TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack)
ADD_EXECUTABLE(dfbuildingsdump buildingsdump.cpp)
TARGET_LINK_LIBRARIES(dfbuildingsdump dfhack)
# a benchmark program, reads the map 1000x
ADD_EXECUTABLE(dfexpbench expbench.cpp)

@ -12,6 +12,10 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <DFTypes.h>
#include <modules/Buildings.h>
#include <modules/Materials.h>
#include "miscutils.h"
int main (int argc,const char* argv[])
@ -51,20 +55,22 @@ int main (int argc,const char* argv[])
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
DFHack::Buildings * Bld = DF.getBuildings();
uint32_t numBuildings;
if(DF.InitReadBuildings(numBuildings))
if(Bld->Start(numBuildings))
{
cout << numBuildings << endl;
vector < uint32_t > addresses;
for(uint32_t i = 0; i < numBuildings; i++)
{
DFHack::t_building temp;
DF.ReadBuilding(i, temp);
Bld->Read(i, temp);
if(temp.type != 0xFFFFFFFF) // check if type isn't invalid
{
string typestr;
mem->resolveClassIDToClassname(temp.type, typestr);
cout << typestr << endl;
if(typestr == argv[1])
{
//cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl;
@ -79,7 +85,7 @@ int main (int argc,const char* argv[])
}
}
interleave_hex(DF,addresses,lines / 4);
DF.FinishReadBuildings();
Bld->Finish();
}
else
{

@ -2819,12 +2819,98 @@
V -- T A B L E S
(for stonesense)
====================================================================
<VTable name="building_vtable">
<multiclass name="building_workshop" typeoffset="0xC8">
<class name="building_alchemists_laboratory" type="0x0"/>
</multiclass>
<class name="building_construction"/>
</VTable>
<VTable name="building_vtable">
<multiclass name="building_workshopst" typeoffset="0x138">
<class name="building_alchemists_laboratoryst" type="0x0"/>
<class name="building_carpenters_workshopst" type="0x1"/>
<class name="building_farmers_workshopst" type="0x2"/>
<class name="building_masons_workshopst" type="0x3"/>
<class name="building_craftdwarfs_workshopst" type="0x4"/>
<class name="building_jewelers_workshopst" type="0x5"/>
<class name="building_metalsmiths_workshopst" type="0x6"/>
<class name="building_magma_forgest" type="0x7"/>
<class name="building_bowyers_workshopst" type="0x8"/>
<class name="building_mechanics_workshopst" type="0x9"/>
<class name="building_siege_workshopst" type="0xA"/>
<class name="building_butchers_shopst" type="0xB"/>
<class name="building_leather_worksst" type="0xC"/>
<class name="building_tanners_shopst" type="0xD"/>
<class name="building_clothiers_shopst" type="0xE"/>
<class name="building_fisheryst" type="0xF"/>
<class name="building_stillst" type="0x10"/>
<class name="building_loomst" type="0x11"/>
<class name="building_quernst" type="0x12"/>
<class name="building_kennelsst" type="0x13"/>
<class name="building_kitchenst" type="0x14"/>
<class name="building_asheryst" type="0x15"/>
<class name="building_dyers_shopst" type="0x16"/>
<class name="building_millstonest" type="0x17"/>
</multiclass>
<multiclass name="building_furnacest" typeoffset="0xDA">
<class name="building_wood_furnacest" type="0x0"/>
<class name="building_smelterst" type="0x1"/>
<class name="building_glass_furnacest" type="0x2"/>
<class name="building_kilnst" type="0x3"/>
<class name="building_magma_smelterst" type="0x4"/>
<class name="building_magma_glass_furnacest" type="0x5"/>
<class name="building_magma_kilnst" type="0x6"/>
</multiclass>
<multiclass name="building_siegeenginest" typeoffset="0xC8">
<class name="building_catapultst" type="0x0"/>
<class name="building_ballistast" type="0x1"/>
</multiclass>
<multiclass name="building_trapst" typeoffset="0xC8">
<class name="building_leverst" type="0x0"/>
<class name="building_pressure_platest" type="0x1"/>
<class name="building_cage_trapst" type="0x2"/>
<class name="building_stonefall_trapst" type="0x3"/>
<class name="building_weapon_trapst" type="0x4"/>
</multiclass>
<class name="building_constructionst"/>
<class name="building_road_pavedst"/>
<class name="building_road_dirtst"/>
<class name="building_roadst"/>
<class name="building_wagonst"/>
<class name="building_tradedepotst"/>
<class name="building_animaltrapst"/>
<class name="building_farmplotst"/>
<class name="building_windowst"/>
<class name="building_statuest"/>
<class name="building_wellst"/>
<class name="building_coffinst"/>
<class name="building_shopst"/>
<class name="building_chairst"/>
<class name="building_tablest"/>
<class name="building_bedst"/>
<class name="building_cagest"/>
<class name="building_chainst"/>
<class name="building_windmillstst"/>
<class name="building_water_wheelst"/>
<class name="building_screw_pumpst"/>
<class name="building_archerytargetst"/>
<class name="building_weaponst"/><!-- retractable spikes -->
<class name="building_supportst"/>
<class name="building_axle_verticalst"/>
<class name="building_axle_horizontalst"/>
<class name="building_gear_assemblyst"/>
<class name="building_bars_floorst"/>
<class name="building_bars_verticalst"/>
<class name="building_grate_floorst"/>
<class name="building_grate_wallst"/>
<class name="building_floodgatest"/>
<class name="building_bridgest"/>
<class name="building_hatchst"/>
<class name="building_doorst"/>
<class name="building_armorstandst"/>
<class name="building_weaponrackst"/>
<class name="building_cabinetst"/>
<class name="building_boxst"/>
<class name="building_actualst"/>
<class name="building_civzonest"/>
<class name="building_stockpilest"/>
<class name="building_window_gemst"/>
<class name="building_window_glassst"/>
</VTable>
</Entry>
@ -3083,8 +3169,7 @@ map_data_1b60_offset 0x1B9c
Buildings
=========
:(
<Address name="buildings_vector">0x0166f9a0</Address>
Effects
=======