fakequeries: fixed hooking problems on certain providers

linkage: added support for fake steam ids for bots controlled via yb_enable_fake_steamids)

note that fake steam ids just used for give ability server owners to run statistics modules with tracking by steam ids ant not nicknames.
This commit is contained in:
jeefo 2024-01-19 18:29:20 +03:00
commit 1dc1043f7d
No known key found for this signature in database
GPG key ID: 927BCA0779BEA8ED
5 changed files with 42 additions and 1 deletions

View file

@ -87,7 +87,7 @@ private:
using SendToProto = decltype (sendto); using SendToProto = decltype (sendto);
private: private:
Detour <SendToProto> m_sendToDetour { }; Detour <SendToProto> m_sendToDetour { }, m_sendToDetourSys {};
public: public:
ServerQueryHook () = default; ServerQueryHook () = default;
@ -100,6 +100,7 @@ public:
public: public:
// disables send hook // disables send hook
bool disable () { bool disable () {
m_sendToDetourSys.restore ();
return m_sendToDetour.restore (); return m_sendToDetour.restore ();
} }

View file

@ -88,6 +88,9 @@ public:
// get the current date and time as string // get the current date and time as string
String getCurrentDateTime (); String getCurrentDateTime ();
// generates fake steam id from bot name
StringRef getFakeSteamId (edict_t *ent);
// get's the wave length // get's the wave length
float getWaveLength (StringRef filename); float getWaveLength (StringRef filename);

View file

@ -68,6 +68,11 @@ void ServerQueryHook::init () {
return; return;
} }
// do not detour twice
if (m_sendToDetour.detoured () || m_sendToDetourSys.detoured ()) {
return;
}
// do not enable on not dedicated server // do not enable on not dedicated server
if (!game.isDedicated ()) { if (!game.isDedicated ()) {
return; return;
@ -83,12 +88,17 @@ void ServerQueryHook::init () {
sendToAddress = address; sendToAddress = address;
} }
} }
m_sendToDetourSys.initialize ("ws2_32.dll", "sendto", sendto);
} }
m_sendToDetour.initialize ("ws2_32.dll", "sendto", sendToAddress); m_sendToDetour.initialize ("ws2_32.dll", "sendto", sendToAddress);
// enable only on modern games // enable only on modern games
if (!game.is (GameFlags::Legacy) && (plat.nix || plat.win) && !plat.isNonX86 () && !m_sendToDetour.detoured ()) { if (!game.is (GameFlags::Legacy) && (plat.nix || plat.win) && !plat.isNonX86 () && !m_sendToDetour.detoured ()) {
m_sendToDetour.install (reinterpret_cast <void *> (BotSupport::sendTo), true); m_sendToDetour.install (reinterpret_cast <void *> (BotSupport::sendTo), true);
if (!m_sendToDetourSys.detoured ()) {
m_sendToDetourSys.install (reinterpret_cast <void *> (BotSupport::sendTo), true);
}
} }
} }

View file

@ -534,6 +534,22 @@ CR_LINKAGE_C int GetEngineFunctions (enginefuncs_t *table, int *) {
}; };
} }
table->pfnGetPlayerAuthId = [] (edict_t *e) -> const char * {
if (bots[e]) {
auto authid = util.getFakeSteamId (e);
if (game.is (GameFlags::Metamod)) {
RETURN_META_VALUE (MRES_SUPERCEDE, authid.chars ());
}
return authid.chars ();
}
if (game.is (GameFlags::Metamod)) {
RETURN_META_VALUE (MRES_IGNORED, nullptr);
}
return engfuncs.pfnGetPlayerAuthId (e);
};
table->pfnEmitSound = [] (edict_t *entity, int channel, const char *sample, float volume, float attenuation, int flags, int pitch) { table->pfnEmitSound = [] (edict_t *entity, int channel, const char *sample, float volume, float attenuation, int flags, int pitch) {
// this function tells the engine that the entity pointed to by "entity", is emitting a sound // this function tells the engine that the entity pointed to by "entity", is emitting a sound
// which fileName is "sample", at level "channel" (CHAN_VOICE, etc...), with "volume" as // which fileName is "sample", at level "channel" (CHAN_VOICE, etc...), with "volume" as

View file

@ -10,6 +10,7 @@
ConVar cv_display_welcome_text ("display_welcome_text", "1", "Enables or disables showing welcome message to host entity on game start."); ConVar cv_display_welcome_text ("display_welcome_text", "1", "Enables or disables showing welcome message to host entity on game start.");
ConVar cv_enable_query_hook ("enable_query_hook", "0", "Enables or disables fake server queries response, that shows bots as real players in server browser."); ConVar cv_enable_query_hook ("enable_query_hook", "0", "Enables or disables fake server queries response, that shows bots as real players in server browser.");
ConVar cv_breakable_health_limit ("breakable_health_limit", "500.0", "Specifies the maximum health of breakable object, that bot will consider to destroy.", true, 1.0f, 3000.0); ConVar cv_breakable_health_limit ("breakable_health_limit", "500.0", "Specifies the maximum health of breakable object, that bot will consider to destroy.", true, 1.0f, 3000.0);
ConVar cv_enable_fake_steamids ("enable_fake_steamids", "0", "Allows or disallows bots to return fake steam id.");
BotSupport::BotSupport () { BotSupport::BotSupport () {
m_needToSendWelcome = false; m_needToSendWelcome = false;
@ -530,6 +531,16 @@ String BotSupport::getCurrentDateTime () {
return String (timebuf); return String (timebuf);
} }
StringRef BotSupport::getFakeSteamId (edict_t *ent) {
if (!cv_enable_fake_steamids.bool_ () || !isPlayer (ent)) {
return "BOT";
}
auto botNameHash = StringRef::fnv1a32 (ent->v.netname.chars ());
// just fake steam id a d return it with get player authid function
return strings.format ("STEAM_0:1:%d", cr::abs (static_cast <int32_t> (botNameHash) & 0xffff00));
}
StringRef BotSupport::weaponIdToAlias (int32_t id) { StringRef BotSupport::weaponIdToAlias (int32_t id) {
StringRef none = "none"; StringRef none = "none";