creatures almost done

develop
Petr Mrázek 2009-11-14 03:46:56 +00:00
parent e88e9b2951
commit 37d08a05ca
17 changed files with 518 additions and 435 deletions

@ -23,7 +23,7 @@ distribution.
*/
#include "DFCommonInternal.h"
using namespace DFHack;
DfVector DMWindows40d::readVector (uint32_t offset, uint32_t item_size)
{

@ -25,6 +25,8 @@ distribution.
#ifndef DATAMODEL_H_INCLUDED
#define DATAMODEL_H_INCLUDED
namespace DFHack
{
class DfVector;
// let's go pure virtual.
@ -50,5 +52,5 @@ class DMLinux40d : public DataModel
// read a vector from memory
virtual DfVector readVector (uint32_t offset, uint32_t item_size);
};
}
#endif // DATAMODEL_H_INCLUDED

@ -973,17 +973,32 @@ bool API::ReadCreature(const uint32_t &index, t_creature & furball)
Mread(temp + d->creature_last_name_offset,sizeof(t_lastname), (uint8_t *) &furball.last_name );
Mread(temp + d->creature_squad_name_offset,sizeof(t_squadname), (uint8_t *) &furball.squad_name );
// custom profession
fill_char_buf(furball.custom_profession, d->dm->readSTLString(temp+d->creature_first_name_offset));
fill_char_buf(furball.custom_profession, d->dm->readSTLString(temp+d->creature_custom_profession_offset));
/*
furball.profession = d->getProfessionByAddress(temp+d->creature_profession_offset);
furball.current_job = d->getCurrentJobByAddress(temp+d->creature_current_job_offset);
d->getSkillsByAddress(temp+d->creature_skills_offset,furball.skills);
d->getTraitsByAddress(temp+d->creature_traits_offset,furball.traits);
d->getLaborsByAddress(temp+d->creature_labors_offset,furball.labors);
*/
// labors
Mread(temp+d->creature_labors_offset, NUM_CREATURE_LABORS, furball.labors);
// traits
Mread(temp+d->creature_traits_offset, sizeof(uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.traits);
// learned skills
DfVector skills(d->dm->readVector(temp+d->creature_skills_offset,4));
furball.numSkills = skills.getSize();
for(uint32_t i = 0; i<furball.numSkills;i++)
{
uint32_t temp2;
skills.read(i, (uint8_t *) &temp2);
// a byte: this gives us 256 skills maximum.
furball.skills[i].id= MreadByte(temp2);
furball.skills[i].rating = MreadByte(temp2+4);
furball.skills[i].experience = MreadWord(temp2+8);
}
// profession
furball.profession = MreadByte(temp+d->creature_profession_offset);
// current job HACK: the job object isn't cleanly represented here
uint32_t jobIdAddr = MreadDWord(temp+d->creature_current_job_offset);
if(furball.current_job.active = jobIdAddr != 0)
{
furball.current_job.jobId = MreadByte(jobIdAddr+d->creature_current_job_id_offset);
}
MreadDWord(temp + d->creature_happiness_offset, furball.happiness);
MreadDWord(temp + d->creature_id_offset, furball.id);
@ -1151,3 +1166,8 @@ bool API::setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z)
Mwrite(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords);
return true;
}
memory_info API::getMemoryInfo()
{
return *d->offset_descriptor;
}

@ -25,30 +25,14 @@ distribution.
#ifndef SIMPLEAPI_H_INCLUDED
#define SIMPLEAPI_H_INCLUDED
/// TODO: add visibility for GCC?
#ifdef LINUX_BUILD
# ifndef DFHACK_EXPORT
# define DFHACK_EXPORT
# endif
#else
# ifdef BUILD_DFHACK_LIB
# ifndef DFHACK_EXPORT
# define DFHACK_EXPORT __declspec(dllexport)
# endif
# else
# ifndef DFHACK_EXPORT
# define DFHACK_EXPORT __declspec(dllimport)
# endif
# endif
#endif
#include "Export.h"
#include <string>
#include <vector>
#include "integers.h"
namespace DFHack
{
class memory_info;
enum VegetationType
{
@ -192,7 +176,8 @@ public:
*/
void InitReadNameTables();
void FinishReadNameTables();
};
memory_info getMemoryInfo();
};
} // namespace DFHack
#endif // SIMPLEAPI_H_INCLUDED

@ -25,9 +25,6 @@ distribution.
#ifndef PROCESSUTIL_H_INCLUDED
#define PROCESSUTIL_H_INCLUDED
// SLOW!
// #include "LinuxMemAccess-ptrace.h"
#ifdef LINUX_BUILD
#include "LinuxMemAccess-memfiles.h"
#else

