Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance
  2. #NoEnv
  3.  
  4. Gui, Color, 111111
  5. Gui, Font, cWhite s12 Q5, Segoe UI
  6. Gui, Add, Text,x10 y10 w200 h50 gtest vtest
  7. Gui, Add, Progress,x10 y10 w200 h50 BackgroundBlack vtest_1
  8. Gui, Add, Progress,x10 y10 w198 h49 Background58ACFA vtest_2
  9. Gui, Add, Progress,x12 y12 w196 h46 Background222222 vTest_3
  10. Gui, Add, Text, x12 y24 w196 r1 BackgroundTrans Center vtest_4, Start
  11.  
  12. Gui, Add, Text,x10 y70 w200 h50 gtestt vtestt
  13. Gui, Add, Progress,x10 y70 w200 h50 BackgroundBlack vtestt_1
  14. Gui, Add, Progress,x10 y70 w198 h49 Background58ACFA vtestt_2
  15. Gui, Add, Progress,x12 y72 w196 h46 Background222222 vTestt_3
  16. Gui, Add, Text, x12 y82 w196 r1 BackgroundTrans Center vtestt_4, Settings
  17.  
  18. Gui, Add, Text,x10 y130 w200 h50 gtesttt vtesttt
  19. Gui, Add, Progress,x10 y130 w200 h50 BackgroundBlack vtesttt_1
  20. Gui, Add, Progress,x10 y130 w198 h49 Background58ACFA vtesttt_2
  21. Gui, Add, Progress,x12 y132 w196 h46 Background222222 vTesttt_3
  22. Gui, Add, Text, x12 y142 w196 r1 BackgroundTrans Center vtesttt_4, Close
  23. Gui, +AlwaysOnTop
  24. Gui, 1:Show,w220 h190
  25. return
  26.  
  27. Test:
  28. Sleep 5000
  29. loop {
  30. sleep 250
  31. Click, 316, 746
  32. Sleep 250
  33. ;
  34. ;
  35. ;
  36. ;
  37. ;
  38. ;
  39. ; DIESE ZEILE UNTER MIR BITTE MIT DEINEM PFAD VON DER TXT ÄNDERN!
  40. FileRead, Clipboard, Text.txt
  41. ;
  42. ;
  43. ;
  44. ;
  45. ;
  46. ;
  47. Send, ^v
  48. Sleep 150
  49. Send {Enter}
  50. Sleep 250
  51. Send, {Esc}
  52. Sleep 50
  53. Send, {Esc}
  54. Sleep 50
  55. t1:=A_TickCount
  56.  
  57. Text:="|<>0xFFFFFF@1.00$94.0000000000100003080000000040001+0U00000000E0004c20000000010000GE81U00000M4M0s180UEUUkE080EE884W22120101010U0EG08E0000040420118EV00F8U0U0E0044U27zV4W0201008EG28E04080804021180V000000U0E0844UG400cI0101000EG088021E0404021083UEEA20080E0A430008000004000002"
  58.  
  59. if (ok:=FindText(141-150000//2, 577-150000//2, 150000, 150000, 0, 0, Text))
  60. {
  61.   CoordMode, Mouse
  62.   X:=ok.1.1, Y:=ok.1.2, W:=ok.1.3, H:=ok.1.4, Comment:=ok.1.5, X+=W//2, Y+=H//2
  63.    Click, %X%, %Y%
  64. }
  65. Sleep 750
  66. Send, {Enter}
  67. }
  68.  
  69. Testt:
  70. ;
  71. ;
  72. ;
  73. ;
  74. ;
  75. ;
  76. ; DIESE ZEILE UNTER MIR BITTE MIT DEINEM PFAD VON DER TXT ÄNDERN!
  77. Run, Text.txt
  78. ;
  79. ;
  80. ;
  81. ;
  82. ;
  83. ;
  84. ;
  85. return
  86.  
  87. Testtt:
  88. ExitApp
  89. return
  90.  
  91. F2::
  92. ExitApp
  93. return
  94.  
  95. ;Image search code
  96.  
  97. FindText(x, y, w, h, err1, err0, text, ScreenShot=1)
  98. {
  99.   xywh2xywh(x,y,w,h,x,y,w,h)
  100.   if (w<1 or h<1)
  101.     return, 0
  102.   bch:=A_BatchLines
  103.   SetBatchLines, -1
  104.   ;--------------------------------------
  105.   GetBitsFromScreen(x,y,w,h,Scan0,Stride,ScreenShot,zx,zy)
  106.   ;--------------------------------------
  107.   sx:=x-zx, sy:=y-zy, sw:=w, sh:=h, arr:=[]
  108.   Loop, 2 {
  109.   Loop, Parse, text, |
  110.   {
  111.     v:=A_LoopField
  112.     IfNotInString, v, $, Continue
  113.     comment:="", e1:=err1, e0:=err0
  114.     ; You Can Add Comment Text within The <>
  115.     if RegExMatch(v,"<([^>]*)>",r)
  116.       v:=StrReplace(v,r), comment:=Trim(r1)
  117.     ; You can Add two fault-tolerant in the [], separated by commas
  118.     if RegExMatch(v,"\[([^\]]*)]",r)
  119.     {
  120.       v:=StrReplace(v,r), r1.=","
  121.       StringSplit, r, r1, `,
  122.       e1:=r1, e0:=r2
  123.     }
  124.     StringSplit, r, v, $
  125.     color:=r1, v:=r2
  126.     StringSplit, r, v, .
  127.     w1:=r1, v:=base64tobit(r2), h1:=StrLen(v)//w1
  128.     if (r0<2 or h1<1 or w1>sw or h1>sh or StrLen(v)!=w1*h1)
  129.       Continue
  130.     ;--------------------------------------
  131.     mode:=InStr(color,"*") ? 2 : !InStr(color,"#") ? 1 : 0
  132.     color:=RegExReplace(color,"[*#]") . "@"
  133.     StringSplit, r, color, @
  134.     color:=mode=0 ? ((r1-1)//w1)*Stride+Mod(r1-1,w1)*4 : r1
  135.     n:=Round(r2,2)+(!r2), n:=Floor(255*3*(1-n))
  136.     StrReplace(v,"1","",len1), len0:=StrLen(v)-len1
  137.     e1:=Round(len1*e1), e0:=Round(len0*e0)
  138.     VarSetCapacity(ss, sw*sh, 0), k:=StrLen(v)*4
  139.     VarSetCapacity(s1, k, 0), VarSetCapacity(s0, k, 0)
  140.     VarSetCapacity(allpos, 1024*4, 0)
  141.     ;--------------------------------------
  142.     if (ok:=PicFind(mode,color,n,Scan0,Stride
  143.       ,sx,sy,sw,sh,ss,v,s1,s0,e1,e0,w1,h1,allpos))
  144.     {
  145.       Loop, % ok
  146.         pos:=NumGet(allpos, 4*(A_Index-1), "uint")
  147.         , rx:=(pos&0xFFFF)+zx, ry:=(pos>>16)+zy
  148.         , arr.Push( [rx,ry,w1,h1,comment] )
  149.     }
  150.   }
  151.   if (err1=0 and err0=0 and !arr.MaxIndex())
  152.     err1:=err0:=0.1
  153.   else Break
  154.   }
  155.   SetBatchLines, %bch%
  156.   return, arr.MaxIndex() ? arr:0
  157. }
  158.  
  159. PicFind(mode, color, n, Scan0, Stride, sx, sy, sw, sh
  160.   , ByRef ss, ByRef text, ByRef s1, ByRef s0
  161.   , err1, err0, w1, h1, ByRef allpos)
  162. {
  163.   static MyFunc, Ptr:=A_PtrSize ? "UPtr" : "UInt"
  164.   if !MyFunc
  165.   {
  166.     x32:="5557565383EC3C8B9C24900000008B7C245085DB0F8EF20"
  167.     . "60000C744241400000000C74424100000000031F6C744240C0"
  168.     . "0000000C744240800000000C7442418000000008B4C24108BA"
  169.     . "C248C0000008B5C24188B54241401CD89C829CB8B8C248C000"
  170.     . "000035C247885C97E67892C2489F989D5895C2404EB1F8DB42"
  171.     . "6000000008B9C248000000083C50483C0018914B383C601390"
  172.     . "424742E8B7C240485C989EA0F45D0803C073175D78B5C24088"
  173.     . "B7C247C83C50483C00139042489149F8D7B01897C240875D28"
  174.     . "B9C248C000000015C241889CF8344240C018B4C246C8B44240"
  175.     . "C014C24108B4C2460014C2414398424900000000F854BFFFFF"
  176.     . "F8B44240839F00F4CC689042485FF0F85D80100008B44246C0"
  177.     . "34424642B84248C000000894424288B442468034424702B842"
  178.     . "49000000039442468894424380F8F960500008B4424608B7C2"
  179.     . "4640FAF442468897424148B74245CC744242C000000008D04B"
  180.     . "803442454894424348B442428394424640F8F4E0100008B442"
  181.     . "468C1E010894424308B442434894424248B442464894424186"
  182.     . "6908B4424248B2C240FB65C060289C72B7C245485ED895C240"
  183.     . "40FB65C06010FB60406895C240C894424100F84B60300008B8"
  184.     . "4248800000031DB894424208B8424840000008944241CEB738"
  185.     . "DB426000000003B5C24147D5A8B8424800000008B149801FA0"
  186.     . "FB64C16020FB64416012B4C24042B44240C0FB614162B54241"
  187.     . "089CDC1FD1F31E929E989C5C1FD1F31E829E889D5C1FD1F01C"
  188.     . "131EA29EA01CA395424587C0F836C2420017871908DB426000"
  189.     . "0000083C3013B1C240F84290300003B5C24087D8E8B4C247C8"
  190.     . "B049901F80FB64C06020FB65406012B4C24042B54240C0FB60"
  191.     . "4062B44241089CDC1FD1F31E929E989D5C1FD1F31EA29EA89C"
  192.     . "5C1FD1F01D131E829E801C83B4424580F8E42FFFFFF836C241"
  193.     . "C010F8937FFFFFF834424180183442424048B4424183944242"
  194.     . "80F8DCFFEFFFF83442468018B7C24608B442438017C24343B4"
  195.     . "424680F8D89FEFFFF8B54242CE90A0200008B4424608B5C246"
  196.     . "40FAF4424688B54246CF7DA83FF018D04988B5C24608D1C938"
  197.     . "95C24140F84D90200008B7C2454C744240400000000C744240"
  198.     . "C000000008D570169FAE80300008B54247089FB8B7C246CC1E"
  199.     . "70285D2897C24107E7B8974241889DF89C58DB426000000008"
  200.     . "B44246C85C07E4D8B4C245C8B5C240C8B74245C035C247401E"
  201.     . "9036C241001EE0FB651020FB6410169D22B01000069C04B020"
  202.     . "00001C20FB6016BC07201D039C70F970383C10483C30139F17"
  203.     . "5D38B74246C0174240C8344240401036C24148B44240439442"
  204.     . "47075988B7424188B44246C2B84248C000000894424188B442"
  205.     . "4702B842490000000894424300F88F30200008B4424688B542"
  206.     . "40889F78B6C247CC744241C00000000C744242C00000000C74"
  207.     . "4242000000000894424288B44241885C00F88B50000008B442"
  208.     . "428C744240400000000C1E010894424248B442464894424148"
  209.     . "B4424040344241C39BC248800000089C3894424100F84B4000"
  210.     . "0008B8424880000008B3424035C24748B8C248400000089442"
  211.     . "40C31C085F60F8434010000894C2408EB2839F87D188B8C248"
  212.     . "00000008B348101DE803E007407836C240C01782283C0013B0"
  213.     . "4240F840601000039D07DD48B74850001DE803E0174C9836C2"
  214.     . "4080179C2834424040183442414018B442404394424180F8D6"
  215.     . "6FFFFFF8344242C018B5C246C8B44242C015C241C834424280"
  216.     . "1394424300F8D1FFFFFFF8B54242083C43C89D05B5E5F5DC24"
  217.     . "800908D74260085D20F84D20100008B7424748B5C241031C08"
  218.     . "B8C248400000001F38B74850001DE803E01740583E90178888"
  219.     . "3C00139D075E98B7424208B8C249400000089F083C00189442"
  220.     . "4208B4424140B442424817C2420FF0300008904B17F9031C08"
  221.     . "D76008B4C850083C00101D939D0C601007CF0E93EFFFFFF8B7"
  222.     . "C242C8B4424300B4424188B9C24940000008D570181FAFF030"
  223.     . "0008904BB0F8F55FFFFFF8954242CE906FDFFFF8B7424208B9"
  224.     . "C249400000089F083C00189C1894424208B4424140B4424248"
  225.     . "1F9FF0300008904B30F8F1BFFFFFF85D20F84DBFEFFFF8B442"
  226.     . "4748B7424108D1C30E973FFFFFF8B5424548B5C2454C744241"
  227.     . "800000000C744241C00000000C1EA100FB6FA897C24040FB6F"
  228.     . "F8B5C2470897C240C0FB67C2454897C24108B7C246CC1E7028"
  229.     . "5DB897C24240F8E8BFDFFFF897424288B4C246C85C97E768B5"
  230.     . "C245C8B74241C8B6C245C0374247401C303442424894424200"
  231.     . "1C58DB426000000000FB64B020FB653012B4C24042B54240C0"
  232.     . "FB6032B44241089CFC1FF1F31F929F989D7C1FF1F31FA29FA8"
  233.     . "9C7C1FF1F01D131F829F801C8394424580F9D0683C30483C60"
  234.     . "139DD75B98B74246C0174241C8B44242083442418010344241"
  235.     . "48B7C2418397C24700F856BFFFFFF8B742428E9E9FCFFFF31D"
  236.     . "2E915FEFFFF8B7424208B9C249400000089F083C00189C1894"
  237.     . "424208B4424140B44242481F9FF0300008904B30F8EACFDFFF"
  238.     . "FE9DFFDFFFFC704240000000031F6C744240800000000E9E3F"
  239.     . "9FFFF9090909090909090909090909090"
  240.     x64:="4157415641554154555756534883EC38448BA424B800000"
  241.     . "04C8BBC24E00000004C89CD448B8C240001000089542410448"
  242.     . "98424900000004585C90F8ED10700004889AC2498000000448"
  243.     . "9A424B800000031FF488BAC24D8000000448BA424F80000003"
  244.     . "1DB31F64531F64531EDC7442408000000004585E47E6248635"
  245.     . "42408458D1C1C89D848039424D00000004189F8EB1B83C0014"
  246.     . "D63D64183C0044183C6014883C2014139C347890C97742A85C"
  247.     . "94589C1440F45C8803A3175D783C0014D63D54183C0044183C"
  248.     . "5014883C2014139C346894C950075D6440164240883C601039"
  249.     . "C24B800000003BC24A000000039B424000100000F857BFFFFF"
  250.     . "F4539F54489F0488BAC2498000000448BA424B8000000410F4"
  251.     . "DC58944242485C90F854F0200008B8424B0000000038424C00"
  252.     . "000004403A424A80000002B842400010000442BA424F800000"
  253.     . "0398424B00000008944242C448964241C0F8F800600008B842"
  254.     . "4A00000008BB424A80000000FAF8424B0000000448B6424244"
  255.     . "C89BC24E00000004589EFC7442420000000008D04B00344241"
  256.     . "0894424288B44241C398424A80000000F8F910100008B8424B"
  257.     . "0000000448B6C2428C1E010894424248B8424A800000089442"
  258.     . "408418D45024489EF2B7C24104585E44898440FB65C0500418"
  259.     . "D450148980FB65C05004963C50FB67405000F846F0400008B8"
  260.     . "424F00000004531C0894424188B8424E80000008944240CE98"
  261.     . "E000000904539CE7E7B488B8C24E0000000428B048101F88D5"
  262.     . "0024863D20FB64C15008D500148980FB64405004863D20FB65"
  263.     . "415004429D94189C929F041C1F91F29DA4431C94429C94189D"
  264.     . "141C1F91F4431CA4429CA4189C141C1F91F01D14431C84429C"
  265.     . "801C8398424900000007C15836C2418010F8898000000662E0"
  266.     . "F1F8400000000004983C0014539C40F8EC30300004539C7458"
  267.     . "9C10F8E67FFFFFF488B8C24D8000000428B048101F88D50024"
  268.     . "863D20FB64C15008D500148980FB64405004863D20FB654150"
  269.     . "04429D94189CA29F041C1FA1F29DA4431D14429D14189D241C"
  270.     . "1FA1F4431D24429D24189C241C1FA1F01D14431D04429D001C"
  271.     . "83B8424900000000F8EFDFEFFFF836C240C010F89F2FEFFFF8"
  272.     . "3442408014183C5048B4424083944241C0F8D8DFEFFFF83842"
  273.     . "4B0000000018BB424A00000008B44242C017424283B8424B00"
  274.     . "000000F8D3AFEFFFF8B4424204883C4385B5E5F5D415C415D4"
  275.     . "15E415FC38B8424A00000008BB424A80000000FAF8424B0000"
  276.     . "0008D04B08BB424A000000089C24489E0F7D883F9018D04868"
  277.     . "94424080F842B030000448B5424108B8C24C00000004531DB3"
  278.     . "1F6428D3CA5000000004183C2014569D2E803000085C90F8EA"
  279.     . "500000044896C240C448974241889D34C89BC24E0000000448"
  280.     . "B6C2408448BB424C00000004C8BBC24C8000000660F1F44000"
  281.     . "04585E47E534863C34C63CE4531C0488D4C05024D01F9662E0"
  282.     . "F1F8400000000000FB6110FB641FF69D22B01000069C04B020"
  283.     . "00001C20FB641FE6BC07201D04139C2430F9704014983C0014"
  284.     . "883C1044539C47FCD01FB4401E64183C3014401EB4539DE759"
  285.     . "C448B6C240C448B7424184C8BBC24E00000004489E58B8424C"
  286.     . "00000002BAC24F80000002B8424000100008944242C0F88420"
  287.     . "300008B8424B0000000488BB424D800000031FF897C240C448"
  288.     . "B5C24244C8B8C24C80000008BBC24F000000089442420418D4"
  289.     . "5FF896C2408C744242800000000C7442418000000004889F54"
  290.     . "88D4486044489A424B800000048894424108B44240885C00F8"
  291.     . "89E0000008B442420448BA424A800000031DBC1E0108944241"
  292.     . "C8B44240C4439F7448D04030F84AC00000031C04585DB89FE4"
  293.     . "48B9424E80000007538E957010000660F1F4400004439F17D1"
  294.     . "B418B14874401C24863D241803C1100740A83EE0178300F1F4"
  295.     . "400004883C0014139C30F8E240100004439E889C17DCC8B548"
  296.     . "5004401C24863D241803C110174BB4183EA0179B583C301418"
  297.     . "3C401395C24080F8D77FFFFFF83442428018B9C24B80000008"
  298.     . "B442428015C240C83442420013944242C0F8D33FFFFFF8B442"
  299.     . "418E995FDFFFF0F1F8400000000004585ED0F84080200008B8"
  300.     . "C24E80000004C8B5424104889EA8B024401C0489841803C010"
  301.     . "1740583E90178904883C2044C39D275E448635424188B4C241"
  302.     . "C488BB424080100004409E189D0890C9683C0013DFF0300000"
  303.     . "F8F32FDFFFF8944241831C08B5485004883C0014401C24139C"
  304.     . "54863D241C60411007FE883C3014183C401395C24080F8DB9F"
  305.     . "EFFFFE93DFFFFFF9048635424208B4C24240B4C2408488BB42"
  306.     . "40801000089D083C001890C963DFF0300000F8FD5FCFFFF894"
  307.     . "42420E98DFCFFFF48635424188B4C241C488BB424080100004"
  308.     . "409E189D0890C9683C0013DFF0300000F8FA5FCFFFF4585ED8"
  309.     . "94424180F856AFFFFFFE9C1FEFFFF660F1F4400008B7424104"
  310.     . "48B8424C000000031C94531DB4889F089F3400FB6F60FB6FC4"
  311.     . "28D04A500000000C1EB104585C00FB6DB8944240C0F8E6EFDF"
  312.     . "FFF4889AC24980000008BAC249000000044896C24184489742"
  313.     . "4104189D54C89BC24E00000004189CE4589DF4585E47E75488"
  314.     . "B8C24980000004D63DF4C039C24C80000004963C54531C94C8"
  315.     . "D440102410FB608410FB650FF410FB640FE29D929FA4189CA2"
  316.     . "9F041C1FA1F4431D14429D14189D241C1FA1F4431D24429D20"
  317.     . "1CA89C1C1F91F31C829C801D039C5430F9D040B4983C101498"
  318.     . "3C0044539CC7FB144036C240C4501E74183C60144036C24084"
  319.     . "439B424C00000000F856FFFFFFF448B6C2418448B7424104C8"
  320.     . "BBC24E0000000E99CFCFFFF31C0E97CFBFFFF48635424188B4"
  321.     . "C241C488BB424080100004409E189D0890C9683C0013DFF030"
  322.     . "0000F8F55FBFFFF89442418E97AFDFFFFC7442424000000004"
  323.     . "531F64531EDE9F3F8FFFF909090909090909090909090"
  324.     MCode(MyFunc, A_PtrSize=8 ? x64:x32)
  325.   }
  326.   return, DllCall(&MyFunc
  327.     , "int",mode, "uint",color, "int",n, Ptr,Scan0
  328.     , "int",Stride, "int",sx, "int",sy, "int",sw, "int",sh
  329.     , Ptr,&ss, "AStr",text, Ptr,&s1, Ptr,&s0
  330.     , "int",err1, "int",err0, "int",w1, "int",h1, Ptr,&allpos)
  331. }
  332.  
  333. xywh2xywh(x1,y1,w1,h1,ByRef x,ByRef y,ByRef w,ByRef h)
  334. {
  335.   SysGet, zx, 76
  336.   SysGet, zy, 77
  337.   SysGet, zw, 78
  338.   SysGet, zh, 79
  339.   left:=x1, right:=x1+w1-1, up:=y1, down:=y1+h1-1
  340.   left:=left<zx ? zx:left, right:=right>zx+zw-1 ? zx+zw-1:right
  341.   up:=up<zy ? zy:up, down:=down>zy+zh-1 ? zy+zh-1:down
  342.   x:=left, y:=up, w:=right-left+1, h:=down-up+1
  343. }
  344.  
  345. GetBitsFromScreen(x, y, w, h, ByRef Scan0, ByRef Stride
  346.   , ScreenShot=1, ByRef zx="", ByRef zy="")
  347. {
  348.   static bits, bpp, oldx, oldy, oldw, oldh
  349.   if (ScreenShot or x<oldx or y<oldy
  350.     or x+w>oldx+oldw or y+h>oldy+oldh)
  351.   {
  352.     oldx:=x, oldy:=y, oldw:=w, oldh:=h, ScreenShot:=1
  353.     VarSetCapacity(bits, w*h*4), bpp:=32
  354.   }
  355.   Scan0:=&bits, Stride:=((oldw*bpp+31)//32)*4, zx:=oldx, zy:=oldy
  356.   if (!ScreenShot or w*h<1)
  357.     return
  358.   Ptr:=A_PtrSize ? "UPtr" : "UInt", PtrP:=Ptr . "*"
  359.   win:=DllCall("GetDesktopWindow", Ptr)
  360.   hDC:=DllCall("GetWindowDC", Ptr,win, Ptr)
  361.   mDC:=DllCall("CreateCompatibleDC", Ptr,hDC, Ptr)
  362.   ;-------------------------
  363.   VarSetCapacity(bi, 40, 0), NumPut(40, bi, 0, "int")
  364.   NumPut(w, bi, 4, "int"), NumPut(-h, bi, 8, "int")
  365.   NumPut(1, bi, 12, "short"), NumPut(bpp, bi, 14, "short")
  366.   ;-------------------------
  367.   if hBM:=DllCall("CreateDIBSection", Ptr,mDC, Ptr,&bi
  368.     , "int",0, PtrP,ppvBits, Ptr,0, "int",0, Ptr)
  369.   {
  370.     oBM:=DllCall("SelectObject", Ptr,mDC, Ptr,hBM, Ptr)
  371.     DllCall("BitBlt", Ptr,mDC, "int",0, "int",0, "int",w, "int",h
  372.       , Ptr,hDC, "int",x, "int",y, "uint",0x00CC0020|0x40000000)
  373.     DllCall("RtlMoveMemory", Ptr,Scan0, Ptr,ppvBits, Ptr,Stride*h)
  374.     DllCall("SelectObject", Ptr,mDC, Ptr,oBM)
  375.     DllCall("DeleteObject", Ptr,hBM)
  376.   }
  377.   DllCall("DeleteDC", Ptr,mDC)
  378.   DllCall("ReleaseDC", Ptr,win, Ptr,hDC)
  379. }
  380.  
  381. MCode(ByRef code, hex)
  382. {
  383.   bch:=A_BatchLines
  384.   SetBatchLines, -1
  385.   VarSetCapacity(code, len:=StrLen(hex)//2)
  386.   Loop, % len
  387.     NumPut("0x" SubStr(hex,2*A_Index-1,2),code,A_Index-1,"uchar")
  388.   Ptr:=A_PtrSize ? "UPtr" : "UInt", PtrP:=Ptr . "*"
  389.   DllCall("VirtualProtect",Ptr,&code, Ptr,len,"uint",0x40,PtrP,0)
  390.   SetBatchLines, %bch%
  391. }
  392.  
  393. base64tobit(s)
  394. {
  395.   Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  396.     . "abcdefghijklmnopqrstuvwxyz"
  397.   SetFormat, IntegerFast, d
  398.   StringCaseSense, On
  399.   Loop, Parse, Chars
  400.   {
  401.     i:=A_Index-1, v:=(i>>5&1) . (i>>4&1)
  402.       . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
  403.     s:=StrReplace(s,A_LoopField,v)
  404.   }
  405.   StringCaseSense, Off
  406.   s:=SubStr(s,1,InStr(s,"1",0,0)-1)
  407.   s:=RegExReplace(s,"[^01]+")
  408.   return, s
  409. }
  410.  
  411. bit2base64(s)
  412. {
  413.   s:=RegExReplace(s,"[^01]+")
  414.   s.=SubStr("100000",1,6-Mod(StrLen(s),6))
  415.   s:=RegExReplace(s,".{6}","|$0")
  416.   Chars:="0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZ"
  417.     . "abcdefghijklmnopqrstuvwxyz"
  418.   SetFormat, IntegerFast, d
  419.   Loop, Parse, Chars
  420.   {
  421.     i:=A_Index-1, v:="|" . (i>>5&1) . (i>>4&1)
  422.       . (i>>3&1) . (i>>2&1) . (i>>1&1) . (i&1)
  423.     s:=StrReplace(s,v,A_LoopField)
  424.   }
  425.   return, s
  426. }
  427.  
  428. ASCII(s)
  429. {
  430.   if RegExMatch(s,"\$(\d+)\.([\w+/]+)",r)
  431.   {
  432.     s:=RegExReplace(base64tobit(r2),".{" r1 "}","$0`n")
  433.     s:=StrReplace(StrReplace(s,"0","_"),"1","0")
  434.   }
  435.   else s=
  436.   return, s
  437. }
  438.  
  439. ; You can put the text library at the beginning of the script,
  440. ; and Use Pic(Text,1) to add the text library to Pic()'s Lib,
  441. ; Use Pic("comment1|comment2|...") to get text images from Lib
  442.  
  443. Pic(comments, add_to_Lib=0)
  444. {
  445.   static Lib:=[]
  446.   if (add_to_Lib)
  447.   {
  448.     re:="<([^>]*)>[^$]+\$\d+\.[\w+/]+"
  449.     Loop, Parse, comments, |
  450.       if RegExMatch(A_LoopField,re,r)
  451.         Lib[Trim(r1)]:=r
  452.     Lib[""]:=""
  453.   }
  454.   else
  455.   {
  456.     Text:=""
  457.     Loop, Parse, comments, |
  458.       Text.="|" . Lib[Trim(A_LoopField)]
  459.     return, Text
  460.   }
  461. }
  462.  
  463. PicN(Number)
  464. {
  465.   return, Pic( RegExReplace(Number, ".", "|$0") )
  466. }
  467.  
  468. ; Use PicX(Text) to automatically cut into multiple characters
  469.  
  470. PicX(Text)
  471. {
  472.   if !RegExMatch(Text,"\|([^$]+)\$(\d+)\.([\w+/]+)",r)
  473.     return, Text
  474.   w:=r2, v:=base64tobit(r3), Text:=""
  475.   c:=StrLen(StrReplace(v,"0"))<=StrLen(v)//2 ? "1":"0"
  476.   wz:=RegExReplace(v,".{" w "}","$0`n")
  477.   SetFormat, IntegerFast, d
  478.   While InStr(wz,c) {
  479.     While !(wz~="m`n)^" c)
  480.       wz:=RegExReplace(wz,"m`n)^.")
  481.     i:=0
  482.     While (wz~="m`n)^.{" i "}" c)
  483.       i++
  484.     v:=RegExReplace(wz,"m`n)^(.{" i "}).*","$1")
  485.     wz:=RegExReplace(wz,"m`n)^.{" i "}")
  486.     if v!=
  487.       Text.="|" r1 "$" i "." bit2base64(v)
  488.   }
  489.   return, Text
  490. }
  491.  
  492. ; Screenshot and retained as the last screenshot.
  493.  
  494. ScreenShot()
  495. {
  496.   n:=150000
  497.   xywh2xywh(-n,-n,2*n+1,2*n+1,x,y,w,h)
  498.   GetBitsFromScreen(x,y,w,h,Scan0,Stride,1)
  499. }
  500.  
  501. FindTextOCR(nX, nY, nW, nH, err1, err0, Text, Interval=20)
  502. {
  503.   OCR:="", RightX:=nX+nW-1, ScreenShot()
  504.   While (ok:=FindText(nX, nY, nW, nH, err1, err0, Text, 0))
  505.   {
  506.     For k,v in ok
  507.     {
  508.       ; X is the X coordinates of the upper left corner
  509.       ; and W is the width of the image have been found
  510.       x:=v.1, y:=v.2, w:=v.3, h:=v.4, comment:=v.5
  511.       ; We need the leftmost X coordinates
  512.       if (A_Index=1 or x<LeftX)
  513.         LeftX:=x, LeftY:=y, LeftW:=w, LeftH:=h, LeftOCR:=comment
  514.       else if (x=LeftX)
  515.       {
  516.         Loop, 100
  517.         {
  518.           err:=A_Index/100
  519.           if FindText(x, y, w, h, err, err, Text, 0)
  520.           {
  521.             LeftX:=x, LeftY:=y, LeftW:=w, LeftH:=h, LeftOCR:=comment
  522.             Break
  523.           }
  524.           if FindText(LeftX, LeftY, LeftW, LeftH, err, err, Text, 0)
  525.             Break
  526.         }
  527.       }
  528.     }
  529.     ; If the interval exceeds the set value, add "*" to the result
  530.     OCR.=(A_Index>1 and LeftX-nX-1>Interval ? "*":"") . LeftOCR
  531.     ; Update nX and nW for next search
  532.     nX:=LeftX+LeftW-1, nW:=RightX-nX+1
  533.   }
  534.   return, OCR
  535. }
  536.  
  537. ; Reordering the objects returned from left to right,
  538. ; from top to bottom, ignore slight height difference
  539.  
  540. SortOK(ok, dy=10) {
  541.   if !IsObject(ok)
  542.     return, ok
  543.   SetFormat, IntegerFast, d
  544.   For k,v in ok
  545.   {
  546.     x:=v.1+v.3//2, y:=v.2+v.4//2
  547.     y:=A_Index>1 and Abs(y-lasty)<dy ? lasty : y, lasty:=y
  548.     n:=(y*150000+x) "." k, s:=A_Index=1 ? n : s "-" n
  549.   }
  550.   Sort, s, N D-
  551.   ok2:=[]
  552.   Loop, Parse, s, -
  553.     ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
  554.   return, ok2
  555. }
  556.  
  557. ; Reordering according to the nearest distance
  558.  
  559. SortOK2(ok, px, py) {
  560.   if !IsObject(ok)
  561.     return, ok
  562.   SetFormat, IntegerFast, d
  563.   For k,v in ok
  564.   {
  565.     x:=v.1+v.3//2, y:=v.2+v.4//2
  566.     n:=((x-px)**2+(y-py)**2) "." k
  567.     s:=A_Index=1 ? n : s "-" n
  568.   }
  569.   Sort, s, N D-
  570.   ok2:=[]
  571.   Loop, Parse, s, -
  572.     ok2.Push( ok[(StrSplit(A_LoopField,".")[2])] )
  573.   return, ok2
  574. }
  575.  
  576. ; Prompt mouse position in remote assistance
  577.  
  578. MouseTip() {
  579.   VarSetCapacity(pt,16,0), DllCall("GetCursorPos","ptr",&pt)
  580.   x:=NumGet(pt,0,"uint"), y:=NumGet(pt,4,"uint")+NumGet(pt,8,"uint")
  581.   x:=Round(x-10), y:=Round(y-10), w:=h:=2*10+1
  582.   ;-------------------------
  583.   Gui, _MouseTip_: +AlwaysOnTop -Caption +ToolWindow +Hwndmyid +E0x08000000
  584.   Gui, _MouseTip_: Show, Hide w%w% h%h%
  585.   ;-------------------------
  586.   dhw:=A_DetectHiddenWindows
  587.   DetectHiddenWindows, On
  588.   d:=4, i:=w-d, j:=h-d
  589.   s=0-0 %w%-0 %w%-%h% 0-%h% 0-0
  590.   s=%s%  %d%-%d% %i%-%d% %i%-%j% %d%-%j% %d%-%d%
  591.   WinSet, Region, %s%, ahk_id %myid%
  592.   DetectHiddenWindows, %dhw%
  593.   ;-------------------------
  594.   Gui, _MouseTip_: Show, NA x%x% y%y%
  595.   Loop, 4 {
  596.     Gui, _MouseTip_: Color, % A_Index & 1 ? "Red" : "Blue"
  597.     Sleep, 500
  598.   }
  599.   Gui, _MouseTip_: Destroy
  600. }
  601.  
  602. ; Note: This function is used for combination lookup,
  603. ; for example, a 0-9 text library has been set up,
  604. ; then any ID number can be found.
  605. ; Use Pic(Text,1) and PicN(number) when using.
  606. ; Use PicX(Text) to automatically cut into multiple characters.
  607. ; Color position mode is not supported.
  608.  
  609. FindText2(x, y, w, h, err1, err0, text, ScreenShot=1, Interval=20)
  610. {
  611.   xywh2xywh(x,y,w,h,x,y,w,h)
  612.   if (w<1 or h<1)
  613.     return, 0
  614.   bch:=A_BatchLines
  615.   SetBatchLines, -1
  616.   ;--------------------------------------
  617.   GetBitsFromScreen(x,y,w,h,Scan0,Stride,ScreenShot,zx,zy)
  618.   ;--------------------------------------
  619.   sx:=x-zx, sy:=y-zy, sw:=w, sh:=h, arr:=[]
  620.   info:=[], allw:=-1, allv:=allcolor:=allcomment:=""
  621.   if (err1=0 and err0=0)
  622.     err1:=err0:=0.1
  623.   Loop, Parse, text, |
  624.   {
  625.     v:=A_LoopField
  626.     IfNotInString, v, $, Continue
  627.     comment:="", e1:=err1, e0:=err0
  628.     ; You Can Add Comment Text within The <>
  629.     if RegExMatch(v,"<([^>]*)>",r)
  630.       v:=StrReplace(v,r), comment:=Trim(r1)
  631.     ; You can Add two fault-tolerant in the [], separated by commas
  632.     if RegExMatch(v,"\[([^\]]*)]",r)
  633.     {
  634.       v:=StrReplace(v,r), r1.=","
  635.       StringSplit, r, r1, `,
  636.       e1:=r1, e0:=r2
  637.     }
  638.     StringSplit, r, v, $
  639.     color:=r1, v:=r2
  640.     IfInString, color, #, Continue
  641.     StringSplit, r, v, .
  642.     w1:=r1, v:=base64tobit(r2), h1:=StrLen(v)//w1
  643.     if (r0<2 or h1<1 or w1>sw or h1>sh or StrLen(v)!=w1*h1)
  644.       Continue
  645.     if (allcolor="")
  646.     {
  647.       mode:=InStr(color,"*") ? 1 : 0
  648.       color:=StrReplace(color,"*") . "@"
  649.       StringSplit, r, color, @
  650.       allcolor:=r1, n:=Round(r2,2)+(!r2), n:=Floor(255*3*(1-n))
  651.     }
  652.     StrReplace(v,"1","",len1), len0:=StrLen(v)-len1
  653.     e1:=Round(len1*e1), e0:=Round(len0*e0)
  654.     info.Push(StrLen(allv),w1,h1,len1,len0,e1,e0)
  655.     allv.=v, allw+=w1+1, allcomment.=comment
  656.   }
  657.   if (allv="")
  658.   {
  659.     SetBatchLines, %bch%
  660.     return, 0
  661.   }
  662.   num:=info.MaxIndex(), VarSetCapacity(in,num*4,0)
  663.   Loop, % num
  664.     NumPut(info[A_Index], in, 4*(A_Index-1), "int")
  665.   VarSetCapacity(ss, sw*sh, 0), k:=StrLen(allv)*4
  666.   VarSetCapacity(s1, k, 0), VarSetCapacity(s0, k, 0)
  667.   VarSetCapacity(allpos, 1024*4, 0)
  668.   offsetX:=Interval, offsetY:=5
  669.   ;--------------------------------------
  670.   if (ok:=PicFind2(mode,allcolor,n,Scan0,Stride,sx,sy,sw,sh
  671.     ,ss,allv,s1,s0,in,num,offsetX,offsetY,allpos))
  672.   {
  673.     Loop, % ok
  674.       pos:=NumGet(allpos, 4*(A_Index-1), "uint")
  675.       , rx:=(pos&0xFFFF)+zx, ry:=(pos>>16)+zy
  676.       , arr.Push( [rx,ry,allw,h1,allcomment] )
  677.   }
  678.   SetBatchLines, %bch%
  679.   return, arr.MaxIndex() ? arr:0
  680. }
  681.  
  682. PicFind2(mode, color, n, Scan0, Stride, sx, sy, sw, sh
  683.   , ByRef ss, ByRef text, ByRef s1, ByRef s0
  684.   , ByRef in, num, offsetX, offsetY, ByRef allpos)
  685. {
  686.   static MyFunc, Ptr:=A_PtrSize ? "UPtr" : "UInt"
  687.   if !MyFunc
  688.   {
  689.     x32:="5557565383EC7C8B8424C8000000C7442414000000008BB"
  690.     . "C24C000000085C00F8EBA0000008B4424148BB424C40000008"
  691.     . "B3486897424088BB424C40000008B5486048B44860885C0895"
  692.     . "42404894424107E778B74240831EDC704240000000089F28B4"
  693.     . "4240485C07E4C8B4C24088D1C28896C240C89E829E9038C24B"
  694.     . "8000000EB0D89049783C00183C20139C3741B803C013175ED8"
  695.     . "BAC24BC0000008944B50083C00183C60139C375E58B5C24040"
  696.     . "15C24088B6C240C8304240103AC24AC0000008B04243944241"
  697.     . "0759883442414078B442414398424C80000000F8F46FFFFFF8"
  698.     . "B8424A80000008BB424A40000000FAF8424A00000008B9424A"
  699.     . "00000008D3CB08B8424AC000000F7D88D0482894424108B842"
  700.     . "49000000085C00F85440500008B842494000000C744240C000"
  701.     . "00000C744241400000000C1E8100FB6C08904248B842494000"
  702.     . "0000FB6C4894424040FB6842494000000894424088B8424AC0"
  703.     . "00000C1E0028944241C8B8424B000000085C00F8E9E0000008"
  704.     . "B8424AC00000085C07E798B9C249C0000008B7424148BAC249"
  705.     . "C00000003B424B400000001FB037C241C897C241801FD0FB64"
  706.     . "B020FB653012B0C242B5424040FB6032B44240889CFC1FF1F3"
  707.     . "1F929F989D7C1FF1F31FA29FA01D19931D029D001C83B84249"
  708.     . "80000000F9E0683C30483C60139DD75BB8B9424AC000000015"
  709.     . "424148B7C24188344240C01037C24108B44240C398424B0000"
  710.     . "0000F8562FFFFFF8B9C24C40000008B8424C40000008BB424C"
  711.     . "40000008B9424C40000008B5B148B40048B760C8B5210895C2"
  712.     . "42C8B9C24C400000089742428895424108B5B18895C24248B9"
  713.     . "C24AC00000029C339D60F4DD68BB424C4000000895C2420895"
  714.     . "424088B9424B00000002B56088954246C0F889B0400008B942"
  715.     . "4BC0000008B74242883E801C744241C00000000C7442460000"
  716.     . "00000C744247400000000894424648D14B2895424788B44242"
  717.     . "085C00F88E70000008B5424608B8424A8000000C7442404000"
  718.     . "0000001D0C1E0108944247089D02B9424D000000089D6BA000"
  719.     . "000000F49D6895424580FAF9424AC0000008954245C8B9424D"
  720.     . "000000001C289542468908B4424040344241C89C1894424188"
  721.     . "B442424394424100F84B40000008B5C240889C6038C24B4000"
  722.     . "00031C08B54242C85DB0F8ED10000008934248B5C24288B6C2"
  723.     . "410EB2939C57E188BB424C00000008B3C8601CF803F0074078"
  724.     . "32C240178289083C001394424080F849B00000039C37ED38BB"
  725.     . "424BC0000008B3C8601CF803F0174C283EA0179BD834424040"
  726.     . "18B442404394424200F8D66FFFFFF83442460018B9424AC000"
  727.     . "0008B4424600154241C3944246C0F8DEFFEFFFF8B4C247483C"
  728.     . "47C89C85B5E5F5DC24800908DB426000000008B7C242885FF7"
  729.     . "E308BB424B40000008B5C241831C08B54242C01F38BB424BC0"
  730.     . "000008B0C8601D9803901740583EA01788683C00139C775EA8"
  731.     . "B4424640344240483BC24C800000007894424300F8EB901000"
  732.     . "08B8424C4000000C744244C0700000083C020894424348B442"
  733.     . "4348B9424AC0000008B7424308B0029C2894424508B8424CC0"
  734.     . "0000001F039C20F4EC289C28944245439F20F8C1CFFFFFF8B4"
  735.     . "424348B5424688B700C8B6808897424408B70108974241489C"
  736.     . "68B4014894424448B8424B00000002B460439C20F4EC289442"
  737.     . "40C8B46FC8BB424BC000000890424C1E00201C6038424C0000"
  738.     . "000894424488B4424588B7C2430037C245C3B44240C8904240"
  739.     . "F8FA50000008D76008DBC270000000085ED7E258B9C24B4000"
  740.     . "0008B54241431C001FB8B0C8601D9803901740583EA0178618"
  741.     . "3C00139C575EA8B4C244085C90F8E9B0000008B54244439D10"
  742.     . "F848F0000008B9C24B4000000896C243831C0897C243C8B6C2"
  743.     . "44801FB89CFEB0F8D74260083C00139FA746939C77E658B4C8"
  744.     . "50001D980390074EA83EA0179E58B6C24388B7C243C8304240"
  745.     . "103BC24AC0000008B04243944240C0F8D65FFFFFF834424300"
  746.     . "18B442430394424540F8D2FFFFFFF83442404018B442404394"
  747.     . "424200F8D5FFDFFFFE9F4FDFFFF8D76008DBC27000000008B4"
  748.     . "424308B7424508344244C07834424341C8D4430FF894424308"
  749.     . "B44244C398424C80000000F8F5DFEFFFF8B5C24748B4424040"
  750.     . "38424A40000008BB424D40000000B4424708D4B0181F9FF030"
  751.     . "00089049E0F8FB5FDFFFF8B54242885D27E278B7424188B942"
  752.     . "4B40000008B8424BC0000008D1C328B7424788B1083C00401D"
  753.     . "A39F0C6020075F28344240401894C24748B442404394424200"
  754.     . "F8DB3FCFFFFE948FDFFFF8B8424940000008BAC24B0000000C"
  755.     . "7042400000000C74424040000000083C00169C0E803000089C"
  756.     . "38B8424AC000000C1E00285ED894424080F8E73FBFFFF89DD8"
  757.     . "BB424AC00000085F67E5B8B8C249C0000008B5C24048BB4249"
  758.     . "C000000039C24B400000001F9037C240801FE66900FB651020"
  759.     . "FB6410169D22B01000069C04B02000001C20FB6016BC07201D"
  760.     . "039C50F970383C10483C30139F175D38B9424AC00000001542"
  761.     . "40483042401037C24108B0424398424B00000007586E9F2FAF"
  762.     . "FFF83C47C31C95B89C85E5F5DC2480090"
  763.     x64:="4157415641554154555756534881EC88000000488B84243"
  764.     . "80100004C8BB424180100004C898C24E8000000448B8C24400"
  765.     . "10000898C24D00000008954241444898424E00000004C8BAC2"
  766.     . "4200100004585C94C8BBC24280100004C8BA42430010000488"
  767.     . "9442408C7442410000000000F8EA10000004C89B4241801000"
  768.     . "0448BB42408010000488B4424088B68088B308B780485ED7E5"
  769.     . "C89F14189F24531DB31DB9085FF7E434863D6468D0C1F4489D"
  770.     . "84C01EAEB164C63C14883C20183C1014389048483C0014139C"
  771.     . "1741C803A3175E54D63C24883C2014183C2014389048783C00"
  772.     . "14139C175E401FE83C3014501F339DD75AF834424100748834"
  773.     . "424081C8B442410398424400100000F8F77FFFFFF4C8BB4241"
  774.     . "80100008B8424000100008B9C24F80000000FAF8424F000000"
  775.     . "0448B8424D00000008D2C988B8424080100008B9C24F000000"
  776.     . "0F7D84585C08D0483894424100F855A0500008B7424148B8C2"
  777.     . "41001000031D24531ED4889F089F3400FB6F60FB6FC8B84240"
  778.     . "8010000C1EB100FB6DBC1E00285C9894424080F8ED70000004"
  779.     . "C89BC24280100004C89A42430010000448BBC24E0000000448"
  780.     . "BA424080100004C89B424180100004189D64585E47E79488B9"
  781.     . "424E80000004D63DD4C039C24180100004863C54531C94C8D4"
  782.     . "402020F1F4000410FB608410FB650FF410FB640FE29D929FA4"
  783.     . "189CA29F041C1FA1F4431D14429D14189D241C1FA1F4431D24"
  784.     . "429D201CA89C1C1F91F31C829C801D04439F8430F9E040B498"
  785.     . "3C1014983C0044539CC7FB0036C24084501E54183C601036C2"
  786.     . "4104439B424100100000F856CFFFFFF4C8BB424180100004C8"
  787.     . "BBC24280100004C8BA42430010000488B9C2438010000488B8"
  788.     . "42438010000448B6B108B5B148B50048B400C895C241C488B9"
  789.     . "C243801000089C68B5B18895C24188B9C240801000029D3443"
  790.     . "9E8895C2414488B9C2438010000410F4CC589C78B842410010"
  791.     . "0002B4308894424740F889404000089F04C89BC24280100004"
  792.     . "C89A4243001000083E8014D89F4C744240800000000498D448"
  793.     . "7044589EE48C744245800000000C744247C000000004189F74"
  794.     . "189FD48894424488D42FF894424688B44241485C00F88EB000"
  795.     . "000488B5C24588B84240001000001D8C1E0108944247889D82"
  796.     . "B84245001000089C6B8000000000F49C631ED894424500FAF8"
  797.     . "42408010000894424548B84245001000001D88944246C4889E"
  798.     . "84489ED4989C58B44240844896C2410428D3C288B442418413"
  799.     . "9C60F84BB0000004189C131C085ED448B44241C0F8EDA00000"
  800.     . "04C8B9424280100004C8B9C2430010000EB2E66904139CE7E1"
  801.     . "B418B148301FA4863D241803C1400740B4183E901782E0F1F4"
  802.     . "400004883C00139C50F8E9A0000004139C789C17ECD418B148"
  803.     . "201FA4863D241803C140174BD4183E80179B74983C50144396"
  804.     . "C24140F8D68FFFFFF4189ED4883442458018BB424080100004"
  805.     . "88B44245801742408394424740F8DE9FEFFFF8B4C247C89C84"
  806.     . "881C4880000005B5E5F5D415C415D415E415FC34585FF7E2C4"
  807.     . "88B9424280100008B4C241C4C8B4424488B0201F8489841803"
  808.     . "C0401740583E901788C4883C2044939D075E58B44246803442"
  809.     . "41083BC2440010000070F8EB4010000488B9C2438010000896"
  810.     . "C24408BAC240801000044897C24304C896C2438C7442428070"
  811.     . "000004189C54883C3204489742434897C24704989DF418B078"
  812.     . "9EA29C28944242C8B8424480100004401E839C20F4EC24439E"
  813.     . "8894424440F8CEF000000418B47148BBC2410010000412B7F0"
  814.     . "4418B5708418B770C458B771089C38B44246C4C897C246039C"
  815.     . "70F4FF8496347FC4189DF48C1E0024989C0480384243001000"
  816.     . "04C0384242801000048894424208B5C24508B4424544401E83"
  817.     . "9FB4189DA0F8F7C0000009085D27E254589F34531C9438B0C8"
  818.     . "801C14863C941803C0C0174064183EB0178504983C1014439C"
  819.     . "A7FE185F60F8E800000004439FE747B4C8B4C24204489FB453"
  820.     . "1DBEB114183C3014983C10439F374624439DE7E5D418B0901C"
  821.     . "14863C941803C0C0074E083EB0179DB0F1F840000000000418"
  822.     . "3C20101E84439D77D854183C50144396C24440F8D5FFFFFFF4"
  823.     . "C8B6C2438448B7C2430448B7424348B6C24404983C50144396"
  824.     . "C24140F8D74FDFFFFE907FEFFFF8B44242C4C8B7C246083442"
  825.     . "42807458D6C05FF4983C71C8B442428398424400100000F8F9"
  826.     . "BFEFFFF448B7C2430448B7424348B6C24404C8B6C24388B7C2"
  827.     . "470486344247C8B542410039424F8000000488B9C245801000"
  828.     . "00B5424788D480181F9FF0300008914830F8FC1FDFFFF4585F"
  829.     . "F7E22488B8424280100004C8B4424488B104883C00401FA493"
  830.     . "9C04863D241C604140075EB4983C50144396C2414894C247C0"
  831.     . "F8DC8FCFFFFE95BFDFFFF0F1F00448B5424148B94241001000"
  832.     . "031DB8B84240801000031F64183C2014569D2E803000085D28"
  833.     . "D3C85000000000F8E84FBFFFF4C8BAC24E8000000448B9C240"
  834.     . "80100004585DB7E524863C54C63CE4531C0498D4C05024D01F"
  835.     . "1660F1F8400000000000FB6110FB641FF69D22B01000069C04"
  836.     . "B02000001C20FB641FE6BC07201D04139C2430F9704014983C"
  837.     . "0014883C1044539C37FCD01FD4401DE83C301036C2410399C2"
  838.     . "4100100007599E908FBFFFF31C9E9CBFCFFFF9090"
  839.     MCode(MyFunc, A_PtrSize=8 ? x64:x32)
  840.   }
  841.   return, DllCall(&MyFunc
  842.     , "int",mode, "uint",color, "int",n, Ptr,Scan0
  843.     , "int",Stride, "int",sx, "int",sy, "int",sw, "int",sh
  844.     , Ptr,&ss, "AStr",text, Ptr,&s1, Ptr,&s0
  845.     , Ptr,&in, "int",num, "int",offsetX, "int",offsetY, Ptr,&allpos)
  846. }
  847.  
  848.  
  849. /***** C source code of machine code *****
  850.  
  851. int __attribute__((__stdcall__)) PicFind(
  852.   int mode, unsigned int c, int n, unsigned char * Bmp
  853.   , int Stride, int sx, int sy, int sw, int sh
  854.   , char * ss, char * text, int * s1, int * s0
  855.   , int err1, int err0, int w1, int h1, int * allpos)
  856. {
  857.   int o, i, j, x, y, sx1, sy1, ok=0;
  858.   int r, g, b, rr, gg, bb, e1, e0, len1, len0, max;
  859.   // Generate Lookup Table
  860.   o=len1=len0=0;
  861.   for (y=0; y<h1; y++)
  862.   {
  863.     for (x=0; x<w1; x++)
  864.     {
  865.       i=mode==0 ? y*Stride+x*4 : y*sw+x;
  866.       if (text[o++]=='1')
  867.         s1[len1++]=i;
  868.       else
  869.         s0[len0++]=i;
  870.     }
  871.   }
  872.   // Color Position Mode
  873.   // This mode will not clear the image that has been found
  874.   if (mode==0)
  875.   {
  876.     sx1=sx+sw-w1; sy1=sy+sh-h1; max=len1>len0 ? len1 : len0;
  877.     for (y=sy; y<=sy1; y++)
  878.     {
  879.       for (x=sx; x<=sx1; x++)
  880.       {
  881.         o=y*Stride+x*4; e1=err1; e0=err0;
  882.         j=o+c; rr=Bmp[2+j]; gg=Bmp[1+j]; bb=Bmp[j];
  883.         for (i=0; i<max; i++)
  884.         {
  885.           if (i<len1)
  886.           {
  887.             j=o+s1[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb;
  888.             if (r<0) r=-r; if (g<0) g=-g; if (b<0) b=-b;
  889.             if (r+g+b>n && (--e1)<0) goto NoMatch2;
  890.           }
  891.           if (i<len0)
  892.           {
  893.             j=o+s0[i]; r=Bmp[2+j]-rr; g=Bmp[1+j]-gg; b=Bmp[j]-bb;
  894.             if (r<0) r=-r; if (g<0) g=-g; if (b<0) b=-b;
  895.             if (r+g+b<=n && (--e0)<0) goto NoMatch2;
  896.           }
  897.         }
  898.         allpos[ok++]=y<<16|x;
  899.         if (ok>=1024) goto Return1;
  900.         NoMatch2:
  901.         continue;
  902.       }
  903.     }
  904.     goto Return1;
  905.   }
  906.   // Generate Two Value Image
  907.   o=sy*Stride+sx*4; j=Stride-4*sw; i=0;
  908.   if (mode==1)  // Color Mode
  909.   {
  910.     rr=(c>>16)&0xFF; gg=(c>>8)&0xFF; bb=c&0xFF;
  911.     for (y=0; y<sh; y++, o+=j)
  912.       for (x=0; x<sw; x++, o+=4, i++)
  913.       {
  914.         r=Bmp[2+o]-rr; g=Bmp[1+o]-gg; b=Bmp[o]-bb;
  915.         if (r<0) r=-r; if (g<0) g=-g; if (b<0) b=-b;
  916.         ss[i]=r+g+b<=n ? 1:0;
  917.       }
  918.   }
  919.   else  // Gray Threshold Mode
  920.   {
  921.     c=(c+1)*1000;
  922.     for (y=0; y<sh; y++, o+=j)
  923.       for (x=0; x<sw; x++, o+=4, i++)
  924.         ss[i]=Bmp[2+o]*299+Bmp[1+o]*587+Bmp[o]*114<c ? 1:0;
  925.   }
  926.   // Start Lookup
  927.   sx1=sw-w1; sy1=sh-h1; max=len1>len0 ? len1 : len0;
  928.   for (y=0; y<=sy1; y++)
  929.   {
  930.     for (x=0; x<=sx1; x++)
  931.     {
  932.       o=y*sw+x; e1=err1; e0=err0;
  933.       if (e0==len0)
  934.       {
  935.         for (i=0; i<len1; i++)
  936.           if (ss[o+s1[i]]!=1 && (--e1)<0) goto NoMatch1;
  937.       }
  938.       else
  939.       {
  940.         for (i=0; i<max; i++)
  941.         {
  942.           if (i<len1 && ss[o+s1[i]]!=1 && (--e1)<0) goto NoMatch1;
  943.           if (i<len0 && ss[o+s0[i]]!=0 && (--e0)<0) goto NoMatch1;
  944.         }
  945.       }
  946.       allpos[ok++]=(sy+y)<<16|(sx+x);
  947.       if (ok>=1024) goto Return1;
  948.       // Clear the image that has been found
  949.       for (i=0; i<len1; i++) ss[o+s1[i]]=0;
  950.       NoMatch1:
  951.       continue;
  952.     }
  953.   }
  954.   Return1:
  955.   return ok;
  956. }
  957.  
  958.  
  959. int __attribute__((__stdcall__)) PicFind2(
  960.   int mode, unsigned int c, int n, unsigned char * Bmp
  961.   , int Stride, int sx, int sy, int sw, int sh
  962.   , char * ss, char * text, int * s1, int * s0
  963.   , int * in, int num, int offsetX, int offsetY, int * allpos )
  964. {
  965.   int o, i, j, x, y, r, g, b, rr, gg, bb, max, e1, e0, ok=0;
  966.   int o1, x1, y1, w1, h1, sx1, sy1, len1, len0, err1, err0;
  967.   int o2, x2, y2, w2, h2, sx2, sy2, len21, len20, err21, err20;
  968.   // Generate Lookup Table
  969.   for (j=0; j<num; j+=7)
  970.   {
  971.     o=o1=o2=in[j]; w1=in[j+1]; h1=in[j+2];
  972.     for (y=0; y<h1; y++)
  973.     {
  974.       for (x=0; x<w1; x++)
  975.       {
  976.         i=y*sw+x;
  977.         if (text[o++]=='1')
  978.           s1[o1++]=i;
  979.         else
  980.           s0[o2++]=i;
  981.       }
  982.     }
  983.   }
  984.   // Generate Two Value Image
  985.   o=sy*Stride+sx*4; j=Stride-4*sw; i=0;
  986.   if (mode==0)  // Color Mode
  987.   {
  988.     rr=(c>>16)&0xFF; gg=(c>>8)&0xFF; bb=c&0xFF;
  989.     for (y=0; y<sh; y++, o+=j)
  990.       for (x=0; x<sw; x++, o+=4, i++)
  991.       {
  992.         r=Bmp[2+o]-rr; g=Bmp[1+o]-gg; b=Bmp[o]-bb;
  993.         if (r<0) r=-r; if (g<0) g=-g; if (b<0) b=-b;
  994.         ss[i]=r+g+b<=n ? 1:0;
  995.       }
  996.   }
  997.   else  // Gray Threshold Mode
  998.   {
  999.     c=(c+1)*1000;
  1000.     for (y=0; y<sh; y++, o+=j)
  1001.       for (x=0; x<sw; x++, o+=4, i++)
  1002.         ss[i]=Bmp[2+o]*299+Bmp[1+o]*587+Bmp[o]*114<c ? 1:0;
  1003.   }
  1004.   // Start Lookup
  1005.   w1=in[1]; h1=in[2]; len1=in[3]; len0=in[4]; err1=in[5]; err0=in[6];
  1006.   sx1=sw-w1; sy1=sh-h1; max=len1>len0 ? len1 : len0;
  1007.   for (y=0; y<=sy1; y++)
  1008.   {
  1009.     for (x=0; x<=sx1; x++)
  1010.     {
  1011.       o=y*sw+x; e1=err1; e0=err0;
  1012.       if (e0==len0)
  1013.       {
  1014.         for (i=0; i<len1; i++)
  1015.           if (ss[o+s1[i]]!=1 && (--e1)<0) goto NoMatch1;
  1016.       }
  1017.       else
  1018.       {
  1019.         for (i=0; i<max; i++)
  1020.         {
  1021.           if (i<len1 && ss[o+s1[i]]!=1 && (--e1)<0) goto NoMatch1;
  1022.           if (i<len0 && ss[o+s0[i]]!=0 && (--e0)<0) goto NoMatch1;
  1023.         }
  1024.       }
  1025.       x1=x+w1-1; y1=y-offsetY; if (y1<0) y1=0;
  1026.       for (j=7; j<num; j+=7)
  1027.       {
  1028.         o2=in[j]; w2=in[j+1]; h2=in[j+2];
  1029.         len21=in[j+3]; len20=in[j+4]; err21=in[j+5]; err20=in[j+6];
  1030.         sx2=sw-w2; i=x1+offsetX; if (i<sx2) sx2=i;
  1031.         sy2=sh-h2; i=y+offsetY; if (i<sy2) sy2=i;
  1032.         for (x2=x1; x2<=sx2; x2++)
  1033.         {
  1034.           for (y2=y1; y2<=sy2; y2++)
  1035.           {
  1036.             o1=y2*sw+x2; e1=err21; e0=err20;
  1037.             for (i=0; i<len21; i++)
  1038.               if (ss[o1+s1[o2+i]]!=1 && (--e1)<0) goto NoMatch2;
  1039.             for (i=0; e0!=len20 && i<len20; i++)
  1040.               if (ss[o1+s0[o2+i]]!=0 && (--e0)<0) goto NoMatch2;
  1041.             goto MatchOK;
  1042.             NoMatch2:
  1043.             continue;
  1044.           }
  1045.         }
  1046.         goto NoMatch1;
  1047.         MatchOK:
  1048.         x1=x2+w2-1;
  1049.       }
  1050.       allpos[ok++]=(sy+y)<<16|(sx+x);
  1051.       if (ok>=1024) goto Return1;
  1052.       // Clear the image that has been found
  1053.       for (i=0; i<len1; i++) ss[o+s1[i]]=0;
  1054.       NoMatch1:
  1055.       continue;
  1056.     }
  1057.   }
  1058.   Return1:
  1059.   return ok;
  1060. }
  1061.  
  1062. */
  1063.  
  1064. ft_End:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement