Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  d
Language: C/C++
Code:
#include <Windows.h>
#include <iostream>
#include <thread>
#include <string_view>
#include <string>
 
auto button_handle = (HWND)nullptr;
auto stop = false;
 
namespace sim
{
     void press_enter()
     {
          auto input = INPUT();
          RtlZeroMemory(&input, sizeof(input));
 
          char buffer[120] = { 0 };
 
          GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ILANGUAGE, buffer, sizeof(buffer));
          const auto keyboard_layout = LoadKeyboardLayoutA(buffer, KLF_ACTIVATE);
 
          const auto EnterVk = VkKeyScanExA('\n', keyboard_layout);
          const auto EnterVKey = MapVirtualKeyA(LOBYTE(EnterVk), 0);
 
          input.type = INPUT_KEYBOARD;
          input.ki.dwFlags = KEYEVENTF_SCANCODE;
          input.ki.wScan = EnterVKey;
 
          SendInput(1, &input, sizeof(input));
          RtlZeroMemory(&input, sizeof(input));
 
          std::this_thread::sleep_for(std::chrono::milliseconds(50));
 
          input.type = INPUT_KEYBOARD;
          input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
          input.ki.wScan = EnterVKey;
 
          SendInput(1, &input, sizeof(input));
          RtlZeroMemory(&input, sizeof(input));
     }
 
     void press_gtahax_button()
     {
          SendMessageA(button_handle, BM_CLICK, 0, 0);
     }
}
 
namespace misc
{
     void error(std::string_view message)
     {
          const auto console = GetStdHandle(STD_OUTPUT_HANDLE);
          SetConsoleTextAttribute(console, 12);
 
          std::cout << message << std::endl;
 
          std::this_thread::sleep_for(std::chrono::seconds(3));
          TerminateProcess(GetCurrentProcess(), 0);
     }
 
     BOOL CALLBACK enum_child_controls(HWND handle, LPARAM lParam)
     {
          if (handle) {
               char _class_name[100];
               GetClassNameA(handle, _class_name, 100);
 
               const auto class_name = std::string_view(_class_name);
               const auto control_id = GetDlgCtrlID(handle);
 
               /// debug output
               //std::cout << "class_name: " << class_name << std::endl;
               //std::cout << "control_id: " << std::to_string(control_id) << std::endl;
 
               if (class_name.compare("Button") == 0 && control_id == 129) {
                    button_handle = handle;
                    //SetWindowTextA(handle, "fuck you");
               }
 
               if (class_name.compare("Edit") == 0) {
                    if (control_id == 1011) {
                         auto text = "$MPPLY_CASINO_CHIPS_WON_GD";
                         SendMessageA(handle, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text));
                    }
 
                    if (control_id == 1012) {
                         auto text = "0";
                         SendMessageA(handle, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(text));
                    }
               }
          }
 
          return TRUE;
     }
}
 
void exit_thread()
{
     while (true)
     {
          if (GetAsyncKeyState(VK_F2))
               stop = true;
 
          std::this_thread::sleep_for(std::chrono::milliseconds(10));
     }
}
 
int main()
{
     std::cout << "F1 to start" << std::endl;
     std::cout << "F2 to stop" << std::endl;
 
     while (!GetAsyncKeyState(VK_F1)) {
          std::this_thread::sleep_for(std::chrono::milliseconds(100));
     }
 
     const auto game_window = FindWindowA("grcWindow", "Grand Theft Auto V");
     if (game_window == nullptr) {
          misc::error("game window");
          return -1;
     }
 
     const auto gtahax_window = FindWindowA(nullptr, "whole lotta gang shit");
     if (gtahax_window == nullptr) {
          misc::error("menu window");
          return -1;
     }
 
     const auto thread = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)exit_thread, nullptr, 0, nullptr);
     if (thread) {
          CloseHandle(thread);
     }
 
     /// prepare gtahax for using
     EnumChildWindows(gtahax_window, misc::enum_child_controls, 0);
 
     while (!stop)
     {
          sim::press_gtahax_button();
          std::this_thread::sleep_for(std::chrono::milliseconds(100));
 
          SetForegroundWindow(game_window);
          std::this_thread::sleep_for(std::chrono::milliseconds(100));
          sim::press_enter();
 
          std::this_thread::sleep_for(std::chrono::seconds(8));
     }
     
     return 1337;
}
Comments: