From 813aa4f1df6e4e50ad49d3ddae0d00d04462b465 Mon Sep 17 00:00:00 2001 From: theTwister Date: Thu, 14 Sep 2023 22:59:12 +0100 Subject: [PATCH] Added `c_debug_menu_value_hs_global_external` --- .../debug_menu/debug_menu_item_numbered.cpp | 36 +++++++++++++++++++ .../debug_menu/debug_menu_item_numbered.hpp | 11 ++++++ 2 files changed, 47 insertions(+) diff --git a/game/source/interface/debug_menu/debug_menu_item_numbered.cpp b/game/source/interface/debug_menu/debug_menu_item_numbered.cpp index 0be881017..3e688a9e4 100644 --- a/game/source/interface/debug_menu/debug_menu_item_numbered.cpp +++ b/game/source/interface/debug_menu/debug_menu_item_numbered.cpp @@ -90,3 +90,39 @@ bool c_debug_menu_item_type::get_readonly() return m_readonly; } +template +inline c_debug_menu_value_hs_global_external::c_debug_menu_value_hs_global_external(char const* hs_global_name) +{ + ASSERT(hs_global_name); + + m_hs_global_external_index = NONE; + for (short hs_global_external_index = 0; hs_global_external_index < k_console_global_count && m_hs_global_external_index == NONE; hs_global_external_index++) + { + if (csstricmp(hs_global_name, k_console_globals[hs_global_external_index]->name)) + continue; + + if (!k_console_globals[hs_global_external_index]->pointer) + continue; + + e_hs_type type = k_console_globals[hs_global_external_index]->type; + if (IN_RANGE_INCLUSIVE(type, _hs_type_boolean, _hs_type_long_integer)) + m_hs_global_external_index = hs_global_external_index; + } +} + +template +inline t_type c_debug_menu_value_hs_global_external::get() +{ + byte bytes[sizeof(t_type)]; + csmemset(bytes, 0, sizeof(t_type)); + + if (m_hs_global_external_index != NONE) + { + ASSERT(k_console_globals[m_hs_global_external_index]->pointer != NULL); + + *reinterpret_cast(bytes) = *static_cast(k_console_globals[m_hs_global_external_index]->pointer); + } + + return *reinterpret_cast(bytes); +} + diff --git a/game/source/interface/debug_menu/debug_menu_item_numbered.hpp b/game/source/interface/debug_menu/debug_menu_item_numbered.hpp index 27242e442..69a6cbf27 100644 --- a/game/source/interface/debug_menu/debug_menu_item_numbered.hpp +++ b/game/source/interface/debug_menu/debug_menu_item_numbered.hpp @@ -35,3 +35,14 @@ struct c_debug_menu_item_type : bool m_readonly; }; +template +class c_debug_menu_value_hs_global_external +{ +public: + c_debug_menu_value_hs_global_external(char const* hs_global_name); + t_type get(); + +protected: + short m_hs_global_external_index; +}; +