[CardTitles] More fixes

This commit is contained in:
momo5502 2017-05-31 10:33:18 +02:00
parent 3e1b5df639
commit fbec01b237

View File

@ -7,7 +7,7 @@ namespace Components
CClient* CardTitles::GetClientByIndex(std::uint32_t index) CClient* CardTitles::GetClientByIndex(std::uint32_t index)
{ {
return reinterpret_cast<CClient*>(0x8E77B0 + (sizeof CClient * index)); return &reinterpret_cast<CClient*>(0x8E77B0)[index];
} }
std::int32_t CardTitles::GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s* data) std::int32_t CardTitles::GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s* data)
@ -25,7 +25,6 @@ namespace Components
for (auto clientNum = 0; clientNum < 18; clientNum++) for (auto clientNum = 0; clientNum < 18; clientNum++)
{ {
CClient* c = GetClientByIndex(clientNum); CClient* c = GetClientByIndex(clientNum);
if (c != nullptr) if (c != nullptr)
{ {
if (!strcmp(data->name, c->Name)) if (!strcmp(data->name, c->Name))
@ -82,14 +81,17 @@ namespace Components
{ {
if (prefix == 0xFE) if (prefix == 0xFE)
{ {
// 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 if (!CustomTitleDvar.get<std::string>().empty())
const char* title = Utils::String::VA("\x15%s", CustomTitleDvar.get<const char*>()); {
// 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
const char* title = Utils::String::VA("\x15%s", CustomTitleDvar.get<const char*>());
// prepare return value // prepare return value
operand->internals.stringVal.string = title; operand->internals.stringVal.string = title;
operand->dataType = Game::VAL_STRING; operand->dataType = Game::VAL_STRING;
return title; return title;
}
} }
else if (prefix == 0xFF) else if (prefix == 0xFF)
{ {
@ -115,41 +117,43 @@ namespace Components
return nullptr; return nullptr;
} }
void __declspec(naked) CardTitles::TableLookupByRowHookStub() __declspec(naked) void CardTitles::TableLookupByRowHookStub()
{ {
__asm __asm
{ {
push esi; push eax
push ebx; pushad
pushad;
call TableLookupByRowHook;
cmp eax, 0;
popad;
jz OriginalTitle; push esi
push ebx
add esp, 8; call TableLookupByRowHook
add esp, 8
pop ecx; mov [esp + 20h], eax
mov ecx, DWORD ptr[esi + 4]; popad
retn; pop eax
cmp eax, 0
jz OriginalTitle
pop ecx
mov ecx, DWORD ptr[esi + 4]
retn
OriginalTitle: OriginalTitle:
add esp, 8; mov eax, [esi + 50h]
cmp eax, 3
mov eax, [esi + 50h]; push 62DCC7h
cmp eax, 3; retn
push 62DCC7h;
retn;
} }
} }
void CardTitles::SendCustomTitlesToClients() void CardTitles::SendCustomTitlesToClients()
{ {
const char* list = ""; std::string list;
for (int i = 0; i < 18; i++) for (int i = 0; i < 18; i++)
{ {
@ -164,11 +168,11 @@ namespace Components
memset(playerTitle, 0, 18); memset(playerTitle, 0, 18);
} }
list = Utils::String::VA("%s\\%s\\%s", list, std::to_string(i).c_str(), playerTitle); list.append(Utils::String::VA("\\%s\\%s", std::to_string(i).c_str(), playerTitle));
} }
list = Utils::String::VA("%c customTitles \"%s\"", 21, list); std::string command = Utils::String::VA("%c customTitles \"%s\"", 21, list.data());
Game::SV_GameSendServerCommand(-1, 0, list); Game::SV_GameSendServerCommand(-1, 0, command.data());
} }
void CardTitles::ParseCustomTitles(const char* msg) void CardTitles::ParseCustomTitles(const char* msg)
@ -177,8 +181,8 @@ namespace Components
{ {
const char* playerTitle = Game::Info_ValueForKey(msg, std::to_string(i).c_str()); const char* playerTitle = Game::Info_ValueForKey(msg, std::to_string(i).c_str());
if (playerTitle) CustomTitles[i] = playerTitle; if (playerTitle) CardTitles::CustomTitles[i] = playerTitle;
else CustomTitles[i].clear(); else CardTitles::CustomTitles[i].clear();
} }
} }
@ -209,10 +213,10 @@ namespace Components
CardTitles::CustomTitles[i].clear(); CardTitles::CustomTitles[i].clear();
} }
Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); Utils::Hook(0x62EB26, CardTitles::GetPlayerCardClientInfoStub).install()->quick();
// Table lookup stuff // Table lookup stuff
Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick(); Utils::Hook(0x62DCC1, CardTitles::TableLookupByRowHookStub).install()->quick();
Utils::Hook::Nop(0x62DCC6, 1); Utils::Hook::Nop(0x62DCC6, 1);
} }
@ -223,4 +227,4 @@ namespace Components
CardTitles::CustomTitles[i].clear(); CardTitles::CustomTitles[i].clear();
} }
} }
} }