From 400ba48fa65d81aea37459c5c6c6e38ef355e909 Mon Sep 17 00:00:00 2001 From: Yimura Date: Fri, 29 Jul 2022 14:32:02 +0200 Subject: [PATCH] Add custom text service (#370) --- BigBaseV2/src/hooking.cpp | 7 + BigBaseV2/src/hooking.hpp | 4 + BigBaseV2/src/hooks/misc/get_label_text.cpp | 13 + BigBaseV2/src/main.cpp | 242 +++++++++--------- BigBaseV2/src/pointers.cpp | 6 + BigBaseV2/src/pointers.hpp | 1 + .../custom_text/custom_text_callbacks.cpp | 12 + .../custom_text/custom_text_callbacks.hpp | 4 + .../custom_text/custom_text_service.cpp | 51 ++++ .../custom_text/custom_text_service.hpp | 33 +++ 10 files changed, 254 insertions(+), 119 deletions(-) create mode 100644 BigBaseV2/src/hooks/misc/get_label_text.cpp create mode 100644 BigBaseV2/src/services/custom_text/custom_text_callbacks.cpp create mode 100644 BigBaseV2/src/services/custom_text/custom_text_callbacks.hpp create mode 100644 BigBaseV2/src/services/custom_text/custom_text_service.cpp create mode 100644 BigBaseV2/src/services/custom_text/custom_text_service.hpp diff --git a/BigBaseV2/src/hooking.cpp b/BigBaseV2/src/hooking.cpp index 0f230884..37164daa 100644 --- a/BigBaseV2/src/hooking.cpp +++ b/BigBaseV2/src/hooking.cpp @@ -23,6 +23,9 @@ namespace big // Script Hook m_run_script_threads_hook("SH", g_pointers->m_run_script_threads, &hooks::run_script_threads), + // Get Label Text + m_get_label_text("GLT", g_pointers->m_get_label_text, &hooks::get_label_text), + // GTA Thead Start m_gta_thread_start_hook("GTS", g_pointers->m_gta_thread_start, &hooks::gta_thread_start), // GTA Thread Kill @@ -77,6 +80,8 @@ namespace big m_run_script_threads_hook.enable(); + m_get_label_text.enable(); + m_gta_thread_start_hook.enable(); m_gta_thread_kill_hook.enable(); @@ -124,6 +129,8 @@ namespace big m_gta_thread_kill_hook.disable(); m_gta_thread_start_hook.disable(); + m_get_label_text.disable(); + m_run_script_threads_hook.disable(); SetWindowLongPtrW(g_pointers->m_hwnd, GWLP_WNDPROC, reinterpret_cast(m_og_wndproc)); diff --git a/BigBaseV2/src/hooking.hpp b/BigBaseV2/src/hooking.hpp index c73cc914..d00833bb 100644 --- a/BigBaseV2/src/hooking.hpp +++ b/BigBaseV2/src/hooking.hpp @@ -21,6 +21,8 @@ namespace big static LRESULT wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam); + static const char* get_label_text(void* unk, const char* label); + static GtaThread* gta_thread_start(unsigned int** a1, unsigned int a2); static rage::eThreadState gta_thread_kill(GtaThread* thread); @@ -83,6 +85,8 @@ namespace big detour_hook m_run_script_threads_hook; + detour_hook m_get_label_text; + detour_hook m_gta_thread_start_hook; detour_hook m_gta_thread_kill_hook; diff --git a/BigBaseV2/src/hooks/misc/get_label_text.cpp b/BigBaseV2/src/hooks/misc/get_label_text.cpp new file mode 100644 index 00000000..43373879 --- /dev/null +++ b/BigBaseV2/src/hooks/misc/get_label_text.cpp @@ -0,0 +1,13 @@ +#include "hooking.hpp" +#include "services/custom_text/custom_text_service.hpp" + +namespace big +{ + const char* hooks::get_label_text(void* unk, const char* label) + { + if (const auto text = g_custom_text_service->get_text(label); text) + return text; + + return g_hooking->m_get_label_text.get_original()(unk, label); + } +} diff --git a/BigBaseV2/src/main.cpp b/BigBaseV2/src/main.cpp index f1484e2b..3bf85578 100644 --- a/BigBaseV2/src/main.cpp +++ b/BigBaseV2/src/main.cpp @@ -12,6 +12,7 @@ #include "backend/backend.hpp" #include "native_hooks/native_hooks.hpp" #include "services/context_menu/context_menu_service.hpp" +#include "services/custom_text/custom_text_service.hpp" #include "services/globals/globals_service.hpp" #include "services/gui/gui_service.hpp" #include "services/gta_data/gta_data_service.hpp" @@ -31,151 +32,154 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) g_hmodule = hmod; g_main_thread = CreateThread(nullptr, 0, [](PVOID) -> DWORD + { + while (!FindWindow(L"grcWindow", L"Grand Theft Auto V")) + std::this_thread::sleep_for(1s); + + std::filesystem::path base_dir = std::getenv("appdata"); + base_dir /= "BigBaseV2"; + auto file_manager_instance = std::make_unique(base_dir); + + auto globals_instance = std::make_unique( + file_manager_instance->get_project_file("./settings.json") + ); + + auto logger_instance = std::make_unique( + "YimMenu", + file_manager_instance->get_project_file("./cout.log") + ); + + EnableMenuItem(GetSystemMenu(FindWindowA(NULL, "YimMenu"), 0), SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); + + try { - while (!FindWindow(L"grcWindow", L"Grand Theft Auto V")) - std::this_thread::sleep_for(1s); + LOG(INFO) << "Yim's Menu Initializing"; + auto pointers_instance = std::make_unique(); + LOG(INFO) << "Pointers initialized."; - std::filesystem::path base_dir = std::getenv("appdata"); - base_dir /= "BigBaseV2"; - auto file_manager_instance = std::make_unique(base_dir); + auto renderer_instance = std::make_unique(); + LOG(INFO) << "Renderer initialized."; - auto globals_instance = std::make_unique( - file_manager_instance->get_project_file("./settings.json") - ); + auto fiber_pool_instance = std::make_unique(11); + LOG(INFO) << "Fiber pool initialized."; - auto logger_instance = std::make_unique( - "YimMenu", - file_manager_instance->get_project_file("./cout.log") - ); + auto hooking_instance = std::make_unique(); + LOG(INFO) << "Hooking initialized."; - EnableMenuItem(GetSystemMenu(FindWindowA(NULL, "YimMenu"), 0), SC_CLOSE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); + g->load(); + LOG(INFO) << "Settings Loaded."; - try - { - LOG(INFO) << "Yim's Menu Initializing"; - auto pointers_instance = std::make_unique(); - LOG(INFO) << "Pointers initialized."; + auto thread_pool_instance = std::make_unique(); + LOG(INFO) << "Thread pool initialized."; - auto renderer_instance = std::make_unique(); - LOG(INFO) << "Renderer initialized."; + auto context_menu_service_instance = std::make_unique(); + auto custom_text_service_instance = std::make_unique(); + auto globals_service_instace = std::make_unique(); + auto mobile_service_instance = std::make_unique(); + auto notification_service_instance = std::make_unique(); + auto pickup_service_instance = std::make_unique(); + auto player_service_instance = std::make_unique(); + auto gta_data_service_instance = std::make_unique(); + auto vehicle_preview_service_instance = std::make_unique(); + auto vehicle_service_instance = std::make_unique(); + auto gui_service_instance = std::make_unique(); + LOG(INFO) << "Registered service instances..."; - auto fiber_pool_instance = std::make_unique(11); - LOG(INFO) << "Fiber pool initialized."; + g_script_mgr.add_script(std::make_unique