Skip to content

Commit 3829aa1

Browse files
committed
allow copying directly from chat
AI helped but couldnt do it solo bruh
1 parent a9e8f64 commit 3829aa1

4 files changed

Lines changed: 347 additions & 16 deletions

File tree

src/engine/client/text.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,43 @@ class CTextRender : public IEngineTextRender
25722572
TextEx(pCursor, SegStart, p - SegStart);
25732573
}
25742574
}
2575+
2576+
std::string RemoveColorCodes(const char *pText) override
2577+
{
2578+
std::string Result = "";
2579+
if(!pText)
2580+
return Result;
2581+
2582+
const char *p = pText;
2583+
while(*p)
2584+
{
2585+
if(*p == '&' && *(p + 1))
2586+
{
2587+
if(*(p + 1) == 'x')
2588+
{
2589+
p += 2;
2590+
}
2591+
else if(isdigit(p[1]) && isdigit(p[2]))
2592+
{
2593+
int CodeLength = 2;
2594+
if(isdigit(p[3]))
2595+
CodeLength = 3;
2596+
p += 1 + CodeLength; // & + code length
2597+
}
2598+
else
2599+
{
2600+
Result += *p;
2601+
++p;
2602+
}
2603+
}
2604+
else
2605+
{
2606+
Result += *p;
2607+
++p;
2608+
}
2609+
}
2610+
return Result;
2611+
}
25752612
};
25762613

25772614
IEngineTextRender *CreateEngineTextRender() { return new CTextRender; }

src/engine/textrender.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ class ITextRender : public IInterface
252252

253253
virtual void ColorParsing(const char *pText, CTextCursor *pCursor, ColorRGBA OriginalCol, STextContainerIndex *pTextContainerIndex = nullptr) = 0;
254254
virtual ColorRGBA HSVtoRGB(float h, float s, float v) = 0;
255+
256+
virtual std::string RemoveColorCodes(const char *pText) = 0;
255257
};
256258

257259
class IEngineTextRender : public ITextRender

0 commit comments

Comments
 (0)