Advertisement
alien_fx_fiend

Rise of Kingdom AHK Bot

Apr 18th, 2019
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv
  2. #SingleInstance Force
  3. #Persistent
  4. #Include FindText.ahk
  5.  
  6. CoordMode, Mouse
  7.  
  8. searchRSS:="|<>*160$23.zU3zy01zs01zVn1y7bXwTDXsyT7XzyD0T0C0K0QTzlwzzXsyz7"
  9. farmerbusy:="|<farmerbusy>*120$22.szzz000s203bw0CT00tw03as0CNk0tX03U00C000s0QHU0tD01ww03nk0DD03ww0Dnk00Tzzzzzzzzzzy"
  10. insideCastle:="|<insideCastle>*142$29.0k0001s007zk00DzU00Tz000xy0w1lw3w3Xs7s77kDkCDUTUQT0z0sy1y1lw3w3zs007zk00DzU00Ty000Tk000zU001z0003y0000Q0000M0001k000zzzzz"
  11. outsideCastle:="|<outsideCastle>*140$29.3m3w4Ta1k8zA00lyQ01Xws077ks0CA0k0s0Zk1UDjU7FzTUTbyzUzDxz3yTvzDwzbzztw3zzl20yy0SsBU7xy0STvzXwzrzjtzjzTnyTyzbU7xz401vs000G1"
  12. cropland:="|<cropland>*122$71.z0000MnlHDw1zU020073aTs3zU0snkS6DzU7zU7rDXkCTy0Dz0TYDz0wzw0TzDyOzy1nzU1zwDxzzw3by03zs7vXsn7zw0DzkTy3VyTzs2zzkxzy2Mzzs0yTrVzl9Vzy6FsTw0zYHLzsMzkTk0y0DzzkVzU103wcsTwVbvE00DvnkztXzq00Qzjjzzk4zi00BzQLzzk0zQ008woDzzwTzs00Dvxzzrxzvw00zrzzzzqzrs03zyDzxz7zTc0DzsDzvzTyzk0DxyzzrzzxzE07yzzwDzzryU07zzzszXzj"
  13. loggingcamp:="|<loggingcamp>*132$71.vDk7zzy3zzzvUTUTzzw7zQzq0D1zzzsDy047M6DzzzkT000Dw0TzzzUU000Tw1zzzz00000zyTzyzy00005zbzDzU00000/yb0Dy00D007rs007s03w00zjw000s0Ts03zTs00001y00Tyzk0000D003zxzU0000Q10DzfzUkk7VkDtzkDzDk0Tz0Dzw0TyDk00Q0T702z6Tk0000s00zyQzk0M01U00zwzzk1w0i00Dzfzzkry0s00TTzzzUzz0U00TzTzzVzzUzk0PyzzzVzzkT00ryzzzXzzsC00T"
  14. stonedeposit:="|<stonedeposit>*140$71.01zzjzzzs0Ts01zzzzzzU0Tk03zzzzzy00Ts0Dzzzzzw00TwTzzzzzzs00Twzzzzzzzm00Dnzzzzzzza00CTzzzzzzz800Rzzzzzzzz000zzzzzzzzzU01zzzzzzzzz002zzzzzzzzy005zzzzzzzzw00/zzzzzzzzs00Tzzzzzzzzk00zzzDzzzzy000zzzzzzzzw005zzzzzzzzw00Pzzzzzzzzw00Tzzzzzzzns01zzzzzzzyDU0Lzzzzzzzly07Dzzzzzzw7s0CDvzzzzzUTk9zzzzzzzw3z1TtT"
  15. searchRSSButton:="|<searchRSSButton>*123$29.000003k7z0DkDz0TUTz0zUwD1b1kS7C3UwCS71sQQDTVksTz3nkzw7zlvkTzXXkwD73lkDD7bUSS7j0wwDU00000000000002"
  16. farm1:="|<>*71$44.UBUDs6082z38003A3k0000m0wA20ODWDW000nzWqM40ATk8cEU81w0D2A30NwXzVUEWRwvs610Xz6SVc2MLk6QC0z4tFjX0TV7z3ss1wFz2SA8Dy3k7r1Uz0zkzwo7s7y9y70ykzXDXmBzBnlxzlDXDwDzt3slzUzzETw/s3zr6zWQMzztbs3zDs"
  17. farm:="|<>*129$71.03YrE3Z7kU0U07k6EDw70000010/wBU00004036Hs000ME001j8XskC7s0046zx7pU01s00MCzzDxWEDk00MvDsCS8FzU43Rz7x4ydzzU07zyByFztzzU03zyBrnjezzE0Tn4FznTkzw00vWtVz0Ntzs0133jmQwrtrs0G42z0TwDbbk0404y8zxDbDk0860zsjsTSDs0E8kTYRwTyTk7zTkTUTsrsTUzzzUTMTpblzfvzyMzwrjDrzyDsTsboby7zzzzwzYDX7y/zzzzxzcDy7w1zryzzzQPy9tXzbx"
  18. croplandlabel:="|<croplandlabel>*191$26.000000000000000000000000Q00070001k000Q03C71lzllwTwQDbbb09stkSSCQDbXb7dttlkTwST7z7blz0ssS0007U001s000000000008"
  19. foodlabel:="|<>*139$33.200001k001UA000A1U001USS7Vw1bNaNUAlgKA1aD3lUAlsSA1aBaFUATDnwk1UM40000004"
  20. gatherRSS:="|<>*123$44.00000000000000000000000y3zwS3kDUzz7Uw7sDzlsD1r0D0S3kNk3k7UwCS0w1sD3XUD0Tzkss3k7zwSD0w1zz7zkD0S3lzw3k7UQzz0w1sDD1sD0S3nUS3k7Uxs7Uw1sDS0w70S1k00000000000000000000000000000000000000000008"
  21. newTroops:="|<>*124$26.0000000000000DzU07zw01zz00DzU00C0tk3UDw0s3z0C0y03UD00s3k0C0w03UD00s3k0C0w03UD00s3k0C0M000000000000000000U"
  22. marchTroops:="|<>*157$23.00000000000000000000000Ts1wzsDxzszvVlk73bUC7C0TyQ0zss1zVs3XVk773liD3zQD3y000000000008"
  23.  
  24.  
  25. SetTimer, CheckIfFarmersBusy, 5000
  26. SetTimer, SearchRSSButton, 5000
  27.  
  28. return
  29.  
  30. CheckIfFarmersBusy:
  31. if (ok:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, farmerbusy))
  32. {
  33.     ;msgbox farmers are busy
  34. }
  35. else
  36. {
  37.   if(okfarm:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, farm)||FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, farm1))
  38.   {
  39.     if(okcl:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, croplandlabel))
  40.     {
  41.       if(okgr:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, gatherRSS))
  42.       {
  43.         X:=okgr[1].1, Y:=okgr[1].2, W:=okgr[1].3, H:=okgr[1].4, X+=W//2, Y+=H//2
  44.         Click, %X%, %Y%
  45.         Sleep, 1000
  46.       }
  47.     }else{
  48.       X:=okfarm[1].1, Y:=okfarm[1].2, W:=okfarm[1].3, H:=okfarm[1].4, X+=W//2, Y+=H//2
  49.       Click, %X%, %Y%
  50.       Sleep, 1000
  51.        X:=okfarm1[1].1, Y:=okfarm1[1].2, W:=okfarm1[1].3, H:=okfarm1[1].4, X+=W//2, Y+=H//2
  52.       Click, %X%, %Y%
  53.       Sleep, 1000
  54.     }
  55.   }
  56.   else if(oksearchRSS:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, searchRSS))
  57.   {
  58.     msgbox i am in searchRSS
  59.     X:=oksearchRSS[1].1, Y:=oksearchRSS[1].2, W:=oksearchRSS[1].3, H:=oksearchRSS[1].4, X+=W//2, Y+=H//2
  60.     Click, %X%, %Y%
  61.     Sleep, 1000
  62.         ;Goto, %A_ThisLabel%
  63.   }else{
  64.     if(oknt:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, newTroops))
  65.     {
  66.       X:=oknt[1].1, Y:=oknt[1].2, W:=oknt[1].3, H:=oknt[1].4, X+=W//2, Y+=H//2
  67.       Click, %X%, %Y%
  68.       Sleep, 1000
  69.     }
  70.     if(okmt:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, marchTroops))
  71.     {
  72.       X:=okmt[1].1, Y:=okmt[1].2, W:=okmt[1].3, H:=okmt[1].4, X+=W//2, Y+=H//2
  73.       Click, %X%, %Y%
  74.       Sleep, 1000
  75.     }
  76.   }
  77. }
  78. return
  79.  
  80. SearchRSSButton:
  81. whattomine:="food"
  82. if(InStr(whattomine, "food"))
  83. {
  84.   if (okc:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, cropland))
  85.   {
  86.     if (okfdl:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, foodlabel))
  87.     {
  88.       if (oksrb:=FindText(0, 0, A_ScreenWidth, A_ScreenHeight, 0, 0, searchRSSButton))
  89.       {
  90.         X:=oksrb[1].1, Y:=oksrb[1].2, W:=oksrb[1].3, H:=oksrb[1].4, X+=W//2, Y+=H//2
  91.         Click, %X%, %Y%
  92.         Sleep, 1000
  93.       }
  94.     }
  95.     else
  96.     {
  97.       X:=okfdl[1].1, Y:=okfdl[1].2, W:=okfdl[1].3, H:=okfdl[1].4, X+=W//2, Y+=H//2
  98.       Click, %X%, %Y%
  99.       Sleep, 1000
  100.     }
  101.   }
  102.   else
  103.   {
  104.       ;msgbox cropland not found
  105.   }
  106.  
  107. }
  108. else if(InStr(whattomine, "wood"))
  109. {
  110.    
  111. }
  112. else if(InStr(whattomine, "stone"))
  113. {
  114.  
  115. }
  116. else if(InStr(whattomine, "gold"))
  117. {
  118.  
  119. }
  120. return
  121.  
  122.  
  123. FindText( x, y, w, h, err1, err0, text, ScreenShot=1
  124.   , FindAll=1, JoinText=0, offsetX=20, offsetY=10 )
  125. {
  126.   xywh2xywh(x,y,w,h,x,y,w,h)
  127.   if (w<1 or h<1)
  128.     return, 0
  129.   bch:=A_BatchLines
  130.   SetBatchLines, -1
  131.   ;-------------------------------
  132.   GetBitsFromScreen(x,y,w,h,Scan0,Stride,ScreenShot,zx,zy)
  133.   ;-------------------------------
  134.   sx:=x-zx, sy:=y-zy, sw:=w, sh:=h
  135.   , arr:=[], info:=[], allv:=""
  136.   Loop, Parse, text, |
  137.   {
  138.     v:=A_LoopField
  139.     IfNotInString, v, $, Continue
  140.     comment:="", e1:=err1, e0:=err0
  141.     ; You Can Add Comment Text within The <>
  142.     if RegExMatch(v,"<([^>]*)>",r)
  143.       v:=StrReplace(v,r), comment:=Trim(r1)
  144.     ; You can Add two fault-tolerant in the [], separated by commas
  145.     if RegExMatch(v,"\[([^\]]*)]",r)
  146.     {
  147.       v:=StrReplace(v,r), r1.=","
  148.       StringSplit, r, r1, `,
  149.       e1:=r1, e0:=r2
  150.     }
  151.     StringSplit, r, v, $
  152.     color:=r1, v:=r2
  153.     StringSplit, r, v, .
  154.     w1:=r1, v:=base64tobit(r2), h1:=StrLen(v)//w1
  155.     if (r0<2 or h1<1 or w1>sw or h1>sh or StrLen(v)!=w1*h1)
  156.       Continue
  157.     mode:=InStr(color,"-") ? 4 : InStr(color,"#") ? 3
  158.       : InStr(color,"**") ? 2 : InStr(color,"*") ? 1 : 0
  159.     if (mode=4)
  160.     {
  161.       color:=StrReplace(color,"0x")
  162.       StringSplit, r, color, -
  163.       color:="0x" . r1, n:="0x" . r2
  164.     }
  165.     else
  166.     {
  167.       color:=RegExReplace(color,"[*#]") . "@"
  168.       StringSplit, r, color, @
  169.       color:=mode=3 ? ((r1-1)//w1)*Stride+Mod(r1-1,w1)*4 : r1
  170.       n:=Round(r2,2)+(!r2), n:=Floor(9*255*255*(1-n)*(1-n))
  171.     }
  172.     StrReplace(v,"1","",len1), len0:=StrLen(v)-len1
  173.     e1:=Round(len1*e1), e0:=Round(len0*e0)
  174.     info.Push( [StrLen(allv),w1,h1,len1,len0,e1,e0
  175.       ,mode,color,n,comment] ), allv.=v
  176.   }
  177.   if (allv="")
  178.   {
  179.     SetBatchLines, %bch%
  180.     return, 0
  181.   }
  182.   num:=info.MaxIndex(), VarSetCapacity(input, num*7*4)
  183.   , VarSetCapacity(gs, sw*sh)
  184.   , VarSetCapacity(ss, sw*sh), k:=StrLen(allv)*4
  185.   , VarSetCapacity(s1, k), VarSetCapacity(s0, k)
  186.   , allpos_max:=FindAll ? 1024 : 1
  187.   , VarSetCapacity(allpos, allpos_max*4)
  188.   ;-------------------------------------
  189.   Loop, 2 {
  190.   if (JoinText)
  191.   {
  192.     mode:=info.1.8, color:=info.1.9, n:=info.1.10
  193.     , w1:=-1, h1:=info.1.3, comment:="", k:=0
  194.     Loop, % num {
  195.       i:=A_Index, w1+=info[i].2+1, comment.=info[i].11
  196.       Loop, 7
  197.         NumPut(info[i][A_Index], input, 4*(k++), "int")
  198.     }
  199.     ok:=PicFind( mode,color,n,offsetX,offsetY
  200.       ,Scan0,Stride,sx,sy,sw,sh,gs,ss,allv,s1,s0
  201.       ,input,num*7,allpos,allpos_max )
  202.     Loop, % ok
  203.       pos:=NumGet(allpos, 4*(A_Index-1), "uint")
  204.       , rx:=(pos&0xFFFF)+zx, ry:=(pos>>16)+zy
  205.       , arr.Push( [rx,ry,w1,h1,comment] )
  206.   }
  207.   else
  208.   {
  209.     For i,j in info
  210.     {
  211.       mode:=j.8, color:=j.9, n:=j.10, comment:=j.11
  212.       , w1:=j.2, h1:=j.3, v:=SubStr(allv, j.1+1, w1*h1)
  213.       Loop, 7
  214.         NumPut(j[A_Index], input, 4*(A_Index-1), "int")
  215.       NumPut(0, input, "int")
  216.       ok:=PicFind( mode,color,n,offsetX,offsetY
  217.         ,Scan0,Stride,sx,sy,sw,sh,gs,ss,v,s1,s0
  218.         ,input,7,allpos,allpos_max )
  219.       Loop, % ok
  220.         pos:=NumGet(allpos, 4*(A_Index-1), "uint")
  221.         , rx:=(pos&0xFFFF)+zx, ry:=(pos>>16)+zy
  222.         , arr.Push( [rx,ry,w1,h1,comment] )
  223.     }
  224.   }
  225.   if (err1=0 and err0=0 and !arr.MaxIndex())
  226.   {
  227.     err1:=err0:=0.1
  228.     For i,j in info
  229.       if (j.6=0 and j.7=0)
  230.         j.6:=Round(j.4*err1), j.7:=Round(j.5*err0)
  231.   }
  232.   else Break
  233.   }
  234.   SetBatchLines, %bch%
  235.   return, arr.MaxIndex() ? arr:0
  236. }
  237.  
  238. PicFind(mode, color, n, offsetX, offsetY
  239.   , Scan0, Stride, sx, sy, sw, sh
  240.   , ByRef gs, ByRef ss, ByRef text, ByRef s1, ByRef s0
  241.   , ByRef input, num, ByRef allpos, allpos_max)
  242. {
  243.   static MyFunc, Ptr:=A_PtrSize ? "UPtr" : "UInt"
  244.   if !MyFunc
  245.   {
  246.     x32:="5557565383EC788B8424CC0000008BBC24CC000000C7442"
  247.     . "424000000008B40048B7F148944243C8B8424CC000000897C2"
  248.     . "42C8BBC24CC0000008B40088B7F18894424348B8424CC00000"
  249.     . "0897C24308B400C89C6894424288B8424CC0000008B401039C"
  250.     . "6894424200F4DC68944241C8B8424D000000085C00F8E15010"
  251.     . "0008BB424CC0000008B44242489F78B0C868B7486048B44870"
  252.     . "88974241085C0894424180F8ED700000089CD894C2414C7442"
  253.     . "40C00000000C744240800000000C744240400000000890C248"
  254.     . "D76008DBC27000000008B5C24108B7424088B4C24148B54240"
  255.     . "C89DF89F029F101F78BB424C000000001CE85DB7E5E8B0C248"
  256.     . "9EB893C2489D7EB198BAC24C800000083C70483C00189548D0"
  257.     . "083C101390424742C83BC248C0000000389FA0F45D0803C063"
  258.     . "175D48BAC24C400000083C70483C00189549D0083C30139042"
  259.     . "475D48B7424100174241489DD890C2483442404018BB424B00"
  260.     . "000008B442404017424088BBC24A4000000017C240C3944241"
  261.     . "80F8554FFFFFF83442424078B442424398424D00000000F8FE"
  262.     . "BFEFFFF83BC248C000000030F84A00600008B8424A40000008"
  263.     . "BB424A80000000FAF8424AC0000008BBC248C0000008D2CB08"
  264.     . "B8424B00000008BB424A4000000F7D885FF8D0486894424100"
  265.     . "F84F702000083BC248C000000010F845F08000083BC248C000"
  266.     . "000020F84130900008B8424900000008B9C24940000000FB6B"
  267.     . "C24940000000FB6B42490000000C744241800000000C744242"
  268.     . "400000000C1E8100FB6DF0FB6D08B84249000000089D10FB6C"
  269.     . "4894424088B842494000000C1E8100FB6C029C101D08904248"
  270.     . "B442408894C24408B4C240801D829D9894424088D043E894C2"
  271.     . "40489F129F9894424148BBC24B40000008B8424B0000000894"
  272.     . "C240C89E98B6C2440C1E00285FF894424380F8EBA0000008BB"
  273.     . "424B000000085F60F8E910000008B8424A00000008B5424240"
  274.     . "39424BC00000001C8034C243889CF894C244003BC24A000000"
  275.     . "0EB3D8D76008DBC2700000000391C247C3D394C24047F37394"
  276.     . "C24087C3189F30FB6F33974240C0F9EC3397424140F9DC183C"
  277.     . "00483C20121D9884AFF39F8741E0FB658020FB648010FB6303"
  278.     . "9DD7EBE31C983C00483C201884AFF39F875E28BBC24B000000"
  279.     . "0017C24248B4C24408344241801034C24108B442418398424B"
  280.     . "40000000F8546FFFFFF8B8424B00000002B44243C8944240C8"
  281.     . "B8424B40000002B442434894424600F884D0900008B4424288"
  282.     . "BBC24C40000008B74243CC744241000000000C744243800000"
  283.     . "000C7442434000000008D3C8789C583EE01897C246C8974247"
  284.     . "48B44240C85C00F88E70000008B7C24388B8424AC000000BE0"
  285.     . "0000000C704240000000001F8C1E0108944246889F82B84249"
  286.     . "C0000000F49F08B84249C000000897424640FAFB424B000000"
  287.     . "001F8894424708974245C8DB6000000008B04240344241089C"
  288.     . "1894424088B442430394424200F84AA0100008B5C241C89C60"
  289.     . "38C24BC00000031C08B54242C85DB0F8EC8010000897424048"
  290.     . "B7C2420EB2D39C77E1C8BB424C80000008B1C8601CB803B007"
  291.     . "40B836C240401782B8D74260083C0013944241C0F849101000"
  292.     . "039C57ECF8BB424C40000008B1C8601CB803B0174BE83EA017"
  293.     . "9B9830424018B04243944240C0F8D68FFFFFF83442438018BB"
  294.     . "424B00000008B44243801742410394424600F8DEFFEFFFF8B4"
  295.     . "C243483C47889C85B5E5F5DC250008B8424900000008BB424B"
  296.     . "4000000C744240C00000000C744241400000000C1E8100FB6C"
  297.     . "08904248B8424900000000FB6C4894424040FB684249000000"
  298.     . "0894424088B8424B0000000C1E00285F68944242489E88BAC2"
  299.     . "4940000000F8E24FEFFFF8B9C24B000000085DB7E758B9C24A"
  300.     . "00000008B7424148BBC24A000000003B424BC00000001C3034"
  301.     . "424248944241801C78D76008DBC27000000000FB643020FB64"
  302.     . "B012B04242B4C24040FB6132B5424080FAFC00FAFC98D04400"
  303.     . "FAFD28D04888D045039C50F930683C30483C60139DF75C98BB"
  304.     . "C24B0000000017C24148B4424188344240C01034424108B742"
  305.     . "40C39B424B40000000F8566FFFFFFE985FDFFFF85ED7E358B7"
  306.     . "424088BBC24BC00000031C08B54242C8D1C378BB424C400000"
  307.     . "08B0C8601D9803901740983EA010F8890FEFFFF83C00139C57"
  308.     . "5E683BC24D0000000070F8EAA0100008B442474030424C7442"
  309.     . "44007000000896C2444894424288B8424CC00000083C020894"
  310.     . "4243C8B44243C8B9424B00000008B7C24288B0029C28944245"
  311.     . "08B84249800000001F839C20F4EC289C68944244C39FE0F8C0"
  312.     . "90100008B44243C8B700C8B78148B6808897424148B7010897"
  313.     . "C245489C7897424248BB424B40000002B700489F08B7424703"
  314.     . "9C60F4EC68BB424C4000000894424188B47FC89442404C1E00"
  315.     . "201C6038424C8000000894424588B4424648B7C2428037C245"
  316.     . "C3B442418894424040F8F8700000085ED7E268B8C24BC00000"
  317.     . "08B54242431C08D1C398B0C8601D9803901740583EA01784A8"
  318.     . "3C00139C575EA8B4424148B4C245439C8747E85C07E7A8B9C2"
  319.     . "4BC000000896C244831C08B6C245801FBEB0983C0013944241"
  320.     . "4745C8B54850001DA803A0074EC83E90179E78B6C244890834"
  321.     . "424040103BC24B00000008B442404394424180F8D79FFFFFF8"
  322.     . "3442428018B4424283944244C0F8D4CFFFFFF830424018B6C2"
  323.     . "4448B04243944240C0F8D7EFCFFFFE911FDFFFF8B4424288B7"
  324.     . "4245083442440078344243C1C8D4430FF894424288B4424403"
  325.     . "98424D00000000F8F7FFEFFFF8B6C24448B7C24348B0424038"
  326.     . "424A80000008BB424D40000000B4424688D4F01398C24D8000"
  327.     . "0008904BE0F8ED8FCFFFF85ED7E278B7424088BBC24BC00000"
  328.     . "08B8424C40000008D1C378B74246C8B1083C00401DA39F0C60"
  329.     . "20075F283042401894C24348B04243944240C0F8DDEFBFFFFE"
  330.     . "971FCFFFF89F68DBC27000000008B8424B0000000038424A80"
  331.     . "000002B44243C894424248B8424AC000000038424B40000002"
  332.     . "B442434398424AC000000894424380F8F520400008B8424A40"
  333.     . "000008BB424A80000000FAF8424AC000000C74424180000000"
  334.     . "08D04B0038424900000008BB424A0000000894424348B44242"
  335.     . "4398424A80000000F8F2B0100008B8424AC000000C1E010894"
  336.     . "4243C8B442434894424148B8424A8000000894424088B44241"
  337.     . "40FB67C060289C52BAC2490000000893C240FB67C0601897C2"
  338.     . "4040FB63C068B44241C85C00F8E140100008B4424308944241"
  339.     . "08B44242C8944240C31C0EB5D394424207E4A8B9C24C800000"
  340.     . "08B0C8301E90FB6540E020FB65C0E012B14242B5C24040FB60"
  341.     . "C0E0FAFD20FAFDB29F98D14520FAFC98D149A8D144A3994249"
  342.     . "4000000720C836C2410017865908D74260083C0013944241C0"
  343.     . "F84A3000000394424287E9D8B9C24C40000008B0C8301E90FB"
  344.     . "6540E020FB65C0E012B14242B5C24040FB60C0E0FAFD20FAFD"
  345.     . "B29F98D14520FAFC98D149A8D144A3B9424940000000F865BF"
  346.     . "FFFFF836C240C010F8950FFFFFF834424080183442414048B4"
  347.     . "42408394424240F8DF6FEFFFF838424AC000000018BBC24A40"
  348.     . "000008B442438017C24343B8424AC0000000F8DA0FEFFFF8B4"
  349.     . "C241883C4785B5E89C85F5DC250008D7426008B7C24188B442"
  350.     . "43C0B4424088B9C24D40000008D4F013B8C24D80000008904B"
  351.     . "B0F8D84FAFFFF894C2418EB848B8424900000008B8C24B4000"
  352.     . "000C7042400000000C74424040000000083C001C1E00789C78"
  353.     . "B8424B0000000C1E00285C98944240889E889FD0F8ECFF8FFF"
  354.     . "F8B9424B000000085D27E5F8B8C24A00000008B5C2404039C2"
  355.     . "4BC00000001C1034424088944240C038424A000000089C70FB"
  356.     . "651020FB641010FB6316BC04B6BD22601C289F0C1E00429F00"
  357.     . "1D039C50F970383C10483C30139F975D58BBC24B0000000017"
  358.     . "C24048B44240C83042401034424108B342439B424B40000007"
  359.     . "582E94CF8FFFF8B8424B0000000C7042400000000C74424040"
  360.     . "0000000C1E002894424088B8424B400000085C00F8E9200000"
  361.     . "08B8424B000000085C07E6F8B8C24A00000008B5C24048BB42"
  362.     . "4B800000001E9036C240801DE039C24BC000000896C240C03A"
  363.     . "C24A00000000FB651020FB6410183C1040FB679FC83C60183C"
  364.     . "3016BC04B6BD22601C289F8C1E00429F801D0C1F8078846FFC"
  365.     . "643FF0039CD75CC8BB424B0000000017424048B6C240C83042"
  366.     . "401036C24108B0424398424B40000000F856EFFFFFF83BC24B"
  367.     . "4000000020F8E80F7FFFF8B8424BC000000038424B00000008"
  368.     . "BAC24B800000003AC24B0000000C7442404010000008944240"
  369.     . "88B8424B400000083E8018944240C8B8424B000000083C0018"
  370.     . "944241083BC24B0000000027E798B44241089E92B8C24B0000"
  371.     . "0008B5C240889EA8D34288D45FE8904240FB642010FB63A038"
  372.     . "4249000000039F87C360FB67A0239F87C2E0FB6790139F87C2"
  373.     . "60FB63E39F87C1F0FB63939F87C180FB6790239F87C100FB67"
  374.     . "EFF39F87C080FB67E0139F87D04C643010183C20183C30183C"
  375.     . "10183C6013B0C2475A3834424040103AC24B00000008B44240"
  376.     . "48BB424B0000000017424083944240C0F8558FFFFFFE98FF6F"
  377.     . "FFF83C47831C95B89C85E5F5DC2500090909090909090"
  378.     x64:="4157415641554154555756534881EC88000000488B84245"
  379.     . "0010000488BB42450010000448B94245801000089542428448"
  380.     . "944240844898C24E80000008B40048B76144C8BBC244001000"
  381.     . "04C8BB42448010000C74424180000000089442430488B84245"
  382.     . "00100008974241C488BB424500100008B40088B76188944243"
  383.     . "C488B842450010000897424388B400C89C789442440488B842"
  384.     . "4500100008B401039C7894424100F4DC74585D289442454488"
  385.     . "B84245001000048894424200F8ECB000000488B442420448B0"
  386.     . "8448B68048B400885C0894424040F8E940000004489CE44890"
  387.     . "C244531E431FF31ED0F1F8400000000004585ED7E614863142"
  388.     . "4418D5C3D0089F848039424380100004589E0EB1D0F1F0083C"
  389.     . "0014D63D94183C0044183C1014883C20139C34789149E74288"
  390.     . "3F9034589C2440F45D0803A3175D783C0014C63DE4183C0048"
  391.     . "3C6014883C20139C34789149F75D844012C2483C50103BC241"
  392.     . "80100004403A42400010000396C24047582834424180748834"
  393.     . "424201C8B442418398424580100000F8F35FFFFFF83F9030F8"
  394.     . "43D0600008B8424000100008BBC24080100000FAF842410010"
  395.     . "0008BB424000100008D3CB88B842418010000F7D885C9448D2"
  396.     . "C860F841101000083F9010F842008000083F9020F84BF08000"
  397.     . "08B742428C744240400000000C74424180000000089F0440FB"
  398.     . "6CEC1E8104589CC0FB6D84889F08B7424080FB6D44189DB89F"
  399.     . "0440FB6C64889F1C1E8100FB6CD89D60FB6C08D2C0A8B94242"
  400.     . "00100004129C301C3438D040129CE4529C48904248B8424180"
  401.     . "10000C1E00285D2894424080F8E660100004C89BC244001000"
  402.     . "0448BBC24180100004585FF0F8E91040000488B8C24F800000"
  403.     . "04863C74C6354241831D24C03942430010000488D440102EB3"
  404.     . "A0F1F80000000004439C37C4039CE7F3C39CD7C384539CC410"
  405.     . "F9EC044390C240F9DC14421C141880C124883C2014883C0044"
  406.     . "139D70F8E2D040000440FB6000FB648FF440FB648FE4539C37"
  407.     . "EBB31C9EBD58B5C2428448B8C242001000031ED4531E44889D"
  408.     . "84189DB0FB6DB0FB6F48B84241801000041C1EB10450FB6DBC"
  409.     . "1E0024585C98904240F8EA10000004C89BC24400100004C89B"
  410.     . "42448010000448B7C2408448BB424180100004585F67E60488"
  411.     . "B8C24F80000004D63D44C039424300100004863C74531C94C8"
  412.     . "D440102410FB600410FB648FF410FB650FE4429D829F10FAFC"
  413.     . "029DA0FAFC98D04400FAFD28D04888D04504139C7430F93040"
  414.     . "A4983C1014983C0044539CE7FC4033C244501F483C5014401E"
  415.     . "F39AC2420010000758C4C8BBC24400100004C8BB4244801000"
  416.     . "08B8424180100002B4424308904248B8424200100002B44243"
  417.     . "C894424680F88540800008B7C24404D89F5488BAC243001000"
  418.     . "0448B7424104C89FEC74424040000000048C74424280000000"
  419.     . "0C74424200000000089F883E801498D4487044189FF4889442"
  420.     . "4088B44243083E801894424788B042485C00F88D9000000488"
  421.     . "B5C24288B8424100100004D89EC448B6C245401D8C1E010894"
  422.     . "4247089D82B8424F000000089C7B8000000000F49C731FF894"
  423.     . "4246C0FAF842418010000894424648B8424F000000001D8894"
  424.     . "42474908B442404897C24188D1C388B4424384139C60F84AB0"
  425.     . "000004189C131C04585ED448B44241C7F36E9C30000000F1F4"
  426.     . "0004139CE7E1B418B148401DA4863D2807C150000740B4183E"
  427.     . "901782E0F1F4400004883C0014139C50F8E920000004139C78"
  428.     . "9C17ECC8B148601DA4863D2807C15000174BD4183E80179B74"
  429.     . "883C701393C240F8D7AFFFFFF4D89E54883442428018B9C241"
  430.     . "8010000488B442428015C2404394424680F8DFCFEFFFF8B4C2"
  431.     . "42089C84881C4880000005B5E5F5D415C415D415E415FC3458"
  432.     . "5FF7E278B4C241C4C8B4424084889F28B0201D84898807C050"
  433.     . "001740583E90178934883C2044939D075E583BC24580100000"
  434.     . "70F8EE60100008B442478488B8C24500100000344241844896"
  435.     . "C2450448BAC241801000044897C24404883C1204889742410C"
  436.     . "744243C07000000448974244448897C24484989CF895C247C8"
  437.     . "9C64C89642430418B074489EA29C28944245C8B8424E800000"
  438.     . "001F039C20F4EC239F0894424580F8CD0000000418B47148BB"
  439.     . "C2420010000412B7F0449635FFC458B4F08458B670C8944246"
  440.     . "08B442474458B771039C70F4FF8488B44241048C1E3024C8D1"
  441.     . "41848035C24308B442464448D04068B44246C39F84189C37F7"
  442.     . "2904585C97E234489F131D2418B04924401C04898807C05000"
  443.     . "1740583E90178464883C2014139D17FE28B4424604139C40F8"
  444.     . "4AA0000004585E40F8EA100000089C131D2EB0D4883C201413"
  445.     . "9D40F8E8E0000008B04934401C04898807C05000074E483E90"
  446.     . "179DF4183C3014501E84439DF7D8F83C601397424580F8D6EF"
  447.     . "FFFFF488B7C2448448B7C2440448B742444448B6C2450488B7"
  448.     . "424104C8B6424304883C701393C240F8D97FDFFFFE918FEFFF"
  449.     . "F6690037C240844017C241883442404014401EF8B442404398"
  450.     . "424200100000F854DFBFFFF4C8BBC2440010000E996FCFFFF8"
  451.     . "B44245C8344243C074983C71C8D7406FF8B44243C398424580"
  452.     . "100000F8F87FEFFFF448B7C2440448B742444448B6C2450488"
  453.     . "B7C24488B5C247C488B7424104C8B64243048634424208B542"
  454.     . "418039424080100004C8B9C24600100000B5424708D4801398"
  455.     . "C2468010000418914830F8E9AFDFFFF4585FF7E1D4C8B44240"
  456.     . "84889F08B104883C00401DA4C39C04863D2C64415000075EB4"
  457.     . "883C701393C24894C24200F8DBAFCFFFFE93BFDFFFF0F1F440"
  458.     . "0008B842418010000038424080100002B442430894424308B8"
  459.     . "42410010000038424200100002B44243C39842410010000894"
  460.     . "424440F8F230400008B8424000100008BBC24080100000FAF8"
  461.     . "42410010000448B642440448B6C24544C8B8C24F8000000C74"
  462.     . "42420000000008D04B8034424288944243C8B4424303984240"
  463.     . "80100000F8F2F0100008B8424100100008B6C243CC1E010894"
  464.     . "424408B8424080100008904248D450289EF2B7C24284585ED4"
  465.     . "898450FB61C018D45014898410FB61C014863C5410FB634010"
  466.     . "F8E140100008B442438894424188B44241C8944240431C0EB6"
  467.     . "244395424107E4E418B0C8601F98D5102448D41014863C9410"
  468.     . "FB60C094863D24D63C0410FB61411470FB6040129F10FAFC94"
  469.     . "429DA4129D80FAFD2450FAFC08D1452428D14828D144A39542"
  470.     . "4087207836C241801786B4883C0014139C50F8E9E000000413"
  471.     . "9C44189C27E96418B0C8701F98D5102448D41014863C9410FB"
  472.     . "60C094863D24D63C0410FB61411470FB6040129F10FAFC9442"
  473.     . "9DA4129D80FAFD2450FAFC08D1452428D14828D144A3B54240"
  474.     . "80F864BFFFFFF836C2404010F8940FFFFFF8304240183C5048"
  475.     . "B0424394424300F8DEDFEFFFF83842410010000018BBC24000"
  476.     . "100008B442444017C243C3B8424100100000F8D9CFEFFFFE97"
  477.     . "CFBFFFF0F1F0048634424208B5424400B1424488BBC2460010"
  478.     . "0008D48013B8C24680100008914870F8D56FBFFFF830424018"
  479.     . "3C504894C24208B0424394424300F8D82FEFFFFEB93448B5C2"
  480.     . "428448B84242001000031DB8B84241801000031F6448B94241"
  481.     . "80100004183C30141C1E3074585C08D2C85000000000F8E8CF"
  482.     . "9FFFF4585D27E57488B8C24F80000004C63CE4C038C2430010"
  483.     . "0004863C74531C0488D4C01020FB6110FB641FF440FB661FE6"
  484.     . "BC04B6BD22601C24489E0C1E0044429E001D04139C3430F970"
  485.     . "4014983C0014883C1044539C27FCC01EF4401D683C3014401E"
  486.     . "F399C24200100007595E91CF9FFFF8B8C24200100008B84241"
  487.     . "801000031DB31F6448B8C241801000085C98D2C85000000007"
  488.     . "E7D4585C97E694C63C6488B8C24F80000004863C74D89C24C0"
  489.     . "38424300100004C0394242801000031D2488D4C0102440FB61"
  490.     . "90FB641FF4883C104440FB661FA6BC04B456BDB264101C3448"
  491.     . "9E0C1E0044429E04401D8C1F8074188041241C60410004883C"
  492.     . "2014139D17FC401EF4401CE83C3014401EF399C24200100007"
  493.     . "58383BC2420010000020F8E6CF8FFFF4863B424180100008B9"
  494.     . "C24180100008BBC2420010000488D5601448D67FFBF0100000"
  495.     . "04889D0480394243001000048038424280100004889D58D53F"
  496.     . "D4C8D6A0183BC241801000002488D1C067E7E4989C04D8D5C0"
  497.     . "5004989D94929F04889E90FB610440FB650FF035424284439D"
  498.     . "27C44440FB650014439D27C3A450FB6104439D27C31450FB61"
  499.     . "14439D27C28450FB650FF4439D27C1E450FB650014439D27C1"
  500.     . "4450FB651FF4439D27C0A450FB651014439D27D03C60101488"
  501.     . "3C0014983C1014883C1014983C0014C39D8759383C7014801F"
  502.     . "54889D84139FC0F8562FFFFFFE989F7FFFF31C9E9FAF8FFFF9"
  503.     . "0909090909090909090909090"
  504.     MCode(MyFunc, A_PtrSize=8 ? x64:x32)
  505.   }
  506.   return, DllCall(&MyFunc, "int",mode, "uint",color
  507.     , "uint",n, "int",offsetX, "int",offsetY, Ptr,Scan0
  508.     , "int",Stride, "int",sx, "int",sy, "int",sw, "int",sh
  509.     , Ptr,&gs, Ptr,&ss, "AStr",text, Ptr,&s1, Ptr,&s0
  510.     , Ptr,&input, "int",num, Ptr,&allpos, "int",allpos_max)
  511. }
  512.  
  513. xywh2xywh(x1,y1,w1,h1,ByRef x,ByRef y,ByRef w,ByRef h)
  514. {
  515.   SysGet, zx, 76
  516.   SysGet, zy, 77
  517.   SysGet, zw, 78
  518.   SysGet, zh, 79
  519.   left:=x1, right:=x1+w1-1, up:=y1, down:=y1+h1-1
  520.   left:=left<zx ? zx:left, right:=right>zx+zw-1 ? zx+zw-1:right
  521.   up:=up<zy ? zy:up, down:=down>zy+zh-1 ? zy+zh-1:down
  522.   x:=left, y:=up, w:=right-left+1, h:=down-up+1
  523. }
  524.  
  525. GetBitsFromScreen(x, y, w, h, ByRef Scan0, ByRef Stride
  526.   , ScreenShot=1, ByRef zx="", ByRef zy="", bpp=32)
  527. {
  528.   static bits, oldx, oldy, oldw, oldh
  529.   static Ptr:=A_PtrSize ? "UPtr" : "UInt", PtrP:=Ptr "*"
  530.   if (ScreenShot or x<oldx or y<oldy
  531.     or x+w>oldx+oldw or y+h>oldy+oldh)
  532.   {
  533.     oldx:=x, oldy:=y, oldw:=w, oldh:=h, ScreenShot:=1
  534.     VarSetCapacity(bits, w*h*4)
  535.   }
  536.   Scan0:=&bits, Stride:=((oldw*bpp+31)//32)*4, zx:=oldx, zy:=oldy
  537.   if (!ScreenShot or w<1 or h<1)
  538.     return
  539.   win:=DllCall("GetDesktopWindow", Ptr)
  540.   hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
  541.   mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
  542.   ;-------------------------
  543.   VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
  544.   NumPut(w, bi, 4, "int"), NumPut(-h, bi, 8, "int")
  545.   NumPut(1, bi, 12, "short"), NumPut(bpp, bi, 14, "short")
  546.   ;-------------------------
  547.   if hBM:=DllCall("CreateDIBSection", Ptr,mDC, Ptr,&bi
  548.     , "int",0, PtrP,ppvBits, Ptr,0, "int",0, Ptr)
  549.   {
  550.     oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
  551.     DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",w, "int",h
  552.       , Ptr,hDC, "int",x, "int",y, "uint",0x00CC0020|0x40000000)
  553.     DllCall("RtlMoveMemory", Ptr,Scan0, Ptr,ppvBits, Ptr,Stride*h)
  554.     DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
  555.     DllCall("DeleteObject", Ptr,hBM)
  556.   }
  557.   DllCall("DeleteDC", Ptr,mDC)
  558.   DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
  559. }
  560.  
  561. MCode(ByRef code, hex)
  562. {
  563.   bch:=A_BatchLines
  564.   SetBatchLines, -1
  565.   VarSetCapacity(code, len:=StrLen(hex)//2)
  566.   lls:=A_ListLines=0 ? "Off" : "On"
  567.   ListLines, Off
  568.   Loop, % len
  569.     NumPut("0x" SubStr(hex,2*A_Index-1,2),code,A_Index-1,"uchar")
  570.   ListLines, %lls%
  571.   Ptr:=A_PtrSize ? "UPtr" : "UInt", PtrP:=Ptr . "*"
  572.   DllCall("VirtualProtect",Ptr,&code, Ptr,len,"uint",0x40,PtrP,0)
  573.   SetBatchLines, %bch%
  574. }
  575.  
  576. base64tobit(s)
  577. {
  578.   Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  579.     . "abcdefghijklmnopqrstuvwxyz"
  580.   SetFormat, IntegerFast, d
  581.   StringCaseSense, On
  582.   lls:=A_ListLines=0 ? "Off" : "On"
  583.   ListLines, Off
  584.   Loop, Parse, Chars
  585.   {
  586.     i:=A_Index-1, v:=(i>>5&1) . (i>>4&1)
  587.       . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
  588.     s:=StrReplace(s,A_LoopField,v)
  589.   }
  590.   ListLines, %lls%
  591.   StringCaseSense, Off
  592.   s:=SubStr(s,1,InStr(s,"1",0,0)-1)
  593.   s:=RegExReplace(s,"[^01]+")
  594.   return, s
  595. }
  596.  
  597. bit2base64(s)
  598. {
  599.   s:=RegExReplace(s,"[^01]+")
  600.   s.=SubStr("100000",1,6-Mod(StrLen(s),6))
  601.   s:=RegExReplace(s,".{6}","|$0")
  602.   Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  603.     . "abcdefghijklmnopqrstuvwxyz"
  604.   SetFormat, IntegerFast, d
  605.   lls:=A_ListLines=0 ? "Off" : "On"
  606.   ListLines, Off
  607.   Loop, Parse, Chars
  608.   {
  609.     i:=A_Index-1, v:="|" . (i>>5&1) . (i>>4&1)
  610.       . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
  611.     s:=StrReplace(s,v,A_LoopField)
  612.   }
  613.   ListLines, %lls%
  614.   return, s
  615. }
  616.  
  617. ASCII(s)
  618. {
  619.   if RegExMatch(s,"\$(\d+)\.([\w+/]+)",r)
  620.   {
  621.     s:=RegExReplace(base64tobit(r2),".{" r1 "}","$0`n")
  622.     s:=StrReplace(StrReplace(s,"0","_"),"1","0")
  623.   }
  624.   else s=
  625.   return, s
  626. }
  627.  
  628. ; You can put the text library at the beginning of the script,
  629. ; and Use Pic(Text,1) to add the text library to Pic()'s Lib,
  630. ; Use Pic("comment1|comment2|...") to get text images from Lib
  631.  
  632. Pic(comments, add_to_Lib=0)
  633. {
  634.   static Lib:=[]
  635.   if (add_to_Lib)
  636.   {
  637.     re:="<([^>]*)>[^$]+\$\d+\.[\w+/]+"
  638.     Loop, Parse, comments, |
  639.       if RegExMatch(A_LoopField,re,r)
  640.         Lib[Trim(r1)]:=r
  641.     Lib[""]:=""
  642.   }
  643.   else
  644.   {
  645.     Text:=""
  646.     Loop, Parse, comments, |
  647.       Text.="|" . Lib[Trim(A_LoopField)]
  648.     return, Text
  649.   }
  650. }
  651.  
  652. PicN(Number)
  653. {
  654.   return, Pic( RegExReplace(Number, ".", "|$0") )
  655. }
  656.  
  657. ; Use PicX(Text) to automatically cut into multiple characters
  658. ; Can't be used in ColorPos mode, because it can cause position errors
  659.  
  660. PicX(Text)
  661. {
  662.   if !RegExMatch(Text,"\|([^$]+)\$(\d+)\.([\w+/]+)",r)
  663.     return, Text
  664.   w:=r2, v:=base64tobit(r3), Text:=""
  665.   c:=StrLen(StrReplace(v,"0"))<=StrLen(v)//2 ? "1":"0"
  666.   wz:=RegExReplace(v,".{" w "}","$0`n")
  667.   SetFormat, IntegerFast, d
  668.   While InStr(wz,c) {
  669.     While !(wz~="m`n)^" c)
  670.       wz:=RegExReplace(wz,"m`n)^.")
  671.     i:=0
  672.     While (wz~="m`n)^.{" i "}" c)
  673.       i++
  674.     v:=RegExReplace(wz,"m`n)^(.{" i "}).*","$1")
  675.     wz:=RegExReplace(wz,"m`n)^.{" i "}")
  676.     if v!=
  677.       Text.="|" r1 "$" i "." bit2base64(v)
  678.   }
  679.   return, Text
  680. }
  681.  
  682. ; Screenshot and retained as the last screenshot.
  683.  
  684. ScreenShot()
  685. {
  686.   n:=150000
  687.   xywh2xywh(-n,-n,2*n+1,2*n+1,x,y,w,h)
  688.   GetBitsFromScreen(x,y,w,h,Scan0,Stride,1)
  689. }
  690.  
  691. FindTextOCR(nX, nY, nW, nH, err1, err0, Text, Interval=20)
  692. {
  693.   OCR:="", RightX:=nX+nW-1, ScreenShot()
  694.   While (ok:=FindText(nX, nY, nW, nH, err1, err0, Text, 0))
  695.   {
  696.     For k,v in ok
  697.     {
  698.       ; X is the X coordinates of the upper left corner
  699.       ; and W is the width of the image have been found
  700.       x:=v.1, y:=v.2, w:=v.3, h:=v.4, comment:=v.5
  701.       ; We need the leftmost X coordinates
  702.       if (A_Index=1 or x<LeftX)
  703.         LeftX:=x, LeftY:=y, LeftW:=w, LeftH:=h, LeftOCR:=comment
  704.       else if (x=LeftX)
  705.       {
  706.         Loop, 100
  707.         {
  708.           err:=A_Index/100
  709.           if FindText(x, y, w, h, err, err, Text, 0)
  710.           {
  711.             LeftX:=x, LeftY:=y, LeftW:=w, LeftH:=h, LeftOCR:=comment
  712.             Break
  713.           }
  714.           if FindText(LeftX, LeftY, LeftW, LeftH, err, err, Text, 0)
  715.             Break
  716.         }
  717.       }
  718.     }
  719.     ; If the interval exceeds the set value, add "*" to the result
  720.     OCR.=(A_Index>1 and LeftX-nX-1>Interval ? "*":"") . LeftOCR
  721.     ; Update nX and nW for next search
  722.     nX:=LeftX+LeftW-1, nW:=RightX-nX+1
  723.   }
  724.   return, OCR
  725. }
  726.  
  727. ; Reordering the objects returned from left to right,
  728. ; from top to bottom, ignore slight height difference
  729.  
  730. SortOK(ok, dy=10) {
  731.   if !IsObject(ok)
  732.     return, ok
  733.   SetFormat, IntegerFast, d
  734.   For k,v in ok
  735.   {
  736.     x:=v.1+v.3//2, y:=v.2+v.4//2
  737.     y:=A_Index>1 and Abs(y-lasty)<dy ? lasty : y, lasty:=y
  738.     n:=(y*150000+x) "." k, s:=A_Index=1 ? n : s "-" n
  739.   }
  740.   Sort, s, N D-
  741.   ok2:=[]
  742.   Loop, Parse, s, -
  743.     ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
  744.   return, ok2
  745. }
  746.  
  747. ; Reordering according to the nearest distance
  748.  
  749. SortOK2(ok, px, py) {
  750.   if !IsObject(ok)
  751.     return, ok
  752.   SetFormat, IntegerFast, d
  753.   For k,v in ok
  754.   {
  755.     x:=v.1+v.3//2, y:=v.2+v.4//2
  756.     n:=((x-px)**2+(y-py)**2) "." k
  757.     s:=A_Index=1 ? n : s "-" n
  758.   }
  759.   Sort, s, N D-
  760.   ok2:=[]
  761.   Loop, Parse, s, -
  762.     ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
  763.   return, ok2
  764. }
  765.  
  766. ; Prompt mouse position in remote assistance
  767.  
  768. MouseTip(x="", y="") {
  769.   if (x="")
  770.   {
  771.     VarSetCapacity(pt,16,0), DllCall("GetCursorPos","ptr",&pt)
  772.     x:=NumGet(pt,0,"uint"), y:=NumGet(pt,4,"uint")
  773.   }
  774.   x:=Round(x-10), y:=Round(y-10), w:=h:=2*10+1
  775.   ;-------------------------
  776.   Gui, _MouseTip_: +AlwaysOnTop -Caption +ToolWindow +Hwndmyid +E0x08000000
  777.   Gui, _MouseTip_: Show, Hide w%w% h%h%
  778.   ;-------------------------
  779.   dhw:=A_DetectHiddenWindows
  780.   DetectHiddenWindows, On
  781.   d:=4, i:=w-d, j:=h-d
  782.   s=0-0 %w%-0 %w%-%h% 0-%h% 0-0
  783.   s=%s%  %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
  784.   WinSet, Region, %s%, ahk_id %myid%
  785.   DetectHiddenWindows, %dhw%
  786.   ;-------------------------
  787.   Gui, _MouseTip_: Show, NA x%x% y%y%
  788.   Loop, 4 {
  789.     Gui, _MouseTip_: Color, % A_Index & 1 ? "Red" : "Blue"
  790.     Sleep, 500
  791.   }
  792.   Gui, _MouseTip_: Destroy
  793. }
  794.  
  795.  
  796. /***** C source code of machine code *****
  797.  
  798. int __attribute__((__stdcall__)) PicFind(
  799.   int mode, unsigned int c, unsigned int n
  800.   , int offsetX, int offsetY, unsigned char * Bmp
  801.   , int Stride, int sx, int sy, int sw, int sh
  802.   , unsigned char * gs, char * ss, char * text
  803.   , int * s1, int * s0, int * input, int num
  804.   , unsigned int * allpos, int allpos_max)
  805. {
  806.   int o, i, j, x, y, r, g, b, rr, gg, bb, max, e1, e0, ok;
  807.   int o1, x1, y1, w1, h1, sx1, sy1, len1, len0, err1, err0;
  808.   int o2, x2, y2, w2, h2, sx2, sy2, len21, len20, err21, err20;
  809.   int r_min, r_max, g_min, g_max, b_min, b_max;
  810.   //----------------------
  811.   ok=0; w1=input[1]; h1=input[2];
  812.   len1=input[3]; len0=input[4];
  813.   err1=input[5]; err0=input[6];
  814.   max=len1>len0 ? len1 : len0;
  815.   //----------------------
  816.   // Generate Lookup Table
  817.   for (j=0; j<num; j+=7)
  818.   {
  819.     o=o1=o2=input[j]; w2=input[j+1]; h2=input[j+2];
  820.     for (y=0; y<h2; y++)
  821.     {
  822.       for (x=0; x<w2; x++)
  823.       {
  824.         i=(mode==3) ? y*Stride+x*4 : y*sw+x;
  825.         if (text[o++]=='1')
  826.           s1[o1++]=i;
  827.         else
  828.           s0[o2++]=i;
  829.       }
  830.     }
  831.   }
  832.   // Color Position Mode
  833.   // This mode is not support combination lookup
  834.   // only used to recognize multicolored Verification Code
  835.   if (mode==3)
  836.   {
  837.     sx1=sx+sw-w1; sy1=sy+sh-h1;
  838.     for (y=sy; y<=sy1; y++)
  839.     {
  840.       for (x=sx; x<=sx1; x++)
  841.       {
  842.         o=y*Stride+x*4; e1=err1; e0=err0;
  843.         j=o+c; rr=Bmp[2+j]; gg=Bmp[1+j]; bb=Bmp[j];
  844.         for (i=0; i<max; i++)
  845.         {
  846.           if (i<len1)
  847.           {
  848.             j=o+s1[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb;
  849.             if (3*r*r+4*g*g+2*b*b>n && (--e1)<0)
  850.               goto NoMatch3;
  851.           }
  852.           if (i<len0)
  853.           {
  854.             j=o+s0[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb;
  855.             if (3*r*r+4*g*g+2*b*b<=n && (--e0)<0)
  856.               goto NoMatch3;
  857.           }
  858.         }
  859.         allpos[ok++]=y<<16|x;
  860.         if (ok>=allpos_max)
  861.           goto Return1;
  862.         NoMatch3:
  863.         continue;
  864.       }
  865.     }
  866.     goto Return1;
  867.   }
  868.   // Generate Two Value Image
  869.   o=sy*Stride+sx*4; j=Stride-4*sw; i=0;
  870.   if (mode==0)  // Color Mode
  871.   {
  872.     rr=(c>>16)&0xFF; gg=(c>>8)&0xFF; bb=c&0xFF;
  873.     for (y=0; y<sh; y++, o+=j)
  874.       for (x=0; x<sw; x++, o+=4, i++)
  875.       {
  876.         r=Bmp[2+o]-rr; g=Bmp[1+o]-gg; b=Bmp[o]-bb;
  877.         ss[i]=(3*r*r+4*g*g+2*b*b<=n) ? 1:0;
  878.       }
  879.   }
  880.   else if (mode==1)  // Gray Threshold Mode
  881.   {
  882.     c=(c+1)*128;
  883.     for (y=0; y<sh; y++, o+=j)
  884.       for (x=0; x<sw; x++, o+=4, i++)
  885.         ss[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15<c) ? 1:0;
  886.   }
  887.   else if (mode==2)  // Gray Difference Mode
  888.   {
  889.     for (y=0; y<sh; y++, o+=j)
  890.     {
  891.       for (x=0; x<sw; x++, o+=4, i++)
  892.       {
  893.         gs[i]=(Bmp[2+o]*38+Bmp[1+o]*75+Bmp[o]*15)>>7;
  894.         ss[i]=0;
  895.       }
  896.     }
  897.     sx1=sw-2; sy1=sh-2;
  898.     for (y=1; y<=sy1; y++)
  899.       for (x=1; x<=sx1; x++)
  900.       {
  901.         i=y*sw+x; j=gs[i]+c;
  902.         if ( gs[i-1]>j || gs[i+1]>j
  903.           || gs[i-sw]>j || gs[i+sw]>j
  904.           || gs[i-sw-1]>j || gs[i-sw+1]>j
  905.           || gs[i+sw-1]>j || gs[i+sw+1]>j )
  906.             ss[i]=1;
  907.       }
  908.   }
  909.   else // (mode==4) Color Difference Mode
  910.   {
  911.     r=(c>>16)&0xFF; g=(c>>8)&0xFF; b=c&0xFF;
  912.     rr=(n>>16)&0xFF; gg=(n>>8)&0xFF; bb=n&0xFF;
  913.     r_min=r-rr; g_min=g-gg; b_min=b-bb;
  914.     r_max=r+rr; g_max=g+gg; b_max=b+bb;
  915.     for (y=0; y<sh; y++, o+=j)
  916.       for (x=0; x<sw; x++, o+=4, i++)
  917.       {
  918.         r=Bmp[2+o]; g=Bmp[1+o]; b=Bmp[o];
  919.         ss[i]=(r>=r_min && r<=r_max
  920.             && g>=g_min && g<=g_max
  921.             && b>=b_min && b<=b_max) ? 1:0;
  922.       }
  923.   }
  924.   // Start Lookup
  925.   sx1=sw-w1; sy1=sh-h1;
  926.   for (y=0; y<=sy1; y++)
  927.   {
  928.     for (x=0; x<=sx1; x++)
  929.     {
  930.       o=y*sw+x; e1=err1; e0=err0;
  931.       if (e0==len0)
  932.       {
  933.         for (i=0; i<len1; i++)
  934.           if (ss[o+s1[i]]!=1 && (--e1)<0)
  935.             goto NoMatch1;
  936.       }
  937.       else
  938.       {
  939.         for (i=0; i<max; i++)
  940.         {
  941.           if (i<len1 && ss[o+s1[i]]!=1 && (--e1)<0)
  942.             goto NoMatch1;
  943.           if (i<len0 && ss[o+s0[i]]!=0 && (--e0)<0)
  944.             goto NoMatch1;
  945.         }
  946.       }
  947.       //------------------
  948.       if (num>7)
  949.       {
  950.         x1=x+w1-1; y1=y-offsetY; if (y1<0) y1=0;
  951.         for (j=7; j<num; j+=7)
  952.         {
  953.           o2=input[j]; w2=input[j+1]; h2=input[j+2];
  954.           len21=input[j+3]; len20=input[j+4];
  955.           err21=input[j+5]; err20=input[j+6];
  956.           sx2=sw-w2; i=x1+offsetX; if (i<sx2) sx2=i;
  957.           sy2=sh-h2; i=y+offsetY; if (i<sy2) sy2=i;
  958.           for (x2=x1; x2<=sx2; x2++)
  959.           {
  960.             for (y2=y1; y2<=sy2; y2++)
  961.             {
  962.               o1=y2*sw+x2; e1=err21; e0=err20;
  963.               for (i=0; i<len21; i++)
  964.               {
  965.                 if (ss[o1+s1[o2+i]]!=1 && (--e1)<0)
  966.                   goto NoMatch2;
  967.               }
  968.               if (e0!=len20)
  969.               {
  970.                 for (i=0; i<len20; i++)
  971.                   if (ss[o1+s0[o2+i]]!=0 && (--e0)<0)
  972.                     goto NoMatch2;
  973.               }
  974.               goto MatchOK;
  975.               NoMatch2:
  976.               continue;
  977.             }
  978.           }
  979.           goto NoMatch1;
  980.           MatchOK:
  981.           x1=x2+w2-1;
  982.         }
  983.       }
  984.       //------------------
  985.       allpos[ok++]=(sy+y)<<16|(sx+x);
  986.       if (ok>=allpos_max)
  987.         goto Return1;
  988.       // Clear the image that has been found
  989.       for (i=0; i<len1; i++)
  990.         ss[o+s1[i]]=0;
  991.       NoMatch1:
  992.       continue;
  993.     }
  994.   }
  995.   Return1:
  996.   return ok;
  997. }
  998.  
  999. */
  1000.  
  1001. ;================= The End =================
  1002.  
  1003. ;
  1004.  
  1005. FindText_Left_Click(Obj,X_Adj=0,Y_Adj=0,Move_Back=0){
  1006. CoordMode, Mouse
  1007. MouseGetPos,Orig_X,Orig_Y
  1008. x:=(obj.1+obj.3//2)+X_Adj
  1009. y:=(obj.2+obj.4//2)+Y_Adj
  1010. Click, %X%,%Y%
  1011. if (Move_Back){
  1012.   Sleep, 30
  1013.   MouseMove, %Orig_X%,%Orig_Y%
  1014. }
  1015. Return
  1016. }
  1017.  
  1018. ;***********Right click*******************
  1019. FindText_Right_Click(Obj,X_Adj=0,Y_Adj=0,Move_Back=0){
  1020. CoordMode, Mouse
  1021. MouseGetPos,Orig_X,Orig_Y
  1022. x:=(obj.1+obj.3//2)+X_Adj
  1023. y:=(obj.2+obj.4//2)+Y_Adj
  1024. Click Right, %X%,%Y%
  1025. if (Move_Back){
  1026.   Sleep, 30
  1027.   MouseMove, %Orig_X%,%Orig_Y%
  1028. }
  1029. Return
  1030. }
  1031.  
  1032. ;***********Double click*******************
  1033. FindText_Double_Click(Obj,X_Adj=0,Y_Adj=0,Move_Back=0){
  1034. CoordMode, Mouse
  1035. MouseGetPos,Orig_X,Orig_Y
  1036. x:=(obj.1+obj.3//2)+X_Adj
  1037. y:=(obj.2+obj.4//2)+Y_Adj
  1038. MouseMove, %X%,%Y%
  1039. Click 2
  1040. if (Move_Back){
  1041.   Sleep, 30
  1042.   MouseMove, %Orig_X%,%Orig_Y%
  1043. }
  1044. }
  1045.  
  1046. ;***********Move mouse to location*******************
  1047. FindText_Move_Mouse(Obj,X_Adj=0,Y_Adj=0){
  1048.   CoordMode, Mouse
  1049. x:=(obj.1+obj.3//2)+X_Adj
  1050. y:=(obj.2+obj.4//2)+Y_Adj
  1051. MouseMove, %X%,%Y%
  1052. }
  1053.  
  1054. ;***********Send text to location*******************
  1055. FindText_Send_Text(Obj,Text,Enter=0,X_Adj=0,Y_Adj=0,Move_Back=0){
  1056. CoordMode, Mouse
  1057. MouseGetPos,Orig_X,Orig_Y
  1058. x:=(obj.1+obj.3//2)+X_Adj
  1059. y:=(obj.2+obj.4//2)+Y_Adj
  1060. MouseMove, %X%,%Y%
  1061. Sleep 30
  1062. Click, %X%,%Y%
  1063. Sleep 30
  1064. SendInput , %Text%
  1065. if (Enter=1)
  1066.   SendInput , {Enter}
  1067. if (Move_Back){
  1068.   Sleep, 30
  1069.   MouseMove, %Orig_X%,%Orig_Y%
  1070. }
  1071. }
  1072.  
  1073.  
  1074. Array_Gui(Array, Parent="") {
  1075.     if !Parent
  1076.     {
  1077.         Gui, +HwndDefault
  1078.         Gui, New, +HwndGuiArray +LabelGuiArray +Resize
  1079.         Gui, Margin, 5, 5
  1080.         Gui, Add, TreeView, w300 h200
  1081.        
  1082.         Item := TV_Add("Array", 0, "+Expand")
  1083.         Array_Gui(Array, Item)
  1084.        
  1085.         Gui, Show,, GuiArray
  1086.         Gui, %Default%:Default
  1087.        
  1088.         WinWait, ahk_id%GuiArray%
  1089.         WinWaitClose, ahk_id%GuiArray%
  1090.         return
  1091.     }
  1092.    
  1093.     For Key, Value in Array
  1094.     {
  1095.         Item := TV_Add(Key, Parent)
  1096.         if (IsObject(Value))
  1097.             Array_Gui(Value, Item)
  1098.         else
  1099.             TV_Add(Value, Item)
  1100.     }
  1101.     return
  1102.    
  1103.     GuiArrayClose:
  1104.     Gui, Destroy
  1105.     return
  1106.    
  1107.     GuiArraySize:
  1108.     GuiControl, Move, SysTreeView321, % "w" A_GuiWidth - 10 " h" A_GuiHeight - 10
  1109.     return
  1110. }
  1111. ; https://p.ahkscript.org/?p=c1fcc762
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement