Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Diagnostics;
- using System.Threading;
- using System.Runtime.InteropServices;
- using AutoItX3Lib;
- namespace Automate
- {
- public partial class Form1 : Form
- {
- private static Point[] points = new Point[] {
- new Point(415, 661),
- new Point(1575, 457),
- new Point(415, 661),
- new Point(415, 661),
- new Point(1575, 457),
- new Point(1575, 457),
- };
- Autoit Cautoit = new Autoit();
- public int numFailure;
- public Form1()
- {
- InitializeComponent();
- }
- [DllImport("ImageSearchDLL.dll")]
- public static extern IntPtr ImageSearch(int x, int y, int right, int bottom, [MarshalAs(UnmanagedType.LPStr)]string imagePath);
- public static string[] UseImageSearch(string imgPath, string tolerance)
- {
- imgPath = "*" + tolerance + " " + imgPath;
- IntPtr result = ImageSearch(0, 0, 1920, 1080, imgPath);
- string res = Marshal.PtrToStringAnsi(result);
- if (res[0] == '0') return null;
- string[] data = res.Split('|');
- int x; int y;
- int.TryParse(data[1], out x);
- int.TryParse(data[2], out y);
- return data;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- Stopwatch timer = new Stopwatch();
- timer.Start();
- var numberOfFailures = 0;
- while (timer.Elapsed.TotalSeconds < 10000)
- {
- foreach (Point point in points)
- {
- if (!Cautoit.myResult(point, CalculateCounter(numberOfFailures)))
- numberOfFailures++;
- else
- numberOfFailures = 0;
- }
- }
- timer.Stop();
- }
- private int CalculateCounter(int numberOfFailures) => (int)Math.Pow(2, numberOfFailures);
- }
- public struct Point
- {
- public int x;
- public int y;
- public Point(int x_, int y_)
- {
- x = x_;
- y = y_;
- }
- }
- }
- namespace Automate
- {
- public class Autoit
- {
- [DllImport("ImageSearchDLL32.dll")]
- public static extern IntPtr ImageSearch(int x, int y, int right, int bottom, [MarshalAs(UnmanagedType.LPStr)]string imagePath);
- public static string[] UseImageSearch(string imgPath, string tolerance)
- {
- imgPath = "*" + tolerance + " " + imgPath;
- IntPtr result = ImageSearch(0, 0, 1920, 1080, imgPath);
- string res = Marshal.PtrToStringAnsi(result);
- if (res[0] == '0') return null;
- string[] data = res.Split('|');
- int x; int y;
- int.TryParse(data[1], out x);
- int.TryParse(data[2], out y);
- return data;
- }
- AutoItX3 auto = new AutoItX3();
- public void mClick(string ClickSide, int x, int y, int manyClick, int Speed)
- {
- auto.MouseClick(ClickSide, x, y, manyClick, Speed);
- }
- public void mSleep(int millisecondi)
- {
- auto.Sleep(millisecondi);
- }
- public bool myResult(Point point, int Counter)
- {
- Autoit Cautoit = new Autoit();
- string image = (@"C:\winningNumber.bmp");
- string[] result = UseImageSearch(image, "30");
- Cautoit.mClick("LEFT", point.x, point.y, Counter, 1);
- Cautoit.mSleep(15000);
- return result != null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement