PickupRange.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include "PickupRange.h"
  2. namespace cheat {
  3. static bool LCSelectPickup_IsInPosition_Hook(void* __this, app::BaseEntity* entity, app::MethodInfo* method);
  4. static bool LCSelectPickup_IsOutPosition_Hook(void* __this, app::BaseEntity* entity, app::MethodInfo* method);
  5. float g_default_range = 3.0f;
  6. PickupRange::PickupRange() {
  7. f_Enabled = config::getValue("functions:ItemTeleport", "enabled", false);
  8. f_CustomRange = config::getValue("functions:ItemTeleport", "range", g_default_range);
  9. f_Hotkey = Hotkey("functions:ItemTeleport");
  10. HookManager::install(app::MoleMole_LCSelectPickup_IsInPosition, LCSelectPickup_IsInPosition_Hook);
  11. HookManager::install(app::MoleMole_LCSelectPickup_IsOutPosition, LCSelectPickup_IsOutPosition_Hook);
  12. }
  13. PickupRange& PickupRange::getInstance() {
  14. static PickupRange instance;
  15. return instance;
  16. }
  17. void PickupRange::GUI() {
  18. ConfigCheckbox(_("Custom Pickup Range"), f_Enabled, _("Enable custom pickup range."));
  19. if (f_Enabled.getValue()) {
  20. ImGui::Indent();
  21. ConfigSliderFloat(_("Range (m)"), f_CustomRange, 0.1f, 40.0f, _("Modifies pickup/open range to this value (in meters)."));
  22. f_Hotkey.Draw();
  23. ImGui::Unindent();
  24. }
  25. }
  26. void PickupRange::Status() {
  27. if (f_Enabled.getValue())
  28. ImGui::Text(_("Pickup range"));
  29. }
  30. void PickupRange::Outer() {
  31. if (f_Hotkey.IsPressed())
  32. f_Enabled.setValue(!f_Enabled.getValue());
  33. }
  34. std::string PickupRange::getModule() {
  35. return _("World");
  36. }
  37. void OnCheckIsInPosition(bool& result, app::BaseEntity* entity)
  38. {
  39. PickupRange& pickupRange = PickupRange::getInstance();
  40. auto& manager = game::EntityManager::getInstance();
  41. float distance = pickupRange.f_Enabled.getValue() ? pickupRange.f_CustomRange.getValue() : g_default_range;
  42. result = manager.avatar()->distance(entity) < distance;
  43. }
  44. static bool LCSelectPickup_IsInPosition_Hook(void* __this, app::BaseEntity* entity, app::MethodInfo* method)
  45. {
  46. bool result = CALL_ORIGIN(LCSelectPickup_IsInPosition_Hook, __this, entity, method);
  47. OnCheckIsInPosition(result, entity);
  48. return result;
  49. }
  50. static bool LCSelectPickup_IsOutPosition_Hook(void* __this, app::BaseEntity* entity, app::MethodInfo* method)
  51. {
  52. bool result = CALL_ORIGIN(LCSelectPickup_IsOutPosition_Hook, __this, entity, method);
  53. OnCheckIsInPosition(result, entity);
  54. return result;
  55. }
  56. }