Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Reflection;
- using System.Threading;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- namespace PixelArt
- {
- class Program
- {
- [DllImport("user32.dll")]
- public static extern bool BlockInput(bool btw);
- [DllImport("user32.dll")]
- static extern bool SetForegroundWindow(IntPtr hWnd);
- [DllImport("user32.dll", SetLastError = true)]
- internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
- public static readonly int X_MIN = 241;
- public static readonly int X_MAX = 1257;
- public static readonly int Y_MIN = 319;
- public static readonly int Y_MAX = 860;
- private static readonly string MainProcessName = "mspaint.exe";
- private static Process pProcess = Process.GetProcessesByName(MainProcessName).FirstOrDefault();
- private static Dictionary<KeyValues, Dictionary<string, int>> dValueT = new Dictionary<KeyValues, Dictionary<string, int>>()
- {
- //{KeyValues.Menu, new Dictionary<string, int>(dValueT[KeyValues.Menu]){ {"X",1190 } } }
- };
- /*private static Dictionary<Enum, Action<bool>> func = new Dictionary<KeyValues, Action<bool>>()
- {2
- //{ KeyValues.Menu,()=>{ } }762 : 60
- };*/
- [STAThread]
- static void Main(string[] args)
- {
- List<Color> c;
- OpenFileDialog z = new OpenFileDialog();
- if (z.ShowDialog() == DialogResult.OK)
- c=GetPixelsFromImage(z.FileName);
- if (pProcess!=null)
- SetForegroundWindow(pProcess.Handle);
- else
- pProcess = Process.Start("mspaint.exe");
- BlockInput(true);
- Thread.Sleep(1000);
- ChangeRGBSTATIC(Color.Black);
- Color cc = Color.Black;
- MouseClickClass mc = new MouseClickClass();
- Thread.Sleep(5000);
- for (int x = X_MIN; x < X_MAX; x += new Random().Next(1,5))
- for (int y = Y_MIN; y < Y_MAX; y += new Random().Next(1,10))
- {
- if (new Random().Next(Y_MAX) % 2 == 0)
- {
- mc.DoMouseRelease();
- Cursor.Position = new Point((new Random().Next(9) * 22) + 762, new int[] { 60, 86 }[new Random().Next(0, 2)]);
- mc.DoMouseClick();
- Thread.Sleep(5);
- mc.DoMouseClick();
- }
- Cursor.Position = new Point(x,y);
- mc.DoMouseHold();
- }
- mc.Dispose();
- Console.Read();
- }
- static void ChangeRGBSTATIC(Color c)
- {
- Point p = Cursor.Position;
- for (int i = 0; i < 5; i++)
- {
- Thread.Sleep(500);
- MoveTo(i);
- Thread.Sleep(1);
- new MouseClickClass().DoMouseClick();
- if (i > 0 && i < 4) { SendKeys.SendWait("{BACKSPACE}"); SendKeys.SendWait(new byte[] { c.R, c.G, c.B }[i - 1].ToString()); }
- }
- Cursor.Position = p;
- }
- static void MoveTo(int ID)
- {
- if(ID==0)
- Cursor.Position = new Point((int)KeyValues.Menu.X, (int)KeyValues.Menu.Y);
- else if(ID==1)
- Cursor.Position = new Point((int)KeyValues.R.X, (int)KeyValues.R.Y);
- else if (ID == 2)
- Cursor.Position = new Point((int)KeyValues.G.X, (int)KeyValues.G.Y);
- else if(ID==3)
- Cursor.Position = new Point((int)KeyValues.B.X, (int)KeyValues.B.Y);
- else if (ID == 4)
- Cursor.Position = new Point((int)KeyValues.Close.X, (int)KeyValues.Close.Y);
- }
- static List<Color> GetPixelsFromImage(string filename)
- {
- List<Color> c = new List<Color>();
- using (Bitmap b = new Bitmap(Image.FromFile(filename)))
- for (int x = 0; x < b.Width; x++)
- for (int y = 0; y < b.Height; y++)
- c.Add(b.GetPixel(x, y));
- return c;
- }
- static void GetPoint(int sleep)
- {
- new Thread(() =>
- {
- Thread.CurrentThread.IsBackground = true;
- for (int i = 0; i < 1000; i++)
- {
- MessageBox.Show($"X:{Cursor.Position.X}\nY:{Cursor.Position.Y}");
- Thread.Sleep(sleep);
- }
- }).Start();
- }
- static void GetKnownNameOfColor(params Color[] c)
- {
- var colorLookup = typeof(Color)
- .GetProperties(BindingFlags.Public | BindingFlags.Static)
- .Select(f => (Color)f.GetValue(null, null))
- .Where(g => g.IsNamedColor)
- .ToLookup(g => g.ToArgb());
- for (int i = 0; i < c.Length; i++)
- foreach (var namedColor in colorLookup[c[i].ToArgb()])
- Console.WriteLine(namedColor.Name);
- }
- void Print(string sep,params Color[] c) => Console.WriteLine($"{String.Join(sep, c.ToArray())}\nCount: {c.Length}");
- class KeyValues
- {
- public enum Menu
- {
- ID = 0,
- X = 996,
- Y = 92
- }
- public enum R
- {
- ID = 1,
- X = 784,
- Y = 517
- }
- public enum G
- {
- ID = 2,
- X = 784,
- Y = 534
- }
- public enum B
- {
- ID = 3,
- X = 784,
- Y = 561
- }
- public enum Close
- {
- ID=4,
- X = 413,
- Y = 583
- }
- }
- public class MouseClickClass : IDisposable
- {
- [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
- public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
- private bool dispose = false;
- private const int MOUSEEVENTF_LEFTDOWN = 0x02;
- private const int MOUSEEVENTF_LEFTUP = 0x04;
- private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
- private const int MOUSEEVENTF_RIGHTUP = 0x10;
- public void DoMouseClick()
- {
- uint X = (uint)Cursor.Position.X;
- uint Y = (uint)Cursor.Position.Y;
- mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
- }
- public void DoMouseHold()
- {
- if (!dispose)
- {
- uint X = (uint)Cursor.Position.X;
- uint Y = (uint)Cursor.Position.Y;
- mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);
- }
- }
- public void DoMouseRelease()
- {
- uint X = (uint)Cursor.Position.X;
- uint Y = (uint)Cursor.Position.Y;
- mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
- }
- public void Dispose()
- {
- if (dispose)
- dispose = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement