From 9bcdc78d005917dfb266dfafd34719c959fc4682 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 31 Aug 2010 05:32:40 +0200 Subject: [PATCH 01/19] name of GUI offset group was wrong in its module --- library/CMakeLists.txt | 39 ++++++++++++++++++++++++++++-------- library/modules/Gui.cpp | 2 +- library/modules/Position.cpp | 32 ++++++++++++++--------------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 6bd4815a6..82fce6887 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -26,20 +26,29 @@ include_directories (${CMAKE_SOURCE_DIR}/library/depends/tinyxml/) include_directories (${CMAKE_SOURCE_DIR}/library/depends/argstream/) include_directories (${CMAKE_SOURCE_DIR}/library/private/) +SET(PROJECT_HDRS_INTERNAL + private/ContextShared.h + private/Internal.h +) + SET(PROJECT_HDRS -private/ContextShared.h -private/Internal.h +include/DFHack.h +include/dfhack/DFContext.h +include/dfhack/DFContextManager.h include/dfhack/DFError.h -include/dfhack/VersionInfoFactory.h -include/dfhack/VersionInfo.h -include/dfhack/DFProcessEnumerator.h +include/dfhack/DFExport.h +include/dfhack/DFGlobal.h +include/dfhack/DFIntegers.h +include/dfhack/DFMiscUtils.h +include/dfhack/DFModule.h +include/dfhack/DFPragma.h include/dfhack/DFProcess.h +include/dfhack/DFProcessEnumerator.h include/dfhack/DFTileTypes.h include/dfhack/DFTypes.h include/dfhack/DFVector.h -include/dfhack-c/DFTypes_C.h -include/dfhack-c/DFContext_C.h -include/dfhack/DFIntegers.h +include/dfhack/VersionInfoFactory.h +include/dfhack/VersionInfo.h include/dfhack/modules/Buildings.h include/dfhack/modules/Constructions.h include/dfhack/modules/Creatures.h @@ -55,8 +64,21 @@ include/dfhack/modules/World.h ) SET(PROJECT_C_HDRS +include/DFHack_C.h include/dfhack-c/DFTypes_C.h include/dfhack-c/DFContext_C.h +include/dfhack-c/modules/Buildings_C.h +include/dfhack-c/modules/Constructions_C.h +include/dfhack-c/modules/Creatures_C.h +include/dfhack-c/modules/Gui_C.h +include/dfhack-c/modules/Items_C.h +include/dfhack-c/modules/Maps_C.h +include/dfhack-c/modules/Materials_C.h +include/dfhack-c/modules/Position_C.h +include/dfhack-c/modules/Translation_C.h +include/dfhack-c/modules/Vegetation_C.h +include/dfhack-c/modules/WindowIO_C.h +include/dfhack-c/modules/World_C.h ) SET(PROJECT_SRCS @@ -206,4 +228,5 @@ endif(MSVC) IF(UNIX) install(TARGETS dfhack LIBRARY DESTINATION lib) install(FILES ${CMAKE_SOURCE_DIR}/output/Memory.xml DESTINATION share/dfhack) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/library/include/ DESTINATION include FILES_MATCHING PATTERN "*.h") ENDIF(UNIX) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 4bb29f1f0..05568c787 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -51,7 +51,7 @@ Gui::Gui(DFContextShared * _d) d->owner = _d->p; d->Inited = d->Started = true; - OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("Gui"); + OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("GUI"); d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state"); d->pause_state_offset = OG_Gui->getAddress ("pause_state"); d->view_screen_offset = OG_Gui->getAddress ("view_screen"); diff --git a/library/modules/Position.cpp b/library/modules/Position.cpp index 8dda58fae..920660321 100644 --- a/library/modules/Position.cpp +++ b/library/modules/Position.cpp @@ -71,22 +71,22 @@ Position::Position(DFContextShared * d_) d->cursor_xyz_offset = OG_Position->getAddress ("cursor_xyz"); d->window_dims_offset = OG_Position->getAddress ("window_dims"); d->Started = true; - try - { - OffsetGroup * OG_Hotkeys = mem->getGroup("Hotkeys"); - d->hotkey_start = OG_Hotkeys->getAddress("start"); - d->hotkey_mode_offset = OG_Hotkeys->getOffset ("mode"); - d->hotkey_xyz_offset = OG_Hotkeys->getOffset("coords"); - d->hotkey_size = OG_Hotkeys->getHexValue("size"); - d->StartedHotkeys = true; - } - catch(exception &){}; - try - { - d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer"); - d->StartedScreen = true; - } - catch(exception &){}; + } + catch(exception &){}; + try + { + OffsetGroup * OG_Hotkeys = mem->getGroup("Hotkeys"); + d->hotkey_start = OG_Hotkeys->getAddress("start"); + d->hotkey_mode_offset = OG_Hotkeys->getOffset ("mode"); + d->hotkey_xyz_offset = OG_Hotkeys->getOffset("coords"); + d->hotkey_size = OG_Hotkeys->getHexValue("size"); + d->StartedHotkeys = true; + } + catch(exception &){}; + try + { + d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer"); + d->StartedScreen = true; } catch(exception &){}; } From b9bee108e1fb8c46470f54e52d11e3b2b53f906f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 31 Aug 2010 06:52:03 +0200 Subject: [PATCH 02/19] Sync, fixes. --- data/Memory-ng.xml | 16 +++++++++------- library/ContextShared.cpp | 7 ++++--- library/VersionInfoFactory.cpp | 26 +++++++++++++------------- library/modules/Creatures.cpp | 4 ++-- library/modules/Materials.cpp | 6 ++++-- tools/examples/creaturedump.cpp | 6 ++++-- 6 files changed, 36 insertions(+), 29 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 9ba868c52..d22192b81 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -892,7 +892,7 @@ -
+
@@ -953,7 +953,7 @@
-
+
@@ -1168,7 +1168,7 @@ -
+
@@ -1350,7 +1350,7 @@ -
+
@@ -1368,6 +1368,7 @@
+
@@ -1419,7 +1420,7 @@ -
+
@@ -1430,6 +1431,7 @@
+
@@ -1553,7 +1555,7 @@
-
+
@@ -1700,7 +1702,7 @@ -
+
diff --git a/library/ContextShared.cpp b/library/ContextShared.cpp index 5b6c0bae6..62ca3fff1 100644 --- a/library/ContextShared.cpp +++ b/library/ContextShared.cpp @@ -40,9 +40,10 @@ DFContextShared::~DFContextShared() bool DFContextShared::InitReadNames() { - name_firstname_offset = offset_descriptor->getOffset("name_firstname"); - name_nickname_offset = offset_descriptor->getOffset("name_nickname"); - name_words_offset = offset_descriptor->getOffset("name_words"); + OffsetGroup * OG = offset_descriptor->getGroup("name"); + name_firstname_offset = OG->getOffset("first"); + name_nickname_offset = OG->getOffset("nick"); + name_words_offset = OG->getOffset("second_words"); return true; } diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index 11007f00c..83102648e 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -294,7 +294,7 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Professions") { - pElement2nd = entry->FirstChildElement("Profession"); + pElement2nd = pElement->FirstChildElement("Profession"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Profession")) { const char * id = pElement2nd->Attribute("id"); @@ -313,7 +313,7 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Jobs") { - pElement2nd = entry->FirstChildElement("Job"); + pElement2nd = pElement->FirstChildElement("Job"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Job")) { const char * id = pElement2nd->Attribute("id"); @@ -331,7 +331,7 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Skills") { - pElement2nd = entry->FirstChildElement("Skill"); + pElement2nd = pElement->FirstChildElement("Skill"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Skill")) { const char * id = pElement2nd->Attribute("id"); @@ -349,17 +349,17 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Traits") { - pElement2nd = entry->FirstChildElement("Trait"); + pElement2nd = pElement->FirstChildElement("Trait"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Trait")) { const char * id = pElement2nd->Attribute("id"); const char * name = pElement2nd->Attribute("name"); - const char * lvl0 = pElement->Attribute("level_0"); - const char * lvl1 = pElement->Attribute("level_1"); - const char * lvl2 = pElement->Attribute("level_2"); - const char * lvl3 = pElement->Attribute("level_3"); - const char * lvl4 = pElement->Attribute("level_4"); - const char * lvl5 = pElement->Attribute("level_5"); + const char * lvl0 = pElement2nd->Attribute("level_0"); + const char * lvl1 = pElement2nd->Attribute("level_1"); + const char * lvl2 = pElement2nd->Attribute("level_2"); + const char * lvl3 = pElement2nd->Attribute("level_3"); + const char * lvl4 = pElement2nd->Attribute("level_4"); + const char * lvl5 = pElement2nd->Attribute("level_5"); if(id && name && lvl0 && lvl1 && lvl2 && lvl3 && lvl4 && lvl5) { mem->setTrait(id, name, lvl0, lvl1, lvl2, lvl3, lvl4, lvl5); @@ -373,7 +373,7 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Labors") { - pElement2nd = entry->FirstChildElement("Labor"); + pElement2nd = pElement->FirstChildElement("Labor"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Labor")) { const char * id = pElement2nd->Attribute("id"); @@ -391,7 +391,7 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Levels") { - pElement2nd = entry->FirstChildElement("Level"); + pElement2nd = pElement->FirstChildElement("Level"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Level")) { const char * id = pElement2nd->Attribute("id"); @@ -410,7 +410,7 @@ void VersionInfoFactory::ParseBase (TiXmlElement* entry, VersionInfo* mem) } else if (type == "Moods") { - pElement2nd = entry->FirstChildElement("Mood"); + pElement2nd = pElement->FirstChildElement("Mood"); for(;pElement2nd;pElement2nd=pElement2nd->NextSiblingElement("Mood")) { const char * id = pElement2nd->Attribute("id"); diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index 141828243..0ab171440 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -83,8 +83,8 @@ Creatures::Creatures(DFContextShared* _d) creatures.profession_offset = OG_creature->getOffset ("profession"); creatures.race_offset = OG_creature->getOffset ("race"); creatures.pos_offset = OG_creature->getOffset ("position"); - creatures.flags1_offset = OG_creature->getOffset ("creature_flags1"); - creatures.flags2_offset = OG_creature->getOffset ("creature_flags2"); + creatures.flags1_offset = OG_creature->getOffset ("flags1"); + creatures.flags2_offset = OG_creature->getOffset ("flags2"); creatures.sex_offset = OG_creature->getOffset ("sex"); creatures.caste_offset = OG_creature->getOffset ("caste"); creatures.id_offset = OG_creature->getOffset ("id"); diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index b5ce66306..a7f4e63da 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -71,6 +71,7 @@ Materials::~Materials() bool Materials::Finish() { + /* inorganic.clear(); organic.clear(); tree.clear(); @@ -80,6 +81,7 @@ bool Materials::Finish() color.clear(); other.clear(); alldesc.clear(); + */ return true; } @@ -331,8 +333,8 @@ bool Materials::ReadCreatureTypesEx (void) OffsetGroup * OG_Creature = OG_Mats->getGroup("creature"); uint32_t castes_vector_offset = OG_Creature->getOffset ("caste_vector"); uint32_t extract_vector_offset = OG_Creature->getOffset ("extract_vector"); - uint32_t tile_offset = OG_Creature->getOffset ("creature_tile"); - uint32_t tile_color_offset = OG_Creature->getOffset ("creature_tile_color"); + uint32_t tile_offset = OG_Creature->getOffset ("tile"); + uint32_t tile_color_offset = OG_Creature->getOffset ("tile_color"); OffsetGroup * OG_Caste = OG_Creature->getGroup("caste"); uint32_t caste_colormod_offset = OG_Caste->getOffset ("color_modifiers"); uint32_t caste_attributes_offset = OG_Caste->getOffset ("attributes"); diff --git a/tools/examples/creaturedump.cpp b/tools/examples/creaturedump.cpp index 316624d92..c4bb8e4ac 100644 --- a/tools/examples/creaturedump.cpp +++ b/tools/examples/creaturedump.cpp @@ -271,8 +271,9 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature) } } - std::vector inventory; - + //std::vector inventory; + // FIXME: TOO BAD... + /* if( Creatures->ReadInventoryPtr(creature.origin, inventory) ) { DFHack::Items * Items = DF->getItems(); @@ -282,6 +283,7 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature) printf("\t\t%s\n", Items->getItemDescription(inventory[i], Materials).c_str()); } } + */ /* if(creature.pregnancy_timer > 0) From ff550a7e098ebe2ba3ae19d4c5fef5e61856d59e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 31 Aug 2010 07:07:37 +0200 Subject: [PATCH 03/19] Fix getPE() --- library/include/dfhack/VersionInfo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/include/dfhack/VersionInfo.h b/library/include/dfhack/VersionInfo.h index 458a2c5af..84a7087da 100644 --- a/library/include/dfhack/VersionInfo.h +++ b/library/include/dfhack/VersionInfo.h @@ -108,7 +108,7 @@ namespace DFHack std::string getMD5(); void setPE (uint32_t PE_); - uint getPE(); + uint32_t getPE(); std::string getMood(const uint32_t moodID); std::string getString (const std::string&); From 66c3d30bd80eea3bf154ff94338bf9501d3f3fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 31 Aug 2010 12:59:48 +0200 Subject: [PATCH 04/19] Fix Gui module so Stonesense can work. --- library/modules/Gui.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 05568c787..37d027495 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -33,12 +33,17 @@ using namespace DFHack; struct Gui::Private { - bool Inited; + Private() + { + Started = PauseInited = ViewScreeInited = MenuStateInited = false; + } bool Started; uint32_t pause_state_offset; + bool PauseInited; uint32_t view_screen_offset; - uint32_t current_cursor_creature_offset; + bool ViewScreeInited; uint32_t current_menu_state_offset; + bool MenuStateInited; DFContextShared *d; Process * owner; }; @@ -49,13 +54,26 @@ Gui::Gui(DFContextShared * _d) d = new Private; d->d = _d; d->owner = _d->p; - d->Inited = d->Started = true; - OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("GUI"); - d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state"); - d->pause_state_offset = OG_Gui->getAddress ("pause_state"); - d->view_screen_offset = OG_Gui->getAddress ("view_screen"); - d->Inited = d->Started = true; + try + { + d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state"); + d->MenuStateInited = true; + } + catch(exception &){}; + try + { + d->pause_state_offset = OG_Gui->getAddress ("pause_state"); + d->PauseInited = true; + } + catch(exception &){}; + try + { + d->view_screen_offset = OG_Gui->getAddress ("view_screen"); + d->ViewScreeInited = true; + } + catch(exception &){}; + d->Started = true; } Gui::~Gui() @@ -76,7 +94,7 @@ bool Gui::Finish() bool Gui::ReadPauseState() { // replace with an exception - if(!d->Inited) return false; + if(!d->PauseInited) return false; uint32_t pauseState = d->owner->readDWord (d->pause_state_offset); return pauseState & 1; @@ -84,14 +102,14 @@ bool Gui::ReadPauseState() uint32_t Gui::ReadMenuState() { - if(d->Inited) + if(d->MenuStateInited) return(d->owner->readDWord(d->current_menu_state_offset)); return false; } bool Gui::ReadViewScreen (t_viewscreen &screen) { - if (!d->Inited) return false; + if (!d->ViewScreeInited) return false; Process * p = d->owner; uint32_t last = p->readDWord (d->view_screen_offset); From 86aa19daa4e77e658725264b213dcd1b9df4b4d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 31 Aug 2010 17:21:47 +0200 Subject: [PATCH 05/19] Fix for Creature module --- data/Memory-ng.xml | 34 ++++++++++++++++++--------------- library/modules/Creatures.cpp | 36 ++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 32 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index d22192b81..d02701380 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -939,11 +939,11 @@ - - - - - + + + + + @@ -1214,11 +1214,11 @@ seems to be just like the old occupations - like mood materials, 0=bars, 4=stone, 5=wood, 57=cloth, 54=leather ... - subsubtype ? - subtype ? - index of material (for example, 2 is for silver) - set only for shell / bone mood requirements ? + like mood materials, 0=bars, 4=stone, 5=wood, 57=cloth, 54=leather ... + subsubtype ? + subtype ? + index of material (for example, 2 is for silver) + set only for shell / bone mood requirements ? @@ -1746,11 +1746,11 @@ seems to be just like the old occupations - like mood materials, 0=bars, 4=stone, 5=wood, 57=cloth, 54=leather ... - subsubtype ? - subtype ? - index of material (for example, 2 is for silver) - set only for shell / bone mood requirements ? + like mood materials, 0=bars, 4=stone, 5=wood, 57=cloth, 54=leather ... + subsubtype ? + subtype ? + index of material (for example, 2 is for silver) + set only for shell / bone mood requirements ? --> @@ -1865,6 +1865,10 @@ + +
+ +
diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index 0ab171440..ee78df9d8 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -54,6 +54,8 @@ struct Creatures::Private uint32_t creature_module; uint32_t dwarf_race_index_addr; uint32_t dwarf_civ_id_addr; + OffsetGroup * OG_jobs; + OffsetGroup * OG_job_mats; DfVector *p_cre; DFContextShared *d; Process *owner; @@ -123,6 +125,8 @@ Creatures::Creatures(DFContextShared* _d) creatures.name_nickname_offset = OG_name->getOffset("nick"); creatures.name_words_offset = OG_name->getOffset("second_words"); } + d->OG_jobs = OG_Creatures->getGroup("job"); + d->OG_job_mats = d->OG_jobs->getGroup("material"); /* // upload offsets to the SHM @@ -231,8 +235,8 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) if(furball.current_job.occupationPtr) { furball.current_job.active = true; - furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + minfo->getOffset("job_type") ); - furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + minfo->getOffset("job_id") ); + furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + d->OG_jobs->getOffset("type") ); + furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + d->OG_jobs->getOffset("id") ); } else { @@ -534,21 +538,19 @@ bool Creatures::WriteMoodSkill(const uint32_t index, const uint16_t moodSkill) bool Creatures::WriteJob(const t_creature * furball, std::vector const& mat) { - unsigned int i; + unsigned int i; if(!d->Inited) return false; if(!furball->current_job.active) return false; Process * p = d->owner; - VersionInfo * minfo = d->d->offset_descriptor; - - DfVector cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector")); + DfVector cmats(p, furball->current_job.occupationPtr + d->OG_jobs->getOffset("materials_vector")); for(i=0;iwriteWord(cmats[i] + minfo->getOffset("job_material_maintype"), mat[i].itemType); - p->writeWord(cmats[i] + minfo->getOffset("job_material_sectype1"), mat[i].subType); - p->writeWord(cmats[i] + minfo->getOffset("job_material_sectype2"), mat[i].subIndex); - p->writeDWord(cmats[i] + minfo->getOffset("job_material_sectype3"), mat[i].index); - p->writeDWord(cmats[i] + minfo->getOffset("job_material_flags"), mat[i].flags); + p->writeWord(cmats[i] + d->OG_job_mats->getOffset("maintype"), mat[i].itemType); + p->writeWord(cmats[i] + d->OG_job_mats->getOffset("sectype1"), mat[i].subType); + p->writeWord(cmats[i] + d->OG_job_mats->getOffset("sectype2"), mat[i].subIndex); + p->writeDWord(cmats[i] + d->OG_job_mats->getOffset("sectype3"), mat[i].index); + p->writeDWord(cmats[i] + d->OG_job_mats->getOffset("flags"), mat[i].flags); } return true; } @@ -610,15 +612,15 @@ bool Creatures::ReadJob(const t_creature * furball, vector & mat) Process * p = d->owner; VersionInfo * minfo = d->d->offset_descriptor; - DfVector cmats(p, furball->current_job.occupationPtr + minfo->getOffset("job_materials_vector")); + DfVector cmats(p, furball->current_job.occupationPtr + d->OG_jobs->getOffset("materials_vector")); mat.resize(cmats.size()); for(i=0;ireadWord(cmats[i] + minfo->getOffset("job_material_maintype")); - 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")); + mat[i].itemType = p->readWord(cmats[i] + d->OG_job_mats->getOffset("maintype")); + mat[i].subType = p->readWord(cmats[i] + d->OG_job_mats->getOffset("sectype1")); + mat[i].subIndex = p->readWord(cmats[i] + d->OG_job_mats->getOffset("sectype2")); + mat[i].index = p->readDWord(cmats[i] + d->OG_job_mats->getOffset("sectype3")); + mat[i].flags = p->readDWord(cmats[i] + d->OG_job_mats->getOffset("flags")); } return true; } From b8fbc7f137293e1e2328545142c06c2b54729b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 1 Sep 2010 04:31:12 +0200 Subject: [PATCH 06/19] Vegetation on Linux --- data/Memory-ng.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index d02701380..56fa6df23 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1872,6 +1872,10 @@
+ +
+ + From 988b1d86921703a18426116cd4e7ed6fd024813f Mon Sep 17 00:00:00 2001 From: thewonderidiot Date: Wed, 1 Sep 2010 11:22:19 -0400 Subject: [PATCH 07/19] Added support for reading and setting the weather. Signed-off-by: Mike Stewart --- data/Memory-ng.xml | 4 +++ library/include/dfhack-c/modules/World_C.h | 3 ++ library/include/dfhack/modules/World.h | 14 +++++++-- library/modules/World.cpp | 15 ++++++++++ library/modules/World_C.cpp | 34 ++++++++++++++++++---- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 56fa6df23..015bc0498 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1032,6 +1032,7 @@
+
@@ -1595,6 +1596,9 @@
+ +
+ diff --git a/library/include/dfhack-c/modules/World_C.h b/library/include/dfhack-c/modules/World_C.h index f6261a738..c4348b5e9 100644 --- a/library/include/dfhack-c/modules/World_C.h +++ b/library/include/dfhack-c/modules/World_C.h @@ -40,6 +40,9 @@ DFHACK_EXPORT int World_ReadCurrentYear(DFHackObject* world, uint32_t* year); DFHACK_EXPORT int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month); DFHACK_EXPORT int World_ReadCurrentDay(DFHackObject* world, uint32_t* day); +DFHACK_EXPORT int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather); +DFHACK_EXPORT int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather); + #ifdef __cplusplus } #endif diff --git a/library/include/dfhack/modules/World.h b/library/include/dfhack/modules/World.h index fdb08baf7..7834d4719 100644 --- a/library/include/dfhack/modules/World.h +++ b/library/include/dfhack/modules/World.h @@ -9,21 +9,29 @@ namespace DFHack { + enum WeatherType + { + CLEAR, + RAINING, + SNOWING + }; class DFContextShared; class DFHACK_EXPORT World : public Module { public: - + World(DFHack::DFContextShared * d); ~World(); bool Start(); bool Finish(); - + uint32_t ReadCurrentTick(); uint32_t ReadCurrentYear(); uint32_t ReadCurrentMonth(); uint32_t ReadCurrentDay(); - + uint8_t ReadCurrentWeather(); + void SetCurrentWeather(uint8_t weather); + private: struct Private; Private *d; diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 7a2cab963..a24dbf2a6 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -49,6 +49,7 @@ struct World::Private bool Started; uint32_t year_offset; uint32_t tick_offset; + uint32_t weather_offset; DFContextShared *d; Process * owner; }; @@ -63,6 +64,7 @@ World::World(DFContextShared * _d) OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World"); d->year_offset = OG_World->getAddress( "current_year" ); d->tick_offset = OG_World->getAddress( "current_tick" ); + d->weather_offset = OG_World->getAddress( "current_weather" ); d->Inited = d->Started = true; } @@ -114,3 +116,16 @@ uint32_t World::ReadCurrentDay() { return ((this->ReadCurrentTick() / 1200) % 28) + 1; } + +uint8_t World::ReadCurrentWeather() +{ + if (d->Inited) + return(d->owner->readByte(d->weather_offset)); + return 0; +} + +void World::SetCurrentWeather(uint8_t weather) +{ + if (d->Inited) + d->owner->writeByte(d->weather_offset,weather); +} diff --git a/library/modules/World_C.cpp b/library/modules/World_C.cpp index a5be3bcd0..6aa0b320f 100644 --- a/library/modules/World_C.cpp +++ b/library/modules/World_C.cpp @@ -39,7 +39,7 @@ int World_Start(DFHackObject* world) else return 0; } - + return -1; } @@ -52,7 +52,7 @@ int World_Finish(DFHackObject* world) else return 0; } - + return -1; } @@ -63,7 +63,7 @@ int World_ReadCurrentTick(DFHackObject* world, uint32_t* tick) *tick = ((DFHack::World*)world)->ReadCurrentTick(); return 1; } - + return -1; } @@ -74,7 +74,7 @@ int World_ReadCurrentYear(DFHackObject* world, uint32_t* year) *year = ((DFHack::World*)world)->ReadCurrentYear(); return 1; } - + return -1; } @@ -85,7 +85,7 @@ int World_ReadCurrentMonth(DFHackObject* world, uint32_t* month) *month = ((DFHack::World*)world)->ReadCurrentMonth(); return 1; } - + return -1; } @@ -96,10 +96,32 @@ int World_ReadCurrentDay(DFHackObject* world, uint32_t* day) *day = ((DFHack::World*)world)->ReadCurrentDay(); return 1; } - + return -1; } +int World_ReadCurrentWeather(DFHackObject* world, uint8_t* weather) +{ + if(world != NULL) + { + *weather = ((DFHack::World*)world)->ReadCurrentWeather(); + return 1; + } + + return -1; +} + +int World_WriteCurrentWeather(DFHackObject* world, uint8_t weather) +{ + if (world != NULL) + { + ((DFHack::World*)world)->SetCurrentWeather(weather); + return 1; + } + + return -1; +} + #ifdef __cplusplus } #endif From f1307d9f13c0481ddd90c605d57af4fdb84553dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 1 Sep 2010 18:03:52 +0200 Subject: [PATCH 08/19] Added a common exception for DFHack, made World and Position use it for feature detection. --- data/Memory-ng.xml | 6 ++--- library/include/dfhack/DFError.h | 41 ++++++++++++++++++-------------- library/modules/Position.cpp | 7 +++--- library/modules/World.cpp | 31 +++++++++++++++++------- 4 files changed, 52 insertions(+), 33 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 015bc0498..620a05cb3 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1596,9 +1596,9 @@
- -
- + +
+ diff --git a/library/include/dfhack/DFError.h b/library/include/dfhack/DFError.h index e4def9883..fcb80f724 100644 --- a/library/include/dfhack/DFError.h +++ b/library/include/dfhack/DFError.h @@ -34,7 +34,12 @@ namespace DFHack { namespace Error { - class DFHACK_EXPORT NoProcess : public std::exception + /* + * our wrapper for the C++ exception. used to differentiate + * the whole array of DFHack exceptions from the rest + */ + class DFHACK_EXPORT All : public std::exception{}; + class DFHACK_EXPORT NoProcess : public All { public: virtual const char* what() const throw() @@ -43,7 +48,7 @@ namespace DFHack } }; - class DFHACK_EXPORT CantAttach : public std::exception + class DFHACK_EXPORT CantAttach : public All { public: virtual const char* what() const throw() @@ -52,7 +57,7 @@ namespace DFHack } }; - class DFHACK_EXPORT NoMapLoaded : public std::exception + class DFHACK_EXPORT NoMapLoaded : public All { public: virtual const char* what() const throw() @@ -61,7 +66,7 @@ namespace DFHack } }; - class DFHACK_EXPORT BadMapDimensions : public std::exception + class DFHACK_EXPORT BadMapDimensions : public All { public: BadMapDimensions(uint32_t& _x, uint32_t& _y) : x(_x), y(_y) {} @@ -75,7 +80,7 @@ namespace DFHack }; // a call to DFHack::mem_info::get* failed - class DFHACK_EXPORT MissingMemoryDefinition : public std::exception + class DFHACK_EXPORT MissingMemoryDefinition : public All { public: MissingMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key) @@ -108,7 +113,7 @@ namespace DFHack }; // a call to DFHack::mem_info::get* failed - class DFHACK_EXPORT UnsetMemoryDefinition : public std::exception + class DFHACK_EXPORT UnsetMemoryDefinition : public All { public: UnsetMemoryDefinition(const char* _type, const std::string _key) : type(_type), key(_key) @@ -141,7 +146,7 @@ namespace DFHack }; // Syntax errors and whatnot, the xml cant be read - class DFHACK_EXPORT MemoryXmlParse : public std::exception + class DFHACK_EXPORT MemoryXmlParse : public All { public: MemoryXmlParse(const char* _desc, int _id, int _row, int _col) @@ -167,7 +172,7 @@ namespace DFHack } }; - class DFHACK_EXPORT MemoryXmlBadAttribute : public std::exception + class DFHACK_EXPORT MemoryXmlBadAttribute : public All { public: MemoryXmlBadAttribute(const char* _attr) : attr(_attr) @@ -187,7 +192,7 @@ namespace DFHack } }; - class DFHACK_EXPORT MemoryXmlNoRoot : public std::exception + class DFHACK_EXPORT MemoryXmlNoRoot : public All { public: MemoryXmlNoRoot() {} @@ -200,7 +205,7 @@ namespace DFHack } }; - class DFHACK_EXPORT MemoryXmlNoDFExtractor : public std::exception + class DFHACK_EXPORT MemoryXmlNoDFExtractor : public All { public: MemoryXmlNoDFExtractor(const char* _name) : name(_name) @@ -220,7 +225,7 @@ namespace DFHack } }; - class DFHACK_EXPORT MemoryXmlUnderspecifiedEntry : public std::exception + class DFHACK_EXPORT MemoryXmlUnderspecifiedEntry : public All { public: MemoryXmlUnderspecifiedEntry(const char * _where) : where(_where) @@ -238,7 +243,7 @@ namespace DFHack } }; - class DFHACK_EXPORT MemoryXmlUnknownType : public std::exception + class DFHACK_EXPORT MemoryXmlUnknownType : public All { public: MemoryXmlUnknownType(const char* _type) : type(_type) @@ -258,7 +263,7 @@ namespace DFHack } }; - class DFHACK_EXPORT SHMServerDisappeared : public std::exception + class DFHACK_EXPORT SHMServerDisappeared : public All { public: SHMServerDisappeared(){} @@ -268,7 +273,7 @@ namespace DFHack return "The server process has disappeared"; } }; - class DFHACK_EXPORT SHMLockingError : public std::exception + class DFHACK_EXPORT SHMLockingError : public All { public: SHMLockingError(const char* _type) : type(_type) @@ -287,7 +292,7 @@ namespace DFHack return full.c_str(); } }; - class DFHACK_EXPORT MemoryAccessDenied : public std::exception + class DFHACK_EXPORT MemoryAccessDenied : public All { public: MemoryAccessDenied() {} @@ -297,7 +302,7 @@ namespace DFHack return "SHM ACCESS DENIED"; } }; - class DFHACK_EXPORT SHMVersionMismatch : public std::exception + class DFHACK_EXPORT SHMVersionMismatch : public All { public: SHMVersionMismatch() {} @@ -307,7 +312,7 @@ namespace DFHack return "SHM VERSION MISMATCH"; } }; - class DFHACK_EXPORT SHMAttachFailure : public std::exception + class DFHACK_EXPORT SHMAttachFailure : public All { public: SHMAttachFailure() {} @@ -317,7 +322,7 @@ namespace DFHack return "SHM ATTACH FAILURE"; } }; - class DFHACK_EXPORT ModuleNotInitialized : public std::exception + class DFHACK_EXPORT ModuleNotInitialized : public All { public: ModuleNotInitialized() {} diff --git a/library/modules/Position.cpp b/library/modules/Position.cpp index 920660321..7442d9ddb 100644 --- a/library/modules/Position.cpp +++ b/library/modules/Position.cpp @@ -27,6 +27,7 @@ distribution. #include "dfhack/modules/Position.h" #include "dfhack/VersionInfo.h" #include "dfhack/DFProcess.h" +#include "dfhack/DFError.h" using namespace DFHack; struct Position::Private @@ -72,7 +73,7 @@ Position::Position(DFContextShared * d_) d->window_dims_offset = OG_Position->getAddress ("window_dims"); d->Started = true; } - catch(exception &){}; + catch(Error::All &){}; try { OffsetGroup * OG_Hotkeys = mem->getGroup("Hotkeys"); @@ -82,13 +83,13 @@ Position::Position(DFContextShared * d_) d->hotkey_size = OG_Hotkeys->getHexValue("size"); d->StartedHotkeys = true; } - catch(exception &){}; + catch(Error::All &){}; try { d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer"); d->StartedScreen = true; } - catch(exception &){}; + catch(Error::All &){}; } Position::~Position() diff --git a/library/modules/World.cpp b/library/modules/World.cpp index a24dbf2a6..009b696ac 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -40,13 +40,15 @@ FIXME: Japa said that he had to do this with the time stuff he got from here #include "dfhack/DFProcess.h" #include "dfhack/VersionInfo.h" #include "dfhack/DFTypes.h" +#include "dfhack/DFError.h" using namespace DFHack; struct World::Private { bool Inited; - bool Started; + bool StartedTime; + bool StartedWeather; uint32_t year_offset; uint32_t tick_offset; uint32_t weather_offset; @@ -60,12 +62,23 @@ World::World(DFContextShared * _d) d = new Private; d->d = _d; d->owner = _d->p; + d->Inited = d->StartedTime = d->StartedWeather = false; OffsetGroup * OG_World = d->d->offset_descriptor->getGroup("World"); - d->year_offset = OG_World->getAddress( "current_year" ); - d->tick_offset = OG_World->getAddress( "current_tick" ); - d->weather_offset = OG_World->getAddress( "current_weather" ); - d->Inited = d->Started = true; + try + { + d->year_offset = OG_World->getAddress( "current_year" ); + d->tick_offset = OG_World->getAddress( "current_tick" ); + d->StartedTime = true; + } + catch(Error::All &){}; + try + { + d->weather_offset = OG_World->getAddress( "current_weather" ); + d->StartedWeather = true; + } + catch(Error::All &){}; + d->Inited = true; } World::~World() @@ -85,14 +98,14 @@ bool World::Finish() uint32_t World::ReadCurrentYear() { - if(d->Inited) + if(d->Inited && d->StartedTime) return(d->owner->readDWord(d->year_offset)); return 0; } uint32_t World::ReadCurrentTick() { - if(d->Inited) + if(d->Inited && d->StartedTime) return(d->owner->readDWord(d->tick_offset)); return 0; } @@ -119,13 +132,13 @@ uint32_t World::ReadCurrentDay() uint8_t World::ReadCurrentWeather() { - if (d->Inited) + if (d->Inited && d->StartedWeather) return(d->owner->readByte(d->weather_offset)); return 0; } void World::SetCurrentWeather(uint8_t weather) { - if (d->Inited) + if (d->Inited && d->StartedWeather) d->owner->writeByte(d->weather_offset,weather); } From 4ca60915a1a80d80f02ccb6e69b64af6f86c7f67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 1 Sep 2010 19:41:40 +0200 Subject: [PATCH 09/19] Weather support on linux --- data/Memory-ng.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 620a05cb3..dba9c706d 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1880,6 +1880,9 @@
+ +
+ From 0702960731a2c95902323ad4142102f51c359af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 1 Sep 2010 20:51:12 +0200 Subject: [PATCH 10/19] Fix problems with CMAKE names, weather tool skeleton --- tools/playground/CMakeLists.txt | 4 ++-- tools/supported/CMakeLists.txt | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/playground/CMakeLists.txt b/tools/playground/CMakeLists.txt index c48ac459d..ab21e3c2d 100644 --- a/tools/playground/CMakeLists.txt +++ b/tools/playground/CMakeLists.txt @@ -61,7 +61,7 @@ ADD_EXECUTABLE(dfcopypaste copypaste.cpp) TARGET_LINK_LIBRARIES(dfcopypaste dfhack) # this needs the C bindings -IF(BUILD_DFHACK_C_BINDIGS) +IF(BUILD_DFHACK_C_BINDINGS) # for trying out some 'stuff' ADD_EXECUTABLE(dftest test.cpp) TARGET_LINK_LIBRARIES(dftest dfhack) @@ -69,7 +69,7 @@ IF(BUILD_DFHACK_C_BINDIGS) dftest RUNTIME DESTINATION bin ) -ENDIF(BUILD_DFHACK_C_BINDIGS) +ENDIF(BUILD_DFHACK_C_BINDINGS) install(TARGETS dfmoodump diff --git a/tools/supported/CMakeLists.txt b/tools/supported/CMakeLists.txt index f7006aeb2..624177d4b 100644 --- a/tools/supported/CMakeLists.txt +++ b/tools/supported/CMakeLists.txt @@ -64,6 +64,11 @@ TARGET_LINK_LIBRARIES(dfposition dfhack) ADD_EXECUTABLE(dfdoffsets dumpoffsets.cpp) TARGET_LINK_LIBRARIES(dfdoffsets dfhack) +# change the weather +ADD_EXECUTABLE(dfweather weather.cpp) +TARGET_LINK_LIBRARIES(dfweather dfhack) + + IF(UNIX) SET(CURSES_NEED_WIDE "YES") SET(CURSES_NEED_NCURSES "NO") From ece423a61190fa5fb2411c281e4456712288239a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 1 Sep 2010 21:09:45 +0200 Subject: [PATCH 11/19] Weather tool --- tools/supported/CMakeLists.txt | 1 + tools/supported/weather.cpp | 96 ++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 tools/supported/weather.cpp diff --git a/tools/supported/CMakeLists.txt b/tools/supported/CMakeLists.txt index 624177d4b..8befe499c 100644 --- a/tools/supported/CMakeLists.txt +++ b/tools/supported/CMakeLists.txt @@ -119,6 +119,7 @@ dfexpbench dfsuspend dfflows dfliquids +dfweather RUNTIME DESTINATION bin ) IF(UNIX) diff --git a/tools/supported/weather.cpp b/tools/supported/weather.cpp new file mode 100644 index 000000000..d5c3139f4 --- /dev/null +++ b/tools/supported/weather.cpp @@ -0,0 +1,96 @@ +// Just show some position data + +#include +#include +#include +#include +#include +#include +#include + +#define DFHACK_WANT_MISCUTILS +#define DFHACK_WANT_TILETYPES +#include + +using namespace DFHack; + +void printWeather(DFHack::WeatherType current) +{ + switch (current) + { + case CLEAR: + cout << "The sky is clear." << endl; + cout << "Options:" << endl; + cout << "'r' to make it rain." << endl; + cout << "'s' to make it snow." << endl; + break; + case RAINING: + cout << "It is raining." << endl; + cout << "'c' to clear the sky." << endl; + cout << "'s' to make it snow." << endl; + break; + case SNOWING: + cout << "It is snowing." << endl; + cout << "'c' to clear the sky." << endl; + cout << "'r' to make it rain." << endl; + break; + } + cout << "'q' to quit." << endl; + cout << "anything else to refresh" << endl; + cout << ">"; +} + +using namespace DFHack; +int main (int numargs, const char ** args) +{ + DFHack::ContextManager DFMgr("Memory.xml"); + DFHack::Context *DF = DFMgr.getSingleContext(); + + try + { + DF->Attach(); + } + catch (std::exception& e) + { + std::cerr << e.what() << std::endl; + #ifndef LINUX_BUILD + cin.ignore(); + #endif + return 1; + } + + World *W = DF->getWorld(); + W->Start(); + bool end = false; + while(!end) + { + WeatherType current = (WeatherType) W->ReadCurrentWeather(); + DF->Resume(); + string command = ""; + printWeather(current); + getline(cin, command); + DF->Suspend(); + if(command == "c") + { + W->SetCurrentWeather(CLEAR); + } + else if(command == "r") + { + W->SetCurrentWeather(RAINING); + } + else if(command == "s") + { + W->SetCurrentWeather(SNOWING); + } + else if(command == "q") + { + end = true; + } + } + #ifndef LINUX_BUILD + std::cout << "Done. Press any key to continue" << std::endl; + cin.ignore(); + #endif + DF->Detach(); + return 0; +} From dc6aa19083ad70c206ff682c4f0157d3ea75a433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 3 Sep 2010 02:15:09 +0200 Subject: [PATCH 12/19] Creature rework --- data/Memory-ng.xml | 2 +- library/modules/Creatures.cpp | 126 ++++++++++++++++------------------ tools/supported/weather.cpp | 2 + 3 files changed, 63 insertions(+), 67 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index dba9c706d..a6f2961b5 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1032,7 +1032,7 @@
-
+
diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index ee78df9d8..e7c203f60 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -50,6 +50,10 @@ struct Creatures::Private { bool Inited; bool Started; + bool Ft_basic; + bool Ft_advanced; + bool Ft_jobs; + bool Ft_soul; Creatures2010::creature_offsets creatures; uint32_t creature_module; uint32_t dwarf_race_index_addr; @@ -69,82 +73,72 @@ Creatures::Creatures(DFContextShared* _d) d->Inited = false; d->Started = false; d->d->InitReadNames(); // throws on error + VersionInfo * minfo = d->d->offset_descriptor; + OffsetGroup *OG_Creatures = minfo->getGroup("Creatures"); + OffsetGroup *OG_creature = OG_Creatures->getGroup("creature"); + OffsetGroup *OG_creature_ex = OG_creature->getGroup("advanced"); + OffsetGroup *OG_soul = OG_Creatures->getGroup("soul"); + OffsetGroup * OG_name = minfo->getGroup("name"); + d->OG_jobs = OG_Creatures->getGroup("job"); + d->OG_job_mats = d->OG_jobs->getGroup("material"); + d->Ft_basic = d->Ft_advanced = d->Ft_jobs = d->Ft_soul = false; + + Creatures2010::creature_offsets &creatures = d->creatures; try { - VersionInfo * minfo = d->d->offset_descriptor; - Creatures2010::creature_offsets &creatures = d->creatures; - OffsetGroup *OG_Creatures = minfo->getGroup("Creatures"); + // Creatures + creatures.vector = OG_Creatures->getAddress ("vector"); + d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race"); + d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ"); + // Creatures/creature + creatures.name_offset = OG_creature->getOffset ("name"); + creatures.custom_profession_offset = OG_creature->getOffset ("custom_profession"); + creatures.profession_offset = OG_creature->getOffset ("profession"); + creatures.race_offset = OG_creature->getOffset ("race"); + creatures.pos_offset = OG_creature->getOffset ("position"); + creatures.flags1_offset = OG_creature->getOffset ("flags1"); + creatures.flags2_offset = OG_creature->getOffset ("flags2"); + creatures.sex_offset = OG_creature->getOffset ("sex"); + creatures.caste_offset = OG_creature->getOffset ("caste"); + creatures.id_offset = OG_creature->getOffset ("id"); + creatures.civ_offset = OG_creature->getOffset ("civ"); + // name struct + creatures.name_firstname_offset = OG_name->getOffset("first"); + creatures.name_nickname_offset = OG_name->getOffset("nick"); + creatures.name_words_offset = OG_name->getOffset("second_words"); + d->Ft_basic = true; + try { - creatures.vector = OG_Creatures->getAddress ("vector"); - d->dwarf_race_index_addr = OG_Creatures->getAddress("current_race"); - d->dwarf_civ_id_addr = OG_Creatures->getAddress("current_civ"); - OffsetGroup *OG_creature = OG_Creatures->getGroup("creature"); - { - creatures.name_offset = OG_creature->getOffset ("name"); - creatures.custom_profession_offset = OG_creature->getOffset ("custom_profession"); - creatures.profession_offset = OG_creature->getOffset ("profession"); - creatures.race_offset = OG_creature->getOffset ("race"); - creatures.pos_offset = OG_creature->getOffset ("position"); - creatures.flags1_offset = OG_creature->getOffset ("flags1"); - creatures.flags2_offset = OG_creature->getOffset ("flags2"); - creatures.sex_offset = OG_creature->getOffset ("sex"); - creatures.caste_offset = OG_creature->getOffset ("caste"); - creatures.id_offset = OG_creature->getOffset ("id"); - creatures.civ_offset = OG_creature->getOffset ("civ"); - OffsetGroup *OG_creature_ex = OG_creature->getGroup("advanced"); - { - creatures.inventory_offset = OG_creature_ex->getOffset("inventory_vector"); - creatures.pickup_equipment_bit = OG_creature_ex->getOffset("pickup_equipment_bit"); - creatures.mood_offset = OG_creature_ex->getOffset("mood"); - // pregnancy - // pregnancy_ptr - creatures.birth_year_offset = OG_creature_ex->getOffset("birth_year"); - creatures.birth_time_offset = OG_creature_ex->getOffset("birth_time"); - creatures.current_job_offset = OG_creature_ex->getOffset("current_job"); - creatures.mood_skill_offset = OG_creature_ex->getOffset("current_job_skill"); - creatures.physical_offset = OG_creature_ex->getOffset("physical"); - creatures.appearance_vector_offset = OG_creature_ex->getOffset("appearance_vector"); - creatures.artifact_name_offset = OG_creature_ex->getOffset("artifact_name"); - creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector"); - creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul"); - creatures.labors_offset = OG_creature_ex->getOffset ("labors"); - creatures.happiness_offset = OG_creature_ex->getOffset ("happiness"); - } - } - OffsetGroup *OG_soul = OG_Creatures->getGroup("soul"); + creatures.inventory_offset = OG_creature_ex->getOffset("inventory_vector"); + creatures.pickup_equipment_bit = OG_creature_ex->getOffset("pickup_equipment_bit"); + creatures.mood_offset = OG_creature_ex->getOffset("mood"); + // pregnancy + // pregnancy_ptr + creatures.birth_year_offset = OG_creature_ex->getOffset("birth_year"); + creatures.birth_time_offset = OG_creature_ex->getOffset("birth_time"); + creatures.current_job_offset = OG_creature_ex->getOffset("current_job"); + creatures.mood_skill_offset = OG_creature_ex->getOffset("current_job_skill"); + creatures.physical_offset = OG_creature_ex->getOffset("physical"); + creatures.appearance_vector_offset = OG_creature_ex->getOffset("appearance_vector"); + creatures.artifact_name_offset = OG_creature_ex->getOffset("artifact_name"); + creatures.labors_offset = OG_creature_ex->getOffset ("labors"); + creatures.happiness_offset = OG_creature_ex->getOffset ("happiness"); + d->Ft_advanced = true; + try { + creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector"); + creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul"); creatures.soul_mental_offset = OG_soul->getOffset("mental"); creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector"); creatures.soul_traits_offset = OG_soul->getOffset("traits"); + d->Ft_soul = true; } + catch(Error::All&){}; } - // name offsets for the creature module - OffsetGroup * OG_name = minfo->getGroup("name"); - { - creatures.name_firstname_offset = OG_name->getOffset("first"); - creatures.name_nickname_offset = OG_name->getOffset("nick"); - creatures.name_words_offset = OG_name->getOffset("second_words"); - } - d->OG_jobs = OG_Creatures->getGroup("job"); - d->OG_job_mats = d->OG_jobs->getGroup("material"); - - /* - // upload offsets to the SHM - if(p->getModuleIndex("Creatures2010",1,d->creature_module)) - { - // supply the module with offsets so it can work with them - memcpy(SHMDATA(Creatures2010::creature_offsets),&creatures,sizeof(Creatures2010::creature_offsets)); - const uint32_t cmd = Creatures2010::CREATURE_INIT + (d->creature_module << 16); - p->SetAndWait(cmd); - } - */ - d->Inited = true; - } - catch (Error::MissingMemoryDefinition&) - { - d->Inited = false; - throw; + catch(Error::All&){}; } + catch(Error::All&){}; + d->Inited = true; } Creatures::~Creatures() diff --git a/tools/supported/weather.cpp b/tools/supported/weather.cpp index d5c3139f4..6d441b00b 100644 --- a/tools/supported/weather.cpp +++ b/tools/supported/weather.cpp @@ -26,11 +26,13 @@ void printWeather(DFHack::WeatherType current) break; case RAINING: cout << "It is raining." << endl; + cout << "Options:" << endl; cout << "'c' to clear the sky." << endl; cout << "'s' to make it snow." << endl; break; case SNOWING: cout << "It is snowing." << endl; + cout << "Options:" << endl; cout << "'c' to clear the sky." << endl; cout << "'r' to make it rain." << endl; break; From 5a5745590a1421136f125481ae8081a78b5b55b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 3 Sep 2010 03:01:37 +0200 Subject: [PATCH 13/19] More Creatures rework, this time with more memset --- data/Memory-ng.xml | 7 +- library/modules/Creatures.cpp | 232 +++++++++++++++----------------- library/modules/Materials.cpp | 101 ++++++++------ tools/examples/creaturedump.cpp | 10 +- 4 files changed, 185 insertions(+), 165 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index a6f2961b5..e7b93bb34 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1737,13 +1737,15 @@ - + diff --git a/library/modules/Creatures.cpp b/library/modules/Creatures.cpp index e7c203f60..0d26f336b 100644 --- a/library/modules/Creatures.cpp +++ b/library/modules/Creatures.cpp @@ -124,16 +124,16 @@ Creatures::Creatures(DFContextShared* _d) creatures.labors_offset = OG_creature_ex->getOffset ("labors"); creatures.happiness_offset = OG_creature_ex->getOffset ("happiness"); d->Ft_advanced = true; - try - { - creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector"); - creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul"); - creatures.soul_mental_offset = OG_soul->getOffset("mental"); - creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector"); - creatures.soul_traits_offset = OG_soul->getOffset("traits"); - d->Ft_soul = true; - } - catch(Error::All&){}; + } + catch(Error::All&){}; + try + { + creatures.soul_vector_offset = OG_creature_ex->getOffset("soul_vector"); + creatures.default_soul_offset = OG_creature_ex->getOffset("current_soul"); + creatures.soul_mental_offset = OG_soul->getOffset("mental"); + creatures.soul_skills_vector_offset = OG_soul->getOffset("skills_vector"); + creatures.soul_traits_offset = OG_soul->getOffset("traits"); + d->Ft_soul = true; } catch(Error::All&){}; } @@ -169,6 +169,7 @@ bool Creatures::Finish() bool Creatures::ReadCreature (const int32_t index, t_creature & furball) { if(!d->Started) return false; + memset(&furball, 0, sizeof(t_creature)); // SHM fast path Process * p = d->owner; /* @@ -190,129 +191,120 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) Creatures2010::creature_offsets &offs = d->creatures; //read creature from memory - - // name - d->d->readName(furball.name,temp + offs.name_offset); - - // basic stuff - p->readDWord (temp + offs.happiness_offset, furball.happiness); - p->readDWord (temp + offs.id_offset, furball.id); - p->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really - 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); - - // physical attributes - p->read(temp + offs.physical_offset, - sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES, - (uint8_t *)&furball.strength); - - // mood stuff - furball.mood = (int16_t) p->readWord (temp + offs.mood_offset); - furball.mood_skill = p->readWord (temp + offs.mood_skill_offset); - d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset); - - // custom profession - p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession)); - //fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset)); - - // labors - p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors); - - // profession - furball.profession = p->readByte (temp + offs.profession_offset); - - furball.current_job.occupationPtr = p->readDWord (temp + offs.current_job_offset); - if(furball.current_job.occupationPtr) + if(d->Ft_basic) { - furball.current_job.active = true; - furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + d->OG_jobs->getOffset("type") ); - furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + d->OG_jobs->getOffset("id") ); + // name + d->d->readName(furball.name,temp + offs.name_offset); + + // basic stuff + p->readDWord (temp + offs.id_offset, furball.id); + p->read (temp + offs.pos_offset, 3 * sizeof (uint16_t), (uint8_t *) & (furball.x)); // xyz really + 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); + // custom profession + p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession)); + // profession + furball.profession = p->readByte (temp + offs.profession_offset); } - else + if(d->Ft_advanced) { - furball.current_job.active = false;; - } - - furball.birth_year = p->readDWord (temp + offs.birth_year_offset ); - furball.birth_time = p->readDWord (temp + offs.birth_time_offset ); - - // current job HACK: the job object isn't cleanly represented here - /* - uint32_t jobIdAddr = p->readDWord (temp + offs.creature_current_job_offset); + // happiness + p->readDWord (temp + offs.happiness_offset, furball.happiness); + + // physical attributes + p->read(temp + offs.physical_offset, + sizeof(t_attrib) * NUM_CREATURE_PHYSICAL_ATTRIBUTES, + (uint8_t *)&furball.strength); + + // mood stuff + furball.mood = (int16_t) p->readWord (temp + offs.mood_offset); + furball.mood_skill = p->readWord (temp + offs.mood_skill_offset); + d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset); + + // labors + p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors); + furball.birth_year = p->readDWord (temp + offs.birth_year_offset ); + furball.birth_time = p->readDWord (temp + offs.birth_time_offset ); + /* + * p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer); + */ + + // appearance + 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]; + } - if (jobIdAddr) - { - furball.current_job.active = true; - furball.current_job.jobId = p->readByte (jobIdAddr + offs.creature_current_job_id_offset); + //likes + /* + DfVector likes(d->p, temp + offs.creature_likes_offset); + furball.numLikes = likes.getSize(); + for(uint32_t i = 0;iread(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]); + }*/ } - else + if(d->Ft_soul) { - furball.current_job.active = false; - } - */ - - /* - p->readDWord(temp + offs.creature_pregnancy_offset, furball.pregnancy_timer); - */ + /* + // enum soul pointer vector + DfVector souls(p,temp + offs.creature_soul_vector_offset); + */ + uint32_t soul = p->readDWord(temp + offs.default_soul_offset); + furball.has_default_soul = false; + + if(soul) + { + furball.has_default_soul = true; + // get first soul's skills + DfVector skills(p, soul + offs.soul_skills_vector_offset); + furball.defaultSoul.numSkills = skills.size(); - /* - // enum soul pointer vector - DfVector souls(p,temp + offs.creature_soul_vector_offset); - */ - uint32_t soul = p->readDWord(temp + offs.default_soul_offset); - furball.has_default_soul = false; + for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++) + { + uint32_t temp2 = skills[i]; + // a byte: this gives us 256 skills maximum. + furball.defaultSoul.skills[i].id = p->readByte (temp2); + furball.defaultSoul.skills[i].rating = + p->readByte (temp2 + offsetof(t_skill, rating)); + furball.defaultSoul.skills[i].experience = + p->readWord (temp2 + offsetof(t_skill, experience)); + } - if(soul) - { - furball.has_default_soul = true; - // get first soul's skills - DfVector skills(p, soul + offs.soul_skills_vector_offset); - furball.defaultSoul.numSkills = skills.size(); + // mental attributes are part of the soul + p->read(soul + offs.soul_mental_offset, + sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES, + (uint8_t *)&furball.defaultSoul.analytical_ability); - for (uint32_t i = 0; i < furball.defaultSoul.numSkills;i++) - { - uint32_t temp2 = skills[i]; - // a byte: this gives us 256 skills maximum. - furball.defaultSoul.skills[i].id = p->readByte (temp2); - furball.defaultSoul.skills[i].rating = - p->readByte (temp2 + offsetof(t_skill, rating)); - furball.defaultSoul.skills[i].experience = - p->readWord (temp2 + offsetof(t_skill, experience)); + // traits as well + p->read(soul + offs.soul_traits_offset, + sizeof (uint16_t) * NUM_CREATURE_TRAITS, + (uint8_t *) &furball.defaultSoul.traits); } - - // mental attributes are part of the soul - p->read(soul + offs.soul_mental_offset, - sizeof(t_attrib) * NUM_CREATURE_MENTAL_ATTRIBUTES, - (uint8_t *)&furball.defaultSoul.analytical_ability); - - // 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++) + if(d->Ft_jobs) { - furball.color[i] = app[i]; + furball.current_job.occupationPtr = p->readDWord (temp + offs.current_job_offset); + if(furball.current_job.occupationPtr) + { + furball.current_job.active = true; + furball.current_job.jobType = p->readByte (furball.current_job.occupationPtr + d->OG_jobs->getOffset("type") ); + furball.current_job.jobId = p->readDWord (furball.current_job.occupationPtr + d->OG_jobs->getOffset("id") ); + } + else + { + furball.current_job.active = false;; + } } - //likes - /* - DfVector likes(d->p, temp + offs.creature_likes_offset); - furball.numLikes = likes.getSize(); - for(uint32_t i = 0;iread(temp2,sizeof(t_like),(uint8_t *) &furball.likes[i]); - }*/ - return true; } diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index a7f4e63da..2ad78361e 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -29,6 +29,7 @@ distribution. #include "dfhack/VersionInfo.h" #include "dfhack/DFProcess.h" #include "dfhack/DFVector.h" +#include using namespace DFHack; @@ -335,20 +336,38 @@ bool Materials::ReadCreatureTypesEx (void) uint32_t extract_vector_offset = OG_Creature->getOffset ("extract_vector"); uint32_t tile_offset = OG_Creature->getOffset ("tile"); uint32_t tile_color_offset = OG_Creature->getOffset ("tile_color"); + + bool have_advanced = false; + uint32_t caste_colormod_offset; + uint32_t caste_attributes_offset; + uint32_t caste_bodypart_offset; + uint32_t bodypart_id_offset; + uint32_t bodypart_category_offset; + uint32_t bodypart_layers_offset; + uint32_t bodypart_singular_offset; + uint32_t bodypart_plural_offset; + uint32_t color_modifier_part_offset; + uint32_t color_modifier_startdate_offset; + uint32_t color_modifier_enddate_offset; + try + { OffsetGroup * OG_Caste = OG_Creature->getGroup("caste"); - uint32_t caste_colormod_offset = OG_Caste->getOffset ("color_modifiers"); - uint32_t caste_attributes_offset = OG_Caste->getOffset ("attributes"); - uint32_t caste_bodypart_offset = OG_Caste->getOffset ("bodypart_vector"); + caste_colormod_offset = OG_Caste->getOffset ("color_modifiers"); + caste_attributes_offset = OG_Caste->getOffset ("attributes"); + caste_bodypart_offset = OG_Caste->getOffset ("bodypart_vector"); OffsetGroup * OG_CasteBodyparts = OG_Creature->getGroup("caste_bodyparts"); - uint32_t bodypart_id_offset = OG_CasteBodyparts->getOffset ("id"); - uint32_t bodypart_category_offset = OG_CasteBodyparts->getOffset ("category"); - uint32_t bodypart_layers_offset = OG_CasteBodyparts->getOffset ("layers_vector"); // unused - uint32_t bodypart_singular_offset = OG_CasteBodyparts->getOffset ("singular_vector"); // unused - uint32_t bodypart_plural_offset = OG_CasteBodyparts->getOffset ("plural_vector"); // unused + bodypart_id_offset = OG_CasteBodyparts->getOffset ("id"); + bodypart_category_offset = OG_CasteBodyparts->getOffset ("category"); + bodypart_layers_offset = OG_CasteBodyparts->getOffset ("layers_vector"); // unused + bodypart_singular_offset = OG_CasteBodyparts->getOffset ("singular_vector"); // unused + bodypart_plural_offset = OG_CasteBodyparts->getOffset ("plural_vector"); // unused OffsetGroup * OG_CasteColorMods = OG_Creature->getGroup("caste_color_mods"); - uint32_t color_modifier_part_offset = OG_CasteColorMods->getOffset ("part"); - uint32_t color_modifier_startdate_offset = OG_CasteColorMods->getOffset ("startdate"); - uint32_t color_modifier_enddate_offset = OG_CasteColorMods->getOffset ("enddate"); + color_modifier_part_offset = OG_CasteColorMods->getOffset ("part"); + color_modifier_startdate_offset = OG_CasteColorMods->getOffset ("startdate"); + color_modifier_enddate_offset = OG_CasteColorMods->getOffset ("enddate"); + have_advanced = true; + } + catch (Error::All &){}; uint32_t size = p_races.size(); uint32_t sizecas = 0; @@ -383,38 +402,36 @@ 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)); - - /* color mod reading */ - 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].colorlist.resize(sizecolorlist); - for(uint32_t l = 0; l < sizecolorlist; l++) - caste.ColorModifier[k].colorlist[l] = p_colorlist[l]; - p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part)); - caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset ); - caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset ); - } - - /* body parts */ - DfVector p_bodypart(p, caste_start + caste_bodypart_offset); - caste.bodypart.empty(); - sizebp = p_bodypart.size(); - for(uint32_t k = 0; k < sizebp; k++) + if(have_advanced) { - t_bodypart part; - p->readSTLString (p_bodypart[k] + bodypart_id_offset, part.id, sizeof(part.id)); - p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category)); - caste.bodypart.push_back(part); + /* color mod reading */ + 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].colorlist.resize(sizecolorlist); + for(uint32_t l = 0; l < sizecolorlist; l++) + caste.ColorModifier[k].colorlist[l] = p_colorlist[l]; + p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part)); + caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset ); + caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset ); + } + /* body parts */ + DfVector p_bodypart(p, caste_start + caste_bodypart_offset); + caste.bodypart.empty(); + sizebp = p_bodypart.size(); + for(uint32_t k = 0; k < sizebp; k++) + { + t_bodypart part; + p->readSTLString (p_bodypart[k] + bodypart_id_offset, part.id, sizeof(part.id)); + p->readSTLString (p_bodypart[k] + bodypart_category_offset, part.category, sizeof(part.category)); + caste.bodypart.push_back(part); + } + p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * (6+11), (uint8_t *)&caste.strength); } - - - p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * (6+11), (uint8_t *)&caste.strength); - mat.castes.push_back(caste); } DfVector p_extract(p, p_races[i] + extract_vector_offset); @@ -438,7 +455,7 @@ void Materials::ReadAllMaterials(void) this->ReadCreatureTypes(); this->ReadCreatureTypesEx(); this->ReadDescriptorColors(); - this->ReadOthers(); + //this->ReadOthers(); } std::string Materials::getDescription(t_material & mat) diff --git a/tools/examples/creaturedump.cpp b/tools/examples/creaturedump.cpp index c4bb8e4ac..eb611eefe 100644 --- a/tools/examples/creaturedump.cpp +++ b/tools/examples/creaturedump.cpp @@ -453,8 +453,14 @@ int main (int numargs, char ** args) } mem = DF->getMemoryInfo(); - Materials->ReadAllMaterials(); - + Materials->ReadInorganicMaterials(); + Materials->ReadOrganicMaterials(); + Materials->ReadWoodMaterials(); + Materials->ReadPlantMaterials(); + Materials->ReadCreatureTypes(); + Materials->ReadCreatureTypesEx(); + Materials->ReadDescriptorColors(); + if(!Tran->Start()) { cerr << "Can't get name tables" << endl; From 813b771cd6201593666ba1f87251d545133d40c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 3 Sep 2010 03:17:03 +0200 Subject: [PATCH 14/19] Correct creature position offset on linux --- data/Memory-ng.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index e7b93bb34..e0528d4b0 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1714,7 +1714,7 @@ - + From f6b137230ad056bbf20af880412a927bad215080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 4 Sep 2010 07:43:39 +0200 Subject: [PATCH 15/19] Fixed pause state offset in 31.12 linux version, dfreveal pauses and has improved usability. --- data/Memory-ng.xml | 4 ++++ library/include/DFHack.h | 1 + library/include/dfhack/modules/Gui.h | 4 +++- library/modules/Gui.cpp | 8 +++++++- library/modules/Maps.cpp | 1 + tools/supported/reveal.cpp | 24 +++++++++++++++++++----- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index e0528d4b0..9941440b4 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1874,6 +1874,10 @@ + + +
+
diff --git a/library/include/DFHack.h b/library/include/DFHack.h index 57e11ad50..95f39729a 100644 --- a/library/include/DFHack.h +++ b/library/include/DFHack.h @@ -32,6 +32,7 @@ #include "dfhack/modules/Items.h" #include "dfhack/modules/Vegetation.h" #include "dfhack/modules/Maps.h" +#include "dfhack/modules/Gui.h" /* * This is a header full of ugly, volatile things. diff --git a/library/include/dfhack/modules/Gui.h b/library/include/dfhack/modules/Gui.h index 0ef170d3f..6ac91f35c 100644 --- a/library/include/dfhack/modules/Gui.h +++ b/library/include/dfhack/modules/Gui.h @@ -21,7 +21,9 @@ namespace DFHack bool Finish(); ///true if paused, false if not - bool ReadPauseState(); + bool ReadPauseState(); + ///true if paused, false if not + void SetPauseState(bool paused); /// read the DF menu view state (stock screen, unit screen, other screens bool ReadViewScreen(t_viewscreen &); /// read the DF menu state (designation menu ect) diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 37d027495..177a00467 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -93,13 +93,19 @@ bool Gui::Finish() bool Gui::ReadPauseState() { - // replace with an exception if(!d->PauseInited) return false; uint32_t pauseState = d->owner->readDWord (d->pause_state_offset); return pauseState & 1; } +void Gui::SetPauseState(bool paused) +{ + if(!d->PauseInited) return; + cout << "pause set" << endl; + d->owner->writeDWord (d->pause_state_offset, paused); +} + uint32_t Gui::ReadMenuState() { if(d->MenuStateInited) diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index eab61faf9..124e9bea9 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -70,6 +70,7 @@ Maps::Maps(DFContextShared* _d) d->d = _d; Process *p = d->owner = _d->p; d->Inited = d->Started = false; + d->block = NULL; DFHack::VersionInfo * mem = p->getDescriptor(); Server::Maps::maps_offsets &off = d->offsets; diff --git a/tools/supported/reveal.cpp b/tools/supported/reveal.cpp index 66ec3d92f..4233be189 100644 --- a/tools/supported/reveal.cpp +++ b/tools/supported/reveal.cpp @@ -6,6 +6,7 @@ using namespace std; #include +#include struct hideblock { @@ -37,6 +38,16 @@ int main (void) } DFHack::Maps *Maps =DF->getMaps(); + DFHack::Gui *Gui =DF->getGui(); + // walk the map, save the hide bits, reveal. + cout << "Pausing..." << endl; + + // horrible hack to make sure the pause is really set + Gui->SetPauseState(true); + DF->Resume(); + usleep(100); + DF->Suspend(); + // init the map if(!Maps->Start()) { @@ -46,11 +57,12 @@ int main (void) #endif return 1; } - + + cout << "Revealing, please wait..." << endl; + Maps->getSize(x_max,y_max,z_max); vector hidesaved; - // walk the map, save the hide bits, reveal. - cout << "Revealing... please wait." << endl; + for(uint32_t x = 0; x< x_max;x++) { for(uint32_t y = 0; y< y_max;y++) @@ -80,8 +92,10 @@ int main (void) } // FIXME: force game pause here! DF->Detach(); - cout << "Map revealed. Close window/force exit to keep it that way." << endl; - cout << "Press any key to unreveal. Don't close DF or unpause in that case!" << endl; + cout << "Map revealed. The game has been paused for you." << endl; + cout << "Unpausing can unleash the forces of hell!" << endl << endl; + cout << "Press any key to unreveal." << endl; + cout << "Close to keep the map revealed." << endl; cin.ignore(); cout << "Unrevealing... please wait." << endl; // FIXME: do some consistency checks here! From ac550c8a7ad4e9393c95942b48d7d97ebf4cc96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 8 Sep 2010 00:06:30 +0200 Subject: [PATCH 16/19] Fix for the build system. Don't install veinlook when it's not built due to missing dependencies. --- tools/supported/CMakeLists.txt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/supported/CMakeLists.txt b/tools/supported/CMakeLists.txt index 8befe499c..22482f5ea 100644 --- a/tools/supported/CMakeLists.txt +++ b/tools/supported/CMakeLists.txt @@ -70,6 +70,7 @@ TARGET_LINK_LIBRARIES(dfweather dfhack) IF(UNIX) + SET(VEINLOOK_BUILT "NO") SET(CURSES_NEED_WIDE "YES") SET(CURSES_NEED_NCURSES "NO") find_package(Curses QUIET) @@ -122,9 +123,3 @@ dfliquids dfweather RUNTIME DESTINATION bin ) -IF(UNIX) - install(TARGETS - dfveinlook - RUNTIME DESTINATION bin - ) -ENDIF(UNIX) From 53930c673b748ee1387cd9637d78d1278e82d2c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 8 Sep 2010 12:36:22 +0200 Subject: [PATCH 17/19] Fix for veinlook - it wasn't reading the creature races. --- tools/supported/veinlook.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/supported/veinlook.cpp b/tools/supported/veinlook.cpp index 1f489b355..7eaa2419f 100644 --- a/tools/supported/veinlook.cpp +++ b/tools/supported/veinlook.cpp @@ -723,6 +723,7 @@ main(int argc, char *argv[]) Maps->Start(); Mats->Start(); Mats->ReadInorganicMaterials(); + Mats->ReadCreatureTypes(); uint32_t effectnum; /* if(DF.InitReadEffects(effectnum)) From d041ed21f7abbbc3be328b247dedb2a968c82dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Wed, 8 Sep 2010 18:03:24 +0200 Subject: [PATCH 18/19] Jobs turned into tags (by Japa) --- data/Memory-ng.xml | 567 +++++++++++++++++---------------------------- 1 file changed, 210 insertions(+), 357 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 9941440b4..f331c10d2 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -144,363 +144,216 @@ - TODO: Parse this and turn it into Job tags - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 294888f84a32195e996e2cdc111a665398032b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 9 Sep 2010 03:36:11 +0200 Subject: [PATCH 19/19] Remove usleep() from reveal, replaced by normal sleep(). --- tools/supported/reveal.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/supported/reveal.cpp b/tools/supported/reveal.cpp index 4233be189..2c82075f7 100644 --- a/tools/supported/reveal.cpp +++ b/tools/supported/reveal.cpp @@ -43,9 +43,12 @@ int main (void) cout << "Pausing..." << endl; // horrible hack to make sure the pause is really set + // preblem here is that we could be 'arriving' at the wrong time and DF could be in the middle of a frame. + // that could mean that revealing, even with suspending DF's thread, would mean unleashing hell *in the same frame* + // this here hack sets the pause state, resumes DF, waits a second for it to enter the pause (I know, BS value.) and suspends. Gui->SetPauseState(true); DF->Resume(); - usleep(100); + sleep(1); DF->Suspend(); // init the map