Skip to content

Commit

Permalink
Added c_debug_menu_value_hs_global_external
Browse files Browse the repository at this point in the history
  • Loading branch information
theTwister authored and theTwister committed Sep 14, 2023
1 parent bf6c703 commit 813aa4f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
36 changes: 36 additions & 0 deletions game/source/interface/debug_menu/debug_menu_item_numbered.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,39 @@ bool c_debug_menu_item_type::get_readonly()
return m_readonly;
}

template<typename t_type>
inline c_debug_menu_value_hs_global_external<t_type>::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<typename t_type>
inline t_type c_debug_menu_value_hs_global_external<t_type>::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<t_type*>(bytes) = *static_cast<t_type*>(k_console_globals[m_hs_global_external_index]->pointer);
}

return *reinterpret_cast<t_type*>(bytes);
}

11 changes: 11 additions & 0 deletions game/source/interface/debug_menu/debug_menu_item_numbered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ struct c_debug_menu_item_type :
bool m_readonly;
};

template<typename t_type>
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;
};

0 comments on commit 813aa4f

Please sign in to comment.