2

I am trying to create some kind of antycheat for counter strike (hl) game. Of course funcionality of making a screenshot in-game is built-in, but exploited (detected) by antyss applications, so every time screenshot is taken from the game, antyss is disabling the cheats (so that no cheats are visible on the screenshots)

For the last few days, I've read dozens of threads regarding this topic. Most of them are outdated and are using libraries, that are obsolete right now.

I've read about the approach with mirage driver (which is not working on windows 10), about injecting to the application (of course application/game is not part of my code) and using/incjeting some code with OPEN GL/D3D library (to read backbuffer). Probably this could be in the end the only solution.

But right now I have almost a working solution. I write "almost" because it is working but giving me only some kind of "cached" data. It is giving me a correct screenshot, but if I take another screenshot - still the same screenshot is taken as last time. If while being in-game I minimize the application (full-screen mode) and then get back to the game, the new screenshot taken will have up to date screenshot, but then again, the next screenshot would be exactly the same.

I don't know if it is "by design" or is it "some sort of bug" Nevertheless my question is: Can I force somehow this "reloading" without having to programmatically call some kind of "alt+tab" and then focusing on the application once again?

In this topic: How to take screenshots of a game with OpenGL

@Andon M. Coleman wrote:

Are you on Windows? In fullscreen mode starting with Windows Vista, there is trouble with anything that tries to capture the front-buffer (including the built-in Alt + PrintScreen). The easiest solution is to change your buffer swap behavior to Copy Swap (PFD_SWAP_COPY, slower but guaranteed to work). Often if you Alt+TAB out and back in after making the fullscreen mode switch that will fix it too; though I have never been able to explain that ;) If you did not write the game in the question, then the second solution may be your only choice if you want to use that code.

This is exactly the problem I am facing. As he wrote: "Alt+Tab" is fixing the problem (although he did not know whether it is a feature or a bug) He proposed to change the buffer swap behavior to Copy Swap(PFD_SWAP_COPY) Any tips on how to change my code with that will also be most welcome (I can try this one) But if I understood correctly, this approach is the viable solution only if you can change this in the game (and this is not my case)

Here is my working code (which in topics about such scenarios was claiming that in this approach the screenshot is BLACK. But it is working for me)

private const int SW_RESTORE = 9;
public void TakeScreenShot()
{
    var guid = Guid.NewGuid();
    string procName = "hl";
    Process proc;

    try
    {
        proc = Process.GetProcessesByName(procName)[0];
    }
    catch (IndexOutOfRangeException e)
    {
        return;
    }


    // Focus on the application
    SetForegroundWindow(proc.MainWindowHandle);
    ShowWindow(proc.MainWindowHandle, SW_RESTORE);

    Thread.Sleep(1000);

    Rect rect = new Rect();
    IntPtr error = GetWindowRect(proc.MainWindowHandle, ref rect);

    while (error == (IntPtr)0)
    {
        error = GetWindowRect(proc.MainWindowHandle, ref rect);
    }

    int width = rect.right - rect.left;
    int height = rect.bottom - rect.top;

    using (Bitmap printscreen = new Bitmap(width, height, PixelFormat.Format32bppArgb))
    {
        using (var graphics = Graphics.FromImage(printscreen))
        {
            graphics.CopyFromScreen(rect.left,
                                               rect.top,
                                               0,
                                               0,
                                               new Size(width, height),
                                               CopyPixelOperation.SourceCopy);
            printscreen.Save($@"{Path.GetTempPath()}\{guid.ToString()}.jpg", ImageFormat.Jpeg);
        }
    }
}

I want this application to work on Windows7, Windows8, Windows 10. The best would be to cover full screen and windowed mode (but fullscreen is probably more important)

Any advice how to proceed (or why I am getting the "cached" data) would be nice :)

Of course if someone will say (with full authority), that what i want to achieve is impossible with CopyFromScreen (and there is no hack to fix that, apart from minimizing and maximazing the screen) i will consider option with injecting the code. But normally i would want to stay away from this one, as this could be treated as cheat and can lead to VAC ban.

