From 7a3b48831bfc9c4aa8c39c1e42d5bf5dd73e43c5 Mon Sep 17 00:00:00 2001 From: boris Date: Tue, 1 Jan 2019 20:31:51 +1300 Subject: whole buncha fixes & switching to vmp --- csgo-loader/csgo-client/Networking/TCPClient.cpp | 44 ++++++++++++++++-------- csgo-loader/csgo-client/Networking/TCPClient.hpp | 4 ++- 2 files changed, 33 insertions(+), 15 deletions(-) (limited to 'csgo-loader/csgo-client/Networking') diff --git a/csgo-loader/csgo-client/Networking/TCPClient.cpp b/csgo-loader/csgo-client/Networking/TCPClient.cpp index 11d4677..9ac3c3e 100644 --- a/csgo-loader/csgo-client/Networking/TCPClient.cpp +++ b/csgo-loader/csgo-client/Networking/TCPClient.cpp @@ -40,23 +40,45 @@ namespace Networking break; } + // Stay in sync with client. + ByteArray Array = { 1 }; + SendRawBytes(Array); + return ReceivedBytes; } void TCPClient::SendBytes(ByteArray &Bytes) { // Encrypt outgoing data. - ByteArray Encrypted = m_Encryption.Encrypt(Bytes); + ByteArray EncryptionKey; + EncryptionKey.insert( + EncryptionKey.begin(), + m_EncryptionKey, + m_EncryptionKey + sizeof m_EncryptionKey + ); + + Wrapper::Encryption Encryption; Encryption.Start(EncryptionKey); + + ByteArray Encrypted = Encryption.Encrypt(Bytes); SendRawBytes(Encrypted); } ByteArray TCPClient::ReceiveBytes() { + // Decrypt incoming data. ByteArray ReceivedBytes = ReceiveRawBytes(); - // Decrypt incoming data. - ByteArray Decrypted = m_Encryption.Decrypt(ReceivedBytes); + ByteArray EncryptionKey; + EncryptionKey.insert( + EncryptionKey.begin(), + m_EncryptionKey, + m_EncryptionKey + sizeof m_EncryptionKey + ); + + Wrapper::Encryption Encryption; Encryption.Start(EncryptionKey); + + ByteArray Decrypted = Encryption.Decrypt(ReceivedBytes); return Decrypted; } @@ -79,16 +101,6 @@ namespace Networking m_Context.sin_addr.s_addr = ServerAddress; m_Context.sin_family = AF_INET; m_Context.sin_port = htons(ServerPort); - - // Allow the socket to time-out. - timeval timeout; - timeout.tv_sec = 5; - - if(setsockopt(m_Socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof timeout) == INVALID_SOCKET) - return false; - - if(setsockopt(m_Socket, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof timeout) == INVALID_SOCKET) - return false; // Attempt connection. if(connect(m_Socket, (sockaddr *)&m_Context, sizeof m_Context)) @@ -96,7 +108,11 @@ namespace Networking // Initialise encryption wrapper. ByteArray EncryptionKey = ReceiveRawBytes(); - m_Encryption.Start(EncryptionKey); + + if(EncryptionKey.empty()) + return false; + + std::memcpy(m_EncryptionKey, EncryptionKey.data(), EncryptionKey.size()); return true; } diff --git a/csgo-loader/csgo-client/Networking/TCPClient.hpp b/csgo-loader/csgo-client/Networking/TCPClient.hpp index 4e3e089..76439e5 100644 --- a/csgo-loader/csgo-client/Networking/TCPClient.hpp +++ b/csgo-loader/csgo-client/Networking/TCPClient.hpp @@ -19,7 +19,7 @@ namespace Networking WSADATA m_WinSocks; SOCKET m_Socket; sockaddr_in m_Context; - Wrapper::Encryption m_Encryption; + uint8_t m_EncryptionKey[32]; public: TCPClient() = default; @@ -38,4 +38,6 @@ namespace Networking void SendBytes(ByteArray &Bytes); ByteArray ReceiveBytes(); }; + + using TCPClientPtr = std::unique_ptr; } \ No newline at end of file -- cgit v1.2.3