More creature stuff

develop
Petr Mrázek 2010-04-09 02:08:46 +02:00
parent 4bb05d015a
commit 409e3ffcf0
5 changed files with 134 additions and 97 deletions

@ -273,6 +273,16 @@ namespace DFHack
t_matglossPair material;
bool active;
};
struct t_attrib
{
uint32_t level;
uint32_t field_4;
uint32_t field_8;
uint32_t field_C;
uint32_t leveldiff;
uint32_t field_14;
uint32_t field_18;
};
// FIXME: define in Memory.xml instead?
#define NUM_CREATURE_TRAITS 30
@ -283,36 +293,41 @@ namespace DFHack
uint16_t x;
uint16_t y;
uint16_t z;
uint32_t type;
uint32_t race;
t_creaturflags1 flags1;
t_creaturflags2 flags2;
t_name name;
t_name squad_name;
int16_t mood;
t_name artifact_name;
uint8_t profession;
char custom_profession[128];
// enabled labors
uint8_t labors[NUM_CREATURE_LABORS];
// personality traits
uint16_t traits[NUM_CREATURE_TRAITS];
uint8_t numSkills;
t_skill skills[256];
/*
uint8_t numLikes;
t_like likes[32];
*/
t_job current_job;
int16_t mood;
uint32_t happiness;
uint32_t id;
uint32_t agility;
uint32_t strength;
uint32_t toughness;
uint32_t money;
t_attrib strength;
t_attrib agility;
t_attrib toughness;
t_attrib endurance;
t_attrib recuperation;
t_attrib disease_resistance;
int32_t squad_leader_id;
uint8_t sex;
uint32_t pregnancy_timer; //Countdown timer to giving birth
int32_t blood_max;
int32_t blood_current;
uint32_t bleed_rate;
};
class APIPrivate;

