Fix AutoParty Stuff and add Anti-kick

This commit is contained in:
BenCat07 2021-12-04 21:36:07 +01:00
parent 492a9eff4a
commit 65173084fa
6 changed files with 130 additions and 21 deletions

View File

@ -13,7 +13,9 @@
<AutoVariable width="fill" target="autoparty.ipc_count" label="IPC host count" tooltip="How many IPC members to use as party hosts."/>
<AutoVariable width="fill" target="autoparty.log" label="Log party leaves and kicks"/>
<AutoVariable width="fill" target="autoparty.message-kicks" label="Log to chat" tooltip="Log kick notifications to party chat."/>
<AutoVariable width="fill" target="autoparty.kick-bypass" label="Party kick bypass" tooltip="Makes your party unkickable ingame (with autovote no enabled), also allows you to nullify any vote with f1/f2."/>
<AutoVariable width="fill" target="autoparty.debug" label="Log locks/unlocks"/>
<AutoVariable width="fill" target="misc.remove_invite_timer" label="Remove Match join Timer" tooltip="Removes the match join timer, allowing to bypass kicks. Do not touch unless you know what you are doing."/>
</List>
</Box>
</Tab>

View File

@ -0,0 +1,4 @@
namespace hacks::tf2::autoparty
{
void joinMatch();
}

View File

@ -105,7 +105,7 @@ void updateSearch()
#if not ENABLE_VISUALS
if (queue_time.test_and_set(1200000))
{
g_IEngine->ClientCmd_Unrestricted("quit"); //lol
g_IEngine->ClientCmd_Unrestricted("quit"); // lol
}
#endif
}

View File

@ -82,11 +82,15 @@ static settings::Boolean ipc_mode{ "autoparty.ipc-mode", "false" };
static settings::Int ipc_count{ "autoparty.ipc-count", "0" };
// How often to run the autoparty routine, in seconds
static settings::Int timeout{ "autoparty.run-frequency", "60" };
// Should we have bots bypass kicks?
static settings::Boolean kickbypass{ "autoparty.kick-bypass", "false" };
// Only run the autoparty routine once every N seconds
static Timer routine_timer{};
// Populated by the routine when empty and by configuration changes
static std::vector<uint32> party_hosts = {};
static settings::Boolean no_autojoin("misc.remove_invite_timer", "false");
// ha ha macros go brr
#define log(...) \
if (*autoparty_log) \
@ -225,6 +229,10 @@ void party_routine()
re::CTFPartyClient *client = re::CTFPartyClient::GTFPartyClient();
if (client)
{
// Toggle anti-kick as needed
if (kickbypass)
no_autojoin = !is_host();
int members = client->GetNumMembers();
// Are we in a party?
if (members == 1)
@ -255,16 +263,9 @@ void party_routine()
// Get a list of party members, then check each one to determine the leader
std::vector<unsigned> members = client->GetPartySteamIDs();
uint32 leader_id = 0;
for (int i = 0; i < members.size(); i++)
{
CSteamID id = CSteamID(members[i], EUniverse::k_EUniversePublic, EAccountType::k_EAccountTypeIndividual);
// Are you my mummy?
if (client->GetCurrentPartyLeader(id))
{
leader_id = members[i];
break;
}
}
CSteamID id;
client->GetCurrentPartyLeader(id);
leader_id = id.GetAccountID();
if (leader_id == g_ISteamUser->GetSteamID().GetAccountID())
{
// Great, let's manage it
@ -286,7 +287,7 @@ void party_routine()
if (pl.state == playerlist::k_EState::RAGE)
{
std::string message = "Kicking Steam32 ID " + std::to_string(members[i]) + " from the party because they are set to RAGE";
logging::Info("AutoParty: %s", message);
logging::Info("AutoParty: %s", message.c_str());
if (*message_kicks)
client->SendPartyChat(message.c_str());
CSteamID id = CSteamID(members[i], EUniverse::k_EUniversePublic, EAccountType::k_EAccountTypeIndividual);
@ -310,7 +311,7 @@ void party_routine()
{
int num_to_kick = members.size() - *max_size;
std::string message = "Kicking " + std::to_string(num_to_kick) + " party members because there are " + std::to_string(members.size()) + " out of " + std::to_string(*max_size) + " allowed members";
logging::Info("AutoParty: %s", message);
logging::Info("AutoParty: %s", message.c_str());
if (*message_kicks)
client->SendPartyChat(message.c_str());
for (int i = 0; i < num_to_kick; i++)
@ -352,9 +353,109 @@ void party_routine()
}
}
static InitRoutine init([]() {
host_list.installChangeCallback([](settings::VariableBase<std::string> &var, std::string after) { repopulate(after); });
ipc_mode.installChangeCallback([](settings::VariableBase<bool> &var, bool after) { party_hosts.clear(); });
EC::Register(EC::Paint, party_routine, "paint_autoparty", EC::average);
});
#define IP_STARTSTR "PB_IP"
// Received party message
void partyChatMessage(IGameEvent *event)
{
if (!event->GetString("text"))
return;
// Only parse actual chat messages
if (event->GetInt("type") != 1)
return;
re::CTFPartyClient *client = re::CTFPartyClient::GTFPartyClient();
if (!client)
return;
// And are we actually the leader?
// Get a list of party members, then check each one to determine the leader
uint32 leader_id = 0;
CSteamID id;
client->GetCurrentPartyLeader(id);
leader_id = id.GetAccountID();
// Party leader doesn't care, they just join
if (leader_id == g_ISteamUser->GetSteamID().GetAccountID() || client->GetNumMembers() == 1)
return;
std::string chat_message = event->GetString("text");
// Found Message about server IP
if (chat_message.find(IP_STARTSTR) == 0)
{
auto ip_string = "connect " + chat_message.substr(sizeof(IP_STARTSTR) - 1);
g_IEngine->ClientCmd_Unrestricted(ip_string.c_str());
}
}
class PartyEventListener : public IGameEventListener2
{
virtual void FireGameEvent(IGameEvent *event)
{
if (enabled && kickbypass)
partyChatMessage(event);
}
};
static PartyEventListener party_listener;
void joinMatch()
{
if (!enabled || !kickbypass)
return;
re::CTFPartyClient *client = re::CTFPartyClient::GTFPartyClient();
if (!client)
return;
CSteamID id;
client->GetCurrentPartyLeader(id);
if (id.GetAccountID() != g_ISteamUser->GetSteamID().GetAccountID())
return;
INetChannel *ch = (INetChannel *) g_IEngine->GetNetChannelInfo();
std::string party_string = IP_STARTSTR;
party_string.append(ch->GetAddress());
client->SendPartyChat(party_string.c_str());
}
static InitRoutine init(
[]()
{
static BytePatch removeInviteTime(gSignatures.GetClientSignature, "55 89 e5 57 56 53 83 ec ? 8b ? ? 89 1c ? e8 ? ? ? ? f7 ? ? ? ? ? fd", 0x00, { 0xC3 });
if (*no_autojoin)
removeInviteTime.Patch();
no_autojoin.installChangeCallback(
[](settings::VariableBase<bool> &, bool new_val)
{
if (new_val)
removeInviteTime.Patch();
else
removeInviteTime.Shutdown();
});
host_list.installChangeCallback([](settings::VariableBase<std::string> &var, std::string after) { repopulate(after); });
ipc_mode.installChangeCallback([](settings::VariableBase<bool> &var, bool after) { party_hosts.clear(); });
kickbypass.installChangeCallback(
[](settings::VariableBase<bool> &var, bool after)
{
if (*var && !after)
no_autojoin = false;
});
EC::Register(EC::Paint, party_routine, "paint_autoparty", EC::average);
g_IEventManager2->AddListener(&party_listener, "party_chat", false);
EC::Register(
EC::Shutdown,
[]()
{
removeInviteTime.Shutdown();
g_IEventManager2->RemoveListener(&party_listener);
},
"shutdown_autoparty");
});
} // namespace hacks::tf2::autoparty

View File

@ -7,6 +7,7 @@
#include <hacks/hacklist.hpp>
#include <settings/Bool.hpp>
#include "AutoParty.hpp"
#include "common.hpp"
#include "hitrate.hpp"
#include "hack.hpp"
@ -41,6 +42,7 @@ DEFINE_HOOKED_METHOD(Paint, void, IEngineVGui *this_, PaintMode_t mode)
#if ENABLE_IPC
ipc::UpdateServerAddress();
#endif
hacks::tf2::autoparty::joinMatch();
}
if (mode & PaintMode_t::PAINT_UIPANELS)

