From f5a0e009eb3da4c06b7548807b9454feaf37a695 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Tue, 23 Sep 2025 20:31:08 -0700 Subject: [PATCH] chore(net): move CanRead helper out of CDataStore --- src/net/grunt/ClientLink.cpp | 12 ++++++------ src/net/grunt/Command.hpp | 3 ++- src/net/grunt/Util.cpp | 7 +++++++ src/net/grunt/Util.hpp | 10 ++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 src/net/grunt/Util.cpp create mode 100644 src/net/grunt/Util.hpp diff --git a/src/net/grunt/ClientLink.cpp b/src/net/grunt/ClientLink.cpp index f0596a5..d8d024a 100644 --- a/src/net/grunt/ClientLink.cpp +++ b/src/net/grunt/ClientLink.cpp @@ -93,7 +93,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) { msg.Get(generatorLen); // TODO - // if (!msg.Sub8CBBF0(v31 + 1)) { + // if (!CanRead(msg, v31 + 1)) { // return 0; // } @@ -104,7 +104,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) { msg.Get(largeSafePrimeLen); // TODO - // if (!msg.sub_8CBBF0(v32 + 48)) { + // if (!CanRead(msg, v32 + 48)) { // return 0; // } @@ -118,7 +118,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) { msg.GetDataInSitu(reinterpret_cast(versionChallenge), 16); // TODO - // if (!msg.Sub8CBBF0(1)) { + // if (!CanRead(msg, 1)) { // return 0; // } @@ -139,7 +139,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) { // PIN if (logonFlags & 0x1) { // TODO - // if (!msg.Sub8CBBF0(20)) { + // if (!CanRead(msg, 20) { // return 0; // } @@ -151,7 +151,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) { if (logonFlags & 0x2) { // TODO /* - if (msg.Sub8CBBF0(12)) { + if (CanRead(msg, 12)) { msg.Get(matrixWidth); msg.Get(matrixHeight); msg.Get(matrixDigitCount); @@ -170,7 +170,7 @@ int32_t Grunt::ClientLink::CmdAuthLogonChallenge(CDataStore& msg) { // TOKEN (authenticator) if (logonFlags & 0x4) { // TODO - // if (!msg.Sub8CBBF0(1)) { + // if (!CanRead(msg, 1)) { // return 0; // } diff --git a/src/net/grunt/Command.hpp b/src/net/grunt/Command.hpp index 9280824..3b8a3dc 100644 --- a/src/net/grunt/Command.hpp +++ b/src/net/grunt/Command.hpp @@ -2,6 +2,7 @@ #define NET_GRUNT_COMMAND_HPP #include "net/Grunt.hpp" +#include "net/grunt/Util.hpp" template class Grunt::Command { @@ -19,7 +20,7 @@ class Grunt::Command { template int32_t Grunt::Command::Process(CDataStore& msg, Command* commands, uint32_t commandCount, T& a4, uint32_t& pos) { while (true) { - if (!msg.Sub8CBBF0(1)) { + if (!CanRead(msg, 1)) { return 1; } diff --git a/src/net/grunt/Util.cpp b/src/net/grunt/Util.cpp new file mode 100644 index 0000000..fd61547 --- /dev/null +++ b/src/net/grunt/Util.cpp @@ -0,0 +1,7 @@ +#include "net/grunt/Util.hpp" +#include + +// Invented name. Appears to be private to Grunt. Found at 8CBBF0 in 3.3.5a (Windows). +bool CanRead(const CDataStore& msg, uint32_t bytes) { + return msg.IsValid() && msg.Size() - msg.Tell() >= bytes; +} diff --git a/src/net/grunt/Util.hpp b/src/net/grunt/Util.hpp new file mode 100644 index 0000000..e04315f --- /dev/null +++ b/src/net/grunt/Util.hpp @@ -0,0 +1,10 @@ +#ifndef NET_GRUNT_UTIL_HPP +#define NET_GRUNT_UTIL_HPP + +#include + +class CDataStore; + +bool CanRead(const CDataStore& msg, uint32_t bytes); + +#endif