Anti-Flood

This commit is contained in:
nullifiedcat 2017-01-21 22:59:23 +03:00
parent bac1aa3640
commit fc6a5dda2c
3 changed files with 101 additions and 0 deletions

View File

@ -4,6 +4,10 @@ Time DRM
Build DRM
SteamID DRM
HWID:
/etc/machine-id
/etc/fstab
FIX crash
FIX conds
Player List

View File

@ -171,7 +171,23 @@ void OverrideView_hook(void* thisptr, CViewSetup* setup) {
}
bool DispatchUserMessage_hook(void* thisptr, int type, bf_read& buf) {
SEGV_BEGIN;
if (type == 4) {
int s = buf.GetNumBytesLeft();
char* data = new char[s];
for (int i = 0; i < s; i++)
data[i] = buf.ReadByte();
int j = 0;
for (int i = 0; i < 3; i++) {
while (char c = data[j++]) {
if (c == '\n') data[j - 1] = ' ';
}
}
buf = bf_read(data, s);
buf.Seek(0);
}
return ((DispatchUserMessage_t*)hooks::hkClient->GetMethod(hooks::offFrameStageNotify + 1))(thisptr, type, buf);
SEGV_END; return false;
}
void LevelInit_hook(void* thisptr, const char* newmap) {

View File

@ -26,6 +26,87 @@ bool bf_write::WriteString(const char *pStr)
return !IsOverflowed();
}
bf_read::bf_read()
{
m_pData = NULL;
m_nDataBytes = 0;
m_nDataBits = -1; // set to -1 so we overflow on any operation
m_iCurBit = 0;
m_bOverflow = false;
m_bAssertOnOverflow = true;
m_pDebugName = NULL;
}
bf_read::bf_read( const void *pData, int nBytes, int nBits )
{
m_bAssertOnOverflow = true;
StartReading( pData, nBytes, 0, nBits );
}
bf_read::bf_read( const char *pDebugName, const void *pData, int nBytes, int nBits )
{
m_bAssertOnOverflow = true;
m_pDebugName = pDebugName;
StartReading( pData, nBytes, 0, nBits );
}
void bf_read::StartReading( const void *pData, int nBytes, int iStartBit, int nBits )
{
// Make sure we're dword aligned.
Assert(((unsigned long)pData & 3) == 0);
m_pData = (unsigned char*)pData;
m_nDataBytes = nBytes;
if ( nBits == -1 )
{
m_nDataBits = m_nDataBytes << 3;
}
else
{
Assert( nBits <= nBytes*8 );
m_nDataBits = nBits;
}
m_iCurBit = iStartBit;
m_bOverflow = false;
}
bool bf_read::ReadString( char *pStr, int maxLen, bool bLine, int *pOutNumChars )
{
Assert( maxLen != 0 );
bool bTooSmall = false;
int iChar = 0;
while(1)
{
char val = ReadChar();
if ( val == 0 )
break;
else if ( bLine && val == '\n' )
break;
if ( iChar < (maxLen-1) )
{
pStr[iChar] = val;
++iChar;
}
else
{
bTooSmall = true;
}
}
// Make sure it's null-terminated.
Assert( iChar < maxLen );
pStr[iChar] = 0;
if ( pOutNumChars )
*pOutNumChars = iChar;
return !IsOverflowed() && !bTooSmall;
}
void bf_write::WriteSBitLong( int data, int numbits )
{
// Do we have a valid # of bits to encode with?