11
There is a game called Tibia (In same window mode) that when trying to take a print screen the game ends up obscuring the image leaving only the whole black game screen independent if the print originated from the Printscreen key, or from some function via code c#.
I have tried some ways to capture the image of the game but without success.
I don’t know exactly what they do that can outshine only the window of the game in question.
I tried two ways:
Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);
The second:
public static Bitmap GetDesktopImage()
{
WIN32_API.SIZE size;
IntPtr hDC = WIN32_API.GetDC(WIN32_API.GetDesktopWindow());
IntPtr hMemDC = WIN32_API.CreateCompatibleDC(hDC);
size.cx = WIN32_API.GetSystemMetrics(WIN32_API.SM_CXSCREEN);
size.cy = WIN32_API.GetSystemMetrics(WIN32_API.SM_CYSCREEN);
m_HBitmap = WIN32_API.CreateCompatibleBitmap(hDC, size.cx, size.cy);
if (m_HBitmap != IntPtr.Zero)
{
IntPtr hOld = (IntPtr)WIN32_API.SelectObject(hMemDC, m_HBitmap);
WIN32_API.BitBlt(hMemDC, 0, 0, size.cx, size.cy, hDC, 0, 0, WIN32_API.SRCCOPY);
WIN32_API.SelectObject(hMemDC, hOld);
WIN32_API.DeleteDC(hMemDC);
WIN32_API.ReleaseDC(WIN32_API.GetDesktopWindow(), hDC);
return System.Drawing.Image.FromHbitmap(m_HBitmap);
}
return null;
}
public class WIN32_API
{
public struct SIZE
{
public int cx;
public int cy;
}
public const int SRCCOPY = 13369376;
public const int SM_CXSCREEN = 0;
public const int SM_CYSCREEN = 1;
[DllImport("gdi32.dll", EntryPoint = "DeleteDC")]
public static extern IntPtr DeleteDC(IntPtr hDc);
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
public static extern IntPtr DeleteObject(IntPtr hDc);
[DllImport("gdi32.dll", EntryPoint = "BitBlt")]
public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, int RasterOp);
[DllImport("gdi32.dll", EntryPoint = "CreateCompatibleBitmap")]
public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
[DllImport("gdi32.dll", EntryPoint = "CreateCompatibleDC")]
public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
[DllImport("gdi32.dll", EntryPoint = "SelectObject")]
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll", EntryPoint = "GetDC")]
public static extern IntPtr GetDC(IntPtr ptr);
[DllImport("user32.dll", EntryPoint = "GetSystemMetrics")]
public static extern int GetSystemMetrics(int abc);
[DllImport("user32.dll", EntryPoint = "GetWindowDC")]
public static extern IntPtr GetWindowDC(Int32 ptr);
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
}
Is there any other way to take print and avoid this obfuscation?
What is the type of blocking of this program? Does it block the print wind as a whole or blocks blurs its image? Without knowing which or how the program works it is difficult to post an assertive answer, being impossible to reproduce the behavior. And if the program does this blocking, it must be for some good reason... Should you really be trying to do this?
– Leandro Angelo
@Leandroangelo I edited the question explaining that it is only the window that comes out black and any other element is printed in print normally.
– Victor Laio
a screen recording program, works ?
– Rovann Linhalis
I’ll try, but what’s the reason for the test?
– Victor Laio
try to understand how his lock works... rs
– Rovann Linhalis
I did a search here... actually there’s a "battleye" service that does this blocking. An option to work around this problem is to set a hot key for the in-game printscreen, and in C#, read the destination folder and send the hot key
– Rovann Linhalis
@Rovannlinhalis I even explored some of this option and it even works but I spend a lot of time processing the Getfiles() function to get the printscreen
– Victor Laio
use a
FileSystemWatcher
– Rovann Linhalis
@Rovannlinhalis Even using Filesystemwatcher got very badly optimized, it really needed something more direct as a printscreen itself. 500~800ms just until the game creates the file in the folder and I load this image to read. Time I can not lose :(
– Victor Laio
@Rovannlinhalis I tried to record the screen with OBS and yes it works
– Victor Laio
@Victorlaio why don’t you use the API of OBS then? Here has the wrapper for . NET.
– CypherPotato
giving a search, I read something about the battleye do a scan every 100 seconds and then pick up the processes that are capturing something from the game. I would do a test using this second code of yours, but running in different processes, one exe to capture the screen and another to process... then each capture will have a different pid or at least every time interval
– Rovann Linhalis
I installed the game in a vm, and the second code works normally... at least in the introduction and tutorial... ok (win 7)
– Rovann Linhalis