Consider material text icons when calculating text width
This commit is contained in:
parent
0875a87e26
commit
57e305277b
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
char Colors::LastColorIndex;
|
||||||
Dvar::Var Colors::NewColors;
|
Dvar::Var Colors::NewColors;
|
||||||
Dvar::Var Colors::ColorBlind;
|
Dvar::Var Colors::ColorBlind;
|
||||||
Game::dvar_t* Colors::ColorAllyColorBlind;
|
Game::dvar_t* Colors::ColorAllyColorBlind;
|
||||||
@ -147,6 +148,8 @@ namespace Components
|
|||||||
Utils::Hook::Set<char>(0x5A2E2E, limit); // No idea :P
|
Utils::Hook::Set<char>(0x5A2E2E, limit); // No idea :P
|
||||||
|
|
||||||
Utils::Hook::Set<char>(0x5A2733, limit - '0'); // No idea :P
|
Utils::Hook::Set<char>(0x5A2733, limit - '0'); // No idea :P
|
||||||
|
|
||||||
|
LastColorIndex = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
char Colors::Add(uint8_t r, uint8_t g, uint8_t b)
|
char Colors::Add(uint8_t r, uint8_t g, uint8_t b)
|
||||||
|
@ -5,6 +5,8 @@ namespace Components
|
|||||||
class Colors : public Component
|
class Colors : public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
static char LastColorIndex;
|
||||||
|
|
||||||
Colors();
|
Colors();
|
||||||
~Colors();
|
~Colors();
|
||||||
|
|
||||||
|
@ -278,6 +278,61 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Materials::R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font)
|
||||||
|
{
|
||||||
|
auto lineWidth = 0;
|
||||||
|
auto maxWidth = 0;
|
||||||
|
|
||||||
|
if (maxChars <= 0)
|
||||||
|
maxChars = 0x7FFFFFFF;
|
||||||
|
|
||||||
|
if (text == nullptr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
auto count = 0;
|
||||||
|
while (*text && count < maxChars)
|
||||||
|
{
|
||||||
|
const auto letter = Game::SEH_ReadCharFromString(&text, nullptr);
|
||||||
|
if (letter == '\r' || letter == '\n')
|
||||||
|
{
|
||||||
|
lineWidth = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (letter == '^' && text)
|
||||||
|
{
|
||||||
|
if (*text >= '0' && *text <= Colors::LastColorIndex)
|
||||||
|
{
|
||||||
|
text += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*text >= '\x01' && *text <= '\x02' && text[1] != '\0' && text[2] != '\0' && text[3] != '\0')
|
||||||
|
{
|
||||||
|
const auto width = text[1];
|
||||||
|
const auto materialNameLength = text[3];
|
||||||
|
|
||||||
|
auto v9 = font->pixelHeight * (text[1] - 16) + 16;
|
||||||
|
auto w = ((((v9 >> 24) & 0x1F) + (signed int)v9) >> 5);
|
||||||
|
|
||||||
|
lineWidth += w;
|
||||||
|
|
||||||
|
text += 3;
|
||||||
|
for (auto currentLength = 0; currentLength < materialNameLength && *text; currentLength++)
|
||||||
|
text++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lineWidth += R_GetCharacterGlyph(font, letter)->dx;
|
||||||
|
if (lineWidth > maxWidth)
|
||||||
|
maxWidth = lineWidth;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return maxWidth;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Materials::Materials()
|
Materials::Materials()
|
||||||
@ -302,6 +357,9 @@ namespace Components
|
|||||||
// Debug material comparison
|
// Debug material comparison
|
||||||
Utils::Hook::Set<void*>(0x523894, Materials::MaterialComparePrint);
|
Utils::Hook::Set<void*>(0x523894, Materials::MaterialComparePrint);
|
||||||
|
|
||||||
|
// Consider material text icons when calculating text width
|
||||||
|
Utils::Hook(0x5056C0, Materials::R_TextWidth_Hk, HOOK_JUMP).install()->quick();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (Flags::HasFlag("dump"))
|
if (Flags::HasFlag("dump"))
|
||||||
{
|
{
|
||||||
|
@ -33,6 +33,8 @@ namespace Components
|
|||||||
static int WriteDeathMessageIcon(char* string, int offset, Game::Material* material);
|
static int WriteDeathMessageIcon(char* string, int offset, Game::Material* material);
|
||||||
static void DeathMessageStub();
|
static void DeathMessageStub();
|
||||||
|
|
||||||
|
static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
static void DumpImageCfg(int, const char*, const char* material);
|
static void DumpImageCfg(int, const char*, const char* material);
|
||||||
static void DumpImageCfgPath(int, const char*, const char* material);
|
static void DumpImageCfgPath(int, const char*, const char* material);
|
||||||
|
@ -279,6 +279,7 @@ namespace Game
|
|||||||
SE_Load_t SE_Load = SE_Load_t(0x502A30);
|
SE_Load_t SE_Load = SE_Load_t(0x502A30);
|
||||||
|
|
||||||
SEH_StringEd_GetString_t SEH_StringEd_GetString = SEH_StringEd_GetString_t(0x44BB30);
|
SEH_StringEd_GetString_t SEH_StringEd_GetString = SEH_StringEd_GetString_t(0x44BB30);
|
||||||
|
SEH_ReadCharFromString_t SEH_ReadCharFromString = SEH_ReadCharFromString_t(0x486560);
|
||||||
|
|
||||||
Dvar_SetFromStringByName_t Dvar_SetFromStringByName = Dvar_SetFromStringByName_t(0x4F52E0);
|
Dvar_SetFromStringByName_t Dvar_SetFromStringByName = Dvar_SetFromStringByName_t(0x4F52E0);
|
||||||
Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource = Dvar_SetFromStringByNameFromSource_t(0x4FC770);
|
Dvar_SetFromStringByNameFromSource_t Dvar_SetFromStringByNameFromSource = Dvar_SetFromStringByNameFromSource_t(0x4FC770);
|
||||||
@ -1258,5 +1259,19 @@ namespace Game
|
|||||||
retn
|
retn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__declspec(naked) Glyph* R_GetCharacterGlyph(Font_s* font, unsigned int letter)
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
{
|
||||||
|
mov edi, [esp + 8]
|
||||||
|
push [esp+4]
|
||||||
|
mov eax, 0x5055C0
|
||||||
|
call eax
|
||||||
|
add esp,0x4
|
||||||
|
|
||||||
|
retn
|
||||||
|
}
|
||||||
|
}
|
||||||
#pragma optimize("", on)
|
#pragma optimize("", on)
|
||||||
}
|
}
|
||||||
|
@ -669,6 +669,9 @@ namespace Game
|
|||||||
typedef char* (__cdecl * SEH_StringEd_GetString_t)(const char* string);
|
typedef char* (__cdecl * SEH_StringEd_GetString_t)(const char* string);
|
||||||
extern SEH_StringEd_GetString_t SEH_StringEd_GetString;
|
extern SEH_StringEd_GetString_t SEH_StringEd_GetString;
|
||||||
|
|
||||||
|
typedef int (__cdecl* SEH_ReadCharFromString_t)(const char** text, int* isTrailingPunctuation);
|
||||||
|
extern SEH_ReadCharFromString_t SEH_ReadCharFromString;
|
||||||
|
|
||||||
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
|
typedef char* (__cdecl * SL_ConvertToString_t)(unsigned short stringValue);
|
||||||
extern SL_ConvertToString_t SL_ConvertToString;
|
extern SL_ConvertToString_t SL_ConvertToString;
|
||||||
|
|
||||||
@ -951,4 +954,6 @@ namespace Game
|
|||||||
void R_AddDebugString(float *color, float *pos, float scale, const char *str);
|
void R_AddDebugString(float *color, float *pos, float scale, const char *str);
|
||||||
void R_AddDebugBounds(float* color, Bounds* b);
|
void R_AddDebugBounds(float* color, Bounds* b);
|
||||||
void R_AddDebugBounds(float* color, Bounds* b, const float(*quat)[4]);
|
void R_AddDebugBounds(float* color, Bounds* b, const float(*quat)[4]);
|
||||||
|
|
||||||
|
Glyph* R_GetCharacterGlyph(Font_s* font, unsigned int letter);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user