From ace8447fcbd2f0e63ccd0cb4241177d1165e7903 Mon Sep 17 00:00:00 2001 From: julianacat Date: Thu, 20 Jul 2017 01:26:06 -0500 Subject: [PATCH] Fix github revert --- src/hooks/others.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/hooks/others.cpp b/src/hooks/others.cpp index d4ee1270..273b147b 100644 --- a/src/hooks/others.cpp +++ b/src/hooks/others.cpp @@ -213,9 +213,89 @@ void Shutdown_hook(void* _this, const char* reason) { static CatVar resolver(CV_SWITCH, "resolver", "0", "Resolve angles"); +CatEnum namesteal_enum({ "OFF", "PASSIVE", "ACTIVE" }); +CatVar namesteal(CV_SWITCH, "name_stealer", "0", "Name Stealer", "Attemt to steal your teammates names. Usefull for avoiding kicks\nPassive only changes when the name stolen is no longer the best name to use\nActive Attemps to change the name whenever possible"); + +static std::string stolen_name; + +// Func to get a new entity to steal name from +bool StolenName(){ + + // Array to store potential namestealer targets with a bookkeeper to tell how full it is + int potential_targets[32]; + int potential_targets_length = 0; + + // Go through entities looking for potential targets + for (int i = 1; i < HIGHEST_ENTITY; i++) { + CachedEntity* ent = ENTITY(i); + + // Check if ent is a good target + if (!ent) continue; + if (ent == LOCAL_E) continue; + if (!ent->m_Type == ENTITY_PLAYER) continue; + if (ent->m_bEnemy) continue; + + // Check if name is current one + player_info_s info; + if (g_IEngine->GetPlayerInfo(ent->m_IDX, &info)) { + + // If our name is the same as current, than change it + if (std::string(info.name) == stolen_name) { + // Since we found the ent we stole our name from and it is still good, if user settings are passive, then we return true and dont alter our name + if ((int)namesteal == 1) { + return true; + // Otherwise we continue to change our name to something else + } else continue; + } + + // a ent without a name is no ent we need, contine for a different one + } else continue; + + // Save the ent to our array + potential_targets[potential_targets_length] = i; + potential_targets_length++; + if (potential_targets_length >= 32) break; + } + + // Get random number that we can use with our array + int target_random_num = floor(RandFloatRange(0, potential_targets_length - 0.1F)); + + // Get a idx from our random array position + int new_target = potential_targets[target_random_num]; + + // Checks to prevent crashes + if (!ENTITY(new_target) || potential_targets_length == 0) return false; + + // Grab username of user + player_info_s info; + if (g_IEngine->GetPlayerInfo(new_target, &info)) { + + // If our name is the same as current, than change it and return true + stolen_name = std::string(info.name); + return true; + } + + // Didnt get playerinfo + return false; +} const char* GetFriendPersonaName_hook(ISteamFriends* _this, CSteamID steamID) { static const GetFriendPersonaName_t original = (GetFriendPersonaName_t)hooks::steamfriends.GetMethod(offsets::GetFriendPersonaName()); + + // Check User settings if namesteal is allowed + if (namesteal && steamID == g_ISteamUser->GetSteamID()) { + + // We dont want to steal names while not in-game as there are no targets to steal from + if (g_IEngine->IsInGame()) { + + // Check if we have a username to steal, func automaticly steals a name in it. + if (StolenName()) { + + // Return the name that has changed from the func above + return format(stolen_name, "\x0F").c_str(); + } + } + } if ((strlen(force_name.GetString()) > 1) && steamID == g_ISteamUser->GetSteamID()) {