System announcement garbled code

Junior Spellweaver
Joined
May 13, 2020
Messages
177
Reaction score
22
1740842059349 - System announcement garbled code - RaGEZONE Forums

Other areas are displaying normally - only one system announcement has garbled text. But English letters and numbers display system announcements normally
 
The issue is likely related to encoding, as it may not support any characters other than letters and numbers (please check the macro definitions in your original code).
 
Upvote 0
The issue is likely related to encoding, as it may not support any characters other than letters and numbers (please check the macro definitions in your original code).
Dear God, should I check that file for specific directions? Should we look at that macro definition?
 
Upvote 0
Not sure if this will work, but you can give it a try (not tested yet).


Try replacing the AddTopAnnounce and AddCenterAnnounce functions with the code below:

C++:
    void CAnnounceRenderer::AddTopAnnounce(const std::string strAnnounce, const std::uint32_t nPlayerIndex) {
        AnnounceData data;

        auto pOldFont = g_Neuz.m_2DRender.GetFont();
        g_Neuz.m_2DRender.SetFont(CWndBase::m_Theme.m_pFontText);

        CEditString str;
        str.SetParsingString(strAnnounce.c_str());

        auto nRightPosition = g_Neuz.m_2DRender.m_clipRect.Width();

        std::string character;

        std::uint16_t index = 0;
        std::uint16_t charSize = 0;
        for (size_t i = 0; i < strAnnounce.size(); i += charSize) {
            textData chardata;
            charSize = (strAnnounce[i] & 0x80) == 0 ? 1 : 2;
            chardata.m_char = strAnnounce[i];
            if (charSize == 2 && i + 1 < strAnnounce.size()) {
                chardata.m_char = strAnnounce[i+1];
            }

            CEditString strEdit;
            strEdit.SetParsingString(character.c_str());

            chardata.m_nPositionX = nRightPosition + g_Neuz.m_2DRender.m_pFont->GetTextExtent_EditString(strEdit).cx;
            data.m_strAnnounce.push_back(chardata);
            character.append(strAnnounce.substr(i, charSize));
            index++;
        }

        g_Neuz.m_2DRender.SetFont(pOldFont);

        data.m_nPlayerCasterIndex = nPlayerIndex;
        m_vTopAnnounces.push_back(data);
    }
    
    void CAnnounceRenderer::AddCenterAnnounce(const std::string strAnnounce, const std::uint32_t nPlayerIndex) {
        AnnounceData data;

        auto pOldFont = g_Neuz.m_2DRender.GetFont();
        g_Neuz.m_2DRender.SetFont(CWndBase::m_Theme.m_pFontText);

        CEditString str;
        str.SetParsingString(strAnnounce.c_str());

        const std::uint16_t nRectWidth = 450;
        int pointX = (g_Neuz.m_2DRender.m_clipRect.Width() / 2) - (nRectWidth / 2);

        auto nRightPosition = pointX + nRectWidth;

        std::string character;

        std::uint16_t index = 0;
        std::uint16_t charSize = 0;
        for (size_t i = 0; i < strAnnounce.size(); i += charSize) {
            textData chardata;
            charSize = (strAnnounce[i] & 0x80) == 0 ? 1 : 2;
            chardata.m_char = strAnnounce[i];
            if (charSize == 2 && i + 1 < strAnnounce.size()) {
                chardata.m_char = strAnnounce[i+1];
            }

            CEditString strEdit;
            strEdit.SetParsingString(character.c_str());

            chardata.m_nPositionX = nRightPosition + g_Neuz.m_2DRender.m_pFont->GetTextExtent_EditString(strEdit).cx;
            data.m_strAnnounce.push_back(chardata);
            character.append(strAnnounce.substr(i, charSize));
            index++;
        }

        g_Neuz.m_2DRender.SetFont(pOldFont);

        data.m_nPlayerCasterIndex = nPlayerIndex;
        m_vCenteredAnnounces.push_back(data);
    }
 
Upvote 0
Not sure if this will work, but you can give it a try (not tested yet).


Try replacing the AddTopAnnounce and AddCenterAnnounce functions with the code below:

