Log system adjustments.

This commit is contained in:
IcePixelx 2021-10-20 18:49:48 +02:00
parent 7f86722116
commit ab12789faf
5 changed files with 45 additions and 41 deletions

View File

@ -1,8 +1,6 @@
#pragma once #pragma once
#define LOGSYSTEM_LINES_TO_SHOW 3 enum class LogType_t : int
enum LogType_t
{ {
SCRIPT_SERVER, SCRIPT_SERVER,
SCRIPT_CLIENT, SCRIPT_CLIENT,
@ -13,6 +11,12 @@ enum LogType_t
struct Log struct Log
{ {
Log(const std::string Message, const int Ticks, const LogType_t Type)
{
this->Message = Message;
this->Ticks = Ticks;
this->Type = Type;
}
std::string Message = ""; std::string Message = "";
int Ticks = 1024; int Ticks = 1024;
LogType_t Type = LogType_t::NATIVE; LogType_t Type = LogType_t::NATIVE;
@ -20,7 +24,6 @@ struct Log
class LogSystem class LogSystem
{ {
public: public:
void AddLog(LogType_t type, std::string text); void AddLog(LogType_t type, std::string text);
void Update(); void Update();

View File

@ -127,6 +127,9 @@ namespace
/*0x1405489C0*/ /*0x1405489C0*/
FUNC_AT_ADDRESS(addr_CMatSystemSurface_UnlockCursor, void(*)(void*), MemoryAddress(0x1405489C0).GetPtr()); // Maybe sigscan this via RTTI. FUNC_AT_ADDRESS(addr_CMatSystemSurface_UnlockCursor, void(*)(void*), MemoryAddress(0x1405489C0).GetPtr()); // Maybe sigscan this via RTTI.
/*0x140547900*/
FUNC_AT_ADDRESS(addr_CMatSystemSurface_DrawColoredText, void(*)(void*, int, int, int, int, int, int, int, int, const char*, ...), MemoryAddress(0x140547900).GetPtr());
#pragma region Utility #pragma region Utility
/*0x140295600*/ /*0x140295600*/
FUNC_AT_ADDRESS(addr_MSG_EngineError, int(*)(char*, va_list), r5_patterns.StringSearch("Engine Error").FindPatternSelf("48 89 ? ? ? 48 89", MemoryAddress::Direction::UP, 500).GetPtr()); FUNC_AT_ADDRESS(addr_MSG_EngineError, int(*)(char*, va_list), r5_patterns.StringSearch("Engine Error").FindPatternSelf("48 89 ? ? ? 48 89", MemoryAddress::Direction::UP, 500).GetPtr());

View File

@ -11,19 +11,18 @@ int Hooks::CEngineVGui_Paint(void* thisptr, int mode)
{ {
int result = originalCEngineVGui_Paint(thisptr, mode); int result = originalCEngineVGui_Paint(thisptr, mode);
static void* g_pMatSystemSurface = MemoryAddress(0x14D40B3B0).RCast<void* (*)()>(); static void* pCMatSystemSurface = MemoryAddress(0x14D40B3B0).RCast<void*(*)()>();
static auto RenderStart = MemoryAddress(0x14053EFC0).RCast<void(*)(void*)>(); static auto fnRenderStart = MemoryAddress(0x14053EFC0).RCast<void(*)(void*)>();
static auto RenderEnd = MemoryAddress(0x14053F1B0).RCast<void*(*)()>(); static auto fnRenderEnd = MemoryAddress(0x14053F1B0).RCast<void*(*)()>();
if (mode == 1 || mode == 2) if (mode == 1 || mode == 2) // Render in main menu and ingame.
{ {
RenderStart(g_pMatSystemSurface); fnRenderStart(pCMatSystemSurface);
g_LogSystem.Update(); g_LogSystem.Update();
RenderEnd(); fnRenderEnd();
} }
return result; return result;
} }

View File

@ -413,7 +413,7 @@ namespace GameGlobals
void* BanConCommand = CreateCustomConCommand("ban", "Bans a client from the Server via name. | Usage: ban (name)", 0, CustomCommandVariations::Ban_Callback, nullptr); void* BanConCommand = CreateCustomConCommand("ban", "Bans a client from the Server via name. | Usage: ban (name)", 0, CustomCommandVariations::Ban_Callback, nullptr);
void* BanIDConCommand = CreateCustomConCommand("banid", "Bans a client from the Server via originID, userID or IP | Usage: banid (originID/ipAddress/userID)", 0, CustomCommandVariations::BanID_Callback, nullptr); void* BanIDConCommand = CreateCustomConCommand("banid", "Bans a client from the Server via originID, userID or IP | Usage: banid (originID/ipAddress/userID)", 0, CustomCommandVariations::BanID_Callback, nullptr);
ConVar* DrawConsoleOverlayConVar = CreateCustomConVar("cl_drawconsoleoverlay", "0", 0, "Draw the console overlay at the top of the screen", false, 0.f, false, 0.f, nullptr, nullptr); ConVar* DrawConsoleOverlayConVar = CreateCustomConVar("cl_drawconsoleoverlay", "0", 0, "Draw the console overlay at the top of the screen", false, 0.f, false, 0.f, nullptr, nullptr);
ConVar* ConsoleOverlayLinesConVar = CreateCustomConVar("cl_consoleoverlay_lines", "3", 0, "Number of lines of console output to draw", false, 1.f, false, 50.f, nullptr, nullptr); ConVar* ConsoleOverlayLinesConVar = CreateCustomConVar("cl_consoleoverlay_lines", "3", 0, "Number of lines of console output to draw", false, 1.f, false, 50.f, nullptr, nullptr);
} }

View File

@ -6,62 +6,59 @@ LogSystem g_LogSystem;
void LogSystem::Update() void LogSystem::Update()
{ {
if (GameGlobals::Cvar->FindVar("cl_drawconsoleoverlay")->m_iValue < 1)
return;
if (m_vLogs.empty()) if (m_vLogs.empty())
return; return;
static void* g_pMatSystemSurface = MemoryAddress(0x14D40B360).RCast<void* (*)()>(); static void* pCMatSystemSurface = MemoryAddress(0x14D40B360).RCast<void*(*)()>();
if (!pCMatSystemSurface)
return;
int fontHeight = 16; static int fontHeight = 16;
for (int i = 0; i < m_vLogs.size(); ++i) { for (int i = 0; i < m_vLogs.size(); ++i)
{
if (m_vLogs[i].Ticks >= 0) if (m_vLogs[i].Ticks >= 0)
{ {
if (GameGlobals::Cvar->FindVar("cl_drawconsoleoverlay")->m_iValue < 1)
return;
if (i < GameGlobals::Cvar->FindVar("cl_consoleoverlay_lines")->m_iValue) if (i < GameGlobals::Cvar->FindVar("cl_consoleoverlay_lines")->m_iValue)
{ {
float fadepct = fminf(static_cast<float>(m_vLogs[i].Ticks) / 64.f, 1.0);
if (i >= m_vLogs.size()) float ptc = static_cast<int>(ceilf( fadepct * 255.f));
{ int alpha = static_cast<int>(ptc);
break;
}
float fadepct = fminf(float(m_vLogs[i].Ticks) / 64.f, 1.0);
float ptc = (int)ceilf( fadepct * 255.f);
int alpha = (int)ptc;
int y = (10 + (fontHeight * i)); int y = (10 + (fontHeight * i));
std::array<int, 3> color = GetLogColorForType(m_vLogs[i].Type); std::array<int, 3> color = GetLogColorForType(m_vLogs[i].Type);
addr_CMatSystemSurface_DrawColoredText(pCMatSystemSurface, 0x13, fontHeight, 10, y, color[0], color[1], color[2], alpha, m_vLogs[i].Message.c_str());
MemoryAddress(0x140547900).RCast<void(*)(void*, QWORD, __int64, QWORD, int, int, DWORD, DWORD, DWORD, const char*, ...)>()(g_pMatSystemSurface, 0x13, fontHeight, 10, y, color[0], color[1], color[2], alpha, m_vLogs[i].Message.c_str());
} }
else { else
{
m_vLogs.erase(m_vLogs.begin()); m_vLogs.erase(m_vLogs.begin());
continue; continue;
} }
m_vLogs[i].Ticks--; m_vLogs[i].Ticks--;
} }
else { else
{
m_vLogs.erase(m_vLogs.begin() + i); m_vLogs.erase(m_vLogs.begin() + i);
} }
} }
} }
void LogSystem::AddLog(LogType_t type, std::string message) void LogSystem::AddLog(LogType_t type, std::string message)
{ {
Log log; if (message.length() > 0)
log.Message = message; {
log.Type = type; m_vLogs.push_back(Log{ message, 1024, type });
log.Ticks = 1024; }
m_vLogs.push_back(log);
} }
std::array<int, 3> LogSystem::GetLogColorForType(LogType_t type) { std::array<int, 3> LogSystem::GetLogColorForType(LogType_t type)
switch(type) { {
switch (type)
{
case LogType_t::NATIVE: case LogType_t::NATIVE:
return { 255, 255, 255 }; return { 255, 255, 255 };
case LogType_t::SCRIPT_SERVER: case LogType_t::SCRIPT_SERVER:
@ -73,4 +70,6 @@ std::array<int, 3> LogSystem::GetLogColorForType(LogType_t type) {
default: default:
return { 255, 255, 255 }; return { 255, 255, 255 };
} }
return { 255, 255, 255 };
} }