Merge branch 'master' of git://github.com/Zhentar/dfhack

Conflicts:
	examples/CMakeLists.txt
	library/DFHackAPI.cpp

Also added offsets for all supported versions
develop
Petr Mrázek 2010-03-26 02:40:17 +01:00
commit 517aa0e6e3
6 changed files with 133 additions and 18 deletions

@ -56,6 +56,11 @@ TARGET_LINK_LIBRARIES(dfsettlementdump dfhack)
ADD_EXECUTABLE(dfvecc veccheck.cpp)
TARGET_LINK_LIBRARIES(dfvecc dfhack)
# catsplosion - Makes every cat pregnant, and almost due...
# Author: Zhentar
ADD_EXECUTABLE(dfcatsplosion catsplosion.cpp)
TARGET_LINK_LIBRARIES(dfcatsplosion dfhack)
IF(UNIX)
SET(CURSES_NEED_WIDE "YES")
SET(CURSES_NEED_NCURSES "YES")
@ -107,6 +112,7 @@ dfmaterialtest
dfposition
dfrenamer
dfsuspend
dfcatsplosion
RUNTIME DESTINATION bin
)
ENDIF(UNIX)

@ -0,0 +1,78 @@
// Catsplosion
// By Zhentar
// This work of evil makes every cat, male or female, grown or kitten, pregnant and due within 2 in-game hours...
#include <iostream>
#include <climits>
#include <integers.h>
#include <vector>
#include <stdlib.h> // for rand()
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
#include <DFProcess.h>
vector<DFHack::t_matgloss> creaturestypes;
DFHack::memory_info *mem;
DFHack::Process *proc;
uint32_t creature_pregnancy_offset;
int fertilizeCat(DFHack::API & DF, const DFHack::t_creature & creature)
{
if(string(creaturestypes[creature.type].id) == "CAT")
{
proc->writeDWord(creature.origin + creature_pregnancy_offset, rand() % 100 + 1);
return 1;
}
return 0;
}
int main (void)
{
DFHack::API DF("Memory.xml");
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
proc = DF.getProcess();
mem = DF.getMemoryInfo();
creature_pregnancy_offset = mem->getOffset("creature_pregnancy");
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
cerr << "Can't get the creature types." << endl;
return 1;
}
uint32_t numCreatures;
if(!DF.InitReadCreatures(numCreatures))
{
cerr << "Can't get creatures" << endl;
return 1;
}
int cats=0;
for(uint32_t i = 0; i < numCreatures; i++)
{
DFHack::t_creature temp;
DF.ReadCreature(i,temp);
cats+=fertilizeCat(DF,temp);
}
cout << cats << " cats impregnated." << endl;
DF.FinishReadCreatures();
DF.Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}

