Advertisement
Guest User

meh abandoned project

a guest
Jul 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Windows.Forms;
  9. using System.Reflection;
  10. using System.Threading;
  11. using System.Runtime.InteropServices;
  12. using System.Diagnostics;
  13.  
  14.  
  15. namespace PixelArt
  16. {
  17.    
  18.     class Program
  19.     {
  20.         [DllImport("user32.dll")]
  21.         public static extern bool BlockInput(bool btw);
  22.         [DllImport("user32.dll")]
  23.         static extern bool SetForegroundWindow(IntPtr hWnd);
  24.         [DllImport("user32.dll", SetLastError = true)]
  25.         internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
  26.  
  27.         public static readonly int X_MIN = 241;
  28.         public static readonly int X_MAX = 1257;
  29.         public static readonly int Y_MIN = 319;
  30.         public static readonly int Y_MAX = 860;
  31.         private static readonly string MainProcessName = "mspaint.exe";
  32.         private static Process pProcess = Process.GetProcessesByName(MainProcessName).FirstOrDefault();
  33.         private static Dictionary<KeyValues, Dictionary<string, int>> dValueT = new Dictionary<KeyValues, Dictionary<string, int>>()
  34.         {
  35.             //{KeyValues.Menu, new Dictionary<string, int>(dValueT[KeyValues.Menu]){ {"X",1190 } } }
  36.         };
  37.         /*private static Dictionary<Enum, Action<bool>> func = new Dictionary<KeyValues, Action<bool>>()
  38.         {2
  39.             //{ KeyValues.Menu,()=>{ } }762 : 60
  40.         };*/
  41.  
  42.         [STAThread]
  43.         static void Main(string[] args)
  44.         {
  45.             List<Color> c;
  46.             OpenFileDialog z = new OpenFileDialog();
  47.             if (z.ShowDialog() == DialogResult.OK)
  48.               c=GetPixelsFromImage(z.FileName);
  49.             if (pProcess!=null)
  50.                 SetForegroundWindow(pProcess.Handle);
  51.             else
  52.                 pProcess = Process.Start("mspaint.exe");
  53.  
  54.             BlockInput(true);
  55.             Thread.Sleep(1000);
  56.             ChangeRGBSTATIC(Color.Black);
  57.             Color cc = Color.Black;
  58.             MouseClickClass mc = new MouseClickClass();
  59.             Thread.Sleep(5000);
  60.             for (int x = X_MIN; x < X_MAX; x += new Random().Next(1,5))
  61.                 for (int y = Y_MIN; y < Y_MAX; y += new Random().Next(1,10))
  62.                 {
  63.                     if (new Random().Next(Y_MAX) % 2 == 0)
  64.                     {
  65.                         mc.DoMouseRelease();
  66.                         Cursor.Position = new Point((new Random().Next(9) * 22) + 762, new int[] { 60, 86 }[new Random().Next(0, 2)]);
  67.                         mc.DoMouseClick();
  68.                         Thread.Sleep(5);
  69.                         mc.DoMouseClick();
  70.                     }
  71.                     Cursor.Position = new Point(x,y);
  72.                     mc.DoMouseHold();
  73.                 }
  74.             mc.Dispose();
  75.             Console.Read();
  76.  
  77.         }
  78.  
  79.         static void ChangeRGBSTATIC(Color c)
  80.         {
  81.             Point p = Cursor.Position;
  82.             for (int i = 0; i < 5; i++)
  83.             {
  84.                 Thread.Sleep(500);
  85.                 MoveTo(i);
  86.                 Thread.Sleep(1);
  87.                 new MouseClickClass().DoMouseClick();
  88.                 if (i > 0 && i < 4) { SendKeys.SendWait("{BACKSPACE}"); SendKeys.SendWait(new byte[] { c.R, c.G, c.B }[i - 1].ToString()); }
  89.             }
  90.             Cursor.Position = p;
  91.         }
  92.         static void MoveTo(int ID)
  93.         {
  94.             if(ID==0)
  95.                 Cursor.Position = new Point((int)KeyValues.Menu.X, (int)KeyValues.Menu.Y);
  96.             else if(ID==1)
  97.                 Cursor.Position = new Point((int)KeyValues.R.X, (int)KeyValues.R.Y);
  98.             else if (ID == 2)
  99.                 Cursor.Position = new Point((int)KeyValues.G.X, (int)KeyValues.G.Y);
  100.             else if(ID==3)
  101.                 Cursor.Position = new Point((int)KeyValues.B.X, (int)KeyValues.B.Y);
  102.             else if (ID == 4)
  103.                 Cursor.Position = new Point((int)KeyValues.Close.X, (int)KeyValues.Close.Y);
  104.         }
  105.         static List<Color> GetPixelsFromImage(string filename)
  106.         {
  107.             List<Color> c = new List<Color>();
  108.             using (Bitmap b = new Bitmap(Image.FromFile(filename)))
  109.                 for (int x = 0; x < b.Width; x++)
  110.                     for (int y = 0; y < b.Height; y++)
  111.                         c.Add(b.GetPixel(x, y));
  112.             return c;
  113.         }
  114.         static void GetPoint(int sleep)
  115.         {
  116.             new Thread(() =>
  117.             {
  118.                 Thread.CurrentThread.IsBackground = true;
  119.                 for (int i = 0; i < 1000; i++)
  120.                 {
  121.                     MessageBox.Show($"X:{Cursor.Position.X}\nY:{Cursor.Position.Y}");
  122.                     Thread.Sleep(sleep);
  123.                 }
  124.             }).Start();
  125.         }
  126.  
  127.         static void GetKnownNameOfColor(params Color[] c)
  128.         {
  129.             var colorLookup = typeof(Color)
  130.              .GetProperties(BindingFlags.Public | BindingFlags.Static)
  131.              .Select(f => (Color)f.GetValue(null, null))
  132.              .Where(g => g.IsNamedColor)
  133.              .ToLookup(g => g.ToArgb());
  134.  
  135.             for (int i = 0; i < c.Length; i++)
  136.                 foreach (var namedColor in colorLookup[c[i].ToArgb()])
  137.                     Console.WriteLine(namedColor.Name);
  138.         }
  139.  
  140.         void Print(string sep,params Color[] c) => Console.WriteLine($"{String.Join(sep, c.ToArray())}\nCount: {c.Length}");
  141.  
  142.      
  143.  
  144.          class KeyValues
  145.         {
  146.             public enum Menu
  147.             {
  148.                 ID = 0,
  149.                 X = 996,
  150.                 Y = 92
  151.             }
  152.  
  153.             public enum R
  154.             {
  155.                 ID = 1,
  156.                 X = 784,
  157.                 Y = 517
  158.             }
  159.  
  160.             public enum G
  161.             {
  162.                 ID = 2,
  163.                 X = 784,
  164.                 Y = 534
  165.             }
  166.  
  167.             public enum B
  168.             {
  169.                 ID = 3,
  170.                 X = 784,
  171.                 Y = 561
  172.             }
  173.  
  174.             public enum Close
  175.             {
  176.                 ID=4,
  177.                 X = 413,
  178.                 Y = 583
  179.             }
  180.         }
  181.  
  182.         public class MouseClickClass : IDisposable
  183.         {
  184.             [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
  185.             public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
  186.             private bool dispose = false;
  187.  
  188.             private const int MOUSEEVENTF_LEFTDOWN = 0x02;
  189.             private const int MOUSEEVENTF_LEFTUP = 0x04;
  190.             private const int MOUSEEVENTF_RIGHTDOWN = 0x08;
  191.             private const int MOUSEEVENTF_RIGHTUP = 0x10;
  192.  
  193.             public void DoMouseClick()
  194.             {
  195.  
  196.                 uint X = (uint)Cursor.Position.X;
  197.                 uint Y = (uint)Cursor.Position.Y;
  198.                 mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
  199.             }
  200.  
  201.             public void DoMouseHold()
  202.             {
  203.                 if (!dispose)
  204.                 {
  205.                     uint X = (uint)Cursor.Position.X;
  206.                     uint Y = (uint)Cursor.Position.Y;
  207.                     mouse_event(MOUSEEVENTF_LEFTDOWN, X, Y, 0, 0);
  208.                 }
  209.             }
  210.  
  211.             public void DoMouseRelease()
  212.             {
  213.                 uint X = (uint)Cursor.Position.X;
  214.                 uint Y = (uint)Cursor.Position.Y;
  215.                 mouse_event(MOUSEEVENTF_LEFTUP, X, Y, 0, 0);
  216.             }
  217.  
  218.             public void Dispose()
  219.             {
  220.                 if (dispose)
  221.                     dispose = false;
  222.             }
  223.         }
  224.     }
  225.  
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement