Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace AutoFish
- {
- class Program
- {
- //Key Press
- [DllImport("user32.dll")]
- public static extern int SetForegroundWindow(IntPtr hWnd);
- //Mouse Click
- [DllImport("user32.dll")]//, CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
- public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
- public const int MOUSEEVENTF_LEFTDOWN = 0x02;
- public const int MOUSEEVENTF_LEFTUP = 0x04;
- public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
- public const int MOUSEEVENTF_RIGHTUP = 0x10;
- private const int MOUSEEVENTF_MOVE = 0x0001;
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool PostMessage(int hWnd, uint Msg, int wParam, int lParam);
- //-----
- private static Color splashColor;
- private static int splashColorThreshold = 35;
- private static bool isFishing = false;
- static void Main(string[] args)
- {
- //Set Values
- splashColor = Color.White;
- //Init
- Console.ForegroundColor = ConsoleColor.White;
- Process[] processes = Process.GetProcessesByName("Wow");
- if (processes.Length==0)
- {
- Console.WriteLine("WOW is not open");
- Console.ReadLine();
- return;
- }
- else
- {
- Console.WriteLine("Found World Of Warcraft!");
- }
- //Actual Fishing
- Console.WriteLine("----------");
- Console.WriteLine("STARTING TO FISH");
- Stopwatch timerFromStartedFishing = new Stopwatch();//30sec
- Stopwatch totalTimer = Stopwatch.StartNew();//30sec
- Stopwatch turnDownComputerTimer = Stopwatch.StartNew();
- float totalFishedTime = 0;
- int totalFishCaught = 0;
- while (true)
- {
- if (!isFishing)
- {
- SetForegroundWindow(processes[0].MainWindowHandle);
- Thread.Sleep(100);
- //Check if we have buff, if don't use one
- UseBuffIfNeeded();
- //Start fishing
- SendKeys.SendWait("{1}");
- isFishing = true;
- timerFromStartedFishing.Start();
- }
- #region Record Screen
- Size screenSize = Screen.PrimaryScreen.Bounds.Size;
- Size offset = new Size(500, 300);//Screen.PrimaryScreen.Bounds.Size;
- Point splashLocation = ScanGetSplashPos(screenSize, offset);
- if (splashLocation != new Point(-1, -1))
- {
- splashLocation.X += (screenSize.Width - offset.Width) / 2;
- splashLocation.Y += (screenSize.Height - offset.Height) / 2;
- }
- #endregion
- if (splashLocation != new Point(-1,-1))
- {
- //Console.Beep();
- float fishedTime = (timerFromStartedFishing.ElapsedMilliseconds / 1000f);
- totalFishedTime += fishedTime;
- totalFishCaught++;
- Console.WriteLine("AVG: " + (totalFishedTime / totalFishCaught) + "s, Total Caught: " + totalFishCaught + "x");
- isFishing = false;
- timerFromStartedFishing.Stop();
- timerFromStartedFishing.Reset();
- //ClickOnPointTool.ClickOnPoint(processes[0].MainWindowHandle, splashLocation);
- DoMouseClick(splashLocation);
- //Console.Beep();
- Thread.Sleep(2000);
- }
- if (timerFromStartedFishing.ElapsedMilliseconds>30000)
- {
- isFishing = false;
- timerFromStartedFishing.Stop();
- timerFromStartedFishing.Reset();
- }
- //stopwatch.Stop();
- //Console.WriteLine(stopwatch.ElapsedMilliseconds);
- //Thread.Sleep(100);
- if (totalTimer.ElapsedMilliseconds>10000)
- {
- System.GC.Collect();
- totalTimer.Reset();
- totalTimer.Start();
- }
- //if (turnDownComputerTimer.ElapsedMilliseconds > 10800000)//(3*60 * 60 * 1000)=10800000
- //{
- // Process.Start("shutdown", "/s /t 0");
- // return;
- //}
- }
- }
- private static void UseBuffIfNeeded()
- {
- Bitmap image= GetDesktopImage(new Size(1, 1), new Size(3052 ,38),false);
- Console.WriteLine(image.GetPixel(0, 0));
- if (image.GetPixel(0,0) != Color.FromArgb(255,0,1,0))
- {
- UseBuff();
- }
- }
- private static void UseBuff()
- {
- Console.WriteLine("Using buff");
- Thread.Sleep(100);
- DoMouseClick(new Point(3000, 965),2000);
- Thread.Sleep(2000);
- DoMouseClick(new Point(240, 840), 2000);
- Thread.Sleep(10000);
- }
- private static Point ScanGetSplashPos(Size screenSize, Size offset)
- {
- Bitmap image;
- image = GetDesktopImage(offset, screenSize,true);
- //image.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\AntiFishingTest\screenshot.png"); // saves the image
- //int splashMatches = TotalCloseColors(image, splashColor, splashColorThreshold);
- return GetColorLocation(image, splashColor, splashColorThreshold);
- }
- private static void DoMouseClick(Point point,int downTime=400)
- {
- //move to coordinates
- //Point pt = (Point)pc.ConvertFromString(X + "," + Y);
- Cursor.Position = point;
- Thread.Sleep(100);
- //perform click
- //mouse_event(MOUSEEVENTF_LEFTDOWN,0,0, 0, 0);
- //mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
- //Thread.Sleep(10);
- mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
- Thread.Sleep(downTime);
- mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
- //Thread.Sleep(2000);
- }
- private static int TotalCloseColors(Bitmap image,Color closeColor,int threshold)
- {
- int counter = 0;
- for (int x = 0; x < image.Width; x++)
- {
- for (int y = 0; y < image.Height; y++)
- {
- if (ColorsAreClose(image.GetPixel(x, y), closeColor,threshold))
- {
- counter++;
- }
- }
- }
- return counter;
- }
- private static Point GetColorLocation(Bitmap image,Color color, int threshold)
- {
- if (image==null)
- {
- return new Point(-1, -1);
- }
- int matches = 0;
- int totalX = 0;
- int totalY = 0;
- for (int x = 0; x < image.Width; x++)
- {
- for (int y = 0; y < image.Height; y++)
- {
- if (ColorsAreClose(image.GetPixel(x, y), color, threshold))
- {
- matches++;
- totalX += x;
- totalY += y;
- }
- }
- }
- if (matches == 0)
- {
- return new Point(-1, -1);
- }
- return new Point(totalX / matches, totalY / matches);
- }
- private static bool ColorsAreClose(Color a, Color z, int threshold = 15)
- {
- int r = (int)a.R - z.R,
- g = (int)a.G - z.G,
- b = (int)a.B - z.B;
- return (r * r + g * g + b * b) <= threshold * threshold;
- }
- public static Bitmap GetDesktopImage(Size inputSize, Size screenSize,bool centerMode)
- {
- WIN32_API.SIZE size;
- size.cx = inputSize.Width;// WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
- size.cy = inputSize.Height;// WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);
- Bitmap bmpScreenshot = new Bitmap(size.cx,
- size.cy,
- PixelFormat.Format32bppArgb);
- // Create a graphics object from the bitmap.
- var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
- // Take the screenshot from the upper left corner to the right bottom corner.
- if (centerMode)
- {
- gfxScreenshot.CopyFromScreen(screenSize.Width / 2 - size.cx / 2, screenSize.Height / 2 - size.cy / 2, 0, 0,
- inputSize,
- CopyPixelOperation.SourceCopy);
- }
- else
- {
- gfxScreenshot.CopyFromScreen(screenSize.Width, screenSize.Height, 0, 0,
- inputSize,
- CopyPixelOperation.SourceCopy);
- }
- gfxScreenshot.Dispose();
- return bmpScreenshot;
- #region Old
- IntPtr hDC = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
- IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC);
- IntPtr m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy);
- if (m_HBitmap != IntPtr.Zero)
- {
- IntPtr hOld = (IntPtr)WIN32_API.SelectObject(hMemDC, m_HBitmap);
- if (centerMode)
- {
- WIN32_API.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, screenSize.Width / 2 - size.cx / 2, screenSize.Height / 2 - size.cy / 2, WIN32_API.SRCCOPY);
- }
- else
- {
- WIN32_API.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, screenSize.Width, screenSize.Height, WIN32_API.SRCCOPY);
- }
- WIN32_API.SelectObject(hMemDC, hOld);
- WIN32_API.DeleteDC(hMemDC);
- WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC);
- return System.Drawing.Image.FromHbitmap(m_HBitmap);
- }
- #endregion
- //Application.Restart();
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement