int main () { DFHack::Process * p; unsigned int i; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; try { DF = DFMgr.getSingleContext(); DF->Attach(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } DFHack::VersionInfo * mem = DF->getMemoryInfo(); p = DF->getProcess(); uint32_t item_vec_offset = 0; try { item_vec_offset = p->getDescriptor()->getAddress ("items_vector"); } catch(DFHack::Error::AllMemdef & e) { cerr << "missing offset for the item vector, exiting :(" << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } DFHack::DfVector <uint32_t> p_items (p, item_vec_offset); uint32_t size = p_items.size(); int numtasked = 0; for (i=0;i<size;i++) { DFHack::t_itemflags flags; flags.whole = p->readDWord(p_items[i] + 0x0C); if (flags.bits.in_job) { flags.bits.in_job = 0; p->writeDWord(p_items[i] + 0x0C, flags.whole); numtasked++; } } cout << "Found and untasked " << numtasked << " items." << endl; #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); #endif return 0; }
int main (int numargs, const char ** args) { map<string, string> buildCommands; buildCommands["building_stockpilest"]=""; buildCommands["building_zonest"]=""; buildCommands["building_construction_blueprintst"]=""; buildCommands["building_wagonst"]=""; buildCommands["building_armor_standst"]="a"; buildCommands["building_bedst"]="b"; buildCommands["building_seatst"]="c"; buildCommands["building_burial_receptaclest"]="n"; buildCommands["building_doorst"]="d"; buildCommands["building_floodgatest"]="x"; buildCommands["building_floor_hatchst"]="H"; buildCommands["building_wall_gratest"]="W"; buildCommands["building_floor_gratest"]="G"; buildCommands["building_vertical_barsst"]="B"; buildCommands["building_floor_barsst"]="alt-b"; buildCommands["building_cabinetst"]="f"; buildCommands["building_containerst"]="h"; buildCommands["building_shopst"]=""; buildCommands["building_workshopst"]=""; buildCommands["building_alchemists_laboratoryst"]="wa"; buildCommands["building_carpenters_workshopst"]="wc"; buildCommands["building_farmers_workshopst"]="ww"; buildCommands["building_masons_workshopst"]="wm"; buildCommands["building_craftdwarfs_workshopst"]="wr"; buildCommands["building_jewelers_workshopst"]="wj"; buildCommands["building_metalsmiths_workshopst"]="wf"; buildCommands["building_magma_forgest"]=""; buildCommands["building_bowyers_workshopst"]="wb"; buildCommands["building_mechanics_workshopst"]="wt"; buildCommands["building_siege_workshopst"]="ws"; buildCommands["building_butchers_shopst"]="wU"; buildCommands["building_leather_worksst"]="we"; buildCommands["building_tanners_shopst"]="wn"; buildCommands["building_clothiers_shopst"]="wk"; buildCommands["building_fisheryst"]="wh"; buildCommands["building_stillst"]="wl"; buildCommands["building_loomst"]="wo"; buildCommands["building_quernst"]="wq"; buildCommands["building_kennelsst"]="k"; buildCommands["building_kitchenst"]="wz"; buildCommands["building_asheryst"]="wy"; buildCommands["building_dyers_shopst"]="wd"; buildCommands["building_millstonest"]="wM"; buildCommands["building_farm_plotst"]="p"; buildCommands["building_weapon_rackst"]="r"; buildCommands["building_statuest"]="s"; buildCommands["building_tablest"]="t"; buildCommands["building_paved_roadst"]="o"; buildCommands["building_bridgest"]="g"; buildCommands["building_wellst"]="l"; buildCommands["building_siege enginest"]="i"; buildCommands["building_catapultst"]="ic"; buildCommands["building_ballistast"]="ib"; buildCommands["building_furnacest"]=""; buildCommands["building_wood_furnacest"]="ew"; buildCommands["building_smelterst"]="es"; buildCommands["building_glass_furnacest"]="ek"; buildCommands["building_kilnst"]="ek"; buildCommands["building_magma_smelterst"]="es"; buildCommands["building_magma_glass_furnacest"]="ek"; buildCommands["building_magma_kilnst"]="ek"; buildCommands["building_glass_windowst"]="y"; buildCommands["building_gem_windowst"]="Y"; buildCommands["building_tradedepotst"]="D"; buildCommands["building_mechanismst"]=""; buildCommands["building_leverst"]="Tl"; buildCommands["building_pressure_platest"]="Tp"; buildCommands["building_cage_trapst"]="Tc"; buildCommands["building_stonefall_trapst"]="Ts"; buildCommands["building_weapon_trapst"]="Tw"; buildCommands["building_spikest"]=""; buildCommands["building_animal_trapst"]="m"; buildCommands["building_screw_pumpst"]="Ms"; buildCommands["building_water_wheelst"]="Mw"; buildCommands["building_windmillst"]="Mm"; buildCommands["building_gear_assemblyst"]="Mg"; buildCommands["building_horizontal_axlest"]="Mh"; buildCommands["building_vertical_axlest"]="Mv"; buildCommands["building_supportst"]="S"; buildCommands["building_cagest"]="j"; buildCommands["building_archery_targetst"]="A"; buildCommands["building_restraintst"]="v"; 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; } DFHack::Gui *Gui = DF->getGui(); DFHack::VersionInfo* mem = DF->getMemoryInfo(); DFHack::Process * p = DF->getProcess(); OffsetGroup * OG_Maps = mem->getGroup("Maps"); OffsetGroup * OG_MapBlock = OG_Maps->getGroup("block"); OffsetGroup * OG_LocalFt = OG_Maps->getGroup("features")->getGroup("local"); uint32_t designations = OG_MapBlock->getOffset("designation"); uint32_t block_feature1 = OG_MapBlock->getOffset("feature_local"); uint32_t block_feature2 = OG_MapBlock->getOffset("feature_global"); uint32_t region_x_offset = OG_Maps->getAddress("region_x"); uint32_t region_y_offset = OG_Maps->getAddress("region_y"); uint32_t region_z_offset = OG_Maps->getAddress("region_z"); uint32_t feature1_start_ptr = OG_LocalFt->getAddress("start_ptr"); int32_t regionX, regionY, regionZ; // read position of the region inside DF world p->readDWord (region_x_offset, (uint32_t &)regionX); p->readDWord (region_y_offset, (uint32_t &)regionY); p->readDWord (region_z_offset, (uint32_t &)regionZ); while(1){ int32_t cx1,cy1,cz1; cx1 = -30000; while(cx1 == -30000) { DF->ForceResume(); cout << "Set cursor at first position, then press any key"; cin.ignore(); DF->Suspend(); Gui->getCursorCoords(cx1,cy1,cz1); } uint32_t tx1,ty1,tz1; tx1 = cx1/16; ty1 = cy1/16; tz1 = cz1; int32_t cx2,cy2,cz2; cx2 = -30000; while(cx2 == -30000) { DF->Resume(); cout << "Set cursor at second position, then press any key"; cin.ignore(); DF->Suspend(); Gui->getCursorCoords(cx2,cy2,cz2); } uint32_t tx2,ty2,tz2; tx2 = cx2/16; ty2 = cy2/16; tz2 = cz2; sort(tx1,tx2); sort(ty1,ty2); sort(tz1,tz2); sort(cx1,cx2); sort(cy1,cy2); sort(cz1,cz2); vector <vector<vector<string> > >dig(cz2-cz1+1,vector<vector<string> >(cy2-cy1+1,vector<string>(cx2-cx1+1))); vector <vector<vector<string> > >build(cz2-cz1+1,vector<vector<string> >(cy2-cy1+1,vector<string>(cx2-cx1+1))); mapblock40d block; DFHack::Maps *Maps = DF->getMaps(); Maps->Start(); for(uint32_t y = ty1;y<=ty2;y++) { for(uint32_t x = tx1;x<=tx2;x++) { for(uint32_t z = tz1;z<=tz2;z++) { if(Maps->isValidBlock(x,y,z)) { if(Maps->ReadBlock40d(x,y,z,&block)) { int ystart,yend,xstart,xend; ystart=xstart=0; yend=xend=15; if(y == ty2) { yend = cy2 % 16; } if(y == ty1) { ystart = cy1 % 16; } if(x == tx2) { xend = cx2 % 16; } if(x == tx1) { xstart = cx1 % 16; } int zidx = z-tz1; for(int yy = ystart; yy <= yend;yy++) { int yidx = yy+(16*(y-ty1)-(cy1%16)); for(int xx = xstart; xx <= xend;xx++) { int xidx = xx+(16*(x-tx1)-(cx1%16)); int16_t tt = block.tiletypes[xx][yy]; DFHack::TileShape ts = DFHack::tileShape(tt); if(DFHack::isOpenTerrain(tt) || DFHack::isFloorTerrain(tt)) { dig[zidx][yidx][xidx] = "d"; } else if(DFHack::STAIR_DOWN == ts) { dig [zidx][yidx][xidx] = "j"; build [zidx][yidx][xidx] = "Cd"; } else if(DFHack::STAIR_UP == ts) { dig [zidx][yidx][xidx] = "u"; build [zidx][yidx][xidx] = "Cu"; } else if(DFHack::STAIR_UPDOWN == ts) { dig [zidx][yidx][xidx] = "i"; build [zidx][yidx][xidx] = "Cx"; } else if(DFHack::isRampTerrain(tt)) { dig [zidx][yidx][xidx] = "r"; build [zidx][yidx][xidx] = "Cr"; } else if(DFHack::isWallTerrain(tt)) { build [zidx][yidx][xidx] = "Cw"; } } yidx++; } } } } } } DFHack::Buildings * Bld = DF->getBuildings(); std::map <uint32_t, std::string> custom_workshop_types; uint32_t numBuildings; if(Bld->Start(numBuildings)) { Bld->ReadCustomWorkshopTypes(custom_workshop_types); for(uint32_t i = 0; i < numBuildings; i++) { DFHack::t_building temp; Bld->Read(i, temp); if(temp.type != 0xFFFFFFFF) // check if type isn't invalid { std::string typestr; mem->resolveClassIDToClassname(temp.type, typestr); if(temp.z == cz1 && cx1 <= temp.x1 && cx2 >= temp.x2 && cy1 <= temp.y1 && cy2 >= temp.y2) { string currStr = build[temp.z-cz1][temp.y1-cy1][temp.x1-cx1]; stringstream stream; string newStr = buildCommands[typestr]; if(temp.x1 != temp.x2) { stream << "(" << temp.x2-temp.x1+1 << "x" << temp.y2-temp.y1+1 << ")"; newStr += stream.str(); } build[temp.z-cz1][temp.y1-cy1][temp.x1-cx1] = newStr + currStr; } } } } // for testing purposes //ofstream outfile("test.txt"); // printVecOfVec(outfile, dig,'\t'); // outfile << endl; // printVecOfVec(outfile, build,'\t'); // outfile << endl; // outfile.close(); int32_t cx3,cy3,cz3,cx4,cy4,cz4; uint32_t tx3,ty3,tz3,tx4,ty4,tz4; char result; while(1){ cx3 = -30000; while(cx3 == -30000){ DF->Resume(); cout << "Set cursor at new position, then press any key:"; result = cin.get(); DF->Suspend(); Gui->getCursorCoords(cx3,cy3,cz3); } if(result == 'q'){ break; } cx4 = cx3+cx2-cx1; cy4 = cy3+cy2-cy1; cz4 = cz3+cz2-cz1; tx3=cx3/16; ty3=cy3/16; tz3=cz3; tx4=cx4/16; ty4=cy4/16; tz4=cz4; DFHack::WindowIO * Win = DF->getWindowIO(); designations40d designationBlock; for(uint32_t y = ty3;y<=ty4;y++) { for(uint32_t x = tx3;x<=tx4;x++) { for(uint32_t z = tz3;z<=tz4;z++) { Maps->Start(); Maps->ReadBlock40d(x,y,z,&block); Maps->ReadDesignations(x,y,z,&designationBlock); int ystart,yend,xstart,xend; ystart=xstart=0; yend=xend=15; if(y == ty4){ yend = cy4 % 16; } if(y == ty3){ ystart = cy3 % 16; } if(x == tx4){ xend = cx4 % 16; } if(x == tx3){ xstart = cx3 % 16; } int zidx = z-tz3; for(int yy = ystart; yy <= yend;yy++){ int yidx = yy+(16*(y-ty3)-(cy3%16)); for(int xx = xstart; xx <= xend;xx++){ int xidx = xx+(16*(x-tx3)-(cx3%16)); if(dig[zidx][yidx][xidx] != ""){ char test = dig[zidx][yidx][xidx].c_str()[0]; switch (test){ case 'd': designationBlock[xx][yy].bits.dig = DFHack::designation_default; break; case 'i': designationBlock[xx][yy].bits.dig = DFHack::designation_ud_stair; break; case 'u': designationBlock[xx][yy].bits.dig = DFHack::designation_u_stair; break; case 'j': designationBlock[xx][yy].bits.dig = DFHack::designation_d_stair; break; case 'r': designationBlock[xx][yy].bits.dig = DFHack::designation_ramp; break; } } } yidx++; } Maps->Start(); Maps->WriteDesignations(x,y,z,&designationBlock); } } } } } DF->Detach(); #ifndef LINUX_BUILD std::cout << "Done. Press any key to continue" << std::endl; cin.ignore(); #endif return 0; }
int main (void) { string select; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF = DFMgr.getSingleContext(); try { DF->Attach(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } DFHack::Process * p = DF->getProcess(); vector <DFHack::t_memrange> selected_ranges; getRanges(p,selected_ranges); DFHack::memory_info *minfo = DF->getMemoryInfo(); DFHack::memory_info::OSType os = minfo->getOS(); string prompt = "Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n" " 4=string, 5=automated offset search, 6=vector by address in its array,\n" " 7=pointer vector by address of an object, 8=vector>first object>string\n"; int mode; do { getNumber(prompt,mode, 1, false); } while (mode < 1 || mode > 8 ); switch (mode) { case 1: DF->Detach(); FindIntegers(DFMgr, selected_ranges); break; case 2: DF->Detach(); FindVectorByLength(DFMgr, selected_ranges); break; case 3: DF->Detach(); FindVectorByObjectRawname(DFMgr, selected_ranges); break; case 4: DF->Detach(); FindStrings(DFMgr, selected_ranges); break; case 5: automatedLangtables(DF,selected_ranges); break; case 6: DF->Detach(); FindVectorByBounds(DFMgr,selected_ranges); break; case 7: DF->Detach(); FindPtrVectorsByObjectAddress(DFMgr,selected_ranges); break; case 8: DF->Detach(); FindVectorByFirstObjectRawname(DFMgr, selected_ranges); break; default: cout << "not implemented :(" << endl; } #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); #endif return 0; }
main(int argc, char *argv[]) { /* initialize your non-curses data structures here */ signal(SIGINT, finish); /* arrange interrupts to terminate */ setlocale(LC_ALL,""); initscr(); /* initialize the curses library */ keypad(stdscr, TRUE); /* enable keyboard mapping */ nonl(); /* tell curses not to do NL->CR/NL on output */ cbreak(); /* take input chars one at a time, no wait for \n */ noecho(); /* don't echo input */ //nodelay(stdscr, true); int wxMax = getmaxx(stdscr); int wyMax = getmaxy(stdscr); keypad(stdscr, TRUE); scrollok(stdscr, TRUE); if (has_colors()) { start_color(); /* * Simple color assignment, often all we need. */ init_pair(COLOR_BLACK, COLOR_BLACK, COLOR_BLACK); init_pair(COLOR_GREEN, COLOR_GREEN, COLOR_BLACK); init_pair(COLOR_RED, COLOR_RED, COLOR_BLACK); init_pair(COLOR_BLUE, COLOR_BLUE, COLOR_BLACK); init_pair(COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK); init_color(COLOR_CYAN, 700, 700, 700); // lt grey init_color(COLOR_MAGENTA, 500, 500, 500); // dk grey init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); init_pair(COLOR_CYAN, COLOR_CYAN, COLOR_BLACK); init_pair(COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK); } int x_max,y_max,z_max; uint32_t x_max_a,y_max_a,z_max_a; /* uint16_t tiletypes[16][16]; DFHack::t_designation designations[16][16]; uint8_t regionoffsets[16]; */ map <int16_t, uint32_t> materials; materials.clear(); mapblock40d blocks[3][3]; vector<DFHack::t_effect_df40d> effects; vector< vector <uint16_t> > layerassign; vector<t_vein> veinVector; vector<t_frozenliquidvein> IceVeinVector; vector<t_spattervein> splatter; t_temperatures b_temp1; t_temperatures b_temp2; DFHack::Materials * Mats = 0; DFHack::Maps * Maps = 0; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context* DF; try { pDF = DF = DFMgr.getSingleContext(); DF->Attach(); Mats = DF->getMaterials(); Maps = DF->getMaps(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif finish(0); } Process* p = DF->getProcess(); // init the map if(!Maps->Start()) { error = "Can't find a map to look at."; finish(0); } Maps->getSize(x_max_a,y_max_a,z_max_a); x_max = x_max_a; y_max = y_max_a; z_max = z_max_a; // get stone matgloss mapping if(!Mats->ReadInorganicMaterials()) { error = "Can't read stone types."; pDF = 0; finish(0); } /* if(!Mats->ReadCreatureTypes()) { error = "Can't read stone types."; pDF = 0; finish(0); } */ /* // get region geology if(!DF.ReadGeology( layerassign )) { error = "Can't read local geology."; pDF = 0; finish(0); } */ // FIXME: could fail on small forts int cursorX = x_max/2 - 1; int cursorY = y_max/2 - 1; int cursorZ = z_max/2 - 1; bool dig = false; bool dump = false; bool digbit = false; bool dotwiddle; unsigned char twiddle = 0; int vein = 0; int filenum = 0; bool dirtybit = false; uint32_t blockaddr = 0; uint32_t blockaddr2 = 0; t_blockflags bflags; bflags.whole = 0; enum e_tempmode { TEMP_NO, TEMP_1, TEMP_2, WATER_SALT, WATER_STAGNANT }; e_tempmode temperature = TEMP_NO; // resume so we don't block DF while we wait for input DF->Resume(); for (;;) { dig = false; dump = false; dotwiddle = false; digbit = false; int c = getch(); /* refresh, accept single keystroke of input */ flushinp(); clrscr(); /* process the command keystroke */ switch(c) { case KEY_DOWN: cursorY ++; break; case KEY_UP: cursorY --; break; case KEY_LEFT: cursorX --; break; case KEY_RIGHT: cursorX ++; break; case KEY_NPAGE: cursorZ --; break; case KEY_PPAGE: cursorZ ++; break; case '+': vein ++; break; case 'd': dig = true; break; case 'o': dump = true; break; case '-': vein --; break; case 'z': digbit = true; break; case '/': if(twiddle != 0) twiddle--; break; case '*': twiddle++; break; case 't': dotwiddle = true; break; case 'b': temperature = TEMP_NO; break; case 'n': temperature = TEMP_1; break; case 'm': temperature = TEMP_2; break; case 'c': temperature = WATER_SALT; break; case 'v': temperature = WATER_STAGNANT; break; case 27: // escape key DF->Detach(); return 0; break; default: break; } cursorX = max(cursorX, 0); cursorY = max(cursorY, 0); cursorZ = max(cursorZ, 0); cursorX = min(cursorX, x_max - 1); cursorY = min(cursorY, y_max - 1); cursorZ = min(cursorZ, z_max - 1); if(twiddle > 31) twiddle = 31; // clear data before we suspend memset(blocks,0,sizeof(blocks)); veinVector.clear(); IceVeinVector.clear(); effects.clear(); splatter.clear(); dirtybit = 0; // Supend, read/write data DF->Suspend(); // restart cleared modules Maps->Start(); Mats->Start(); Mats->ReadInorganicMaterials(); Mats->ReadCreatureTypes(); uint32_t effectnum; /* if(DF.InitReadEffects(effectnum)) { for(uint32_t i = 0; i < effectnum;i++) { t_effect_df40d effect; DF.ReadEffect(i,effect); effects.push_back(effect); } } */ for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) { mapblock40d * Block = &blocks[i+1][j+1]; if(Maps->isValidBlock(cursorX+i,cursorY+j,cursorZ)) { Maps->ReadBlock40d(cursorX+i,cursorY+j,cursorZ, Block); // extra processing of the block in the middle if(i == 0 && j == 0) { do_features(DF, Block, cursorX, cursorY, 50,10, Mats->inorganic); // read veins Maps->ReadVeins(cursorX+i,cursorY+j,cursorZ,&veinVector,&IceVeinVector,&splatter); // get pointer to block blockaddr = Maps->getBlockPtr(cursorX+i,cursorY+j,cursorZ); blockaddr2 = Block->origin; // dig all veins and trees if(dig) { for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) { TileClass tc = tileTypeTable[Block->tiletypes[x][y]].c; TileMaterial tm = tileTypeTable[Block->tiletypes[x][y]].m; if( tc == WALL && tm == VEIN || tc == TREE_OK || tc == TREE_DEAD) { Block->designation[x][y].bits.dig = designation_default; } } Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation)); } // read temperature data Maps->ReadTemperatures(cursorX+i,cursorY+j,cursorZ,&b_temp1, &b_temp2 ); if(dotwiddle) { bitset<32> bs = Block->designation[0][0].whole; bs.flip(twiddle); Block->designation[0][0].whole = bs.to_ulong(); Maps->WriteDesignations(cursorX+i,cursorY+j,cursorZ, &(Block->designation)); dotwiddle = false; } // do a dump of the block data if(dump) { hexdump(DF,blockaddr,0x1E00,filenum); filenum++; } // read/write dirty bit of the block Maps->ReadDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit); Maps->ReadBlockFlags(cursorX+i,cursorY+j,cursorZ,bflags); if(digbit) { dirtybit = !dirtybit; Maps->WriteDirtyBit(cursorX+i,cursorY+j,cursorZ,dirtybit); } } } } // Resume, print stuff to the terminal DF->Resume(); for(int i = -1; i <= 1; i++) for(int j = -1; j <= 1; j++) { mapblock40d * Block = &blocks[i+1][j+1]; for(int x = 0; x < 16; x++) for(int y = 0; y < 16; y++) { int color = COLOR_BLACK; color = pickColor(Block->tiletypes[x][y]); /* if(!Block->designation[x][y].bits.hidden) { puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color); } else*/ { attron(A_STANDOUT); puttile(x+(i+1)*16,y+(j+1)*16,Block->tiletypes[x][y], color); attroff(A_STANDOUT); } } // print effects for the center tile /* if(i == 0 && j == 0) { for(uint zz = 0; zz < effects.size();zz++) { if(effects[zz].z == cursorZ && !effects[zz].isHidden) { // block coords to tile coords uint16_t x = effects[zz].x - (cursorX * 16); uint16_t y = effects[zz].y - (cursorY * 16); if(x < 16 && y < 16) { putch(x + 16,y + 16,'@',COLOR_WHITE); } } } } */ } gotoxy(50,0); cprintf("arrow keys, PGUP, PGDN = navigate"); gotoxy(50,1); cprintf("+,- = switch vein"); gotoxy(50,2); uint32_t mineralsize = veinVector.size(); uint32_t icesize = IceVeinVector.size(); uint32_t splattersize = splatter.size(); uint32_t totalVeinSize = mineralsize+ icesize + splattersize; if(vein == totalVeinSize) vein = totalVeinSize - 1; if(vein < -1) vein = -1; cprintf("X %d/%d, Y %d/%d, Z %d/%d. Vein %d of %d",cursorX+1,x_max,cursorY+1,y_max,cursorZ,z_max,vein+1,totalVeinSize); if(!veinVector.empty() || !IceVeinVector.empty() || !splatter.empty()) { if(vein != -1 && vein < totalVeinSize) { uint32_t realvein = 0; if(vein < mineralsize) { realvein = vein; //iterate through vein rows for(uint32_t j = 0;j<16;j++) { //iterate through the bits for (uint32_t k = 0; k< 16;k++) { /* if(tileTypeTable[blocks[1][1].tiletypes[k][j]].m != VEIN) continue; */ /* if(blocks[1][1].designation[k][j].bits.hidden) continue; */ // and the bit array with a one-bit mask, check if the bit is set bool set = !!(((1 << k) & veinVector[realvein].assignment[j]) >> k); if(set) { putch(k+16,j+16,'$',COLOR_RED); } } } gotoxy(50,3); cprintf("Mineral: %s",Mats->inorganic[veinVector[vein].type].id); } else if (vein < mineralsize + icesize) { realvein = vein - mineralsize; t_frozenliquidvein &frozen = IceVeinVector[realvein]; for(uint32_t i = 0;i<16;i++) { for (uint32_t j = 0; j< 16;j++) { int color = COLOR_BLACK; int tile = frozen.tiles[i][j]; color = pickColor(tile); attron(A_STANDOUT); puttile(i+16,j+16,tile, color); attroff(A_STANDOUT); } } gotoxy(50,3); cprintf("ICE"); } else { realvein = vein - mineralsize - icesize; t_spattervein &bloodmud = splatter[realvein]; for(uint32_t yyy = 0; yyy < 16; yyy++) { for(uint32_t xxx = 0; xxx < 16; xxx++) { uint8_t intensity = splatter[realvein].intensity[xxx][yyy]; if(intensity) { attron(A_STANDOUT); putch(xxx+16,yyy+16,'*', COLOR_RED); attroff(A_STANDOUT); } } } gotoxy(50,3); cprintf("Spatter: %s",PrintSplatterType(splatter[realvein].mat1,splatter[realvein].mat2,Mats->race).c_str()); } }
int main (int numargs, char ** args) { DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF = DFMgr.getSingleContext(); DFHack::Process * p; try { DF->Attach(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } p = DF->getProcess(); string check = ""; if(numargs == 2) check = args[1]; DFHack::Creatures * Creatures = DF->getCreatures(); Materials = DF->getMaterials(); DFHack::Translation * Tran = DF->getTranslation(); uint32_t numCreatures; if(!Creatures->Start(numCreatures)) { cerr << "Can't get creatures" << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } if(!numCreatures) { cerr << "No creatures to print" << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } mem = DF->getMemoryInfo(); if(!Materials->ReadInorganicMaterials()) { cerr << "Can't get the inorganics types." << endl; return 1; } if(!Materials->ReadCreatureTypesEx()) { cerr << "Can't get the creature types." << endl; return 1; } if(!Tran->Start()) { cerr << "Can't get name tables" << endl; return 1; } vector<uint32_t> addrs; //DF.InitViewAndCursor(); for(uint32_t i = 0; i < numCreatures; i++) { DFHack::t_creature temp; unsigned int current_job; unsigned int mat_start; unsigned int mat_end; unsigned int j,k; unsigned int matptr; Creatures->ReadCreature(i,temp); if(temp.mood>=0) { current_job = p->readDWord(temp.origin + 0x390); if(current_job == 0) continue; mat_start = p->readDWord(current_job + 0xa4 + 4*3); mat_end = p->readDWord(current_job + 0xa4 + 4*4); for(j=mat_start;j<mat_end;j+=4) { matptr = p->readDWord(j); for(k=0;k<4;k++) printf("%.4X ", p->readWord(matptr + k*2)); for(k=0;k<3;k++) printf("%.8X ", p->readDWord(matptr + k*4 + 0x8)); for(k=0;k<2;k++) printf("%.4X ", p->readWord(matptr + k*2 + 0x14)); for(k=0;k<3;k++) printf("%.8X ", p->readDWord(matptr + k*4 + 0x18)); for(k=0;k<4;k++) printf("%.2X ", p->readByte(matptr + k + 0x24)); for(k=0;k<6;k++) printf("%.8X ", p->readDWord(matptr + k*4 + 0x28)); for(k=0;k<4;k++) printf("%.2X ", p->readByte(matptr + k + 0x40)); for(k=0;k<9;k++) printf("%.8X ", p->readDWord(matptr + k*4 + 0x44)); printf(" [%p]\n", matptr); } } } Creatures->Finish(); DF->Detach(); return 0; }
int main ( int argc, char** argv ) { DFHack::memory_info *mem; DFHack::Process *proc; uint32_t creature_pregnancy_offset; //bool femaleonly = 0; bool showcreatures = 0; int maxpreg = 1000; // random start value, since its not required and im not sure how to set it to infinity list<string> s_creatures; // parse input, handle this nice and neat before we get to the connecting argstream as(argc,argv); as // >>option('f',"female",femaleonly,"Impregnate females only") >>option('s',"show",showcreatures,"Show creature list (read only)") >>parameter('m',"max",maxpreg,"The maximum limit of pregnancies ", false) >>values<string>(back_inserter(s_creatures), "any number of creatures") >>help(); // make the creature list unique s_creatures.unique(); if (!as.isOk()) { cout << as.errorLog(); return(0); } else if (as.helpRequested()) { cout<<as.usage()<<endl; return(1); } else if(showcreatures==1) { } else if (s_creatures.size() == 0 && showcreatures != 1) { cout << as.usage() << endl << "---------------------------------------" << endl; cout << "Creature list empty, assuming CATs" << endl; s_creatures.push_back("CAT"); } DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context *DF; try { DF = DFMgr.getSingleContext(); DF->Attach(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } proc = DF->getProcess(); mem = DF->getMemoryInfo(); DFHack::Materials *Mats = DF->getMaterials(); DFHack::Creatures *Cre = DF->getCreatures(); creature_pregnancy_offset = mem->getOffset("creature_pregnancy"); if(!Mats->ReadCreatureTypesEx()) { cerr << "Can't get the creature types." << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } uint32_t numCreatures; if(!Cre->Start(numCreatures)) { cerr << "Can't get creatures" << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } int totalcount=0; int totalchanged=0; string sextype; // shows all the creatures and returns. int maxlength = 0; map<string, vector <t_creature> > male_counts; map<string, vector <t_creature> > female_counts; // classify for(uint32_t i =0;i < numCreatures;i++) { DFHack::t_creature creature; Cre->ReadCreature(i,creature); DFHack::t_creaturetype & crt = Mats->raceEx[creature.race]; string castename = crt.castes[creature.sex].rawname; if(castename == "FEMALE") { female_counts[Mats->raceEx[creature.race].rawname].push_back(creature); male_counts[Mats->raceEx[creature.race].rawname].size(); } else // male, other, etc. { male_counts[Mats->raceEx[creature.race].rawname].push_back(creature); female_counts[Mats->raceEx[creature.race].rawname].size(); //auto initialize the females as well } } // print (optional) if (showcreatures == 1) { cout << "Type\t\tMale #\tFemale #" << endl; for(map<string, vector <t_creature> >::iterator it1 = male_counts.begin();it1!=male_counts.end();it1++) { cout << it1->first << "\t\t" << it1->second.size() << "\t" << female_counts[it1->first].size() << endl; } } // process for (list<string>::iterator it = s_creatures.begin(); it != s_creatures.end(); ++it) { std::string clinput = *it; std::transform(clinput.begin(), clinput.end(), clinput.begin(), ::toupper); vector <t_creature> &females = female_counts[clinput]; uint32_t sz_fem = females.size(); totalcount += sz_fem; for(uint32_t i = 0; i < sz_fem && totalchanged != maxpreg; i++) { t_creature & female = females[i]; uint32_t preg_timer = proc->readDWord(female.origin + creature_pregnancy_offset); if(preg_timer != 0) { proc->writeDWord(female.origin + creature_pregnancy_offset, rand() % 100 + 1); totalchanged++; } } } cout << totalchanged << " pregnancies accelerated. Total creatures checked: " << totalcount << "." << endl; Cre->Finish(); DF->Detach(); #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); #endif return 0; }
int main (int argc, char *argv[]) { bool print_refs = false; bool print_hex = false; bool print_acc = false; for(int i = 1; i < argc; i++) { char *arg = argv[i]; if (arg[0] != '-') continue; for (; *arg; arg++) { switch (arg[0]) { case 'r': print_refs = true; break; case 'x': print_hex = true; break; case 'a': print_acc = true; break; } } } DFHack::Process * p; DFHack::ContextManager DFMgr("Memory.xml"); DFHack::Context * DF; try { DF = DFMgr.getSingleContext(); DF->Attach(); } catch (exception& e) { cerr << e.what() << endl; #ifndef LINUX_BUILD cin.ignore(); #endif return 1; } DFHack::Materials * Materials = DF->getMaterials(); Materials->ReadAllMaterials(); DFHack::Gui * Gui = DF->getGui(); DFHack::Items * Items = DF->getItems(); Items->Start(); DFHack::VersionInfo * mem = DF->getMemoryInfo(); p = DF->getProcess(); int32_t x,y,z; Gui->getCursorCoords(x,y,z); std::vector<uint32_t> p_items; Items->readItemVector(p_items); uint32_t size = p_items.size(); // FIXME: tools should never be exposed to DFHack internals! DFHack::OffsetGroup* itemGroup = mem->getGroup("Items"); uint32_t ref_vector = itemGroup->getOffset("item_ref_vector"); for(size_t i = 0; i < size; i++) { DFHack::dfh_item itm; memset(&itm, 0, sizeof(DFHack::dfh_item)); Items->readItem(p_items[i],itm); if (x != -30000 && !(itm.base.x == x && itm.base.y == y && itm.base.z == z && itm.base.flags.on_ground && !itm.base.flags.in_chest && !itm.base.flags.in_inventory && !itm.base.flags.in_building)) continue; printf( "%5d: %08x %6d %08x (%d,%d,%d) #%08x [%d] *%d %s - %s\n", i, itm.origin, itm.id, itm.base.flags.whole, itm.base.x, itm.base.y, itm.base.z, itm.base.vtable, itm.wear_level, itm.quantity, Items->getItemClass(itm).c_str(), Items->getItemDescription(itm, Materials).c_str() ); if (print_hex) hexdump(DF,p_items[i],0x300); if (print_acc) cout << Items->dumpAccessors(itm) << endl; if (print_refs) { DFHack::DfVector<uint32_t> p_refs(p, itm.origin + ref_vector); for (size_t j = 0; j < p_refs.size(); j++) { uint32_t vptr = p->readDWord(p_refs[j]); uint32_t val = p->readDWord(p_refs[j]+4); printf("\t-> %d \t%s\n", int(val), p->readClassName(vptr).c_str()); } } } #ifndef LINUX_BUILD cout << "Done. Press any key to continue" << endl; cin.ignore(); #endif return 0; }