Results 1 to 1 of 1
  1. #1
    DatSik
    DatSik is offline
    New member DatSik's Avatar
    Join Date
    2012 Sep
    Location
    Oklahoma
    Posts
    24
    Thanks
    1
    Thanked 9 Times in 1 Post
    Rep Power
    0

    [C# source] I need help finding the Components/Units to make this in Delphi.

    OK, first off, I am in no way asking for someone to do all the work for me an convert/translate this directly over, but rather help me find out what all i need in order to make this happen in Delphi.

    The only thing I'm seeing if Getpixel, should i keep this or use something else?

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    using System.Threading;
    
    namespace Login_Button_Click_for_Puzzle_Pirates
    {
        public partial class frmMain : Form
        {
            [DllImport("user32.dll")]
            static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint dwData,
              int dwExtraInfo);
    
            public enum MouseEventFlags : uint
            {
                LEFTDOWN = 0x00000002,
                LEFTUP = 0x00000004,
                MIDDLEDOWN = 0x00000020,
                MIDDLEUP = 0x00000040,
                MOVE = 0x00000001,
                ABSOLUTE = 0x00008000,
                RIGHTDOWN = 0x00000008,
                RIGHTUP = 0x00000010,
                WHEEL = 0x00000800,
                XDOWN = 0x00000080,
                XUP = 0x00000100
            }
    
            public frmMain()
            {
                InitializeComponent();
            }
    
            private void btnLogin_Click(object sender, EventArgs e)
            {
                // takes a snapshot of the screen
                Bitmap bmpScreenshot = Screenshot();
    
                // makes the background of the form a screenshot of the screen
                this.BackgroundImage = bmpScreenshot;
    
                // find the login button and check if it exists
                Point location;
                bool success = FindBitmap(Properties.Resources.bmpLogin, bmpScreenshot, out location);
    
                // check if it found the bitmap
                if (success == false)
                {
                    MessageBox.Show("Couldn't find the login button");
                    return;
                }
    
                // move the mouse to login button
                Cursor.Position = location;
    
                // click
                MouseClick();
    
    
                /*
                 *     [x] Snapshot of the whole screen
                 *     [x] Find the login button and check if it exists
                 *     [x] Move the mouse to login button
                 *     [ ] Click the login button
                 */
            }
    
            /// <summary>
            /// Simulates a mouse click
            /// </summary>
            private void MouseClick()
            {
                mouse_event((uint)MouseEventFlags.LEFTDOWN, 0, 0, 0, 0);
                Thread.Sleep((new Random()).Next(20, 30));
                mouse_event((uint)MouseEventFlags.LEFTUP, 0, 0, 0, 0);
            }
    
            /// <summary>
            /// Takes a snapshot of the screen
            /// </summary>
            /// <returns>A snapshot of the screen</returns>
            private Bitmap Screenshot()
            {
                // this is where we will store a snapshot of the screen
                Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
    
    
                // creates a graphics object so we can draw the screen in the bitmap (bmpScreenshot)
                Graphics g = Graphics.FromImage(bmpScreenshot);
    
                // copy from screen into the bitmap we created
                g.CopyFromScreen(0, 0, 0, 0, Screen.PrimaryScreen.Bounds.Size);
    
                // return the screenshot
                return bmpScreenshot;
            }
    
            /// <summary>
            /// Find the location of a bitmap within another bitmap and return if it was successfully found
            /// </summary>
            /// <param name="bmpNeedle">The image we want to find</param>
            /// <param name="bmpHaystack">Where we want to search for the image</param>
            /// <param name="location">Where we found the image</param>
            /// <returns>If the bmpNeedle was found successfully</returns>
            private bool FindBitmap(Bitmap bmpNeedle, Bitmap bmpHaystack, out Point location)
            {
                for(int outerX = 0; outerX < bmpHaystack.Width - bmpNeedle.Width; outerX++)
                {
                    for (int outerY = 0; outerY < bmpHaystack.Height - bmpNeedle.Height; outerY++)
                    {
                        for (int innerX = 0; innerX < bmpNeedle.Width; innerX++)
                        {
                            for (int innerY = 0; innerY < bmpNeedle.Height; innerY++)
                            {
                                Color cNeedle = bmpNeedle.GetPixel(innerX, innerY);
                                Color cHaystack = bmpHaystack.GetPixel(innerX + outerX, innerY + outerY);
    
                                if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
                                {
                                    goto notFound;
                                }
                            }
                        }
                        location = new Point(outerX, outerY);
                        return true;
                    notFound:
                        continue;
                    }
                }
                location = Point.Empty;
                return false;
            }
    
            private void frmMain_Load(object sender, EventArgs e)
            {
    
            }
        }
    }

Similar Threads

  1. Replies: 1
    Last Post: 2013-10-23, 07:09 PM
  2. [Release] Fusion Trainer [Delphi Source]
    By topera in forum Aika Bots, Hacks, Cheats
    Replies: 26
    Last Post: 2012-11-10, 07:10 AM
  3. [Hack] WYD BR Trainner + Delphi Source
    By ]'LyNxy~' in forum Other MMO
    Replies: 1
    Last Post: 2012-11-02, 05:30 PM
  4. [Source] Aika jit to dds Converter Full Delphi source.
    By Dwar in forum Delphi
    Replies: 1
    Last Post: 2012-07-23, 02:21 PM
  5. delphi source code - npcgen.data NPC dumper
    By idk123 in forum Perfect World
    Replies: 3
    Last Post: 2012-05-22, 04:23 AM
Visitors found this page by searching for:
Nobody landed on this page from a search engine, yet!

Posting Permissions

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