[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
{
cmp byte ptr[edi + 01h], 0FFh; // Check if skip prefix exists (edi + 0x00 = @)
jne back;
add edi, 2; // Ignore the 0x40 and 0xFF prefix (Localize and Skip prefix)
jmp jumpback;
std::uint8_t prefix = (request->tableRow >> (8 * 3)) & 0xFF;
std::uint8_t data = (request->tableRow >> (8 * 2)) & 0xFF;
const char* title = nullptr;
back:
add edi, 1;
push edi;
mov eax, 4F1700h;
call eax;
add esp, 4;
mov edi, eax;
jumpback:
push 63A2E3h;
retn;
}
}
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
{
mov currentLookupRequest, esi;
mov currentLookupResult, ebx;
}
prefix = (currentLookupRequest->tableRow >> (8 * 3)) & 0xff;
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.
if (!strcmp(currentLookupRequest->tablename, "mp/cardTitleTable.csv"))
if (request->tablename == "mp/cardTitleTable.csv"s)
{
if (prefix != 0x00)
{
// Column 1 = CardTitle
if (currentLookupRequest->tableColumn == 1)
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 ((BYTE)*CustomTitleDvar->current.string)
if (*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.
title = Utils::String::VA("\x15%s", CustomTitleDvar->current.string);
__asm
{
mov eax, title;
pop ecx;
mov ecx, currentLookupRequest;
mov ecx, DWORD ptr[ecx + 4];
retn;
}
// prepare return value
operand->internals.stringVal.string = title;
operand->dataType = Game::VAL_STRING;
return title;
}
}
else if (prefix == 0xFF)
{
if (!CustomTitles[data].empty())
{
title = Utils::String::VA("\xFF%s", CustomTitles[data].data());
currentLookupResult->result = title;
currentLookupResult->dunno = 2;
title = Utils::String::VA("\x15%s", CustomTitles[data].data());
__asm
{
mov eax, title;
pop ecx;
mov ecx, currentLookupRequest;
mov ecx, DWORD ptr[ecx + 4];
retn;
}
// prepare return value
operand->internals.stringVal.string = title;
operand->dataType = Game::VAL_STRING;
return title;
}
}
}
// 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)));
request->tableRow = static_cast<std::int32_t>(*(reinterpret_cast<WORD*>(&request->tableRow)));
}
}
// Continue with the normal lookup request because we did not use our custom result
return nullptr;
}
void __declspec(naked) CardTitles::TableLookupByRowHookStub()
{
__asm
{
push esi;
push ebx;
pushad;
call TableLookupByRowHook;
cmp eax, 0;
popad;
jz OriginalTitle;
add esp, 8;
pop ecx;
mov ecx, DWORD ptr[esi + 4];
retn;
OriginalTitle:
add esp, 8;
mov eax, [esi + 50h];
cmp eax, 3;
@ -208,9 +186,13 @@ namespace Components
CardTitles::CustomTitles.resize(18);
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);
}

View File

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