diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp index e3d9984..8e85eaa 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.cpp @@ -17,15 +17,19 @@ namespace cheat::feature { CustomTeleports::CustomTeleports() : 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") + 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_Auto, "Auto Teleport", "CustomTeleports", false), + NF(f_DelayTime, "Delay time (in s)", "CustomTeleports", 20), + NF(f_Interpolate, "Interpolate Teleport", "CustomTeleports", false), + NF(f_Speed, "Interpolation Speed", "CustomTeleports", 10.0f), + dir(util::GetCurrentPath() /= "teleports"), + nextTime(0) { f_Next.value().PressedEvent += MY_METHOD_HANDLER(CustomTeleports::OnNext); f_Previous.value().PressedEvent += MY_METHOD_HANDLER(CustomTeleports::OnPrevious); + events::GameUpdateEvent += MY_METHOD_HANDLER(CustomTeleports::OnGameUpdate); } const FeatureGUIInfo& CustomTeleports::GetGUIInfo() const @@ -79,16 +83,19 @@ namespace cheat::feature } } - Teleport CustomTeleports::SerializeFromJson(std::string json, bool fromfile) + std::optional CustomTeleports::SerializeFromJson(std::string json, bool fromfile) { nlohmann::json j; - try { j = nlohmann::json::parse(json);} - catch (nlohmann::json::parse_error &e) + try { j = nlohmann::json::parse(json); } + catch (nlohmann::json::parse_error& e) { LOG_ERROR("Invalid JSON Format"); LOG_ERROR("Failed to parse JSON: %s", e.what()); + return std::nullopt; } - std::string teleportName; + + std::string teleportName; + teleportName = j["name"]; if (j["name"].is_null() && fromfile) { @@ -98,7 +105,8 @@ namespace cheat::feature std::string description; if (j["description"].is_null()) description = ""; else description = j["description"]; - return Teleport_(teleportName, {j["position"][0], j["position"][1], j["position"][2]}, description); + return Teleport_(teleportName, { j["position"][0], j["position"][1], j["position"][2] }, description); + } void CustomTeleports::ReloadTeleports() @@ -113,7 +121,8 @@ namespace cheat::feature std::ifstream ifs(file.path()); std::string json; std::getline(ifs, json); - SerializeTeleport(SerializeFromJson(json, true)); + auto t = SerializeFromJson(json, true); + if(t.has_value()) SerializeTeleport(t.value()); } } } @@ -188,13 +197,38 @@ namespace cheat::feature void CustomTeleports::OnPrevious() { + if (f_Auto) return; OnTeleportKeyPressed(false); } void CustomTeleports::OnNext() { + if (f_Auto) return; OnTeleportKeyPressed(true); } + void CustomTeleports::OnGameUpdate() + { + if (!f_Enabled || !f_Auto) + return; + + auto currentTime = util::GetCurrentTimeMillisec(); + if (currentTime < nextTime) + return; + + auto loadingManager = GET_SINGLETON(MoleMole_LoadingManager); + if (loadingManager == nullptr || !app::MoleMole_LoadingManager_IsLoaded(loadingManager, nullptr)) + return; + + auto camera = app::Camera_get_main(nullptr); + if (camera == nullptr) return; + + if (!app::Behaviour_get_isActiveAndEnabled(reinterpret_cast(camera), nullptr)) + return; + + nextTime = currentTime + (int64_t)f_DelayTime * 1000; + OnTeleportKeyPressed(true); + } + void itr(std::regex exp, std::string name, std::string s) { std::sregex_iterator itr(name.begin(), name.end(), exp); @@ -260,26 +294,35 @@ namespace cheat::feature ImGui::SameLine(); if (ImGui::Button("Load from JSON")) { - selectedIndex = -1; - UpdateIndexName(); - SerializeTeleport(SerializeFromJson(JSONBuffer_, false)); - JSONBuffer_ = ""; + if (!JSONBuffer_.empty()) { + auto t = SerializeFromJson(JSONBuffer_, false); + if (t.has_value()) { + selectedIndex = -1; + UpdateIndexName(); + SerializeTeleport(t.value()); + } + JSONBuffer_.clear(); + } + } ImGui::InputTextMultiline("JSON input", &JSONBuffer_, ImVec2(0, 50), ImGuiInputTextFlags_AllowTabInput); - ConfigWidget("Teleport Next", f_Next, true, "Press to teleport next of selected"); - ConfigWidget("Teleport Previous", f_Previous, true, "Press to teleport previous of selected"); + ConfigWidget("Teleport Next", f_Next, true, "Press to teleport next of selected."); + ConfigWidget("Teleport Previous", f_Previous, true, "Press to teleport previous of selected."); ConfigWidget("Enable", f_Enabled, - "Enable teleport-through-list functionality\n" + "Enable teleport-through-list functionality.\n" "Usage:\n" "1. Put Checkmark to the teleports you want to teleport using hotkey\n" "2. Single click the teleport (with checkmark) to select where you want to start\n" "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("Enable Interpolation", f_Interpolate, "Enable interpolation between teleports when using keybinds."); ImGui::SameLine(); ImGui::SetNextItemWidth(300.0f); ConfigWidget("Interpolation Speed", f_Speed, 0.1f, 0.1f, 99.0f, "Interpolation speed.\n recommended setting below or equal to 0.1."); + ConfigWidget("Auto Teleport", f_Auto, "Enable automatic forward teleporation between teleports"); ImGui::SameLine(); ImGui::SetNextItemWidth(300.0f); + ConfigWidget("Delay Time (s)", f_DelayTime, 1, 0, 60, "Delay (in s) between teleport.\n" + "Note: This is not fully tested detection-wise.\nNot recommended with low values."); if (ImGui::Button("Delete Checked")) { @@ -396,9 +439,12 @@ namespace cheat::feature if (ImGui::Button(("Select##Button" + stringIndex).c_str())) { - selectedIndex = index; - selectedByClick = true; - UpdateIndexName(); + auto isChecked = checkedIndices.find(index) != checkedIndices.end(); + if (isChecked) { + selectedIndex = index; + selectedByClick = true; + UpdateIndexName(); + } } ImGui::TableNextColumn(); @@ -432,7 +478,7 @@ namespace cheat::feature void CustomTeleports::DrawStatus() { - ImGui::Text("Custom Teleport\n[%s]", selectedIndexName); + ImGui::Text("Custom Teleport\n[%s|%s]", f_Auto ? "Auto" : "Manual", selectedIndexName); } CustomTeleports &CustomTeleports::GetInstance() diff --git a/cheat-library/src/user/cheat/teleport/CustomTeleports.h b/cheat-library/src/user/cheat/teleport/CustomTeleports.h index 6b2de3c..5352f36 100644 --- a/cheat-library/src/user/cheat/teleport/CustomTeleports.h +++ b/cheat-library/src/user/cheat/teleport/CustomTeleports.h @@ -4,6 +4,7 @@ #include #include +#include #include namespace cheat::feature @@ -27,9 +28,11 @@ namespace cheat::feature public: config::Field> f_Enabled; config::Field> f_Interpolate; + config::Field> f_Auto; config::Field f_Speed; config::Field f_Next; config::Field f_Previous; + config::Field f_DelayTime; static CustomTeleports& GetInstance(); const FeatureGUIInfo& GetGUIInfo() const override; @@ -38,12 +41,13 @@ namespace cheat::feature Teleport Teleport_(std::string name, app::Vector3 position, std::string description); void SerializeTeleport(Teleport t); void ReloadTeleports(); - Teleport SerializeFromJson(std::string json, bool fromfile); + std::optional SerializeFromJson(std::string json, bool fromfile); void DrawMain() override; virtual bool NeedStatusDraw() const override; void DrawStatus() override; + void OnGameUpdate(); std::vector Teleports; std::filesystem::path dir; @@ -55,6 +59,7 @@ namespace cheat::feature int selectedIndex = -1; std::string selectedName; std::string selectedIndexName; + SafeValue nextTime; CustomTeleports(); void TeleportTo(app::Vector3 position, bool interpolate); void OnTeleportKeyPressed(bool next);