h1-mod/src/client/component/lui.cpp

131 lines
3.1 KiB
C++
Raw Normal View History

2022-02-11 22:21:53 -05:00
#include <std_include.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include "command.hpp"
#include "console.hpp"
2022-06-26 15:28:07 -04:00
#include "scheduler.hpp"
2022-02-11 22:21:53 -05:00
#include <utils/hook.hpp>
namespace lui
{
2022-06-26 15:28:07 -04:00
namespace
{
uint64_t event_count{};
2022-07-07 20:18:13 -04:00
uint64_t obituary_count{};
2022-06-26 15:28:07 -04:00
bool begin_game_message_event_stub(int a1, const char* name, void* a3)
{
if (event_count > 30)
{
return false;
}
else
{
event_count++;
}
return utils::hook::invoke<bool>(0x2655A0_b, a1, name, a3);
}
2022-07-07 20:18:13 -04:00
void cg_entity_event_stub(void* a1, void* a2, unsigned int event_type, void* a4)
{
if (event_type == 140 && obituary_count++ >= 20)
{
return;
}
utils::hook::invoke<void>(0xF9400_b, a1, a2, event_type, a4);
}
2022-06-26 15:28:07 -04:00
}
2022-02-11 22:21:53 -05:00
class component final : public component_interface
{
public:
void post_unpack() override
{
2022-06-26 15:28:07 -04:00
if (game::environment::is_mp())
{
// Patch game message overflow
utils::hook::call(0x266E6B_b, begin_game_message_event_stub);
2022-07-07 20:18:13 -04:00
utils::hook::call(0xEAC1C_b, cg_entity_event_stub);
2022-06-26 15:28:07 -04:00
scheduler::loop([]()
{
if (event_count > 0)
{
event_count--;
}
}, scheduler::pipeline::lui, 50ms);
2022-07-07 20:18:13 -04:00
scheduler::loop([]()
{
obituary_count = 0;
}, scheduler::pipeline::lui, 0ms);
2022-06-26 15:28:07 -04:00
}
// Increase max extra LUI memory
/*const auto max_memory = 0x900000 * 2;
utils::hook::set<uint32_t>(0x278E61_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27A2C5_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27A993_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27AB3A_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27AB35_b - 4, max_memory);
utils::hook::set<uint32_t>(0x27C002_b - 4, max_memory);*/
// Increase max extra frontend memory
/*const auto max_frontend_memory = 0x180000 * 2;
utils::hook::set<uint32_t>(0x278EA6_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x278F01_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27A2D4_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27A2E3_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27F9E9_b - 4, max_frontend_memory);
utils::hook::set<uint32_t>(0x27FA84_b - 4, max_frontend_memory);*/
2022-02-11 22:21:53 -05:00
command::add("lui_open", [](const command::params& params)
2022-02-23 15:23:00 -05:00
{
if (params.size() <= 1)
2022-02-11 22:21:53 -05:00
{
2022-02-23 15:23:00 -05:00
console::info("usage: lui_open <name>\n");
return;
}
2022-02-11 22:21:53 -05:00
2022-02-23 15:23:00 -05:00
game::LUI_OpenMenu(0, params[1], 0, 0, 0);
});
2022-02-11 22:21:53 -05:00
2022-09-12 16:41:54 -04:00
command::add("lui_close", [](const command::params& params)
{
if (params.size() <= 1)
{
console::info("usage: lui_close <name>\n");
return;
}
game::LUI_LeaveMenuByName(0, params[1], 0, *game::hks::lua_state);
});
2022-02-11 22:21:53 -05:00
command::add("lui_open_popup", [](const command::params& params)
2022-02-23 15:23:00 -05:00
{
if (params.size() <= 1)
2022-02-11 22:21:53 -05:00
{
2022-02-23 15:23:00 -05:00
console::info("usage: lui_open_popup <name>\n");
return;
}
2022-02-11 22:21:53 -05:00
2022-02-23 15:23:00 -05:00
game::LUI_OpenMenu(0, params[1], 1, 0, 0);
});
2022-02-11 22:21:53 -05:00
command::add("runMenuScript", [](const command::params& params)
2022-02-23 15:23:00 -05:00
{
const auto args_str = params.join(1);
const auto* args = args_str.data();
game::UI_RunMenuScript(0, &args);
});
2022-02-11 22:21:53 -05:00
}
};
}
2022-05-19 18:06:09 -04:00
REGISTER_COMPONENT(lui::component)