Merge remote branch 'upstream/master'

develop
doomchild 2010-04-12 12:05:02 -05:00
commit ecb2aefba1
11 changed files with 756 additions and 2594 deletions

@ -54,6 +54,7 @@ API::API (const string path_to_xml)
d->xml += "/";
d->xml += path_to_xml;
d->pm = NULL;
d->p = 0;
d->shm_start = 0;
}

@ -296,6 +296,7 @@ namespace DFHack
uint8_t numLikes;
t_like likes[32];
*/
uint16_t traits[NUM_CREATURE_TRAITS];
t_attrib analytical_ability;
t_attrib focus;
t_attrib willpower;

@ -197,14 +197,14 @@ namespace DFHack
typedef int16_t tiletypes40d [16][16];
typedef DFHack::t_designation designations40d [16][16];
// typedef DFHack::t_occupancy occupancies40d [16][16];
typedef DFHack::t_occupancy occupancies40d [16][16];
typedef uint8_t biome_indices40d [16];
typedef struct
{
tiletypes40d tiletypes;
designations40d designation;
// occupancies40d occupancy;
occupancies40d occupancy;
biome_indices40d biome_indices;
uint32_t origin; // the address where it came from
t_blockflags blockflags;
@ -290,11 +290,10 @@ namespace DFHack
bool ReadDesignations(uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
bool WriteDesignations (uint32_t blockx, uint32_t blocky, uint32_t blockz, designations40d *buffer);
/*
/// read/write block occupancies
bool ReadOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
bool WriteOccupancy(uint32_t blockx, uint32_t blocky, uint32_t blockz, occupancies40d *buffer);
*/
/// read/write the block dirty bit - this is used to mark a map block so that DF scans it for designated jobs like digging
bool ReadDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool &dirtybit);
bool WriteDirtyBit(uint32_t blockx, uint32_t blocky, uint32_t blockz, bool dirtybit);

@ -86,6 +86,7 @@ Creatures::Creatures(APIPrivate* _d)
// soul offsets
creatures.soul_skills_vector_offset = minfo->getOffset("soul_skills_vector");
creatures.soul_mental_offset = minfo->getOffset("soul_mental");
creatures.soul_traits_offset = minfo->getOffset("soul_traits");
// name offsets for the creature module
creatures.name_firstname_offset = minfo->getOffset("name_firstname");
@ -219,10 +220,11 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
furball.defaultSoul.skills[i].rating = g_pProcess->readByte (temp2 + 4);
furball.defaultSoul.skills[i].experience = g_pProcess->readWord (temp2 + 8);
}
g_pProcess->read(temp + offs.soul_mental_offset, sizeof(t_attrib) * 13, (uint8_t *)&furball.defaultSoul.analytical_ability);
// mental attributes are part of the soul
g_pProcess->read(soul + offs.soul_mental_offset, sizeof(t_attrib) * 13, (uint8_t *)&furball.defaultSoul.analytical_ability);
// traits
//g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
// traits as well
g_pProcess->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits);
//likes
/*

@ -72,6 +72,7 @@ Maps::Maps(APIPrivate* _d)
off.z_count_offset = mem->getAddress ("z_count_block");
off.tile_type_offset = mem->getOffset ("type");
off.designation_offset = mem->getOffset ("designation");
off.occupancy_offset = mem->getOffset("occupancy");
off.biome_stuffs = mem->getOffset ("biome_stuffs");
off.veinvector = mem->getOffset ("v_vein");
@ -156,6 +157,14 @@ bool Maps::Start()
return true;
}
// getter for map size
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
{
x = d->x_block_count;
y = d->y_block_count;
z = d->z_block_count;
}
bool Maps::Finish()
{
if (d->block != NULL)
@ -166,6 +175,10 @@ bool Maps::Finish()
return true;
}
/*
* Block reading
*/
bool Maps::isValidBlock (uint32_t x, uint32_t y, uint32_t z)
{
if ( x >= d->x_block_count || y >= d->y_block_count || z >= d->z_block_count)
@ -200,6 +213,7 @@ bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer
{
g_pProcess->read (addr + d->offsets.tile_type_offset, sizeof (buffer->tiletypes), (uint8_t *) buffer->tiletypes);
g_pProcess->read (addr + d->offsets.designation_offset, sizeof (buffer->designation), (uint8_t *) buffer->designation);
g_pProcess->read (addr + d->offsets.occupancy_offset, sizeof (buffer->occupancy), (uint8_t *) buffer->occupancy);
g_pProcess->read (addr + d->offsets.biome_stuffs, sizeof (biome_indices40d), (uint8_t *) buffer->biome_indices);
buffer->origin = addr;
uint32_t addr_of_struct = g_pProcess->readDWord(addr);
@ -210,8 +224,10 @@ bool Maps::ReadBlock40d(uint32_t x, uint32_t y, uint32_t z, mapblock40d * buffer
}
}
/*
* Tiletypes
*/
// 256 * sizeof(uint16_t)
bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
@ -223,6 +239,21 @@ bool Maps::ReadTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buff
return false;
}
bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->write (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true;
}
return false;
}
/*
* Dirty flags
*/
bool Maps::ReadDirtyBit(uint32_t x, uint32_t y, uint32_t z, bool &dirtybit)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
@ -274,6 +305,10 @@ bool Maps::WriteBlockFlags(uint32_t x, uint32_t y, uint32_t z, t_blockflags bloc
return false;
}
/*
* Designations
*/
bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
@ -285,35 +320,46 @@ bool Maps::ReadDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d
return false;
}
// 256 * sizeof(uint16_t)
bool Maps::WriteTileTypes (uint32_t x, uint32_t y, uint32_t z, tiletypes40d *buffer)
bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->write (addr + d->offsets.tile_type_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
g_pProcess->write (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
return true;
}
return false;
}
/*
* Occupancies
*/
// 256 * sizeof(uint32_t)
bool Maps::WriteDesignations (uint32_t x, uint32_t y, uint32_t z, designations40d *buffer)
bool Maps::ReadOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->write (addr + d->offsets.designation_offset, sizeof (designations40d), (uint8_t *) buffer);
g_pProcess->read (addr + d->offsets.occupancy_offset, sizeof (occupancies40d), (uint8_t *) buffer);
return true;
}
return false;
}
// FIXME: this is bad. determine the real size!
//16 of them? IDK... there's probably just 7. Reading more doesn't cause errors as it's an array nested inside a block
// 16 * sizeof(uint8_t)
bool Maps::WriteOccupancy (uint32_t x, uint32_t y, uint32_t z, occupancies40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
if (addr)
{
g_pProcess->write (addr + d->offsets.occupancy_offset, sizeof (tiletypes40d), (uint8_t *) buffer);
return true;
}
return false;
}
/*
* Region Offsets - used for layer geology
*/
bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices40d *buffer)
{
uint32_t addr = d->block[x*d->y_block_count*d->z_block_count + y*d->z_block_count + z];
@ -325,8 +371,9 @@ bool Maps::ReadRegionOffsets (uint32_t x, uint32_t y, uint32_t z, biome_indices4
return false;
}
// veins of a block, expects empty vein vectors
/*
* Block events
*/
bool Maps::ReadVeins(uint32_t x, uint32_t y, uint32_t z, vector <t_vein>* veins, vector <t_frozenliquidvein>* ices, vector <t_spattervein> *splatter)
{
t_vein v;
@ -378,21 +425,28 @@ try_again:
}
else
{
if(g_pProcess->readClassName(type) == "block_square_event_frozen_liquidst")
string cname = g_pProcess->readClassName(type);
if(ices && cname == "block_square_event_frozen_liquidst")
{
off.vein_ice_vptr = type;
goto try_again;
}
else if(g_pProcess->readClassName(type) == "block_square_event_mineralst")
else if(veins && cname == "block_square_event_mineralst")
{
off.vein_mineral_vptr = type;
goto try_again;
}
else if(g_pProcess->readClassName(type) == "block_square_event_material_spatterst")
else if(splatter && cname == "block_square_event_material_spatterst")
{
off.vein_spatter_vptr = type;
goto try_again;
}
#ifdef DEBUG
else
{
cerr << "unknown vein " << cname << endl;
}
#endif
// or it was something we don't care about
}
}
@ -401,14 +455,6 @@ try_again:
return false;
}
// getter for map size
void Maps::getSize (uint32_t& x, uint32_t& y, uint32_t& z)
{
x = d->x_block_count;
y = d->y_block_count;
z = d->z_block_count;
}
/*
__int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __int16 block_Y<di>, int block_addr<esi>, int Y)
{
@ -464,7 +510,9 @@ __int16 __userpurge GetGeologicalRegion<ax>(__int16 block_X<cx>, int X<ebx>, __i
}
*/
//vector<uint16_t> v_geology[eBiomeCount];
/*
* Layer geology
*/
bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
{
memory_info * minfo = d->d->offset_descriptor;
@ -472,8 +520,6 @@ bool Maps::ReadGeology (vector < vector <uint16_t> >& assign)
int region_x_offset = minfo->getAddress ("region_x");
int region_y_offset = minfo->getAddress ("region_y");
int region_z_offset = minfo->getAddress ("region_z");
/* <Address name="geoblock_vector">0x16AF52C</Address>
<Address name="ptr2_region_array">0x16AF574</Address>*/
int world_regions = minfo->getAddress ("ptr2_region_array");
int region_size = minfo->getHexValue ("region_size");
int region_geo_index_offset = minfo->getOffset ("region_geo_index_off");

@ -58,6 +58,7 @@ typedef struct
uint32_t name_nickname_offset;
uint32_t name_words_offset;
uint32_t soul_mental_offset;
uint32_t soul_traits_offset;
} creature_offsets;
typedef struct