====== UPDATE ======

You can try reproduce the process of taking screenshot by downloading the game (is small one, 260 MB): https://cssetti.pl/Api/GameDownload.php?GameDownloadId=v43

Then you can copy-paste my code to Linqpad (or any other editor) and run the code. The application after launching will launch the HL process which is then use to try to grab the screenshot.

====== UPDATE 2 ======

In windows mode everything works correctly (the printscreens are ok)

Piotr
  • 1,155
  • 12
  • 29
  • What is antyss? Also, off topic: why do you want to do this? It looks like the user needs to install this application in order to detect cheat programs he/she might be using...? – bolov Oct 21 '19 at 15:38
  • Antyss is some library (cheat), which is being attached/injected to the game and it discovers all calls to in-game screenshot. While it discovers such call, it disables all cheats (the most popular one is something called wallhack - you see your opponents through walls) As I wrote, I want to do this, because I want to create antycheat (some part of code, which will discover cheats) And yes, you are right. The user which want to use my game server (or at least some part of the suspicious ones) is obliged to install my application (which we are right now debating how to write:) ) – Piotr Oct 21 '19 at 15:43
  • One more disclaimer about antyss.The game itself has its own plugin system (called AMXX) using this system (written in c++ kinda language called PAWN) there has been plugins created, which are responsible for triggering screenshots on player side by calling high level access to the game function called "screenshot" and after that player is banned from the server. The only way to be unbanned is to provide on the forum proof of playing without cheats (those screenshot taken somewhere on player disk) Of course without antyss all of them would be with transparent walls (if the player is cheating) – Piotr Oct 21 '19 at 15:49
  • I've added update to the question. One can download the game and try to run my code in Linqpad or similar to try to capture the screenshot – Piotr Oct 21 '19 at 16:22
  • My humble opinion is that is an uphill battle you can never win. The user's system is the user's system. You have 0 control over it. . – bolov Oct 21 '19 at 17:25
  • And even if you somehow manage to take control over it you would need to keep fighting with cheats. I guarantee that whatever anticheat method you find, if the service you provide is popular they will find a way to subvert it and quicker then you can say "What happened?" – bolov Oct 21 '19 at 17:25
  • The program I did describe will be used only for my forum and will not be used wider. That is it's protection;) overall you are right. There was a time when there was a global application (exactly the same I want to create) it was called "Sxe injected" and it was shutdown because it was popular and hackers did decompile it and create a workaround. This is not the case with my application – Piotr Oct 21 '19 at 17:29
  • I wish you the best of luck! – bolov Oct 21 '19 at 17:33
  • take a look at [Getting screenshot of a child window running OpenGL in it (Windows)](https://stackoverflow.com/a/18107834/2521214) and [How can I access a graphics card's output directly?](https://stackoverflow.com/a/38549548/2521214) – Spektre Oct 23 '19 at 12:47
  • @Spektre First URL did not even have an answer marked as resolved. The second one is not in C#, not in bitblt and is not using copyfromscreen. Not to mention the resolution in the second part is good if you CONTROL the source code of the application (which I don't) So you've totally missed – Piotr Oct 23 '19 at 19:24
  • @Piotr you misunderstood you do not need to own the app ... you just need to obtain the handle. Your problems are most likely related to use of `copyfromscreen` itself. The way I am using have no problem of taking video feed from 3th party aps even GL/DX overlays ... PS all animated GIFs in mine answers where captured like this from different app ... language does not matter what matters is the winapi code .... – Spektre Oct 23 '19 at 20:36
  • Yes, but still no c# example :( – Piotr Oct 23 '19 at 21:24
  • @Piotr winapi code should be the same in C# ... – Spektre Oct 24 '19 at 07:42
  • The difference between "should" and "is" is a difference between the solution and the speculation:) – Piotr Oct 24 '19 at 11:22
  • What happens if you run it in windowed mode and not fullscreen? – user9385381 Oct 26 '19 at 19:17
  • In windows mode everything works correctly (the printscreens are ok) – Piotr Oct 26 '19 at 21:37

0 Answers0