From 9b6fa57534cfab956f46dac493a867570258c14a Mon Sep 17 00:00:00 2001 From: divinity76 Date: Fri, 13 Sep 2024 09:28:41 +0200 Subject: [PATCH 1/2] Make outputMessage::addRawString available in Lua Why write ```lua msg:addU8(1); msg:addU8(0); msg:addU8(113); ``` when you can instead write ```lua msg:addRawString("\x01\x00\x71"); ``` ? Would make some lua scripts much easier to write :) --- src/framework/luafunctions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index 40059f2ca..dc157e539 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -819,6 +819,7 @@ void Application::registerLuaFunctions() g_lua.bindClassMemberFunction("addU32", &OutputMessage::addU32); g_lua.bindClassMemberFunction("addU64", &OutputMessage::addU64); g_lua.bindClassMemberFunction("addString", &OutputMessage::addString); + g_lua.bindClassMemberFunction("addRawString", &OutputMessage::addRawString); g_lua.bindClassMemberFunction("addPaddingBytes", &OutputMessage::addPaddingBytes); g_lua.bindClassMemberFunction("encryptRsa", &OutputMessage::encryptRsa); g_lua.bindClassMemberFunction("getMessageSize", &OutputMessage::getMessageSize); From f4271567181cc750e2fbf0aa5d15e8a76dccd8fa Mon Sep 17 00:00:00 2001 From: divinity76 Date: Fri, 13 Sep 2024 09:37:09 +0200 Subject: [PATCH 2/2] oops add OutputMessage::addRawString --- src/framework/net/outputmessage.cpp | 11 +++++++++++ src/framework/net/outputmessage.h | 1 + 2 files changed, 12 insertions(+) diff --git a/src/framework/net/outputmessage.cpp b/src/framework/net/outputmessage.cpp index c0e475e13..688491193 100644 --- a/src/framework/net/outputmessage.cpp +++ b/src/framework/net/outputmessage.cpp @@ -89,6 +89,17 @@ void OutputMessage::addString(const std::string& buffer) m_messageSize += len; } +void OutputMessage::addRawString(const std::string& buffer) +{ + int len = buffer.length(); + if (len > MAX_STRING_LENGTH) + throw stdext::exception(stdext::format("string length > %d", MAX_STRING_LENGTH)); + checkWrite(len); + memcpy((char*)(m_buffer + m_writePos), buffer.c_str(), len); + m_writePos += len; + m_messageSize += len; +} + void OutputMessage::addPaddingBytes(int bytes, uint8 byte) { if(bytes <= 0) diff --git a/src/framework/net/outputmessage.h b/src/framework/net/outputmessage.h index 3dcc53312..3a66518a0 100644 --- a/src/framework/net/outputmessage.h +++ b/src/framework/net/outputmessage.h @@ -48,6 +48,7 @@ class OutputMessage : public LuaObject void addU32(uint32 value); void addU64(uint64 value); void addString(const std::string& buffer); + void addRawString(const std::string& buffer); void addPaddingBytes(int bytes, uint8 byte = 0); void encryptRsa();