Files
anit-cheat/Anit-Cheat_EXE/main.cpp
T
2026-08-24 14:47:59 +08:00

171 lines
3.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "Base.h"
#include "server_pipe.h"
#include "Gui.h"
#include "XorStr.h"
#include "resource.h"
#include "utils.h"
BOOL WINAPI CtrlHandler(DWORD type)
{
switch (type)
{
case CTRL_C_EVENT:
case CTRL_BREAK_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
RequestShutdown(XorStr("console ctrl"));
return TRUE;
default:
return FALSE;
}
}
HWND g_hWnd = NULL;
HICON g_hTrayIcon = NULL;
BOOL g_bIconAdded = FALSE;
// 自定义消息,托盘通知消息
#define WM_TRAYMESSAGE (WM_USER + 1001)
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
NOTIFYICONDATA nid = { 0 };
switch (msg)
{
case WM_TRAYMESSAGE:
{
// 托盘消息
switch (LOWORD(lParam))
{
case WM_RBUTTONUP:
{
// 右键弹出菜单
POINT pt;
GetCursorPos(&pt);
HMENU hMenu = CreatePopupMenu();
AppendMenuA(hMenu, MF_STRING, 1001, "关于");
AppendMenuA(hMenu, MF_STRING, 1002, "退出程序");
// 弹出菜单
SetForegroundWindow(hWnd);
TrackPopupMenu(hMenu, TPM_BOTTOMALIGN | TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, NULL);
DestroyMenu(hMenu);
break;
}
}
break;
}
case WM_COMMAND:
{
UINT cmdId = LOWORD(wParam);
if (cmdId == 1001)
{
MessageBoxA(hWnd, "ESP反挂插件\nwww.espgom.com", "", MB_OK);
}
else if (cmdId == 1002)
{
// 退出,先移除托盘图标
nid.cbSize = sizeof(nid);
nid.hWnd = g_hWnd;
Shell_NotifyIcon(NIM_DELETE, &nid);
ExitProcess(0);
}
break;
}
case WM_DESTROY:
nid.cbSize = sizeof(nid);
nid.hWnd = g_hWnd;
Shell_NotifyIcon(NIM_DELETE, &nid);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}
BOOL CreateHiddenWindow()
{
WNDCLASSEXA wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEXA);
wc.lpfnWndProc = WndProc;
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = "TrayWndClass";
RegisterClassExA(&wc);
g_hWnd = CreateWindowExA(0, wc.lpszClassName, "Tray", 0,
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, wc.hInstance, NULL);
// 不显示窗口(隐藏)
ShowWindow(g_hWnd, SW_HIDE);
return g_hWnd != NULL;
}
BOOL AddTrayIcon()
{
NOTIFYICONDATAA nid = { 0 };
nid.cbSize = sizeof(NOTIFYICONDATAA);
nid.hWnd = g_hWnd;
nid.uID = 3276147; // 图标唯一ID
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_TRAYMESSAGE;
// 图标:可以 LoadIcon/LoadImage,也可以用自带默认图标
// ========== 加载资源图标(托盘建议16x16 ==========
g_hTrayIcon = (HICON)LoadImageA(
GetModuleHandle(NULL),
MAKEINTRESOURCEA(IDI_ICON1),
IMAGE_ICON,
64, 64, // 托盘标准尺寸 16*16
LR_DEFAULTCOLOR
);
nid.hIcon = g_hTrayIcon;
strcpy_s(nid.szTip, "Esp Tray System");
BOOL ok = Shell_NotifyIconA(NIM_ADD, &nid);
if (ok)
g_bIconAdded = TRUE;
return ok;
}
auto GuiWindowThread(LPVOID)->DWORD
{
CreateHiddenWindow();
AddTrayIcon();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
auto WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -> int
{
//AllocConsole();
//freopen("CONOUT$", "w+", stdout);
if (!utils::check_mutex())
return 0;
SetConsoleCtrlHandler(CtrlHandler, TRUE);
CreateThread(NULL, 0, GuiWindowThread, NULL, 0, NULL);
Gui::CreateGuiWindow();
StartServer();
MSG msg;
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}