@ -152,7 +152,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
{
if(string(creaturestypes[creature.type].id) == "DWARF")
{
cout << "address: " << creature.origin << " 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.type].id << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
bool addendl = false;
if(creature.name.first_name[0])
{
@ -170,17 +170,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout << ", trans name: " << transName;
addendl=true;
}
//cout << ", generic name: " << DF.TranslateName(creature.last_name,names,"GENERIC");
/*
if(!creature.trans_name.empty()){
cout << ", trans name: " << creature.trans_name;
addendl =true;
}
if(!creature.generic_name.empty()){
cout << ", generic name: " << creature.generic_name;
addendl=true;
}
*/
cout << ", likes: ";
for(uint32_t i = 0;i<creature.numLikes; i++)
{
@ -223,6 +213,12 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature)
cout <<"Male";
}
cout << endl;
if(creature.pregnancy_timer > 0)
cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate;
cout << endl;
/*
//skills
for(unsigned int i = 0; i < creature.skills.size();i++){

@ -97,6 +97,10 @@ public:
uint32_t creature_likes_offset;
uint32_t creature_artifact_name_offset;
uint32_t creature_mood_offset;
uint32_t creature_pregnancy_offset;
uint32_t creature_blood_max_offset;
uint32_t creature_blood_current_offset;
uint32_t creature_bleed_offset;
uint32_t item_material_offset;
@ -1083,6 +1087,11 @@ bool API::InitReadCreatures( uint32_t &numcreatures )
d->creature_artifact_name_offset = minfo->getOffset("creature_artifact_name");
d->creature_mood_offset = minfo->getOffset("creature_mood");
d->creature_pregnancy_offset = minfo->getOffset("creature_pregnancy");
d->creature_blood_max_offset = minfo->getOffset("creature_blood_max");
d->creature_blood_current_offset = minfo->getOffset("creature_blood_current");
d->creature_bleed_offset = minfo->getOffset("creature_bleed");
d->p_cre = new DfVector (d->p->readVector (creatures, 4));
d->creaturesInited = true;
numcreatures = d->p_cre->getSize();
@ -1360,6 +1369,13 @@ bool API::ReadCreature (const int32_t index, t_creature & furball)
g_pProcess->readDWord (temp + d->creature_money_offset, furball.money);
furball.squad_leader_id = (int32_t) g_pProcess->readDWord (temp + d->creature_squad_leader_id_offset);
g_pProcess->readByte (temp + d->creature_sex_offset, furball.sex);
g_pProcess->readDWord(temp+d->creature_pregnancy_offset, furball.pregnancy_timer);
furball.blood_max = (int32_t) g_pProcess->readDWord(temp+d->creature_blood_max_offset);
furball.blood_current = (int32_t) g_pProcess->readDWord(temp+d->creature_blood_current_offset);
g_pProcess->readDWord(temp+d->creature_bleed_offset, furball.bleed_rate);
return true;
}

@ -607,6 +607,10 @@ struct t_creature
uint32_t money;
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;
};
//raw
struct t_item_df40d

@ -849,9 +849,15 @@
<Offset name="creature_id">0xF4</Offset>
<Offset name="creature_squad_name">0x158</Offset>
<Offset name="creature_mood">0x1F8</Offset>
<Offset name="creature_pregnancy">0x1FC</Offset>
<Offset name="creature_squad_leader_id">0x228</Offset>
<Offset name="creature_money">0x2F8</Offset><!-- this is wrong -->
<Offset name="creature_current_job">0x2AC</Offset>
<Offset name="creature_blood_max">0x328</Offset>
<Offset name="creature_blood_current">0x32C</Offset>
<Offset name="creature_bleed">0x330</Offset>
<Offset name="creature_artifact_name">0x3CC</Offset>
<Offset name="creature_strength">0x438</Offset>
<Offset name="creature_agility">0x43C</Offset>
@ -1223,9 +1229,13 @@
<Offset name="creature_id">0x10C</Offset>
<Offset name="creature_squad_name">0x198</Offset>
<Offset name="creature_mood">0x238</Offset>
<Offset name="creature_pregnancy">0x23C</Offset>
<Offset name="creature_squad_leader_id">0x268</Offset>
<Offset name="creature_money">0x2F8</Offset>
<Offset name="creature_current_job">0x314</Offset>
<Offset name="creature_blood_max">0x3C0</Offset>
<Offset name="creature_blood_current">0x3C4</Offset>
<Offset name="creature_bleed">0x3C8</Offset>
<Offset name="creature_artifact_name">0x484</Offset>
<Offset name="creature_strength">0x4F0</Offset>
<Offset name="creature_agility">0x4F4</Offset>
@ -1235,7 +1245,6 @@
<Offset name="creature_labors">0x544</Offset>
<Offset name="creature_happiness">0x610</Offset>
<Offset name="creature_traits">0x700</Offset>
<!-- tree and shrub offsets -->
<Offset name="tree_desc_offset">0x70</Offset>
@ -1637,10 +1646,16 @@
<Offset name="creature_custom_profession">0x003c</Offset>
<Offset name="creature_profession">0x0040</Offset>
<Offset name="creature_sex">0x009E</Offset>
<Offset name="creature_id">0x00A0</Offset>
<Offset name="creature_id">0x00A0</Offset> <!-- either this or the squad leader ID is wrong -->
<Offset name="creature_squad_name">0x00F0</Offset>
<Offset name="creature_mood">0x160</Offset>
<Offset name="creature_pregnancy">0x164</Offset>
<Offset name="creature_squad_leader_id">0x00A0</Offset>
<Offset name="creature_blood_max">0x264</Offset>
<Offset name="creature_blood_current">0x268</Offset>
<Offset name="creature_bleed">0x26C</Offset>
<Offset name="creature_money">0x02F8</Offset> <!-- most probably wrong -->
<Offset name="creature_current_job">0x0200</Offset>
<Offset name="creature_artifact_name">0x02F8</Offset>