2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2017-05-30 07:45:19 -04:00
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
char CardTitles::CustomTitles[Game::MAX_CLIENTS][18];
|
2022-07-16 17:24:26 -04:00
|
|
|
Dvar::Var CardTitles::CustomTitle;
|
2017-05-30 07:45:19 -04:00
|
|
|
|
|
|
|
CClient* CardTitles::GetClientByIndex(std::uint32_t index)
|
|
|
|
{
|
2017-05-31 04:33:18 -04:00
|
|
|
return &reinterpret_cast<CClient*>(0x8E77B0)[index];
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
int CardTitles::GetPlayerCardClientInfo(int lookupResult, Game::PlayerCardData* data)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
auto result = lookupResult;
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
const auto* username = Dvar::Var("name").get<const char*>();
|
|
|
|
if (std::strcmp(data->name, username) == 0)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
result += 0xFE000000;
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
2017-06-14 06:06:04 -04:00
|
|
|
else
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
CClient* c = GetClientByIndex(i);
|
2017-06-14 06:06:04 -04:00
|
|
|
if (c != nullptr)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-07-16 17:24:26 -04:00
|
|
|
if (!std::strcmp(data->name, c->Name))
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
|
|
|
// Since a 4 byte integer is overkill for a row num: We can use it to store the customprefix + clientNum and use a 2 byte integer for the row number
|
2022-12-25 12:23:53 -05:00
|
|
|
result += 0xFF000000;
|
|
|
|
result += i * 0x10000;
|
2017-05-30 07:45:19 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
return result;
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
2017-05-31 03:59:03 -04:00
|
|
|
|
2017-05-30 07:45:19 -04:00
|
|
|
void __declspec(naked) CardTitles::GetPlayerCardClientInfoStub()
|
|
|
|
{
|
2017-06-14 06:06:04 -04:00
|
|
|
__asm
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2017-05-31 03:59:03 -04:00
|
|
|
push eax
|
|
|
|
pushad
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2017-05-31 03:59:03 -04:00
|
|
|
push esi
|
|
|
|
push eax
|
|
|
|
call GetPlayerCardClientInfo
|
|
|
|
add esp, 8
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2017-05-31 03:59:03 -04:00
|
|
|
mov [esp + 20h], eax
|
|
|
|
popad
|
|
|
|
pop eax
|
|
|
|
|
|
|
|
pop esi
|
|
|
|
pop ebp
|
2017-06-14 06:06:04 -04:00
|
|
|
mov [ebx + 4], eax
|
2017-05-31 03:59:03 -04:00
|
|
|
pop ebx
|
|
|
|
|
|
|
|
retn
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 17:39:57 -04:00
|
|
|
const char* CardTitles::TableLookupByRowHook(Game::Operand* operand, tablelookuprequest_s* request)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2017-06-14 06:06:04 -04:00
|
|
|
std::uint8_t prefix = (request->tableRow >> (8 * 3)) & 0xFF;
|
|
|
|
std::uint8_t data = (request->tableRow >> (8 * 2)) & 0xFF;
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
if (data >= Game::MAX_CLIENTS) return nullptr;
|
2017-06-02 09:36:20 -04:00
|
|
|
|
2017-05-30 17:39:57 -04:00
|
|
|
if (request->tablename == "mp/cardTitleTable.csv"s)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2017-05-30 17:39:57 -04:00
|
|
|
if (prefix != 0x00)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
|
|
|
// Column 1 = CardTitle
|
2017-05-30 17:39:57 -04:00
|
|
|
if (request->tableColumn == 1)
|
|
|
|
{
|
|
|
|
if (prefix == 0xFE)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
if (!CustomTitle.get<std::string>().empty())
|
2017-05-31 04:33:18 -04:00
|
|
|
{
|
|
|
|
// 0xFF in front of the title to skip localization. Or else it will wait for a couple of seconds for the asset of type localize
|
2022-12-25 12:23:53 -05:00
|
|
|
const auto* title = Utils::String::VA("\x15%s", CustomTitle.get<const char*>());
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
// prepare return value
|
|
|
|
operand->internals.stringVal.string = title;
|
|
|
|
operand->dataType = Game::VAL_STRING;
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
return title;
|
|
|
|
}
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
2017-05-30 17:39:57 -04:00
|
|
|
else if (prefix == 0xFF)
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
if (CustomTitles[data][0] != '\0')
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
const auto* title = Utils::String::VA("\x15%s", CustomTitles[data]);
|
2017-05-30 17:39:57 -04:00
|
|
|
|
|
|
|
// prepare return value
|
|
|
|
operand->internals.stringVal.string = title;
|
|
|
|
operand->dataType = Game::VAL_STRING;
|
|
|
|
|
|
|
|
return title;
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-30 07:45:19 -04:00
|
|
|
// If the title was changed it already returned at this point so...
|
|
|
|
// Remove prefix and data to make being readable to the normal lookuprequest
|
2017-05-30 17:39:57 -04:00
|
|
|
request->tableRow = static_cast<std::int32_t>(*(reinterpret_cast<WORD*>(&request->tableRow)));
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 17:39:57 -04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
__declspec(naked) void CardTitles::TableLookupByRowHookStub()
|
2017-05-30 17:39:57 -04:00
|
|
|
{
|
2017-06-14 06:06:04 -04:00
|
|
|
__asm
|
2017-05-30 07:45:19 -04:00
|
|
|
{
|
2017-05-31 04:33:18 -04:00
|
|
|
push eax
|
|
|
|
pushad
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
push esi
|
|
|
|
push ebx
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
call TableLookupByRowHook
|
|
|
|
add esp, 8
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
mov [esp + 20h], eax
|
|
|
|
popad
|
|
|
|
pop eax
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
cmp eax, 0
|
|
|
|
jz OriginalTitle
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
pop ecx
|
|
|
|
mov ecx, DWORD ptr[esi + 4]
|
|
|
|
retn
|
|
|
|
|
|
|
|
OriginalTitle:
|
2017-05-30 17:39:57 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
mov eax, [esi + 50h]
|
|
|
|
cmp eax, 3
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2017-05-31 04:33:18 -04:00
|
|
|
push 62DCC7h
|
|
|
|
retn
|
2017-05-30 07:45:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-14 06:06:04 -04:00
|
|
|
void CardTitles::SendCustomTitlesToClients()
|
2017-05-30 18:27:08 -04:00
|
|
|
{
|
2017-05-31 04:33:18 -04:00
|
|
|
std::string list;
|
2017-05-30 18:27:08 -04:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i)
|
2017-05-30 18:27:08 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
char playerTitle[18]{};
|
2017-05-30 18:27:08 -04:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
if (Game::svs_clients[i].userinfo[0] != '\0')
|
2017-05-30 18:27:08 -04:00
|
|
|
{
|
2022-07-16 17:24:26 -04:00
|
|
|
strncpy_s(playerTitle, Game::Info_ValueForKey(Game::svs_clients[i].userinfo, "customTitle"), _TRUNCATE);
|
2017-05-30 18:27:08 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-16 17:24:26 -04:00
|
|
|
playerTitle[0] = '\0';
|
2017-05-30 18:27:08 -04:00
|
|
|
}
|
|
|
|
|
2022-12-11 12:54:24 -05:00
|
|
|
list.append(std::format("\\{}\\{}", std::to_string(i), playerTitle));
|
2017-05-30 18:27:08 -04:00
|
|
|
}
|
|
|
|
|
2022-12-11 12:54:24 -05:00
|
|
|
const auto* command = Utils::String::Format("{:c} customTitles \"{}\"", 21, list);
|
2022-05-31 11:57:44 -04:00
|
|
|
Game::SV_GameSendServerCommand(-1, Game::SV_CMD_CAN_IGNORE, command);
|
2017-05-30 18:27:08 -04:00
|
|
|
}
|
|
|
|
|
2017-06-14 06:06:04 -04:00
|
|
|
void CardTitles::ParseCustomTitles(const char* msg)
|
2017-05-30 08:29:09 -04:00
|
|
|
{
|
2022-07-16 17:24:26 -04:00
|
|
|
for (std::size_t i = 0; i < Game::MAX_CLIENTS; ++i)
|
2017-05-30 08:29:09 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
const auto index = std::to_string(i);
|
|
|
|
const auto* playerTitle = Game::Info_ValueForKey(msg, index.data());
|
2017-05-30 08:29:09 -04:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
if (playerTitle[0] == '\0')
|
|
|
|
{
|
|
|
|
CustomTitles[i][0] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Game::I_strncpyz(CustomTitles[i], playerTitle, sizeof(CustomTitles[0]) / sizeof(char));
|
|
|
|
}
|
2017-05-30 08:29:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 07:45:19 -04:00
|
|
|
CardTitles::CardTitles()
|
|
|
|
{
|
2022-05-27 06:19:28 -04:00
|
|
|
Scheduler::Once([]
|
2017-05-31 03:59:03 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
CustomTitle = Dvar::Register<const char*>("customTitle", "", Game::DVAR_USERINFO | Game::DVAR_ARCHIVE, "Custom card title");
|
2022-05-27 06:19:28 -04:00
|
|
|
}, Scheduler::Pipeline::MAIN);
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
std::memset(&CustomTitles, 0, sizeof(char[Game::MAX_CLIENTS][18]));
|
|
|
|
|
2017-05-31 03:59:03 -04:00
|
|
|
ServerCommands::OnCommand(21, [](Command::Params* params)
|
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
if (std::strcmp(params->get(1), "customTitles") == 0)
|
2017-05-30 08:29:09 -04:00
|
|
|
{
|
2022-03-17 14:50:20 -04:00
|
|
|
if (params->size() == 3)
|
2017-05-30 08:29:09 -04:00
|
|
|
{
|
2022-12-25 12:23:53 -05:00
|
|
|
ParseCustomTitles(params->get(2));
|
2017-05-30 08:29:09 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2022-12-25 12:23:53 -05:00
|
|
|
Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick();
|
2017-05-30 07:45:19 -04:00
|
|
|
|
2017-05-30 17:39:57 -04:00
|
|
|
// Table lookup stuff
|
2022-12-25 12:23:53 -05:00
|
|
|
Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick();
|
2017-05-30 07:45:19 -04:00
|
|
|
Utils::Hook::Nop(0x62DCC6, 1);
|
|
|
|
}
|
2017-05-31 04:33:18 -04:00
|
|
|
}
|