Merge pull request #353 from diamante0018/develop

[General] Make some improvements
This commit is contained in:
Dss0 2022-07-11 11:54:17 +02:00 committed by GitHub
commit d915481928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 74 additions and 48 deletions

View File

@ -4,7 +4,7 @@ namespace Components
{ {
Ceg::Ceg() Ceg::Ceg()
{ {
Utils::Hook::Signature signature(0x401000, 0x740000); Utils::Hook::Signature signature(0x401000, 0x340000);
// Generic killer caller. // Generic killer caller.
signature.add({ signature.add({
@ -45,5 +45,11 @@ namespace Components
Utils::Hook::Set<BYTE>(0x4F4CF0, 0xC3); Utils::Hook::Set<BYTE>(0x4F4CF0, 0xC3);
Utils::Hook::Set<BYTE>(0x432180, 0xC3); Utils::Hook::Set<BYTE>(0x432180, 0xC3);
Utils::Hook::Set<BYTE>(0x461930, 0xC3); Utils::Hook::Set<BYTE>(0x461930, 0xC3);
// Looking for stuff in the registry
Utils::Hook::Nop(0x4826F8, 5);
// Live_Init
Utils::Hook::Nop(0x420937, 5);
} }
} }

View File

@ -213,6 +213,11 @@ namespace Components
} }
} }
void Debug::Com_Assert_f()
{
assert(("a", false));
}
void Debug::CL_InitDebugDvars() void Debug::CL_InitDebugDvars()
{ {
static const char* debugOverlayNames_0[] = static const char* debugOverlayNames_0[] =
@ -236,5 +241,7 @@ namespace Components
// Hook end of CG_DrawDebugOverlays (This is to ensure some checks are done before our hook is executed). // Hook end of CG_DrawDebugOverlays (This is to ensure some checks are done before our hook is executed).
Utils::Hook(0x49CB0A, CG_DrawDebugOverlays_Hk, HOOK_JUMP).install()->quick(); Utils::Hook(0x49CB0A, CG_DrawDebugOverlays_Hk, HOOK_JUMP).install()->quick();
Utils::Hook::Set<void(*)()>(0x60BCEA, Com_Assert_f);
} }
} }

View File

@ -31,6 +31,8 @@ namespace Components
static void CG_DrawDebugOverlays_Hk(int localClientNum); static void CG_DrawDebugOverlays_Hk(int localClientNum);
static void Com_Assert_f();
static void CL_InitDebugDvars(); static void CL_InitDebugDvars();
}; };
} }

View File

@ -26,25 +26,33 @@ namespace Components
void Logger::MessagePrint(const int channel, const std::string& msg) void Logger::MessagePrint(const int channel, const std::string& msg)
{ {
std::string out = msg;
// Filter out coloured strings
if (out[0] == '^' && out[1] != '\0')
{
out = out.substr(2);
}
if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests()) if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests())
{ {
printf("%s", msg.data()); printf("%s", out.data());
fflush(stdout); fflush(stdout);
return; return;
} }
if (!Logger::IsConsoleReady()) if (!Logger::IsConsoleReady())
{ {
OutputDebugStringA(msg.data()); OutputDebugStringA(out.data());
} }
if (!Game::Sys_IsMainThread()) if (!Game::Sys_IsMainThread())
{ {
Logger::EnqueueMessage(msg); Logger::EnqueueMessage(out);
} }
else else
{ {
Game::Com_PrintMessage(channel, msg.data(), 0); Game::Com_PrintMessage(channel, out.data(), 0);
} }
} }
@ -54,7 +62,8 @@ namespace Components
const auto msg = std::vformat(fmt, args); const auto msg = std::vformat(fmt, args);
const auto out = std::format("Debug:\n {}\nFile: {}\nLine: {}\n", msg, loc.file_name(), loc.line()); const auto out = std::format("Debug:\n {}\nFile: {}\nLine: {}\n", msg, loc.file_name(), loc.line());
#else #else
const auto out = "^2" + std::vformat(fmt, args); const auto msg = std::vformat(fmt, args);
const auto out = std::format("^2{}\n", msg);
#endif #endif
Logger::MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out); Logger::MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out);

View File

