Skip to content

Commit

Permalink
Supported WindowsGraphicsCapture for Windows 10 as default
Browse files Browse the repository at this point in the history
  • Loading branch information
emako committed Sep 1, 2023
1 parent 31f851d commit ccb0fc8
Show file tree
Hide file tree
Showing 40 changed files with 2,439 additions and 75 deletions.
25 changes: 25 additions & 0 deletions src/GenshinFishingToy.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenshinFishingToy", "Genshi
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "GenshinFishingToySetup", "GenshinFishingToySetup\GenshinFishingToySetup.wapproj", "{A80A34DD-ACBC-4D67-A22D-156A0FFC32A8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WindowsGraphicsCapture", "WindowsGraphicsCapture", "{61B278E1-2049-475B-B200-3F0C3DDA87C2}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScreenCapture", "WindowsGraphicsCapture\ScreenCapture\ScreenCapture.csproj", "{AB145A23-0897-4517-8EA6-BEB87CB9D26A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CaptureSampleCore", "WindowsGraphicsCapture\CaptureSampleCore\CaptureSampleCore.csproj", "{D8154C31-38C2-49E2-96A0-69EB76567461}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Composition.WindowsRuntimeHelpers", "WindowsGraphicsCapture\Composition.WindowsRuntimeHelpers\Composition.WindowsRuntimeHelpers.csproj", "{AE6F99F5-AFD5-467E-A082-D4003E3EEECF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -23,10 +31,27 @@ Global
{A80A34DD-ACBC-4D67-A22D-156A0FFC32A8}.Release|x64.ActiveCfg = Release|x64
{A80A34DD-ACBC-4D67-A22D-156A0FFC32A8}.Release|x64.Build.0 = Release|x64
{A80A34DD-ACBC-4D67-A22D-156A0FFC32A8}.Release|x64.Deploy.0 = Release|x64
{AB145A23-0897-4517-8EA6-BEB87CB9D26A}.Debug|x64.ActiveCfg = Debug|x64
{AB145A23-0897-4517-8EA6-BEB87CB9D26A}.Debug|x64.Build.0 = Debug|x64
{AB145A23-0897-4517-8EA6-BEB87CB9D26A}.Release|x64.ActiveCfg = Release|x64
{AB145A23-0897-4517-8EA6-BEB87CB9D26A}.Release|x64.Build.0 = Release|x64
{D8154C31-38C2-49E2-96A0-69EB76567461}.Debug|x64.ActiveCfg = Debug|x64
{D8154C31-38C2-49E2-96A0-69EB76567461}.Debug|x64.Build.0 = Debug|x64
{D8154C31-38C2-49E2-96A0-69EB76567461}.Release|x64.ActiveCfg = Release|x64
{D8154C31-38C2-49E2-96A0-69EB76567461}.Release|x64.Build.0 = Release|x64
{AE6F99F5-AFD5-467E-A082-D4003E3EEECF}.Debug|x64.ActiveCfg = Debug|x64
{AE6F99F5-AFD5-467E-A082-D4003E3EEECF}.Debug|x64.Build.0 = Debug|x64
{AE6F99F5-AFD5-467E-A082-D4003E3EEECF}.Release|x64.ActiveCfg = Release|x64
{AE6F99F5-AFD5-467E-A082-D4003E3EEECF}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AB145A23-0897-4517-8EA6-BEB87CB9D26A} = {61B278E1-2049-475B-B200-3F0C3DDA87C2}
{D8154C31-38C2-49E2-96A0-69EB76567461} = {61B278E1-2049-475B-B200-3F0C3DDA87C2}
{AE6F99F5-AFD5-467E-A082-D4003E3EEECF} = {61B278E1-2049-475B-B200-3F0C3DDA87C2}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DFA8F1CD-513D-45D7-856D-378146C4D367}
EndGlobalSection
Expand Down
6 changes: 5 additions & 1 deletion src/GenshinFishingToy/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GenshinFishingToy.Core;
using Composition.WindowsRuntimeHelpers;
using GenshinFishingToy.Core;
using GenshinFishingToy.ViewModels;
using Hardcodet.Wpf.TaskbarNotification;
using Microsoft.Toolkit.Uwp.Notifications;
Expand All @@ -9,11 +10,13 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using Windows.System;

namespace GenshinFishingToy;

