-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
156 lines (144 loc) · 3.96 KB
/
Program.cs
File metadata and controls
156 lines (144 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NOPixelLockPickSolver
{
internal class Program
{
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern short GetAsyncKeyState(Keys vKey);
static void Main(string[] args)
{
Task Solver = new Task(() =>
{
Point LP = new Point(960, 520);
Bitmap lpimg = new Bitmap(380, 380);
List<int> colorCircles = new List<int>();
List<int> colorMatches = new List<int>();
while (true)
{
if (GetAsyncKeyState(Keys.F1) != 0)
{
break;
}
if (GetAsyncKeyState(Keys.XButton2) != 0)
{
using (Graphics g = Graphics.FromImage(lpimg))
{
g.CopyFromScreen(LP.X - 190, LP.Y - 190, 0, 0, lpimg.Size);
}
for (int numOfTimes = 0; numOfTimes < 4; numOfTimes++)
{
colorCircles.Clear();
colorMatches.Clear();
int newOffsets = (numOfTimes * 40);
for (int i = 0; i < 12; i++)
{
double newCos = Math.Cos(i * 30 * Math.PI / 180);
double newSin = Math.Sin(i * 30 * Math.PI / 180);
colorCircles.Add(GetColorAt(lpimg, new Point(LP.X + (int)(newOffsets * newCos + 35 * newCos), LP.Y + (int)(newOffsets * newSin + 35 * newSin))));
}
for (int i = 0; i < 12; i++)
{
double newCos = Math.Cos(i * 30 * Math.PI / 180);
double newSin = Math.Sin(i * 30 * Math.PI / 180);
colorMatches.Add(GetColorAt(lpimg, new Point(LP.X + (int)(newOffsets * newCos + 54 * newCos), LP.Y + (int)(newOffsets * newSin + 54 * newSin))));
}
List<string> moveSet = SolveMatch(colorCircles, colorMatches);
foreach (string move in moveSet)
{
if (move == "L")
{
SendKeys.SendWait("{LEFT}");
}
else if (move == "R")
{
SendKeys.SendWait("{RIGHT}");
}
System.Threading.Thread.Sleep(50);
}
SendKeys.SendWait("{SPACE}");
System.Threading.Thread.Sleep(50);
}
System.Threading.Thread.Sleep(300);
}
}
});
Solver.Start();
Solver.Wait();
}
private static List<string> SolveMatch(List<int> colorCircles, List<int> colorMatches)
{
int n = colorCircles.Count;
if (colorCircles.SequenceEqual(colorMatches))
{
return new List<string>();
}
int min_shifts = int.MaxValue;
List<string> min_directions = new List<string>();
for (int direction = 0; direction < 2; direction++)
{
var shiftedCircles = new List<int>(colorCircles);
for (int i = 0; i < n; i++)
{
if (direction == 0)
{
shiftedCircles.Add(shiftedCircles[0]);
shiftedCircles.RemoveAt(0);
}
else
{
shiftedCircles.Insert(0, shiftedCircles[n - 1]);
shiftedCircles.RemoveAt(n);
}
int num_matches = 0;
for (int j = 0; j < n; j++)
{
if (shiftedCircles[j] == colorMatches[j] || colorMatches[j] == 0)
{
num_matches++;
}
}
if (num_matches == n)
{
if (i < min_shifts)
{
min_shifts = i;
min_directions = new List<string>();
for (int k = 0; k < i + 1; k++)
{
min_directions.Add(direction == 0 ? "L" : "R");
}
}
break;
}
}
}
return min_directions;
}
private static int GetColorAt(Bitmap clp, Point point)
{
Color color = clp.GetPixel(point.X - 770, point.Y - 330);
if (color.R > 90 && color.G > 120 && color.B < 120)
{
return 1; // yellow
}
else if (color.R > 100 && color.G < 90 && color.B > 45)
{
return 2; // purple
}
else if (color.R < 100 && color.G > 120 && color.B > 200)
{
return 3; // blue
}
else
{
clp.SetPixel(point.X - 770, point.Y - 330, Color.White);
return 0;
}
}
}
}