Skip to content

Commit 6e43274

Browse files
committed
init
0 parents  commit 6e43274

34 files changed

+3299
-0
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# User-specific files
2+
*.suo
3+
*.user
4+
*.userosscache
5+
*.sln.docstates
6+
.vs/
7+
8+
# User-specific files (MonoDevelop/Xamarin Studio)
9+
*.userprefs
10+
11+
# Build results
12+
[Dd]ebug/
13+
[Dd]ebugPublic/
14+
[Rr]elease/
15+
[Rr]eleases/
16+
x64/
17+
x86/
18+
bld/
19+
[Bb]in/
20+
[Oo]bj/
21+
[Ll]og/
22+
23+
# Mine
24+
Tmp/
25+
/packages/
26+
node_modules/

GenshinAutoFish.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31229.75
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GenshinAutoFish", "GenshinAutoFish\GenshinAutoFish.csproj", "{F17BE4C5-926C-456D-9CC0-606DAE304ED8}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{F17BE4C5-926C-456D-9CC0-606DAE304ED8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{F17BE4C5-926C-456D-9CC0-606DAE304ED8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{F17BE4C5-926C-456D-9CC0-606DAE304ED8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{F17BE4C5-926C-456D-9CC0-606DAE304ED8}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {DFA8F1CD-513D-45D7-856D-378146C4D367}
24+
EndGlobalSection
25+
EndGlobal

GenshinAutoFish/App.config

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="GenshinAutoFish.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<startup>
9+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
10+
</startup>
11+
<runtime>
12+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
13+
<dependentAssembly>
14+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
15+
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
16+
</dependentAssembly>
17+
</assemblyBinding>
18+
</runtime>
19+
<userSettings>
20+
<GenshinAutoFish.Properties.Settings>
21+
<setting name="StrainBarAreaLocation" serializeAs="String">
22+
<value>0, 0</value>
23+
</setting>
24+
<setting name="StrainBarAreaSize" serializeAs="String">
25+
<value>599, 50</value>
26+
</setting>
27+
<setting name="FormMainLocation" serializeAs="String">
28+
<value>100, 100</value>
29+
</setting>
30+
<setting name="TopMostChecked" serializeAs="String">
31+
<value>False</value>
32+
</setting>
33+
<setting name="FrameRate" serializeAs="String">
34+
<value>30</value>
35+
</setting>
36+
<setting name="AutoPullUpChecked" serializeAs="String">
37+
<value>True</value>
38+
</setting>
39+
<setting name="DisplayDetectChecked" serializeAs="String">
40+
<value>False</value>
41+
</setting>
42+
<setting name="AlwaysHideAreaChecked" serializeAs="String">
43+
<value>False</value>
44+
</setting>
45+
</GenshinAutoFish.Properties.Settings>
46+
</userSettings>
47+
</configuration>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using GenshinAutoFish.Utils;
2+
using System;
3+
using System.Drawing;
4+
5+
namespace GenshinAutoFish.Core
6+
{
7+
public class ImageCapture
8+
{
9+
IntPtr hwnd;
10+
IntPtr hdc;
11+
12+
public int X { get; set; }
13+
public int Y { get; set; }
14+
public int W { get; set; }
15+
public int H { get; set; }
16+
17+
public void Start(int x, int y, int w, int h)
18+
{
19+
hwnd = Native.GetDesktopWindow();
20+
hdc = Native.GetDC(hwnd);
21+
this.X = x;
22+
this.Y = y;
23+
this.W = w;
24+
this.H = h;
25+
}
26+
27+
public Bitmap Capture(bool extend, out Bitmap rodWordsAreaBitmap)
28+
{
29+
Bitmap bmp = new Bitmap(W, H);
30+
Graphics bmpGraphic = Graphics.FromImage(bmp);
31+
//get handle to source graphic
32+
IntPtr bmpHdc = bmpGraphic.GetHdc();
33+
34+
//copy it
35+
bool res = Native.StretchBlt(bmpHdc, 0, 0, W, H,
36+
hdc, X, Y, W, H, Native.CopyPixelOperation.SourceCopy);
37+
bmpGraphic.ReleaseHdc();
38+
39+
// 非钓鱼期间不需要这个图片
40+
if (extend)
41+
{
42+
rodWordsAreaBitmap = new Bitmap(W, H * 2);
43+
Graphics bmpGraphic2 = Graphics.FromImage(rodWordsAreaBitmap);
44+
IntPtr bmpHdc2 = bmpGraphic2.GetHdc();
45+
Native.StretchBlt(bmpHdc2, 0, 0, W, H * 2,
46+
hdc, X, Y + H, W, H * 2, Native.CopyPixelOperation.SourceCopy);
47+
bmpGraphic2.ReleaseHdc();
48+
49+
}
50+
else
51+
{
52+
rodWordsAreaBitmap = null;
53+
}
54+
return bmp;
55+
}
56+
57+
public void Stop()
58+
{
59+
Native.ReleaseDC(hwnd, hdc);
60+
}
61+
}
62+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using OpenCvSharp;
2+
using OpenCvSharp.Extensions;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Drawing;
6+
using System.Drawing.Imaging;
7+
using System.Linq;
8+
using System.Runtime.InteropServices;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
12+
namespace GenshinAutoFish.Core
13+
{
14+
class ImageRecognition
15+
{
16+
public static Bitmap GetRect(Bitmap img, out List<Rect> rects, bool enableImShow)
17+
{
18+
using (Mat mask = new Mat())
19+
using (Mat rgbMat = new Mat())
20+
using (Mat src = img.ToMat())
21+
{
22+
Cv2.CvtColor(src, rgbMat, ColorConversionCodes.BGR2RGB);
23+
var lowPurple = new Scalar(255, 255, 192);
24+
var highPurple = new Scalar(255, 255, 192);
25+
Cv2.InRange(rgbMat, lowPurple, highPurple, mask);
26+
Cv2.Threshold(mask, mask, 0, 255, ThresholdTypes.Binary); //二值化
27+
28+
OpenCvSharp.Point[][] contours;
29+
HierarchyIndex[] hierarchy;
30+
Cv2.FindContours(mask, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple, null);
31+
if (contours.Length > 0)
32+
{
33+
var imgTar = src.Clone();
34+
var boxes = contours.Select(Cv2.BoundingRect).Where(w => w.Height >= 10);
35+
rects = boxes.ToList();
36+
foreach (Rect rect in rects)
37+
{
38+
Cv2.Rectangle(imgTar, new OpenCvSharp.Point(rect.X, rect.Y), new OpenCvSharp.Point(rect.X + rect.Width, rect.Y + rect.Height), Scalar.Red, 2);
39+
}
40+
if (enableImShow)
41+
{
42+
Cv2.ImShow("钓鱼条识别窗口", imgTar);
43+
}
44+
return imgTar.ToBitmap();
45+
}
46+
else
47+
{
48+
rects = null;
49+
return src.ToBitmap();
50+
}
51+
}
52+
53+
}
54+
55+
public static Rect MatchWords(Bitmap img, ImageCapture capture, bool enableImShow)
56+
{
57+
using (Mat src = img.ToMat())
58+
using (Mat result = new Mat())
59+
{
60+
Cv2.CvtColor(src, src, ColorConversionCodes.BGR2RGB);
61+
var lowPurple = new Scalar(253, 253, 253);
62+
var highPurple = new Scalar(255, 255, 255);
63+
Cv2.InRange(src, lowPurple, highPurple, src);
64+
Cv2.Threshold(src, src, 0, 255, ThresholdTypes.Binary);
65+
var kernel = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(20, 20), new OpenCvSharp.Point(-1, -1));
66+
Cv2.Dilate(src, src, kernel); //膨胀
67+
68+
Scalar color = new Scalar(0, 0, 255);
69+
OpenCvSharp.Point[][] contours;
70+
HierarchyIndex[] hierarchy;
71+
Cv2.FindContours(src, out contours, out hierarchy, RetrievalModes.External, ContourApproximationModes.ApproxSimple, null);
72+
if (contours.Length > 0)
73+
{
74+
var imgTar = img.ToMat();
75+
var boxes = contours.Select(Cv2.BoundingRect);
76+
List<Rect> rects = boxes.ToList();
77+
if (rects.Count > 1)
78+
{
79+
rects.Sort((a, b) => b.Height.CompareTo(a.Height));
80+
}
81+
if (rects[0].Height < src.Height
82+
&& rects[0].Width * 1.0 / rects[0].Height >= 3 // 长宽比判断
83+
&& capture.W > rects[0].Width * 3 // 文字范围3倍小于钓鱼条范围的
84+
&& capture.W * 1.0 / 2 > rects[0].X // 中轴线判断左
85+
&& capture.W * 1.0 / 2 < rects[0].X + rects[0].Width) // 中轴线判断右
86+
{
87+
foreach (Rect rect in rects)
88+
{
89+
Cv2.Rectangle(imgTar, new OpenCvSharp.Point(rect.X, rect.Y), new OpenCvSharp.Point(rect.X + rect.Width, rect.Y + rect.Height), Scalar.Red, 2);
90+
}
91+
if (enableImShow)
92+
{
93+
Cv2.ImShow("自动提杆识别窗口", imgTar);
94+
}
95+
return rects[0];
96+
}
97+
}
98+
}
99+
return Rect.Empty;
100+
}
101+
102+
}
103+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using GenshinAutoFish.Utils;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Diagnostics;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using System.Windows.Forms;
11+
12+
namespace GenshinAutoFish.Core
13+
{
14+
public class YuanShenWindow
15+
{
16+
public static uint WM_LBUTTONDOWN = 0x201; //按下鼠标左键
17+
18+
public static uint WM_LBUTTONUP = 0x202; //释放鼠标左键
19+
20+
21+
private IntPtr hWnd;
22+
public YuanShenWindow()
23+
{
24+
25+
}
26+
27+
public bool GetHWND()
28+
{
29+
var pros = Process.GetProcessesByName("YuanShen");
30+
if (pros.Any())
31+
{
32+
hWnd = pros[0].MainWindowHandle;
33+
return true;
34+
}
35+
else
36+
{
37+
pros = Process.GetProcessesByName("GenshinImpact");
38+
if (pros.Any())
39+
{
40+
hWnd = pros[0].MainWindowHandle;
41+
return true;
42+
}
43+
else
44+
{
45+
return false;
46+
}
47+
}
48+
}
49+
50+
public Rectangle GetSize()
51+
{
52+
Native.RECT rc = new Native.RECT();
53+
Native.GetWindowRect(hWnd, ref rc);
54+
return new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top);
55+
}
56+
57+
public void MouseLeftButtonDown()
58+
{
59+
IntPtr p = (IntPtr)((0 << 16) | 0);
60+
Native.PostMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, p);
61+
62+
}
63+
64+
public void MouseLeftButtonUp()
65+
{
66+
IntPtr p = (IntPtr)((0 << 16) | 0);
67+
Native.PostMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, p);
68+
}
69+
70+
public void MouseClick(int x, int y)
71+
{
72+
IntPtr p = (IntPtr)((y << 16) | x);
73+
Native.PostMessage(hWnd, WM_LBUTTONDOWN, IntPtr.Zero, p);
74+
Thread.Sleep(100);
75+
Native.PostMessage(hWnd, WM_LBUTTONUP, IntPtr.Zero, p);
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)