Example #1
0
def sellShip(proc, bossid):
    '''
    卖船
    '''
    
    bossid = int(bossid)
     
    
    if(not __isOpened(proc)):
        
        
        openDialog(proc, bossid, 0x53)
    
        while(True):
            if(not dolScript.isOnline(proc)):
                return
            
            if(__isOpened(proc)):
                print "Open finished!"
                break      
            print "Wait..."      
            time.sleep(0.2)
    
    para2 = __getSellPara(proc)
    
    
    cpara = (c_ubyte * PARASIZE)()
    ip = cast(cpara, POINTER(c_int))
    ip[0] = bossid
    ip[1] = para2
    ip[2] = 0x53
    
    time.sleep(4) #sleep for sell the correct ship, but it doesn't works....
    dountil(isNormal, [proc])
    execCmd(proc, area.sellShipCmd, cpara)
Example #2
0
def custom_safe(proc, num, keyNum = 8):
    num = int(num)
    keyNum = int(keyNum)
    assert num >= 1 and num <= 8
    
    if(not dolScript.isOnline(proc)):
        return
    
    hlper = helper.ProcessHelper()
    hwnd = hlper.getHwndByProc(proc)
    

    if(dolScript.isCustomOpen(proc)):
        Key("KeyClick", hwnd, win32con.VK_F9)
        
        time.sleep(2)
    
    ret = Key("KeyClick", hwnd, win32con.VK_ESCAPE)
    ret = Key("KeyClick", hwnd, win32con.VK_ESCAPE)
    
    dountil(isNormal, [proc])
    ret = Key("KeyClick", hwnd, 0x6F + keyNum)
    count = 0
    interval = 0.2
    timeWait = 4
    
    while(not dolScript.isCustomOpen(proc) and count < timeWait / float(interval)):
        print 'wait custom... %d' % (count)
        count +=1
        time.sleep(interval)
    time.sleep(0.5)
    print 'press key %d' % (0x6F + num)
    ret = Key("KeyClick", hwnd, 0x6F + num)
    dountil(isNormal, [proc])
Example #3
0
def gotoCity(proc, cityid, wayPointList):
    
    def isClose(x1, y1):
        x, y = dolScript.getSeaPos(proc)
        return dolLib.distance(x1, y1, x, y) <= 10
    
    print 'Go to City %x' % (cityid)

    for x1, y1 in wayPointList:
        x, y = dolScript.getSeaPos(proc)
        log('Going to %d, %d' % (x1, y1))
        log('My pos = %d, %d' % (x, y))
        while(dolLib.distance(x1, y1, x, y) > 5):
            log('---Going to %d, %d' % (x1, y1))
            dolLib.turnPos(proc, x1, y1)
            time.sleep(2)
            
            state = dolScript.getSailState(proc)
            if(state < 4):
                dolCall.sail(proc, 4)
                time.sleep(2)
            
            if(not isClose(x1, y1) and not dolScript.isSceneChange(proc) and not dolScript.isAutoSail(proc) and dolScript.getHP(proc) >= 10):
                dolCall.custom_safe(proc, 1)
                time.sleep(2)
                
            sCount, sList = dolScript.getSkill(proc) 
    
            if(not isClose(x1, y1) and not dolScript.isSceneChange(proc) and sCount != 3 and 75 not in sList): #75 == 警戒
                log("发动警戒技能") 
                dolCall.custom_safe(proc, 3)#f3 警戒
                time.sleep(2)
            
            
            
            if(not isClose(x1, y1) and dolScript.getHPRatio(proc) < 0.4):
                if(not dolScript.isOnline(proc)):
                    break
                    
                hp1 = dolScript.getHP(proc)
                log("要补行动力, 行动力 = %d" % (hp1))
                dountil(dolScript.isNormal, [proc])
                
                dolCall.custom_safe(proc, 7) #f7 要设置为料理
                time.sleep(2)
                hp2 = dolScript.getHP(proc)
                log("吃了一个料理, 行动力 = %d" % (hp2))
                if(hp1 == hp2):
                    time.sleep(5)
                time.sleep(0.2)
            x, y = dolScript.getSeaPos(proc)
            print "Now in (%d, %d), distance to (%d, %d) is %d" % (x,y, x1, y1, dolLib.distance(x1, y1, x, y))
    dolCall.sail(proc, 0)
    dolCall.enterDoor(proc, cityid)
            
        
    
Example #4
0
def execCmd(proc, cmdList, cPara):
    #===========================================================================
    # if(not isinstance(clean, bool)):
    #    print 'invalid parameter'
    #    return
    #===========================================================================
    #print "cmd, para = %d, %d" % (cmdBuf, paraBuf)
    
    if(not dolScript.isOnline(proc)):
        print 'disconnected when execCmd()'
        raise dolScript.UnrecoverableException('disconnected')
    
    size = len(cmdList)
    
    #assert len(cmdList) == size
    cmd = (c_ubyte * size)()
    
    for i in range(size):
        cmd[i] = cmdList[i]
    
    cmdGuard = MemGuard(proc, size)
    cmdGuard.write(cmd)
    cmdBuf = cmdGuard.buf
    
    paraGuard = MemGuard(proc, sizeof(cPara))
    paraGuard.write(cPara)

    paraBuf = paraGuard.buf
    
    tHandle, tid = win32process.CreateRemoteThread(proc.handle, None, 0, cmdBuf, paraBuf, 0)
    print "Success! ThreadHandle, ThreadID = %d,%d" %( tHandle, tid)
    
    
    
    
    ret = win32event.WaitForSingleObject(tHandle, win32event.INFINITE)
    if(ret != win32event.WAIT_OBJECT_0):
        print 'Result of waitforSingleObject = %d' % (ret)
        raise MemException('WaitForSingleObject fail')
    ret = win32api.CloseHandle(tHandle)
    if(ret == 0):
        print 'Last error = %d' % (win32api.GetLastError())
        raise MemException("Close handle failed!")
