diff --git a/library/include/dfhack/modules/Materials.h b/library/include/dfhack/modules/Materials.h index c4c97a870..0b6284b56 100644 --- a/library/include/dfhack/modules/Materials.h +++ b/library/include/dfhack/modules/Materials.h @@ -34,21 +34,149 @@ distribution. #include "dfhack/Types.h" #include +#include namespace DFHack { - class DFContextShared; + struct t_syndrome + { + // it's lonely here... + }; + /// Research by Quietust + struct df_material + { + std::string Material_ID; + std::string IS_GEM_singular; + std::string IS_GEM_plural; + std::string STONE_NAME; + int16_t SPEC_HEAT; + int16_t HEATDAM_POINT; + int16_t COLDDAM_POINT; + int16_t IGNITE_POINT; + int16_t MELTING_POINT; + int16_t BOILING_POINT; + int16_t MAT_FIXED_TEMP; + //int16_t padding; // added by compiler automatically + int32_t SOLID_DENSITY; + int32_t LIQUID_DENSITY; + int32_t MOLAR_MASS; + int32_t STATE_COLOR_SOLID; // (color token index) + int32_t STATE_COLOR_LIQUID; // (color token index) + int32_t STATE_COLOR_GAS; // (color token index) + int32_t STATE_COLOR_POWDER; // (color token index) + int32_t STATE_COLOR_PASTE; // (color token index) + int32_t STATE_COLOR_PRESSED;// (color token index) + std::string STATE_NAME_SOLID; + std::string STATE_NAME_LIQUID; + std::string STATE_NAME_GAS; + std::string STATE_NAME_POWDER; + std::string STATE_NAME_PASTE; + std::string STATE_NAME_PRESSED; + std::string STATE_ADJ_SOLID; + std::string STATE_ADJ_LIQUID; + std::string STATE_ADJ_GAS; + std::string STATE_ADJ_POWDER; + std::string STATE_ADJ_PASTE; + std::string STATE_ADJ_PRESSED; + int32_t ABSORPTION; + int32_t BENDING_YIELD; + int32_t SHEAR_YIELD; + int32_t TORSION_YIELD; + int32_t IMPACT_YIELD; + int32_t TENSILE_YIELD; + int32_t COMPRESSIVE_YIELD; + int32_t BENDING_FRACTURE; + int32_t SHEAR_FRACTURE; + int32_t TORSION_FRACTURE; + int32_t IMPACT_FRACTURE; + int32_t TENSILE_FRACTURE; + int32_t COMPRESSIVE_FRACTURE; + int32_t BENDING_STRAIN_AT_YIELD; + int32_t SHEAR_STRAIN_AT_YIELD; + int32_t TORSION_STRAIN_AT_YIELD; + int32_t IMPACT_STRAIN_AT_YIELD; + int32_t TENSILE_STRAIN_AT_YIELD; + int32_t COMPRESSIVE_STRAIN_AT_YIELD; + int32_t MAX_EDGE; + int32_t MATERIAL_VALUE; + uint32_t * flagarray_properties; + uint32_t flagarray_properties_length; + int16_t EXTRACT_STORAGE;// (item type) + int16_t BUTCHER_SPECIAL_type;// (item type) + int16_t BUTCHER_SPECIAL_subtype;// (item subtype) + //int16_t padding; // added by compiler + std::string MEAT_NAME_1st_parm; // (adj) + std::string MEAT_NAME_2nd_parm; + std::string MEAT_NAME_3rd_parm; + std::string BLOCK_NAME_1st_parm; + std::string BLOCK_NAME_2nd_parm; + std::vector MATERIAL_REACTION_PRODUCT_1st_parm;// (e.g. TAN_MAT) + std::vector unknown1; + std::vector unknown2; + std::vector MATERIAL_REACTION_PRODUCT_2nd_parm;// (e.g. LOCAL_CREATURE_MAT) + std::vector MATERIAL_REACTION_PRODUCT_3rd_parm;// (e.g. LEATHER) + std::vector MATERIAL_REACTION_PRODUCT_4th_parm;// (if you used CREATURE_MAT or PLANT_MAT) + int16_t unknown3; + //int16_t padding; // added by compiler + int32_t unknown4; + std::string HARDENS_WITH_WATER_1st_parm;// (e.g. INORGANIC) + std::string HARDENS_WITH_WATER_2nd_parm;// (e.g. GYPSUM) + std::string HARDENS_WITH_WATER_3rd_parm;// (if you used CREATURE_MAT or PLANT_MAT) + std::vector REACTION_CLASS; + int16_t TILE; + int16_t BASIC_COLOR_foreground; + int16_t BASIC_COLOR_bright; + // what exactly ARE those colors? + int16_t BUILD_COLOR1; + int16_t BUILD_COLOR2; + int16_t BUILD_COLOR3; + // same... + int16_t TILE_COLOR1; + int16_t TILE_COLOR2; + int16_t TILE_COLOR3; + int16_t ITEM_SYMBOL; + int16_t POWDER_DYE; // (color token index) + int16_t TEMP_DIET_INFO;// (whatever it means) + std::vector SYNDROME; + int32_t SOAP_LEVEL; + std::string PREFIX; + // etc... + }; + /// Research by Quietust + struct df_inorganic_base + { + std::string Inorganic_ID; + void * inorganic_flags; + uint32_t inorganic_flags_length; + std::vector empty1; + std::vector METAL_ORE_matID; + std::vector METAL_ORE_prob; + std::vector empty2; + std::vector THREAD_METAL_matID; + std::vector THREAD_METAL_prob; + std::vector unknown_in_1; + std::vector empty3; + std::vector ENVIRONMENT_SPEC_matID; + std::vector ENVIRONMENT_SPEC_inclusion_type; + std::vector ENVIRONMENT_SPEC_prob; + std::vector ENVIRONMENT_location; + std::vector ENVIRONMENT_inclusion_type; + std::vector ENVIRONMENT_prob; + int32_t unknown_in_2; + }; + struct df_inorganic_material:public df_inorganic_base, public df_material {}; /** + * A copy of the game's material data. * \ingroup grp_materials */ class DFHACK_EXPORT t_matgloss { public: - char id[128]; //the id in the raws - uint8_t fore; // Annoyingly the offset for this differs between types + std::string id; // raw name + std::string name; // a sensible human-readable name + uint8_t fore; uint8_t back; uint8_t bright; - char name[128]; //this is the name displayed ingame int32_t value; // Material value uint16_t wall_tile; // Tile when a natural wall @@ -57,25 +185,28 @@ namespace DFHack public: t_matgloss(); }; - + /** + * A copy of the game's inorganic material data. + * \ingroup grp_materials + */ class DFHACK_EXPORT t_matglossInorganic : public t_matgloss { public: // Types of metals the ore will produce when smelted. Each number // is an index into the inorganic matglass vector. - std::vector* ore_types; + std::vector ore_types; // Percent chance that the ore will produce each type of metal // when smelted. - std::vector* ore_chances; + std::vector ore_chances; // Types of metals the ore will produce from strand extraction. // Each number is an index into the inorganic matglass vector. - std::vector* strand_types; + std::vector strand_types; // Percent chance that the ore will produce each type of metal // fram strand extraction. - std::vector* strand_chances; + std::vector strand_chances; public: t_matglossInorganic(); @@ -89,42 +220,42 @@ namespace DFHack */ struct t_descriptor_color { - char id[128]; // id in the raws + std::string id; + std::string name; float red; float green; float blue; - char name[128]; //displayed name }; /** * \ingroup grp_materials */ struct t_matglossPlant { - char id[128]; //the id in the raws - uint8_t fore; // Annoyingly the offset for this differs between types + std::string id; + std::string name; + uint8_t fore; uint8_t back; uint8_t bright; - char name[128]; //this is the name displayed ingame - char drink_name[128]; //the name this item becomes a drink - char food_name[128]; - char extract_name[128]; + std::string drink_name; + std::string food_name; + std::string extract_name; }; /** * \ingroup grp_materials */ struct t_bodypart { - char id[128]; - char category[128]; - char single[128]; - char plural[128]; + std::string id; + std::string category; + std::string singular; + std::string plural; }; /** * \ingroup grp_materials */ struct t_colormodifier { - char part[128]; + std::string part; std::vector colorlist; uint32_t startdate; /* in days */ uint32_t enddate; /* in days */ @@ -134,10 +265,10 @@ namespace DFHack */ struct t_creaturecaste { - char rawname[128]; - char singular[128]; - char plural[128]; - char adjective[128]; + std::string id; + std::string singular; + std::string plural; + std::string adjective; std::vector ColorModifier; std::vector bodypart; @@ -166,21 +297,21 @@ namespace DFHack */ struct t_matglossOther { - char rawname[128]; + std::string id; }; /** * \ingroup grp_materials */ struct t_creatureextract { - char rawname[128]; + std::string id; }; /** * \ingroup grp_materials */ struct t_creaturetype { - char rawname[128]; + std::string id; std::vector castes; std::vector extract; uint8_t tile_character; @@ -216,6 +347,7 @@ namespace DFHack ~Materials(); bool Finish(); + std::vector* df_inorganic; std::vector inorganic; std::vector organic; std::vector tree; diff --git a/library/include/dfhack/modules/Vermin.h b/library/include/dfhack/modules/Vermin.h index f5eaac583..5fa345df0 100644 --- a/library/include/dfhack/modules/Vermin.h +++ b/library/include/dfhack/modules/Vermin.h @@ -19,7 +19,7 @@ namespace DFHack struct t_spawnPoint { uint32_t origin; - uint16_t race; + int16_t race; uint16_t type; uint16_t x; uint16_t y; diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index d5072a792..978d12634 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -52,13 +52,12 @@ class Materials::Private public: Process * owner; OffsetGroup * OG_Materials; - uint32_t vector_inorganic; uint32_t vector_organic_all; uint32_t vector_organic_plants; uint32_t vector_organic_trees; uint32_t vector_races; uint32_t vector_other; - +/* class t_inorganic_extras { public: @@ -72,6 +71,7 @@ class Materials::Private }; t_inorganic_extras i_ex; + */ }; Materials::Materials() @@ -81,12 +81,13 @@ Materials::Materials() d->owner = c.p; OffsetGroup *OG_Materials = d->OG_Materials = c.vinfo->getGroup("Materials"); { - d->vector_inorganic = OG_Materials->getAddress("inorganics"); + df_inorganic = (vector *) OG_Materials->getAddress("inorganics"); d->vector_organic_all = OG_Materials->getAddress ("organics_all"); d->vector_organic_plants = OG_Materials->getAddress ("organics_plants"); d->vector_organic_trees = OG_Materials->getAddress ("organics_trees"); d->vector_races = OG_Materials->getAddress("creature_type_vector"); } + /* OffsetGroup *OG_Offsets = OG_Materials->getGroup("inorganic_extras"); { d->i_ex.offset_ore_types = OG_Offsets->getOffset("ore_types"); @@ -97,6 +98,7 @@ Materials::Materials() d->i_ex.offset_wall_tile = OG_Offsets->getOffset("wall_tile"); d->i_ex.offset_boulder_tile = OG_Offsets->getOffset("boulder_tile"); } + */ } Materials::~Materials() @@ -146,7 +148,6 @@ bool API::ReadInorganicMaterials (vector & inorganic) t_matgloss::t_matgloss() { - name[0] = 0; fore = 0; back = 0; bright = 0; @@ -155,17 +156,10 @@ t_matgloss::t_matgloss() wall_tile = 0; boulder_tile = 0; } - -t_matglossInorganic::t_matglossInorganic() -{ - ore_types = NULL; - ore_chances = NULL; - strand_types = NULL; - strand_chances = NULL; -} - +// FIXME: implement properly bool t_matglossInorganic::isOre() { + /* if (ore_chances != NULL && !ore_chances->empty()) { if ( (*ore_chances)[0] > 0) @@ -177,13 +171,13 @@ bool t_matglossInorganic::isOre() if ( (*strand_chances)[0] > 0) return true; } - +*/ return false; } - +// FIXME: implement properly bool t_matglossInorganic::isGem() { - return (wall_tile == 15 && boulder_tile == 7); + //return (wall_tile == 15 && boulder_tile == 7); } // good for now @@ -196,7 +190,8 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector & nam for (uint32_t i = 0; i < size;i++) { t_matgloss mat; - p->readSTLString (p_matgloss[i], mat.id, 128); + mat.id = *(std::string *)p_matgloss[i]; + //p->readSTLString (p_matgloss[i], mat.id, 128); names.push_back(mat); } return true; @@ -205,42 +200,26 @@ inline bool ReadNamesOnly(Process* p, uint32_t address, vector & nam bool Materials::ReadInorganicMaterials (void) { Process * p = d->owner; - DfVector p_matgloss (d->vector_inorganic); - uint32_t size = p_matgloss.size(); + uint32_t size = df_inorganic->size(); inorganic.clear(); inorganic.reserve (size); for (uint32_t i = 0; i < size;i++) { + df_inorganic_material * orig = df_inorganic->at(i); t_matglossInorganic mat; - - p->readSTLString (p_matgloss[i], mat.id, 128); + mat.id = orig->Inorganic_ID; + mat.name = orig->STONE_NAME; //p->readSTLString (p_matgloss[i] + mat_name, mat.name, 128); - uint32_t ptr = p_matgloss[i] + d->i_ex.offset_ore_types; - if ( *( (uint32_t*) ptr) != 0) - mat.ore_types = (std::vector*) ptr; - - ptr = p_matgloss[i] + d->i_ex.offset_ore_chances; - if ( *( (uint32_t*) ptr) != 0) - mat.ore_chances = (std::vector*) ptr; - - ptr = p_matgloss[i] + d->i_ex.offset_strand_types; - if ( *( (uint32_t*) ptr) != 0) - mat.strand_types = (std::vector*) ptr; - - ptr = p_matgloss[i] + d->i_ex.offset_strand_chances; - if ( *( (uint32_t*) ptr) != 0) - mat.strand_chances = (std::vector*) ptr; - - ptr = p_matgloss[i] + d->i_ex.offset_value; - mat.value = *( (int32_t*) ptr); - - ptr = p_matgloss[i] + d->i_ex.offset_wall_tile; - mat.wall_tile = *( (uint8_t*) ptr); - - ptr = p_matgloss[i] + d->i_ex.offset_boulder_tile; - mat.boulder_tile = *( (uint8_t*) ptr); - + mat.ore_types = orig->METAL_ORE_matID; + mat.ore_chances = orig->METAL_ORE_prob; + mat.strand_types = orig->THREAD_METAL_matID; + mat.strand_chances = orig->THREAD_METAL_prob; + mat.value = orig->MATERIAL_VALUE; + mat.wall_tile = orig->TILE; + mat.boulder_tile = orig->ITEM_SYMBOL; + mat.bright = orig->BASIC_COLOR_bright; + mat.fore = orig->BASIC_COLOR_foreground; inorganic.push_back(mat); } return true; @@ -272,17 +251,17 @@ bool Materials::ReadOthers(void) Process * p = d->owner; uint32_t matBase = d->OG_Materials->getAddress ("other"); uint32_t i = 0; - uint32_t ptr; + std::string * ptr; other.clear(); while(1) { t_matglossOther mat; - ptr = p->readDWord(matBase + i*4); + ptr = (std::string *) p->readDWord(matBase + i*4); if(ptr==0) break; - p->readSTLString(ptr, mat.rawname, sizeof(mat.rawname)); + mat.id = *ptr; other.push_back(mat); i++; } @@ -303,8 +282,8 @@ bool Materials::ReadDescriptorColors (void) for (uint32_t i = 0; i < size;i++) { t_descriptor_color col; - p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("rawname"), col.id, 128); - p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("name"), col.name, 128); + col.id = p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("rawname") ); + col.name = p->readSTLString (p_colors[i] + OG_Descriptors->getOffset ("name") ); col.red = p->readFloat( p_colors[i] + OG_Descriptors->getOffset ("color_r") ); col.green = p->readFloat( p_colors[i] + OG_Descriptors->getOffset ("color_v") ); col.blue = p->readFloat( p_colors[i] + OG_Descriptors->getOffset ("color_b") ); @@ -379,7 +358,7 @@ bool Materials::ReadCreatureTypesEx (void) // word tilecolor.fore : tile_color_offset, // word tilecolor.back : tile_color_offset + 2, // word tilecolor.bright : tile_color_offset + 4 - p->readSTLString (p_races[i], mat.rawname, sizeof(mat.rawname)); + mat.id = p->readSTLString (p_races[i]); mat.tile_character = p->readByte( p_races[i] + tile_offset ); mat.tilecolor.fore = p->readWord( p_races[i] + tile_color_offset ); mat.tilecolor.back = p->readWord( p_races[i] + tile_color_offset + 2 ); @@ -392,10 +371,10 @@ bool Materials::ReadCreatureTypesEx (void) /* caste name */ t_creaturecaste caste; uint32_t caste_start = p_castes[j]; - p->readSTLString (caste_start, caste.rawname, sizeof(caste.rawname)); - 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)); + caste.id = p->readSTLString (caste_start); + caste.singular = p->readSTLString (caste_start + sizeof_string); + caste.plural = p->readSTLString (caste_start + 2 * sizeof_string); + caste.adjective = p->readSTLString (caste_start + 3 * sizeof_string); //cout << "Caste " << caste.rawname << " " << caste.singular << ": 0x" << hex << caste_start << endl; if(have_advanced) { @@ -413,7 +392,7 @@ bool Materials::ReadCreatureTypesEx (void) for(uint32_t l = 0; l < sizecolorlist; l++) caste.ColorModifier[k].colorlist[l] = p_colorlist[l]; // color mod [color_modifier_part_offset] = string part - p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part)); + caste.ColorModifier[k].part = p->readSTLString( p_colormod[k] + color_modifier_part_offset); 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 ); } @@ -424,8 +403,8 @@ bool Materials::ReadCreatureTypesEx (void) 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)); + part.id = p->readSTLString (p_bodypart[k] + bodypart_id_offset); + part.category = p->readSTLString (p_bodypart[k] + bodypart_category_offset); caste.bodypart.push_back(part); } p->read(caste_start + caste_attributes_offset, sizeof(t_attrib) * NUM_CREAT_ATTRIBS, (uint8_t *)&caste.strength); @@ -440,7 +419,7 @@ bool Materials::ReadCreatureTypesEx (void) for(uint32_t j = 0; j < p_extract.size(); j++) { t_creatureextract extract; - p->readSTLString( p_extract[j], extract.rawname, sizeof(extract.rawname)); + extract.id = p->readSTLString( p_extract[j] ); mat.extract.push_back(extract); } raceEx.push_back(mat); @@ -487,14 +466,14 @@ std::string Materials::getDescription(const t_material & mat) return "any"; if(mat.subIndex>=this->raceEx.size()) return "stuff"; - return this->raceEx[mat.subIndex].rawname; + return this->raceEx[mat.subIndex].id; } else { if (mat.index==-1) - return std::string(this->other[mat.subIndex].rawname); + return std::string(this->other[mat.subIndex].id); else - return std::string(this->other[mat.subIndex].rawname) + " derivate"; + return std::string(this->other[mat.subIndex].id) + " derivate"; } } else @@ -511,9 +490,9 @@ std::string Materials::getDescription(const t_material & mat) typeC -=19; if ((typeC<0) || (typeC>=this->raceEx[mat.index].extract.size())) { - return string(this->raceEx[mat.index].rawname).append(" extract"); + return string(this->raceEx[mat.index].id).append(" extract"); } - return std::string(this->raceEx[mat.index].rawname).append(" ").append(this->raceEx[mat.index].extract[typeC].rawname); + return std::string(this->raceEx[mat.index].id).append(" ").append(this->raceEx[mat.index].extract[typeC].id); } } else diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index 635f344d3..f985fd95e 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -123,6 +123,7 @@ endif() DFHACK_PLUGIN(reveal reveal.cpp) DFHACK_PLUGIN(prospector prospector.cpp) +DFHACK_PLUGIN(rawdump rawdump.cpp) DFHACK_PLUGIN(cleanmap cleanmap.cpp) DFHACK_PLUGIN(weather weather.cpp) DFHACK_PLUGIN(vdig vdig.cpp) diff --git a/plugins/colonies.cpp b/plugins/colonies.cpp index bd5bfe839..6674e64a0 100644 --- a/plugins/colonies.cpp +++ b/plugins/colonies.cpp @@ -111,7 +111,7 @@ void convertColonies(DFHack::SpawnPoints *points, DFHack::Materials *Materials) { int bee_idx = -1; for (size_t i = 0; i < Materials->raceEx.size(); i++) - if (strcmp(Materials->raceEx[i].rawname, "HONEY_BEE") == 0) + if (Materials->raceEx[i].id == "HONEY_BEE") { bee_idx = i; break; @@ -152,8 +152,8 @@ void showColonies(Core *c, DFHack::SpawnPoints *points, { numColonies++; string race="(no race)"; - if (Materials->raceEx[sp.race].rawname[0]) - race = Materials->raceEx[sp.race].rawname; + if(sp.race != -1) + race = Materials->raceEx[sp.race].id; c->con.print("Spawn point %u: %s at %d:%d:%d\n", i, race.c_str(), sp.x, sp.y, sp.z); diff --git a/plugins/rawdump.cpp b/plugins/rawdump.cpp new file mode 100644 index 000000000..b1f6f4848 --- /dev/null +++ b/plugins/rawdump.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +using std::vector; +using std::string; +using namespace DFHack; +//FIXME: possible race conditions with calling kittens from the IO thread and shutdown from Core. +bool shutdown_flag = false; +bool final_flag = true; +bool timering = false; +uint64_t timeLast = 0; + +DFhackCExport command_result rawdump (Core * c, vector & parameters); + +DFhackCExport const char * plugin_name ( void ) +{ + return "rawdump"; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("rawdump","Dump them raws.",rawdump)); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +DFhackCExport command_result rawdump (Core * c, vector & parameters) +{ + int index = -1; + Console & con = c->con; + if(parameters.size()) + { + index = atoi(parameters[0].c_str()); + } + c->Suspend(); + Materials * mats = c->getMaterials(); + if(!mats->df_inorganic) + { + con.printerr("No inorganic materials :(\n"); + return CR_FAILURE; + } + if(index >= 0) + { + if( index < mats->df_inorganic->size()) + { + df_inorganic_material * mat = mats->df_inorganic->at(index); + // dump single material + con.print("%-3d : [%s] %s\n", + index, + mat->Inorganic_ID.c_str(), + mat->STATE_NAME_SOLID.c_str()); + con.print("MAX EDGE: %d\n",mat->MAX_EDGE); + } + else + { + con.printerr("Index out of range: %d of %d\n",index, mats->df_inorganic->size()); + } + } + else + { + // dump all materials + for(int i = 0; i < mats->df_inorganic->size();i++) + { + con.print("%-3d : %s\n",i,mats->df_inorganic->at(i)->Inorganic_ID.c_str()); + } + } + c->Resume(); + return CR_OK; +}