[CardTitles] Refactored CardTitle code.

This commit is contained in:
RektInator 2017-05-30 23:39:57 +02:00
parent f6b855e3c1
commit e55f807003
2 changed files with 65 additions and 86 deletions

View File

@ -61,103 +61,81 @@ namespace Components
} }
} }
void __declspec(naked) CardTitles::LocalizationSkipHookStub() const char* CardTitles::TableLookupByRowHook(Game::Operand* operand, tablelookuprequest_s* request)
{ {
__asm std::uint8_t prefix = (request->tableRow >> (8 * 3)) & 0xFF;
std::uint8_t data = (request->tableRow >> (8 * 2)) & 0xFF;
const char* title = nullptr;
if (request->tablename == "mp/cardTitleTable.csv"s)
{ {
cmp byte ptr[edi + 01h], 0FFh; // Check if skip prefix exists (edi + 0x00 = @) if (prefix != 0x00)
jne back; {
add edi, 2; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix) // Column 1 = CardTitle
jmp jumpback; if (request->tableColumn == 1)
{
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->current.string)
{
title = Utils::String::VA("\x15%s", CustomTitleDvar->current.string);
back: // prepare return value
add edi, 1; operand->internals.stringVal.string = title;
push edi; operand->dataType = Game::VAL_STRING;
mov eax, 4F1700h; return title;
call eax; }
}
else if (prefix == 0xFF)
{
if (!CustomTitles[data].empty())
{
title = Utils::String::VA("\x15%s", CustomTitles[data].data());
add esp, 4; // prepare return value
mov edi, eax; operand->internals.stringVal.string = title;
operand->dataType = Game::VAL_STRING;
jumpback: return title;
push 63A2E3h; }
retn; }
}
// If the title was changed it already returned at this point so...
// Remove prefix and data to make being readable to the normal lookuprequest
request->tableRow = static_cast<std::int32_t>(*(reinterpret_cast<WORD*>(&request->tableRow)));
}
} }
return nullptr;
} }
void __declspec(naked) CardTitles::TableLookupByRowHookStub() void __declspec(naked) CardTitles::TableLookupByRowHookStub()
{ {
static tablelookuprequest_s* currentLookupRequest;
static tablelookupresult_s* currentLookupResult;
static std::int32_t prefix;
static std::int32_t data;
static const char* title;
__asm __asm
{ {
mov currentLookupRequest, esi; push esi;
mov currentLookupResult, ebx; push ebx;
}
pushad;
call TableLookupByRowHook;
cmp eax, 0;
popad;
prefix = (currentLookupRequest->tableRow >> (8 * 3)) & 0xff; jz OriginalTitle;
data = (currentLookupRequest->tableRow >> (8 * 2)) & 0xff;
//So we don't accidentally mess up other tables that might have a ridiculous amount of rows. Who knows. add esp, 8;
if (!strcmp(currentLookupRequest->tablename, "mp/cardTitleTable.csv"))
{
if (prefix != 0x00)
{
// Column 1 = CardTitle
if (currentLookupRequest->tableColumn == 1)
{
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 ((BYTE)*CustomTitleDvar->current.string)
{
title = Utils::String::VA("\xFF%s", CustomTitleDvar->current.string);
currentLookupResult->result = title;
currentLookupResult->dunno = 2; // Seems to be nessecary. Don't ask me why.
__asm pop ecx;
{ mov ecx, DWORD ptr[esi + 4];
mov eax, title; retn;
pop ecx;
mov ecx, currentLookupRequest;
mov ecx, DWORD ptr[ecx + 4];
retn;
}
}
}
else if (prefix == 0xFF)
{
if (!CustomTitles[data].empty())
{
title = Utils::String::VA("\xFF%s", CustomTitles[data].data());
currentLookupResult->result = title;
currentLookupResult->dunno = 2;
__asm OriginalTitle:
{
mov eax, title; add esp, 8;
pop ecx;
mov ecx, currentLookupRequest;
mov ecx, DWORD ptr[ecx + 4];
retn;
}
}
}
}
// If the title was changed it already returned at this point so...
// Remove prefix and data to make being readable to the normal lookuprequest
currentLookupRequest->tableRow = static_cast<std::int32_t>(*(reinterpret_cast<WORD*>(&currentLookupRequest->tableRow)));
}
}
// Continue with the normal lookup request because we did not use our custom result
__asm
{
mov eax, [esi + 50h]; mov eax, [esi + 50h];
cmp eax, 3; cmp eax, 3;
@ -208,9 +186,13 @@ namespace Components
CardTitles::CustomTitles.resize(18); CardTitles::CustomTitles.resize(18);
Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick(); Utils::Hook(0x62EB26, GetPlayerCardClientInfoStub).install()->quick();
Utils::Hook(0x63A2D5, LocalizationSkipHookStub).install()->quick();
Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick();
// Translation fixup
// Utils::Hook(0x63A2D9, LocalizationSkipHookStub).install()->quick();
// Utils::Hook::Nop(0x63A2D5, 3);
// Table lookup stuff
Utils::Hook(0x62DCC1, TableLookupByRowHookStub).install()->quick();
Utils::Hook::Nop(0x62DCC6, 1); Utils::Hook::Nop(0x62DCC6, 1);
} }

View File

@ -11,11 +11,6 @@ namespace Components
std::uint8_t padding3[4]; std::uint8_t padding3[4];
std::int32_t tableColumn; std::int32_t tableColumn;
}; };
struct tablelookupresult_s
{
std::uint32_t dunno;
const char* result;
};
struct playercarddata_s struct playercarddata_s
{ {
std::uint32_t padding; std::uint32_t padding;
@ -71,7 +66,9 @@ namespace Components
static CClient * GetClientByIndex(std::uint32_t index); static CClient * GetClientByIndex(std::uint32_t index);
static std::int32_t GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s * data); static std::int32_t GetPlayerCardClientInfo(std::int32_t lookupResult, playercarddata_s * data);
static void GetPlayerCardClientInfoStub(); static void GetPlayerCardClientInfoStub();
static const char* LocalizationSkipHook(const char * string);
static void LocalizationSkipHookStub(); static void LocalizationSkipHookStub();
static const char* TableLookupByRowHook(Game::Operand * operand, tablelookuprequest_s * request);
static void TableLookupByRowHookStub(); static void TableLookupByRowHookStub();
}; };