Advertisement
Zodihax

ZodJect

Nov 2nd, 2013
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.77 KB | None | 0 0
  1. // Launches the game with a .dll injected, and minimizes the game with a set hotkey
  2.  
  3. #include <windows.h>
  4. #include <tlhelp32.h>
  5. #include <shlwapi.h>
  6. #include <conio.h>
  7. #include <stdio.h>
  8. #include "detours.h"
  9. #include "ini.h"
  10.  
  11.  
  12. #define WIN32_LEAN_AND_MEAN
  13.  
  14.  
  15. #include <shellapi.h>
  16. #include <string>
  17. #define HOTKEY_ID 40022
  18. #define SHELL_ICON_ID 101
  19. #define SHELL_CALLBACK WM_USER+14
  20.  
  21. #include "resource.h"
  22. //#include "main.h"
  23.  
  24. using namespace std;
  25.  
  26. LRESULT CALLBACK winProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
  27. HMENU hmenu;
  28. string check = "Enemy Territory";
  29.  
  30. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
  31. {
  32.     HWND hwnd;
  33.     WNDCLASSEX wc;
  34.  
  35.     wc.cbSize = sizeof(WNDCLASSEX);
  36.     wc.cbClsExtra = 0;
  37.     wc.cbWndExtra = 0;
  38.     wc.hbrBackground = (HBRUSH)WHITE_BRUSH+1;
  39.     wc.hCursor = NULL;
  40.     wc.hIcon = NULL;
  41.     wc.hIconSm = NULL;
  42.     wc.hInstance = hInst;
  43.     wc.lpfnWndProc = winProc;
  44.     wc.lpszClassName = "zodiac";
  45.     wc.style = CS_DBLCLKS;
  46.     wc.lpszMenuName = NULL;
  47.  
  48.     if (!RegisterClassEx(&wc)) { return -1; }
  49.  
  50.     hwnd = CreateWindow("zodiac", "zodiac", NULL, 0, 0, 50, 50, NULL, NULL, hInst, NULL);
  51.  
  52.     if (!hwnd)
  53.     {
  54.         MessageBox(0, "try again", NULL, NULL);
  55.         return -1;
  56.     }
  57.  
  58.     //register hot key
  59.     if (!RegisterHotKey(NULL, HOTKEY_ID, MOD_ALT, 'Z'))
  60.     {
  61.         MessageBox(0, "try again", NULL, NULL);
  62.         return -1;
  63.     }
  64.  
  65. //  ShowWindow(hwnd, SW_SHOW);
  66.  
  67.     //create tray icon
  68.     NOTIFYICONDATA nid;
  69.     ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
  70.  
  71.     nid.cbSize = sizeof(NOTIFYICONDATA);
  72.     nid.hWnd = hwnd;
  73.     nid.uID = SHELL_ICON_ID;
  74.     nid.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
  75.     nid.uCallbackMessage = SHELL_CALLBACK;
  76.     nid.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1));
  77.     strcpy_s(nid.szTip, "Zodiac Minimizer");
  78.        
  79.     Shell_NotifyIcon(NIM_ADD, &nid);
  80.  
  81.     //get menu
  82.     hmenu = GetSubMenu(LoadMenu(hInst, MAKEINTRESOURCE(IDR_MENU1)), 0);
  83.  
  84.  
  85.         //message loop
  86.     MSG msg;
  87.     while (GetMessage(&msg, NULL, NULL, NULL) != 0)
  88.     {
  89.         if (msg.message == WM_HOTKEY)
  90.             msg.hwnd = hwnd;
  91.  
  92.         TranslateMessage(&msg);
  93.         DispatchMessage(&msg);
  94.     }
  95.  
  96.     //cleanup
  97.     Shell_NotifyIcon(NIM_DELETE, &nid);
  98.  
  99.     UnregisterHotKey(NULL, HOTKEY_ID);
  100.  
  101.     return 0;
  102. }
  103.  
  104. void tryMin()
  105. {
  106.     string::size_type f = 0;
  107.     string::size_type r = 0;
  108.     string curWin;
  109.     HWND hwet;
  110.  
  111.     while (f != string::npos)
  112.     {
  113.         r = check.find('\t', r+1);
  114.         if (r == string::npos)
  115.         {
  116.             curWin = check.substr(f);
  117.             f = r;
  118.         }
  119.         else
  120.         {
  121.             curWin = check.substr(f,r);
  122.             f=r+1;
  123.         }
  124.  
  125.        
  126.         hwet = FindWindow(curWin.c_str(), NULL);
  127.        
  128.         if (hwet)
  129.         {
  130.             WINDOWPLACEMENT wp;
  131.             GetWindowPlacement(hwet, &wp);
  132.             if (wp.showCmd == SW_SHOWMINIMIZED) {
  133.                 ShowWindow(hwet, SW_RESTORE);              
  134.                 HWND hWnd = FindWindowExA(FindWindow(0, "ET Console"), NULL, "Edit", 0);
  135.                 SendMessage(hWnd, WM_SETTEXT, 0, (LPARAM) "vid_restart");
  136.                 SendMessage(hWnd, WM_CHAR, 13, 0);
  137.             } else {
  138.                 ShowWindow(hwet, SW_MINIMIZE);
  139.                 ChangeDisplaySettings(NULL,0);
  140.             }
  141.         }
  142.     }
  143.  
  144. }
  145.  
  146. LRESULT CALLBACK winProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
  147. {
  148.    
  149.     switch(msg)
  150.     {
  151.     case WM_CREATE:
  152.         // ..
  153.         break;
  154.  
  155.     case WM_HOTKEY:
  156.         if (wp == HOTKEY_ID)
  157.             tryMin();
  158.         break;
  159.  
  160.     case SHELL_CALLBACK:
  161.         switch(lp)
  162.         {
  163.         case WM_RBUTTONDOWN:
  164.             {
  165.                 if (hmenu != 0)
  166.                 {
  167.                     SetForegroundWindow(hwnd);
  168.                     POINT p;
  169.                     GetCursorPos(&p);
  170.                     TrackPopupMenu(hmenu, 0, p.x, p.y, 0, hwnd, 0);
  171.                     PostMessage(hwnd, WM_NULL, 0,0);
  172.                 }
  173.             }
  174.             break;
  175.         case WM_LBUTTONDBLCLK:
  176.             tryMin();
  177.             break;
  178.         }
  179.         return TRUE;
  180.         break;
  181.     case WM_COMMAND:
  182.         switch(LOWORD(wp))
  183.         {
  184.             case ID_YOLO_EXIT:
  185.                 PostQuitMessage(0);
  186.                 break;
  187.             case ID_YOLO_PLAY:
  188.                 char buffer[MAX_PATH];
  189.                 GetModuleFileName( NULL, buffer, MAX_PATH );
  190.                 string::size_type pos = string( buffer ).find_last_of( "\\/" );
  191.                
  192.                 char path[MAX_PATH];
  193.                 char path2[MAX_PATH];
  194.                 GetPrivateProfileStringA("settings", "path", "C:\\Program Files (x86)\\Wolfenstein - Enemy Territory\\ET.exe", path, MAX_PATH, string( buffer ).substr( 0, pos).append("\\file.ini").c_str());
  195.                 GetPrivateProfileStringA("settings", "path2", "C:\\Program Files (x86)\\Wolfenstein - Enemy Territory", path2, MAX_PATH, string( buffer ).substr( 0, pos).append("\\file.ini").c_str());
  196.  
  197.                 STARTUPINFOA _StartupInfo;
  198.                 PROCESS_INFORMATION _Information;              
  199.                 ZeroMemory( &_StartupInfo, sizeof( STARTUPINFOA ) );
  200.                 _StartupInfo.cb = sizeof( STARTUPINFOA );              
  201.                 ZeroMemory( &_Information, sizeof( PROCESS_INFORMATION ) );
  202.                 DetourCreateProcessWithDllA( path, NULL, NULL, NULL, TRUE, CREATE_DEFAULT_ERROR_MODE, NULL, path2, &_StartupInfo, &_Information, string( buffer ).substr( 0, pos).append("\\RInput.dll").c_str(), NULL );
  203.                 break;     
  204.         }
  205.  
  206.  
  207.     default:
  208.         return DefWindowProc(hwnd, msg, wp, lp);
  209.     }
  210.  
  211.     return TRUE;
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement