[APPEARANCE]
COLOR = 155, 20, 40;
SIZE_X = 8;
SIZE_Y =4;
[END]

[INTERFACE]
DIALOG, "Решение клик капчи rucaptcha.com (ReCaptcha и т.д.)", 833, 307;
STATIC, "Капча в", 4, 4, 48, 20;
COMBO, "Активный по Экрану""Активный по Указателю""Фоновый по Указателю""По Скриншоту", 60, 4, 164, 100, int EW;
STATIC, "Указатель на окно", 288, 4, 100, 20;
EDIT, 392, 4, 128, 20, win W;
STATIC, "Указатель на скрин", 608, 4, 104, 20;
EDIT, 720, 4, 100, 20, int Screen;
STATIC, "Ключ в rucaptcha.com", 4, 28, 116, 20;
EDIT, 124, 28, 696, 20, string Key;
STATIC, "Максимальное время ожидания", 4, 52, 168, 20;
EDIT, 176, 52, 100, 20, int T;
STATIC, "Зона капчи старт", 4, 76, 96, 20;
EDIT, 104, 76, 116, 20, int eX1;
EDIT, 232, 76, 116, 20, int eY1;
STATIC, "Зона капчи финиш", 464, 76, 100, 20;
EDIT, 576, 76, 116, 20, int eX2;
EDIT, 704, 76, 116, 20, int eY2;
CHECK, "Вопрос к капче на русском", 4, 100, 160, 20, int RUSS;
STATIC, "Переменные:  Количество объектов в", 4, 124, 200, 20;
EDIT, 208, 124, 100, 20, int NUM_CAPCHA;
STATIC, "Указатели на координаты от лев. верх. угла зоны X", 320, 124, 272, 20;
EDIT, 596, 124, 100, 20, int X_CAPCHA;
STATIC, "Y", 704, 124, 12, 20;
EDIT, 720, 124, 100, 20, int Y_CAPCHA;
STATIC, "Дополнительный комментарий для работника разгадывающего капчу", 4, 148, 360, 20;
EDIT, 368, 148, 452, 20, string COMM;
STATIC, "Решенная капча в", 4, 172, 96, 20;
EDIT, 104, 172, 160, 20, string Rez;
CHECK, "Перекликать объекты после решения капчи", 4, 196, 244, 20, int KL;
STATIC, "Комментарий", 4, 220, 76, 20;
EDIT, 84, 220, 736, 20, unknown Comment;
BUTTON_OK, "Принять", 608, 252, 100, 20;
BUTTON_CANCEL, "Закрыть", 720, 252, 100, 20;
[END]

[INFO]
[ENDL]>>Comment
[END]

[ASSOC_NUMBER]
Path
[END]

[ASSOC_VAR]
EW=0;
W=W_Kib;
Screen=Screen;
Key="dce6bcbb1a728ea8d563de6d169a2057";
T=90000;
eX1=300;
eY1=500;
eX2=580;
eY2=610;
KL=0;
RUSS=0;
NUM_CAPCHA=NUM_Captcha;
X_CAPCHA=X_Captcha;
Y_CAPCHA=Y_Captcha;
COMM="";
Rez=T_Captcha;
W_V = #~W~;
V_X=~W~.leftclient;
V_Y=~W~.topclient;
V_Screen=#~Screen~;
V_Rez=#~Rez~;
V_NUM_CAPCHA=#~NUM_CAPCHA~;
V_X_CAPCHA=#~X_CAPCHA~;
V_Y_CAPCHA=#~Y_CAPCHA~;
Comment=;
[END]

[GLOBAL_VAR]
win ~W~;
int ~Screen~[3000][3000];  
string ~Rez~;
int ~X_CAPCHA~[25];
int ~Y_CAPCHA~[25];
int ~NUM_CAPCHA~;
[END]

[EVENT]
IF (I_MODE_BIND_WINDOW!=0)SENDBUTTON(GETID(EW), S_MODE_BIND_WINDOW);
IF (I_MODE_BIND_WINDOW!=0)SENDEDIT(GETID(W), W_Kib);
IF (I_MODE_BIND_WINDOW!=0)ENABLE(GETID(EW), 0);
IF (I_MODE_BIND_WINDOW!=0)ENABLE(GETID(W), 0);
IF (I_MODE_BIND_WINDOW!=0)ENABLE(GETID(Screen), 0);
IF (EW==3)ENABLE(GETID(KL), 0);
IF (EW!=3)ENABLE(GETID(KL), 1);
[END]

