From 884ef8390ecd4b6526720d9e0db7cfd86e609557 Mon Sep 17 00:00:00 2001 From: Yimura Date: Mon, 8 Feb 2021 20:57:58 +0100 Subject: [PATCH] refactor(CustomText): Changed custom_text global to be static --- BigBaseV2/src/features/custom_text.cpp | 16 +++------------- BigBaseV2/src/features/custom_text.hpp | 18 +++++++----------- BigBaseV2/src/gui.cpp | 12 ++++++------ BigBaseV2/src/hooks/get_label_text.cpp | 2 +- BigBaseV2/src/main.cpp | 4 ---- 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/BigBaseV2/src/features/custom_text.cpp b/BigBaseV2/src/features/custom_text.cpp index 91e8b58a..763c2857 100644 --- a/BigBaseV2/src/features/custom_text.cpp +++ b/BigBaseV2/src/features/custom_text.cpp @@ -2,34 +2,24 @@ namespace big { - custom_text::custom_text() - { - g_custom_text = this; - } - - custom_text::~custom_text() - { - g_custom_text = nullptr; - } - void custom_text::add_text(Hash hash, const char* text) { auto size = strlen(text) + 1; auto buffer = std::make_unique(size); std::copy_n(text, size, buffer.get()); - this->m_text_map.emplace(hash, std::move(buffer)); + custom_text::m_text_map.emplace(hash, std::move(buffer)); } const char* custom_text::get_text(Hash hash) { - if (auto it = this->m_text_map.find(hash); it != m_text_map.end()) + if (auto it = custom_text::m_text_map.find(hash); it != custom_text::m_text_map.end()) return it->second.get(); return nullptr; } void custom_text::remove_text(Hash hash) { - this->m_text_map.erase(hash); + custom_text::m_text_map.erase(hash); } } \ No newline at end of file diff --git a/BigBaseV2/src/features/custom_text.hpp b/BigBaseV2/src/features/custom_text.hpp index 908ac26d..6a3a332b 100644 --- a/BigBaseV2/src/features/custom_text.hpp +++ b/BigBaseV2/src/features/custom_text.hpp @@ -4,17 +4,13 @@ namespace big { class custom_text { - public: - explicit custom_text(); - ~custom_text(); - - void add_text(Hash hash, const char* text); - const char* get_text(Hash hash); - void remove_text(Hash hash); - private: - std::unordered_map> m_text_map; - }; + inline static std::unordered_map> m_text_map; - inline custom_text* g_custom_text{}; + public: + static void add_text(Hash hash, const char* text); + static const char* get_text(Hash hash); + static void remove_text(Hash hash); + + }; } \ No newline at end of file diff --git a/BigBaseV2/src/gui.cpp b/BigBaseV2/src/gui.cpp index b2164d3f..30cdb266 100644 --- a/BigBaseV2/src/gui.cpp +++ b/BigBaseV2/src/gui.cpp @@ -126,14 +126,14 @@ namespace big void gui::script_init() { - g_custom_text->add_text(RAGE_JOAAT("LOADING_SPLAYER_L"), "Preparing for awesomeness."); - g_custom_text->add_text(RAGE_JOAAT("HUD_JOINING"), "Yim's Menu"); - g_custom_text->add_text(RAGE_JOAAT("HUD_TRANSP"), "Transaction's fucked..."); - g_custom_text->add_text(RAGE_JOAAT("HUD_QUITTING"), "Leaving are we?"); + custom_text::add_text(RAGE_JOAAT("LOADING_SPLAYER_L"), "Preparing for awesomeness."); + custom_text::add_text(RAGE_JOAAT("HUD_JOINING"), "Yim's Menu"); + custom_text::add_text(RAGE_JOAAT("HUD_TRANSP"), "Transaction's fucked..."); + custom_text::add_text(RAGE_JOAAT("HUD_QUITTING"), "Leaving are we?"); - g_custom_text->add_text(RAGE_JOAAT("HUD_QUITRACE"), "Are you a pussy?"); + custom_text::add_text(RAGE_JOAAT("HUD_QUITRACE"), "Are you a pussy?"); - g_custom_text->add_text(RAGE_JOAAT("HUD_SAVDNWARN"), "Rockstar crashed their toaster again..."); + custom_text::add_text(RAGE_JOAAT("HUD_SAVDNWARN"), "Rockstar crashed their toaster again..."); notify::above_map("Yim's Menu is ready."); } diff --git a/BigBaseV2/src/hooks/get_label_text.cpp b/BigBaseV2/src/hooks/get_label_text.cpp index 46655020..d1f1b6e2 100644 --- a/BigBaseV2/src/hooks/get_label_text.cpp +++ b/BigBaseV2/src/hooks/get_label_text.cpp @@ -7,7 +7,7 @@ namespace big const char* hooks::get_label_text(void* unk, const char* label) { if (g_running) - if (auto text = g_custom_text->get_text(rage::joaat(label))) + if (auto text = custom_text::get_text(rage::joaat(label))) return text; return g_hooking->m_get_label_text_hook.get_original()(unk, label); diff --git a/BigBaseV2/src/main.cpp b/BigBaseV2/src/main.cpp index fa571235..a049a24d 100644 --- a/BigBaseV2/src/main.cpp +++ b/BigBaseV2/src/main.cpp @@ -1,6 +1,5 @@ #include "common.hpp" #include "features.hpp" -#include "features/custom_text.hpp" #include "fiber_pool.hpp" #include "gui.hpp" #include "logger.hpp" @@ -46,9 +45,6 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) auto hooking_instance = std::make_unique(); LOG(INFO) << "Hooking initialized."; - auto custom_text_instance = std::make_unique(); - LOG(INFO) << "Custom Text Initialized."; - g_settings.load(); LOG(INFO) << "Settings Loaded.";