Majesty 1,761 #1 Posted March 18, 2019 Extended Opcodes https://otland.net/threads/extended-opcodes-server-side.180536/ O que são? Extended opcodes, é um sistema que permite a adição de novos opcodes no protocolo de jogo usando apenas scripts em lua tanto no Servidor quanto no OTClient. Tornando assim mais fácil de implementar novas funcionalidades tanto no OTClient quanto no servidor. O que se pode fazer com eles? Com extended opcodes criam-se inúmeras formas de se personalizar o OTClient, com eles você pode pegar storage de um player, informações detalhadas, fazendo por exemplo point system, entre muitos outros, pois o OTClient sem opcode, não consegue utilizar essas funções, de pegar o storage do player, entre outras informações, então sua criatividade é o limite. Como instalar? (Obs: tutorial para versões 8.54 ou superior) Para isso será necessário que você tenha as sources do seu servidor e saiba compilá-lo, então caso não tenha a source ou não saiba opera-lá é melhor não seguir a diante, pois você pode acabar bugando toda sua source. Códigos: protocolgame.h -[Diff] protocolgame.h - Pastebin.com protocolgame.cpp -[Diff] protocolgame.cpp - Pastebin.com const.h -[Diff] const.h - Pastebin.com luascript.cpp -[Diff] luascript.cpp - Pastebin.com player.h -[Diff] player.h - Pastebin.com creatureevent.h -[Diff] creatureevent.h - Pastebin.com creatureevent.cpp -[Diff] creatureevent.cpp - Pastebin.com game.h -[Diff] game.h - Pastebin.com game.cpp -[Diff] game.cpp - Pastebin.com /creaturescripts/creaturescrips.xml -[Diff] creaturescripts.xml - Pastebin.com /creaturescripts/extendedopcode.lua -[Lua] extendedopcode.lua - Pastebin.com Ou baixe um pach dos arquivos aqui: https://github.com/edubart/otclient/blob/master/tools/tfs_extendedopcode.patch Créditos: Benny Edubart Share this post Link to post
Majesty 1,761 #2 Posted March 18, 2019 Adaptação para sources de servidores 8.54+ Códigos: protocolgame.h Embaixo de void AddShopItem(NetworkMessage_ptr msg, const ShopInfo item); Adicione void parseExtendedOpcode(NetworkMessage& msg);void sendExtendedOpcode(uint8_t opcode, const std::string& buffer); protocolgame.cpp Embaixo de uint32_t key[4] = {msg.GetU32(), msg.GetU32(), msg.GetU32(), msg.GetU32()};enableXTEAEncryption();setXTEAKey(key); Adicione // notifies to otclient that this server can receive extended game protocol opcodesif(operatingSystem >= CLIENTOS_OTCLIENT_LINUX)sendExtendedOpcode(0x00, std::string()); Embaixo de void ProtocolGame::AddShopItem(NetworkMessage_ptr msg, const ShopInfo item){const ItemType& it = Item::items[item.itemId];msg->AddU16(it.clientId);if(it.isSplash() || it.isFluidContainer())msg->AddByte(fluidMap[item.subType % 8]);else if(it.stackable || it.charges)msg->AddByte(item.subType);elsemsg->AddByte(0x01);msg->AddString(item.itemName);msg->AddU32(uint32_t(it.weight * 100));msg->AddU32(item.buyPrice);msg->AddU32(item.sellPrice);} Adicione void ProtocolGame::parseExtendedOpcode(NetworkMessage& msg){uint8_t opcode = msg.GetByte();std::string buffer = msg.GetString();// process additional opcodes via lua script eventaddGameTask(&Game::parsePlayerExtendedOpcode, player->getID(), opcode, buffer);}void ProtocolGame::sendExtendedOpcode(uint8_t opcode, const std::string& buffer){// extended opcodes can only be send to players using otclient, cipsoft's tibia can't understand themNetworkMessage_ptr msg = getOutputBuffer();if(msg){TRACK_MESSAGE(msg);msg->AddByte(0x32);msg->AddByte(opcode);msg->AddString(buffer);}} Embaixo de case 0x1E: // keep alive / ping responseparseReceivePing(msg);break; Adicione case 0x32: // otclient extended opcodeparseExtendedOpcode(msg);break; enums.h Embaixo de enum GuildLevel_t{GUILDLEVEL_NONE = 0,GUILDLEVEL_MEMBER,GUILDLEVEL_VICE,GUILDLEVEL_LEADER}; Substitua o OperatingSystem por este enum OperatingSystem_t{CLIENTOS_LINUX = 0x01,CLIENTOS_WINDOWS = 0x02,CLIENTOS_OTCLIENT_LINUX = 0x0A,CLIENTOS_OTCLIENT_WINDOWS = 0x0B,CLIENTOS_OTCLIENT_MAC = 0x0C,};/ player.h Embaixo de void sendCreatureShield(const Creature* creature) Adicione void sendExtendedOpcode(uint8_t opcode, const std::string& buffer){if(client) client->sendExtendedOpcode(opcode, buffer);} luascript.cpp Embaixo de void LuaScriptInterface::registerFunctions(){ Adicione //doSendPlayerExtendedOpcode(cid, opcode, buffer)lua_register(m_luaState, "doSendPlayerExtendedOpcode", LuaScriptInterface::luaDoSendPlayerExtendedOpcode); Embaixo de SHIFT_OPERATOR(int32_t, LeftShift, <<)SHIFT_OPERATOR(int32_t, RightShift, >>)SHIFT_OPERATOR(uint32_t, ULeftShift, <<)SHIFT_OPERATOR(uint32_t, URightShift, >>)#undef SHIFT_OPERATOR Adicione int32_t LuaScriptInterface::luaDoSendPlayerExtendedOpcode(lua_State* L){//doSendPlayerExtendedOpcode(cid, opcode, buffer)std::string buffer = popString(L);int opcode = popNumber(L);ScriptEnviroment* env = getEnv();if(Player* player = env->getPlayerByUID(popNumber(L))) {player->sendExtendedOpcode(opcode, buffer);lua_pushboolean(L, true);}lua_pushboolean(L, false);return 1;} luascript.h Embaixo de virtual void registerFunctions(); Adicione static int32_t luaDoSendPlayerExtendedOpcode(lua_State* L); creatureevent.h Substitua CREATURE_EVENT_PREPAREDEATH Por isso CREATURE_EVENT_PREPAREDEATH,CREATURE_EVENT_EXTENDED_OPCODE // otclient additional network opcodes Embaixo de uint32_t executePrepareDeath(Creature* creature, DeathList deathList); Adicione uint32_t executeExtendedOpcode(Creature* creature, uint8_t opcode, const std::string& buffer); creatureevent.cpp Embaixo de else if(tmpStr == "death")m_type = CREATURE_EVENT_DEATH; Adicione else if(tmpStr == "extendedopcode")m_type = CREATURE_EVENT_EXTENDED_OPCODE; Embaixo de case CREATURE_EVENT_DEATH:return "onDeath"; Adicione case CREATURE_EVENT_EXTENDED_OPCODE:return "onExtendedOpcode"; Embaixo de case CREATURE_EVENT_DEATH:return "cid, corpse, deathList"; Adicione case CREATURE_EVENT_EXTENDED_OPCODE:return "cid, opcode, buffer"; Embaixo de std::cout << "[Error - CreatureEvent::executeFollow] Call stack overflow." << std::endl;return 0;}} Adicione uint32_t CreatureEvent::executeExtendedOpcode(Creature* creature, uint8_t opcode, const std::string& buffer){//onExtendedOpcode(cid, opcode, buffer)if(m_interface->reserveEnv()){ScriptEnviroment* env = m_interface->getEnv();if(m_scripted == EVENT_SCRIPT_BUFFER){env->setRealPos(creature->getPosition());std::stringstream scriptstream;scriptstream << "local cid = " << env->addThing(creature) << std::endl;scriptstream << "local opcode = " << (int)opcode << std::endl;scriptstream << "local buffer = " << buffer.c_str() << std::endl;scriptstream << m_scriptData;bool result = true;if(m_interface->loadBuffer(scriptstream.str())){lua_State* L = m_interface->getState();result = m_interface->getGlobalBool(L, "_result", true);}m_interface->releaseEnv();return result;}else{#ifdef __DEBUG_LUASCRIPTS__char desc[35];sprintf(desc, "%s", player->getName().c_str());env->setEvent(desc);#endifenv->setScriptId(m_scriptId, m_interface);env->setRealPos(creature->getPosition());lua_State* L = m_interface->getState();m_interface->pushFunction(m_scriptId);lua_pushnumber(L, env->addThing(creature));lua_pushnumber(L, opcode);lua_pushlstring(L, buffer.c_str(), buffer.length());bool result = m_interface->callFunction(3);m_interface->releaseEnv();return result;}}else{std::cout << "[Error - CreatureEvent::executeRemoved] Call stack overflow." << std::endl;return 0;}} game.h Embaixo de int32_t getLightHour() {return lightHour;}void startDecay(Item* item); Adicione void parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string& buffer); game.cppEmbaixo de player->sendTextMessage(MSG_INFO_DESCR, buffer);} Adicione void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const std::string& buffer){Player* player = getPlayerByID(playerId);if(!player || player->isRemoved())return;CreatureEventList extendedOpcodeEvents = player->getCreatureEvents(CREATURE_EVENT_EXTENDED_OPCODE);for(CreatureEventList::iterator it = extendedOpcodeEvents.begin(); it != extendedOpcodeEvents.end(); ++it)(*it)->executeExtendedOpcode(player, opcode, buffer);} /creaturescripts/creaturescrips.xml <event type="extendedopcode" name="ExtendedOpcode" event="script" value="extendedopcode.lua"/> /creaturescripts/extendedopcode.lua OPCODE_LANGUAGE = 1function onExtendedOpcode(cid, opcode, buffer)if opcode == OPCODE_LANGUAGE then-- otclient languageif buffer == 'en' or buffer == 'pt' then-- example, setting player language, because otclient is multi-language...--doCreatureSetStorage(cid, CREATURE_STORAGE_LANGUAGE, buffer)endelse-- other opcodes can be ignored, and the server will just work fine...endend Exemplo de aplicação, getPlayerVocation em extended opcode: No cliente: 1- Vá em otclient/modules/gamelib/game.lua e adicione: function getPlayerVocation() local protocol = g_game.getProtocolGame() protocol:sendExtendedOpcode(25,5) end 2- No seu script adicione isto: ProtocolGame.registerExtendedOpcode(26, function(protocol, opcode, buffer) vocation = buffer print(vocation) end ) No servidor: 1- Em creaturescripts/script/extendedopcode.lua adicione isto: function onExtendedOpcode(cid, opcode, buffer) if opcode == 25 then doSendPlayerExtendedOpcode(cid, 26, getPlayerVocation(cid)) end return true end Créditos : MaXwEllDeN 100% por adaptar o código 3 TEKADON, koete and Raulcdj reacted to this Share this post Link to post