Page 1 of 8 123 ... LastLast
Results 1 to 25 of 182

Thread: Appa - SCAR Minimizeable WebClient

  1. #1
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default Appa - SCAR Minimizeable WebClient

    Hey,

    This is Appa, a WebClient plugin for SCAR. It has a lot of features and potential. It can help automate tasks on the internet using SCAR. For example, you can fill in forms or play flash games (minimized).

    A few features:
    • Browse the web
    • Simulate mouse and keyboard events
    • Get page source
    • Adjust page source
    • Get screen contents when minimized
    • Block input (kind of useless, but fun )
    • Get/Set target in page (useful for flash applets)
    • Submit forms
    • Cookie support
    • Proxy support
    • Frame support


    NOTE: the mouse and keyboard simulations do not work for JAVA applets.

    Here are a few examples on how to use:

    SCAR Code:
    //Searches through all forms for "form1"
    //and sets the value of the third element
    //of the form to ''
    var
      f: TAppaFormArray;
    begin
      f := appa_GetForms;
      for i := 0 to High(f) do
        if (f[i].Name = 'form1') then
        begin
          appa_FormElementAction(i, 3, appa_SetValue, '');
          Break;
        end;
    end;
    SCAR Code:
    //Searches through all elements for an element
    //with tag "A" (link), then it gets the href attribute
    //to check if it is the proper link I'm looking for.
    //If it is, it clicks the link.
    var
      e: TAppaElementArray;
    begin
      e := appa_GetElements;
      for i := 0 to High(e) do
      begin
        if (e[i].Tag <> 'A') then
          Continue;
        s := LowerCase(Trim(e[i].innerText));
        t := appa_ElementAction(i, appa_GetAttribute, 'href');
        if ((s = q) and (q <> '')) or (s = a[4]) then
          if (Pos('javascript: submitForm', t) > 0) then
          begin
            appa_ElementAction(i, appa_Click, '');
            Break;
          end;
      end;
    end;
    SCAR Code:
    //This is a general function to navigate to a page
    function appa_NavigateTo(URL: string; TimeOut: Integer): Boolean;
    var
      t: Integer;
    begin
      Result := False;
      if (not appa_Showing) then
        Exit;
       
      if (URL <> '') then
        appa_Navigate(URL);
      t := GetSystemTime + TimeOut;
      while (not appa_PageLoaded) and appa_Showing and (GetSystemTime < t) do
        Wait(250);
       
      Result := appa_PageState >= 3;
    end;

    begin
      appa_ShowForm; //Show the form
      appa_NavigateTo('', 10000); //Wait until it's fully loaded
      appa_NavigateTo('http://www.freerice.com/index.php', 10000); //Navigate to freerice.com
    end.

    As you might have guessed, these snippets are from a FreeRice script which I'll release later today. It demonstrates how to and what for Appa can be used.

    If you have any further questions, please ask

    ~Nielsie95


    Here's a list with available functions:

    SCAR Code:
    procedure SaveBitmapAsJPEG(const Bitmap, w, h, Compression: Integer; const FileName: string);
    function PostHTTPFormData(const URL: string; const fieldNames, fieldValues, fileFieldNames, fileNames, fileContentType: TStringArray): string;

    function appa_SetProxy(IP: string; Port: Integer; ByPass: string): Boolean;
    procedure appa_ShowForm;
    function appa_Showing: Boolean;
    procedure appa_CloseForm;
    function appa_CurrentPage: string;
    function appa_PageState: Integer;
    function appa_PageLoaded: Boolean;
    procedure appa_Navigate(const URL: string);
    function appa_GetTargets: TStringArray;
    procedure appa_SetTargetHandle(const h: HWND);
    procedure appa_SetTargetFromPoint(const p: TPoint);
    function appa_SetTargetName(const Name: string): Boolean;

    procedure appa_KeyDown(const Key: Byte);
    procedure appa_KeyUp(const Key: Byte);
    procedure appa_MoveMouse(const x, y:Integer);
    procedure appa_HoldMouse(const x, y: Integer; const Left: Boolean);
    procedure appa_ReleaseMouse(const x, y: Integer; const Left: Boolean);

    function appa_GetSize: TPoint;
    procedure appa_SetSize(Width, Height: Integer);
    procedure appa_CopyContentToBitmap(const bIndex: Integer);
    function appa_GetElements: THTMLElementArray;
    function appa_GetForms: THTMLFormArray;
    function appa_ElementAction(const elIndex: Integer; const act: THTMLElementAction; const Param: string): string;
    function appa_FormElementAction(const FormIndex, elIndex: Integer; const act: THTMLElementAction; const Param: string): string;
    procedure appa_SubmitForm(const Index: Integer);

    procedure appa_ScrollTo(const x, y: Integer);
    function appa_GetHTML: string;
    function appa_GetCookies: string;
    procedure appa_SetCookies(const Cookies: string);
    procedure appa_Caption(const s: string);

    function appa_GetFrameCount: Integer;
    procedure appa_SetCurrentFrame(Frame: Integer; Nest: Boolean);
    procedure appa_ResetFrameNest;  

    type
      TAppaElement = record
        Box: TBox;
        innerText, innerHTML, outerHTML, ID, ClassName, Tag: string;
      end;
      TAppaElementArray = array of TAppaElement;
      TAppaFormElement = record
        outerHTML, ID, ClassName, Tag, Name, Value: string;
      end;
      TAppaFormElementArray = array of TAppaFormElement;
      TAppaForm = record
        Name, Action, Method: string;
        Elements: TAppaFormElementArray;
      end;
      TAppaFormArray = array of TAppaForm;
      TAppaElementAction = (appa_ScrollIntoView, appa_Click, appa_SetInnerHTML, appa_SetOuterHTML, appa_GetAttribute, appa_SetAttribute, appa_RemoveAttribute, appa_SetValue);

    If you're having some annoying Just-in-time errors go to Internet Explorer and enable "Disable script debugging (other)".
    Last edited by nielsie95; 05-22-2011 at 10:38 AM.

  2. #2
    Join Date
    Jan 2007
    Location
    Kansas
    Posts
    3,760
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    Mmmmm, sweet. I'll look at the code when I get home but from what you said, great job.

    I love utilities made in SCAR


  3. #3
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Amazing 2nd post ftw!

    Will try this out

  4. #4
    Join Date
    May 2007
    Location
    UK
    Posts
    4,007
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Looks SIIIICKK!
    Cheers Niels

    T|M

  5. #5
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Nice!!!@

  6. #6
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by Bobarkinator View Post
    Mmmmm, sweet. I'll look at the code when I get home but from what you said, great job.

    I love utilities made in SCAR
    It's a plugin

  7. #7
    Join Date
    Feb 2007
    Location
    Het ademt zwaar en moedeloos vannacht.
    Posts
    7,211
    Mentioned
    26 Post(s)
    Quoted
    72 Post(s)

    Default

    I made a new script, check it out!.

  8. #8
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by Markus View Post
    Wow, it is. I didn't know he actually made it this far

  9. #9
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Disabled input, yet normal left clicking isn't working
    Otherwise, glad there's something to further macroing on Linux since it ran (does this mean I have IE installed through Wine? eww), but if Raymond has sauce, then he wins
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

  10. #10
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ZOMG!

    Checking it out.

    Dutchies FTW!
    ~Hermen

  11. #11
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Niels, we want your sauce!

    Btw why
    SCAR Code:
    TAppaElementArray = array of THTMLElement;
    instead of
    SCAR Code:
    TAppaElementArray = array of TAppaElement;

  12. #12
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    So it it is a kind of smart for all flash games?
    all browser applets?
    ~Hermen

  13. #13
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by lordsaturn View Post
    Niels, we want your sauce!

    Btw why
    SCAR Code:
    TAppaElementArray = array of THTMLElement;
    instead of
    SCAR Code:
    TAppaElementArray = array of TAppaElement;
    Oh you're right It's called THTMLElement in the plugin
    I might post the source later.

    Quote Originally Posted by Hermen View Post
    So it it is a kind of smart for all flash games?
    all browser applets?
    Could be used for that yes, JAVA applets don't work though.

  14. #14
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Any idea why Java applets don't work?

  15. #15
    Join Date
    Oct 2007
    Location
    Denmark
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Shit, this is cool!

  16. #16
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    Interesting fact: 'Appa' means 'drunk' in Dutch (NL: in straattaal dan)

  17. #17
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Wow... Awesome job, Niels!! This plugin is pretty damn cool.

    Thanks.

  18. #18
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Woah this is really sweet (: Great job man (: Much cookies A LOADS OF COOKIES FOR YOU Niels =)

    ~Home

  19. #19
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Home View Post
    Woah this is really sweet (: Great job man (: Much cookies A LOADS OF COOKIES FOR YOU Niels =)

    ~Home
    If he isn't getting fat from scripting all the time, he will get it from your loads and LOADS of cookies.

    Who pays the cookies after all?
    ~Hermen

  20. #20
    Join Date
    May 2007
    Location
    UK
    Posts
    4,007
    Mentioned
    1 Post(s)
    Quoted
    12 Post(s)

    Default

    Wait so can Appa be used to script in?
    Like smart?
    Sorry if im wrong

    T~M

  21. #21
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yes only for applets without java, I am actually copying Nielsie's sentence.
    ~Hermen

  22. #22
    Join Date
    Feb 2006
    Posts
    3,044
    Mentioned
    4 Post(s)
    Quoted
    21 Post(s)

    Default

    Sorry this mya look like double posting ? But should this be included in SRL or even fro Scar as a default plugin :O And should for this make a seperate include because i really love this stuff!

    ~Home

  23. #23
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,553
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The plugin folder.(appa)
    Then just run the script, AFAIK.
    ~Hermen

  24. #24
    Join Date
    Oct 2007
    Location
    Denmark
    Posts
    409
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Found a bug: Popups.

  25. #25
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by Frt View Post
    Found a bug: Popups.
    What about them?

    Anyway, here's a small script that demonstrates how to work with flash applets:

    SCAR Code:
    program New;

    const
      ScrollIntoView = True;

    var
      Client: TBox;
      Target: Integer;
      TargetSize: TPoint;

    procedure appa_UpdateBitmap;
    var
      p: TPoint;
    begin
      if (not appa_Showing) then
        Exit;
      p := appa_GetSize; //Get the size of the browser
      if (p.x <> TargetSize.x) or (p.y <> TargetSize.y) then //If it has changed -> New bitmap
      begin
        try FreeBitmap(Target); except end;
        Target := BitmapFromString(p.x, p.y, '');
        TargetSize := p;
        SetTargetBitmap(Target);
      end;
      appa_CopyContentToBitmap(Target); //Update the bitmap
     
      //DisplayDebugImgWindow(p.x, p.y);
      //SafeDrawBitmap(Target, GetDebugCanvas, 0, 0);
    end;

    function appa_NavigateTo(URL: string; TimeOut: Integer): Boolean;
    var
      t: Integer;
    begin
      Result := False;
      if (not appa_Showing) then
        Exit;

      if (URL <> '') then
        appa_Navigate(URL);
      t := GetSystemTime + TimeOut;
      while (not appa_PageLoaded) and appa_Showing and (GetSystemTime < t) do
        Wait(250);

      Result := appa_PageState >= 3;
    end;

    procedure GetClientBox; //Because you can only get the bitmap of the whole page, you need to know where the client is
    var
      e: TAppaElementArray;
      i: Integer;
    begin
      if (not appa_Showing) then
        Exit;
      e := appa_GetElements; //Get all elements
      for i := 0 to High(e) do
        if (e[i].Tag = 'OBJECT') then //Search for the applet
        begin
          Client := e[i].Box;
          if ScrollIntoView then
          begin
            appa_ScrollTo(0, Client.y1);
            Client.y2 := Client.y2 - Client.y1;
            Client.y1 := 0;
          end;
          Break;
        end;
    end;

    procedure ScriptTerminate;
    begin
      try FreeBitmap(Target); except end;
    end;

    procedure ClickSquare(x, y: Integer);
    begin
      //No offset here, because it is sent directly to the applet
      x := 285 + (100 * x);
      y := 67 + (100 * y);
      appa_MoveMouse(x, y);
      appa_HoldMouse(x, y, True);
      Wait(40);
      appa_ReleaseMouse(x, y, True);
    end;

    procedure HandleScreen;
    begin
      GetClientBox;
      appa_UpdateBitmap; //Update the target bitmap

      while (GetColor(Client.x1 + 160, Client.y1 + 285) = clWhite) do    //Relative coordinates
      begin
        Wait(500);
        appa_UpdateBitmap; //Update the target bitmap
      end;
      if (GetColor(Client.x1 + 190, Client.y1 + 223) = 1776513) then     //All colorchecking is relative
      begin
        appa_MoveMouse(180, 225);     //Not relative here -- Directly sent to applet
        appa_HoldMouse(180, 225, True);
        Wait(40);
        appa_ReleaseMouse(180, 225, True);
        Wait(2000);
        appa_MoveMouse(300, 355);
        appa_HoldMouse(300, 355, True);
        Wait(40);
        appa_ReleaseMouse(300, 355, True);
        Wait(2000);
        appa_UpdateBitmap;
      end;
      if (CountColor(39423, Client.x1 + 475, Client.y1 + 358, Client.x1 + 510, Client.y1 + 380) > 0) then
      begin
        appa_MoveMouse(490, 375);
        appa_HoldMouse(490, 375, True);
        Wait(40);
        appa_ReleaseMouse(490, 375, True);
        Wait(2000);
        appa_UpdateBitmap;
      end;
      while (GetColor(Client.x1 + 246, Client.y1 + 368) = 13421568) do
      begin
        Wait(100);
        appa_UpdateBitmap;
      end;
    end;

    procedure NextMove;
    var
      PlayField: array[0..2] of array[0..2] of Integer;
      x, y, c: Integer;
    begin
      GetClientBox;
      appa_UpdateBitmap; //Update the target bitmap
     
      c := 0;
      for x := 0 to 2 do
        for y := 0 to 2 do
        begin
          PlayField[x][y] := CountColor(10092543, 240 + (100 * x) + Client.x1, 30 + (100 * y) + Client.y1, 320 + (100 * x) + Client.x1, 110 + (100 * y) + Client.y1);
          //FindColors/CountColors always with offset (Client.x1)
          case PlayField[x][y] of
            4144: PlayField[x][y] := 2; //Computer
            4160: PlayField[x][y] := 5; //You
            else  PlayField[x][y] := 0; //Empty
          end;
          if (PlayField[x][y] = 0) then
            c := 1;
        end;
      if (c <> 1) then
        Exit;
       
      for y := 0 to 2 do
      begin
        c := 0;
        for x := 0 to 2 do
          c := c + PlayField[x][y];
        if (c = 4) or (c = 10) then
          for x := 0 to 2 do
            if (PlayField[x][y] = 0) then
            begin
              ClickSquare(x, y);
              Exit;
            end;
      end;
      for x := 0 to 2 do
      begin
        c := 0;
        for y := 0 to 2 do
          c := c + PlayField[x][y];
        if (c = 4) or (c = 10) then
          for y := 0 to 2 do
            if (PlayField[x][y] = 0) then
            begin
              ClickSquare(x, y);
              Exit;
            end;
      end;
      c := PlayField[0][0] + PlayField[1][1] + PlayField[2][2];
      if (c = 4) or (c = 10) then
      begin
        if (PlayField[0][0] = 0) then
          ClickSquare(0, 0)
        else if (PlayField[1][1] = 0) then
          ClickSquare(1, 1)
        else if (PlayField[2][2] = 0) then
          ClickSquare(2, 2);
        Exit;
      end;
      c := PlayField[0][2] + PlayField[1][1] + PlayField[2][0];
      if (c = 4) or (c = 10) then
      begin
        if (PlayField[0][2] = 0) then
          ClickSquare(0, 2)
        else if (PlayField[1][1] = 0) then
          ClickSquare(1, 1)
        else if (PlayField[2][0] = 0) then
          ClickSquare(2, 0);
        Exit;
      end;
     
      while True do
      begin
        x := Random(3);
        y := Random(3);
       
        if (PlayField[x][y] = 0) then
          Break;
      end;
      ClickSquare(x, y);
    end;

    begin
      appa_ShowForm;
      appa_NavigateTo('', 10000);
      appa_NavigateTo('http://www.novelgames.com/flashgames/game.php?id=30', 10000);

      appa_SetTargetName('MacromediaFlashPlayerActiveX'); //Set target to first flash applet
     
      repeat
        HandleScreen;
        NextMove;
        Wait(50);
      until IsFKeyDown(3) or (not appa_Showing);
    end.

    I understand it might be a bit complicated at first, so feel free to ask. It should play a game of TicTacToe btw
    Last edited by nielsie95; 05-20-2009 at 02:33 PM.

Page 1 of 8 123 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •