[General]: Remove redundant std::to_string (#832)

This commit is contained in:
Edo 2023-03-14 12:07:20 +00:00 committed by GitHub
parent a109b85042
commit d8aa762573
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 25 deletions

View File

@ -16,7 +16,7 @@ namespace Components
{
auto result = lookupResult;
const auto* username = Dvar::Var("name").get<const char*>();
const auto* username = Dvar::Name.get<const char*>();
if (std::strcmp(data->name, username) == 0)
{
result += 0xFE000000;
@ -170,7 +170,7 @@ namespace Components
playerTitle[0] = '\0';
}
list.append(std::format("\\{}\\{}", std::to_string(i), playerTitle));
list.append(std::format("\\{}\\{}", i, playerTitle));
}
const auto* command = Utils::String::Format("{:c} customTitles \"{}\"", 21, list);

View File

@ -5,7 +5,7 @@
namespace Components
{
Game::dvar_t* ClanTags::ClanName;
const Game::dvar_t* ClanTags::ClanName;
// bgs_t and clientState_s do not have this
char ClanTags::ClientState[Game::MAX_CLIENTS][5];
@ -28,7 +28,7 @@ namespace Components
for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i)
{
list.append(std::format("\\{}\\{}", std::to_string(i), ClientState[i]));
list.append(std::format("\\{}\\{}", i, ClientState[i]));
}
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, Utils::String::Format("{:c} clanNames \"{}\"", 22, list));
@ -118,7 +118,7 @@ namespace Components
{
AssertIn(clientNum, Game::MAX_CLIENTS);
auto* clanAbbrev = Game::Info_ValueForKey(s, "clanAbbrev");
const auto* clanAbbrev = Game::Info_ValueForKey(s, "clanAbbrev");
if (clanAbbrev[0] == '\0')
{
@ -193,11 +193,11 @@ namespace Components
void __declspec(naked) ClanTags::PlayerCards_SetCachedPlayerData_Stub()
{
static DWORD func = 0x4D6F80; // I_strncpyz
using namespace Game;
__asm
{
call func
call I_strncpyz
add esp, 0xC
mov byte ptr [esi + 0x3C], 0x0
@ -235,8 +235,7 @@ namespace Components
{
Events::OnClientInit([]
{
ClanName = Game::Dvar_RegisterString("clanName", "", Game::DVAR_ARCHIVE,
"Your clan abbreviation");
ClanName = Game::Dvar_RegisterString("clanName", "", Game::DVAR_ARCHIVE, "Your clan abbreviation");
});
std::memset(&ClientState, 0, sizeof(char[Game::MAX_CLIENTS][5]));

View File

@ -14,7 +14,7 @@ namespace Components
static void CL_SanitizeClanName();
private:
static Game::dvar_t* ClanName;
static const Game::dvar_t* ClanName;
static const char* dvarNameList[];

View File

@ -37,9 +37,10 @@ namespace Components
template<typename T> static Var Register(const char* dvarName, T value, std::uint16_t flag, const char* description);
template<typename T> static Var Register(const char* dvarName, T value, T min, T max, std::uint16_t flag, const char* description);
private:
static Var Name;
private:
static const Game::dvar_t* Dvar_RegisterName(const char* dvarName, const char* value, std::uint16_t flags, const char* description);
static const Game::dvar_t* Dvar_RegisterSVNetworkFps(const char* dvarName, int value, int min, int max, std::uint16_t flags, const char* description);
static const Game::dvar_t* Dvar_RegisterPerkExtendedMeleeRange(const char* dvarName, float value, float min, float max, std::uint16_t flags, const char* description);

View File

@ -6,11 +6,11 @@ namespace Components
{
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 int size)
{
if (!sv_allowColoredNames.get<bool>())
{
char nameBuffer[64] = {0};
char nameBuffer[64]{};
TextRenderer::StripColors(name, nameBuffer, sizeof(nameBuffer));
TextRenderer::StripAllTextIcons(nameBuffer, buffer, size);
}
@ -32,17 +32,18 @@ namespace Components
{
__asm
{
mov eax, [esp + 4h] // length
push eax
pushad
push [esp + 0x20 + 0x4] // length
push ecx // name
push edx // buffer
call UserInfoCopy
add esp, 0xC
add esp, 0Ch
retn
popad
ret
}
}
@ -58,7 +59,7 @@ namespace Components
char* PlayerName::CleanStrStub(char* string)
{
TextRenderer::StripColors(string, string, strlen(string) + 1);
TextRenderer::StripColors(string, string, std::strlen(string) + 1);
return string;
}
@ -69,9 +70,16 @@ namespace Components
auto i = 0;
while (i < size - 1 && dest[i] != '\0')
{
if (dest[i] > 125 || dest[i] < 32 || dest[i] == '%')
// Check for various illegal characters
if (dest[i] == '%')
{
return false; // Illegal string
return false;
}
if (std::iscntrl(static_cast<unsigned char>(dest[i])))
{
return false;
}
++i;
@ -82,6 +90,8 @@ namespace Components
__declspec(naked) void PlayerName::SV_UserinfoChangedStub()
{
using namespace Game;
__asm
{
call CopyClientNameCheck
@ -94,8 +104,7 @@ namespace Components
push 1 // tellThem
push INVALID_NAME_MSG // reason
push edi // drop
mov eax, 0x4D1600 // SV_DropClient
call eax
call SV_DropClient
add esp, 0xC
popad
@ -114,7 +123,8 @@ namespace Components
Utils::Hook::Set<BYTE>(0x6258D0, 0xC3);
// Allow colored names ingame. Hook placed in ClientUserinfoChanged
Utils::Hook(0x5D8B40, ClientCleanName, HOOK_JUMP).install()->quick();
Utils::Hook(0x445301, ClientCleanName, HOOK_CALL).install()->quick();
Utils::Hook(0x44533A, ClientCleanName, HOOK_CALL).install()->quick();
// Though, don't apply that to overhead names.
Utils::Hook(0x581932, GetClientName, HOOK_CALL).install()->quick();

View File

@ -7,7 +7,7 @@ namespace Components
public:
PlayerName();
static void UserInfoCopy(char* buffer, const char* name, size_t size);
static void UserInfoCopy(char* buffer, const char* name, int size);
static int GetClientName(int localClientNum, int index, char* buf, int size);