Halflife: Fix non-english symbols in the chat

Created on 23 Aug 2013  路  6Comments  路  Source: ValveSoftware/halflife

Please fix non-english symbols in the chat. If the "dropshadow" property of the chat font is enabled, all utf-8 characters have missed right vertical column of pixels.

1
2
4
3
And bug in the notify
5

reviewed

Most helpful comment

@mikela-valve can you look at this?
Code by WPMGPRoSToTeMa which fixes bug.

#include <Windows.h>
#include <tchar.h>

BOOL WINAPI GetCharABCWidthsW_Hooked(void *pThis, HDC hdc, UINT wFirst, UINT wLast, LPABC lpABC)
{
    //MessageBox(NULL, _T("Hello!"), _T(""), MB_OK);

    BOOL bRet = GetCharABCWidthsW(hdc, wFirst, wLast, lpABC);

    lpABC->abcA = lpABC->abcA - *(int *)((byte *)pThis + 632);
    lpABC->abcB = lpABC->abcB + *(int *)((byte *)pThis + 48) + *(int *)((byte *)pThis + 632) * 2;
    lpABC->abcC = lpABC->abcC - *(int *)((byte *)pThis + 48) - *(int *)((byte *)pThis + 632);

    return bRet;
}

void __declspec(naked) GetCharABCWidthsW_Helper(HDC hdc, UINT wFirst, UINT wLast, LPABC lpABC)
{
    _asm
    {
        push[esp]
        mov[esp + 4], ebp;
        jmp GetCharABCWidthsW_Hooked;
    }
}

BOOL WINAPI DllMain(HMODULE hDllHandle, DWORD dwReason, LPVOID lpReserved)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCTSTR)&DllMain, &hDllHandle);

        HMODULE hEngine = GetModuleHandle(_T("hw.dll"));
        byte *pCall = (byte *)hEngine + 0xCF410;
        DWORD dwOldProt;
        VirtualProtect(pCall, 6, PAGE_EXECUTE_READWRITE, &dwOldProt);
        *pCall = 0xE8;
        *(long *)(pCall + 1) = (long)&GetCharABCWidthsW_Helper - ((long)pCall + 5);
        *(pCall + 5) = 0x90;
        VirtualProtect(pCall, 6, dwOldProt, &dwOldProt);
    }

    return TRUE;
}

All 6 comments

Added screenshots

This is on Windows right?

Yes, XP and 7. Linux version gives right result.
If I remember correctly, the same problem was in old builds of source engine.

You will fix it ?

@mikela-valve can you look at this?
Code by WPMGPRoSToTeMa which fixes bug.

#include <Windows.h>
#include <tchar.h>

BOOL WINAPI GetCharABCWidthsW_Hooked(void *pThis, HDC hdc, UINT wFirst, UINT wLast, LPABC lpABC)
{
    //MessageBox(NULL, _T("Hello!"), _T(""), MB_OK);

    BOOL bRet = GetCharABCWidthsW(hdc, wFirst, wLast, lpABC);

    lpABC->abcA = lpABC->abcA - *(int *)((byte *)pThis + 632);
    lpABC->abcB = lpABC->abcB + *(int *)((byte *)pThis + 48) + *(int *)((byte *)pThis + 632) * 2;
    lpABC->abcC = lpABC->abcC - *(int *)((byte *)pThis + 48) - *(int *)((byte *)pThis + 632);

    return bRet;
}

void __declspec(naked) GetCharABCWidthsW_Helper(HDC hdc, UINT wFirst, UINT wLast, LPABC lpABC)
{
    _asm
    {
        push[esp]
        mov[esp + 4], ebp;
        jmp GetCharABCWidthsW_Hooked;
    }
}

BOOL WINAPI DllMain(HMODULE hDllHandle, DWORD dwReason, LPVOID lpReserved)
{
    if (dwReason == DLL_PROCESS_ATTACH)
    {
        GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_PIN, (LPCTSTR)&DllMain, &hDllHandle);

        HMODULE hEngine = GetModuleHandle(_T("hw.dll"));
        byte *pCall = (byte *)hEngine + 0xCF410;
        DWORD dwOldProt;
        VirtualProtect(pCall, 6, PAGE_EXECUTE_READWRITE, &dwOldProt);
        *pCall = 0xE8;
        *(long *)(pCall + 1) = (long)&GetCharABCWidthsW_Helper - ((long)pCall + 5);
        *(pCall + 5) = 0x90;
        VirtualProtect(pCall, 6, dwOldProt, &dwOldProt);
    }

    return TRUE;
}

@kisak-valve fix proposal?

Was this page helpful?
0 / 5 - 0 ratings