[FUNCTION_BODY]
function(int ew, int #Scr, win #w, int v_x, int v_y, int t, string KEY, string comment, int russ, string #Ot, int #x_captcha, int #y_captcha, int #num_captcha, int sx, int sy, int fx, int fy, int kl)
{
  if (ew==0)
  {
  savescreen(JPG, pathfolder()+"temp_capcha.jpg", sx, sy, fx, fy, -1);
  savescreen(pathfolder()+"temp_capcha_bmp.bmp", sx, sy, fx, fy, -1);
  }
  if (ew==1)
  {
  savescreen(JPG, pathfolder()+"temp_capcha.jpg", v_x+sx, v_y+sy, v_x+fx, v_y+fy, -1);
  savescreen(pathfolder()+"temp_capcha_bmp.jpg", v_x+sx, v_y+sy, v_x+fx, v_y+fy, -1);
  }
  if (ew==2)
  {
  savescreen(JPG, pathfolder()+"temp_capcha.jpg", sx, sy, fx, fy, w);
  savescreen(pathfolder()+"temp_capcha_bmp.jpg", sx, sy, fx, fy, w);
  }
  if (ew==3)
  {
  saveimage(JPG, #Scr[0][0], pathfolder()+"temp_capcha.jpg", sx, sy, fx, fy);
  saveimage(#Scr[0][0], pathfolder()+"temp_capcha_bmp.jpg", sx, sy, fx, fy);
  }
num_captcha=0;
string Num[50];
char BYTE[200000];
string H="--kibor-post^r^n";
H=H+"Content-Disposition: form-data; name=^"method^"^r^n^r^n";
H=H+"post^r^n";
H=H+"--kibor-post^r^n";
H=H+"Content-Disposition: form-data; name=^"key^"^r^n^r^n";
H=H+KEY+"^r^n";
H=H+"--kibor-post^r^n";
H=H+"Content-Disposition: form-data; name=^"language^"^r^n^r^n";
H=H+format(russ)+"^r^n";
H=H+"--kibor-post^r^n";
H=H+"Content-Disposition: form-data; name=^"coordinatescaptcha^"^r^n^r^n";
H=H+"1^r^n";
  if (comment!="")
  {
  H=H+"--kibor-post^r^n";
  H=H+"Content-Disposition: form-data; name=^"textinstructions^"^r^n^r^n";
  H=H+ansitoutf8(comment)+"^r^n";
  }
H=H+"--kibor-post^r^n";
H=H+"Content-Disposition: form-data; name=^"file^"; filename=^"temp_capcha.jpg^"^r^n";
H=H+"Content-Type: image/jpeg^r^n^r^n";
strcpy(#BYTE[0], H);
int S=size(H);
int size_file=0;
  if (fopen (pathfolder()+"temp_capcha.jpg", "rb")!=0)
  {
  size_file=freadb(#BYTE[S], 200000-S);
  fclose();
  }
  else return -5;
size_file=size_file+S;
strcpy(#BYTE[size_file], "^r^n--kibor-post");
size_file=size_file+14;
string Header="Content-Type: multipart/form-data; boundary=kibor-post";
string REZ;
  if (sendgetweb(#REZ, "My bot", "POST", "https:/^/rucaptcha.com", "in.php", Header, #BYTE[0], size_file))
  {
  string id;
  if (regexsearch(1, #id, REZ, "(?<=OK\|)(\d+)")==0){Ot=REZ; return -1;}
  pause(3000);
  if (t==0) t=1;
    looptime(t)
    {
    pause(2000);  
      if (sendgetweb(#REZ, "My bot", "POST", "https:/^/rucaptcha.com", "res.php?key="+KEY+"&action=get&id="+id))
      {
      if (regexsearch(1, #Ot, REZ, "ERROR_CAPTCHA_UNSOLVABLE")){Ot=REZ; num_captcha=0; return 1;}
      if (regexsearch(1, #Ot, REZ, "ERROR")){Ot=REZ; return -6;}
        if (regexsearch(1, #Ot, REZ, "(?<=OK\|)(.*)+"))
        {
        string to;
          if (regexsearch(1, #to, Ot, "coordinates"))
          {
          int K=regexsearch(50, #Num[0], Ot, "\d+");
            for (int n=0; n<K-1; n=n+2)
            {   
            x_captcha[num_captcha]=formatsn(Num[n]);
            y_captcha[num_captcha]=formatsn(Num[n+1]);
            num_captcha++;
            }
            if (kl)
            {
              for(n=0; n<num_captcha; n++)
              {
              if (ew==0) mouse(LEFT, sx+x_captcha[n], sy+y_captcha[n]);
              if (ew==1) mouse(LEFT, v_x+sx+x_captcha[n], v_y+sy+y_captcha[n]);
              if (ew==2) mouse(LEFT, sx+x_captcha[n], sy+y_captcha[n], 0, w);
              sleep(500);
              }
            }
          return 1;
          }
          else
          {
          loadimage (#Scr[0][0], pathfolder()+"temp_capcha_bmp.bmp");
          int xi=imagewidth(#Scr[0][0]);
          int yi=imageheight(#Scr[0][0]);
          int Ya[150][150];
          int nn1, nn2;
          int pol;
            for (int nn=80; nn<150; nn++)
            {
            pol=nn/2;
            nn1=nn/2-5;
            nn2=nn1+10;
            initialarray(#Ya[0][0], 0);
            for (n=0; n<nn1; n++)Ya[n][0]=16777215;
            for (n=1; n<nn; n++)Ya[0][n]=16777215;
              for (n=nn1; n<nn2; n++)
              {
              Ya[n][nn]=16777215;
              Ya[nn][n]=16777215;
              }
            int xx[25], yy[25];
            int X, Y;
            K=findimage(25, #Ya[0][0], 0, #xx[0], #yy[0], 0, 0, xi, yi, #Scr[0][0]);
              if (K>8)
              {
              int stx=xx[0]-1, sty=yy[0]-1;
              int kx=0, ky=0;
                for (n=0; n<K; n++)
                {
                if (xx[n]>stx){stx=xx[n]+5; kx++;}
                if (yy[n]>sty){sty=yy[n]+5; ky++;}
                }
              int tx[5][5], ty[5][5];
              n=0;
                for (int y=0; y<ky; y++)
                {
                  for (int x=0; x<kx; x++)
                  {
                  tx[x][y]=xx[n];
                  ty[x][y]=yy[n];
                  n++;
                  }
                }
              n=0;
                for (x=0; x<kx; x++)
                {
                  for (y=0; y<ky; y++)
                  {
                  xx[n]=tx[x][y]+pol;
                  yy[n]=ty[x][y]+pol;
                  n++;
                  }
                }
              int Nom[25];
              int k_nom=0;
              string ts;
              char tc[52];
              strcpy(#tc[0], Ot);
              int aw=size(Ot);
              if (aw==0) {num_captcha=0; return 1;}
              Ot="";
              for (n=0; n<aw; n++){if (tc[n]>47 && tc[n]<58)Ot=Ot+tc[n];}
              strcpy(#tc[0], Ot);
              aw=size(Ot);
              if (aw==0) {num_captcha=0; return 1;}
              ts="";
              int para=0;
                for (n=0; n<aw; n++)
                {
                ts=tc[n];
                if (n>0 && tc[n]=='1')para=1;
                if (n>1 && tc[n]=='2')para=1;
                if (para==1 && n+1<aw){ts=ts+tc[n+1]; n++;}
                Nom[k_nom]=formatsn(ts);
                k_nom++;
                ts="";
                }
              num_captcha=k_nom;
                for (n=0; n<num_captcha; n++)
                {
                if (Nom[n]==0)return -9;
                x_captcha[n]=xx[Nom[n]-1];
                y_captcha[n]=yy[Nom[n]-1];
                }
                if (kl)
                {
                  for(n=0; n<num_captcha; n++)
                  {
                  if (ew==0) mouse(LEFT, sx+x_captcha[n], sy+y_captcha[n]);
                  if (ew==1) mouse(LEFT, v_x+sx+x_captcha[n], v_y+sy+y_captcha[n]);
                  if (ew==2) mouse(LEFT, sx+x_captcha[n], sy+y_captcha[n], 0, w);
                  sleep(500);
                  }
                }
              return 1;
              }
            }
          return -8;
          }
        return -7;
        }
      }
    }
  }
  else
  {
  Ot=REZ;
  return -3;
  }
Ot="Ошибка";
return -4;
}
[END]

[CALL]
(EW, V_Screen[0][0], W_V, V_X, V_Y, T, Key, COMM, RUSS, V_Rez, V_X_CAPCHA[0], V_Y_CAPCHA[0], V_NUM_CAPCHA, eX1, eY1, eX2, eY2, KL)
[END]

[FUNCTION_LOGIC]  
>0
[END]








