changes to GetPlayerName

This commit is contained in:
rei-2
2025-11-02 19:07:23 -05:00
parent 79b012d413
commit dece5be39e
9 changed files with 163 additions and 73 deletions
+97 -25
View File
@@ -11,6 +11,19 @@ uint32_t CPlayerlistUtils::GetAccountID(int iIndex)
return 0;
}
int CPlayerlistUtils::GetIndex(uint32_t uAccountID)
{
auto pResource = H::Entities.GetResource();
if (!pResource)
return 0;
for (int n = 1; n <= I::EngineClient->GetMaxClients(); n++)
{
if (pResource->m_bValid(n) && !pResource->IsFakePlayer(n) && pResource->m_iAccountID(n) == uAccountID)
return n;
}
return 0;
}
PriorityLabel_t* CPlayerlistUtils::GetTag(int iID)
{
if (iID > -1 && iID < m_vTags.size())
@@ -304,51 +317,110 @@ bool CPlayerlistUtils::IsPrioritized(int iIndex)
return IsPrioritized(GetAccountID(iIndex));
}
const char* CPlayerlistUtils::GetPlayerName(int iIndex, const char* sDefault, int* pType)
int CPlayerlistUtils::GetNameType(int iIndex)
{
if (Vars::Visuals::UI::StreamerMode.Value)
{
if (iIndex == I::EngineClient->GetLocalPlayer())
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Local)
{
if (pType) *pType = 1;
return "Local";
}
return NameTypeEnum::Local;
}
else if (H::Entities.IsFriend(iIndex))
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Friends)
{
if (pType) *pType = 1;
return "Friend";
}
return NameTypeEnum::Friend;
}
else if (H::Entities.InParty(iIndex))
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Party)
{
if (pType) *pType = 1;
return "Party";
}
return NameTypeEnum::Party;
}
else if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::All)
{
if (pType) *pType = 1;
if (auto pTag = GetSignificantTag(iIndex, 0))
return pTag->m_sName.c_str();
else if (auto pResource = H::Entities.GetResource(); pResource && pResource->m_bValid(iIndex))
return pResource->m_iTeam(I::EngineClient->GetLocalPlayer()) != pResource->m_iTeam(iIndex) ? "Enemy" : "Teammate";
return "Player";
}
return NameTypeEnum::Player;
}
if (const uint32_t uAccountID = GetAccountID(iIndex))
if (const uint32_t uAccountID = GetAccountID(iIndex); uAccountID && GetPlayerAlias(uAccountID))
return NameTypeEnum::Custom;
return NameTypeEnum::None;
}
int CPlayerlistUtils::GetNameType(uint32_t uAccountID)
{
if (Vars::Visuals::UI::StreamerMode.Value)
{
if (auto sAlias = GetPlayerAlias(uAccountID))
if (uAccountID == I::SteamUser->GetSteamID().GetAccountID())
{
if (pType) *pType = 2;
return sAlias->c_str();
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Local)
return NameTypeEnum::Local;
}
else if (H::Entities.IsFriend(uAccountID))
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Friends)
return NameTypeEnum::Friend;
}
else if (H::Entities.InParty(uAccountID))
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Party)
return NameTypeEnum::Party;
}
else if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::All)
return NameTypeEnum::Player;
}
if (GetPlayerAlias(uAccountID))
return NameTypeEnum::Custom;
return NameTypeEnum::None;
}
const char* CPlayerlistUtils::GetPlayerName(int iIndex, const char* sDefault, int* pType)
{
int iType = GetNameType(iIndex);
if (pType) *pType = iType;
switch (iType)
{
case NameTypeEnum::Local:
return "Local";
case NameTypeEnum::Friend:
return "Friend";
case NameTypeEnum::Party:
return "Party";
case NameTypeEnum::Player:
if (auto pTag = GetSignificantTag(iIndex, 0))
return pTag->m_sName.c_str();
else if (auto pResource = H::Entities.GetResource(); pResource && pResource->m_bValid(iIndex))
return pResource->m_iTeam(I::EngineClient->GetLocalPlayer()) != pResource->m_iTeam(iIndex) ? "Enemy" : "Teammate";
return "Player";
case NameTypeEnum::Custom:
if (auto sAlias = GetPlayerAlias(GetAccountID(iIndex)))
return sAlias->c_str();
}
return sDefault;
}
const char* CPlayerlistUtils::GetPlayerName(uint32_t uAccountID, const char* sDefault, int* pType)
{
int iType = GetNameType(uAccountID);
if (pType) *pType = iType;
switch (iType)
{
case NameTypeEnum::Local:
return "Local";
case NameTypeEnum::Friend:
return "Friend";
case NameTypeEnum::Party:
return "Party";
case NameTypeEnum::Player:
if (auto pTag = GetSignificantTag(uAccountID, 0))
return pTag->m_sName.c_str();
else if (auto pResource = H::Entities.GetResource(); (iType = GetIndex(uAccountID)) && pResource && pResource->m_bValid(iType))
return pResource->m_iTeam(I::EngineClient->GetLocalPlayer()) != pResource->m_iTeam(iType) ? "Enemy" : "Teammate";
return "Player";
case NameTypeEnum::Custom:
if (auto sAlias = GetPlayerAlias(uAccountID))
return sAlias->c_str();
}
return sDefault;
}
@@ -37,6 +37,8 @@ struct PriorityLabel_t
bool m_bLocked = false; // don't allow it to be removed
};
Enum(NameType, None = 0, Local = 1 << 0, Friend = 1 << 1, Party = 1 << 2, Player = 1 << 3, Custom = 1 << 4, Privacy = Local | Friend | Party | Player);
class CPlayerlistUtils
{
public:
@@ -67,6 +69,8 @@ public:
void Store();
uint32_t GetAccountID(int iIndex);
int GetIndex(uint32_t uAccountID);
PriorityLabel_t* GetTag(int iID);
int GetTag(const std::string& sTag);
inline int TagToIndex(int iTag)
@@ -112,7 +116,10 @@ public:
bool IsPrioritized(uint32_t uAccountID);
bool IsPrioritized(int iIndex);
int GetNameType(int iIndex);
int GetNameType(uint32_t uAccountID);
const char* GetPlayerName(int iIndex, const char* sDefault, int* pType = nullptr);
const char* GetPlayerName(uint32_t uAccountID, const char* sDefault, int* pType = nullptr);
std::vector<int>& GetPlayerTags(uint32_t uAccountID) { return m_mPlayerTags.contains(uAccountID) ? m_mPlayerTags[uAccountID] : m_vDummy; }
std::string* GetPlayerAlias(uint32_t uAccountID) { return m_mPlayerAliases.contains(uAccountID) ? &m_mPlayerAliases[uAccountID] : nullptr; }
@@ -23,7 +23,7 @@ MAKE_HOOK(CBaseHudChatLine_InsertAndColorizeText, S::CBaseHudChatLine_InsertAndC
const char* sName = pResource->GetName(clientIndex);
auto iFind = sMessage.find(sName);
int iType = 0;
int iType;
if (const char* sReplace = F::PlayerUtils.GetPlayerName(clientIndex, nullptr, &iType))
{
if (iFind != std::string::npos)
@@ -31,7 +31,7 @@ MAKE_HOOK(CBaseHudChatLine_InsertAndColorizeText, S::CBaseHudChatLine_InsertAndC
sName = sReplace;
}
if (Vars::Visuals::UI::ChatTags.Value && iType != 1)
if (Vars::Visuals::UI::ChatTags.Value && !(iType & NameTypeEnum::Privacy))
{
std::string sTag, cColor;
if (Vars::Visuals::UI::ChatTags.Value & Vars::Visuals::UI::ChatTagsEnum::Local && clientIndex == I::EngineClient->GetLocalPlayer())
@@ -60,12 +60,16 @@ MAKE_HOOK(CBaseHudChatLine_InsertAndColorizeText, S::CBaseHudChatLine_InsertAndC
if (auto pResource = H::Entities.GetResource())
{
std::vector<std::pair<std::string, std::string>> vReplace;
for (auto& pEntity : H::Entities.GetGroup(EntityEnum::PlayerAll))
for (int n = 1; n <= I::EngineClient->GetMaxClients(); n++)
{
int iIndex = pEntity->entindex();
int iType = 0; const char* sReplace = F::PlayerUtils.GetPlayerName(iIndex, nullptr, &iType);
if (sReplace && iType == 1)
vReplace.emplace_back(pResource->GetName(iIndex), sReplace);
if (!pResource->m_bValid(n))
continue;
int iType; const char* sReplace = F::PlayerUtils.GetPlayerName(n, nullptr, &iType);
if (!sReplace || !(iType & NameTypeEnum::Privacy))
continue;
vReplace.emplace_back(pResource->GetName(n), sReplace);
}
for (auto& [sFind, sReplace] : vReplace)
{
@@ -3,7 +3,7 @@
MAKE_SIGNATURE(CBasePlayer_CalcViewModelView, "client.dll", "48 89 74 24 ? 55 41 56 41 57 48 8D AC 24", 0x0);
MAKE_HOOK(CBasePlayer_CalcViewModelView, S::CBasePlayer_CalcViewModelView(), void,
void* rcx, CBaseEntity* pOwner, Vec3& vEyePosition, Vec3& vEyeAngles)
void* rcx, CBaseEntity* pOwner, /*const*/ Vec3& vEyePosition, Vec3& vEyeAngles)
{
#ifdef DEBUG_HOOKS
if (!Vars::Hooks::CBasePlayer_CalcViewModelView[DEFAULT_BIND])
+10 -14
View File
@@ -1,5 +1,7 @@
#include "../SDK/SDK.h"
#include "../Features/Players/PlayerUtils.h"
MAKE_SIGNATURE(CTFBadgePanel_SetupBadge, "client.dll", "48 85 D2 0F 84 ? ? ? ? 48 89 5C 24 ? 48 89 7C 24 ? 4C 89 74 24", 0x0);
MAKE_SIGNATURE(CModelImagePanel_InvalidateImage, "client.dll", "40 53 48 83 EC ? 48 8B D9 48 8B 89 ? ? ? ? 48 85 C9 74 ? 48 8B 01 FF 50 ? 48 C7 83 ? ? ? ? ? ? ? ? 48 8B 8B", 0x0);
MAKE_SIGNATURE(vgui_Panel_GetBounds, "client.dll", "48 89 5C 24 ? 48 89 6C 24 ? 48 89 74 24 ? 57 41 56 41 57 48 83 EC ? 48 8B 1D ? ? ? ? 4D 8B F9", 0x0);
@@ -17,21 +19,15 @@ MAKE_HOOK(CTFBadgePanel_SetupBadge, S::CTFBadgePanel_SetupBadge(), void,
if (!Vars::Visuals::UI::StreamerMode.Value)
return CALL_ORIGINAL(rcx, pMatchDesc, levelInfo, steamID);
auto pResource = H::Entities.GetResource();
if (!pResource)
return CALL_ORIGINAL(rcx, pMatchDesc, levelInfo, steamID);
uint32_t uAccountID = steamID.GetAccountID();
// probably only need to worry about local, friends, a/o party
bool bShouldHide = false;
if (pResource->m_iAccountID(I::EngineClient->GetLocalPlayer()) == uAccountID)
bShouldHide = Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Local;
else if (H::Entities.IsFriend(uAccountID))
bShouldHide = Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Friends;
else if (H::Entities.InParty(uAccountID))
bShouldHide = Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Party;
if (!bShouldHide)
switch (F::PlayerUtils.GetNameType(steamID.GetAccountID()))
{ // probably only need to worry about local, friends, a/o party
case NameTypeEnum::Local:
case NameTypeEnum::Friend:
case NameTypeEnum::Party:
break;
default:
return CALL_ORIGINAL(rcx, pMatchDesc, levelInfo, steamID);
}
int nOldLevelNum = levelInfo.m_nLevelNum;
levelInfo.m_nLevelNum = 1;
@@ -2,7 +2,8 @@
#include "../Features/Players/PlayerUtils.h"
// are all of these even used? (i.e. CTFHudMatchStatus_UpdatePlayerAvatar)
MAKE_SIGNATURE(CAvatarImage_SetAvatarSteamID, "client.dll", "48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC ? 66 C7 41", 0x0);
MAKE_SIGNATURE(CAvatarImagePanel_SetPlayer, "client.dll", "48 89 5C 24 ? 48 89 74 24 ? 57 48 83 EC ? 48 8B F9 33 F6 48 8B 89 ? ? ? ? 48 8B DA", 0x0);
MAKE_SIGNATURE(CTFClientScoreBoardDialog_UpdatePlayerAvatar, "client.dll", "4D 85 C0 0F 84 ? ? ? ? 53 41 54 41 57", 0x0);
MAKE_SIGNATURE(CTFMatchSummary_UpdatePlayerAvatar, "client.dll", "40 55 41 57 48 83 EC ? 48 8B E9 4D 8B F8", 0x0);
MAKE_SIGNATURE(CTFHudMannVsMachineScoreboard_UpdatePlayerAvatar, "client.dll", "4D 85 C0 0F 84 ? ? ? ? 55 41 57 48 81 EC ? ? ? ? 48 8B 05 ? ? ? ? 4D 8B F8 48 8B E9 48 83 78 ? ? 0F 84 ? ? ? ? 48 83 78 ? ? 0F 84 ? ? ? ? 48 8B 0D ? ? ? ? 4C 8D 44 24 ? 48 8B 01 FF 50 ? 84 C0 0F 84 ? ? ? ? 83 7C 24 ? ? 0F 84 ? ? ? ? 48 89 9C 24 ? ? ? ? 48 89 B4 24 ? ? ? ? 48 89 BC 24 ? ? ? ? 4C 89 A4 24 ? ? ? ? 4C 89 B4 24 ? ? ? ? E8 ? ? ? ? 8B 4C 24 ? 48 8D B5 ? ? ? ? 0F B7 7E ? 41 BC ? ? ? ? 88 84 24 ? ? ? ? 8B 84 24 ? ? ? ? 25 ? ? ? ? 89 8C 24 ? ? ? ? 0D ? ? ? ? 89 84 24 ? ? ? ? 48 8B 9C 24 ? ? ? ? 48 89 5C 24 ? 66 41 3B FC 74 ? 66 66 0F 1F 84 00 ? ? ? ? 48 8B 56 ? 0F B7 C7 48 83 C2 ? 48 8D 0C 80 4C 8D 34 8D ? ? ? ? 49 03 D6 48 8D 4C 24 ? FF 16 84 C0 74 ? 66 41 3B FC 74 ? 48 8B 7E ? 41 0F B7 3C 3E EB ? 48 8B 4E ? 48 8D 54 24 ? 48 83 C1 ? 49 03 CE FF 16 84 C0 74 ? 66 41 3B FC 74 ? 48 8B 7E ? 42 0F B7 7C 37 ? 66 41 3B FC 75 ? 66 41 3B FC 75 ? B9 ? ? ? ? E8 ? ? ? ? 48 85 C0 74 ? 48 8B C8 E8 ? ? ? ? 48 8B F8 EB ? 33 FF 45 33 C0 48 8B D3 48 8B CF E8 ? ? ? ? BA ? ? ? ? 48 8B CF 44 8B C2 E8 ? ? ? ? C6 47", 0x0);
@@ -10,6 +11,13 @@ MAKE_SIGNATURE(CTFHudMatchStatus_UpdatePlayerAvatar, "client.dll", "4D 85 C0 0F
MAKE_SIGNATURE(SectionedListPanel_SetItemFgColor, "client.dll", "40 53 48 83 EC ? 48 8B D9 3B 91 ? ? ? ? 73 ? 3B 91 ? ? ? ? 7F ? 48 8B 89 ? ? ? ? 48 89 7C 24 ? 8B FA 48 03 FF 39 54 F9 ? 75 ? 39 54 F9 ? 75 ? 48 8B 0C F9 41 8B D0 48 8B 01 FF 90 ? ? ? ? 48 8B 83 ? ? ? ? B2 ? 48 8B 0C F8 48 8B 01 FF 90 ? ? ? ? 48 8B 83 ? ? ? ? 45 33 C0", 0x0);
MAKE_SIGNATURE(CTFClientScoreBoardDialog_UpdatePlayerList_SetItemFgColor_Call, "client.dll", "49 8B 04 24 8B D5 C7 44 24", 0x0);
enum EAvatarSize
{
k_EAvatarSize32x32 = 0,
k_EAvatarSize64x64 = 1,
k_EAvatarSize184x184 = 2,
};
static int s_iPlayerIndex;
static inline Color_t GetScoreboardColor(int iIndex)
@@ -28,6 +36,22 @@ static inline Color_t GetScoreboardColor(int iIndex)
return out;
}
MAKE_HOOK(CAvatarImage_SetAvatarSteamID, S::CAvatarImage_SetAvatarSteamID(), bool,
void* rcx, CSteamID steamIDUser, EAvatarSize avatarSize)
{
if (!(F::PlayerUtils.GetNameType(steamIDUser.GetAccountID()) & NameTypeEnum::Privacy))
return CALL_ORIGINAL(rcx, steamIDUser, avatarSize);
return CALL_ORIGINAL(rcx, CSteamID(), avatarSize);
}
MAKE_HOOK(CAvatarImagePanel_SetPlayer, S::CAvatarImagePanel_SetPlayer(), void,
void* rcx, CSteamID steamIDForPlayer, EAvatarSize avatarSize)
{
if (!(F::PlayerUtils.GetNameType(steamIDForPlayer.GetAccountID()) & NameTypeEnum::Privacy))
return CALL_ORIGINAL(rcx, steamIDForPlayer, avatarSize);
CALL_ORIGINAL(rcx, CSteamID(), avatarSize);
}
MAKE_HOOK(CTFClientScoreBoardDialog_UpdatePlayerAvatar, S::CTFClientScoreBoardDialog_UpdatePlayerAvatar(), void,
void* rcx, int playerIndex, KeyValues* kv)
{
@@ -38,8 +62,7 @@ MAKE_HOOK(CTFClientScoreBoardDialog_UpdatePlayerAvatar, S::CTFClientScoreBoardDi
s_iPlayerIndex = playerIndex;
int iType = 0; F::PlayerUtils.GetPlayerName(playerIndex, nullptr, &iType);
if (iType != 1)
if (!(F::PlayerUtils.GetNameType(playerIndex) & NameTypeEnum::Privacy))
CALL_ORIGINAL(rcx, playerIndex, kv);
}
@@ -51,8 +74,7 @@ MAKE_HOOK(CTFMatchSummary_UpdatePlayerAvatar, S::CTFMatchSummary_UpdatePlayerAva
return CALL_ORIGINAL(rcx, playerIndex, kv);
#endif
int iType = 0; F::PlayerUtils.GetPlayerName(playerIndex, nullptr, &iType);
if (iType != 1)
if (!(F::PlayerUtils.GetNameType(playerIndex) & NameTypeEnum::Privacy))
CALL_ORIGINAL(rcx, playerIndex, kv);
}
@@ -64,8 +86,7 @@ MAKE_HOOK(CTFHudMannVsMachineScoreboard_UpdatePlayerAvatar, S::CTFHudMannVsMachi
return CALL_ORIGINAL(rcx, playerIndex, kv);
#endif
int iType = 0; F::PlayerUtils.GetPlayerName(playerIndex, nullptr, &iType);
if (iType != 1)
if (!(F::PlayerUtils.GetNameType(playerIndex) & NameTypeEnum::Privacy))
CALL_ORIGINAL(rcx, playerIndex, kv);
}
@@ -77,8 +98,7 @@ MAKE_HOOK(CTFHudMatchStatus_UpdatePlayerAvatar, S::CTFHudMatchStatus_UpdatePlaye
return CALL_ORIGINAL(rcx, playerIndex, kv);
#endif
int iType = 0; F::PlayerUtils.GetPlayerName(playerIndex, nullptr, &iType);
if (iType != 1)
if (!(F::PlayerUtils.GetNameType(playerIndex) & NameTypeEnum::Privacy))
CALL_ORIGINAL(rcx, playerIndex, kv);
}
@@ -17,20 +17,11 @@ MAKE_HOOK(ISteamFriends_GetFriendPersonaName, U::Memory.GetVirtual(I::SteamFrien
if (Vars::Visuals::UI::StreamerMode.Value && dwRetAddr == dwDesired)
{
if (I::SteamUser->GetSteamID() == steamIDFriend)
switch (F::PlayerUtils.GetNameType(steamIDFriend.GetAccountID()))
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Local)
return "Local";
}
else if (I::SteamFriends->HasFriend(steamIDFriend, k_EFriendFlagImmediate))
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Friends)
return "Friend";
}
else
{
if (Vars::Visuals::UI::StreamerMode.Value >= Vars::Visuals::UI::StreamerModeEnum::Party)
return "Party";
case NameTypeEnum::Local: return "Local";
case NameTypeEnum::Friend: return "Friend";
case NameTypeEnum::Party: return "Party";
}
}
+2 -2
View File
@@ -28,8 +28,8 @@ MAKE_HOOK(bf_read_ReadString, S::bf_read_ReadString(), bool,
if (!iTarget)
return bReturn;
int iType = 0; const char* sName = F::PlayerUtils.GetPlayerName(iTarget, nullptr, &iType);
if (iType == 0)
int iType; const char* sName = F::PlayerUtils.GetPlayerName(iTarget, nullptr, &iType);
if (iType == NameTypeEnum::None)
return bReturn;
int iChar = 0;
@@ -196,8 +196,8 @@ void CEntities::Store()
int iMembers = pParty->GetNumMembers();
for (int i = 0; i < iMembers; i++)
{
auto cSteamID = CSteamID(); pParty->GetMember(&cSteamID, i);
auto uAccountID = cSteamID.GetAccountID();
auto tSteamID = CSteamID(); pParty->GetMember(&tSteamID, i);
auto uAccountID = tSteamID.GetAccountID();
mParties[uAccountID] = 1;
}
}