@ -24,6 +24,8 @@ distribution.
#include "DFCommonInternal.h"
using namespace DFHack;
memory_info::memory_info()
{
base = 0;
@ -159,10 +161,12 @@ void memory_info::setLabor(string key, string value)
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
labors[keyInt] = value;
}
void memory_info::setProfession (string key, string value)
{
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
if(professions.size() <= keyInt){
if(professions.size() <= keyInt)
{
professions.resize(keyInt+1);
}
professions[keyInt] = value;
@ -171,7 +175,8 @@ void memory_info::setProfession (string key, string value)
void memory_info::setJob (string key, string value)
{
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
if(jobs.size() <= keyInt){
if(jobs.size() <= keyInt)
{
jobs.resize(keyInt+1);
}
jobs[keyInt] = value;
@ -189,7 +194,8 @@ void memory_info::setSkill (string key, string value)
void memory_info::setTrait(string key,string value,string zero,string one,string two,string three,string four,string five)
{
uint32_t keyInt = strtol(key.c_str(), NULL, 10);
if(traits.size() <= keyInt){
if(traits.size() <= keyInt)
{
traits.resize(keyInt+1);
}
traits[keyInt].push_back(zero);
@ -475,20 +481,20 @@ string memory_info::getTrait (uint32_t traitIdx, uint32_t traitValue)
return string("Trait is not Defined");
}
string memory_info::getTraitName(uint32_t key)
string memory_info::getTraitName(uint32_t traitIdx)
{
if(traits.size() > key)
if(traits.size() > traitIdx)
{
return traits[key][traits[key].size()-1];
return traits[traitIdx][traits[traitIdx].size()-1];
}
return string("Trait is not Defined");
}
string memory_info::getLabor (uint32_t key)
string memory_info::getLabor (uint32_t laborIdx)
{
if(labors.count(key))
if(labors.count(laborIdx))
{
return labors[key];
return labors[laborIdx];
}
return string("");
}

@ -25,7 +25,14 @@ distribution.
#ifndef MEMINFO_H_INCLUDED
#define MEMINFO_H_INCLUDED
class memory_info
#include "Export.h"
#include <map>
#include <vector>
#include <string>
namespace DFHack
{
class DFHACK_EXPORT memory_info
{
public:
enum OSType
@ -129,4 +136,5 @@ private:
string version;
OSType OS;
};
}
#endif // MEMINFO_H_INCLUDED

@ -23,7 +23,7 @@ distribution.
*/
#include "DFCommonInternal.h"
using namespace DFHack;
Process::Process(DataModel * dm, memory_info* mi, ProcessHandle ph, uint32_t pid)
{

@ -23,11 +23,12 @@ distribution.
*/
#include "DFCommonInternal.h"
using namespace DFHack;
/// HACK: global variables (only one process can be attached at the same time.)
Process * g_pProcess; ///< current process. non-NULL when picked
ProcessHandle g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
int g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
Process * DFHack::g_pProcess; ///< current process. non-NULL when picked
ProcessHandle DFHack::g_ProcessHandle; ///< cache of handle to current process. used for speed reasons
int DFHack::g_ProcessMemFile; ///< opened /proc/PID/mem, valid when attached
#ifdef LINUX_BUILD

@ -25,17 +25,21 @@ distribution.
#ifndef PROCESSMANAGER_H_INCLUDED
#define PROCESSMANAGER_H_INCLUDED
class TiXmlElement;
namespace DFHack
{
class memory_info;
class DataModel;
class Process;
#ifdef LINUX_BUILD
typedef pid_t ProcessHandle;
#else
typedef HANDLE ProcessHandle;
#endif
class memory_info;
class DataModel;
class TiXmlElement;
class Process;
/*
* Currently attached process and its handle
*/
@ -93,5 +97,5 @@ private:
Process* addProcess(const string & exe,ProcessHandle PH,const string & memFile);
#endif
};
}
#endif // PROCESSMANAGER_H_INCLUDED

@ -25,6 +25,8 @@ distribution.
#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED
#include "Export.h"
struct t_matgloss
{
char id[128];
@ -447,16 +449,33 @@ struct t_trait
}
};
*/
/*
CREATURE
*/
struct t_lastname
{
int names[7];
};
struct t_squadname
{
int names[6];
};
struct t_skill
{
uint16_t id;
uint32_t experience;
uint16_t rating;
};
struct t_job
{
bool active;
uint8_t jobId;
};
#define NUM_CREATURE_TRAITS 30
#define NUM_CREATURE_LABORS 102
struct t_creature
{
uint16_t x;
@ -469,11 +488,19 @@ struct t_creature
char nick_name [128];
t_lastname last_name;
t_squadname squad_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];
/*
//string last_name;
string current_job;
*/
t_job current_job;
uint32_t happiness;
uint32_t id;
uint32_t agility;
@ -482,7 +509,6 @@ struct t_creature
uint32_t money;
int32_t squad_leader_id;
uint8_t sex;
uint8_t profession;
/*
vector <t_skill> skills;
vector <t_trait> traits;

@ -24,7 +24,8 @@ distribution.
#ifndef DFVECTOR_H_INCLUDED
#define DFVECTOR_H_INCLUDED
namespace DFHack
{
class DfVector
{
private:
@ -64,4 +65,5 @@ public:
};
};
}
#endif // DFVECTOR_H_INCLUDED

@ -0,0 +1,40 @@
/*
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.
*/
/// TODO: add visibility for GCC?
#ifdef LINUX_BUILD
# ifndef DFHACK_EXPORT
# define DFHACK_EXPORT
# endif
#else
# ifdef BUILD_DFHACK_LIB
# ifndef DFHACK_EXPORT
# define DFHACK_EXPORT __declspec(dllexport)
# endif
# else
# ifndef DFHACK_EXPORT
# define DFHACK_EXPORT __declspec(dllimport)
# endif
# endif
#endif

@ -38,7 +38,7 @@ void Mread (const uint32_t &offset, const uint32_t &size, uint8_t *target)
if(size == 0) return;
int result;
result = pread(g_ProcessMemFile, target,size,offset);
result = pread(DFHack::g_ProcessMemFile, target,size,offset);
if(result != size)
{
if(result == -1)
@ -102,7 +102,7 @@ void MreadDWord (const uint32_t &offset, uint32_t &val)
inline
void MwriteDWord (uint32_t offset, uint32_t data)
{
ptrace(PTRACE_POKEDATA,g_ProcessHandle, offset, data);
ptrace(PTRACE_POKEDATA,DFHack::g_ProcessHandle, offset, data);
}
// using these is expensive.
@ -116,7 +116,7 @@ void MwriteWord (uint32_t offset, uint16_t data)
orig |= 0x0000FFFF;
orig &= data;
*/
ptrace(PTRACE_POKEDATA,g_ProcessHandle, offset, orig);
ptrace(PTRACE_POKEDATA,DFHack::g_ProcessHandle, offset, orig);
}
inline
@ -129,7 +129,7 @@ void MwriteByte (uint32_t offset, uint8_t data)
orig |= 0x000000FF;
orig &= data;
*/
ptrace(PTRACE_POKEDATA,g_ProcessHandle, offset, orig);
ptrace(PTRACE_POKEDATA,DFHack::g_ProcessHandle, offset, orig);
}
// blah. I hate the kernel devs for crippling /proc/PID/mem. THIS IS RIDICULOUS

@ -42,7 +42,7 @@ inline
uint8_t MreadByte (const uint32_t &offset)
{
uint8_t result;
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint8_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint8_t), NULL);
return result;
}
@ -50,7 +50,7 @@ uint8_t MreadByte (const uint32_t &offset)
inline
void MreadByte (const uint32_t &offset,uint8_t &result)
{
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint8_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint8_t), NULL);
}
@ -58,7 +58,7 @@ inline
uint16_t MreadWord (const uint32_t &offset)
{
uint16_t result;
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint16_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint16_t), NULL);
return result;
}
@ -66,7 +66,7 @@ uint16_t MreadWord (const uint32_t &offset)
inline
void MreadWord (const uint32_t &offset, uint16_t &result)
{
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint16_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint16_t), NULL);
}
@ -74,7 +74,7 @@ inline
uint32_t MreadDWord (const uint32_t &offset)
{
uint32_t result;
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint32_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint32_t), NULL);
return result;
}
@ -82,7 +82,7 @@ uint32_t MreadDWord (const uint32_t &offset)
inline
void MreadDWord (const uint32_t &offset, uint32_t &result)
{
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint32_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint32_t), NULL);
}
@ -90,7 +90,7 @@ inline
uint64_t MreadQuad (const uint32_t &offset)
{
uint64_t result;
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint64_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint64_t), NULL);
return result;
}
@ -98,40 +98,40 @@ uint64_t MreadQuad (const uint32_t &offset)
inline
void MreadQuad (const uint32_t &offset, uint64_t &result)
{
ReadProcessMemory(g_ProcessHandle, (int*) offset, &result, sizeof(uint64_t), NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &result, sizeof(uint64_t), NULL);
}
inline
void Mread (const uint32_t &offset, uint32_t size, uint8_t *target)
{
ReadProcessMemory(g_ProcessHandle, (int*) offset, target, size, NULL);
ReadProcessMemory(DFHack::g_ProcessHandle, (int*) offset, target, size, NULL);
}
// WRITING
inline
void MwriteDWord (const uint32_t offset, uint32_t data)
{
WriteProcessMemory(g_ProcessHandle, (int*) offset, &data, sizeof(uint32_t), NULL);
WriteProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &data, sizeof(uint32_t), NULL);
}
// using these is expensive.
inline
void MwriteWord (uint32_t offset, uint16_t data)
{
WriteProcessMemory(g_ProcessHandle, (int*) offset, &data, sizeof(uint16_t), NULL);
WriteProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &data, sizeof(uint16_t), NULL);
}
inline
void MwriteByte (uint32_t offset, uint8_t data)
{
WriteProcessMemory(g_ProcessHandle, (int*) offset, &data, sizeof(uint8_t), NULL);
WriteProcessMemory(DFHack::g_ProcessHandle, (int*) offset, &data, sizeof(uint8_t), NULL);
}
inline
void Mwrite (uint32_t offset, uint32_t size, uint8_t *source)
{
WriteProcessMemory(g_ProcessHandle, (int*) offset, source, size, NULL);
WriteProcessMemory(DFHack::g_ProcessHandle, (int*) offset, source, size, NULL);
}
@ -143,7 +143,7 @@ const string MreadCString (const uint32_t &offset)
string temp;
char temp_c[256];
DWORD read;
ReadProcessMemory(g_ProcessHandle, (int *) offset, temp_c, 255, &read);
ReadProcessMemory(DFHack::g_ProcessHandle, (int *) offset, temp_c, 255, &read);
temp_c[read+1] = 0;
temp = temp_c;
return temp;