@ -10,6 +10,7 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
#include <modules/Materials.h>
#include <modules/Creatures.h>
#include <modules/Translation.h>
@ -270,6 +271,15 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout << laborname << ", ";
}
cout << endl;
cout << "Traits" << endl;
for(uint32_t i = 0; i < 30;i++)
{
string trait = mem->getTrait (i, creature.defaultSoul.traits[i]);
if(!trait.empty())
cout << trait << ", ";
}
cout << endl;
/*
* FLAGS 1
*/

@ -39,7 +39,7 @@ int main (int numargs, const char ** args)
#endif
return 1;
}
/*
DFHack::Position *Pos = DF.getPosition();
DFHack::Maps *Maps = DF.getMaps();
@ -60,6 +60,25 @@ int main (int numargs, const char ** args)
cout << tiletype << endl;
}
}
*/
vector <string> classIdStrings;
DFHack::memory_info * minfo = DF.getMemoryInfo();
if(!minfo)
{
cerr <<"FAIL!" << endl;
return 1;
}
for(int i = 0; ; i++)
{
string temp;
if(!minfo->resolveClassIDToClassname(i, temp))
{
break;
}
classIdStrings.push_back(temp);
}
for (int i = 0; i < classIdStrings.size(); i++)
cout << i << ": " << classIdStrings[i] << endl;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();

@ -675,6 +675,14 @@ main(int argc, char *argv[])
}
}
}
mapblock40d * Block = &blocks[1][1];
for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++)
{
if((Block->occupancy[x][y].whole & (1 << twiddle)))
{
putch(x + 16,y + 16,'@',COLOR_WHITE);
}
}
gotoxy (0,52);
cprintf("block address 0x%x, flags 0x%08x",blockaddr, bflags.whole);
gotoxy (0,53);

File diff suppressed because it is too large Load Diff

@ -0,0 +1,41 @@
// Make stuck DF run again.
#include <iostream>
#include <climits>
#include <integers.h>
#include <vector>
#include <ctime>
#include <string>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
int main (void)
{
string blah;
DFHack::API DF("Memory.xml");
try
{
DF.Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
DF.ForceResume();
cout << "DF should be running again :)" << endl;
getline(cin, blah);
if(!DF.Detach())
{
cerr << "Can't detach from DF" << endl;
return 1;
}
return 0;
}