From 4a49e139f7c8850329a7c6216e39754f774784c2 Mon Sep 17 00:00:00 2001 From: Nanako <00sh.chiha+github@gmail.com> Date: Thu, 4 Aug 2022 17:32:13 +0900 Subject: [PATCH] Refactor and Interpolate Hotkey --- .../user/cheat/teleport/CustomTeleports.cpp | 71 +++++++++++-------- .../src/user/cheat/teleport/CustomTeleports.h | 2 + 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index 91776a9..7444093 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -20,6 +20,7 @@ namespace cheat::feature NF(f_Enabled, "Custom Teleport", "CustomTeleports", false), NF(f_Next, "Teleport Next", "CustomTeleports", Hotkey(VK_OEM_6)), NF(f_Previous, "Teleport Previous", "CustomTeleports", Hotkey(VK_OEM_4)), + NF(f_Interpolate, "Custom Teleport", "CustomTeleports", false), NF(f_Speed, "Interpolation Speed", "CustomTeleports", 10.0f), dir(util::GetCurrentPath() / "teleports") { @@ -122,6 +123,42 @@ namespace cheat::feature return sqrt(pow(a.x - b.x, 2) + pow(a.y - b.y, 2) + pow(a.z - b.z, 2)); } + void CustomTeleports::TeleportTo(app::Vector3 position, bool interpolate) + { + auto &manager = game::EntityManager::instance(); + auto avatar = manager.avatar(); + if (avatar->moveComponent() == nullptr) + { + LOG_ERROR("Avatar has no move component, Is scene loaded?"); + return; + } + if (interpolate) + { + float speed = this->f_Speed; + auto avatarPos = manager.avatar()->absolutePosition(); + auto endPos = position; + std::thread interpolate([avatarPos, endPos, &manager, speed]() + { + float t = 0.0f; + app::Vector3 zero = {0,0,0}; + auto newPos = zero; + while (t < 1.0f) { + newPos = app::Vector3_Lerp(avatarPos, endPos, t, nullptr); + manager.avatar()->setAbsolutePosition(newPos); + t += speed / 100.0f; + Sleep(10); + } }); + interpolate.detach(); + } + else + { + if (PositionDistance(position, app::ActorUtils_GetAvatarPos(nullptr)) > 60.0f) + MapTeleport::GetInstance().TeleportTo(position); + else + manager.avatar()->setAbsolutePosition(position); + } + } + void CustomTeleports::OnTeleportKeyPressed(bool next) { if (!f_Enabled || selectedIndex < 0) @@ -144,7 +181,7 @@ namespace cheat::feature position = Teleports.at(list.at(index + (next ? 1 : -1))).position; selectedIndex = list.at(index + (next ? 1 : -1)); } - mapTeleport.TeleportTo(position); + TeleportTo(position, this->f_Interpolate); UpdateIndexName(); } @@ -239,9 +276,9 @@ namespace cheat::feature "3. You can now press Next or Previous Hotkey to Teleport through the Checklist\n" "Initially it will teleport the player to the selection made\n" "Note: Double click or click the arrow to open teleport details"); + ConfigWidget("Enable Interpolation", f_Interpolate, "Enable interpolation between teleports when using keybinds"); ConfigWidget("Interpolation Speed", f_Speed, 0.1f, 0.1f, 99.0f, - "Interpolation speed.\n" \ - "recommended setting below or equal to 0.1."); + "Interpolation speed.\n recommended setting below or equal to 0.1."); if (ImGui::Button("Delete Checked")) { @@ -347,37 +384,13 @@ namespace cheat::feature ImGui::SameLine(); if (ImGui::Button(("TP##Button" + stringIndex).c_str())) { - auto &manager = game::EntityManager::instance(); - auto avatar = manager.avatar(); - if (avatar->moveComponent() == nullptr) - { - LOG_ERROR("Avatar has no move component, Is scene loaded?"); - return; - } - if (PositionDistance(position, app::ActorUtils_GetAvatarPos(nullptr)) > 60.0f) - MapTeleport::GetInstance().TeleportTo(position); - else - manager.avatar()->setAbsolutePosition(position); + TeleportTo(position, false); } ImGui::SameLine(); if (ImGui::Button(("Lerp##Button" + stringIndex).c_str())) { - float speed = this->f_Speed; - auto &manager = game::EntityManager::instance(); - auto avatarPos = manager.avatar()->absolutePosition(); - auto endPos = position; - std::thread interpolate([avatarPos, endPos, &manager, speed](){ - float t = 0.0f; - app::Vector3 zero = {0,0,0}; - auto newPos = zero; - while (t < 1.0f) { - newPos = app::Vector3_Lerp(avatarPos, endPos, t, nullptr); - manager.avatar()->setAbsolutePosition(newPos); - t += speed / 100.0f; - Sleep(10); - } }); - interpolate.detach(); + TeleportTo(position, true); } ImGui::SameLine(); diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.h b/cheat-library/src/user/cheat/teleport/CustomTeleports.h index 3150659..6b2de3c 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.h +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.h @@ -26,6 +26,7 @@ namespace cheat::feature { public: config::Field> f_Enabled; + config::Field> f_Interpolate; config::Field f_Speed; config::Field f_Next; config::Field f_Previous; @@ -55,6 +56,7 @@ namespace cheat::feature std::string selectedName; std::string selectedIndexName; CustomTeleports(); + void TeleportTo(app::Vector3 position, bool interpolate); void OnTeleportKeyPressed(bool next); void OnPrevious(); void OnNext();