autotp.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. #include "AutoTP.h"
  2. namespace cheat {
  3. std::vector<AutoTP::TP> AutoTP::parseds;
  4. std::atomic<bool> stopThread(false);
  5. static void TeleportToCurrentPoint(int point);
  6. static void AutoTpThread();
  7. AutoTP::AutoTP() {
  8. f_Enabled = config::getValue("functions:AutoTP", "enabled", false);
  9. f_TeleportBackHotkey = Hotkey("functions:AutoTP", "teleportBackHotkey");
  10. f_TeleportForwardHotkey = Hotkey("functions:AutoTP", "teleportForwardHotkey");
  11. f_TeleportAutoHotkey = Hotkey("functions:AutoTP", "teleportAutoHotkey");
  12. std::thread thread(AutoTpThread);
  13. thread.detach();
  14. }
  15. AutoTP& AutoTP::getInstance() {
  16. static AutoTP instance;
  17. return instance;
  18. }
  19. void AutoTP::GUI() {
  20. ConfigCheckbox(_("Auto TP"), f_Enabled);
  21. if (f_Enabled.getValue()) {
  22. ImGui::Indent();
  23. ImGui::InputText("Json folder", folderPathBuffer, sizeof(folderPathBuffer));
  24. if (ImGui::Button("Read jsons")) {
  25. parseds.clear();
  26. std::string folderPath = folderPathBuffer;
  27. if (!std::filesystem::exists(folderPath)) {
  28. std::filesystem::path path = std::filesystem::current_path() / folderPath;
  29. folderPath = path.string();
  30. if (!std::filesystem::exists(path)) {
  31. LOG_ERROR("Folder not found: %s", folderPath); // Use %s for string format
  32. return;
  33. }
  34. }
  35. for (const auto& entry : std::filesystem::directory_iterator(folderPath)) {
  36. if (entry.is_regular_file() && entry.path().extension() == ".json") {
  37. std::ifstream stream(entry.path());
  38. if (stream.good()) {
  39. nlohmann::json parsed;
  40. try {
  41. stream >> parsed;
  42. TP tp;
  43. tp.name = parsed["name"];
  44. tp.description = parsed["description"];
  45. tp.position = { parsed["position"][0], parsed["position"][1], parsed["position"][2] };
  46. parseds.push_back(tp);
  47. }
  48. catch (const nlohmann::json::exception& e) {
  49. std::cout << e.what() << std::endl;
  50. }
  51. }
  52. else {
  53. std::cout << "Failed to open file: " << entry.path() << std::endl;
  54. }
  55. }
  56. }
  57. }
  58. if (!parseds.empty()) {
  59. ImGui::Text("Amount of loaded points: %zu", parseds.size());
  60. ImGui::Separator();
  61. ImGui::Text("Current point name: %s", currentPoint.name.c_str());
  62. ImGui::Text("Current point description: %s", currentPoint.description.c_str());
  63. ImGui::Text("Current point pos: %f, %f, %f", currentPoint.position.x, currentPoint.position.y, currentPoint.position.z);
  64. ImGui::Separator();
  65. ImGui::Checkbox("TP automatically through all points", &ifAutomatic);
  66. if (ifAutomatic) {
  67. if (!b_startTeleporting) {
  68. if (ImGui::Button("Start teleporting")) {
  69. b_startTeleporting = true;
  70. LOG_DEBUG("Start teleporting pressed");
  71. }
  72. }
  73. if (b_startTeleporting) {
  74. if (ImGui::Button("Stop teleporting")) {
  75. b_startTeleporting = false;
  76. LOG_DEBUG("Stop teleporting pressed");
  77. }
  78. }
  79. ImGui::SliderFloat("Time to wait", &timerWait, 0.f, 100.0f);
  80. f_TeleportAutoHotkey.Draw();
  81. }
  82. ImGui::Checkbox("TP manually", &ifManual);
  83. if (ifManual) {
  84. ImGui::Text("Manual TP Controls:");
  85. ImGui::SameLine();
  86. if (ImGui::Button("<")) {
  87. if (currentPointIndex > 0) {
  88. currentPointIndex--;
  89. TeleportToCurrentPoint(currentPointIndex);
  90. }
  91. }
  92. ImGui::SameLine();
  93. if (ImGui::Button(">")) {
  94. if (currentPointIndex < parseds.size() - 1) {
  95. currentPointIndex++;
  96. TeleportToCurrentPoint(currentPointIndex);
  97. }
  98. }
  99. f_TeleportBackHotkey.Draw();
  100. ImGui::SameLine();
  101. f_TeleportBackHotkey.Draw();
  102. }
  103. ImGui::Separator();
  104. }
  105. ImGui::Unindent();
  106. }
  107. }
  108. void AutoTP::Outer() {
  109. if (f_TeleportBackHotkey.IsPressed()) {
  110. if (currentPointIndex > 0) {
  111. currentPointIndex--;
  112. TeleportToCurrentPoint(currentPointIndex);
  113. }
  114. }
  115. if (f_TeleportForwardHotkey.IsPressed()) {
  116. if (currentPointIndex < parseds.size() - 1) {
  117. currentPointIndex++;
  118. TeleportToCurrentPoint(currentPointIndex);
  119. }
  120. }
  121. if (f_TeleportAutoHotkey.IsPressed())
  122. b_startTeleporting = !b_startTeleporting;
  123. }
  124. void AutoTP::Status() {
  125. if (f_Enabled.getValue())
  126. ImGui::Text("AutoTP");
  127. }
  128. std::string AutoTP::getModule() {
  129. return _("World");
  130. }
  131. void TeleportToCurrentPoint(int point) {
  132. if (point >= 0 && point < AutoTP::parseds.size()) {
  133. AutoTP::currentPoint = AutoTP::parseds[point];
  134. LOG_INFO("Teleporting to point: %s", AutoTP::parseds[point].name.c_str());
  135. auto avatarPos = app::ActorUtils_GetAvatarPos();
  136. auto endPos = AutoTP::parseds[point].position;
  137. std::thread interpolate([avatarPos, endPos]() {
  138. float t = 0.0f;
  139. app::Vector3 zero = { 0,0,0 };
  140. auto newPos = zero;
  141. while (t < 1.0f) {
  142. newPos = app::Vector3_Lerp(avatarPos, endPos, t);
  143. app::ActorUtils_SetAvatarPos(newPos);
  144. t += 5 / 100.0f;
  145. LOG_INFO("time; %f", t);
  146. Sleep(10);
  147. } });
  148. interpolate.detach();
  149. LOG_INFO("Teleported to pos: %f, %f, %f", AutoTP::currentPoint.position.x, AutoTP::currentPoint.position.y, AutoTP::currentPoint.position.z);
  150. }
  151. }
  152. void AutoTpThread() {
  153. auto& autoTP = AutoTP::getInstance();
  154. while (!stopThread.load()) {
  155. if (!autoTP.f_Enabled.getValue() || !AutoTP::b_startTeleporting)
  156. return;
  157. for (int i = 0; i < AutoTP::parseds.size(); i++) {
  158. if (!AutoTP::b_startTeleporting)
  159. break;
  160. TeleportToCurrentPoint(i);
  161. if (AutoTP::parseds.size() - i != 1) {
  162. Sleep(static_cast<DWORD>(AutoTP::timerWait * 1000));
  163. }
  164. }
  165. AutoTP::b_startTeleporting = false;
  166. }
  167. }
  168. }