Merge branch 'main' into d-v2

This commit is contained in:
辉鸭蛋
2025-04-20 13:12:14 +08:00
14 changed files with 33 additions and 44 deletions

View File

@@ -223,6 +223,11 @@ public class GlobalMethod
Simulation.SendInput.Mouse.MiddleButtonUp();
}
public static void VerticalScroll(int scrollAmountInClicks)
{
Simulation.SendInput.Mouse.VerticalScroll(scrollAmountInClicks);
}
#endregion
#region
@@ -263,7 +268,7 @@ public class GlobalMethod
}
catch (Exception ex)
{
TaskControl.Logger.LogDebug("输入文本时发生错误: {Msg}",ex.Message);
TaskControl.Logger.LogDebug("输入文本时发生错误: {Msg}", ex.Message);
}
finally
{

View File

@@ -8,7 +8,7 @@ public class Log
public void Debug(string? message, params object?[] args)
{
_logger.LogInformation(message, args);
_logger.LogDebug(message, args);
}
public void Info(string? message, params object?[] args)

View File

@@ -98,6 +98,7 @@ public class EngineExtend
engine.AddHostObject("middleButtonClick", GlobalMethod.MiddleButtonClick);
engine.AddHostObject("middleButtonDown", GlobalMethod.MiddleButtonDown);
engine.AddHostObject("middleButtonUp", GlobalMethod.MiddleButtonUp);
engine.AddHostObject("verticalScroll", GlobalMethod.VerticalScroll);
engine.AddHostObject("captureGameRegion", GlobalMethod.CaptureGameRegion);
engine.AddHostObject("inputText", GlobalMethod.InputText);
#pragma warning restore CS8974 // Converting method group to non-delegate type

View File

@@ -119,10 +119,10 @@ public class Avatar
/// tp 到七天神像恢复
/// </summary>
/// <param name="ct"></param>
/// <param name="ex"></param>
/// <exception cref="RetryException"></exception>
public static void TpForRecover(CancellationToken ct, Exception ex)
{
Simulation.SendInput.SimulateAction(GIActions.OpenMap);
// tp 到七天神像复活
var tpTask = new TpTask(ct);
tpTask.TpToStatueOfTheSeven().Wait(ct);

View File

@@ -318,8 +318,9 @@ public class CombatScenes : IDisposable
/// <returns></returns>
public Avatar? SelectAvatar(int avatarIndex)
{
if (avatarIndex < 1 || avatarIndex >= AvatarCount)
if (avatarIndex < 1 || avatarIndex > AvatarCount)
{
Logger.LogError("切换角色编号错误,当前角色数量{Count},编号{Index}", AvatarCount, avatarIndex);
return null;
}

View File

@@ -336,6 +336,7 @@ public class TpTask(CancellationToken ct)
if (!await TryToOpenBigMapUi())
{
await new ReturnMainUiTask().Start(ct);
await Delay(500, ct);
if (!await TryToOpenBigMapUi())
{
throw new RetryException("打开大地图失败,请检查按键绑定中「打开地图」按键设置是否和原神游戏中一致!");

View File

@@ -7,7 +7,6 @@ namespace Fischless.GameCapture.BitBlt;
public class BitBltCapture : IGameCapture
{
public CaptureModes Mode => CaptureModes.BitBltNew;
public bool IsCapturing { get; private set; }
private readonly Stopwatch _sizeCheckTimer = new();
private readonly ReaderWriterLockSlim _lockSlim = new();
@@ -136,7 +135,7 @@ public class BitBltCapture : IGameCapture
{
_lockSlim.EnterReadLock();
var result = Capture0();
if (result is not null && !result.Empty())
if (result is not null)
{
// 成功截图
_lastCaptureFailed = false;
@@ -166,9 +165,9 @@ public class BitBltCapture : IGameCapture
/// 截图功能的实现。需要加锁后调用,一般只由 Capture 方法调用。
/// </summary>
/// <returns></returns>
private Mat? Capture0()
private Bitmap? Capture0()
{
Mat? mat = null;
Bitmap? bitmap = null;
try
{
if (_session is null)
@@ -176,27 +175,14 @@ public class BitBltCapture : IGameCapture
// 没有成功创建会话,直接返回空
return null;
}
mat = _session.GetMat();
if (mat is null) return null; // 执行失败
if (!mat.Empty()) // 成功执行并且获取到了图
{
return mat;
}
else // 成功执行但是没有图,可能是截图过快导致的
{
mat.Dispose();
mat = null; // 防止二次释放
}
return null;
bitmap = _session.GetImage();
return bitmap;
}
catch (Exception e)
{
// 理论这里不应出现异常除非窗口不存在了或者有什么bug
// 出现异常的时候释放内存
mat?.Dispose();
bitmap?.Dispose();
Error.WriteLine("[BitBlt]Failed to capture image {0}", e);
return null;
}

View File

@@ -7,8 +7,6 @@ public class BitBltOldCapture : IGameCapture
{
private nint _hWnd;
public CaptureModes Mode => CaptureModes.BitBlt;
public static object LockObject { get; } = new();
public bool IsCapturing { get; private set; }

View File

@@ -160,10 +160,9 @@ public class BitBltSession : IDisposable
/// <summary>
/// 调用GDI复制到缓冲区并返回新mat
/// 调用GDI复制到缓冲区并返回新Image
/// </summary>
/// <returns>MatType.CV_8UC3</returns>
public Mat? GetMat()
public Bitmap? GetImage()
{
lock (_lockObject)
{
@@ -184,17 +183,18 @@ public class BitBltSession : IDisposable
return null;
}
// 这个是bitmap的结构信息不用手动释放
if (bitmap.bmPlanes != 1 || bitmap.bmBitsPixel != 24)
// 不支持的位图格式
return null;
// 直接返回转换后的位图
var success = Gdi32.AlphaBlend(_hdcDest, 0, 0, _width, _height, _hdcSrc, 0, 0,
_width, _height, BlendFunction);
if (!success || !Gdi32.GdiFlush()) return null;
// 这个是bitmap的结构信息不用手动释放
if (bitmap.bmPlanes != 1 || bitmap.bmBitsPixel != 24)
// 不支持的位图格式
return null;
return Mat.FromPixelData(bitmap.bmHeight, bitmap.bmWidth, MatType.CV_8UC3, bitmap.bmBits,
bitmap.bmWidthBytes);
// return Mat.FromPixelData(bitmap.bmHeight, bitmap.bmWidth, MatType.CV_8UC3, bitmap.bmBits,bitmap.bmWidthBytes);
return _hBitmap.ToBitmap();
// 原始宏 ((((biWidth * biBitCount) + 31) & ~31) >> 3) => (biWidth * biBitCount + 3) & ~3) (在总位数是8的倍数时两者等价)
// 对齐 https://learn.microsoft.com/zh-cn/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader

View File

@@ -4,11 +4,11 @@ namespace Fischless.GameCapture;
public enum CaptureModes
{
[Description("BitBlt稳定")]
BitBlt,
// [Description("BitBlt稳定")]
// BitBlt,
[Description("BitBlt(极速)")]
BitBltNew,
[Description("BitBlt")]
BitBlt,
[Description("WindowsGraphicsCapture")]
WindowsGraphicsCapture,

View File

@@ -22,7 +22,6 @@ namespace Fischless.GameCapture.DwmSharedSurface
private ResourceRegion? _region;
public CaptureModes Mode => CaptureModes.DwmGetDxSharedSurface;
public void Start(nint hWnd, Dictionary<string, object>? settings = null)
{

View File

@@ -11,8 +11,8 @@ public class GameCaptureFactory
{
return mode switch
{
CaptureModes.BitBltNew => new BitBlt.BitBltCapture(),
CaptureModes.BitBlt => new BitBlt.BitBltOldCapture(),
CaptureModes.BitBlt => new BitBlt.BitBltCapture(),
// CaptureModes.BitBlt => new BitBlt.BitBltOldCapture(),
CaptureModes.WindowsGraphicsCapture => new Graphics.GraphicsCapture(),
CaptureModes.DwmGetDxSharedSurface => new DwmSharedSurface.SharedSurfaceCapture(),
_ => throw new ArgumentOutOfRangeException(nameof(mode), mode, null),

View File

@@ -24,7 +24,6 @@ public class GraphicsCapture : IGameCapture
private IDirect3DDevice _d3dDevice = null!;
public CaptureModes Mode => CaptureModes.WindowsGraphicsCapture;
public bool IsCapturing { get; private set; }
private ResourceRegion? _region;

View File

@@ -4,7 +4,6 @@ namespace Fischless.GameCapture;
public interface IGameCapture : IDisposable
{
public CaptureModes Mode { get; }
public bool IsCapturing { get; }
public void Start(nint hWnd, Dictionary<string, object>? settings = null);