t8-mod/source/proxy-dll/component/debugging.cpp

82 lines
2.0 KiB
C++
Raw Normal View History

2023-03-06 15:40:07 -05:00
#include <std_include.hpp>
#include "definitions/game.hpp"
#include "component/scheduler.hpp"
2023-03-06 15:40:07 -05:00
#include "loader/component_loader.hpp"
#include <utils/string.hpp>
2023-03-06 15:40:07 -05:00
namespace debugging
{
namespace
{
const char* get_connectivity_info_string(int infoBitmask)
2023-03-06 15:40:07 -05:00
{
char connectionInfoString[64];
2023-03-06 15:40:07 -05:00
for (int bitNumber = 0; bitNumber < 21; bitNumber++)
2023-03-06 15:40:07 -05:00
{
if ((1 << bitNumber) & infoBitmask)
{
connectionInfoString[bitNumber * 2] = bitNumber + 0x41;
}
2023-03-06 15:40:07 -05:00
else
{
connectionInfoString[bitNumber * 2] = 0x2D;
}
2023-03-06 15:40:07 -05:00
connectionInfoString[(bitNumber * 2) + 1] = 0x2E;
2023-03-06 15:40:07 -05:00
}
connectionInfoString[42] = NULL;
2023-03-06 15:40:07 -05:00
return utils::string::va("%s", connectionInfoString);
}
2023-03-06 15:40:07 -05:00
void draw_debug_info()
{
int infoBitmask = 0; int requiredMask = 0x1337FA;
game::Live_GetConnectivityInformation(0, &infoBitmask);
bool connected = (requiredMask & infoBitmask) == requiredMask;
void* font = reinterpret_cast<void*>(game::sharedUiInfo->assets.bigFont); if (!font) return;
2023-03-06 15:40:07 -05:00
if (!connected)
{
float color[4] = { 0.8f, 1.0f, 0.3, 0.8f };
2023-03-06 15:40:07 -05:00
2023-09-06 08:32:21 -04:00
const char* sz = get_connectivity_info_string(infoBitmask);
2023-03-06 15:40:07 -05:00
game::ScreenPlacement* scrPlace = game::ScrPlace_GetView(0);
2023-03-06 15:40:07 -05:00
float offset_x = scrPlace->realViewportSize[0] - 8.0f
- game::UI_TextWidth(0, sz, 0x7FFFFFFF, font, 0.45f);
float offset_y = scrPlace->realViewportSize[1] - 8.0f;
2023-03-06 15:40:07 -05:00
game::R_AddCmdDrawText(sz, 0x7FFFFFFF, font, offset_x, offset_y, 0.45f, 0.45f, 0.0f, color, game::ITEM_TEXTSTYLE_BORDERED);
}
2023-03-06 15:40:07 -05:00
}
void test_key_catcher()
{
static uint32_t last_press_time = 0;
if ((GetAsyncKeyState(VK_HOME) & 0x01)/* && (static_cast<uint32_t>(time(nullptr)) - last_press_time) > 1*/)
{
last_press_time = static_cast<uint32_t>(time(nullptr));
/* ACTION_PLACE_HOLDER */
2023-03-06 15:40:07 -05:00
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
scheduler::loop(draw_debug_info, scheduler::renderer);
scheduler::loop(test_key_catcher, scheduler::main);
}
};
2023-03-06 15:40:07 -05:00
}
REGISTER_COMPONENT(debugging::component)