From a7bf3595b72604eab0a313b98a855c184be96a53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 7 Nov 2009 21:05:10 +0000 Subject: [PATCH] merged a big patch from belal, unstable on anything but windows 40d16 --- library/DFHackAPI.cpp | 149 +++++++++++++- library/DFHackAPI.h | 33 +++ library/DFMemInfo.cpp | 41 ++++ library/DFMemInfo.h | 9 + library/DFProcessManager.cpp | 10 +- library/DFTypes.h | 47 +++-- output/Memory.xml | 381 +++++++++++++++++++++++++++++++++-- tools/creaturedump.cpp | 37 ++++ 8 files changed, 666 insertions(+), 41 deletions(-) diff --git a/library/DFHackAPI.cpp b/library/DFHackAPI.cpp index d1b070a43..20d2512a8 100644 --- a/library/DFHackAPI.cpp +++ b/library/DFHackAPI.cpp @@ -649,12 +649,98 @@ uint32_t DFHackAPIImpl::InitReadCreatures() creature_flags2_offset = offset_descriptor->getOffset("creature_flags2"); creature_first_name_offset = offset_descriptor->getOffset("first_name"); creature_nick_name_offset = offset_descriptor->getOffset("nick_name"); + creature_last_name_offset = offset_descriptor->getOffset("last_name"); + creature_custom_profession_offset = offset_descriptor->getOffset("custom_profession"); + creature_profession_offset = offset_descriptor->getOffset("creature_profession"); + creature_sex_offset = offset_descriptor->getOffset("sex"); + creature_id_offset = offset_descriptor->getOffset("id"); + creature_squad_name_offset = offset_descriptor->getOffset("squad_name"); + creature_squad_leader_id_offset = offset_descriptor->getOffset("squad_leader_id"); + creature_money_offset = offset_descriptor->getOffset("money"); + creature_current_job_offset = offset_descriptor->getOffset("current_job"); + creature_current_job_id_offset = offset_descriptor->getOffset("current_job_id"); + creature_strength_offset = offset_descriptor->getOffset("strength"); + creature_agility_offset = offset_descriptor->getOffset("agility"); + creature_toughness_offset = offset_descriptor->getOffset("toughness"); + creature_skills_offset = offset_descriptor->getOffset("skills"); + creature_labors_offset = offset_descriptor->getOffset("labors"); + creature_happiness_offset = offset_descriptor->getOffset("happiness"); + creature_traits_offset = offset_descriptor->getOffset("traits"); assert(creatures && creature_pos_offset && creature_type_offset && - creature_flags1_offset && creature_flags2_offset && creature_nick_name_offset); + creature_flags1_offset && creature_flags2_offset && creature_nick_name_offset + && creature_custom_profession_offset + && creature_profession_offset + && creature_sex_offset + && creature_id_offset + && creature_squad_name_offset + && creature_squad_leader_id_offset + && creature_money_offset + && creature_current_job_offset + && creature_strength_offset + && creature_agility_offset + && creature_toughness_offset + && creature_skills_offset + && creature_labors_offset + && creature_happiness_offset + && creature_traits_offset + ); p_cre = new DfVector(dm->readVector(creatures, 4)); + InitReadNameTables(); + return p_cre->getSize(); } +//This code was mostly adapted fromh dwarftherapist by chmod +string DFHackAPIImpl::getLastName(const uint32_t &index, bool use_generic) +{ + string out; + uint32_t wordIndex; + for (int i = 0; i<7;i++) + { + MreadDWord(index+i*4, wordIndex); + if(wordIndex == 0xFFFFFFFF) + { + break; + } + if(use_generic) + { + uint32_t genericPtr; + p_generic->read(wordIndex,(uint8_t *)&genericPtr); + out.append(dm->readSTLString(genericPtr)); + } + else + { + uint32_t transPtr; + p_dwarf_names->read(wordIndex,(uint8_t *)&transPtr); + out.append(dm->readSTLString(transPtr)); + } + } + return out; +} + +string DFHackAPIImpl::getProfession(const uint32_t &index) +{ + string profession; + uint8_t profId = MreadByte(index); + profession = offset_descriptor->getProfession(profId); + return profession; +} + +string DFHackAPIImpl::getJob(const uint32_t &index) +{ + string job; + uint32_t jobIdAddr = MreadDWord(index); + if(jobIdAddr != 0) + { + uint8_t jobId = MreadByte(jobIdAddr+creature_current_job_id_offset); + job = offset_descriptor->getJob(jobId); + } + else + { + job ="No Job"; + } + return job; +} bool DFHackAPIImpl::ReadCreature(const uint32_t &index, t_creature & furball) { @@ -664,21 +750,70 @@ bool DFHackAPIImpl::ReadCreature(const uint32_t &index, t_creature & furball) p_cre->read(index,(uint8_t *)&temp); //read creature from memory Mread(temp + creature_pos_offset, 3 * sizeof(uint16_t), (uint8_t *) &(furball.x)); // xyz really - Mread(temp + creature_type_offset, sizeof(uint32_t), (uint8_t *) &furball.type); - Mread(temp + creature_flags1_offset, sizeof(uint32_t), (uint8_t *) &furball.flags1); - Mread(temp + creature_flags2_offset, sizeof(uint32_t), (uint8_t *) &furball.flags2); - // names. + MreadDWord(temp + creature_type_offset, furball.type); + MreadDWord(temp + creature_flags1_offset, furball.flags1.whole); + MreadDWord(temp + creature_flags2_offset, furball.flags2.whole); + // names furball.first_name = dm->readSTLString(temp+creature_first_name_offset); - furball.nick_name = dm->readSTLString(temp+creature_nick_name_offset); + furball.nick_name = dm->readSTLString(temp+creature_nick_name_offset); + furball.trans_name = getLastName(temp+creature_last_name_offset); + furball.generic_name = getLastName(temp+creature_last_name_offset,true); + furball.custom_profession = dm->readSTLString(temp+creature_custom_profession_offset); + furball.profession = getProfession(temp+creature_profession_offset); + furball.current_job = getJob(temp+creature_current_job_offset); + + MreadDWord(temp + creature_happiness_offset, furball.happiness); + MreadDWord(temp + creature_id_offset, furball.id); + MreadDWord(temp + creature_agility_offset, furball.agility); + MreadDWord(temp + creature_strength_offset, furball.strength); + MreadDWord(temp + creature_toughness_offset, furball.toughness); + MreadDWord(temp + creature_money_offset, furball.money); + MreadDWord(temp + creature_squad_leader_id_offset, furball.squad_leader_id); + MreadByte(temp + creature_sex_offset, furball.sex); return true; } +void DFHackAPIImpl::InitReadNameTables() +{ + int genericAddress = offset_descriptor->getAddress("language_vector"); + int transAddress = offset_descriptor->getAddress("translation_vector"); + int word_table_offset = offset_descriptor->getOffset("word_table"); + + p_generic = new DfVector(dm->readVector(genericAddress, 4)); + p_trans = new DfVector(dm->readVector(transAddress, 4)); + uint32_t dwarf_entry = 0; + + for(uint32_t i = 0; i < p_trans->getSize();i++) + { + uint32_t namePtr; + p_trans->read(i,(uint8_t *)&namePtr); + string raceName = dm->readSTLString(namePtr); + + if(raceName == "DWARF") + { + dwarf_entry = namePtr; + } + } + + dwarf_lang_table_offset = dwarf_entry + word_table_offset-4; + p_dwarf_names = new DfVector(dm->readVector(dwarf_lang_table_offset,4)); + nameTablesInited = true; +} + +void DFHackAPIImpl::FinishReadNameTables() +{ + delete p_trans; + delete p_generic; + p_trans=p_generic=NULL; + nameTablesInited=false; +} void DFHackAPIImpl::FinishReadCreatures() { delete p_cre; p_cre = NULL; creaturesInited = false; + FinishReadNameTables(); } bool DFHackAPIImpl::Attach() @@ -714,7 +849,7 @@ bool DFHackAPIImpl::Detach() bool DFHackAPIImpl::isAttached() { - return dm != NULL; + return dm != NULL; } void DFHackAPIImpl::ReadRaw (const uint32_t &offset, const uint32_t &size, uint8_t *target) diff --git a/library/DFHackAPI.h b/library/DFHackAPI.h index d5fc8b3dc..a8fcc4c75 100644 --- a/library/DFHackAPI.h +++ b/library/DFHackAPI.h @@ -194,6 +194,26 @@ private: uint32_t creature_flags2_offset; uint32_t creature_first_name_offset; uint32_t creature_nick_name_offset; + uint32_t creature_last_name_offset; + + uint32_t creature_custom_profession_offset; + uint32_t creature_profession_offset; + uint32_t creature_sex_offset; + uint32_t creature_id_offset; + uint32_t creature_squad_name_offset; + uint32_t creature_squad_leader_id_offset; + uint32_t creature_money_offset; + uint32_t creature_current_job_offset; + uint32_t creature_current_job_id_offset; + uint32_t creature_strength_offset; + uint32_t creature_agility_offset; + uint32_t creature_toughness_offset; + uint32_t creature_skills_offset; + uint32_t creature_labors_offset; + uint32_t creature_happiness_offset; + uint32_t creature_traits_offset; + + uint32_t dwarf_lang_table_offset; ProcessManager* pm; Process* p; @@ -206,11 +226,18 @@ private: bool buildingsInited; bool vegetationInited; bool creaturesInited; + + bool nameTablesInited; + uint32_t tree_offset; DfVector *p_cre; DfVector *p_cons; DfVector *p_bld; DfVector *p_veg; + + DfVector *p_trans; + DfVector *p_generic; + DfVector *p_dwarf_names; public: @@ -311,6 +338,12 @@ public: uint32_t InitReadCreatures(); bool ReadCreature(const uint32_t &index, t_creature & furball); void FinishReadCreatures(); + + void InitReadNameTables(); + void FinishReadNameTables(); + string getLastName(const uint32_t &index, bool use_generic=false); + string getProfession(const uint32_t &index); + string getJob(const uint32_t &index); void ReadRaw (const uint32_t &offset, const uint32_t &size, uint8_t *target); }; diff --git a/library/DFMemInfo.cpp b/library/DFMemInfo.cpp index ba53acc75..1f084b4f6 100644 --- a/library/DFMemInfo.cpp +++ b/library/DFMemInfo.cpp @@ -109,6 +109,8 @@ memory_info::memory_info(const memory_info &old) classes = old.classes; classsubtypes = old.classsubtypes; classindex = old.classindex; + professions = old.professions; + jobs = old.jobs; } @@ -156,6 +158,24 @@ void memory_info::setString (string key, string value) strings[key] = value; } +void memory_info::setProfession (string key, string value) +{ + uint32_t keyInt = strtol(key.c_str(), NULL, 10); + if(professions.size() <= keyInt){ + professions.resize(keyInt+1); + } + professions[keyInt] = value; +} + +void memory_info::setJob (string key, string value) +{ + uint32_t keyInt = strtol(key.c_str(), NULL, 10); + if(jobs.size() <= keyInt){ + jobs.resize(keyInt+1); + } + jobs[keyInt] = value; +} + // FIXME: next three methods should use some kind of custom container so it doesn't have to search so much. void memory_info::setClass (const char * name, const char * vtable) @@ -369,6 +389,27 @@ uint32_t memory_info::getHexValue (string key) return 0; } +// Get Profession +string memory_info::getProfession (uint32_t key) +{ + if(professions.size() > key) + { + return professions[key]; + } + else{ + return string(""); + } +} + +// Get Job +string memory_info::getJob (uint32_t key) +{ + if(jobs.size() > key){ + return jobs[key]; + } + return string("Job Does Not Exist"); +} + // Reset everything void memory_info::flush() diff --git a/library/DFMemInfo.h b/library/DFMemInfo.h index e419dfa9e..3968225fb 100644 --- a/library/DFMemInfo.h +++ b/library/DFMemInfo.h @@ -63,6 +63,8 @@ public: uint32_t getAddress (string); uint32_t getHexValue (string); string getString (string); + string getProfession(uint32_t); + string getJob(uint32_t); void setVersion(const char *); void setVersion(string); @@ -86,6 +88,9 @@ public: void setAddress (string, string); void setHexValue (string, string); void setString (string, string); + + void setProfession(string, string); + void setJob(string, string); void RebaseVTable(int32_t offset); void setClass (const char * name, const char * vtable); @@ -103,6 +108,10 @@ private: map offsets; map hexvals; map strings; + + vector professions; + vector jobs; + vector classes; vector > classsubtypes; int32_t base; diff --git a/library/DFProcessManager.cpp b/library/DFProcessManager.cpp index e1d0b8fe9..bfe895812 100644 --- a/library/DFProcessManager.cpp +++ b/library/DFProcessManager.cpp @@ -437,6 +437,14 @@ void ProcessManager::ParseEntry (TiXmlElement* entry, memory_info& mem, map 0x0664 --> + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + 37 + 38 + 39 + 40 + 41 + 42 + 43 + 44 + 45 + 46 + 47 + 48 + 49 + 50 + 51 + 52 + 53 + 54 + 55 + 56 + 57 + 58 + 59 + 60 + 61 + 62 + 63 + 64 + 65 + 66 + 67 + 68 + 69 + 70 + 71 + 72 + 73 + 74 + 75 + 76 + 77 + 78 + 79 + 80 + 81 + 82 + 83 + 84 + 85 + 86 + 87 + 88 + 89 + 90 + 91 + 92 + 93 + 94 + 95 + 96 + 97 + 98 + 99 + 100 + 101 + 102 + 103 + 104 + 105 + 106 + 107 + 108 + 109 + 110 + 111 + 112 + 113 + 114 + 115 + 116 + 117 + 118 + 119 + 120 + 121 + 122 + 123 + 124 + 125 + 126 + 127 + 128 + 129 + 130 + 131 + 132 + 133 + 134 + 135 + 136 + 137 + 138 + 139 + 140 + 141 + 142 + 143 + 144 + 145 + 146 + 147 + 148 + 149 + 150 + 151 + 152 + 153 + 154 + 155 + 156 + 157 + 158 + 159 + 160 + 161 + 162 + 163 + 164 + 165 + 166 + 167 + 168 + 169 + 170 + 171 + 172 + 173 + 174 + 175 + 176 + 177 + 178 + 179 + 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 + 190 + 191 + 192 + 193 + 194 + 195 + 196 + 197 + 198 + 199 + 200 + 201 + 202 + + + .,:rsr, :2;,;r2A@@5 @2::s5A#@@@ @r. . @@ -55,7 +377,7 @@ and W I N E - + 0x48C330DF 2c686c26307dcccd7c36cc79737ebe4f @@ -93,6 +415,24 @@ 0x8C 0xE4 0xE8 + 0x6c + 0x88 + 0x8C + 0xFC + 0x100 + 0x10A + 0x10C + 0x1D8 + 0x268 + 0x2F8 + 0x314 + 0x4f0 + 0x4f4 + 0x4f8 + 0x504 + 0x544 + 0x610 + 0x700 0x70 @@ -310,6 +650,7 @@
0x015FCE3C
+
@@ -341,7 +682,13 @@ 59ab29021aca9f3c66b1ab102fb3ceea - + +
0x01604134
+
0x01604104
+ 0x38 + 0x58 + 0x08 +
.-"""-. ' \ @@ -363,7 +710,7 @@ `"--...,+"""" `._,.-' - + 992afd73855e787860277f53d18afcbb @@ -382,6 +729,7 @@ 0x00 0x04 + 0x38 0x4C 0x44 0x90 @@ -389,17 +737,17 @@ 0x40 - +
0x09372FD4
0x09372FD8
0x09372FDC
- +
0x09372FEC
0x09372FF0
0x09372FF4
- + 0x08 0x2C @@ -407,21 +755,21 @@ 0x0254 0x0654 0x1D54 - +
0x093745EC
0x54 0x56 0x5A4 0x5C8 - + 0x58 0x54 - + 0x4 - +
0x9374E88
0xC @@ -444,7 +792,7 @@ - + @@ -525,27 +873,27 @@ 4367c59934cbcf14f43fd3af6444c455 - +
0x08F95BBC
0x08F41918
0x08F55740
0x08F58890
0x08F55250
- +
0x08F95BD0
0x08F95BD4
0x08F95BD8
- +
0x08F95BE8
0x08F95BEC
0x08F95BF0
- +
0x08F971E8
- +
0x08F97A84
@@ -578,6 +926,7 @@
+ diff --git a/tools/creaturedump.cpp b/tools/creaturedump.cpp index fa45d1d2e..c1e97aeb9 100644 --- a/tools/creaturedump.cpp +++ b/tools/creaturedump.cpp @@ -57,10 +57,47 @@ int main (void) cout << ", nick name: " << temp.nick_name; addendl = true; } + if(!temp.trans_name.empty()){ + cout << ", trans name: " << temp.trans_name; + addendl =true; + } + if(!temp.generic_name.empty()){ + cout << ", generic name: " << temp.generic_name; + addendl=true; + } if(addendl) { cout << endl; + addendl = false; + } + if(!temp.profession.empty()){ + cout << "profession: " << temp.profession; + addendl = false; + } + if(!temp.custom_profession.empty()){ + cout << ", custom profession: " << temp.custom_profession; + addendl = false; } + if(!temp.current_job.empty()){ + cout << ", current job: " << temp.current_job; + addendl = false; + } + if(addendl) + { + cout << endl; + addendl = false; + } + cout << "happiness: " << temp.happiness << ", strength: " << temp.strength << ", agility: " + << temp.agility << ", toughness: " << temp.toughness << ", money: " << temp.money; + cout << ", sex"; + if(temp.sex == 0){ + cout << ", Female"; + } + else{ + cout <<", Male"; + } + cout << endl; + /* * FLAGS 1 */