示例#1
0
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;
}
示例#2
0
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;
}
void DwarfClipboardPng::waitTillScreenPosition(cursorIdx check)
{
    DFHack::Position * p = DF->getPosition();
    DFHack::WindowIO * w = DF->getWindowIO();
    cursorIdx state;
    p->getViewCoords(state.x,state.y,state.z);
    while(state.x != check.x && state.y != check.y && state.z != check.z){
       DF->Resume();
       w->TypeSpecial(DFHack::WAIT,1,delay);
       p->getViewCoords(state.x,state.y,state.z);
    }
    w->TypeSpecial(DFHack::WAIT,1,delay);
}
void DwarfClipboardPng::waitTillDigMenuClear()
{
    DFHack::Position * Pos = DF->getPosition();
    DFHack::WindowIO * Win = DF->getWindowIO();

    int32_t screenWidth,screenHeight;
    Pos->getWindowSize(screenWidth,screenHeight);
    DFHack::t_screen *screen;
    screen = new DFHack::t_screen[screenWidth*screenHeight];
    Pos->getScreenTiles(screenWidth,screenHeight,screen);
    while(screen[3*screenWidth+50].symbol == 'M'){
        DF->Resume();
        Win->TypeSpecial(DFHack::WAIT,1,delay);
        DF->Resume();
        Pos->getScreenTiles(screenWidth,screenHeight,screen);
    }
}
QList<QImage> DwarfClipboardPng::getImagesForRange(QList<cursorIdx> range)
{
    QList<QImage> retImages;
    DFHack::Position * Pos = DF->getPosition();
    DFHack::WindowIO * Win = DF->getWindowIO();
    dfLocationIterator itr(range[0],range[1]);
    cursorIdx begin = itr.begin();
    cursorIdx end = itr.end();
    cursorIdx size;
    size.x = (end.x-begin.x)+1;
    size.y = (end.y-begin.y)+1;
    size.z = begin.z-end.z+1;
    cursorIdx oldCursor,oldPosition;
    START_READ
    Pos->getCursorCoords(oldCursor.x,oldCursor.y,oldCursor.z);
    Pos->getViewCoords(oldPosition.x,oldPosition.y,oldPosition.z);
    Pos->setCursorCoords(-30000,oldCursor.y,oldCursor.z);
    int32_t screenWidth,screenHeight;
    Pos->getWindowSize(screenWidth,screenHeight);
    int32_t effectiveWidth = screenWidth-2-55; // 55 is the width of the map and the menus
    int32_t effectiveHeight = screenHeight-2;

    DFHack::t_screen *screen;
    screen = new DFHack::t_screen[screenWidth*screenHeight];
    QString rawComplete = QString("%1,%2,%3|").arg(size.x).arg(size.y).arg(size.z);
    for(int zitr = 0;zitr < size.z;zitr++){
        QVector<QVector<QString> > rawNumbers(size.x,QVector<QString>(size.y));
        for(int xIdx = 0;xIdx < int(size.x/effectiveWidth)+1;xIdx++){
            for(int yIdx=0;yIdx < int(size.y/effectiveHeight)+1;yIdx++){
                Pos->setViewCoords(begin.x+xIdx*effectiveWidth,begin.y+yIdx*effectiveHeight,begin.z-zitr);
		END_READ
                Win->TypeSpecial(DFHack::WAIT,1,delay);
		START_READ
                Pos->getScreenTiles(screenWidth,screenHeight,screen);
		END_READ
                int ylim = effectiveHeight;
                int xlim = effectiveWidth;
                if(yIdx == int(size.y/effectiveHeight)){
                    ylim = size.y % effectiveHeight;
                }
                if(xIdx == int(size.x/effectiveWidth)){
                    xlim = size.x % effectiveWidth;
                }
                for(int yitr = 1;yitr < ylim+1;yitr++){
                    for(int xitr = 1;xitr < xlim+1;xitr++){
                        QString test = stringFromScreen(screen[yitr*screenWidth+xitr]);
                        rawNumbers[effectiveWidth*xIdx + xitr-1][effectiveHeight*yIdx + yitr-1] = test;
                    }
                }
            }
        }
        for(int yitr = 0;yitr < rawNumbers[0].size();yitr++){
            for(int xitr = 0;xitr < rawNumbers.size();xitr++){
                rawComplete.append(rawNumbers[xitr][yitr]);
            }
            rawComplete.append(':');
        }
        rawComplete.append("|");
    }
    START_READ
    Pos->setViewCoords(oldPosition.x,oldPosition.y,oldPosition.z);
    Pos->setCursorCoords(oldCursor.x,oldCursor.y,oldCursor.z);
    END_READ
    retImages = ImagesFromString(rawComplete); // this is a little weird, but it will be easier to only have to debug one way to get the images
    for(int itr = 0;itr<retImages.size();itr++){
        retImages[itr].setText("rawNumbers",rawComplete);
    }
    delete screen;
    return(retImages);
}