@ -16,7 +16,6 @@ namespace Components
static void Flush(); static void Flush();
static void MessagePrint(int channel, const std::string& msg);
static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args); static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args);
static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args); static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args);
static void PrintErrorInternal(int channel, std::string_view fmt, std::format_args&& args); static void PrintErrorInternal(int channel, std::string_view fmt, std::format_args&& args);
@ -99,6 +98,7 @@ namespace Components
static std::vector<Network::Address> LoggingAddresses[2]; static std::vector<Network::Address> LoggingAddresses[2];
static void(*PipeCallback)(const std::string&); static void(*PipeCallback)(const std::string&);
static void MessagePrint(int channel, const std::string& msg);
static void Frame(); static void Frame();
static void G_LogPrintfStub(const char* fmt, ...); static void G_LogPrintfStub(const char* fmt, ...);
static void PrintMessageStub(); static void PrintMessageStub();

View File

@ -2,57 +2,57 @@
namespace Components namespace Components
{ {
Dvar::Var PlayerName::sv_allowColoredNames; Dvar::Var PlayerName::sv_allowColoredNames;
void PlayerName::UserInfoCopy(char* buffer, const char* name, const size_t size) void PlayerName::UserInfoCopy(char* buffer, const char* name, const size_t size)
{ {
if (!sv_allowColoredNames.get<bool>()) if (!sv_allowColoredNames.get<bool>())
{ {
char nameBuffer[64] = {0}; char nameBuffer[64] = {0};
TextRenderer::StripColors(name, nameBuffer, sizeof(nameBuffer)); TextRenderer::StripColors(name, nameBuffer, sizeof(nameBuffer));
TextRenderer::StripAllTextIcons(nameBuffer, buffer, size); TextRenderer::StripAllTextIcons(nameBuffer, buffer, size);
} }
else else
{ {
TextRenderer::StripAllTextIcons(name, buffer, size); TextRenderer::StripAllTextIcons(name, buffer, size);
} }
std::string readablePlayerName(buffer); std::string readablePlayerName(buffer);
readablePlayerName = Utils::String::Trim(readablePlayerName); readablePlayerName = Utils::String::Trim(readablePlayerName);
if (readablePlayerName.size() < 3) if (readablePlayerName.size() < 3)
{ {
strncpy(buffer, "Unknown Soldier", size); strncpy(buffer, "Unknown Soldier", size);
} }
} }
__declspec(naked) void PlayerName::ClientCleanName() __declspec(naked) void PlayerName::ClientCleanName()
{ {
__asm __asm
{ {
mov eax, [esp + 4h] // length mov eax, [esp + 4h] // length
push eax push eax
push ecx // name push ecx // name
push edx // buffer push edx // buffer
call UserInfoCopy call UserInfoCopy
add esp, 0Ch add esp, 0Ch
retn retn
} }
} }
char* PlayerName::GetClientName(int localClientNum, int index, char* buf, size_t size) char* PlayerName::GetClientName(int localClientNum, int index, char* buf, size_t size)
{ {
Game::CL_GetClientName(localClientNum, index, buf, size); Game::CL_GetClientName(localClientNum, index, buf, size);
// Append clantag to username & remove the colors // Append clantag to username & remove the colors
strncpy_s(buf, size, TextRenderer::StripColors(ClanTags::GetUserClantag(index, buf)).data(), size); strncpy_s(buf, size, TextRenderer::StripColors(ClanTags::GetUserClantag(index, buf)).data(), size);
return buf; return buf;
} }
char* PlayerName::CleanStrStub(char* string) char* PlayerName::CleanStrStub(char* string)
{ {

View File

@ -7070,6 +7070,8 @@ namespace Game
entityState_s noDeltaEntities[1024]; entityState_s noDeltaEntities[1024];
}; };
static_assert(sizeof(clientStatic_t) == 0xA7AEC);
struct ConDrawInputGlob struct ConDrawInputGlob
{ {
char autoCompleteChoice[64]; char autoCompleteChoice[64];

View File

@ -9,7 +9,7 @@ namespace Utils
{ {
if (this->signatures.empty()) return; if (this->signatures.empty()) return;
char* _start = reinterpret_cast<char*>(this->start); char* _start = static_cast<char*>(this->start);
unsigned int sigCount = this->signatures.size(); unsigned int sigCount = this->signatures.size();
Hook::Signature::Container* containers = this->signatures.data(); Hook::Signature::Container* containers = this->signatures.data();