From 8f466b432cab83721cf4cc1e5740e9934f19b2d3 Mon Sep 17 00:00:00 2001 From: "Andre (Notebook)" Date: Fri, 13 Jan 2012 09:19:33 +0800 Subject: [PATCH] add lua functions to support packet manipulation/send --- src/framework/net/outputmessage.h | 5 ++++- src/otclient/luafunctions.cpp | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/framework/net/outputmessage.h b/src/framework/net/outputmessage.h index 526a36fc..bdc72309 100644 --- a/src/framework/net/outputmessage.h +++ b/src/framework/net/outputmessage.h @@ -25,8 +25,11 @@ #include "declarations.h" #include "networkexception.h" +#include -class OutputMessage +typedef std::shared_ptr OutputMessagePtr; + +class OutputMessage : public LuaObject { public: enum { diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 9e5f4d8a..cb0d9261 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -89,6 +89,18 @@ void OTClient::registerLuaFunctions() g_lua.registerClass(); + g_lua.registerClass(); + g_lua.bindClassStaticFunction("new", []{ return OutputMessagePtr(new OutputMessage); }); + g_lua.bindClassMemberFunction("reset", &OutputMessage::reset); + g_lua.bindClassMemberFunction("addU8", &OutputMessage::addU8); + g_lua.bindClassMemberFunction("addU16", &OutputMessage::addU16); + g_lua.bindClassMemberFunction("addU32", &OutputMessage::addU32); + g_lua.bindClassMemberFunction("addU64", &OutputMessage::addU64); + g_lua.bindClassMemberFunction("addString", (void(OutputMessage::*)(const std::string&))&OutputMessage::addString); + + g_lua.registerClass(); + g_lua.bindClassStaticFunction("send", [](const ProtocolPtr proto, OutputMessagePtr msg) { proto->send(*msg.get()); }); + g_lua.registerClass(); g_lua.bindClassMemberFunction("setId", &Thing::setId); g_lua.bindClassMemberFunction("setPos", &Thing::setPos); @@ -202,6 +214,7 @@ void OTClient::registerLuaFunctions() g_lua.bindClassStaticFunction("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3)); g_lua.bindClassStaticFunction("getLocalPlayer", std::bind(&Game::getLocalPlayer, &g_game)); g_lua.bindClassStaticFunction("getProtocolVersion", std::bind(&Game::getProtocolVersion, &g_game)); + g_lua.bindClassStaticFunction("getProtocolGame", std::bind(&Game::getProtocolGame, &g_game)); g_lua.bindClassStaticFunction("setSelectedThing", std::bind(&Game::setSelectedThing, &g_game, _1)); g_lua.bindClassStaticFunction("getSelectedThing", std::bind(&Game::getSelectedThing, &g_game));