From cdc4f4b9e2d6e95be3387a71294501be2420d8f8 Mon Sep 17 00:00:00 2001 From: Nanako <00sh.chiha+github@gmail.com> Date: Wed, 3 Aug 2022 18:46:41 +0900 Subject: [PATCH 1/5] interpolata --- .../user/cheat/teleport/CustomTeleports.cpp | 26 ++++++++++++++++++- .../src/user/cheat/teleport/CustomTeleports.h | 1 - 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index 8e6738f..5c10866 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -17,7 +17,6 @@ namespace cheat::feature { CustomTeleports::CustomTeleports() : Feature(), - NF(f_DebugMode, "Debug Mode", "CustomTeleports", false), // Soon to be added 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)), @@ -194,6 +193,8 @@ namespace cheat::feature selectedIndexName = name; } + app::Vector3 Lerp(const app::Vector3 &a, const app::Vector3 &b, float t) { return a + (b - a) * t; } + void CustomTeleports::DrawMain() { // Buffers @@ -368,6 +369,29 @@ namespace cheat::feature } ImGui::SameLine(); + if (ImGui::Button("Interpolate to")) + { + auto &manager = game::EntityManager::instance(); + auto avatarPos = manager.avatar()->absolutePosition(); + LOG_DEBUG("Defined avatar pos: %s", il2cppi_to_string(avatarPos).c_str()); + auto endPos = position; + LOG_DEBUG("Defined end pos: %s", il2cppi_to_string(endPos).c_str()); + std::thread interpolate([avatarPos, endPos, &manager](){ + float t = 0.0f; + app::Vector3 zero = {0,0,0}; + auto newPos = zero, speed = zero; + while (t <= 1.0f) { + newPos = Lerp(avatarPos, endPos, t); + manager.avatar()->setAbsolutePosition(newPos); + t += 0.01f; + LOG_DEBUG("newpos: %s, completion rate: %.02f%%", il2cppi_to_string(newPos).c_str(), t * 100.0f); + Sleep(10); + if (t >= 1.0f) break; // this *might* be redundant, but i'm paranoid + } }); + interpolate.detach(); + } + ImGui::SameLine(); + if (ImGui::Button(("Select##Button" + std::to_string(index)).c_str())) { selectedIndex = index; diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.h b/cheat-library/src/user/cheat/teleport/CustomTeleports.h index e1fd414..3800dc2 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.h +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.h @@ -25,7 +25,6 @@ namespace cheat::feature class CustomTeleports : public Feature { public: - config::Field> f_DebugMode; config::Field> f_Enabled; config::Field f_Next; config::Field f_Previous; From bb8a1f79667cfec13afdfe5d073b4b1225a836a8 Mon Sep 17 00:00:00 2001 From: Joaquin <67109235+Taiga74164@users.noreply.github.com> Date: Wed, 3 Aug 2022 05:01:52 -0600 Subject: [PATCH 2/5] Lerp function --- cheat-library/src/user/cheat/teleport/CustomTeleports.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index 5c10866..633be4c 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -193,8 +193,6 @@ namespace cheat::feature selectedIndexName = name; } - app::Vector3 Lerp(const app::Vector3 &a, const app::Vector3 &b, float t) { return a + (b - a) * t; } - void CustomTeleports::DrawMain() { // Buffers @@ -381,7 +379,7 @@ namespace cheat::feature app::Vector3 zero = {0,0,0}; auto newPos = zero, speed = zero; while (t <= 1.0f) { - newPos = Lerp(avatarPos, endPos, t); + newPos = app::Vector3_Lerp(avatarPos, endPos, t, nullptr); manager.avatar()->setAbsolutePosition(newPos); t += 0.01f; LOG_DEBUG("newpos: %s, completion rate: %.02f%%", il2cppi_to_string(newPos).c_str(), t * 100.0f); From 7db1b4eff28c25c79a410cc85069d042dfda0b56 Mon Sep 17 00:00:00 2001 From: Nanako <00sh.chiha+github@gmail.com> Date: Wed, 3 Aug 2022 20:56:45 +0900 Subject: [PATCH 3/5] Make speed option - and some fixes --- .../user/cheat/teleport/CustomTeleports.cpp | 30 +++++++++---------- .../src/user/cheat/teleport/CustomTeleports.h | 1 + 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index 633be4c..6f9a71a 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_Speed, "Interpolation Speed", "CustomTeleports", 10.0f), dir(util::GetCurrentPath() / "teleports") { f_Next.value().PressedEvent += MY_METHOD_HANDLER(CustomTeleports::OnNext); @@ -172,9 +173,7 @@ namespace cheat::feature while (wordItr != std::sregex_iterator()) { for (unsigned i = 0; i < wordItr->size(); i++) - { shortened.append((*wordItr)[i]); - } wordItr++; } @@ -248,6 +247,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("Interpolation Speed", f_Speed, 0.1f, 0.1f, 99.0f, + "Interpolation speed.\n" \ + "recommended setting below or equal to 0.1."); ImGui::SameLine(); if (ImGui::Button("Delete Checked")) @@ -315,7 +317,7 @@ namespace cheat::feature maxNameLength = Teleport.name.length(); ImGui::BeginTable("Teleports", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_NoSavedSettings); ImGui::TableSetupColumn("#", ImGuiTableColumnFlags_WidthFixed, 20); - ImGui::TableSetupColumn("Commands", ImGuiTableColumnFlags_WidthFixed, 100); + ImGui::TableSetupColumn("Commands", ImGuiTableColumnFlags_WidthFixed, 130); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, maxNameLength * 8 + 10); ImGui::TableSetupColumn("Position"); ImGui::TableHeadersRow(); @@ -331,12 +333,13 @@ namespace cheat::feature bool checked = std::any_of(checkedIndices.begin(), checkedIndices.end(), [&index](const auto &i) { return i == index; }); bool selected = index == selectedIndex; + std::string stringIndex = std::to_string(index); ImGui::TableNextRow(); ImGui::TableNextColumn(); ImGui::Text("%d", index); ImGui::TableNextColumn(); - ImGui::Checkbox(("##Index" + std::to_string(index)).c_str(), &checked); + ImGui::Checkbox(("##Index" + stringIndex).c_str(), &checked); if (ImGui::IsItemClicked(0)) { if (checked) @@ -351,7 +354,7 @@ namespace cheat::feature } ImGui::SameLine(); - if (ImGui::Button(("TP##Button" + std::to_string(index)).c_str())) + if (ImGui::Button(("TP##Button" + stringIndex).c_str())) { auto &manager = game::EntityManager::instance(); auto avatar = manager.avatar(); @@ -367,30 +370,27 @@ namespace cheat::feature } ImGui::SameLine(); - if (ImGui::Button("Interpolate to")) + if (ImGui::Button(("Lerp##Button" + stringIndex).c_str())) { + float speed = this->f_Speed; auto &manager = game::EntityManager::instance(); auto avatarPos = manager.avatar()->absolutePosition(); - LOG_DEBUG("Defined avatar pos: %s", il2cppi_to_string(avatarPos).c_str()); auto endPos = position; - LOG_DEBUG("Defined end pos: %s", il2cppi_to_string(endPos).c_str()); - std::thread interpolate([avatarPos, endPos, &manager](){ + std::thread interpolate([avatarPos, endPos, &manager, speed](){ float t = 0.0f; app::Vector3 zero = {0,0,0}; - auto newPos = zero, speed = zero; - while (t <= 1.0f) { + auto newPos = zero; + while (t < 1.0f) { newPos = app::Vector3_Lerp(avatarPos, endPos, t, nullptr); manager.avatar()->setAbsolutePosition(newPos); - t += 0.01f; - LOG_DEBUG("newpos: %s, completion rate: %.02f%%", il2cppi_to_string(newPos).c_str(), t * 100.0f); + t += speed / 100.0f; Sleep(10); - if (t >= 1.0f) break; // this *might* be redundant, but i'm paranoid } }); interpolate.detach(); } ImGui::SameLine(); - if (ImGui::Button(("Select##Button" + std::to_string(index)).c_str())) + if (ImGui::Button(("Select##Button" + stringIndex).c_str())) { selectedIndex = index; selectedByClick = true; diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.h b/cheat-library/src/user/cheat/teleport/CustomTeleports.h index 3800dc2..3150659 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_Speed; config::Field f_Next; config::Field f_Previous; static CustomTeleports& GetInstance(); From cac25b8a96596ed5fe4f06e3af6f0d80846bd149 Mon Sep 17 00:00:00 2001 From: Nanako <00sh.chiha+github@gmail.com> Date: Thu, 4 Aug 2022 16:24:28 +0900 Subject: [PATCH 4/5] Little Refactor --- .../user/cheat/teleport/CustomTeleports.cpp | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index 6f9a71a..91776a9 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -157,36 +157,28 @@ namespace cheat::feature OnTeleportKeyPressed(true); } + void itr(std::regex exp, std::string name, std::string s) + { + std::sregex_iterator itr(name.begin(), name.end(), exp); + while (itr != std::sregex_iterator()) + { + for (unsigned i = 0; i < itr->size(); i++) + s.append((*itr)[i]); + itr++; + } + } void CustomTeleports::UpdateIndexName() { - std::string name(selectedIndex == -1 || checkedIndices.empty() ? "" : Teleports.at(selectedIndex).name); - // abbreviate teleport names that are too long + std::string name(selectedIndex == -1 || checkedIndices.empty() ? "" : Teleports.at(selectedIndex).name); if (name.length() > 15) { std::string shortened; std::regex numsExp("[\\d]+"); std::regex firstCharsExp("\\b[A-Za-z]"); - - std::sregex_iterator wordItr(name.begin(), name.end(), firstCharsExp); - while (wordItr != std::sregex_iterator()) - { - for (unsigned i = 0; i < wordItr->size(); i++) - shortened.append((*wordItr)[i]); - wordItr++; - } - - std::sregex_iterator numItr(name.begin(), name.end(), numsExp); - while (numItr != std::sregex_iterator()) - { - for (unsigned i = 0; i < numItr->size(); i++) - { - shortened.append(" "); - shortened.append((*numItr)[i]); - } - numItr++; - } + itr(firstCharsExp, name, shortened); + itr(numsExp, name, shortened); name = shortened; } selectedIndexName = name; @@ -250,7 +242,6 @@ namespace cheat::feature ConfigWidget("Interpolation Speed", f_Speed, 0.1f, 0.1f, 99.0f, "Interpolation speed.\n" \ "recommended setting below or equal to 0.1."); - ImGui::SameLine(); if (ImGui::Button("Delete Checked")) { 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 5/5] 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();