Skip to main content

TopMost Protection

TopMost protection is a critical defense mechanism that prevents players from opening external cheating tools, particularly injectors, during gameplay. By maintaining a fullscreen window that stays on top of all other applications, ACHCE Client creates a barrier that makes it significantly more difficult to launch unauthorized software.
TopMost is a Windows Forms property that forces a window to remain visible above all other windows, even when it loses focus.

What is TopMost?

In Windows programming, the TopMost property is a boolean flag that, when set to true, ensures a window remains on top of all other windows in the z-order. This is commonly used for:
  • Critical system notifications
  • Always-visible toolbars
  • Security overlays
  • Splash screens and loading windows
In ACHCE Client, TopMost serves as a protective shield that covers the entire screen, preventing users from accessing external applications that could inject malicious code into the game process.

Why TopMost Matters for Anti-Cheat

The Injector Problem

Injectors are tools that insert unauthorized code into a running game process. They typically:
  • Modify game memory to enable cheats
  • Hook game functions to alter behavior
  • Inject DLLs that provide unfair advantages
  • Enable wallhacks, aimbots, and other exploits

How TopMost Prevents Injection

By maintaining a fullscreen overlay, ACHCE Client:
  1. Blocks Visual Access: Users cannot see or interact with injector windows
  2. Prevents Focus Changes: External tools cannot steal focus from the protected window
  3. Creates User Friction: Makes the injection process significantly more complex
  4. Deters Casual Cheaters: Most users will not attempt advanced bypass techniques
While TopMost is a strong deterrent, it should not be the only protection layer. ACHCE Client combines it with temporary folders and hardware identification for comprehensive security.

Implementation Details

Form2: The TopMost Window

The TopMost protection is implemented in Form2.cs, which displays a fullscreen overlay window:
public partial class Form2 : Form
{
    public Form2()
    {
        InitializeComponent();
    }

    private void Form2_Load(object sender, EventArgs e)
    {
        // Get the primary monitor's resolution
        Rectangle resolution = Screen.PrimaryScreen.Bounds;

        // Set window size to match screen resolution
        this.Size = new Size(resolution.Width, resolution.Height);

        // Position window to cover entire screen
        this.Location = new Point(
            (resolution.Width - this.Width), 
            (resolution.Height - this.Height)
        );
    }

    private void pictureBox2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }
}

Window Activation Flow

The transition from the initial form to the TopMost window is handled by a timer in Form1.cs:
private void timer1_Tick(object sender, EventArgs e)
{
    if (IpPlayer != null)
    {
        // Create and display TopMost protection window
        Form2 form2 = new Form2();
        this.Hide();        // Hide initial loading form
        timer2.Stop();      // Stop loading animation
        form2.Show();       // Show fullscreen protection
    }
}
The TopMost window is only displayed after the player’s IP address has been successfully retrieved and registered in the database, ensuring the protection is active before game access.

Technical Breakdown

Screen Resolution Detection

ACHCE Client dynamically adapts to the player’s monitor configuration:
// Get primary screen dimensions
Rectangle resolution = Screen.PrimaryScreen.Bounds;

// Properties available:
// - resolution.Width: Screen width in pixels
// - resolution.Height: Screen height in pixels
// - resolution.X: Screen origin X coordinate
// - resolution.Y: Screen origin Y coordinate
This ensures the TopMost window covers the entire screen regardless of resolution (1080p, 1440p, 4K, etc.).

Window Sizing and Positioning

// Match window size to screen size
this.Size = new Size(resolution.Width, resolution.Height);

// Position at top-left corner (0, 0)
this.Location = new Point(
    (resolution.Width - this.Width),   // X: 0
    (resolution.Height - this.Height)  // Y: 0
);
The calculation (resolution.Width - this.Width) evaluates to 0 when the window width matches the screen width, effectively positioning the window at the screen origin.

Multi-Monitor Considerations

The current implementation uses Screen.PrimaryScreen.Bounds, which covers only the primary monitor. For multi-monitor setups:
// To cover all monitors (enhancement):
Rectangle allScreens = SystemInformation.VirtualScreen;
this.Size = new Size(allScreens.Width, allScreens.Height);
this.Location = new Point(allScreens.X, allScreens.Y);

Form Designer Configuration

While not shown in the code excerpts, the Form2 window must have its TopMost property set in the designer or programmatically:
// In Form2 constructor or designer:
this.TopMost = true;  // Ensures window stays on top
this.FormBorderStyle = FormBorderStyle.None;  // Removes borders
this.WindowState = FormWindowState.Maximized;  // Fullscreen mode

User Interface Elements

Exit Control

The TopMost window includes a clickable exit control (pictureBox2):
private void pictureBox2_Click(object sender, EventArgs e)
{
    Application.Exit();  // Terminate entire application
}
This exit button allows users to close ACHCE Client when they want to stop playing. Its placement and design should make it visible but not accidentally clickable.

Security Analysis

Strengths

  1. Simple to Implement: Uses native Windows Forms functionality
  2. Low Performance Impact: No background scanning or memory monitoring required
  3. Immediate Effect: Active as soon as the form is displayed
  4. Platform Native: Leverages OS-level window management

