Cleanup menus
This commit is contained in:
parent
1b8dbc535f
commit
1c5a01bcf7
@ -13,66 +13,21 @@
|
|||||||
|
|
||||||
namespace menus
|
namespace menus
|
||||||
{
|
{
|
||||||
void* ui_info_array;
|
namespace
|
||||||
|
{
|
||||||
std::string script_main_menu;
|
std::string script_main_menu;
|
||||||
|
|
||||||
bool UI_AllowScriptMenuResponse()
|
bool keys_bypass_menu()
|
||||||
{
|
{
|
||||||
return *reinterpret_cast<bool*>(0x3532A7C_b);
|
const auto* cl_bypass_mouse_input = game::Dvar_FindVar("cl_bypassMouseInput");
|
||||||
}
|
if (cl_bypass_mouse_input && cl_bypass_mouse_input->current.enabled)
|
||||||
|
|
||||||
bool UI_Started()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<bool*>(0x2ED2074_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool UI_KeysBypassMenu()
|
|
||||||
{
|
|
||||||
game::dvar_t* cl_bypassMouseInput = game::Dvar_FindVar("cl_bypassMouseInput");
|
|
||||||
if (cl_bypassMouseInput && cl_bypassMouseInput->current.enabled)
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int UI_SetActiveMenu(int local_client_num, int menu)
|
|
||||||
{
|
|
||||||
return utils::hook::invoke<int>(0x1E4D80_b, local_client_num, menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CL_ShowSystemCursor(int a1)
|
|
||||||
{
|
|
||||||
return utils::hook::invoke<void>(0x5BAA60_b, a1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CL_GetCursorPos(tagPOINT* position)
|
|
||||||
{
|
|
||||||
return utils::hook::invoke<void>(0x5BA800_b, position);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Menu_Count()
|
|
||||||
{
|
|
||||||
return *reinterpret_cast<int*>(0x352F9B8_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void* Menus_FindByName(void* dc, const char* name)
|
|
||||||
{
|
|
||||||
return utils::hook::invoke<void*>(0x1AC810_b, dc, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Menus_Open(void* dc, void* menu, int a3)
|
|
||||||
{
|
|
||||||
return utils::hook::invoke<void>(0x1E1296_b, dc, menu, a3);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Display_MouseMove(void* dc)
|
|
||||||
{
|
|
||||||
return utils::hook::invoke<void>(0x180B70_b, dc);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
game::XAssetHeader load_script_menu_internal(const char* menu)
|
game::XAssetHeader load_script_menu_internal(const char* menu)
|
||||||
{
|
{
|
||||||
const char* menu_file = utils::string::va("ui_mp/scriptmenus/%s.menu", menu);
|
const char* menu_file = utils::string::va("ui_mp/scriptmenus/%s.menu", menu);
|
||||||
@ -82,15 +37,16 @@ namespace menus
|
|||||||
bool load_script_menu(int client_num, const char* menu)
|
bool load_script_menu(int client_num, const char* menu)
|
||||||
{
|
{
|
||||||
game::XAssetHeader asset = load_script_menu_internal(menu);
|
game::XAssetHeader asset = load_script_menu_internal(menu);
|
||||||
if (asset.data)
|
if (asset.data != nullptr)
|
||||||
{
|
{
|
||||||
game::UI_AddMenuList(ui_info_array, asset.data, 1);
|
game::UI_AddMenuList(game::ui_info_array, asset.data, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cg_precache_script_menu(int client_num, int config_string_index)
|
void precache_script_menu(int client_num, int config_string_index)
|
||||||
{
|
{
|
||||||
const char* menu = game::CL_GetConfigString(config_string_index);
|
const char* menu = game::CL_GetConfigString(config_string_index);
|
||||||
if (menu)
|
if (menu)
|
||||||
@ -110,49 +66,52 @@ namespace menus
|
|||||||
auto nesting = game::R_PopRemoteScreenUpdate();
|
auto nesting = game::R_PopRemoteScreenUpdate();
|
||||||
for (auto i = 3432; i < (3432 + 50); i++)
|
for (auto i = 3432; i < (3432 + 50); i++)
|
||||||
{
|
{
|
||||||
cg_precache_script_menu(client_num, i);
|
precache_script_menu(client_num, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
game::R_PushRemoteScreenUpdate(nesting);
|
game::R_PushRemoteScreenUpdate(nesting);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_mouse_event(int client_num, int x, int y)
|
void ui_mouse_event(int client_num, int x, int y)
|
||||||
{
|
{
|
||||||
auto scrPlaceFull = game::ScrPlace_GetViewPlacement();
|
const auto scr_place = game::ScrPlace_GetViewPlacement();
|
||||||
auto vX = x / (game::ScrPlace_HiResGetScaleX() * scrPlaceFull->scaleVirtualToFull[0]);
|
|
||||||
auto vY = y / (game::ScrPlace_HiResGetScaleY() * scrPlaceFull->scaleVirtualToFull[1]);
|
|
||||||
*reinterpret_cast<float*>(0x352E590_b) = vX; // cursorX
|
|
||||||
*reinterpret_cast<float*>(0x352E594_b) = vY; // cursorY
|
|
||||||
auto isCursorVisible = vX >= 0.0 && vX <= 640.0 && vY >= 0.0 && vY <= 480.0;
|
|
||||||
|
|
||||||
if (isCursorVisible)
|
const auto v_x = x / (game::ScrPlace_HiResGetScaleX() * scr_place->scaleVirtualToFull[0]);
|
||||||
|
const auto v_y = y / (game::ScrPlace_HiResGetScaleY() * scr_place->scaleVirtualToFull[1]);
|
||||||
|
|
||||||
|
game::ui_info_array->cursor_x = v_x;
|
||||||
|
game::ui_info_array->cursor_x = v_y;
|
||||||
|
|
||||||
|
const auto cursor_visible = v_x >= 0.0 && v_x <= 640.0 && v_y >= 0.0 && v_y <= 480.0;
|
||||||
|
if (!cursor_visible)
|
||||||
{
|
{
|
||||||
auto menu_count = Menu_Count();
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto menu_count = *reinterpret_cast<int*>(0x352F9B8_b);
|
||||||
if (menu_count > 0)
|
if (menu_count > 0)
|
||||||
{
|
{
|
||||||
*reinterpret_cast<float*>(reinterpret_cast<std::uintptr_t>(ui_info_array) + 16) = vX; // cursor X
|
game::ui_info_array->cursor_x = v_x;
|
||||||
*reinterpret_cast<float*>(reinterpret_cast<std::uintptr_t>(ui_info_array) + 20) = vY; // cursor Y
|
game::ui_info_array->cursor_y = v_y;
|
||||||
|
game::ui_info_array->cursor_time = game::Sys_Milliseconds() + 200;
|
||||||
*reinterpret_cast<int*>(reinterpret_cast<std::uintptr_t>(ui_info_array) + 24) = game::Sys_Milliseconds() + 200; // cursor time until ready to move
|
game::ui_info_array->ingame_cursor_visible = cursor_visible;
|
||||||
|
game::Display_MouseMove(game::ui_info_array);
|
||||||
*reinterpret_cast<int*>(reinterpret_cast<std::uintptr_t>(ui_info_array) + 28) = isCursorVisible; // ingame cursor visible
|
|
||||||
|
|
||||||
Display_MouseMove(ui_info_array);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int ui_mouse_fix(int cx_, int cy_, int dx_, int dy_)
|
int ui_mouse_fix(int cx_, int cy_, int dx_, int dy_)
|
||||||
{
|
{
|
||||||
if ((*game::keyCatchers & 0x10) != 0 && !UI_KeysBypassMenu())
|
if ((*game::keyCatchers & 0x10) != 0 && !keys_bypass_menu())
|
||||||
{
|
{
|
||||||
tagPOINT cursor;
|
tagPOINT cursor{};
|
||||||
|
|
||||||
CL_ShowSystemCursor(0);
|
game::CL_ShowSystemCursor(0);
|
||||||
CL_GetCursorPos(&cursor);
|
game::CL_GetCursorPos(&cursor);
|
||||||
|
|
||||||
ui_mouse_event(0, cursor.x, cursor.y);
|
ui_mouse_event(0, cursor.x, cursor.y);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return utils::hook::invoke<int>(0x1384C0_b, cx_, cy_, dx_, dy_);
|
return utils::hook::invoke<int>(0x1384C0_b, cx_, cy_, dx_, dy_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,13 +119,14 @@ namespace menus
|
|||||||
{
|
{
|
||||||
if (!script_main_menu.empty())
|
if (!script_main_menu.empty())
|
||||||
{
|
{
|
||||||
void* menu = Menus_FindByName(ui_info_array, script_main_menu.data());
|
void* menu = game::Menus_FindByName(game::ui_info_array, script_main_menu.data());
|
||||||
if (menu)
|
if (menu)
|
||||||
{
|
{
|
||||||
Menus_Open(ui_info_array, menu, 0);
|
game::Menus_Open(game::ui_info_array, menu, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,7 +138,7 @@ namespace menus
|
|||||||
{
|
{
|
||||||
if (game::Menu_IsMenuOpenAndVisible(0, script_main_menu.data()))
|
if (game::Menu_IsMenuOpenAndVisible(0, script_main_menu.data()))
|
||||||
{
|
{
|
||||||
UI_SetActiveMenu(0, 0);
|
game::UI_SetActiveMenu(0, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (open_script_main_menu())
|
else if (open_script_main_menu())
|
||||||
@ -188,7 +148,9 @@ namespace menus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return utils::hook::invoke<void>(0x270A90_b, controller_index, context); // LUI_ToggleMenu
|
|
||||||
|
// LUI_ToggleMenu
|
||||||
|
return utils::hook::invoke<void>(0x270A90_b, controller_index, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +169,6 @@ namespace menus
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_info_array = reinterpret_cast<void*>(0x352E580_b);
|
|
||||||
|
|
||||||
// add back legacy menu precache
|
// add back legacy menu precache
|
||||||
cg_set_config_values_hook.create(0x11AC50_b, cg_set_config_values_stub);
|
cg_set_config_values_hook.create(0x11AC50_b, cg_set_config_values_stub);
|
||||||
|
|
||||||
|
@ -1590,6 +1590,15 @@ namespace game
|
|||||||
|
|
||||||
static_assert(sizeof(mapInfo) == 4648);
|
static_assert(sizeof(mapInfo) == 4648);
|
||||||
|
|
||||||
|
struct ui_info
|
||||||
|
{
|
||||||
|
char __pad0[16];
|
||||||
|
float cursor_x;
|
||||||
|
float cursor_y;
|
||||||
|
int cursor_time;
|
||||||
|
int ingame_cursor_visible;
|
||||||
|
};
|
||||||
|
|
||||||
namespace mp
|
namespace mp
|
||||||
{
|
{
|
||||||
struct cachedSnapshot_t
|
struct cachedSnapshot_t
|
||||||
|
@ -62,6 +62,9 @@ namespace game
|
|||||||
WEAK symbol<void(int a1)> CL_VirtualLobbyShutdown{0x0, 0x0};
|
WEAK symbol<void(int a1)> CL_VirtualLobbyShutdown{0x0, 0x0};
|
||||||
WEAK symbol<const char* (int configStringIndex)> CL_GetConfigString{0x0, 0x33B820};
|
WEAK symbol<const char* (int configStringIndex)> CL_GetConfigString{0x0, 0x33B820};
|
||||||
|
|
||||||
|
WEAK symbol<void(int a1)> CL_ShowSystemCursor{0x0, 0x5BAA60};
|
||||||
|
WEAK symbol<void(tagPOINT* position)> CL_GetCursorPos{0x0, 0x5BA800};
|
||||||
|
|
||||||
WEAK symbol<void(int hash, const char* name, const char* buffer)> Dvar_SetCommand{0x41BAD0, 0x1857D0};
|
WEAK symbol<void(int hash, const char* name, const char* buffer)> Dvar_SetCommand{0x41BAD0, 0x1857D0};
|
||||||
WEAK symbol<dvar_t*(const char* name)> Dvar_FindVar{0x41A600, 0x183EB0};
|
WEAK symbol<dvar_t*(const char* name)> Dvar_FindVar{0x41A600, 0x183EB0};
|
||||||
WEAK symbol<dvar_t*(int hash)> Dvar_FindMalleableVar{0x41A570, 0x183E20};
|
WEAK symbol<dvar_t*(int hash)> Dvar_FindMalleableVar{0x41A570, 0x183E20};
|
||||||
@ -210,6 +213,9 @@ namespace game
|
|||||||
WEAK symbol<bool(int clientNum, const char* menu)> Menu_IsMenuOpenAndVisible{0x4F43C0, 0x1AAF10};
|
WEAK symbol<bool(int clientNum, const char* menu)> Menu_IsMenuOpenAndVisible{0x4F43C0, 0x1AAF10};
|
||||||
WEAK symbol<void(int clientNum, const char* menu)> Menus_OpenByName{0x0, 0x1E1270};
|
WEAK symbol<void(int clientNum, const char* menu)> Menus_OpenByName{0x0, 0x1E1270};
|
||||||
WEAK symbol<void(int clientNum, const char* menu)> Menus_CloseByName{0x0, 0x1DA4C0};
|
WEAK symbol<void(int clientNum, const char* menu)> Menus_CloseByName{0x0, 0x1DA4C0};
|
||||||
|
WEAK symbol<void*(void* dc, const char* name)> Menus_FindByName{0x0, 0x1AC810};
|
||||||
|
WEAK symbol<void(void* dc, void* menu, int a3)> Menus_Open{0x0, 0x1E1296};
|
||||||
|
WEAK symbol<void(void* dc)> Display_MouseMove{0x0, 0x180B70};
|
||||||
|
|
||||||
WEAK symbol<scr_string_t(const char* str)> SL_FindString{0x3C0F50, 0x507FD0};
|
WEAK symbol<scr_string_t(const char* str)> SL_FindString{0x3C0F50, 0x507FD0};
|
||||||
WEAK symbol<scr_string_t(const char* str, unsigned int user)> SL_GetString{0x3C1210, 0x5083A0};
|
WEAK symbol<scr_string_t(const char* str, unsigned int user)> SL_GetString{0x3C1210, 0x5083A0};
|
||||||
@ -259,6 +265,8 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<const char*(const char* string)> UI_SafeTranslateString{0x3840A0, 0x4E8BC0};
|
WEAK symbol<const char*(const char* string)> UI_SafeTranslateString{0x3840A0, 0x4E8BC0};
|
||||||
|
|
||||||
|
WEAK symbol<int(int local_client_num, int menu)> UI_SetActiveMenu{0x0, 0x1E4D80};
|
||||||
|
|
||||||
WEAK symbol<void*(jmp_buf* Buf, int Value)> longjmp{0x6DCA90, 0x826710};
|
WEAK symbol<void*(jmp_buf* Buf, int Value)> longjmp{0x6DCA90, 0x826710};
|
||||||
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x758980, 0x8A3190};
|
WEAK symbol<int(jmp_buf* Buf)> _setjmp{0x758980, 0x8A3190};
|
||||||
|
|
||||||
@ -309,6 +317,7 @@ namespace game
|
|||||||
WEAK symbol<int> ui_num_arenas{0x0, 0xAA55AD8};
|
WEAK symbol<int> ui_num_arenas{0x0, 0xAA55AD8};
|
||||||
WEAK symbol<int> ui_arena_buf_pos{0x0, 0xAA55ADC};
|
WEAK symbol<int> ui_arena_buf_pos{0x0, 0xAA55ADC};
|
||||||
WEAK symbol<char*> ui_arena_infos{0x0, 0xAA55AE0};
|
WEAK symbol<char*> ui_arena_infos{0x0, 0xAA55AE0};
|
||||||
|
WEAK symbol<ui_info> ui_info_array{0x0, 0x352E580};
|
||||||
|
|
||||||
WEAK symbol<int> level_time{0x56DBAA0, 0x7361F9C};
|
WEAK symbol<int> level_time{0x56DBAA0, 0x7361F9C};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user