Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private static DirectBitmap GetAdjustedDirectBitmapOfImage(Image img, float brig

public string TestWeapons()
{
this._logger?.NewSnapshot();
var w1Img = GetWeapon1Image(FullScreenMode);
var w2Img = GetWeapon2Image(FullScreenMode);
w1Img.SaveTestImage();
Expand Down
40 changes: 39 additions & 1 deletion ScreenAssistant.ScreenInfoRecognition/ScreenCapture.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;

namespace TiqSoft.ScreenAssistant.ScreenInfoRecognition
Expand Down Expand Up @@ -30,6 +31,7 @@ public static Image CaptureScreenRelatively(float startX, float endX, float star
if (fullScreen)
{
return CaptureWindow(User32.GetDesktopWindow(), startX, endX, startY, endY);
//return CaptureWindowFromGraphics(User32.GetForegroundWindow(), startX, endX, startY, endY);
}

return CaptureWindow(User32.GetForegroundWindow(), startX, endX, startY, endY);
Expand Down Expand Up @@ -62,7 +64,7 @@ internal static Image CaptureWindow(IntPtr handle, float startX, float endX, flo
IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
// bitblt over
GDI32.BitBlt(hdcDest, 0, 0, (int)((endX - startX) * width / 100), (int)((endY - startY) * height / 100),
hdcSrc, (int)(startX * width / 100), (int)(startY * height / 100), GDI32.SRCCOPY);
hdcSrc, (int)(startX * width / 100), (int)(startY * height / 100), GDI32.SRCCOPY | GDI32.CAPTUREBLT);
// restore selection
GDI32.SelectObject(hdcDest, hOld);
// clean up
Expand All @@ -74,6 +76,41 @@ internal static Image CaptureWindow(IntPtr handle, float startX, float endX, flo
GDI32.DeleteObject(hBitmap);
return img;
}

/// <summary>
/// Creates an Image object containing a screen shot of a specific window
/// </summary>
/// <param name="handlePtr">The handle to the window.</param>
/// <param name="startX">0-100 percent of start by X</param>
/// <param name="endX">0-100 percent of end by X</param>
/// <param name="startY">0-100 percent of start by Y</param>
/// <param name="endY">0-100 percent of end by Y</param>
/// <returns></returns>
internal static Image CaptureWindowFromGraphics(IntPtr handlePtr, float startX, float endX, float startY, float endY)
{
User32.RECT windowRect = new User32.RECT();
User32.GetWindowRect(handlePtr, ref windowRect);
int width = windowRect.right - windowRect.left;
int height = windowRect.bottom - windowRect.top;
var tWidth = (int) ((endX - startX) * width / 100);
var tHeight = (int) ((endY - startY) * height / 100);
var xSrc = (int) (startX * width / 100);
var ySrc = (int) (startY * height / 100);

if (tWidth > 0 && tHeight > 0)
{
Bitmap bitmap = new Bitmap(tWidth, tHeight);
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(xSrc, ySrc), Point.Empty, new Size(tWidth, tHeight));
}
return bitmap;
}

return new Bitmap(1, 1);
}


/// <summary>
/// Captures a screen shot of a specific window, and saves it to a file
/// </summary>
Expand Down Expand Up @@ -101,6 +138,7 @@ public static void CaptureScreenToFile(string filename, ImageFormat format)
/// </summary>
private class GDI32
{
public const int CAPTUREBLT = 0x40000000;

public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
[DllImport("gdi32.dll")]
Expand Down
2 changes: 1 addition & 1 deletion ScreenAssistant/Games/ApLeg/WeaponAL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum WeaponAL
{
[WeaponData("", 0, " ")]
Unknown = 1 << 0,
[WeaponData("Havoc", 5, "HAVUC")]
[WeaponData("Havoc", 4, "HAVUC")]
Havoc = 1 << 1,
[WeaponData("Triple take", 4)]
TripleTake = 1 << 2,
Expand Down
2 changes: 1 addition & 1 deletion ScreenAssistant/Games/ApLeg/Weapons/Havoc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Havoc(string name, double burstSeconds, string recognizedName, int numOfM

public override double AdjustMouse(int shotNumber)
{
var notOffsettingDelay = this.GetModuleType(4) == WeaponModuleType.Legendary ? 0 : 6;
var notOffsettingDelay = this.GetModuleType(3) == WeaponModuleType.Legendary ? 0 : 6;
if (shotNumber > notOffsettingDelay)
{
this.AdjustmentCoefficient = CalculateAdjustment(shotNumber, 40);
Expand Down