-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
93 lines (82 loc) · 3.09 KB
/
Program.cs
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
using System;
using System.IO;
using System.Media;
using System.Drawing;
using System.Diagnostics;
using System.Windows.Forms;
namespace 原神_启动_
{
internal class Program
{
[STAThread]
static void Main(string[] args)
{
string game_path;
try
{
game_path = File.ReadAllText("config.txt");
if (string.IsNullOrEmpty(game_path))
throw new Exception();
if (!File.Exists(game_path))
throw new Exception();
}
catch (Exception)
{
var ofd = new OpenFileDialog
{
Title = "Select game path",
Filter = "Game executable|*.exe"
};
if (ofd.ShowDialog() == DialogResult.OK)
{
game_path = ofd.FileName;
File.WriteAllText("config.txt", game_path);
}
else return;
ofd.Dispose();
}
while (true)
{
Console.WriteLine($"Info: Screens count: {ScreenUtils.ScreensCount}");
for (int i = 0; i < ScreenUtils.ScreensCount; i++)
{
ScreenUtils.GetScreenShot(i, out var screenshot);
if (screenshot == null)
{
Console.WriteLine($"Warn: Failed to get the ScreenShot in screen {i}");
continue;
}
var bmp = new Bitmap(screenshot);
screenshot.Dispose();
if (bmp == null)
{
Console.WriteLine("Warn: Failed to convert a Image object into a Bitmap object");
continue;
}
int whiteBitsCount = 0;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
var color = bmp.GetPixel(x, y);
bool check(int val) => val >= 230 && val <= 255;
if (check(color.R) && check(color.G) && check(color.B))
whiteBitsCount++;
}
}
bmp.Dispose();
// Console.WriteLine($"{whiteBitsCount} {ScreenUtils.GetScreenSize(i).Width * ScreenUtils.GetScreenSize(i).Height * 0.9}");
if (whiteBitsCount >= ScreenUtils.GetScreenSize(i).Width * ScreenUtils.GetScreenSize(i).Height * 0.9)
{
var soundPlayer = new SoundPlayer(Properties.Resources.music);
soundPlayer.Play();
Process.Start(game_path);
MessageBox.Show("原神,启动!");
}
}
// Code above are slow enough
// Thread.Sleep(100);
}
}
}
}