Limitations

  1. Visual Only: Does not prevent background processes or command-line injectors
  2. Bypassable: Advanced users can disable TopMost via external tools
  3. Single Monitor: Current implementation only covers primary screen
  4. UI Dependent: Can be circumvented if form loses TopMost flag

Why It Still Works

Despite these limitations, TopMost protection is effective because:
  • Target Audience: Most cheaters use GUI-based tools that require visual interaction
  • Layered Defense: Combined with other protections (temporary folders, hardware ID)
  • Deterrent Effect: Raises the technical barrier for cheating attempts
  • Ease of Detection: Attempts to bypass TopMost can be monitored

Best Practices

1

Set TopMost Early

Enable the TopMost flag as soon as Form2 is created, before showing the window
2

Monitor Window State

Periodically verify that TopMost remains true using a timer
3

Handle Focus Loss

Implement event handlers to detect and respond to focus changes
4

Log Bypass Attempts

Track when TopMost is disabled or window is minimized unexpectedly

Enhancement Opportunities

Persistent TopMost Verification

Add a timer to continuously verify the TopMost state:
private Timer topMostVerifier;

public Form2()
{
    InitializeComponent();
    
    // Create verification timer
    topMostVerifier = new Timer();
    topMostVerifier.Interval = 1000;  // Check every second
    topMostVerifier.Tick += VerifyTopMost;
    topMostVerifier.Start();
}

private void VerifyTopMost(object sender, EventArgs e)
{
    if (!this.TopMost)
    {
        // TopMost was disabled - restore and log
        this.TopMost = true;
        LogSecurityEvent("TopMost protection was bypassed");
    }
}

Window State Monitoring

Detect attempts to minimize or hide the window:
protected override void OnResize(EventArgs e)
{
    base.OnResize(e);
    
    // Prevent minimization
    if (this.WindowState == FormWindowState.Minimized)
    {
        this.WindowState = FormWindowState.Maximized;
        LogSecurityEvent("Window minimization attempt blocked");
    }
}

Focus Protection

Prevent other applications from stealing focus:
protected override void OnDeactivate(EventArgs e)
{
    base.OnDeactivate(e);
    
    // Immediately reclaim focus
    this.Activate();
    this.Focus();
}

Multi-Monitor Support

To protect multi-monitor setups:
private void Form2_Load(object sender, EventArgs e)
{
    // Get virtual screen dimensions (all monitors)
    int totalWidth = SystemInformation.VirtualScreen.Width;
    int totalHeight = SystemInformation.VirtualScreen.Height;
    int leftMost = SystemInformation.VirtualScreen.Left;
    int topMost = SystemInformation.VirtualScreen.Top;
    
    // Cover entire desktop space
    this.Size = new Size(totalWidth, totalHeight);
    this.Location = new Point(leftMost, topMost);
}

Performance Considerations

TopMost protection has minimal performance impact:
  • Memory: Single Form instance (~few KB)
  • CPU: No continuous processing required
  • GPU: Standard window rendering only
The main performance consideration is the window’s content. Keep the UI lightweight with optimized images and minimal animations to avoid impacting game performance.

Testing TopMost Protection

Manual Testing

  1. Launch ACHCE Client
  2. Verify fullscreen coverage appears
  3. Attempt to open Task Manager (Ctrl+Shift+Esc)
  4. Try Alt+Tab to switch applications
  5. Attempt to open injector tools

Automated Testing

[TestMethod]
public void TestTopMostIsEnabled()
{
    Form2 protectionWindow = new Form2();
    protectionWindow.Show();
    
    Assert.IsTrue(protectionWindow.TopMost, 
        "TopMost protection should be enabled");
    
    protectionWindow.Close();
}

Common Issues

Set FormBorderStyle to None and WindowState to Maximized in addition to sizing manually.
Verify that TopMost is set to true in both the designer and code. Some applications (like Task Manager) can override TopMost.
Optimize the form’s content. Use compressed images, disable unnecessary animations, and avoid complex UI elements that require continuous repainting.
Alt+Tab operates at the OS level and cannot be completely blocked. However, returning to the game will show the TopMost window again. Consider using keyboard hooks to intercept Alt+Tab (requires careful implementation to avoid system instability).

Relationship to Other Protection Layers

TopMost protection works in concert with other ACHCE Client features:
  • Temporary Folders: While TopMost prevents injector UI access, temporary folders prevent modified game files
  • Hardware ID: If TopMost is bypassed and cheating occurs, hardware ID ensures bans persist
  • Database Tracking: Active sessions are monitored regardless of TopMost bypass attempts

Summary

TopMost protection is a foundational security layer that:
  • Creates a visual and interactive barrier against injector tools
  • Operates with minimal performance overhead
  • Provides immediate protection upon activation
  • Works best when combined with other anti-cheat mechanisms
The implementation in Form2.cs demonstrates a straightforward approach to fullscreen window protection, with opportunities for enhancement through continuous monitoring and multi-monitor support.
For maximum effectiveness, combine TopMost protection with kernel-level drivers, memory integrity checks, and behavioral analysis in future versions.

Build docs developers (and LLMs) love