Example #5
0
def walk(proc, x, y, diff = 200):
    print 'walk'
    x = float(x)
    y = float(y)
    
    def distance(x1, y1, x, y):
        return ((x1 - x) ** 2 + (y1 - y) ** 2) ** 0.5
    
    nowx, nowy = dolScript.getLandPos(proc)
    
    if(distance(x, y, nowx, nowy) <= diff):
        print 'close enough. No Walk'
        return
    
    flagRun = False
        
    
        
    #=======================================================================
    # for i in range(24):
    #    print "para = %x" % (cpara[i])
    #=======================================================================
        
    
    
    
    while(distance(x, y, nowx, nowy) > diff):
        print 'is Online = %s' % (dolScript.isOnline(proc))
        flagRun = True
        
        #dountil(isNormal, [proc])
        walkonce(proc, x, y)
        
        time.sleep(0.2)
        nowx, nowy = dolScript.getLandPos(proc)
        print 'pos diff = %.3f' % (distance(x, y, nowx, nowy))
Example #6
0
 def read(self, hwnd, proc, isFellow = False):
     print 'read'
     myname = dolScript.getRoleName(proc)
     print '[%s](%d) start to read. (isFellow = %s)' % (myname, hwnd, isFellow)
     statusAddr = 0xAFD700
     
     def __markOK(_hwnd):
         procGuard = helper.ProcGuard(_hwnd)
         dolCall.writeMem(procGuard.proc, statusAddr, dolCall.c_uint(0))
     
     def __whenRead():
         log('讀到圖')
         bossid = dolScript.getPCID(proc)
         dolCall.openDialog(proc, bossid, 0x20)
         myname = dolScript.getRoleName(proc)
         dountil(dolScript.isDialogOpen, [proc])
         
         l = MutexGuard(msgBoxMutex)
         msgBox(myname, '读到图。准备弹出窗口……')
         
         win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
         win32gui.SetActiveWindow(hwnd)
         
         win32gui.SetForegroundWindow(hwnd)
         msgBox(myname, '请在摆好露天后点击确定。(将会有购买窗口弹出……)')
         dowhile(dolScript.isDialogOpen, [proc])
         win32gui.ShowWindow(hwnd, win32con.SW_MINIMIZE)
         
         
         tarhwnd = self.serHwnd
         
         self.makeBuy(tarhwnd, hwnd)
         print 'one read loop end'
     
     x, y = self.cityRead.toReadPos
     if(dolScript.getLandFollow(proc) == 0):
         dolCall.walk(proc, x, y)
     
     if(not isFellow):
         for _hwnd in self.fellowList:
             __markOK(_hwnd)
         self.makeAllDo(self.read, [True], hwndPos = 0, procPos = 1)
         self.nextDoFunc = self.lib2Dock
         
         self.nextDoPara = []
     
     
     
     
     while(True):
         while(not dolScript.isDialogOpen(proc)):
             dolCall.openDialog(proc, self.cityRead.manID, 0x83)
             time.sleep(0.5)
         dountil(dolScript.isDialogOpen, [proc])
         
         while(dolScript.getToRead(proc) != 5): #5是美术
             print '[%s](%d) press left arrow' % (myname, hwnd)
             dll.Key('KeyClick', hwnd, win32con.VK_LEFT)
             time.sleep(1)
         
         print 'Click begin'
         print "-------%s %s-------" % (dolScript.getInt(proc, dolCall.CALLADDR.DIALOG) != 0, not dolScript.isReading(proc))
         while(dolScript.getInt(proc, dolCall.CALLADDR.DIALOG) != 0 and not dolScript.isReading(proc)):
             print "%s %s" % (dolScript.getInt(proc, dolCall.CALLADDR.DIALOG) != 0, not dolScript.isReading(proc))
             
             dll.Mouse('LClick', hwnd, 547, 240)
             time.sleep(2)
         print 'Click end'
             
         #547, 240
         
         while(True):
             print '[' + myname + ('] reading... (Money = %d)' % (dolScript.getMoney(proc)))
             if(dolScript.inLog(proc, '頭腦疲勞', 3)):
                 log('疲勞了...')
                 startTime = time.time()
                 if(isFellow):
                     procGuard = helper.ProcGuard(hwnd)
                     print '[%s] 疲劳了, 写内存' % (myname)
                     dolCall.writeMem(procGuard.proc, statusAddr, dolCall.c_uint(1))
                 else:
                     okFellowDict = {}
                     if(len(self.fellowList) > 0):
                         while(True):
                             if(len(okFellowDict) == len(self.fellowList)):
                                 #timeout一分钟也走人
                                 log('全部疲倦了,走人')
                                 return
                             
                             for _hwnd in self.fellowList:
                                 if(okFellowDict.has_key(_hwnd)):
                                     continue
                                 procGuard = helper.ProcGuard(_hwnd)
                                 if(not dolScript.isOnline(procGuard.proc)):
                                     okFellowDict[_hwnd] = -1
                                 
                                 
                                 if(dolScript.getInt(procGuard.proc, statusAddr) != 0):
                                     okFellowDict[_hwnd] = 1
                             time.sleep(0.5) 
                 
                 return
             
             
             if(dolScript.inLog(proc, self.readMsg, 3)):
                 __whenRead()
                 break
                 
             time.sleep(0.2)