From f46a7f1213fb878d999c7c0b4f9b39c2dd22f9ab Mon Sep 17 00:00:00 2001 From: "U-glouglou\\simon" Date: Sun, 2 May 2010 10:35:23 +0200 Subject: [PATCH 01/13] Basic code for item handling, now it should be tested :) --- dfhack/CMakeLists.txt | 3 +- dfhack/include/modules/Items.h | 66 ++++++++++ dfhack/include/modules/Materials.h | 2 +- dfhack/modules/Creatures.cpp | 4 +- dfhack/modules/Items.cpp | 202 +++++++++++++++++++++++++++++ examples/creaturedump.cpp | 2 +- output/Memory.xml | 6 + 7 files changed, 280 insertions(+), 5 deletions(-) create mode 100755 dfhack/include/modules/Items.h create mode 100755 dfhack/modules/Items.cpp diff --git a/dfhack/CMakeLists.txt b/dfhack/CMakeLists.txt index c00d3218e..f3b49b315 100644 --- a/dfhack/CMakeLists.txt +++ b/dfhack/CMakeLists.txt @@ -36,6 +36,7 @@ depends/tinyxml/tinyxmlparser.cpp modules/Creatures.cpp modules/Gui.cpp +modules/Items.cpp modules/Maps.cpp modules/Materials.cpp modules/Position.cpp @@ -135,4 +136,4 @@ ENDIF(UNIX) # SWIG_ADD_MODULE(pydfhack python pydfhack.i) # SWIG_LINK_LIBRARIES(pydfhack ${PYTHON_LIBRARIES} dfhack) # ENDIF(PYTHONLIBS_FOUND) -#ENDIF(SWIG_FOUND) \ No newline at end of file +#ENDIF(SWIG_FOUND) diff --git a/dfhack/include/modules/Items.h b/dfhack/include/modules/Items.h new file mode 100755 index 000000000..30f4bd8d8 --- /dev/null +++ b/dfhack/include/modules/Items.h @@ -0,0 +1,66 @@ +#ifndef CL_MOD_ITEMS +#define CL_MOD_ITEMS +/* +* Creatures +*/ +#include "Export.h" +namespace DFHack +{ + +enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT}; + +/* this is used to store data about the way accessors work */ +class DFHACK_EXPORT Accessor +{ +private: + accessor_type type; + int32_t constant; + uint32_t offset1; + uint32_t offset2; + Process * p; + uint32_t dataWidth; +public: + Accessor(uint32_t function, Process * p); + Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p); + int32_t getValue(uint32_t objectPtr); +}; + +struct t_item +{ + t_material matdesc; + int32_t quantity; + int32_t quality; +}; + +class DFHACK_EXPORT ItemDesc +{ +private: + Accessor * AMainType; + Accessor * ASubType; + Accessor * ASubIndex; + Accessor * AIndex; + Accessor * AQuality; + Process * p; + bool hasDecoration; +public: + ItemDesc(uint32_t VTable, Process * p); + bool getItem(uint32_t itemptr, t_item & item); + std::string className; + uint32_t vtable; +}; + +class DFHACK_EXPORT Items +{ +public: + Items(DFHack::APIPrivate * _d); + ~Items(); + std::string getItemDescription(uint32_t itemptr); + bool getItemData(uint32_t itemptr, t_item & item); +private: + class Private; + Private* d; + /*std::map descType; might be useful later */ + std::map descVTable; +}; +} +#endif diff --git a/dfhack/include/modules/Materials.h b/dfhack/include/modules/Materials.h index 8198b2991..1fd4d66fe 100644 --- a/dfhack/include/modules/Materials.h +++ b/dfhack/include/modules/Materials.h @@ -74,8 +74,8 @@ namespace DFHack struct t_material { int16_t itemType; - int16_t typeB; int16_t subType; + int16_t subIndex; int32_t index; uint32_t flags; }; diff --git a/dfhack/modules/Creatures.cpp b/dfhack/modules/Creatures.cpp index 9b22d2ad8..55e86f18b 100644 --- a/dfhack/modules/Creatures.cpp +++ b/dfhack/modules/Creatures.cpp @@ -375,8 +375,8 @@ bool Creatures::ReadJob(const t_creature * furball, vector & mat) for(i=0;ireadWord(cmats[i] + minfo->getOffset("job_material_maintype")); - mat[i].typeB = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype1")); - mat[i].subType = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype2")); + mat[i].subType = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype1")); + mat[i].subIndex = p->readWord(cmats[i] + minfo->getOffset("job_material_sectype2")); mat[i].index = p->readDWord(cmats[i] + minfo->getOffset("job_material_sectype3")); mat[i].flags = p->readDWord(cmats[i] + minfo->getOffset("job_material_flags")); } diff --git a/dfhack/modules/Items.cpp b/dfhack/modules/Items.cpp new file mode 100755 index 000000000..093236d97 --- /dev/null +++ b/dfhack/modules/Items.cpp @@ -0,0 +1,202 @@ +/* +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. +*/ + +#include "DFCommonInternal.h" +#include "../private/APIPrivate.h" +#include "modules/Materials.h" +#include "modules/Items.h" +#include "DFMemInfo.h" +#include "DFProcess.h" +#include "DFVector.h" + +using namespace DFHack; + +class Items::Private +{ + public: + APIPrivate *d; + Process * owner; + /* + bool Inited; + bool Started; + */ +}; + +Items::Items(APIPrivate * d_) +{ + d = new Private; + d->d = d_; + d->owner = d_->p; +} +Items::~Items() +{ + delete d; + /* TODO : delete all item descs */ +} + +Accessor::Accessor(uint32_t function, Process *p) +{ + this->p = p; + this->constant = 0; + this->offset1 = 0; + this->offset2 = 0; + this->type = ACCESSOR_CONSTANT; + this->dataWidth = 2; + uint64_t funcText = p->readQuad(function); + if( funcText == 0xCCCCCCCCCCC3C033LL ) + { + return; + } + if( funcText == 0xCCCCCCCCC3FFC883LL ) + { + /* or eax,-1; ret; */ + this->constant = -1; + return; + } + if( (funcText&0xFFFFFFFFFF0000FFLL) == 0xCCCCC300000000B8LL ) + { + /* mov eax, xx; ret; */ + this->constant = (funcText>>8) & 0xffff; + return; + } + if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC300000000818B66LL ) + { + /* mov ax, [ecx+xx]; ret; */ + this->type = ACCESSOR_INDIRECT; + this->offset1 = (funcText>>24) & 0xffff; + return; + } + if( (funcText&0xFFFFFFFF0000FFFFLL) == 0x8B6600000000818BLL ) + { + uint64_t funcText2 = p->readQuad(function+8); + if( (funcText2&0xFFFFFFFFFFFF00FFLL) == 0xCCCCCCCCCCC30040LL ) + { + this->type = ACCESSOR_DOUBLE_INDIRECT; + this->offset1 = (funcText>>16) & 0xffff; + this->offset2 = (funcText2>>8) & 0xff; + return; + } + } + if( (funcText&0xFFFFFFFF0000FFFFLL) == 0xCCC300000000818BLL ) + { + /* mov eax, [ecx+xx]; ret; */ + this->type = ACCESSOR_INDIRECT; + this->offset1 = (funcText>>16) & 0xffff; + this->dataWidth = 4; + return; + } + printf("bad accessor @0x%x\n", function); +} + +int32_t Accessor::getValue(uint32_t objectPtr) +{ + switch(this->type) + { + case ACCESSOR_CONSTANT: + return this->constant; + break; + case ACCESSOR_INDIRECT: + switch(this->dataWidth) + { + case 2: + return p->readWord(objectPtr + this->offset1); + case 4: + return p->readDWord(objectPtr + this->offset1); + default: + return -1; + } + break; + case ACCESSOR_DOUBLE_INDIRECT: + switch(this->dataWidth) + { + case 2: + return p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2); + case 4: + return p->readDWord(p->readDWord(objectPtr + this->offset1) + this->offset2); + default: + return -1; + } + break; + default: + return -1; + } +} + +ItemDesc::ItemDesc(uint32_t VTable, Process *p) +{ + uint32_t funcOffsetA = p->getDescriptor()->getOffset("item_type_accessor"); + uint32_t funcOffsetB = p->getDescriptor()->getOffset("item_subtype_accessor"); + uint32_t funcOffsetC = p->getDescriptor()->getOffset("item_subindex_accessor"); + uint32_t funcOffsetD = p->getDescriptor()->getOffset("item_index_accessor"); + uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor"); + this->vtable = VTable; + this->p = p; + this->className = p->readClassName(VTable); + this->AMainType = new Accessor( p->readDWord( VTable + funcOffsetA ), p); + this->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), p); + this->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p); + this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p); + this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p); + this->hasDecoration = false; +} + +bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item) +{ + item.matdesc.itemType = this->AMainType->getValue(itemptr); + item.matdesc.subType = this->ASubType->getValue(itemptr); + item.matdesc.subIndex = this->ASubIndex->getValue(itemptr); + item.matdesc.index = this->AIndex->getValue(itemptr); + item.quality = this->AQuality->getValue(itemptr); + item.quantity = 1; /* TODO */ + return true; +} + +bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item) +{ + std::map::iterator it; + Process * p = d->owner; + ItemDesc * desc; + + it = this->descVTable.find(itemptr); + if(it==descVTable.end()) + { + uint32_t vtable = p->readDWord(itemptr); + desc = new ItemDesc(vtable, p); + this->descVTable[vtable] = desc; + } + else + desc = it->second; + + return desc->getItem(itemptr, item); +} + +std::string Items::getItemDescription(uint32_t itemptr) +{ + DFHack::t_item item; + std::string out; + + if(!this->getItemData(itemptr, item)) + return "??"; + return "!!"; +} \ No newline at end of file diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index 2c08f7532..02378a3b5 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -241,7 +241,7 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) { for(unsigned int i = 0; i < mymat.size(); i++) { - printf("\t%s(%d)\t%d %d %d - %.8x\n", Materials->getDescription(mymat[i]).c_str(), mymat[i].itemType, mymat[i].typeB, mymat[i].subType, mymat[i].index, mymat[i].flags); + printf("\t%s(%d)\t%d %d %d - %.8x\n", Materials->getDescription(mymat[i]).c_str(), mymat[i].itemType, mymat[i].subType, mymat[i].subIndex, mymat[i].index, mymat[i].flags); } } } diff --git a/output/Memory.xml b/output/Memory.xml index a54ef24b5..b9dced466 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1502,6 +1502,12 @@ map_data_1b60_offset 0x1B9c Items =====
0x166FE00
+ List of offsets in the VTable : + 0x0 + 0x4 + 0x8 + 0xC + 0x238 0xA0 0x14 From 663d5894b8bc9922670d46bd9fd4b8418526e780 Mon Sep 17 00:00:00 2001 From: "U-glouglou\\simon" Date: Sun, 2 May 2010 10:36:13 +0200 Subject: [PATCH 02/13] proper modes --- dfhack/include/modules/Items.h | 0 dfhack/modules/Items.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 dfhack/include/modules/Items.h mode change 100755 => 100644 dfhack/modules/Items.cpp diff --git a/dfhack/include/modules/Items.h b/dfhack/include/modules/Items.h old mode 100755 new mode 100644 diff --git a/dfhack/modules/Items.cpp b/dfhack/modules/Items.cpp old mode 100755 new mode 100644 From 2e61410fb446e2c9ce866c02d3a0ce8fbc1fcc22 Mon Sep 17 00:00:00 2001 From: "U-glouglou\\simon" Date: Sun, 2 May 2010 11:27:16 +0200 Subject: [PATCH 03/13] Debugging the material access system : seems to work now --- dfhack/APIPrivate.cpp | 1 + dfhack/DFHackAPI.cpp | 13 ++++ dfhack/include/DFHackAPI.h | 4 ++ dfhack/include/DFTypes.h | 28 -------- dfhack/include/modules/Items.h | 128 ++++++++++++++++----------------- dfhack/modules/Items.cpp | 87 ++++++++++++---------- dfhack/private/APIPrivate.h | 2 + dfhack/python/DF_Helpers.cpp | 4 +- examples/creaturedump.cpp | 1 - examples/dfitemdump.cpp | 8 +++ tools/moodump.cpp | 1 - 11 files changed, 143 insertions(+), 134 deletions(-) diff --git a/dfhack/APIPrivate.cpp b/dfhack/APIPrivate.cpp index 74df2b358..95da0cf04 100644 --- a/dfhack/APIPrivate.cpp +++ b/dfhack/APIPrivate.cpp @@ -31,6 +31,7 @@ APIPrivate::APIPrivate() vegetation = 0; buildings = 0; constructions = 0; + items = 0; } APIPrivate::~APIPrivate() diff --git a/dfhack/DFHackAPI.cpp b/dfhack/DFHackAPI.cpp index 407a6b595..9aea26544 100644 --- a/dfhack/DFHackAPI.cpp +++ b/dfhack/DFHackAPI.cpp @@ -37,6 +37,7 @@ distribution. #include "modules/Maps.h" #include "modules/Materials.h" +#include "modules/Items.h" #include "modules/Position.h" #include "modules/Gui.h" #include "modules/Creatures.h" @@ -148,6 +149,11 @@ bool API::Detach() delete d->materials; d->materials = 0; } + if(d->items) + { + delete d->items; + d->items = 0; + } if(d->gui) { delete d->gui; @@ -265,6 +271,13 @@ Materials * API::getMaterials() return d->materials; } +Items * API::getItems() +{ + if(!d->items) + d->items = new Items(d); + return d->items; +} + Translation * API::getTranslation() { if(!d->translation) diff --git a/dfhack/include/DFHackAPI.h b/dfhack/include/DFHackAPI.h index f802e4b64..188f295ca 100644 --- a/dfhack/include/DFHackAPI.h +++ b/dfhack/include/DFHackAPI.h @@ -52,6 +52,7 @@ namespace DFHack class Vegetation; class Buildings; class Constructions; + class Items; class DFHACK_EXPORT API { @@ -103,6 +104,9 @@ namespace DFHack // get the materials module Materials * getMaterials(); + + // get the items module + Items * getItems(); // get the translation module Translation * getTranslation(); diff --git a/dfhack/include/DFTypes.h b/dfhack/include/DFTypes.h index c1cf2186e..fea2247b2 100644 --- a/dfhack/include/DFTypes.h +++ b/dfhack/include/DFTypes.h @@ -169,34 +169,6 @@ union t_itemflags }; //cooked -struct t_item -{ - uint32_t origin; - uint32_t vtable; - - uint32_t x; - uint32_t y; - uint32_t z; - - t_itemflags flags; - uint32_t ID; - uint32_t type; - t_matglossPair material; - /* - uint8_t matType; - uint8_t material; - */ - // vector bytes; used for item research - // FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed) -}; - -// can add more here later, but this is fine for now -struct t_itemType -{ - char id[128]; - char name[128]; -}; - struct t_viewscreen { int32_t type; diff --git a/dfhack/include/modules/Items.h b/dfhack/include/modules/Items.h index 30f4bd8d8..181ee68ee 100644 --- a/dfhack/include/modules/Items.h +++ b/dfhack/include/modules/Items.h @@ -1,66 +1,66 @@ -#ifndef CL_MOD_ITEMS -#define CL_MOD_ITEMS -/* -* Creatures -*/ -#include "Export.h" -namespace DFHack -{ - -enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT}; - -/* this is used to store data about the way accessors work */ -class DFHACK_EXPORT Accessor -{ -private: - accessor_type type; - int32_t constant; - uint32_t offset1; - uint32_t offset2; - Process * p; - uint32_t dataWidth; -public: - Accessor(uint32_t function, Process * p); - Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p); - int32_t getValue(uint32_t objectPtr); -}; - -struct t_item -{ - t_material matdesc; - int32_t quantity; - int32_t quality; -}; - -class DFHACK_EXPORT ItemDesc -{ -private: - Accessor * AMainType; - Accessor * ASubType; - Accessor * ASubIndex; - Accessor * AIndex; - Accessor * AQuality; - Process * p; - bool hasDecoration; -public: - ItemDesc(uint32_t VTable, Process * p); - bool getItem(uint32_t itemptr, t_item & item); - std::string className; - uint32_t vtable; -}; - -class DFHACK_EXPORT Items -{ -public: - Items(DFHack::APIPrivate * _d); - ~Items(); - std::string getItemDescription(uint32_t itemptr); - bool getItemData(uint32_t itemptr, t_item & item); +#ifndef CL_MOD_ITEMS +#define CL_MOD_ITEMS +/* +* Creatures +*/ +#include "Export.h" +namespace DFHack +{ + +enum accessor_type {ACCESSOR_CONSTANT, ACCESSOR_INDIRECT, ACCESSOR_DOUBLE_INDIRECT}; + +/* this is used to store data about the way accessors work */ +class DFHACK_EXPORT Accessor +{ +private: + accessor_type type; + int32_t constant; + uint32_t offset1; + uint32_t offset2; + Process * p; + uint32_t dataWidth; +public: + Accessor(uint32_t function, Process * p); + Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p); + int32_t getValue(uint32_t objectPtr); +}; + +struct t_item +{ + t_material matdesc; + int32_t quantity; + int32_t quality; +}; + +class DFHACK_EXPORT ItemDesc +{ +private: + Accessor * AMainType; + Accessor * ASubType; + Accessor * ASubIndex; + Accessor * AIndex; + Accessor * AQuality; + Process * p; + bool hasDecoration; +public: + ItemDesc(uint32_t VTable, Process * p); + bool getItem(uint32_t itemptr, t_item & item); + std::string className; + uint32_t vtable; +}; + +class DFHACK_EXPORT Items +{ +public: + Items(DFHack::APIPrivate * _d); + ~Items(); + std::string getItemDescription(uint32_t itemptr); + bool getItemData(uint32_t itemptr, t_item & item); private: class Private; - Private* d; - /*std::map descType; might be useful later */ - std::map descVTable; -}; -} -#endif + Private* d; + /*std::map descType; might be useful later */ + std::map descVTable; +}; +} +#endif diff --git a/dfhack/modules/Items.cpp b/dfhack/modules/Items.cpp index 093236d97..ca9be516a 100644 --- a/dfhack/modules/Items.cpp +++ b/dfhack/modules/Items.cpp @@ -1,37 +1,37 @@ -/* -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. -*/ - -#include "DFCommonInternal.h" -#include "../private/APIPrivate.h" -#include "modules/Materials.h" -#include "modules/Items.h" -#include "DFMemInfo.h" -#include "DFProcess.h" -#include "DFVector.h" - -using namespace DFHack; - +/* +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. +*/ + +#include "DFCommonInternal.h" +#include "../private/APIPrivate.h" +#include "modules/Materials.h" +#include "modules/Items.h" +#include "DFMemInfo.h" +#include "DFProcess.h" +#include "DFVector.h" + +using namespace DFHack; + class Items::Private { public: @@ -41,8 +41,8 @@ class Items::Private bool Inited; bool Started; */ -}; - +}; + Items::Items(APIPrivate * d_) { d = new Private; @@ -98,6 +98,13 @@ Accessor::Accessor(uint32_t function, Process *p) return; } } + if( (funcText&0xFFFFFF0000FFFFFFLL) == 0xC30000000081BF0FLL ) + { + /* movsx eax, word ptr [ecx+xx]; ret */ + this->type = ACCESSOR_INDIRECT; + this->offset1 = (funcText>>24) & 0xffff; + return; + } if( (funcText&0xFFFFFFFF0000FFFFLL) == 0xCCC300000000818BLL ) { /* mov eax, [ecx+xx]; ret; */ @@ -111,6 +118,8 @@ Accessor::Accessor(uint32_t function, Process *p) int32_t Accessor::getValue(uint32_t objectPtr) { + int32_t sout; + switch(this->type) { case ACCESSOR_CONSTANT: @@ -120,7 +129,7 @@ int32_t Accessor::getValue(uint32_t objectPtr) switch(this->dataWidth) { case 2: - return p->readWord(objectPtr + this->offset1); + return (int16_t) p->readWord(objectPtr + this->offset1); case 4: return p->readDWord(objectPtr + this->offset1); default: @@ -131,7 +140,7 @@ int32_t Accessor::getValue(uint32_t objectPtr) switch(this->dataWidth) { case 2: - return p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2); + return (int16_t) p->readWord(p->readDWord(objectPtr + this->offset1) + this->offset2); case 4: return p->readDWord(p->readDWord(objectPtr + this->offset1) + this->offset2); default: @@ -167,6 +176,8 @@ bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item) item.matdesc.subType = this->ASubType->getValue(itemptr); item.matdesc.subIndex = this->ASubIndex->getValue(itemptr); item.matdesc.index = this->AIndex->getValue(itemptr); + if(item.matdesc.index == 0xffff) + printf("wtf"); item.quality = this->AQuality->getValue(itemptr); item.quantity = 1; /* TODO */ return true; diff --git a/dfhack/private/APIPrivate.h b/dfhack/private/APIPrivate.h index c331886de..259730d58 100644 --- a/dfhack/private/APIPrivate.h +++ b/dfhack/private/APIPrivate.h @@ -36,6 +36,7 @@ namespace DFHack class Position; class Maps; class Creatures; + class Items; class Translation; class Buildings; class ProcessEnumerator; @@ -71,6 +72,7 @@ namespace DFHack Position * position; Gui * gui; Materials * materials; + Items * items; Translation * translation; Vegetation * vegetation; Buildings * buildings; diff --git a/dfhack/python/DF_Helpers.cpp b/dfhack/python/DF_Helpers.cpp index c646b9c55..046022bfc 100644 --- a/dfhack/python/DF_Helpers.cpp +++ b/dfhack/python/DF_Helpers.cpp @@ -148,12 +148,12 @@ static PyObject* BuildAttribute(DFHack::t_attrib& at) return attrObj; } - +/* static PyObject* BuildItemType(DFHack::t_itemType& item) { return Py_BuildValue("ss", item.id, item.name); } - +*/ static PyObject* BuildLike(DFHack::t_like& like) { PyObject* item; diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index 02378a3b5..33a653819 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -27,7 +27,6 @@ enum likeType }; DFHack::Materials * Materials; -vector< vector > itemTypes; DFHack::memory_info *mem; vector< vector > englishWords; vector< vector > foreignWords; diff --git a/examples/dfitemdump.cpp b/examples/dfitemdump.cpp index 9ec127a20..3848c32ad 100644 --- a/examples/dfitemdump.cpp +++ b/examples/dfitemdump.cpp @@ -18,6 +18,7 @@ using namespace std; #include #include #include +#include DFHack::Materials * Materials; @@ -69,6 +70,7 @@ int main () DFHack::API DF("Memory.xml"); DFHack::Process * p; unsigned int i,j; + DFHack::Items * Items; try { @@ -89,6 +91,7 @@ int main () p = DF.getProcess(); DFHack::DfVector p_items (p, p->getDescriptor()->getAddress ("items_vector")); uint32_t size = p_items.size(); + Items = DF.getItems(); printf("type\tvtable\tname\tquality\tdecorate\n"); @@ -115,6 +118,9 @@ int main () uint32_t quality = 0; bool hasDecorations; string desc = p->readClassName(vtable); + DFHack::t_item itm; + + Items->getItemData(p_items[i], itm); if ( (funct0&0xFFFFFFFFFF000000LL) != 0xCCCCC30000000000LL ) { @@ -190,6 +196,8 @@ int main () printf("%d\t%p\t%s\t%d\t[%d,%d,%d -> %s]", type, (void*)vtable, desc.c_str(), quality, typeB, typeC, typeD, getMatDesc(typeB, typeC, typeD).c_str()); // printf("\t%p\t%.16LX", (void *) funcD, funcDt); + if( (type!=itm.matdesc.itemType) || (typeB!=itm.matdesc.subType) || (typeC!=itm.matdesc.subIndex) || (typeD!=itm.matdesc.index) ) + printf("\tbad[%d,%d,%d,%d]", itm.matdesc.itemType, itm.matdesc.subType, itm.matdesc.subIndex, itm.matdesc.index); if (hasDecorations) { bool sep = false; diff --git a/tools/moodump.cpp b/tools/moodump.cpp index 1f243211f..9b61c0701 100644 --- a/tools/moodump.cpp +++ b/tools/moodump.cpp @@ -16,7 +16,6 @@ using namespace std; #include DFHack::Materials * Materials; -vector< vector > itemTypes; DFHack::memory_info *mem; vector< vector > englishWords; vector< vector > foreignWords; From f4d6836a85a90be3c88f3b809195e1e71c0fc1fc Mon Sep 17 00:00:00 2001 From: "U-glouglou\\simon" Date: Sun, 2 May 2010 12:50:51 +0200 Subject: [PATCH 04/13] A bit of debugging done, and the Items::getItemDescription is finally here ! --- dfhack/include/modules/Items.h | 7 +- dfhack/include/modules/Materials.h | 75 ++++++++++----------- dfhack/modules/Items.cpp | 52 +++++++++++++-- dfhack/modules/Materials.cpp | 104 +++++++++++++---------------- examples/dfitemdump.cpp | 53 ++------------- 5 files changed, 138 insertions(+), 153 deletions(-) diff --git a/dfhack/include/modules/Items.h b/dfhack/include/modules/Items.h index 181ee68ee..162701688 100644 --- a/dfhack/include/modules/Items.h +++ b/dfhack/include/modules/Items.h @@ -23,6 +23,7 @@ public: Accessor(uint32_t function, Process * p); Accessor(accessor_type type, int32_t constant, uint32_t offset1, uint32_t offset2, uint32_t dataWidth, Process * p); int32_t getValue(uint32_t objectPtr); + bool isConstant(); }; struct t_item @@ -47,6 +48,7 @@ public: bool getItem(uint32_t itemptr, t_item & item); std::string className; uint32_t vtable; + uint32_t mainType; }; class DFHACK_EXPORT Items @@ -54,12 +56,13 @@ class DFHACK_EXPORT Items public: Items(DFHack::APIPrivate * _d); ~Items(); - std::string getItemDescription(uint32_t itemptr); + std::string getItemDescription(uint32_t itemptr, Materials * Materials); + std::string getItemClass(int32_t index); bool getItemData(uint32_t itemptr, t_item & item); private: class Private; Private* d; - /*std::map descType; might be useful later */ + std::map descType; std::map descVTable; }; } diff --git a/dfhack/include/modules/Materials.h b/dfhack/include/modules/Materials.h index 1fd4d66fe..6fbbd2ab8 100644 --- a/dfhack/include/modules/Materials.h +++ b/dfhack/include/modules/Materials.h @@ -82,47 +82,46 @@ namespace DFHack class DFHACK_EXPORT Materials { - public: - - Materials(DFHack::APIPrivate * _d); - ~Materials(); + public: + Materials(DFHack::APIPrivate * _d); + ~Materials(); - std::vector inorganic; - std::vector organic; - std::vector tree; - std::vector plant; - std::vector race; - std::vector raceEx; - std::vector color; - std::vector other; - - bool ReadInorganicMaterials (void); - bool ReadOrganicMaterials (void); - bool ReadWoodMaterials (void); - bool ReadPlantMaterials (void); - bool ReadCreatureTypes (void); - bool ReadCreatureTypesEx (void); - bool ReadDescriptorColors(void); - bool ReadOthers (void); + std::vector inorganic; + std::vector organic; + std::vector tree; + std::vector plant; + std::vector race; + std::vector raceEx; + std::vector color; + std::vector other; - void ReadAllMaterials(void); + bool ReadInorganicMaterials (void); + bool ReadOrganicMaterials (void); + bool ReadWoodMaterials (void); + bool ReadPlantMaterials (void); + bool ReadCreatureTypes (void); + bool ReadCreatureTypesEx (void); + bool ReadDescriptorColors(void); + bool ReadOthers (void); - std::string getDescription(t_material & mat); - /* - bool ReadInorganicMaterials (std::vector & output); - bool ReadOrganicMaterials (std::vector & output); - bool ReadWoodMaterials (std::vector & output); - bool ReadPlantMaterials (std::vector & output); - - // TODO: maybe move to creatures? - bool ReadCreatureTypes (std::vector & output); - bool ReadCreatureTypesEx (vector & creatures); - bool ReadDescriptorColors(std::vector & output); - */ - private: - class Private; - Private* d; - }; + void ReadAllMaterials(void); + + std::string getDescription(t_material & mat); + /* + bool ReadInorganicMaterials (std::vector & output); + bool ReadOrganicMaterials (std::vector & output); + bool ReadWoodMaterials (std::vector & output); + bool ReadPlantMaterials (std::vector & output); + + // TODO: maybe move to creatures? + bool ReadCreatureTypes (std::vector & output); + bool ReadCreatureTypesEx (vector & creatures); + bool ReadDescriptorColors(std::vector & output); + */ + private: + class Private; + Private* d; + }; } #endif diff --git a/dfhack/modules/Items.cpp b/dfhack/modules/Items.cpp index ca9be516a..55c900feb 100644 --- a/dfhack/modules/Items.cpp +++ b/dfhack/modules/Items.cpp @@ -116,10 +116,16 @@ Accessor::Accessor(uint32_t function, Process *p) printf("bad accessor @0x%x\n", function); } -int32_t Accessor::getValue(uint32_t objectPtr) +bool Accessor::isConstant() { - int32_t sout; + if(this->type == ACCESSOR_CONSTANT) + return true; + else + return false; +} +int32_t Accessor::getValue(uint32_t objectPtr) +{ switch(this->type) { case ACCESSOR_CONSTANT: @@ -161,13 +167,21 @@ ItemDesc::ItemDesc(uint32_t VTable, Process *p) uint32_t funcOffsetQuality = p->getDescriptor()->getOffset("item_quality_accessor"); this->vtable = VTable; this->p = p; - this->className = p->readClassName(VTable); + this->className = p->readClassName(VTable).substr(5); + this->className.resize(this->className.size()-2); this->AMainType = new Accessor( p->readDWord( VTable + funcOffsetA ), p); this->ASubType = new Accessor( p->readDWord( VTable + funcOffsetB ), p); this->ASubIndex = new Accessor( p->readDWord( VTable + funcOffsetC ), p); this->AIndex = new Accessor( p->readDWord( VTable + funcOffsetD ), p); this->AQuality = new Accessor( p->readDWord( VTable + funcOffsetQuality ), p); this->hasDecoration = false; + if(this->AMainType->isConstant()) + this->mainType = this->AMainType->getValue(0); + else + { + fprintf(stderr, "Bad item main type at function %p\n", (void*) p->readDWord( VTable + funcOffsetA )); + this->mainType = 0; + } } bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item) @@ -176,8 +190,6 @@ bool ItemDesc::getItem(uint32_t itemptr, DFHack::t_item &item) item.matdesc.subType = this->ASubType->getValue(itemptr); item.matdesc.subIndex = this->ASubIndex->getValue(itemptr); item.matdesc.index = this->AIndex->getValue(itemptr); - if(item.matdesc.index == 0xffff) - printf("wtf"); item.quality = this->AQuality->getValue(itemptr); item.quantity = 1; /* TODO */ return true; @@ -195,6 +207,7 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item) uint32_t vtable = p->readDWord(itemptr); desc = new ItemDesc(vtable, p); this->descVTable[vtable] = desc; + this->descType[desc->mainType] = desc; } else desc = it->second; @@ -202,12 +215,37 @@ bool Items::getItemData(uint32_t itemptr, DFHack::t_item &item) return desc->getItem(itemptr, item); } -std::string Items::getItemDescription(uint32_t itemptr) +std::string Items::getItemClass(int32_t index) +{ + std::map::iterator it; + std::string out; + + it = this->descType.find(index); + if(it==this->descType.end()) + return "unknown"; + out = it->second->className; + return out; +} + +std::string Items::getItemDescription(uint32_t itemptr, Materials * Materials) { DFHack::t_item item; std::string out; if(!this->getItemData(itemptr, item)) return "??"; - return "!!"; + switch(item.quality) + { + case 0: break; + case 1: out.append("Well crafted "); break; + case 2: out.append("Finely crafted "); break; + case 3: out.append("Superior quality "); break; + case 4: out.append("Exceptionnal "); break; + case 5: out.append("Masterful "); break; + default: out.append("Crazy quality "); break; + } + out.append(Materials->getDescription(item.matdesc)); + out.append(" "); + out.append(this->getItemClass(item.matdesc.itemType)); + return out; } \ No newline at end of file diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 460725d8a..4303c3156 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -347,66 +347,52 @@ void Materials::ReadAllMaterials(void) std::string Materials::getDescription(t_material & mat) { std::string out; + int32_t typeC; - switch(mat.itemType) - { - case 0: - if(mat.index>=0) - { - if(uint32_t(mat.index) <= this->inorganic.size()) - { - out.append(this->inorganic[mat.index].id); - out.append(" bar"); - } - else - out = "invalid bar"; - } - else - out = "any metal bar"; - break; - case 1: - out = "cut gem"; - break; - case 2: - out = "block"; - break; - case 3: - switch(mat.subType) - { - case 3: out = "raw green glass"; break; - case 4: out = "raw clear glass"; break; - case 5: out = "raw crystal glass"; break; - default: out = "raw gems"; break; - } - break; - case 4: - out = "raw stone"; - break; - case 5: - out = "wood log"; - break; - case 24: - out = "weapon?"; - break; - case 26: - out = "footwear"; - break; - case 28: - out = "headwear"; - break; - case 54: - out = "leather"; - break; - case 57: - out = "cloth"; - break; - case 71: - out = "food"; - break; - default: - out = "unknown"; - break; - } + if ( (mat.subIndex<419) || (mat.subIndex>618) ) + { + if ( (mat.subIndex<19) || (mat.subIndex>218) ) + { + if (mat.subIndex) + if (mat.subIndex>0x292) + return "?"; + else + { + if (mat.subIndex>=this->other.size()) + { + if(mat.subIndex>=this->raceEx.size()) + return "stuff"; + else + return this->raceEx[mat.subIndex].rawname; + } + else + { + if (mat.index==-1) + return std::string(this->other[mat.subIndex].rawname); + else + return std::string(this->other[mat.subIndex].rawname) + " derivate"; + } + } + else + return this->inorganic[mat.index].id; + } + else + { + if (mat.index>=this->raceEx.size()) + return "unknown race"; + typeC = mat.subIndex; + typeC -=19; + if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size())) + { + return string(this->raceEx[mat.index].rawname).append(" extract"); + } + return std::string(this->raceEx[mat.index].rawname).append(" ").append(this->raceEx[mat.index].extract[typeC].rawname); + } + } + else + { + return this->organic[mat.index].id; + } return out; } diff --git a/examples/dfitemdump.cpp b/examples/dfitemdump.cpp index 3848c32ad..59f0c70dd 100644 --- a/examples/dfitemdump.cpp +++ b/examples/dfitemdump.cpp @@ -22,55 +22,13 @@ using namespace std; DFHack::Materials * Materials; - -std::string getMatDesc(int32_t typeB, int32_t typeC, int32_t typeD) -{ - if ( (typeC<419) || (typeC>618) ) - { - if ( (typeC<19) || (typeC>218) ) - { - if (typeC) - if (typeC>0x292) - return "?"; - else - { - if (typeC>=Materials->other.size()) - return "stuff"; - else - { - if (typeD==-1) - return std::string(Materials->other[typeC].rawname); - else - return std::string(Materials->other[typeC].rawname) + " derivate"; - } - } - else - return Materials->inorganic[typeD].id; - } - else - { - if (typeD>=Materials->raceEx.size()) - return "unknown race"; - typeC-=19; - if ((typeC<0) || (typeC>=Materials->raceEx[typeD].extract.size())) - { - return string(Materials->raceEx[typeD].rawname).append(" extract"); - } - return std::string(Materials->raceEx[typeD].rawname).append(" ").append(Materials->raceEx[typeD].extract[typeC].rawname); - } - } - else - { - return Materials->organic[typeD].id; - } -} +DFHack::Items * Items; int main () { DFHack::API DF("Memory.xml"); DFHack::Process * p; unsigned int i,j; - DFHack::Items * Items; try { @@ -193,10 +151,11 @@ int main () printf("bad typeD func @%p\n", (void*) funcD); // printf("%p\t%.16LX\t", (void*) func2, funct2); - printf("%d\t%p\t%s\t%d\t[%d,%d,%d -> %s]", type, (void*)vtable, desc.c_str(), quality, - typeB, typeC, typeD, getMatDesc(typeB, typeC, typeD).c_str()); + printf("%d\t%p\t%s\t%d\t[%d,%d,%d]", type, (void*)vtable, desc.c_str(), quality, + typeB, typeC, typeD); + printf("\t%s", Items->getItemDescription(p_items[i], Materials).c_str()); // printf("\t%p\t%.16LX", (void *) funcD, funcDt); - if( (type!=itm.matdesc.itemType) || (typeB!=itm.matdesc.subType) || (typeC!=itm.matdesc.subIndex) || (typeD!=itm.matdesc.index) ) + if( (type!=itm.matdesc.itemType) || (typeB!=itm.matdesc.subType) || (typeC!=itm.matdesc.subIndex) || (typeD!=itm.matdesc.index) || (quality!=itm.quality) ) printf("\tbad[%d,%d,%d,%d]", itm.matdesc.itemType, itm.matdesc.subType, itm.matdesc.subIndex, itm.matdesc.index); if (hasDecorations) { @@ -223,7 +182,7 @@ int main () printf("bad decoration type function, address=%p\n", (void*) dtypefunc); if (sep) printf(","); - printf("%s[t=%d,q=%d,%s{%d,%d}]", ddesc.c_str(), dtype, dqual, getMatDesc(-1, dtypeC, dtypeD).c_str(), dtypeC, dtypeD); + //printf("%s[t=%d,q=%d,%s{%d,%d}]", ddesc.c_str(), dtype, dqual, getMatDesc(-1, dtypeC, dtypeD).c_str(), dtypeC, dtypeD); sep = true; } } From 32176875f94767b77d97297c6e7bd703da3933e8 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 4 May 2010 16:46:15 +0200 Subject: [PATCH 05/13] preliminary improvement system --- dfhack/include/modules/Items.h | 19 +++++++++++++++++++ examples/dfitemdump.cpp | 4 +++- output/Memory.xml | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dfhack/include/modules/Items.h b/dfhack/include/modules/Items.h index 162701688..99a6a9046 100644 --- a/dfhack/include/modules/Items.h +++ b/dfhack/include/modules/Items.h @@ -33,6 +33,24 @@ struct t_item int32_t quality; }; +struct t_improvement +{ + t_material matdesc; + int32_t quality; +}; + +class DFHACK_EXPORT ItemImprovementDesc +{ +private: + Accessor * AType; + Process * p; +public: + ItemImprovementDesc(uint32_t VTable, Process * p); + bool getImprovement(uint32_t descptr, t_improvement & imp); + uint32_t vtable; + uint32_t maintype; +}; + class DFHACK_EXPORT ItemDesc { private: @@ -49,6 +67,7 @@ public: std::string className; uint32_t vtable; uint32_t mainType; + std::vector improvement; }; class DFHACK_EXPORT Items diff --git a/examples/dfitemdump.cpp b/examples/dfitemdump.cpp index 59f0c70dd..01b734e06 100644 --- a/examples/dfitemdump.cpp +++ b/examples/dfitemdump.cpp @@ -178,7 +178,9 @@ int main () uint32_t dqual = p->readWord(decoration + 20); if ( (dtypefunct&0xFFFFFFFFFFFF00FFLL) == 0xCCCCC300000000B8LL) dtype = (dtypefunct>>8)&0xfffffff; - else + else if ( dtypefunct == 0xCCCCCCCCCCC3C033LL) + dtype = 0; + else printf("bad decoration type function, address=%p\n", (void*) dtypefunc); if (sep) printf(","); diff --git a/output/Memory.xml b/output/Memory.xml index b9dced466..973714ff8 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1510,7 +1510,10 @@ map_data_1b60_offset 0x1B9c 0x238 0xA0 + 0x4 + 0x8 0x14 + 0x14 (in the vtable) .-"""-. From 2356e4976875c9f96159e69949f3958daa5d555c Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 4 May 2010 16:47:40 +0200 Subject: [PATCH 06/13] proper offsets for sex and caste (they are different things) --- output/Memory.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/output/Memory.xml b/output/Memory.xml index 973714ff8..c26b3c221 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1413,7 +1413,8 @@ map_data_1b60_offset 0x1B9c 0x90 0xF8 0xFC - 0x110 + 0x110 + 0x112 0x114 0X120 0X1F4 From 99b0d7dc1e42fb807b603c5cc115ef36b91b1451 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 5 May 2010 11:17:40 +0200 Subject: [PATCH 07/13] Color modifiers are now decoded for castes --- dfhack/include/modules/Materials.h | 1 + dfhack/modules/Materials.cpp | 17 +++++++++++++++++ examples/materialtest.cpp | 7 +++++++ output/Memory.xml | 6 ++++++ 4 files changed, 31 insertions(+) diff --git a/dfhack/include/modules/Materials.h b/dfhack/include/modules/Materials.h index 6fbbd2ab8..ebf2c6206 100644 --- a/dfhack/include/modules/Materials.h +++ b/dfhack/include/modules/Materials.h @@ -44,6 +44,7 @@ namespace DFHack char singular[128]; char plural[128]; char adjective[128]; + std::vector > ColorModifier; }; struct t_matglossOther diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 4303c3156..b60628525 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -293,8 +293,11 @@ bool Materials::ReadCreatureTypesEx (void) uint32_t castes_vector_offset = mem->getOffset ("creature_type_caste_vector"); uint32_t extract_vector_offset = mem->getOffset ("creature_type_extract_vector"); uint32_t sizeof_string = mem->getHexValue ("sizeof_string"); + uint32_t caste_colormod_offset = mem->getOffset ("caste_color_modifiers"); uint32_t size = p_races.size(); uint32_t sizecas = 0; + uint32_t sizecolormod; + uint32_t sizecolorlist; uint32_t tile_offset = mem->getOffset ("creature_tile"); uint32_t tile_color_offset = mem->getOffset ("creature_tile_color"); raceEx.clear(); @@ -313,6 +316,18 @@ bool Materials::ReadCreatureTypesEx (void) p->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular)); p->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural)); p->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective)); + DfVector p_colormod(p, caste_start + caste_colormod_offset); + sizecolormod = p_colormod.size(); + caste.ColorModifier.resize(sizecolormod); + + for(uint32_t k = 0; k < sizecolormod;k++) + { + DfVector p_colorlist(p, p_colormod[k]); + sizecolorlist = p_colorlist.size(); + caste.ColorModifier[k].resize(sizecolorlist); + for(uint32_t l = 0; l < sizecolorlist; l++) + caste.ColorModifier[k][l] = p_colorlist[l]; + } mat.castes.push_back(caste); } mat.tile_character = p->readByte( p_races[i] + tile_offset ); @@ -327,6 +342,8 @@ bool Materials::ReadCreatureTypesEx (void) p->readSTLString( p_extract[j], extract.rawname, sizeof(extract.rawname)); mat.extract.push_back(extract); } + + raceEx.push_back(mat); } return true; diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index 77be49ba7..583f5a6e2 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -81,6 +81,13 @@ int main (int numargs, const char ** args) << castes[j].plural << ":" << castes[j].adjective << "] "; cout << endl; + for(uint32_t k = 0; k < castes[j].ColorModifier.size(); k++) + { + cout << " colormod[" << k << "] "; + for(uint32_t l = 0; l < castes[j].ColorModifier[k].size(); l++) + cout << castes[j].ColorModifier[k][l] << " "; + cout << endl; + } } cout << endl; } diff --git a/output/Memory.xml b/output/Memory.xml index c26b3c221..7ac380e80 100755 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1422,6 +1422,8 @@ map_data_1b60_offset 0x1B9c 0x288 + 0x298 + 0x29C 0x464 0x390 0x394 the skill that will be increased at the end of the mood (or not) - 0x604 seems to be indexes in the list of possible colors defined in the raws for each group + 0x604 0x6D4 0x774 0x0740 @@ -1444,7 +1444,17 @@ map_data_1b60_offset 0x1B9c Castes ====== + 0x51C 0xACC + 0x70 + + Body Parts + ========== + 0x0 + 0x1C + 0x44 + 0x78 + 0x90 Materials ========= From a6dc645f48c834c3222c334347ca834d2502516c Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 5 May 2010 14:08:18 +0200 Subject: [PATCH 10/13] Creatures colors are now decodable ! --- dfhack/include/modules/Creatures.h | 9 +++++++-- dfhack/modules/Creatures.cpp | 14 ++++++++++++++ dfhack/shm/mod-creature2010.h | 2 ++ examples/creaturedump.cpp | 29 +++++++++++++++++++---------- examples/materialtest.cpp | 2 +- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/dfhack/include/modules/Creatures.h b/dfhack/include/modules/Creatures.h index af0014b8b..85910afdf 100644 --- a/dfhack/include/modules/Creatures.h +++ b/dfhack/include/modules/Creatures.h @@ -314,7 +314,9 @@ namespace DFHack t_attrib empathy; t_attrib social_awareness; }; - + +#define MAX_COLORS 15 + struct t_creature { uint32_t origin; @@ -349,10 +351,13 @@ namespace DFHack t_attrib recuperation; t_attrib disease_resistance; int32_t squad_leader_id; - uint8_t sex; // really a caste + uint8_t sex; + uint16_t caste; uint32_t pregnancy_timer; //Countdown timer to giving birth bool has_default_soul; t_soul defaultSoul; + uint32_t nbcolors; + uint32_t color[MAX_COLORS]; }; class APIPrivate; diff --git a/dfhack/modules/Creatures.cpp b/dfhack/modules/Creatures.cpp index 55e86f18b..004233d66 100644 --- a/dfhack/modules/Creatures.cpp +++ b/dfhack/modules/Creatures.cpp @@ -81,6 +81,7 @@ Creatures::Creatures(APIPrivate* _d) creatures.flags2_offset = minfo->getOffset ("creature_flags2"); creatures.name_offset = minfo->getOffset ("creature_name"); creatures.sex_offset = minfo->getOffset ("creature_sex"); + creatures.caste_offset = minfo->getOffset ("creature_caste"); creatures.id_offset = minfo->getOffset ("creature_id"); creatures.labors_offset = minfo->getOffset ("creature_labors"); creatures.happiness_offset = minfo->getOffset ("creature_happiness"); @@ -97,6 +98,9 @@ Creatures::Creatures(APIPrivate* _d) creatures.soul_mental_offset = minfo->getOffset("soul_mental"); creatures.soul_traits_offset = minfo->getOffset("soul_traits"); + // appearance + creatures.appearance_vector_offset = minfo->getOffset("creature_appearance_vector"); + // name offsets for the creature module creatures.name_firstname_offset = minfo->getOffset("name_firstname"); creatures.name_nickname_offset = minfo->getOffset("name_nickname"); @@ -179,6 +183,7 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) p->readDWord (temp + offs.race_offset, furball.race); furball.civ = p->readDWord (temp + offs.civ_offset); p->readByte (temp + offs.sex_offset, furball.sex); + p->readWord (temp + offs.caste_offset, furball.caste); p->readDWord (temp + offs.flags1_offset, furball.flags1.whole); p->readDWord (temp + offs.flags2_offset, furball.flags2.whole); @@ -258,6 +263,15 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) // traits as well p->read(soul + offs.soul_traits_offset, sizeof (uint16_t) * NUM_CREATURE_TRAITS, (uint8_t *) &furball.defaultSoul.traits); } + + DfVector app(p, temp + offs.appearance_vector_offset); + furball.nbcolors = app.size(); + if(furball.nbcolors>MAX_COLORS) + furball.nbcolors = MAX_COLORS; + for(uint32_t i = 0; i < furball.nbcolors; i++) + { + furball.color[i] = app[i]; + } //likes /* DfVector likes(d->p, temp + offs.creature_likes_offset); diff --git a/dfhack/shm/mod-creature2010.h b/dfhack/shm/mod-creature2010.h index ae9c60ab7..93006d827 100644 --- a/dfhack/shm/mod-creature2010.h +++ b/dfhack/shm/mod-creature2010.h @@ -44,6 +44,7 @@ typedef struct uint32_t flags2_offset; uint32_t name_offset; uint32_t sex_offset; + uint32_t caste_offset; uint32_t id_offset; uint32_t labors_offset; uint32_t happiness_offset; @@ -63,6 +64,7 @@ typedef struct uint32_t name_words_offset; uint32_t soul_mental_offset; uint32_t soul_traits_offset; + uint32_t appearance_vector_offset; } creature_offsets; typedef struct diff --git a/examples/creaturedump.cpp b/examples/creaturedump.cpp index 33a653819..50e716137 100644 --- a/examples/creaturedump.cpp +++ b/examples/creaturedump.cpp @@ -204,6 +204,22 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) } */ cout << endl; + cout << "Appearance : "; + for(unsigned int i = 0; iraceEx[creature.race].castes[creature.caste].ColorModifier[i].part << " "; + uint32_t color = Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].colorlist[creature.color[i]]; + if(colorcolor.size()) + cout << Materials->color[color].name << "[" + << (unsigned int) (Materials->color[color].r*255) << ":" + << (unsigned int) (Materials->color[color].v*255) << ":" + << (unsigned int) (Materials->color[color].b*255) << "]"; + else + cout << Materials->alldesc[color].id; + cout << " - "; + + } + cout << endl; cout << "happiness: " << creature.happiness << ", strength: " << creature.strength.level << ", agility: " << creature.agility.level @@ -359,6 +375,8 @@ void printCreature(DFHack::API & DF, const DFHack::t_creature & creature) string artifact_name = Tran->TranslateName(creature.artifact_name,false); cout << "artifact: " << artifact_name << endl; } + + cout << endl; } @@ -405,16 +423,7 @@ int main (int numargs, char ** args) } mem = DF.getMemoryInfo(); - if(!Materials->ReadInorganicMaterials()) - { - cerr << "Can't get the inorganics types." << endl; - return 1; - } - if(!Materials->ReadCreatureTypesEx()) - { - cerr << "Can't get the creature types." << endl; - return 1; - } + Materials->ReadAllMaterials(); if(!Tran->Start()) { diff --git a/examples/materialtest.cpp b/examples/materialtest.cpp index 4dc1b1088..0ebddf300 100644 --- a/examples/materialtest.cpp +++ b/examples/materialtest.cpp @@ -74,7 +74,7 @@ int main (int numargs, const char ** args) cout << i << ": " << Materials->color[i].id << " - " << Materials->color[i].name << "[" << (unsigned int) (Materials->color[i].r*255) << ":" << (unsigned int) (Materials->color[i].v*255) << ":" - << (unsigned int) (Materials->color[i].b*255) << ":" + << (unsigned int) (Materials->color[i].b*255) << "]" << endl; } cout << endl << "----==== All descriptors ====----" << endl; From 25d66ee039303a0c199de50be8a8efaa7eb36eae Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 5 May 2010 14:14:22 +0200 Subject: [PATCH 11/13] A little temporary fix before the mood overhaul --- dfhack/modules/Materials.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 2c95c9c4c..8c6102893 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -416,7 +416,10 @@ std::string Materials::getDescription(t_material & mat) } } else - return this->inorganic[mat.index].id; + if(mat.index<0) + return "any inorganic"; + else + return this->inorganic[mat.index].id; } else { From 52b7ab6f462beab543fb3b7f77a0e973e3616532 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 6 May 2010 16:47:36 +0200 Subject: [PATCH 12/13] Some support for decoding mood added Fucked indentation a little bit with visual studio --- dfhack/include/modules/Creatures.h | 2 +- dfhack/modules/Items.cpp | 16 +++++++++++++++- dfhack/modules/Materials.cpp | 5 +++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dfhack/include/modules/Creatures.h b/dfhack/include/modules/Creatures.h index 85910afdf..a0177ad50 100644 --- a/dfhack/include/modules/Creatures.h +++ b/dfhack/include/modules/Creatures.h @@ -265,7 +265,7 @@ namespace DFHack bool active; uint32_t jobId; uint8_t jobType; - uint32_t occupationPtr; + uint32_t occupationPtr; }; struct t_like { diff --git a/dfhack/modules/Items.cpp b/dfhack/modules/Items.cpp index 55c900feb..149b10312 100644 --- a/dfhack/modules/Items.cpp +++ b/dfhack/modules/Items.cpp @@ -222,7 +222,21 @@ std::string Items::getItemClass(int32_t index) it = this->descType.find(index); if(it==this->descType.end()) - return "unknown"; + { + /* these are dummy values for mood decoding */ + switch(index) + { + case 0: return "bar"; + case 1: return "cut gem"; + case 2: return "block"; + case 3: return "raw gem"; + case 4: return "raw stone"; + case 5: return "log"; + case 54: return "leather"; + case 57: return "cloth"; + default: return "unknown"; + } + } out = it->second->className; return out; } diff --git a/dfhack/modules/Materials.cpp b/dfhack/modules/Materials.cpp index 8c6102893..2c7997f82 100644 --- a/dfhack/modules/Materials.cpp +++ b/dfhack/modules/Materials.cpp @@ -402,10 +402,11 @@ std::string Materials::getDescription(t_material & mat) { if (mat.subIndex>=this->other.size()) { + if(mat.subIndex<0) + return "any"; if(mat.subIndex>=this->raceEx.size()) return "stuff"; - else - return this->raceEx[mat.subIndex].rawname; + return this->raceEx[mat.subIndex].rawname; } else { From bb4b613583e75019fea1537ab605a995107cff8b Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 6 May 2010 17:28:29 +0200 Subject: [PATCH 13/13] Added dummy description for bones and stuff like that --- dfhack/modules/Items.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dfhack/modules/Items.cpp b/dfhack/modules/Items.cpp index 149b10312..ec2ef540e 100644 --- a/dfhack/modules/Items.cpp +++ b/dfhack/modules/Items.cpp @@ -234,6 +234,7 @@ std::string Items::getItemClass(int32_t index) case 5: return "log"; case 54: return "leather"; case 57: return "cloth"; + case -1: return "probably bone or shell, but I really don't know"; default: return "unknown"; } }