/ src / main.cpp
main.cpp
  1  // 作者: feng_xingzhe_cn_.86
  2  
  3  #include <iostream>
  4  #include <thread>
  5  #include <chrono>
  6  #include <string>
  7  #include <atomic>
  8  #include <exception>
  9  
 10  #include "AImGui.h"
 11  #include "KittyMemoryMgr.hpp"
 12  #include <onyx/utils/Memory.hpp>
 13  #include <onyx/core/esp_manager.hpp>
 14  #include <onyx/sdk/game/CameraSystem.hpp>
 15  #include <onyx/render/renderer.hpp>
 16  
 17  namespace {
 18  
 19      onyx::core::EspManager            g_esp_manager;
 20      onyx::sdk::game::CameraSystem     g_camera;
 21      onyx::render::Renderer            g_renderer;
 22  
 23      KittyMemoryMgr g_ktmgr;
 24  
 25      std::atomic<uintptr_t> s_il2cpp_base{0};
 26      std::atomic<bool>      s_is_ready{false};
 27      std::atomic<bool>      s_show_menu{true};
 28      std::atomic<bool>      s_running{true};
 29  
 30      const std::string k_package_name = "com.criticalforceentertainment.criticalops";
 31  
 32      void gui_loop() {
 33  
 34          try {
 35  
 36              android::AImGui imgui;
 37  
 38              if (!imgui) {
 39  
 40                  std::cerr << "[-] AImGui initialization failed (Unknown error)" << std::endl;
 41  
 42                  return;
 43  
 44              }
 45  
 46              g_renderer.initialize();
 47  
 48              std::cout << "[+] Rendering and Input loops starting on main thread." << std::endl;
 49  
 50              while (s_running) {
 51  
 52                  imgui.ProcessInputEvent();
 53  
 54                  imgui.BeginFrame();
 55  
 56                  if (s_is_ready) {
 57  
 58                      g_renderer.render_frame(g_esp_manager, g_camera, s_il2cpp_base.load());
 59  
 60                  } else {
 61  
 62                      ImGui::SetNextWindowPos({20, 20}, ImGuiCond_FirstUseEver);
 63                      ImGui::SetNextWindowBgAlpha(0.0f); // Make it almost transparent for a cleaner look if desired
 64  
 65                      if (ImGui::Begin("##SearchStatus", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings)) {
 66  
 67                          ImGui::TextColored({1.0f, 1.0f, 1.0f, 0.6f}, "Searching for game process...");
 68  
 69                      }
 70  
 71                      ImGui::End();
 72  
 73                  }
 74  
 75                  imgui.EndFrame();
 76  
 77                  std::this_thread::sleep_for(std::chrono::milliseconds(1));
 78  
 79              }
 80  
 81          } catch (const std::exception& e) {
 82  
 83              std::cerr << "[-] AImGui Critical Error: " << e.what() << std::endl;
 84  
 85          }
 86  
 87      }
 88  
 89      void logic_worker() {
 90  
 91          while (s_running) {
 92  
 93              if (s_is_ready) {
 94  
 95                  g_esp_manager.update_loop(s_il2cpp_base.load(), g_camera);
 96  
 97              }
 98  
 99              std::this_thread::sleep_for(std::chrono::milliseconds(500));
100  
101          }
102  
103      }
104  
105      void discovery_worker() {
106  
107          while (s_running) {
108  
109              if (!s_is_ready) {
110  
111                  pid_t pid = KittyMemoryEx::getProcessID(k_package_name);
112  
113                  if (pid > 0) {
114  
115                      std::cout << "[+] Found process " << k_package_name << " with PID: " << pid << std::endl;
116  
117                      if (g_ktmgr.initialize(pid, EK_MEM_OP_SYSCALL, true)) {
118  
119                          onyx::utils::Memory::s_mgr = &g_ktmgr;
120  
121                          auto il2cpp_elf = g_ktmgr.elfScanner.findElf("libil2cpp.so");
122  
123                          if (il2cpp_elf.isValid()) {
124  
125                              onyx::utils::Memory::s_base_address = il2cpp_elf.base();
126  
127                              s_il2cpp_base.store(il2cpp_elf.base());
128                              s_is_ready = true;
129  
130                          }
131  
132                      }
133  
134                  }
135  
136              } else {
137  
138                  if (KittyMemoryEx::getProcessID(k_package_name) == 0) {
139  
140                      std::cout << "[-] Game process terminated. Returning to search mode." << std::endl;
141  
142                      s_is_ready = false;
143                      s_il2cpp_base.store(0);
144  
145                  }
146  
147              }
148  
149              std::this_thread::sleep_for(std::chrono::seconds(2));
150  
151          }
152  
153      }
154  
155  }
156  
157  int main() {
158  
159      std::cout << "[+] Onyx External starting..." << std::endl;
160  
161      std::thread discovery_thread(discovery_worker);
162      std::thread logic_thread(logic_worker);
163  
164      gui_loop();
165  
166      discovery_thread.join();
167      logic_thread.join();
168  
169      return 0;
170  }