AutoLoot.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include "AutoLoot.h"
  2. namespace cheat {
  3. static void LCSelectPickup_AddInteeBtnByID_Hook(void* __this, app::BaseEntity* entity, app::MethodInfo* method);
  4. void OnAutoLoot();
  5. void GameManager_Update_AutoLootHook(app::GameManager* __this, app::MethodInfo* method);
  6. app::MoleMole_ItemModule* ItemModule;
  7. SafeQueue<uint32_t> toBeLootedItems;
  8. int64_t nextLootTime;
  9. AutoLoot::AutoLoot() {
  10. f_Enabled = config::getValue("functions:AutoLoot", "enabled", false);
  11. f_Hotkey = Hotkey("functions:AutoLoot");
  12. HookManager::install(app::GameManager_Update, GameManager_Update_AutoLootHook);
  13. HookManager::install(app::MoleMole_LCSelectPickup_AddInteeBtnByID, LCSelectPickup_AddInteeBtnByID_Hook);
  14. }
  15. AutoLoot& AutoLoot::getInstance() {
  16. static AutoLoot instance;
  17. return instance;
  18. }
  19. void AutoLoot::GUI() {
  20. ConfigCheckbox(_("Auto loot"), f_Enabled, _("AutoLoot"));
  21. if (f_Enabled.getValue()) {
  22. ImGui::Indent();
  23. if (ImGui::BeginTable(_("AutoLootDrawTable"), 2, ImGuiTableFlags_NoBordersInBody)) {
  24. ImGui::TableNextRow();
  25. ImGui::TableSetColumnIndex(0);
  26. BeginGroupPanel("Auto-Pickup");
  27. {
  28. ConfigCheckbox(_("Enabled"), f_AutoPickup, _("Automatically picks up dropped items.\n" \
  29. "Note: Using this with custom range and low delay times is extremely risky.\n" \
  30. "Abuse will definitely merit a ban.\n\n" \
  31. "If using with custom range, make sure this is turned on FIRST."));
  32. ImGui::SameLine();
  33. ImGui::TextColored(ImColor(255, 165, 0, 255), "Read the note!");
  34. }
  35. EndGroupPanel();
  36. BeginGroupPanel(_("Custom Pickup Range"));
  37. {
  38. ConfigCheckbox(_("Enabled"), f_UseCustomRange, _("Enable custom pickup range.\n" \
  39. "High values are not recommended, as it is easily detected by the server.\n\n" \
  40. "If using with auto-pickup/auto-treasure, turn this on LAST."));
  41. ImGui::SameLine();
  42. ImGui::TextColored(ImColor(255, 165, 0, 255), "Read the note!");
  43. ImGui::SetNextItemWidth(100.0f);
  44. ConfigSliderFloat(_("Range (m)"), f_CustomRange, 0.1f, 40.0f, _("Modifies pickup/open range to this value (in meters)."));
  45. }
  46. EndGroupPanel();
  47. BeginGroupPanel("Looting Speed");
  48. {
  49. ImGui::SetNextItemWidth(100.0f);
  50. ConfigSliderInt(_("Delay Time (ms)"), f_DelayTime, 1, 1000, _("Delay (in ms) between loot/open actions.\n" \
  51. "Values under 200ms are unsafe.\nNot used if no auto-functions are on."));
  52. }
  53. EndGroupPanel();
  54. BeginGroupPanel("Looting delay fluctuation");
  55. {
  56. ConfigCheckbox(_("Enabled"), f_UseDelayTimeFluctuation, _("Enable delay fluctuation.\n" \
  57. "Simulates human clicking delay as manual clickling never consistent."));
  58. ImGui::SameLine();
  59. ImGui::TextColored(ImColor(255, 165, 0, 255), "Read the note!");
  60. ImGui::SetNextItemWidth(100.0f);
  61. ConfigSliderInt(_("Delay range +(ms)"), f_DelayTimeFluctuation, 1, 1000, _("Delay randomly fluctuates between 'Delay Time'+'Delay Time+range'"));
  62. }
  63. EndGroupPanel();
  64. ImGui::TableSetColumnIndex(1);
  65. BeginGroupPanel("Auto-Treasure");
  66. {
  67. ConfigCheckbox(_("Enabled"), f_AutoTreasure, _("Automatically opens chests and other treasures.\n" \
  68. "Note: Using this with custom range and low delay times is extremely risky.\n" \
  69. "Abuse will definitely merit a ban.\n\n" \
  70. "If using with custom range, make sure this is turned on FIRST."));
  71. ImGui::SameLine();
  72. ImGui::TextColored(ImColor(255, 165, 0, 255), "Read the note!");
  73. ImGui::Indent();
  74. ConfigCheckbox(_("Chests"), f_Chest, _("Common, precious, luxurious, etc."));
  75. ConfigCheckbox(_("Leyline"), f_Leyline, _("Mora/XP, overworld/Trounce bosses, etc."));
  76. ConfigCheckbox(_("Search Points"), f_Investigate, _("Marked as Investigate/Search, etc."));
  77. ConfigCheckbox(_("Quest Interacts"), f_QuestInteract, _("Valid quest interact points."));
  78. ConfigCheckbox(_("Others"), f_Others, _("Book Pages, Spincrystals, etc."));
  79. ImGui::Unindent();
  80. }
  81. EndGroupPanel();
  82. ImGui::EndTable();
  83. }
  84. BeginGroupPanel("Pickup Filter");
  85. {
  86. ConfigCheckbox(_("Enabled"), f_PickupFilter, _("Enable pickup filter.\n"));
  87. ConfigCheckbox(_("Animals"), f_PickupFilter_Animals, _("Fish, Lizard, Frog, Flying animals.")); ImGui::SameLine();
  88. ConfigCheckbox(_("Drop Items"), f_PickupFilter_DropItems, _("Material, Mineral, Artifact.")); ImGui::SameLine();
  89. ConfigCheckbox(_("Resources"), f_PickupFilter_Resources, _("Everything beside Animals and Drop Items (Plants, Books, etc).")); ImGui::SameLine();
  90. ConfigCheckbox(_("Oculus"), f_PickupFilter_Oculus, _("Filter Oculus"));
  91. }
  92. EndGroupPanel();
  93. f_Hotkey.Draw();
  94. ImGui::Unindent();
  95. }
  96. }
  97. void AutoLoot::Status() {
  98. if (f_Enabled.getValue())
  99. ImGui::Text(_("Item teleport"));
  100. }
  101. void AutoLoot::Outer() {
  102. if (f_Hotkey.IsPressed())
  103. f_Enabled.setValue(!f_Enabled.getValue());
  104. }
  105. std::string AutoLoot::getModule() {
  106. return _("World");
  107. }
  108. void GameManager_Update_AutoLootHook(app::GameManager* __this, app::MethodInfo* method) {
  109. AutoLoot& autoLoot = AutoLoot::getInstance();
  110. if (autoLoot.f_Enabled.getValue())
  111. OnAutoLoot();
  112. CALL_ORIGIN(GameManager_Update_AutoLootHook, __this, method);
  113. }
  114. void OnAutoLoot() {
  115. AutoLoot& autoLoot = AutoLoot::getInstance();
  116. auto currentTime = util::GetCurrentTimeMillisec();
  117. if (currentTime < nextLootTime)
  118. return;
  119. auto entityManager = app::MoleMole_InLevelDrumPageContext_get_ENTITY(nullptr);
  120. if (entityManager == nullptr)
  121. return;
  122. if (autoLoot.f_AutoTreasure.getValue()) {
  123. auto& manager = game::EntityManager::getInstance();
  124. for (auto& entity : manager.entities(game::filters::combined::Chests)) {
  125. auto chest = reinterpret_cast<game::Chest*>(entity);
  126. auto chestType = chest->itemType();
  127. if (!autoLoot.f_Investigate.getValue() && chestType == game::Chest::ItemType::Investigate)
  128. continue;
  129. if (!autoLoot.f_QuestInteract.getValue() && chestType == game::Chest::ItemType::QuestInteract)
  130. continue;
  131. if (!autoLoot.f_Others.getValue() && (
  132. chestType == game::Chest::ItemType::BGM ||
  133. chestType == game::Chest::ItemType::BookPage))
  134. continue;
  135. if (!autoLoot.f_Leyline.getValue() && chestType == game::Chest::ItemType::Flora)
  136. continue;
  137. if (chestType == game::Chest::ItemType::Chest) {
  138. if (!autoLoot.f_Chest.getValue())
  139. continue;
  140. }
  141. uint32_t entityId = entity->runtimeID();
  142. toBeLootedItems.push(entityId);
  143. }
  144. }
  145. auto entityId = toBeLootedItems.pop();
  146. if (!entityId || ItemModule == nullptr)
  147. return;
  148. auto entity = app::MoleMole_EntityManager_GetValidEntity(entityManager, *entityId);
  149. if (entity == nullptr)
  150. return;
  151. app::MoleMole_ItemModule_PickItem(ItemModule, *entityId, nullptr);
  152. int fluctuation = 0;
  153. if (autoLoot.f_UseDelayTimeFluctuation.getValue())
  154. fluctuation = std::rand() % (autoLoot.f_DelayTimeFluctuation.getValue() + 1);
  155. nextLootTime = currentTime + (int)autoLoot.f_DelayTime.getValue() + fluctuation;
  156. }
  157. bool OnCreateButton(app::BaseEntity* entity) {
  158. AutoLoot& autoLoot = AutoLoot::getInstance();
  159. if (!autoLoot.f_AutoPickup.getValue())
  160. return false;
  161. auto entityId = entity->fields._runtimeID_k__BackingField;
  162. if (autoLoot.f_DelayTime.getValue() == 0) {
  163. LOG_DEBUG("trying to pick item");
  164. app::MoleMole_ItemModule_PickItem(ItemModule, entityId, nullptr);
  165. LOG_DEBUG("picked up");
  166. return true;
  167. }
  168. toBeLootedItems.push(entityId);
  169. return false;
  170. }
  171. static void LCSelectPickup_AddInteeBtnByID_Hook(void* __this, app::BaseEntity* entity, app::MethodInfo* method) {
  172. bool canceled = OnCreateButton(entity);
  173. if (!canceled)
  174. CALL_ORIGIN(LCSelectPickup_AddInteeBtnByID_Hook, __this, entity, method);
  175. }
  176. }