From fb555cf7ddfa8cbc54686fa01756e7bc072ca2b7 Mon Sep 17 00:00:00 2001 From: Miya Date: Tue, 9 Aug 2022 12:22:11 +0800 Subject: [PATCH] Auto Challenge --- cheat-library/cheat-library.vcxproj | 2 + cheat-library/cheat-library.vcxproj.filters | 6 ++ cheat-library/src/user/cheat/cheat.cpp | 2 + cheat-library/src/user/cheat/game/filters.cpp | 2 +- cheat-library/src/user/cheat/game/filters.h | 1 + .../src/user/cheat/world/AutoChallenge.cpp | 80 +++++++++++++++++++ .../src/user/cheat/world/AutoChallenge.h | 29 +++++++ 7 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 cheat-library/src/user/cheat/world/AutoChallenge.cpp create mode 100644 cheat-library/src/user/cheat/world/AutoChallenge.h diff --git a/cheat-library/cheat-library.vcxproj b/cheat-library/cheat-library.vcxproj index 12cc502..349d0b9 100644 --- a/cheat-library/cheat-library.vcxproj +++ b/cheat-library/cheat-library.vcxproj @@ -24,6 +24,7 @@ + @@ -117,6 +118,7 @@ + diff --git a/cheat-library/cheat-library.vcxproj.filters b/cheat-library/cheat-library.vcxproj.filters index c949b36..0dcfe1c 100644 --- a/cheat-library/cheat-library.vcxproj.filters +++ b/cheat-library/cheat-library.vcxproj.filters @@ -255,6 +255,9 @@ Header Files + + Header Files + @@ -468,6 +471,9 @@ Source Files + + Source Files + diff --git a/cheat-library/src/user/cheat/cheat.cpp b/cheat-library/src/user/cheat/cheat.cpp index 1dbdcae..234b7f9 100644 --- a/cheat-library/src/user/cheat/cheat.cpp +++ b/cheat-library/src/user/cheat/cheat.cpp @@ -42,6 +42,7 @@ #include #include +#include #include #include @@ -97,6 +98,7 @@ namespace cheat FEAT_INST(FreezeEnemies), FEAT_INST(ElementalSight), FEAT_INST(KillAura), + FEAT_INST(AutoChallenge), FEAT_INST(MobVacuum), FEAT_INST(FakeTime), diff --git a/cheat-library/src/user/cheat/game/filters.cpp b/cheat-library/src/user/cheat/game/filters.cpp index 3c23e4f..6c6b486 100644 --- a/cheat-library/src/user/cheat/game/filters.cpp +++ b/cheat-library/src/user/cheat/game/filters.cpp @@ -320,7 +320,7 @@ namespace cheat::game::filters WhitelistFilter DreamForm = { {EntityType__Enum_1::Field, EntityType__Enum_1::Platform }, "_AnimalSeelie" }; SimpleFilter StarlightCoalescence = { EntityType__Enum_1::Field, "_PaperStar" }; SimpleFilter TheRavenForum = { EntityType__Enum_1::Gadget, "_NightCrowStatue" }; - + WhitelistFilter TimeTrialChallengeCollection = { { EntityType__Enum_1::Field, EntityType__Enum_1::Gadget }, { "SkillObj_EmptyGadget", "_GlideChampOrb" } }; } namespace combined diff --git a/cheat-library/src/user/cheat/game/filters.h b/cheat-library/src/user/cheat/game/filters.h index 2edd84f..a1b21a9 100644 --- a/cheat-library/src/user/cheat/game/filters.h +++ b/cheat-library/src/user/cheat/game/filters.h @@ -320,6 +320,7 @@ namespace cheat::game::filters extern WhitelistFilter DreamForm; extern SimpleFilter StarlightCoalescence; extern SimpleFilter TheRavenForum; + extern WhitelistFilter TimeTrialChallengeCollection; } namespace combined diff --git a/cheat-library/src/user/cheat/world/AutoChallenge.cpp b/cheat-library/src/user/cheat/world/AutoChallenge.cpp new file mode 100644 index 0000000..9cba70e --- /dev/null +++ b/cheat-library/src/user/cheat/world/AutoChallenge.cpp @@ -0,0 +1,80 @@ +#include "pch-il2cpp.h" +#include "AutoChallenge.h" + +#include +#include +#include + +namespace cheat::feature +{ + + AutoChallenge::AutoChallenge() : Feature(), + NF(f_Enabled, "Auto challenge", "AutoChallenge", false), + NF(f_Delay, "Collect delay", "AutoChallenge", 1000), + NF(f_Range, "Collect range", "AutoChallenge", 20.f) + { + events::GameUpdateEvent += MY_METHOD_HANDLER(AutoChallenge::OnGameUpdate); + } + + const FeatureGUIInfo& AutoChallenge::GetGUIInfo() const + { + static const FeatureGUIInfo info{ "Auto Challenge", "World", true }; + return info; + } + + void AutoChallenge::DrawMain() + { + ConfigWidget("Enabled", f_Enabled, "Auto collect time challenge item"); + ImGui::SetNextItemWidth(200.f); + ConfigWidget("Range", f_Range, 0.1f, 0.f, 300.f, "Collect range."); + ImGui::SameLine(); + ImGui::SetNextItemWidth(200.f); + ConfigWidget("Delay", f_Delay, 1, 0, 2000, "Collect delay."); + } + + bool AutoChallenge::NeedStatusDraw() const + { + return f_Enabled; + } + + void AutoChallenge::DrawStatus() + { + ImGui::Text("Challenge [%.01fm]", f_Range.value()); + } + + AutoChallenge& AutoChallenge::GetInstance() + { + static AutoChallenge instance; + return instance; + } + + void AutoChallenge::OnGameUpdate() + { + static uint64_t lastTime = 0; + auto timestamp = app::MoleMole_TimeUtil_get_NowTimeStamp(nullptr); + + if (!f_Enabled || lastTime + f_Delay > timestamp) + return; + + auto& entityManager = game::EntityManager::instance(); + auto avatarEntity = entityManager.avatar(); + + for (auto& entity : entityManager.entities(game::filters::puzzle::TimeTrialChallengeCollection)) + { + if (avatarEntity->distance(entity) > f_Range) + continue; + + auto combat = entity->combat(); + if (combat != nullptr) + { + auto combatProp = combat->fields._combatProperty_k__BackingField; + auto maxHP = app::MoleMole_SafeFloat_get_Value(combatProp->fields.maxHP, nullptr); + // so many entities named "SkillObj_EmptyGadget", but the collection's hp is 99999.f + if (maxHP > 99998 && maxHP < 99999.9) + { + entity->setRelativePosition(avatarEntity->relativePosition()); + } + } + } + } +} \ No newline at end of file diff --git a/cheat-library/src/user/cheat/world/AutoChallenge.h b/cheat-library/src/user/cheat/world/AutoChallenge.h new file mode 100644 index 0000000..ca442cc --- /dev/null +++ b/cheat-library/src/user/cheat/world/AutoChallenge.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include + +namespace cheat::feature +{ + + class AutoChallenge : public Feature + { + public: + config::Field> f_Enabled; + config::Field f_Delay; + config::Field f_Range; + + static AutoChallenge& GetInstance(); + + void OnGameUpdate(); + + const FeatureGUIInfo& GetGUIInfo() const override; + void DrawMain() override; + + virtual bool NeedStatusDraw() const override; + void DrawStatus() override; + + private: + AutoChallenge(); + }; +} +