2022-11-27 01:29:14 +08:00
|
|
|
#include "hotkey_service.hpp"
|
|
|
|
#include "fiber_pool.hpp"
|
|
|
|
#include "util/teleport.hpp"
|
2022-12-16 18:55:55 +01:00
|
|
|
#include "renderer.hpp"
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2022-11-29 20:48:58 +01:00
|
|
|
#include "network/ChatData.hpp"
|
|
|
|
#include "pointers.hpp"
|
2023-01-22 21:57:32 +00:00
|
|
|
#include "gui.hpp"
|
2022-11-29 20:48:58 +01:00
|
|
|
|
2022-11-27 01:29:14 +08:00
|
|
|
namespace big
|
|
|
|
{
|
|
|
|
hotkey_service::hotkey_service()
|
|
|
|
{
|
2022-12-22 21:23:32 +00:00
|
|
|
register_hotkey("waypoint", g.settings.hotkeys.teleport_waypoint, RAGE_JOAAT("waypointtp"));
|
|
|
|
register_hotkey("objective", g.settings.hotkeys.teleport_objective, RAGE_JOAAT("objectivetp"));
|
|
|
|
register_hotkey("noclip", g.settings.hotkeys.noclip, RAGE_JOAAT("noclip"));
|
2023-01-09 11:40:03 -05:00
|
|
|
register_hotkey("bringpv", g.settings.hotkeys.bringvehicle, RAGE_JOAAT("bringpv"));
|
|
|
|
register_hotkey("invis", g.settings.hotkeys.invis, RAGE_JOAAT("invis"));
|
|
|
|
register_hotkey("heal", g.settings.hotkeys.heal, RAGE_JOAAT("heal"));
|
|
|
|
register_hotkey("fillsnacks", g.settings.hotkeys.fill_inventory, RAGE_JOAAT("fillsnacks"));
|
|
|
|
register_hotkey("skipcutscene", g.settings.hotkeys.skip_cutscene, RAGE_JOAAT("skipcutscene"));
|
|
|
|
register_hotkey("superjump", g.settings.hotkeys.superjump, RAGE_JOAAT("superjump"));
|
|
|
|
register_hotkey("beastjump", g.settings.hotkeys.beastjump, RAGE_JOAAT("beastjump"));
|
|
|
|
register_hotkey("invisveh", g.settings.hotkeys.invisveh, RAGE_JOAAT("invisveh"));
|
|
|
|
register_hotkey("localinvisveh", g.settings.hotkeys.localinvisveh, RAGE_JOAAT("localinvisveh"));
|
2023-02-01 19:48:50 +01:00
|
|
|
register_hotkey("fastquit", g.settings.hotkeys.fast_quit, RAGE_JOAAT("fastquit"));
|
2022-11-27 01:29:14 +08:00
|
|
|
|
2022-12-16 18:55:55 +01:00
|
|
|
g_renderer->add_wndproc_callback([this](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
wndproc(static_cast<eKeyState>(msg), wparam);
|
|
|
|
});
|
|
|
|
|
2022-11-27 01:29:14 +08:00
|
|
|
g_hotkey_service = this;
|
|
|
|
}
|
|
|
|
|
|
|
|
hotkey_service::~hotkey_service()
|
|
|
|
{
|
|
|
|
g_hotkey_service = nullptr;
|
|
|
|
}
|
|
|
|
|
2022-12-22 21:23:32 +00:00
|
|
|
void hotkey_service::register_hotkey(const std::string_view name, key_t key, rage::joaat_t command_hash, eKeyState state, std::optional<std::chrono::high_resolution_clock::duration> cooldown)
|
2022-11-27 01:29:14 +08:00
|
|
|
{
|
2022-12-22 21:23:32 +00:00
|
|
|
m_hotkeys[state == eKeyState::RELEASE].emplace(key, hotkey(rage::joaat(name), key, command_hash, cooldown));
|
2022-11-27 01:29:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hotkey_service::update_hotkey(const std::string_view name, const key_t key)
|
|
|
|
{
|
2022-11-26 22:12:21 +01:00
|
|
|
static auto update_hotkey_map = [](hotkey_map& hotkey_map, rage::joaat_t name_hash, key_t new_key) -> bool
|
2022-11-27 01:29:14 +08:00
|
|
|
{
|
2022-11-26 22:12:21 +01:00
|
|
|
for (auto it = hotkey_map.begin(); it != hotkey_map.end(); ++it)
|
2022-11-27 01:29:14 +08:00
|
|
|
{
|
|
|
|
auto hotkey = it->second;
|
2022-11-26 22:12:21 +01:00
|
|
|
if (hotkey.name_hash() != name_hash)
|
|
|
|
continue;
|
2022-11-27 01:29:14 +08:00
|
|
|
|
|
|
|
hotkey_map.erase(it);
|
2022-11-26 22:12:21 +01:00
|
|
|
hotkey.set_key(new_key);
|
|
|
|
hotkey_map.emplace(new_key, hotkey);
|
2022-11-27 01:29:14 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
const auto name_hash = rage::joaat(name);
|
2022-11-26 22:12:21 +01:00
|
|
|
return update_hotkey_map(m_hotkeys[1], name_hash, key) // released
|
|
|
|
&& update_hotkey_map(m_hotkeys[0], name_hash, key); // down
|
2022-11-27 01:29:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void hotkey_service::wndproc(eKeyState state, key_t key)
|
|
|
|
{
|
2022-11-29 20:48:58 +01:00
|
|
|
if (const auto chat_data = *g_pointers->m_chat_data; chat_data && (chat_data->m_chat_open || chat_data->m_timer_two))
|
|
|
|
return;
|
|
|
|
|
2023-01-22 21:57:32 +00:00
|
|
|
if (g_gui->is_open())
|
|
|
|
return;
|
|
|
|
|
2022-11-27 01:29:14 +08:00
|
|
|
if (state == eKeyState::RELEASE || state == eKeyState::DOWN)
|
|
|
|
{
|
|
|
|
auto &hotkey_map = m_hotkeys[state == eKeyState::RELEASE];
|
|
|
|
if (const auto &it = hotkey_map.find(key); it != hotkey_map.end())
|
|
|
|
{
|
|
|
|
if (auto &hotkey = it->second; hotkey.can_exec())
|
|
|
|
{
|
|
|
|
g_fiber_pool->queue_job([&hotkey]
|
|
|
|
{
|
|
|
|
hotkey.exec();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|