C++:
    void CAnnounceRenderer::AddTopAnnounce(const std::string strAnnounce, const std::uint32_t nPlayerIndex) {
        AnnounceData data;

        auto pOldFont = g_Neuz.m_2DRender.GetFont();
        g_Neuz.m_2DRender.SetFont(CWndBase::m_Theme.m_pFontText);

        CEditString str;
        str.SetParsingString(strAnnounce.c_str());

        auto nRightPosition = g_Neuz.m_2DRender.m_clipRect.Width();

        std::string character;

        std::uint16_t index = 0;
        std::uint16_t charSize = 0;
        for (size_t i = 0; i < strAnnounce.size(); i += charSize) {
            textData chardata;
            charSize = (strAnnounce[i] & 0x80) == 0 ? 1 : 2;
            chardata.m_char = strAnnounce[i];
            if (charSize == 2 && i + 1 < strAnnounce.size()) {
                chardata.m_char = strAnnounce[i+1];
            }

            CEditString strEdit;
            strEdit.SetParsingString(character.c_str());

            chardata.m_nPositionX = nRightPosition + g_Neuz.m_2DRender.m_pFont->GetTextExtent_EditString(strEdit).cx;
            data.m_strAnnounce.push_back(chardata);
            character.append(strAnnounce.substr(i, charSize));
            index++;
        }

        g_Neuz.m_2DRender.SetFont(pOldFont);

        data.m_nPlayerCasterIndex = nPlayerIndex;
        m_vTopAnnounces.push_back(data);
    }
   
    void CAnnounceRenderer::AddCenterAnnounce(const std::string strAnnounce, const std::uint32_t nPlayerIndex) {
        AnnounceData data;

        auto pOldFont = g_Neuz.m_2DRender.GetFont();
        g_Neuz.m_2DRender.SetFont(CWndBase::m_Theme.m_pFontText);

        CEditString str;
        str.SetParsingString(strAnnounce.c_str());

        const std::uint16_t nRectWidth = 450;
        int pointX = (g_Neuz.m_2DRender.m_clipRect.Width() / 2) - (nRectWidth / 2);

        auto nRightPosition = pointX + nRectWidth;

        std::string character;

        std::uint16_t index = 0;
        std::uint16_t charSize = 0;
        for (size_t i = 0; i < strAnnounce.size(); i += charSize) {
            textData chardata;
            charSize = (strAnnounce[i] & 0x80) == 0 ? 1 : 2;
            chardata.m_char = strAnnounce[i];
            if (charSize == 2 && i + 1 < strAnnounce.size()) {
                chardata.m_char = strAnnounce[i+1];
            }

            CEditString strEdit;
            strEdit.SetParsingString(character.c_str());

            chardata.m_nPositionX = nRightPosition + g_Neuz.m_2DRender.m_pFont->GetTextExtent_EditString(strEdit).cx;
            data.m_strAnnounce.push_back(chardata);
            character.append(strAnnounce.substr(i, charSize));
            index++;
        }

        g_Neuz.m_2DRender.SetFont(pOldFont);

        data.m_nPlayerCasterIndex = nPlayerIndex;
        m_vCenteredAnnounces.push_back(data);
    }
It doesn't work, but the garbled code changes the shape,
I think it is useful, but I need to adjust the code.
God, see where you need to modify it.

dc38f97e4ca493ae2411ca78651c249 - System announcement garbled code - RaGEZONE Forums
096cb89c1afb4e8a58a5bd6212f766 - System announcement garbled code - RaGEZONE Forums
 
Upvote 0
This should fix your problem