View File

@ -50,7 +50,7 @@ bool re::CTFPartyClient::BCanQueueForStandby(re::CTFPartyClient *this_)
{
typedef bool (*BCanQueueForStandby_t)(re::CTFPartyClient *);
static uintptr_t addr = gSignatures.GetClientSignature("55 89 E5 53 83 EC 24 8B 5D 08 80 7B 46 00 75 40 8B 4B 38 85 C9 74 39 "
"E8 ? ? ? ? 89 04 24 E8 ? ? ? ? 84 C0 75 28");
"E8 ? ? ? ? 89 04 24 E8 ? ? ? ? 84 C0 75 28");
static BCanQueueForStandby_t BCanQueueForStandby_fn = BCanQueueForStandby_t(addr);
return BCanQueueForStandby_fn(this_);
@ -115,7 +115,7 @@ int re::CTFPartyClient::BInvitePlayerToParty(CSteamID steamid)
{
typedef int (*BInvitePlayerToParty_t)(re::CTFPartyClient *, CSteamID, bool);
static uintptr_t addr = gSignatures.GetClientSignature("55 89 E5 57 56 53 81 EC ? ? ? ? 8B 45 ? 8B 5D ? 8B 55 ? 89 85"
"65 A1 ? ? ? ? 89 45 ? 31 C0 8B 45");
"65 A1 ? ? ? ? 89 45 ? 31 C0 8B 45");
static BInvitePlayerToParty_t BInvitePlayerToParty_fn = BInvitePlayerToParty_t(addr);
return BInvitePlayerToParty_fn(this, steamid, false);
}
@ -160,7 +160,7 @@ int re::CTFPartyClient::KickPlayer(CSteamID steamid)
}
bool re::CTFPartyClient::GetCurrentPartyLeader(CSteamID &id)
{
uintptr_t party = *reinterpret_cast<uintptr_t *>(reinterpret_cast<uintptr_t>(this) + 0x30);
uintptr_t party = *reinterpret_cast<uintptr_t *>(reinterpret_cast<uintptr_t>(this) + 0x18);
if (!party)
return false;