diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index cf8a32fcc..76c872445 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -128,17 +128,6 @@ void compound_identity::Init(Core *core) // they are called in an undefined order. for (compound_identity *p = list; p; p = p->next) p->doInit(core); - - //FIXME: ... nuked. the group was empty... -/* - // Read pre-filled vtable ptrs - OffsetGroup *ptr_table = core->vinfo->getGroup("vtable"); - for (virtual_identity *p = list; p; p = p->next) { - void * tmp; - if (ptr_table->getSafeAddress(p->getName(),tmp)) - p->vtable_ptr = tmp; - } - */ } bitfield_identity::bitfield_identity(size_t size, @@ -223,17 +212,23 @@ virtual_identity::virtual_identity(size_t size, TAllocateFn alloc, { } +/* Vtable name to identity lookup. */ static std::map name_lookup; +/* Vtable pointer to identity lookup. */ +std::map virtual_identity::known; + void virtual_identity::doInit(Core *core) { struct_identity::doInit(core); - name_lookup[getOriginalName()] = this; -} + auto vtname = getOriginalName(); + name_lookup[vtname] = this; -/* Vtable to identity lookup. */ -std::map virtual_identity::known; + vtable_ptr = core->vinfo->getVTable(vtname); + if (vtable_ptr) + known[vtable_ptr] = this; +} virtual_identity *virtual_identity::get(virtual_ptr instance_ptr) { @@ -265,8 +260,8 @@ virtual_identity *virtual_identity::get(virtual_ptr instance_ptr) << ", previous 0x" << unsigned(p->vtable_ptr) << std::dec << std::endl; abort(); } else if (!p->vtable_ptr) { - std::cerr << "class '" << p->getName() << "': vtable = 0x" - << std::hex << unsigned(vtable) << std::dec << std::endl; + std::cerr << "" << std::endl; } known[vtable] = p; diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index cf63e3b1a..36dbd9aae 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -118,7 +118,8 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem) string type, name, value; const char *cstr_type = pMemEntry->Value(); type = cstr_type; - if(type == "global-address") + bool is_vtable = (type == "vtable-address"); + if(is_vtable || type == "global-address") { const char *cstr_key = pMemEntry->Attribute("name"); if(!cstr_key) @@ -129,7 +130,11 @@ void VersionInfoFactory::ParseVersion (TiXmlElement* entry, VersionInfo* mem) cerr << "Dummy symbol table entry: " << cstr_key << endl; continue; } - mem->setAddress(cstr_key, strtol(cstr_value, 0, 0)); + uint32_t addr = strtol(cstr_value, 0, 0); + if (is_vtable) + mem->setVTable(cstr_key, addr); + else + mem->setAddress(cstr_key, addr); } else if (type == "md5-hash") { diff --git a/library/include/VersionInfo.h b/library/include/VersionInfo.h index d996722c0..7f82163ef 100644 --- a/library/include/VersionInfo.h +++ b/library/include/VersionInfo.h @@ -51,6 +51,7 @@ namespace DFHack std::vector md5_list; std::vector PE_list; std::map Addresses; + std::map VTables; uint32_t base; std::string version; OSType OS; @@ -66,6 +67,7 @@ namespace DFHack md5_list = rhs.md5_list; PE_list = rhs.PE_list; Addresses = rhs.Addresses; + VTables = rhs.VTables; base = rhs.base; version = rhs.version; OS = rhs.OS; @@ -79,13 +81,10 @@ namespace DFHack int64_t newx = new_base; int64_t rebase = newx - old; base = new_base; - auto iter = Addresses.begin(); - while (iter != Addresses.end()) - { - uint32_t & ref = (*iter).second; - ref += rebase; - iter ++; - } + for (auto iter = Addresses.begin(); iter != Addresses.end(); ++iter) + iter->second += rebase; + for (auto iter = VTables.begin(); iter != VTables.end(); ++iter) + iter->second += rebase; }; void addMD5 (const std::string & _md5) @@ -125,6 +124,7 @@ namespace DFHack value = (T) (*i).second; return true; }; + uint32_t getAddress (const std::string& key) const { auto i = Addresses.find(key); @@ -133,6 +133,18 @@ namespace DFHack return (*i).second; } + void setVTable (const std::string& key, const uint32_t value) + { + VTables[key] = value; + }; + void *getVTable (const std::string& key) const + { + auto i = VTables.find(key); + if(i == VTables.end()) + return 0; + return (void*)i->second; + } + void setOS(const OSType os) { OS = os; diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index d884a734e..20b95bc23 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -454,6 +454,8 @@ bool Items::setOwner(df::item *item, df::unit *unit) vector_erase_at(item->itemrefs, i); } + item->flags.bits.owned = false; + if (unit) { auto ref = df::allocate(); @@ -466,8 +468,6 @@ bool Items::setOwner(df::item *item, df::unit *unit) insert_into_vector(unit->owned_items, item->id); item->itemrefs.push_back(ref); } - else - item->flags.bits.owned = false; return true; }