public partial class App : Application
{
private DispatcherQueueController _controller;
public static new App? Current { get; protected set; } = null!;
public TaskbarIcon Taskbar { get; protected set; } = null!;
public static bool IsElevated { get; } = GetElevated();
Expand All @@ -23,6 +26,7 @@ public App()
Logger.Info("Startup");
Current = this;
Current.DispatcherUnhandledException += (_, e) => e.Handled = true;
_controller = CoreMessagingHelper.CreateDispatcherQueueControllerForCurrentThread();
AppDomain.CurrentDomain.UnhandledException += (s, e) => Logger.Error(e);
ToastNotificationManagerCompat.OnActivated += NotifyIconViewModel.OnNotificationActivated;
NoticeService.ClearNotice();
Expand Down
42 changes: 40 additions & 2 deletions src/GenshinFishingToy/Core/ImageCapture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows;
using WPFCaptureSample;

namespace GenshinFishingToy.Core;

Expand All @@ -11,6 +13,8 @@ internal static class ImageCapture
public static int W { get; set; }
public static int H { get; set; }

public static ImageCaptureType CaptureType = ImageCaptureType.WindowsGraphicsCapture;

public static void Setup(int x, int y, int w, int h)
{
X = x;
Expand All @@ -24,6 +28,11 @@ public static void Setup((int x, int y, int w, int h) rect)
Setup(rect.x, rect.y, rect.w, rect.h);
}

public static void Teardown()
{
GraphicsCapture.Uncapture();
}

public static bool IsFullScreen { get; private set; } = false;
public static bool IsFullScreenMode(IntPtr hwnd)
{
Expand Down Expand Up @@ -52,11 +61,40 @@ private static int GetCaptionHeight(IntPtr? hwnd = null)

public static Bitmap Capture(IntPtr? hwnd = null)
{
return ImageExtension.Capture(X, Y - GetCaptionHeight(hwnd), W, H, hwnd);
if (CaptureType == ImageCaptureType.BitBlt)
{
return ImageExtension.Capture(X, Y - GetCaptionHeight(hwnd), W, H, hwnd);
}
else if (CaptureType == ImageCaptureType.WindowsGraphicsCapture)
{
return GraphicsCapture.Capture(X, Y, W, H, hwnd);
}
return null!;
}

public static Bitmap CaptureLiftingWords(IntPtr? hwnd = null)
{
return ImageExtension.Capture(X, Y - GetCaptionHeight(hwnd) + H, W, (int)(H * 2.5d), hwnd);
if (CaptureType == ImageCaptureType.BitBlt)
{
return ImageExtension.Capture(X, Y - GetCaptionHeight(hwnd) + H, W, (int)(H * 2.5d), hwnd);
}
else if (CaptureType == ImageCaptureType.WindowsGraphicsCapture)
{
return GraphicsCapture.Capture(X, Y + H, W, (int)(H * 2.5d), hwnd);
}
return null!;
}
}

public enum ImageCaptureType
{
/// <summary>
/// BitBlt (Windows 7 and up)
/// </summary>
BitBlt,

/// <summary>
/// Windows 10 (1903 and up)
/// </summary>
WindowsGraphicsCapture,
}
10 changes: 10 additions & 0 deletions src/GenshinFishingToy/Core/ImageJigging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ internal class ImageJigging

public bool IsRunning { get; protected set; } = false;

private Preview previewForm = null!;

public ImageJigging()
{
timerCapture.Tick += Tick;
timerCapture.Interval = Convert.ToInt32(1000d / frameRate);
timerCapture.Start();
previewForm = new();

if (Settings.ShowRecognitionCapture.Get())
{
previewForm.Show();
}
}

public async Task StartFishing()
Expand All @@ -47,6 +55,7 @@ public async Task StopFishing()
IsRunning = false;
findFishBoxTips = false;
isFishingProcess = false;
ImageCapture.Teardown();
}

public async void Tick(object? sender, EventArgs e)
Expand Down Expand Up @@ -102,6 +111,7 @@ public async void Tick(object? sender, EventArgs e)
ImageCapture.Setup(rect);

using Bitmap captured = ImageCapture.Capture(window.Hwnd);
previewForm.SetImage(captured);
rects = ImageRecognition.GetRect(captured, Settings.ShowRecognitionJigging);

window.MotionArea.Rects = rects?.ToArray() ?? Array.Empty<Rect>();
Expand Down
3 changes: 3 additions & 0 deletions src/GenshinFishingToy/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura />
</Weavers>
141 changes: 141 additions & 0 deletions src/GenshinFishingToy/FodyWeavers.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. -->
<xs:element name="Weavers">
<xs:complexType>
<xs:all>
<xs:element name="Costura" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with line breaks</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with line breaks.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:all>
<xs:attribute name="CreateTemporaryAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>This will copy embedded files to disk before loading them into memory. This is helpful for some scenarios that expected an assembly to be loaded from a physical file.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeDebugSymbols" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if .pdbs for reference assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeReferences" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls if runtime assemblies are also embedded.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="UseRuntimeReferencePaths" type="xs:boolean">
<xs:annotation>
<xs:documentation>Controls whether the runtime assemblies are embedded with their full path or only with their assembly name.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCompression" type="xs:boolean">
<xs:annotation>
<xs:documentation>Embedded assemblies are compressed by default, and uncompressed when they are loaded. You can turn compression off with this option.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="DisableCleanup" type="xs:boolean">
<xs:annotation>
<xs:documentation>As part of Costura, embedded assemblies are no longer included as part of the build. This cleanup can be turned off.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="LoadAtModuleInit" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura by default will load as part of the module initialization. This flag disables that behavior. Make sure you call CosturaUtility.Initialize() somewhere in your code.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IgnoreSatelliteAssemblies" type="xs:boolean">
<xs:annotation>
<xs:documentation>Costura will by default use assemblies with a name like 'resources.dll' as a satellite resource and prepend the output path. This flag disables that behavior.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="ExcludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to exclude from the default action of "embed all Copy Local references", delimited with |</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="IncludeRuntimeAssemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of runtime assembly names to include from the default action of "embed all Copy Local references", delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged32Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 32 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="Unmanaged64Assemblies" type="xs:string">
<xs:annotation>
<xs:documentation>A list of unmanaged 64 bit assembly names to include, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="PreloadOrder" type="xs:string">
<xs:annotation>
<xs:documentation>The order of preloaded assemblies, delimited with |.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:all>
<xs:attribute name="VerifyAssembly" type="xs:boolean">
<xs:annotation>
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="VerifyIgnoreCodes" type="xs:string">
<xs:annotation>
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute name="GenerateXsd" type="xs:boolean">
<xs:annotation>
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:schema>
Loading

0 comments on commit ccb0fc8

Please sign in to comment.