2023-03-06 15:40:07 -05:00
|
|
|
#include <std_include.hpp>
|
2023-09-06 08:08:38 -04:00
|
|
|
#include "definitions/game.hpp"
|
|
|
|
#include "component/scheduler.hpp"
|
2023-03-06 15:40:07 -05:00
|
|
|
#include "loader/component_loader.hpp"
|
|
|
|
|
2024-01-09 09:26:31 -05:00
|
|
|
#include <utilities/hook.hpp>
|
2023-11-10 16:52:20 -05:00
|
|
|
#include <utilities/string.hpp>
|
2023-03-06 15:40:07 -05:00
|
|
|
|
|
|
|
namespace debugging
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2023-09-06 08:08:38 -04:00
|
|
|
const char* get_connectivity_info_string(int infoBitmask)
|
2023-03-06 15:40:07 -05:00
|
|
|
{
|
2023-09-06 08:08:38 -04:00
|
|
|
char connectionInfoString[64];
|
2023-03-06 15:40:07 -05:00
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
for (int bitNumber = 0; bitNumber < 21; bitNumber++)
|
2023-03-06 15:40:07 -05:00
|
|
|
{
|
2023-09-06 08:08:38 -04:00
|
|
|
if ((1 << bitNumber) & infoBitmask)
|
|
|
|
{
|
2024-01-09 09:26:31 -05:00
|
|
|
connectionInfoString[bitNumber * 2] = (char)(bitNumber + 0x41);
|
2023-09-06 08:08:38 -04:00
|
|
|
}
|
2023-03-06 15:40:07 -05:00
|
|
|
else
|
2023-09-06 08:08:38 -04:00
|
|
|
{
|
|
|
|
connectionInfoString[bitNumber * 2] = 0x2D;
|
|
|
|
}
|
2023-03-06 15:40:07 -05:00
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
connectionInfoString[(bitNumber * 2) + 1] = 0x2E;
|
2023-03-06 15:40:07 -05:00
|
|
|
}
|
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
connectionInfoString[42] = NULL;
|
2023-03-06 15:40:07 -05:00
|
|
|
|
2023-11-10 16:52:20 -05:00
|
|
|
return utilities::string::va("%s", connectionInfoString);
|
2023-09-06 08:08:38 -04:00
|
|
|
}
|
|
|
|
|
2023-03-06 15:40:07 -05:00
|
|
|
void draw_debug_info()
|
|
|
|
{
|
2023-09-06 08:08:38 -04:00
|
|
|
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
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
if (!connected)
|
|
|
|
{
|
2024-01-09 09:26:31 -05:00
|
|
|
float color[4] = { 0.8f, 1.0f, 0.3f, 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
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
game::ScreenPlacement* scrPlace = game::ScrPlace_GetView(0);
|
2023-03-06 15:40:07 -05:00
|
|
|
|
2023-09-06 08:08:38 -04: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
|
|
|
|
2023-09-06 08:08:38 -04: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));
|
2023-09-06 08:08:38 -04:00
|
|
|
|
|
|
|
/* ACTION_PLACE_HOLDER */
|
2023-03-06 15:40:07 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 09:26:31 -05:00
|
|
|
utilities::hook::detour sys_error_hook;
|
|
|
|
|
|
|
|
void sys_error_stub(uint32_t code, const char* message)
|
|
|
|
{
|
2024-05-31 18:35:20 -04:00
|
|
|
const char* error_message = runtime_errors::get_error_message(code);
|
2024-01-09 09:26:31 -05:00
|
|
|
|
|
|
|
if (error_message)
|
|
|
|
{
|
|
|
|
logger::write(logger::LOG_TYPE_ERROR, "[sys_error] %s (%d): %s", error_message, code, message);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logger::write(logger::LOG_TYPE_ERROR, "[sys_error] %d: %s", code, message);
|
|
|
|
}
|
|
|
|
|
|
|
|
sys_error_hook.invoke<void>(code, message);
|
|
|
|
}
|
|
|
|
|
2023-09-06 08:08:38 -04:00
|
|
|
class component final : public component_interface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void post_unpack() override
|
|
|
|
{
|
2024-01-09 09:26:31 -05:00
|
|
|
sys_error_hook.create(0x143D36CC0_g, sys_error_stub);
|
2023-09-06 08:08:38 -04:00
|
|
|
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)
|