Вопрос Через время пропадает текст в esp

Пользователь
Статус
Оффлайн
Регистрация
19 Авг 2020
Сообщения
223
Реакции[?]
138
Поинты[?]
6K
Юзаю steam overlay ipc вот код для отрисовки текста

C++:
TextureInfo info;

    if (!StringCache.Find(fontHandle, string, info))
    {
        SelectObject(DcHandle.get(), fontHandle);

        // calculate string info
        size_t stringLength = wcslen(string);
        RECT stringRect = {};

        DrawTextW(DcHandle.get(), string, stringLength, &stringRect, DT_CALCRECT);

        // clamp string size
        SIZE pageSize = StringPage.GetSize();

        if (stringRect.right > pageSize.cx)
            stringRect.right = pageSize.cx;

        if (stringRect.bottom > pageSize.cy)
            stringRect.bottom = pageSize.cy;

        // pack into page
        RECT packedStringRect = stringRect;

        if (!StringPage.Pack(packedStringRect))
        {
            StringPage.Reset();
            StringCache.Clear();

            StringPage.Pack(packedStringRect); // always successful
        }

        DWORD size = stringRect.right * stringRect.bottom * 4;

        // setup bitmap
        BITMAPINFOHEADER bmpInfoHeader = {};
        bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
        bmpInfoHeader.biWidth = stringRect.right;
        bmpInfoHeader.biHeight = -stringRect.bottom;
        bmpInfoHeader.biSizeImage = size;
        bmpInfoHeader.biPlanes = 1;
        bmpInfoHeader.biBitCount = 32;
        bmpInfoHeader.biCompression = BI_RGB;

        char* buffer;
        HBITMAP dibHandle = CreateDIBSection(DcHandle.get(), (BITMAPINFO*)&bmpInfoHeader, DIB_RGB_COLORS, (void**)&buffer, nullptr, 0);
        if (!buffer) return;
        SelectObject(DcHandle.get(), dibHandle);

        // draw the string
        SetBkMode(DcHandle.get(), TRANSPARENT);
        SetTextColor(DcHandle.get(), RGB(255, 255, 255));
        DrawTextW(DcHandle.get(), string, stringLength, &stringRect, DT_CENTER | DT_NOCLIP | DT_END_ELLIPSIS);
       
            // correct alpha
        for (size_t i = 0; i < size; i += 4)
        {
            if (!buffer) continue;
            char r = buffer[i];
            char g = buffer[i + 1];
            char b = buffer[i + 2];
            buffer[i + 3] = (char)((float)r * 0.34f + (float)g * 0.55f + (float)b * 0.11f);
        }
       
       
       

        // try to load the texture
        long textureId = StringPage.GetTextureId();
        bool loaded = LoadTexture(textureId, 0, size, stringRect.right, stringRect.bottom, packedStringRect.left, packedStringRect.top, buffer);

        DeleteObject(dibHandle);

        // not enough room in the render buffer
        // maybe come up with a way of doing this before expensive rendering?
        if (!loaded)
            return;

        info.TextureId = textureId;

        info.Coordinates[0] = (float)packedStringRect.left / pageSize.cx;
        info.Coordinates[1] = (float)packedStringRect.top / pageSize.cy;
        info.Coordinates[2] = (float)packedStringRect.right / pageSize.cx;
        info.Coordinates[3] = (float)packedStringRect.bottom / pageSize.cy;

        info.Size =
        {
            stringRect.right,
            stringRect.bottom
        };

        StringCache.Insert(fontHandle, string, info);
    }

    DrawTexturedRect(x, y,
        x + info.Size.cx, y + info.Size.cy,
        info.Coordinates[0], info.Coordinates[1], info.Coordinates[2], info.Coordinates[3],
        0xFFFFFFFF, 0x0,
        GradientDirection::None,
        info.TextureId);
Но при этом боксы нормально рисуются. Вот код боксов

C++:
void Overlay::DrawBox(long x, long y, long width, long height, int thickness)
{
    DrawLine(x, y - 1, x + width, y + thickness, 0xFFFFFFFF);
    DrawLine(x, y + height - 1, x + width, y + height + thickness, 0xFFFFFFFF);
    DrawLine(x - 1, y - 1, x + thickness, y + height + thickness, 0xFFFFFFFF);
    DrawLine(x + width - 1, y - 1, x + width + thickness, y + height + thickness, 0xFFFFFFFF);
}
void Overlay::DrawLine(long x0, long y0, long x1, long y1, DWORD color)
{
    static auto texture = CreateAndLoadNewTexturePage(1, 1);
    DrawTexturedRect(x0, y0, x1, y1, 0.0f, 0.0f, 1.0f, 1.0f, color, 0x00000000, GradientDirection::None, texture.GetTextureId());
}
И пропадает оно где-то через минут 5-7 после начала игры. Из-за чего может быть?
 
Последнее редактирование:
Сверху Снизу