C#:
    void CAnnounceRenderer::RenderTopAnnounces(C2DRender* p2DRender) {
        CPoint point = CPoint(50, 5);

        if (m_vTopAnnounces.empty()) return;
        auto itAnnounce = m_vTopAnnounces.begin();

        RenderRectangles(p2DRender, CRect(point.x, point.y - 5, g_Neuz.m_2DRender.m_clipRect.Width() - 50, point.y + 20), itAnnounce->m_nAlpha, 50);

        for (auto itLetter = itAnnounce->m_strAnnounce.begin(); itLetter != itAnnounce->m_strAnnounce.end(); )
        {
            if (itLetter->m_nPositionX <= g_Neuz.m_2DRender.m_clipRect.Width())
            {
                std::string strLetter = itLetter->m_char;
                CEditString string;
                string.SetParsingString(strLetter.c_str(), D3DCOLOR_ARGB(255, 254, 254, 254));
                p2DRender->TextOut_EditString(itLetter->m_nPositionX, point.y, string);

                itLetter->m_nPositionX -= 2; // scroll speed

                if (itLetter->m_nPositionX <= 0)
                {
                    itLetter->m_nPositionX += g_Neuz.m_2DRender.m_clipRect.Width();
                    itLetter->m_nRoundsCount++;

                    if (itLetter->m_nRoundsCount >= MAX_ROUNDS_TOP)
                        itLetter = itAnnounce->m_strAnnounce.erase(itLetter);
                    else
                        ++itLetter;
                }
                else
                {
                    ++itLetter;
                }
            }
            else
            {
                ++itLetter;
            }
        }

        if (itAnnounce->m_strAnnounce.empty()) {
            if (itAnnounce->m_tDelay == 0) {
                if (std::distance(itAnnounce, m_vTopAnnounces.end()) == 1)
                    itAnnounce->m_tDelay = GetTickCount() + REMOVE_DELAY;
                else
                    m_vTopAnnounces.erase(itAnnounce);
            }
        }
    }

    void CAnnounceRenderer::RenderCenterAnnounces(C2DRender* p2DRender) {
        auto offSetY = (184 * p2DRender->m_clipRect.Height() / 768) - 120;
        if (m_vCenteredAnnounces.empty()) return;

        auto itAnnounce = m_vCenteredAnnounces.begin();

        std::string strFull;
        for (const auto& text : itAnnounce->m_strAnnounce) {
            strFull += text.m_char; // correct, supports full UTF-8 characters
        }


        CEditString str;
        str.SetParsingString(strFull.c_str());

        const std::uint16_t nRectWidth = 450;

        CPoint point = CPoint((p2DRender->m_clipRect.Width() / 2) - (nRectWidth / 2), offSetY);

        RenderRectangles(p2DRender, CRect(point.x, point.y - 5, point.x + nRectWidth, point.y + 20), itAnnounce->m_nAlpha, 50);

        for (auto itLetter = itAnnounce->m_strAnnounce.begin(); itLetter != itAnnounce->m_strAnnounce.end(); )
        {
            if (itLetter->m_nPositionX <= point.x + nRectWidth && itLetter->m_nPositionX >= point.x)
            {
                std::string strLetter = itLetter->m_char;

                CEditString string;
                string.SetParsingString(strLetter.c_str(), D3DCOLOR_ARGB(255, 254, 254, 254));

                p2DRender->TextOut_EditString(itLetter->m_nPositionX, point.y, string);
            }

            itLetter->m_nPositionX -= 2;

            ++itLetter;
        }

        if (itAnnounce->m_strAnnounce.empty()) {
            if (itAnnounce->m_tDelay == 0) {
            if( std::distance(itAnnounce, m_vCenteredAnnounces.end()) == 1)
                itAnnounce->m_tDelay = GetTickCount() + REMOVE_DELAY;
            else
                m_vCenteredAnnounces.erase(itAnnounce);
            }
        }
    }

Then replace the

C++:
    struct textData {
        char m_char = { 0, };
        std::int32_t m_nPositionX = 0;

        std::uint8_t m_nRoundsCount = 0;
    };

    struct AnnounceData {
        std::vector<textData> m_strAnnounce;
        std::uint32_t m_nPlayerCasterIndex = 0;

        __time64_t    m_tDelay = 0;
        std::int32_t m_nAlpha = ALPHA_BASE;
    };

to

C++:
    struct textData
    {
        std::string m_char;              // Full UTF-8 character

        std::int32_t m_nPositionX = 0;
        std::uint8_t m_nRoundsCount = 0;
    };


    struct AnnounceData {
        std::vector<textData> m_strAnnounce;   // now contains full UTF-8 character data
        std::uint32_t m_nPlayerCasterIndex = 0;

        __time64_t m_tDelay = 0;
        std::int32_t m_nAlpha = ALPHA_BASE;
    };

after this dont forget to create a new font on ITheme.cpp
Set the font to this.
C++:
Microsoft YaHei
 
Last edited:
Upvote 0
Not sure if this will work, but you can give it a try (not tested yet).


Try replacing the AddTopAnnounce and AddCenterAnnounce functions with the code below:

C++:
    void CAnnounceRenderer::AddTopAnnounce(const std::string strAnnounce, const std::uint32_t nPlayerIndex) {
        AnnounceData data;

        auto pOldFont = g_Neuz.m_2DRender.GetFont();
        g_Neuz.m_2DRender.SetFont(CWndBase::m_Theme.m_pFontText);

        CEditString str;
        str.SetParsingString(strAnnounce.c_str());

        auto nRightPosition = g_Neuz.m_2DRender.m_clipRect.Width();

        std::string character;

        std::uint16_t index = 0;
        std::uint16_t charSize = 0;
        for (size_t i = 0; i < strAnnounce.size(); i += charSize) {
            textData chardata;
            charSize = (strAnnounce[i] & 0x80) == 0 ? 1 : 2;
            chardata.m_char = strAnnounce[i];
            if (charSize == 2 && i + 1 < strAnnounce.size()) {
                chardata.m_char = strAnnounce[i+1];
            }

            CEditString strEdit;
            strEdit.SetParsingString(character.c_str());

            chardata.m_nPositionX = nRightPosition + g_Neuz.m_2DRender.m_pFont->GetTextExtent_EditString(strEdit).cx;
            data.m_strAnnounce.push_back(chardata);
            character.append(strAnnounce.substr(i, charSize));
            index++;
        }

        g_Neuz.m_2DRender.SetFont(pOldFont);

        data.m_nPlayerCasterIndex = nPlayerIndex;
        m_vTopAnnounces.push_back(data);
    }
  
    void CAnnounceRenderer::AddCenterAnnounce(const std::string strAnnounce, const std::uint32_t nPlayerIndex) {
        AnnounceData data;

        auto pOldFont = g_Neuz.m_2DRender.GetFont();
        g_Neuz.m_2DRender.SetFont(CWndBase::m_Theme.m_pFontText);

        CEditString str;
        str.SetParsingString(strAnnounce.c_str());

        const std::uint16_t nRectWidth = 450;
        int pointX = (g_Neuz.m_2DRender.m_clipRect.Width() / 2) - (nRectWidth / 2);

        auto nRightPosition = pointX + nRectWidth;

        std::string character;

        std::uint16_t index = 0;
        std::uint16_t charSize = 0;
        for (size_t i = 0; i < strAnnounce.size(); i += charSize) {
            textData chardata;
            charSize = (strAnnounce[i] & 0x80) == 0 ? 1 : 2;
            chardata.m_char = strAnnounce[i];
            if (charSize == 2 && i + 1 < strAnnounce.size()) {
                chardata.m_char = strAnnounce[i+1];
            }

            CEditString strEdit;
            strEdit.SetParsingString(character.c_str());

            chardata.m_nPositionX = nRightPosition + g_Neuz.m_2DRender.m_pFont->GetTextExtent_EditString(strEdit).cx;
            data.m_strAnnounce.push_back(chardata);
            character.append(strAnnounce.substr(i, charSize));
            index++;
        }

        g_Neuz.m_2DRender.SetFont(pOldFont);

        data.m_nPlayerCasterIndex = nPlayerIndex;
        m_vCenteredAnnounces.push_back(data);
    }
It doesn't work, but the garbled code changes the shape,
I think it is useful, but I need to adjust the code.
God, see where you need to modify it.

View attachment 279100View attachment 279101
This should fix your problem

