From 4f907837892bbd21806f1d31809a737fc6bd937c Mon Sep 17 00:00:00 2001 From: Henrique Santiago Date: Wed, 16 May 2012 17:09:37 -0300 Subject: [PATCH] extended opcode disabled by default. current locale is sent to server on login, bot protection exception --- .../extended.lua | 2 +- .../extended.otmod | 4 +- modules/client_locales/locales.lua | 38 ++++++++++++++++--- modules/client_locales/locales.otmod | 1 + modules/game/game.otmod | 2 +- src/otclient/CMakeLists.txt | 8 ++++ src/otclient/core/game.cpp | 13 +++++-- src/otclient/core/game.h | 3 ++ src/otclient/net/protocolgameparse.cpp | 2 + src/otclient/net/protocolgamesend.cpp | 2 + 10 files changed, 62 insertions(+), 13 deletions(-) rename modules/{gamelib_extended => client_extended}/extended.lua (96%) rename modules/{gamelib_extended => client_extended}/extended.otmod (64%) diff --git a/modules/gamelib_extended/extended.lua b/modules/client_extended/extended.lua similarity index 96% rename from modules/gamelib_extended/extended.lua rename to modules/client_extended/extended.lua index 6fa09eb7..2a594cad 100644 --- a/modules/gamelib_extended/extended.lua +++ b/modules/client_extended/extended.lua @@ -7,7 +7,7 @@ local callbacks = {} local function onExtendedOpcode(protocol, opcode, buffer) local callback = callbacks[opcode] if callback then - callback(opcode, buffer) + callback(protocol, opcode, buffer) end end diff --git a/modules/gamelib_extended/extended.otmod b/modules/client_extended/extended.otmod similarity index 64% rename from modules/gamelib_extended/extended.otmod rename to modules/client_extended/extended.otmod index df5093e0..b0ca614e 100644 --- a/modules/gamelib_extended/extended.otmod +++ b/modules/client_extended/extended.otmod @@ -1,6 +1,6 @@ Module - name: gamelib_extended - description: Manage client extended messages + name: client_extended + description: Manage client extended messages callbacks author: baxnie website: www.otclient.info diff --git a/modules/client_locales/locales.lua b/modules/client_locales/locales.lua index 8ef03423..71a9873c 100644 --- a/modules/client_locales/locales.lua +++ b/modules/client_locales/locales.lua @@ -10,10 +10,33 @@ local currentLocale local localeComboBox -- private functions +local function sendLocale(localeName) + local protocolGame = g_game.getProtocolGame() + if protocolGame then + protocolGame:sendExtendedOpcode(0, localeName) + return true + end + return false +end + local function onLocaleComboBoxOptionChange(self, optionText, optionData) - Locales.setLocale(optionData) - Settings.set('locale', optionData) - reloadModules() + if Locales.setLocale(optionData) then + Settings.set('locale', optionData) + sendLocale(currentLocale.name) + reloadModules() + end +end + +-- hooked functions +local function onGameStart() + sendLocale(currentLocale.name) +end + +local function onServerSetLocale(protocol, opcode, buffer) + local locale = installedLocales[buffer] + if locale then + localeComboBox:setCurrentOption(locale.languageName) + end end -- public functions @@ -24,9 +47,9 @@ function Locales.init() local userLocaleName = Settings.get('locale') if userLocaleName and Locales.setLocale(userLocaleName)then - print('Using configured locale: ' .. userLocaleName) + info('Using configured locale: ' .. userLocaleName) else - print('Using default locale: ' .. defaultLocaleName) + info('Using default locale: ' .. defaultLocaleName) Locales.setLocale(defaultLocaleName) Settings.set('locale', defaultLocaleName) end @@ -39,12 +62,17 @@ function Locales.init() localeComboBox:setCurrentOption(currentLocale.languageName) localeComboBox.onOptionChange = onLocaleComboBoxOptionChange end, false) + + Extended.register(0, onServerSetLocale) + connect(g_game, { onGameStart = onGameStart }) end function Locales.terminate() installedLocales = nil currentLocale = nil localeComboBox = nil + Extended.unregister(0) + disconnect(g_game, { onGameStart = onGameStart }) end function Locales.installLocale(locale) diff --git a/modules/client_locales/locales.otmod b/modules/client_locales/locales.otmod index a9983dd4..c8027c11 100644 --- a/modules/client_locales/locales.otmod +++ b/modules/client_locales/locales.otmod @@ -5,6 +5,7 @@ Module website: www.otclient.info dependencies: + - client_extended - client_topmenu @onLoad: | diff --git a/modules/game/game.otmod b/modules/game/game.otmod index 13c0a81c..d355baae 100644 --- a/modules/game/game.otmod +++ b/modules/game/game.otmod @@ -5,7 +5,7 @@ Module website: www.otclient.info dependencies: - - gamelib_extended + - client_extended - game_tibiafiles - client_background //- game_shaders diff --git a/src/otclient/CMakeLists.txt b/src/otclient/CMakeLists.txt index 1a83cd55..a1a5a40c 100644 --- a/src/otclient/CMakeLists.txt +++ b/src/otclient/CMakeLists.txt @@ -5,6 +5,7 @@ ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6) # otclient options OPTION(BOT_PROTECTION "Enable bot protection" ON) +OPTION(EXTENDED_OPCODE "Enable extended opcode" OFF) SET(PROTOCOL 860 CACHE "Protocol version" STRING) OPTION(CIPSOFT_RSA "Use cipsoft RSA to login into original tibia" OFF) ADD_DEFINITIONS(-DPROTOCOL=${PROTOCOL}) @@ -24,6 +25,13 @@ ELSE(BOT_PROTECTION) MESSAGE(STATUS "Bot protection: OFF") ENDIF(BOT_PROTECTION) +IF(EXTENDED_OPCODE) + ADD_DEFINITIONS(-DEXTENDED_OPCODE) + MESSAGE(STATUS "Extended opcode: ON") +ELSE(EXTENDED_OPCODE) + MESSAGE(STATUS "Extended opcode: OFF") +ENDIF(EXTENDED_OPCODE) + SET(otclient_SOURCES ${otclient_SOURCES} # otclient ${CMAKE_CURRENT_LIST_DIR}/otclient.cpp diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 4a09e33c..682af373 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -42,6 +42,11 @@ Game::Game() void Game::resetGameStates() { +#ifdef BOT_PROTECTION + m_denyBotCall = true; +#else + m_denyBotCall = false; +#endif m_dead = false; m_serverBeat = 50; m_canReportBugs = false; @@ -114,8 +119,10 @@ void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat, b // synchronize fight modes with the server m_protocolGame->sendChangeFightModes(m_fightMode, m_chaseMode, m_safeFight); - // NOTE: the entire map description and local player information is not known yet + // NOTE: the entire map description and local player information is not known yet (bot call is allowed here) + enableBotCall(); g_lua.callGlobalField("g_game", "onGameStart"); + disableBotCall(); } void Game::processGameEnd() @@ -991,14 +998,12 @@ void Game::mount(bool mount) bool Game::checkBotProtection() { -#ifdef BOT_PROTECTION // accepts calls comming from a stacktrace containing only C++ functions, // if the stacktrace contains a lua function, then only accept if the engine is processing an input event - if(g_lua.isInCppCallback() && !g_app->isOnInputEvent()) { + if(g_lua.isInCppCallback() && !g_app->isOnInputEvent() && m_denyBotCall) { logError(g_lua.traceback("caught a lua call to a bot protected game function, the call was canceled")); return false; } -#endif return true; } diff --git a/src/otclient/core/game.h b/src/otclient/core/game.h index f577dbf4..7a6de5c9 100644 --- a/src/otclient/core/game.h +++ b/src/otclient/core/game.h @@ -232,6 +232,8 @@ public: bool canPerformGameAction(); bool canReportBugs() { return m_canReportBugs; } bool checkBotProtection(); + void enableBotCall() { m_denyBotCall = false; } + void disableBotCall() { m_denyBotCall = true; } bool isOnline() { return !!m_localPlayer; } bool isDead() { return m_dead; } @@ -261,6 +263,7 @@ private: std::map m_containers; std::map m_vips; + bool m_denyBotCall; bool m_dead; int m_serverBeat; Otc::FightModes m_fightMode; diff --git a/src/otclient/net/protocolgameparse.cpp b/src/otclient/net/protocolgameparse.cpp index c8451396..dad75c61 100644 --- a/src/otclient/net/protocolgameparse.cpp +++ b/src/otclient/net/protocolgameparse.cpp @@ -1212,11 +1212,13 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg) int opcode = msg->getU8(); std::string buffer = msg->getString(); +#ifdef EXTENDED_OPCODE try { callLuaField("onExtendedOpcode", opcode, buffer); } catch(Exception& e) { logError("Network exception in extended opcode ", opcode, ": ", e.what()); } +#endif } void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height) diff --git a/src/otclient/net/protocolgamesend.cpp b/src/otclient/net/protocolgamesend.cpp index 922e3e14..6dd512b2 100644 --- a/src/otclient/net/protocolgamesend.cpp +++ b/src/otclient/net/protocolgamesend.cpp @@ -33,11 +33,13 @@ void ProtocolGame::safeSend(const OutputMessagePtr& outputMessage) void ProtocolGame::sendExtendedOpcode(uint8 opcode, const std::string& buffer) { +#ifdef EXTENDED_OPCODE OutputMessagePtr msg(new OutputMessage); msg->addU8(Proto::ClientExtendedOpcode); msg->addU8(opcode); msg->addString(buffer); safeSend(msg); +#endif } void ProtocolGame::sendLoginPacket(uint challangeTimestamp, uint8 challangeRandom)