Skip to content

Commit

Permalink
Add ClampRectangle method and update D3D11Screen logic
Browse files Browse the repository at this point in the history
Introduced a new private method `ClampRectangle` in the `AIManager`
class to ensure rectangles are clamped within screen bounds,
preventing out-of-bounds issues. Updated the `D3D11Screen` method
to use `ClampRectangle` for adjusting the `detectionBox` parameter.
Added a `using` directive for `System.Windows.Threading` to support
the use of `Dispatcher`.
  • Loading branch information
TaylorIsBlue committed Aug 13, 2024
1 parent f195e56 commit cce7a1e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Aimmy2/AILogic/AIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Drawing.Imaging;
using System.IO;
using System.Windows;
using System.Windows.Threading;
using Visuality;
using Vortice.Direct3D;
using Vortice.Direct3D11;
Expand Down Expand Up @@ -672,7 +673,12 @@ private void ReinitializeD3D11()
// Reinitialize Direct3D device and context
InitializeDirect3D();
}

private Rectangle ClampRectangle(Rectangle rect, int screenWidth, int screenHeight)
{
int x = Math.Max(0, Math.Min(rect.X, screenWidth - rect.Width));
int y = Math.Max(0, Math.Min(rect.Y, screenHeight - rect.Height));
return new Rectangle(x, y, rect.Width, rect.Height);
}
private Bitmap? D3D11Screen(Rectangle detectionBox)
{
try
Expand All @@ -681,7 +687,7 @@ private void ReinitializeD3D11()
{
throw new InvalidOperationException("Direct3D device or context is not initialized.");
}

detectionBox = ClampRectangle(detectionBox, ScreenWidth, ScreenHeight);
var result = _outputDuplication.AcquireNextFrame(500, out var frameInfo, out var desktopResource);

if (result != Result.Ok)
Expand Down

0 comments on commit cce7a1e

Please sign in to comment.