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

102 lines
2.6 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 <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
{
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] = (char)(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
2023-11-10 16:52:20 -05:00
return utilities::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.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
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
}
}
}
utilities::hook::detour sys_error_hook;
void sys_error_stub(uint32_t code, const char* message)
{
const char* error_message = runtime_errors::get_error_message(code);
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);
}
class component final : public component_interface
{
public:
void post_unpack() override
{
sys_error_hook.create(0x143D36CC0_g, sys_error_stub);
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)