From 9967136097b354ea62323b88d60956e2be6155ff Mon Sep 17 00:00:00 2001 From: rei-2 <174158077+rei-2@users.noreply.github.com> Date: Thu, 23 Oct 2025 20:55:12 -0400 Subject: [PATCH] misc changes --- Amalgam/src/Core/Core.cpp | 4 +-- .../Definitions/Misc/IMatchGroupDescription.h | 30 ++++++++++------ Amalgam/src/SDK/Helpers/Entities/Entities.cpp | 12 +++++-- Amalgam/src/Utils/ConVars/ConVars.cpp | 36 ++++++++++++------- Amalgam/src/Utils/ConVars/ConVars.h | 11 +++--- 5 files changed, 61 insertions(+), 32 deletions(-) diff --git a/Amalgam/src/Core/Core.cpp b/Amalgam/src/Core/Core.cpp index 52dd7b06..b8bd7cec 100644 --- a/Amalgam/src/Core/Core.cpp +++ b/Amalgam/src/Core/Core.cpp @@ -94,7 +94,7 @@ void CCore::Load() if (m_bUnload = m_bFailed2 = !U::Hooks.Initialize() || !U::BytePatches.Initialize() || !H::Events.Initialize()) return; F::Materials.LoadMaterials(); - U::ConVars.Initialize(); + U::ConVars.Unlock(); F::Configs.LoadConfig(F::Configs.m_sCurrentConfig, false); @@ -142,7 +142,7 @@ void CCore::Unload() Sleep(250); F::EnginePrediction.Unload(); - U::ConVars.Unload(); + U::ConVars.Restore(); F::Materials.UnloadMaterials(); if (m_bFailed2) diff --git a/Amalgam/src/SDK/Definitions/Misc/IMatchGroupDescription.h b/Amalgam/src/SDK/Definitions/Misc/IMatchGroupDescription.h index 1a85baa3..fa7860f0 100644 --- a/Amalgam/src/SDK/Definitions/Misc/IMatchGroupDescription.h +++ b/Amalgam/src/SDK/Definitions/Misc/IMatchGroupDescription.h @@ -120,17 +120,9 @@ public: class IMatchGroupDescription { public: - inline int GetLevelForIndex(int iIndex) + inline int GetLevelForSteamID(CSteamID* pSteamID) { - player_info_t tInfo; - if (!I::EngineClient->GetPlayerInfo(iIndex, &tInfo) || tInfo.fakeplayer) - return -1; - - CSteamID cSteamID = { tInfo.friendsID, 1, k_EUniversePublic, k_EAccountTypeIndividual }; - if (!cSteamID.IsValid()) - return -1; - - auto pRating = S::CTFRatingData_YieldingGetPlayerRatingDataBySteamID.Call(&cSteamID, m_eMatchType == MATCH_TYPE_CASUAL ? m_eCurrentDisplayRating : m_eCurrentDisplayRank); + auto pRating = S::CTFRatingData_YieldingGetPlayerRatingDataBySteamID.Call(pSteamID, m_eMatchType == MATCH_TYPE_CASUAL ? m_eCurrentDisplayRating : m_eCurrentDisplayRank); if (!pRating) return -1; @@ -141,6 +133,24 @@ public: return m_pProgressionDesc->GetLevelByNumber(nLevel).m_nLevelNum; } + inline int GetLevelForAccountID(uint32 uAccountID) + { + CSteamID tSteamID = { uAccountID, 1, k_EUniversePublic, k_EAccountTypeIndividual }; + if (!tSteamID.IsValid()) + return -1; + + return GetLevelForSteamID(&tSteamID); + } + + inline int GetLevelForIndex(int iIndex) + { + player_info_t tInfo; + if (!I::EngineClient->GetPlayerInfo(iIndex, &tInfo) || tInfo.fakeplayer) + return -1; + + return GetLevelForAccountID(tInfo.friendsID); + } + public: byte pad0[8]; const ETFMatchGroup m_eMatchGroup; diff --git a/Amalgam/src/SDK/Helpers/Entities/Entities.cpp b/Amalgam/src/SDK/Helpers/Entities/Entities.cpp index 59cb59b6..490aa6a5 100644 --- a/Amalgam/src/SDK/Helpers/Entities/Entities.cpp +++ b/Amalgam/src/SDK/Helpers/Entities/Entities.cpp @@ -170,19 +170,25 @@ void CEntities::Store() if (auto pLobby = I::TFGCClientSystem->GetLobby()) { + auto pGameRules = I::TFGameRules(); + auto pMatchDesc = pGameRules ? pGameRules->GetMatchGroupDescription() : nullptr; + int iMembers = pLobby->GetNumMembers(); for (int i = 0; i < iMembers; i++) { - auto cSteamID = CSteamID(); pLobby->GetMember(&cSteamID, i); - auto uAccountID = cSteamID.GetAccountID(); + auto tSteamID = CSteamID(); pLobby->GetMember(&tSteamID, i); + auto uAccountID = tSteamID.GetAccountID(); ConstTFLobbyPlayer pDetails; pLobby->GetMemberDetails(&pDetails, i); auto pProto = pDetails.Proto(); mF2P[uAccountID] = pProto->chat_suspension; - mLevels[uAccountID] = pProto->rank; mParties[uAccountID] = pProto->original_party_id; + if (pMatchDesc && pMatchDesc->m_pProgressionDesc) + mLevels[uAccountID] = std::max(int(pProto->rank), pMatchDesc->GetLevelForSteamID(&tSteamID)); + else + mLevels[uAccountID] = pProto->rank; } } if (auto pParty = I::TFGCClientSystem->GetParty()) diff --git a/Amalgam/src/Utils/ConVars/ConVars.cpp b/Amalgam/src/Utils/ConVars/ConVars.cpp index 773957b7..8165771f 100644 --- a/Amalgam/src/Utils/ConVars/ConVars.cpp +++ b/Amalgam/src/Utils/ConVars/ConVars.cpp @@ -2,30 +2,42 @@ #include "../../SDK/Definitions/Interfaces/ICVar.h" -void CConVars::Initialize() +bool CConVars::Unlock() { - ConCommandBase* pCmdBase = I::CVar->GetCommands(); - while (pCmdBase != nullptr) + if (!m_bUnlocked) { - mFlagMap[pCmdBase] = pCmdBase->m_nFlags; - pCmdBase->m_nFlags &= ~(FCVAR_HIDDEN | FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT | FCVAR_NOT_CONNECTED); - pCmdBase = pCmdBase->m_pNext; + ConCommandBase* pCmdBase = I::CVar->GetCommands(); + while (pCmdBase != nullptr) + { + m_mFlagMap[pCmdBase] = pCmdBase->m_nFlags; + pCmdBase->m_nFlags &= ~(FCVAR_HIDDEN | FCVAR_DEVELOPMENTONLY | FCVAR_CHEAT | FCVAR_NOT_CONNECTED); + pCmdBase = pCmdBase->m_pNext; + } + m_bUnlocked = true; + + return true; } + return false; } -void CConVars::Unload() +bool CConVars::Restore() { - for (auto& [pCmdBase, nFlags] : mFlagMap) + if (m_bUnlocked) { - if (pCmdBase) + for (auto& [pCmdBase, nFlags] : m_mFlagMap) pCmdBase->m_nFlags = nFlags; + m_mFlagMap.clear(); + m_bUnlocked = false; + + return true; } + return false; } ConVar* CConVars::FindVar(const char* sCVar) { auto uHash = FNV1A::Hash32(sCVar); - if (!mCVarMap.contains(uHash)) - mCVarMap[uHash] = I::CVar->FindVar(sCVar); - return mCVarMap[uHash]; + if (!m_mCVarMap.contains(uHash)) + m_mCVarMap[uHash] = I::CVar->FindVar(sCVar); + return m_mCVarMap[uHash]; } \ No newline at end of file diff --git a/Amalgam/src/Utils/ConVars/ConVars.h b/Amalgam/src/Utils/ConVars/ConVars.h index 36324b1a..0ac246d4 100644 --- a/Amalgam/src/Utils/ConVars/ConVars.h +++ b/Amalgam/src/Utils/ConVars/ConVars.h @@ -7,14 +7,15 @@ class CConVars { private: - std::unordered_map mCVarMap = {}; - std::unordered_map mFlagMap = {}; + std::unordered_map m_mCVarMap = {}; + std::unordered_map m_mFlagMap = {}; + + bool m_bUnlocked = false; public: + bool Unlock(); + bool Restore(); ConVar* FindVar(const char* sCVar); - - void Initialize(); - void Unload(); }; ADD_FEATURE_CUSTOM(CConVars, ConVars, U); \ No newline at end of file