@ -7,7 +7,6 @@
#include <vector>
#include <ctime>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>

@ -8,6 +8,7 @@ using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
template <typename T>
void print_bits ( T val, std::ostream& out )
@ -32,6 +33,7 @@ int main (void)
return 1;
}
DFHack::memory_info mem = DF.getMemoryInfo();
// get stone matgloss mapping
if(!DF.ReadCreatureMatgloss(creaturestypes))
{
@ -44,7 +46,7 @@ int main (void)
{
t_creature temp;
DF.ReadCreature(i, temp);
cout << "creature type " << creaturestypes[temp.type].id << ", position:" << temp.x << " " << temp.y << " "<< temp.z << endl;
cout << "creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl;
bool addendl = false;
if(temp.first_name[0])
{
@ -71,36 +73,27 @@ int main (void)
cout << endl;
addendl = false;
}
/*
if(!temp.profession.empty()){
cout << ", profession: " << temp.profession;
addendl = false;
}
if(!temp.custom_profession.empty()){
cout << "profession: " << mem.getProfession(temp.profession) << "(" << (int) temp.profession << ")";
if(temp.custom_profession[0])
{
cout << ", custom profession: " << temp.custom_profession;
addendl = false;
}
if(!temp.current_job.empty()){
cout << ", current job: " << temp.current_job;
addendl = false;
}
*/
if(addendl)
if(temp.current_job.active)
{
cout << endl;
addendl = false;
cout << ", current job: " << mem.getJob(temp.current_job.jobId);
}
cout << ", happiness: " << temp.happiness << ", strength: " << temp.strength << ", agility: "
cout << endl;
cout << "happiness: " << temp.happiness << ", strength: " << temp.strength << ", agility: "
<< temp.agility << ", toughness: " << temp.toughness << ", money: " << temp.money << ", id: " << temp.id;
if(temp.squad_leader_id != -1){
cout << ", squad_leader_id: " << temp.squad_leader_id;
}
cout << ", sex";
cout << ", sex: ";
if(temp.sex == 0){
cout << ", Female";
cout << "Female";
}
else{
cout <<", Male";
cout <<"Male";
}
cout << endl;
/*
@ -158,19 +151,19 @@ int main (void)
}
if(temp.flags2.bits.resident)
{
cout << "resident ";
cout << "resident, ";
}
if(temp.flags2.bits.gutted)
{
cout << "gutted ";
cout << "gutted, ";
}
if(temp.flags2.bits.slaughter)
{
cout << "slaughter ";
cout << "marked for slaughter, ";
}
if(temp.flags2.bits.underworld)
{
cout << "from the underworld ";
cout << "from the underworld, ";
}
cout << endl << endl;
}