@ -66,21 +66,23 @@ Creatures::Creatures(APIPrivate* _d)
{
memory_info * minfo = d->d->offset_descriptor;
Creatures2010::creature_offsets &creatures = d->creatures;
creatures.creature_vector = minfo->getAddress ("creature_vector");
creatures.creature_pos_offset = minfo->getOffset ("creature_position");
creatures.creature_profession_offset = minfo->getOffset ("creature_profession");
creatures.creature_custom_profession_offset = minfo->getOffset ("creature_custom_profession");
creatures.creature_race_offset = minfo->getOffset ("creature_race");
creatures.creature_flags1_offset = minfo->getOffset ("creature_flags1");
creatures.creature_flags2_offset = minfo->getOffset ("creature_flags2");
creatures.creature_name_offset = minfo->getOffset ("creature_name");
creatures.creature_sex_offset = minfo->getOffset ("creature_sex");
creatures.creature_id_offset = minfo->getOffset ("creature_id");
creatures.creature_labors_offset = minfo->getOffset ("creature_labors");
creatures.creature_happiness_offset = minfo->getOffset ("creature_happiness");
creatures.creature_artifact_name_offset = minfo->getOffset("creature_artifact_name");
creatures.creature_soul_vector_offset = minfo->getOffset("creature_soul_vector");
creatures.vector = minfo->getAddress ("creature_vector");
creatures.pos_offset = minfo->getOffset ("creature_position");
creatures.profession_offset = minfo->getOffset ("creature_profession");
creatures.custom_profession_offset = minfo->getOffset ("creature_custom_profession");
creatures.race_offset = minfo->getOffset ("creature_race");
creatures.flags1_offset = minfo->getOffset ("creature_flags1");
creatures.flags2_offset = minfo->getOffset ("creature_flags2");
creatures.name_offset = minfo->getOffset ("creature_name");
creatures.sex_offset = minfo->getOffset ("creature_sex");
creatures.id_offset = minfo->getOffset ("creature_id");
creatures.labors_offset = minfo->getOffset ("creature_labors");
creatures.happiness_offset = minfo->getOffset ("creature_happiness");
creatures.artifact_name_offset = minfo->getOffset("creature_artifact_name");
creatures.soul_vector_offset = minfo->getOffset("creature_soul_vector");
creatures.default_soul_offset = minfo->getOffset("creature_default_soul");
creatures.physical_offset = minfo->getOffset("creature_physical");
creatures.mood_offset = minfo->getOffset("creature_mood");
// soul offsets
creatures.soul_skills_vector_offset = minfo->getOffset("soul_skills_vector");
@ -114,7 +116,7 @@ Creatures::~Creatures()
bool Creatures::Start( uint32_t &numcreatures )
{
d->p_cre = new DfVector (d->d->p, d->creatures.creature_vector, 4);
d->p_cre = new DfVector (d->d->p, d->creatures.vector, 4);
d->Started = true;
numcreatures = d->p_cre->getSize();
return true;
@ -150,26 +152,37 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
furball.origin = temp;
Creatures2010::creature_offsets &offs = d->creatures;
//read creature from memory
g_pProcess->read (temp + offs.creature_pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
g_pProcess->readDWord (temp + offs.creature_race_offset, furball.type);
g_pProcess->readDWord (temp + offs.creature_flags1_offset, furball.flags1.whole);
g_pProcess->readDWord (temp + offs.creature_flags2_offset, furball.flags2.whole);
// names
d->d->readName(furball.name,temp + offs.creature_name_offset);
//d->readName(furball.squad_name, temp + offs.creature_squad_name_offset);
d->d->readName(furball.artifact_name, temp + offs.creature_artifact_name_offset);
// name
d->d->readName(furball.name,temp + offs.name_offset);
// basic stuff
g_pProcess->readDWord (temp + offs.happiness_offset, furball.happiness);
g_pProcess->readDWord (temp + offs.id_offset, furball.id);
g_pProcess->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really
g_pProcess->readDWord (temp + offs.race_offset, furball.race);
g_pProcess->readByte (temp + offs.sex_offset, furball.sex);
g_pProcess->readDWord (temp + offs.flags1_offset, furball.flags1.whole);
g_pProcess->readDWord (temp + offs.flags2_offset, furball.flags2.whole);
// physical attributes
g_pProcess->read(temp + offs.physical_offset, sizeof(t_attrib) * 6, (uint8_t *)&furball.strength);
// mood stuff
furball.mood = (int16_t) g_pProcess->readWord (temp + offs.mood_offset);
d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset);
// custom profession
fill_char_buf (furball.custom_profession, g_pProcess->readSTLString (temp + offs.creature_custom_profession_offset));
fill_char_buf (furball.custom_profession, g_pProcess->readSTLString (temp + offs.custom_profession_offset));
// labors
g_pProcess->read (temp + offs.creature_labors_offset, NUM_CREATURE_LABORS, furball.labors);
// traits
//g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
g_pProcess->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors);
// profession
furball.profession = g_pProcess->readByte (temp + offs.creature_profession_offset);
furball.profession = g_pProcess->readByte (temp + offs.profession_offset);
// current job HACK: the job object isn't cleanly represented here
/*
uint32_t jobIdAddr = g_pProcess->readDWord (temp + offs.creature_current_job_offset);
@ -184,50 +197,41 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball)
furball.current_job.active = false;
}
*/
//likes
/*
DfVector likes(d->p, temp + offs.creature_likes_offset, 4);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
uint32_t temp2 = *(uint32_t *) likes[i];
g_pProcess->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}
furball.mood = (int16_t) g_pProcess->readWord (temp + offs.creature_mood_offset);
*/
g_pProcess->readDWord (temp + offs.creature_happiness_offset, furball.happiness);
g_pProcess->readDWord (temp + offs.creature_id_offset, furball.id);
/*
g_pProcess->readDWord (temp + offs.creature_agility_offset, furball.agility);
g_pProcess->readDWord (temp + offs.creature_strength_offset, furball.strength);
g_pProcess->readDWord (temp + offs.creature_toughness_offset, furball.toughness);
g_pProcess->readDWord (temp + offs.creature_money_offset, furball.money);
furball.squad_leader_id = (int32_t) g_pProcess->readDWord (temp + offs.creature_squad_leader_id_offset);
*/
g_pProcess->readByte (temp + offs.creature_sex_offset, furball.sex);
/*
g_pProcess->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer);
furball.blood_max = (int32_t) g_pProcess->readDWord(temp + offs.creature_blood_max_offset);
furball.blood_current = (int32_t) g_pProcess->readDWord(temp + offs.creature_blood_current_offset);
g_pProcess->readDWord(temp + offs.creature_bleed_offset, furball.bleed_rate);
*/
/*
// enum soul pointer vector
DfVector souls(g_pProcess,temp + offs.creature_soul_vector_offset,4);
*/
uint32_t soul = g_pProcess->readDWord(temp + offs.default_soul_offset);
// get first soul's skills
DfVector skills(g_pProcess, *(uint32_t *)souls.at(0) + offs.soul_skills_vector_offset,4 );
DfVector skills(g_pProcess, soul + offs.soul_skills_vector_offset, 4 );
furball.numSkills = skills.getSize();
for (uint32_t i = 0; i < furball.numSkills;i++)
{
uint32_t temp2 = * (uint32_t *) skills[i];
//skills.read(i, (uint8_t *) &temp2);
// a byte: this gives us 256 skills maximum.
furball.skills[i].id = g_pProcess->readByte (temp2);
furball.skills[i].rating = g_pProcess->readByte (temp2 + 4);
furball.skills[i].experience = g_pProcess->readWord (temp2 + 8);
}
// traits
//g_pProcess->read (temp + offs.creature_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
//likes
/*
DfVector likes(d->p, temp + offs.creature_likes_offset, 4);
furball.numLikes = likes.getSize();
for(uint32_t i = 0;i<furball.numLikes;i++)
{
uint32_t temp2 = *(uint32_t *) likes[i];
g_pProcess->read(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]);
}*/
return true;
}
@ -261,7 +265,7 @@ int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
{
// read pointer from vector at position
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
g_pProcess->read (temp + d->creatures.creature_pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
g_pProcess->read (temp + d->creatures.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) &coords);
if (coords[0] >= x1 && coords[0] < x2)
{
if (coords[1] >= y1 && coords[1] < y2)
@ -285,7 +289,7 @@ bool Creatures::WriteLabors(const uint32_t index, uint8_t labors[NUM_CREATURE_LA
{
if(!d->Started) return false;
uint32_t temp = * (uint32_t *) d->p_cre->at (index);
g_pProcess->write(temp + d->creatures.creature_labors_offset, NUM_CREATURE_LABORS, labors);
g_pProcess->write(temp + d->creatures.labors_offset, NUM_CREATURE_LABORS, labors);
}
/*

@ -34,20 +34,23 @@ namespace DFHack
typedef struct
{
// creature offsets
uint32_t creature_vector;
uint32_t creature_pos_offset;
uint32_t creature_profession_offset;
uint32_t creature_custom_profession_offset;
uint32_t creature_race_offset;
uint32_t creature_flags1_offset;
uint32_t creature_flags2_offset;
uint32_t creature_name_offset;
uint32_t creature_sex_offset;
uint32_t creature_id_offset;
uint32_t creature_labors_offset;
uint32_t creature_happiness_offset;
uint32_t creature_artifact_name_offset;
uint32_t creature_soul_vector_offset;
uint32_t vector;
uint32_t pos_offset;
uint32_t profession_offset;
uint32_t custom_profession_offset;
uint32_t race_offset;
uint32_t flags1_offset;
uint32_t flags2_offset;
uint32_t name_offset;
uint32_t sex_offset;
uint32_t id_offset;
uint32_t labors_offset;
uint32_t happiness_offset;
uint32_t artifact_name_offset;
uint32_t physical_offset;
uint32_t mood_offset;
uint32_t soul_vector_offset;
uint32_t default_soul_offset;
// soul offsets
uint32_t soul_skills_vector_offset;
// name offsets (needed for reading creature names)

@ -154,7 +154,7 @@ likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector<
void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
cout << "address: " << hex << creature.origin << dec << " creature type: " << creaturestypes[creature.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
cout << "address: " << hex << creature.origin << dec << " creature type: " << creaturestypes[creature.race].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
bool addendl = false;
if(creature.name.first_name[0])
{
@ -398,7 +398,7 @@ int main (void)
{
DFHack::t_creature temp;
Creatures->ReadCreature(i,temp);
if(string(creaturestypes[temp.type].id) == "DWARF")
if(string(creaturestypes[temp.race].id) == "DWARF")
{
cout << "index " << i << " ";
printCreature(DF,temp);

@ -2963,9 +2963,13 @@ map_data_1b60_offset 0x1B9c
<Offset name="name_nickname">0x1C</Offset>
<Offset name="name_words">0x38</Offset>
Creatures
=========
<Address name="creature_vector">0x0166ecc4</Address>
<Address name="dwarf_race_index">0x01470fbc</Address>
<Offset name="creature_name">0x0</Offset>
<Offset name="creature_custom_profession">0x6c</Offset>
<Offset name="creature_profession">0x88</Offset>
@ -2975,20 +2979,31 @@ map_data_1b60_offset 0x1B9c
<Offset name="creature_flags2">0xFC</Offset>
<Offset name="creature_sex">0x110</Offset>
<Offset name="creature_id">0x114</Offset>
<Offset name="creature_side">0X120</Offset> <!-- what? -->
<Offset name="creature_soulskill_vector">0X1F4</Offset>
<Offset name="creature_mood">0x238</Offset>
<Offset name="creature_physical">0x464</Offset>
<!--
<Offset name="creature_strength">0x464</Offset>
<Offset name="creature_agility">0x480</Offset>
<Offset name="creature_toughness">0x49C</Offset>
<Offset name="creature_endurance">0x4B8</Offset>
<Offset name="creature_recuperation">0x4D4</Offset>
<Offset name="creature_disease_resistance">0x4F0</Offset>
-->
<Offset name="creature_current_job">0x390</Offset> <!-- from chmod -->
<Offset name="creature_artifact_name">0x6D0</Offset>
<Offset name="creature_labors">0x770</Offset>
<Offset name="creature_happiness">0x830</Offset>
<Offset name="creature_soul_vector">0x073C</Offset>
<Offset name="creature_default_soul">0x0754</Offset>
<Offset name="creature_happiness">0x830</Offset>
Souls
=====
<Offset name="soul_name">0x0</Offset>
<Offset name="soul_skills_vector">0x1F4</Offset>
<!-- from DT -->
<Address name="dwarf_race_index">0x01470fbc</Address>DWORD, OK
This seems to be wrong:
creature_vector = 0x0166ed2c
Materials
=========
<!-- Number vectors are vector <uint32_t> -->