C#:
    void CAnnounceRenderer::RenderTopAnnounces(C2DRender* p2DRender) {
        CPoint point = CPoint(50, 5);

        if (m_vTopAnnounces.empty()) return;
        auto itAnnounce = m_vTopAnnounces.begin();

        RenderRectangles(p2DRender, CRect(point.x, point.y - 5, g_Neuz.m_2DRender.m_clipRect.Width() - 50, point.y + 20), itAnnounce->m_nAlpha, 50);

        for (auto itLetter = itAnnounce->m_strAnnounce.begin(); itLetter != itAnnounce->m_strAnnounce.end(); )
        {
            if (itLetter->m_nPositionX <= g_Neuz.m_2DRender.m_clipRect.Width())
            {
                std::string strLetter = itLetter->m_char;
                CEditString string;
                string.SetParsingString(strLetter.c_str(), D3DCOLOR_ARGB(255, 254, 254, 254));
                p2DRender->TextOut_EditString(itLetter->m_nPositionX, point.y, string);

                itLetter->m_nPositionX -= 2; // scroll speed

                if (itLetter->m_nPositionX <= 0)
                {
                    itLetter->m_nPositionX += g_Neuz.m_2DRender.m_clipRect.Width();
                    itLetter->m_nRoundsCount++;

                    if (itLetter->m_nRoundsCount >= MAX_ROUNDS_TOP)
                        itLetter = itAnnounce->m_strAnnounce.erase(itLetter);
                    else
                        ++itLetter;
                }
                else
                {
                    ++itLetter;
                }
            }
            else
            {
                ++itLetter;
            }
        }

        if (itAnnounce->m_strAnnounce.empty()) {
            if (itAnnounce->m_tDelay == 0) {
                if (std::distance(itAnnounce, m_vTopAnnounces.end()) == 1)
                    itAnnounce->m_tDelay = GetTickCount() + REMOVE_DELAY;
                else
                    m_vTopAnnounces.erase(itAnnounce);
            }
        }
    }

    void CAnnounceRenderer::RenderCenterAnnounces(C2DRender* p2DRender) {
        auto offSetY = (184 * p2DRender->m_clipRect.Height() / 768) - 120;
        if (m_vCenteredAnnounces.empty()) return;

        auto itAnnounce = m_vCenteredAnnounces.begin();

        std::string strFull;
        for (const auto& text : itAnnounce->m_strAnnounce) {
            strFull += text.m_char; // correct, supports full UTF-8 characters
        }


        CEditString str;
        str.SetParsingString(strFull.c_str());

        const std::uint16_t nRectWidth = 450;

        CPoint point = CPoint((p2DRender->m_clipRect.Width() / 2) - (nRectWidth / 2), offSetY);

        RenderRectangles(p2DRender, CRect(point.x, point.y - 5, point.x + nRectWidth, point.y + 20), itAnnounce->m_nAlpha, 50);

        for (auto itLetter = itAnnounce->m_strAnnounce.begin(); itLetter != itAnnounce->m_strAnnounce.end(); )
        {
            if (itLetter->m_nPositionX <= point.x + nRectWidth && itLetter->m_nPositionX >= point.x)
            {
                std::string strLetter = itLetter->m_char;

                CEditString string;
                string.SetParsingString(strLetter.c_str(), D3DCOLOR_ARGB(255, 254, 254, 254));

                p2DRender->TextOut_EditString(itLetter->m_nPositionX, point.y, string);
            }

            itLetter->m_nPositionX -= 2;

            ++itLetter;
        }

        if (itAnnounce->m_strAnnounce.empty()) {
            if (itAnnounce->m_tDelay == 0) {
            if( std::distance(itAnnounce, m_vCenteredAnnounces.end()) == 1)
                itAnnounce->m_tDelay = GetTickCount() + REMOVE_DELAY;
            else
                m_vCenteredAnnounces.erase(itAnnounce);
            }
        }
    }

Then replace the

C++:
    struct textData {
        char m_char = { 0, };
        std::int32_t m_nPositionX = 0;

        std::uint8_t m_nRoundsCount = 0;
    };

    struct AnnounceData {
        std::vector<textData> m_strAnnounce;
        std::uint32_t m_nPlayerCasterIndex = 0;

        __time64_t    m_tDelay = 0;
        std::int32_t m_nAlpha = ALPHA_BASE;
    };

to

C++:
    struct textData
    {
        std::string m_char;              // Full UTF-8 character

        std::int32_t m_nPositionX = 0;
        std::uint8_t m_nRoundsCount = 0;
    };


    struct AnnounceData {
        std::vector<textData> m_strAnnounce;   // now contains full UTF-8 character data
        std::uint32_t m_nPlayerCasterIndex = 0;

        __time64_t m_tDelay = 0;
        std::int32_t m_nAlpha = ALPHA_BASE;
    };

after this dont forget to create a new font on ITheme.cpp
Set the font to this.
C++:
Microsoft YaHei
after this dont forget to create a new font on ITheme.cpp
Set the font to this.
C++:
Microsoft YaHei
The code is still out of order. The last step has not been completed and the code will not be written,
I have modified the above with your help, but it is still garbled, and nothing has changed.
 
Upvote 0
isn't it much easier to use the game's engine own messaging system instead of creating a whole new function for it? It will than support all ime's through the editstring info? Am i missing something?
 
Upvote 0
isn't it much easier to use the game's engine own messaging system instead of creating a whole new function for it? It will than support all ime's through the editstring info? Am i missing something?
Only the new bulletin system can be blocked. It is normal to use the original system bulletin
 
Upvote 0
Only the new bulletin system can be blocked. It is normal to use the original system bulletin
Have you solved it? No matter how I change the language and font encoding, I still can't change the display of garbled characters. I think it's because the encoding in AnnounceRedrader.cpp is not supported, only English and numbers are supported, and it cannot recognize other languages
 
Upvote 0
Have you solved it? No matter how I change the language and font encoding, I still can't change the display of garbled characters. I think it's because the encoding in AnnounceRedrader.cpp is not supported, only English and numbers are supported, and it cannot recognize other languages
This part of code is shielded
 
Upvote 0
Back