Rundimental ingame chat support

Technically, this implements #168.
However, it's very ugly, so it needs cleanup.
This commit is contained in:
momo5502 2023-03-13 20:33:59 +01:00
parent a4437fb0db
commit a3769a4489
4 changed files with 54 additions and 5 deletions

View File

@ -1,8 +1,10 @@
#include <std_include.hpp> #include <std_include.hpp>
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "chat.hpp"
#include "game/game.hpp" #include "game/game.hpp"
#include <utils/hook.hpp> #include <utils/hook.hpp>
#include <utils/string.hpp>
#include "command.hpp" #include "command.hpp"
#include "client_command.hpp" #include "client_command.hpp"
@ -41,17 +43,54 @@ namespace chat
utils::hook::invoke<void>(0x140298E70_g, ent, p.data()); utils::hook::invoke<void>(0x140298E70_g, ent, p.data());
} }
void get_chat_client_name_stub(uint64_t xuid, char* buffer, const size_t max_length)
{
utils::string::copy(buffer, max_length, utils::string::va("%llX-something", xuid));
OutputDebugStringA(buffer);
}
} }
class component final : public server_component const char* GetClientName(const uint64_t xuid)
{
if (xuid < 19 && !game::is_server())
{
char buffer[256];
game::CL_GetClientName(0, static_cast<int>(xuid - 1), buffer, sizeof(buffer), true);
return utils::string::va("%s\n", buffer);
}
return "Unknown Soldier";
}
uint64_t* divert_xuid_to_client_num_stub(int, int client_num, int)
{
static thread_local uint64_t value;
// zero xuid is invalid, so increase the clientnum to prevent 0 values
value = static_cast<uint64_t>(client_num) + 1;
return &value;
}
class component final : public generic_component
{ {
public: public:
void post_unpack() override void post_unpack() override
{ {
client_command::add("say", cmd_say_f); utils::hook::call(game::select(0x141974B04, 0x14029908A), divert_xuid_to_client_num_stub);
client_command::add("say_team", cmd_say_f);
client_command::add("chat", cmd_chat_f); if (game::is_server())
{
client_command::add("say", cmd_say_f);
client_command::add("say_team", cmd_say_f);
client_command::add("chat", cmd_chat_f);
}
else
{
// Ignore some check that suppresses the chat
utils::hook::nop(0x141DEA9BD_g, 2);
}
} }
}; };
} }

View File

@ -0,0 +1,6 @@
#pragma once
namespace chat
{
const char* GetClientName(const uint64_t xuid);
}

View File

@ -13,6 +13,9 @@ namespace game
int numPrivateSlots, const char* mapname, const char* gametype, int numPrivateSlots, const char* mapname, const char* gametype,
const char* somethingWithUserMaps)> CL_ConnectFromLobby const char* somethingWithUserMaps)> CL_ConnectFromLobby
{0x14134C570}; {0x14134C570};
WEAK symbol<bool(int localClientNum, int index, char* buf, int size, bool addClanName)> CL_GetClientName{
0x1413E3140
};
// Game // Game
WEAK symbol<void(gentity_s* ent, gentity_s* target, int mode, const char* chatText)> G_Say{0x0, 0x140299170}; WEAK symbol<void(gentity_s* ent, gentity_s* target, int mode, const char* chatText)> G_Say{0x0, 0x140299170};

View File

@ -4,6 +4,7 @@
#include <utils/nt.hpp> #include <utils/nt.hpp>
#include "component/name.hpp" #include "component/name.hpp"
#include "component/chat.hpp"
namespace steam namespace steam
{ {
@ -44,7 +45,7 @@ namespace steam
const char* friends::GetFriendPersonaName(steam_id steamIDFriend) const char* friends::GetFriendPersonaName(steam_id steamIDFriend)
{ {
return ""; return chat::GetClientName(steamIDFriend.bits);
} }
bool friends::GetFriendGamePlayed(steam_id steamIDFriend, void* pFriendGameInfo) bool friends::GetFriendGamePlayed(steam_id steamIDFriend, void* pFriendGameInfo)