elishacloud / Silent-Hill-2-Enhancements

A project designed to enhance Silent Hill 2 (SH2) graphics and audio for the PC. It also includes scripts to build or modify SH2 audio files (SFX, BGM and Dialog).
http://www.enhanced.townofsilenthill.com/SH2/
zlib License
597 stars 42 forks source link

Missing HDD space values on the Save screen #544

Closed IlDucci closed 2 years ago

IlDucci commented 2 years ago

As someone else noted on Twitter, the modification that allows for changing the measure unit and values of the HDD free space is targeted at the English text: imagen

There's one additional thing, as well. Have you considered the decimal character used? Because, for example, Spanish uses a comma instead of a period to identify the decimal values.

Bruno3589 commented 2 years ago

Hi, as I said in the italian translation issue I also found out while testing the new update yesterday. Apparently there are 2 issues which, as I found out, happen in all languages except English:

1- There's an extra "KB" measure unit This is because, before the change, the measure unit was hardcoded into the language files, instead now it's determined dynamically based on free space. The fix is fairly easy, just remove the extra "KB" from the corresponding strings.

2- There are 2 missing letters in the string Not sure why this happens but as you said it's probably related to the change being targeted specifically at English text. I dug a little deeper today by trying to switch between languages and I found out a common pattern: the two missing letters are always the 17th and 18th characters. IT= Spazio disponib__e: FR= Espace disponib__: DE= Freier Speicher__atz: ES= Espacio libre: __

This is not an issue in the language files as the string is fine, so it's probably something in the code. There's no hurry however, both @elishacloud and @Polymega are on a well deserved holiday break now.

As for the decimal character used I don't think it affects the game since it's a system setting, but I could be wrong. In Italian we use a period and it displays correctly.

Polymega commented 2 years ago

This is because, before the change, the measure unit was hardcoded into the language files, instead now it's determined dynamically based on free space. The fix is fairly easy, just remove the extra "KB" from the corresponding strings.

That shouldn't be needed and I'd recommend keeping it in the string. You can see KB is removed with this use of this fix here: https://github.com/elishacloud/Silent-Hill-2-Enhancements/commit/39e5c189358bac34e568ed58406b15bfbe2d31ee#diff-63598fdbd07f8394383041a86630d062d6af161477d78d47028be69ec63c0fceR134-R146

I dug a little deeper today by trying to switch between languages and I found out a common pattern: the two missing letters are always the 17th and 18th characters.

Nice. Finding a correlation with the text display error can help hone in on the issue. Thanks.

Polymega commented 2 years ago

Steam006, being the wonderful person he is, has been keeping eyes on tickets and sent me a fix for this issue. Steam006, I know you'll be reading this, so thank you again for all your help.

int __cdecl SilentHill2_PC_Fix_TextToGame(unsigned __int16* a1, unsigned __int16 a2)
{
    //_cprintf_s("TextToGame --> %d\n", a2);

    int ToG = oTextToGame(a1, a2);

    if (a2 == 147)
    {
        BYTE Lang[32] = { 0 };
        SIZE_T BytesRead = 0;

        ReadProcessMemory(GetCurrentProcess(), ((LPVOID)ToG), Lang, sizeof(Lang), &BytesRead);

        BYTE RemoveKBPatch[2] = { 0x00, 0x00 };

        if (Lang[0x10] == 0x2B && Lang[0x11] == 0x22)
        {
            //English
            WriteToMemory(ToG + 0x10, RemoveKBPatch, 2);
        }
        else if (Lang[0x1B] == 0x2B && Lang[0x1C] == 0x22)
        {
            //German
            WriteToMemory(ToG + 0x1B, RemoveKBPatch, 2);
        }
        else if (Lang[0x1A] == 0x2B && Lang[0x1B] == 0x22)
        {
            //French
            WriteToMemory(ToG + 0x1A, RemoveKBPatch, 2);
        }
        else if (Lang[0x16] == 0x2B && Lang[0x17] == 0x22)
        {
            //Italian
            WriteToMemory(ToG + 0x16, RemoveKBPatch, 2);
        }
        else if (Lang[0x15] == 0x2B && Lang[0x16] == 0x22)
        {
            //Spanish
            WriteToMemory(ToG + 0x15, RemoveKBPatch, 2);
        }
    }

    return ToG;
}
IlDucci commented 2 years ago

That looks fantastic, but I think you are still making this solution incompatible with any non-official language translations, like Russians or Turkishes. Better than nothing, though.

I still think it's best to alter the .mes file.

Polymega commented 2 years ago

I still think it's best to alter the .mes file.

For fan translation packs, the .mes file will need to be altered, of course, but we ought to find a way to where you don't have to alter/remove the <VARIABLE-01> KB part of this string.

That way, in case someone disables this feature for whatever reason, it'll still display the original ___ KB measurement like normal. Let's look into this a bit more.

Polymega commented 2 years ago

Steam006 got back to me with the following:

This is a better solution that should work with fan translations and won't patch the language file if the "KB" text is not there.

bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
    for (; *szMask; ++szMask, ++pData, ++bMask)
        if (*szMask == 'x' && *pData != *bMask)
            return false;

    return *szMask == NULL;
}

DWORD FindPattern(DWORD ImageBase, DWORD SizeOfImage, const BYTE* Pattern, const char* szMask)
{
    for (DWORD i = 0; i < SizeOfImage; i++)
        if (Compare((BYTE*)(ImageBase + i), Pattern, szMask))
            return ImageBase + i;

    return 0;
}

int __cdecl SilentHill2_PC_Fix_TextToGame(unsigned __int16* a1, unsigned __int16 a2)
{
    //_cprintf_s("TextToGame --> %d\n", a2);

    int TTG = oTextToGame(a1, a2);

    if (a2 == 147)
    {
        DWORD KBText = FindPattern((DWORD)TTG, 50, (BYTE*)"\x2B\x22\xFF\xFF", "xxxx");

        if (KBText != 0)
        {
            BYTE RemoveKBPatch[2] = { 0x00, 0x00 };
            WriteToMemory(KBText, RemoveKBPatch, 2);
        }
    }
    return TTG;
}
elishacloud commented 2 years ago

Thanks @Steam006. I put the fix in for this. Here is a new build with the fix in it: d3d8.zip

Edit: here is a new update: d3d8.zip

Bruno3589 commented 2 years ago

Thanks everyone! Did a quick test right now, both problems seem solved at least with all five official languages, text is displayed correctly and there is no double measure unit. Nice job!

Polymega commented 2 years ago

Thanks Steam006 and Elisha.

Screenshot 2022-07-05 18-04-08