本文整理汇总了C++中dfhack::Context::Detach方法的典型用法代码示例。如果您正苦于以下问题:C++ Context::Detach方法的具体用法?C++ Context::Detach怎么用?C++ Context::Detach使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dfhack::Context
的用法示例。
在下文中一共展示了Context::Detach方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max = 0, y_max = 0, z_max = 0;
DFHack::ContextManager manager("Memory.xml");
DFHack::Context *context = manager.getSingleContext();
if (!context->Attach())
{
std::cerr << "Unable to attach to DF!" << std::endl;
if(temporary_terminal)
std::cin.ignore();
return 1;
}
DFHack::Maps *maps = context->getMaps();
if (!maps->Start())
{
std::cerr << "Cannot get map info!" << std::endl;
context->Detach();
if(temporary_terminal)
std::cin.ignore();
return 1;
}
maps->getSize(x_max, y_max, z_max);
MapExtras::MapCache map(maps);
for(uint32_t z = 0; z < z_max; z++)
{
for(uint32_t b_y = 0; b_y < y_max; b_y++)
{
for(uint32_t b_x = 0; b_x < x_max; b_x++)
{
// Get the map block
DFHack::DFCoord blockCoord(b_x, b_y);
MapExtras::Block *b = map.BlockAt(DFHack::DFCoord(b_x, b_y, z));
if (!b || !b->valid)
{
continue;
}
DFHack::t_blockflags flags = b->BlockFlags();
flags.whole = flags.whole ^ 0xFFFFFFFF;
b->setBlockFlags(flags);
b->Write();
} // block x
} // block y
} // z
maps->Finish();
context->Detach();
return 0;
}
示例2: main
int main (int argc, char** argv)
{
bool quiet = false;
for(int i = 1; i < argc; i++)
{
string test = argv[i];
if(test == "-q")
{
quiet = true;
}
}
DFHack::Position * Position = 0;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
try
{
DF = DFMgr.getSingleContext();
DF->Attach();
Position = DF->getPosition();
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
if (Position)
{
int32_t x,y,z;
int32_t width,height;
if(Position->getViewCoords(x,y,z))
cout << "view coords: " << x << "/" << y << "/" << z << endl;
if(Position->getCursorCoords(x,y,z))
cout << "cursor coords: " << x << "/" << y << "/" << z << endl;
if(Position->getWindowSize(width,height))
cout << "window size : " << width << " " << height << endl;
}
else
{
cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
}
if(!DF->Detach())
{
cerr << "Can't detach from DF" << endl;
}
#ifndef LINUX_BUILD
if(!quiet)
{
cout << "Done. Press any key to continue" << endl;
cin.ignore();
}
#endif
return 0;
}
示例3: main
int main (void)
{
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::memory_info * mem = DF->getMemoryInfo();
DFHack::Position * Pos = DF->getPosition();
// get stone matgloss mapping
/*
uint32_t numNotes;
if(!DF.InitReadNotes(numNotes))
{
cerr << "Can't get notes" << endl;
return 1;
}
*/
/*
cout << "Notes" << endl;
for(uint32_t i = 0; i < numNotes; i++)
{
DFHack::t_note temp;
DF.ReadNote(i,temp);
cout << "x: " << temp.x << "\ty: " << temp.y << "\tz: " << temp.z <<
"\tsymbol: " << temp.symbol << "\tfg: " << temp.foreground << "\tbg: " << temp.background <<
"\ttext: " << temp.name << endl;
}
*/
cout << "Hotkeys" << endl;
DFHack::t_hotkey hotkeys[NUM_HOTKEYS];
Pos->ReadHotkeys(hotkeys);
for(uint32_t i =0;i< NUM_HOTKEYS;i++)
{
cout << "x: " << hotkeys[i].x << "\ty: " << hotkeys[i].y << "\tz: " << hotkeys[i].z <<
"\ttext: " << hotkeys[i].name << endl;
}
//DF.FinishReadNotes();
DF->Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}
示例4: sf
/*
{
vector <uint64_t> found;
Bytestream select;
while (Incremental(found,"byte stream",select,"byte stream","byte streams"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Incremental< Bytestream ,uint32_t>(select,1,found, findBytestream);
DF->Detach();
}
}
*/
void DataPtrTrace(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
int element_size;
do
{
getNumber("Set search granularity",element_size, 4);
} while (element_size < 1);
vector <uint64_t> found;
set <uint64_t> check; // to detect circles
uint32_t select;
Bytestream bs_select;
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
DFMgr.Refresh();
found.clear();
SegmentedFinder sf(ranges,DF);
while(found.empty())
{
Incremental(found,"byte stream",bs_select,"byte stream","byte streams");
sf.Incremental< Bytestream ,uint32_t>(bs_select,1,found, findBytestream);
}
select = found[0];
cout <<"Starting: 0x" << hex << select << endl;
while(sf.getSegmentForAddress(select))
{
sf.Incremental<uint32_t,uint32_t>(select,element_size,found, equalityP<uint32_t>);
if(found.empty())
{
cout << ".";
cout.flush();
select -=element_size;
continue;
}
cout << endl;
cout <<"Object start: 0x" << hex << select << endl;
cout <<"Pointer: 0x" << hex << found[0] << endl;
// make sure we don't go in circles'
if(check.count(select))
{
break;
}
check.insert(select);
// ascend
select = found[0];
found.clear();
}
DF->Detach();
}
示例5: main
int main(int argc, char** argv) {
if(argc < 2) {
::std::cout << "gimme a file!" << ::std::endl;
return 1;
}
::std::ifstream map_in(argv[1]);
::std::vector< ::std::string > dig_map;
while (map_in.good() && !map_in.eof() && !map_in.bad()) {
::std::string line;
map_in >> line;
dig_map.push_back(line);
}
dig_map.resize(dig_map.size() - 1);
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
::std::cin.ignore();
#endif
return 1;
}
DFHack::Maps *layers = DF->getMaps();
if (layers && layers->Start()) {
dig(layers, DF->getGui(), dig_map, true);
::std::cout << "Finished digging" << ::std::endl;
layers->Finish();
if (!DF->Detach()) {
::std::cerr << "Unable to detach DF process" << ::std::endl;
}
} else {
::std::cerr << "Unable to init map" << ::std::endl;
}
#ifndef LINUX_BUILD
::std::cout << "Done. Press any key to continue" << ::std::endl;
::std::cin.ignore();
#endif
return 0;
}
示例6: FindStrings
void FindStrings(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
vector <uint64_t> found;
string select;
while (Incremental(found,"string",select,"string","strings"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Incremental< const char * ,uint32_t>(select.c_str(),1,found, findString);
DF->Detach();
}
}
示例7: FindData
void FindData(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
vector <uint64_t> found;
Bytestream select;
while (Incremental(found,"byte stream",select,"byte stream","byte streams"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Incremental< Bytestream ,uint32_t>(select,1,found, findBytestream);
DF->Detach();
}
}
示例8: FindPtrVectorsByObjectAddress
void FindPtrVectorsByObjectAddress(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
vector <uint64_t> found;
uint32_t select;
while (Incremental(found, "object address",select,"vector","vectors"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Find<int ,vecTriplet>(0,4,found, vectorAll);
sf.Filter<uint32_t ,vecTriplet>(select,found, vectorOfPtrWithin);
DF->Detach();
}
}
示例9: FindVectorByFirstObjectRawname
void FindVectorByFirstObjectRawname(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
vector <uint64_t> found;
string select;
while (Incremental(found, "raw name",select,"vector","vectors"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Find<int ,vecTriplet>(0,4,found, vectorAll);
sf.Filter<const char * ,vecTriplet>(select.c_str(),found, vectorStringFirst);
DF->Detach();
}
}
示例10: main
int main (void)
{
string blah;
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;
}
cout << "Attached, DF should be suspended now" << endl;
getline(cin, blah);
DF->Resume();
cout << "Resumed, DF should be running" << endl;
getline(cin, blah);
DF->Suspend();
cout << "Suspended, DF should be suspended now" << endl;
getline(cin, blah);
DF->Resume();
cout << "Resumed, testing ForceResume. Suspend using SysInternals Process Explorer" << endl;
getline(cin, blah);
DF->ForceResume();
cout << "ForceResumed. DF should be running." << endl;
getline(cin, blah);
if(!DF->Detach())
{
cerr << "Can't detach from DF" << endl;
return 1;
}
cout << "Detached, DF should be running again" << endl;
getline(cin, blah);
return 0;
}
示例11: FindVectorByBounds
void FindVectorByBounds(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
vector <uint64_t> found;
uint32_t select;
while (Incremental(found, "address between vector.start and vector.end",select,"vector","vectors"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Find<int ,vecTriplet>(0,4,found, vectorAll);
sf.Filter<uint32_t ,vecTriplet>(select,found, vectorAddrWithin);
// sort by size of vector
std::sort(found.begin(), found.end(), VectorSizeFunctor(sf));
DF->Detach();
}
}
示例12: FindVectorByLength
void FindVectorByLength(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges )
{
int element_size;
do
{
getNumber("Select searched vector item size in bytes",element_size, 4);
} while (element_size < 1);
uint32_t length;
vector <uint64_t> found;
found.reserve(100);
while (Incremental(found, "vector length",length,"vector","vectors"))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
sf.Incremental<int ,vecTriplet>(0,4,found,vectorAll);
sf.Filter<uint32_t,vecTriplet>(length * element_size,found,vectorLength<uint32_t>);
DF->Detach();
}
}
示例13: FindIntegers
void FindIntegers(DFHack::ContextManager & DFMgr, vector <DFHack::t_memrange>& ranges)
{
// input / validation of variable size
int size;
do
{
getNumber("Select variable size (1,2,4 bytes)",size, 4);
} while (size != 1 && size != 2 && size != 4);
// input / validation of variable alignment (default is to use the same alignment as size)
int alignment;
do
{
getNumber("Select variable alignment (1,2,4 bytes)",alignment, size);
} while (alignment != 1 && alignment != 2 && alignment != 4);
uint32_t test1;
vector <uint64_t> found;
found.reserve(100);
while(Incremental(found, "integer",test1))
{
DFMgr.Refresh();
DFHack::Context * DF = DFMgr.getSingleContext();
DF->Attach();
SegmentedFinder sf(ranges,DF);
switch(size)
{
case 1:
sf.Incremental<uint8_t,uint8_t>(test1,alignment,found, equalityP<uint8_t>);
break;
case 2:
sf.Incremental<uint16_t,uint16_t>(test1,alignment,found, equalityP<uint16_t>);
break;
case 4:
sf.Incremental<uint32_t,uint32_t>(test1,alignment,found, equalityP<uint32_t>);
break;
}
DF->Detach();
}
}
示例14: main
//.........这里部分代码省略.........
//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;
}
示例15: main
int main (void)
{
bool temporary_terminal = TemporaryTerminal();
uint32_t x_max,y_max,z_max;
DFHack::designations40d designations;
DFHack::tiletypes40d tiles;
int32_t oldT, newT;
uint64_t count = 0;
int dirty=0;
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context *DF = DFMgr.getSingleContext();
//Init
try
{
DF->Attach();
}
catch (exception& e)
{
cerr << e.what() << endl;
if(temporary_terminal)
cin.ignore();
return 1;
}
DFHack::Maps *Mapz = DF->getMaps();
// init the map
if (!Mapz->Start())
{
cerr << "Can't init map." << endl;
if(temporary_terminal)
cin.ignore();
return 1;
}
Mapz->getSize(x_max,y_max,z_max);
if(!Mapz->StartFeatures())
{
cerr << "Can't get features." << endl;
if(temporary_terminal)
cin.ignore();
return 1;
}
// walk the map
for (uint32_t x = 0; x< x_max;x++)
{
for (uint32_t y = 0; y< y_max;y++)
{
for (uint32_t z = 0; z< z_max;z++)
{
DFHack::t_feature * locf = 0;
DFHack::t_feature * glof = 0;
if (Mapz->ReadFeatures(x,y,z,&locf,&glof))
{
// we're looking for addy tubes
if(!locf) continue;
if(locf->type != DFHack::feature_Adamantine_Tube) continue;
dirty=0;
Mapz->ReadDesignations(x,y,z, &designations);
Mapz->ReadTileTypes(x,y,z, &tiles);
for (uint32_t ty=0;ty<16;++ty)
{
for (uint32_t tx=0;tx<16;++tx)
{
if(!designations[tx][ty].bits.feature_local) continue;
oldT = tiles[tx][ty];
if ( DFHack::tileShape(oldT) != DFHack::WALL )
{
//Current tile is not a wall.
//Set current tile, as accurately as can be expected
//newT = DFHack::findSimilarTileType(oldT,DFHack::WALL);
newT = DFHack::findTileType( DFHack::WALL, DFHack::FEATSTONE, DFHack::tilevariant_invalid, DFHack::TILE_NORMAL, DFHack::TileDirection() );
//If no change, skip it (couldn't find a good tile type)
if ( oldT == newT) continue;
//Set new tile type, clear designation
tiles[tx][ty] = newT;
dirty=1;
++count;
}
}
}
//If anything was changed, write it all.
if (dirty)
{
Mapz->WriteTileTypes(x,y,z, &tiles);
}
}
}
}
}
DF->Detach();
cout << "Found and changed " << count << " tiles." << endl;
if(temporary_terminal)
//.........这里部分代码省略.........