From 619285069c92df255857fe7f65c2903c30d95b26 Mon Sep 17 00:00:00 2001 From: BeniS Date: Thu, 27 Dec 2012 02:56:06 +1300 Subject: [PATCH] Started updating to 9.8+ features, not yet finished (unsafe version). Need to finish: * Pending login state * New creature speed changes * Vip state displays Fixed: * Creature light * Missing lua constants If someone can finish this off that would be good, I will be busy for a while :) --- modules/game_market/marketprotocol.lua | 8 +++- modules/gamelib/const.lua | 2 + modules/gamelib/game.lua | 2 +- modules/gamelib/protocol.lua | 10 +++-- src/framework/net/inputmessage.cpp | 7 ++++ src/framework/net/inputmessage.h | 1 + src/otclient/const.h | 9 ++++ src/otclient/creature.cpp | 2 +- src/otclient/game.cpp | 19 +++++---- src/otclient/game.h | 6 +-- src/otclient/protocolcodes.h | 4 +- src/otclient/protocolgame.h | 4 +- src/otclient/protocolgameparse.cpp | 58 +++++++++++++++++++++----- 13 files changed, 103 insertions(+), 29 deletions(-) diff --git a/modules/game_market/marketprotocol.lua b/modules/game_market/marketprotocol.lua index ea7c5d7f..d5a650c2 100644 --- a/modules/game_market/marketprotocol.lua +++ b/modules/game_market/marketprotocol.lua @@ -38,7 +38,13 @@ end -- parsing protocols local function parseMarketEnter(msg) - local balance = msg:getU32() + local balance + if(g_game.getClientVersion() >= 980) then + balance = msg:getU64() + else + balance = msg:getU32() + end + local vocation = -1 if g_game.getClientVersion() < 950 then vocation = msg:getU8() -- get vocation id diff --git a/modules/gamelib/const.lua b/modules/gamelib/const.lua index eb9c1353..df22c81f 100644 --- a/modules/gamelib/const.lua +++ b/modules/gamelib/const.lua @@ -65,6 +65,8 @@ GamePurseSlot = 21 GameFormatCreatureName = 22 GameSpellList = 23 GameClientPing = 24 +GameLoginPending = 25 +GameNewSpeedLaw = 26 TextColors = { red = '#f55e5e', --'#c83200' diff --git a/modules/gamelib/game.lua b/modules/gamelib/game.lua index 59cbecf0..c0faccfe 100644 --- a/modules/gamelib/game.lua +++ b/modules/gamelib/game.lua @@ -50,7 +50,7 @@ function g_game.getSupportedProtocols() return { 810, 853, 854, 860, 861, 862, 870, 910, 940, 944, 953, 954, 960, 961, - 963, 970, 971 + 963, 970, 971, 980, 981 } end diff --git a/modules/gamelib/protocol.lua b/modules/gamelib/protocol.lua index 22e99edd..17cca0f3 100644 --- a/modules/gamelib/protocol.lua +++ b/modules/gamelib/protocol.lua @@ -1,9 +1,11 @@ GameServerOpcodes = { GameServerInitGame = 10, GameServerGMActions = 11, + GameServerEnterGame = 15, GameServerLoginError = 20, GameServerLoginAdvice = 21, GameServerLoginWait = 22, + GameServerAddCreature = 23, GameServerPingBack = 29, GameServerPing = 30, GameServerChallange = 31, @@ -94,7 +96,8 @@ GameServerOpcodes = { GameServerMarketEnter = 246, -- 944 GameServerMarketLeave = 247, -- 944 GameServerMarketDetail = 248, -- 944 - GameServerMarketBrowse = 249 -- 944 + GameServerMarketBrowse = 249, -- 944 + GameServerShowModalDialog = 250 -- 960 } ClientOpcodes = { @@ -184,5 +187,6 @@ ClientOpcodes = { ClientMarketBrowse = 245, -- 944 ClientMarketCreate = 246, -- 944 ClientMarketCancel = 247, -- 944 - ClientMarketAccept = 248 -- 944 -} \ No newline at end of file + ClientMarketAccept = 248, -- 944 + ClientAnswerModalDialog = 249 -- 960 +} diff --git a/src/framework/net/inputmessage.cpp b/src/framework/net/inputmessage.cpp index 51a1a46c..b4045347 100644 --- a/src/framework/net/inputmessage.cpp +++ b/src/framework/net/inputmessage.cpp @@ -86,6 +86,13 @@ std::string InputMessage::getString() return std::string(v, stringLength); } +double InputMessage::getDouble() +{ + uint8 precision = getU8(); + uint32 v = getU32(); + return (v / std::pow((float)10, precision)); +} + bool InputMessage::decryptRsa(int size) { checkRead(size); diff --git a/src/framework/net/inputmessage.h b/src/framework/net/inputmessage.h index 2a224a2c..0485e543 100644 --- a/src/framework/net/inputmessage.h +++ b/src/framework/net/inputmessage.h @@ -46,6 +46,7 @@ public: uint32 getU32(); uint64 getU64(); std::string getString(); + double getDouble(); uint8 peekU8() { uint8 v = getU8(); m_readPos-=1; return v; } uint16 peekU16() { uint16 v = getU16(); m_readPos-=2; return v; } diff --git a/src/otclient/const.h b/src/otclient/const.h index f839a02b..13ad712c 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -340,6 +340,8 @@ namespace Otc GameFormatCreatureName = 22, GameSpellList = 23, GameClientPing = 24, + GameLoginPending = 25, + GameNewSpeedLaw = 26, // 23-50 unused yet // 51-100 reserved to be defined in lua LastGameFeature = 101 @@ -383,6 +385,13 @@ namespace Otc MAPMARK_GREENNORTH, MAPMARK_GREENSOUTH }; + + enum VipState + { + VIPSTATE_OFFLINE = 0, + VIPSTATE_ONLINE = 1, + VIPSTATE_PENDING = 2 + }; } #endif diff --git a/src/otclient/creature.cpp b/src/otclient/creature.cpp index 4f676c45..4674480f 100644 --- a/src/otclient/creature.cpp +++ b/src/otclient/creature.cpp @@ -83,7 +83,7 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate, LightVie if(lightView) { Light light = rawGetThingType()->getLight(); - if(m_light.intensity > light.intensity) + if(m_light.intensity != light.intensity && m_light.color != light.color) light = m_light; // local player always have a minimum light in complete darkness diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index e4f2f411..29c586c7 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -305,16 +305,16 @@ void Game::processRuleViolationLock() g_lua.callGlobalField("g_game", "onRuleViolationLock"); } -void Game::processVipAdd(uint id, const std::string& name, bool online) +void Game::processVipAdd(uint id, const std::string& name, uint status) { - m_vips[id] = Vip(name, online); - g_lua.callGlobalField("g_game", "onAddVip", id, name, online); + m_vips[id] = Vip(name, status); + g_lua.callGlobalField("g_game", "onAddVip", id, name, status); } -void Game::processVipStateChange(uint id, bool online) +void Game::processVipStateChange(uint id, uint status) { - std::get<1>(m_vips[id]) = online; - g_lua.callGlobalField("g_game", "onVipStateChange", id, online); + std::get<1>(m_vips[id]) = status; + g_lua.callGlobalField("g_game", "onVipStateChange", id, status); } void Game::processTutorialHint(int id) @@ -1181,7 +1181,7 @@ void Game::setClientVersion(int version) if(isOnline()) stdext::throw_exception("Unable to change client version while online"); - if(version != 0 && (version < 810 || version > 970)) + if(version != 0 && (version < 810 || version > 981)) stdext::throw_exception(stdext::format("Protocol version %d not supported", version)); m_features.reset(); @@ -1233,6 +1233,11 @@ void Game::setClientVersion(int version) enableFeature(Otc::GameOfflineTrainingTime); } + if(version >= 980) { + enableFeature(Otc::GameLoginPending); + enableFeature(Otc::GameNewSpeedLaw); + } + m_clientVersion = version; Proto::buildMessageModesMap(version); diff --git a/src/otclient/game.h b/src/otclient/game.h index 71260ca3..0a8bca7d 100644 --- a/src/otclient/game.h +++ b/src/otclient/game.h @@ -36,7 +36,7 @@ #include -typedef std::tuple Vip; +typedef std::tuple Vip; //@bindsingleton g_game class Game @@ -93,8 +93,8 @@ protected: void processRuleViolationLock(); // vip related - void processVipAdd(uint id, const std::string& name, bool online); - void processVipStateChange(uint id, bool online); + void processVipAdd(uint id, const std::string& name, uint status); + void processVipStateChange(uint id, uint status); // tutorial hint void processTutorialHint(int id); diff --git a/src/otclient/protocolcodes.h b/src/otclient/protocolcodes.h index 4fd1c954..96834fb3 100644 --- a/src/otclient/protocolcodes.h +++ b/src/otclient/protocolcodes.h @@ -43,9 +43,11 @@ namespace Proto { { GameServerInitGame = 10, GameServerGMActions = 11, + GameServerEnterGame = 15, GameServerLoginError = 20, GameServerLoginAdvice = 21, GameServerLoginWait = 22, + GameServerAddCreature = 23, GameServerPingBack = 29, GameServerPing = 30, GameServerChallange = 31, @@ -124,7 +126,7 @@ namespace Proto { GameServerFloorChangeDown = 191, GameServerChooseOutfit = 200, GameServerVipAdd = 210, - GameServerVipLogin = 211, + GameServerVipState = 211, GameServerVipLogout = 212, GameServerTutorialHint = 220, GameServerAutomapFlag = 221, diff --git a/src/otclient/protocolgame.h b/src/otclient/protocolgame.h index 2496caa5..aca63451 100644 --- a/src/otclient/protocolgame.h +++ b/src/otclient/protocolgame.h @@ -119,6 +119,8 @@ public: private: void parseMessage(const InputMessagePtr& msg); + void parsePendingGame(const InputMessagePtr& msg); + void parseEnterGame(const InputMessagePtr& msg); void parseInitGame(const InputMessagePtr& msg); void parseGMActions(const InputMessagePtr& msg); void parseLoginError(const InputMessagePtr& msg); @@ -191,7 +193,7 @@ private: void parseFloorChangeDown(const InputMessagePtr& msg); void parseOpenOutfitWindow(const InputMessagePtr& msg); void parseVipAdd(const InputMessagePtr& msg); - void parseVipLogin(const InputMessagePtr& msg); + void parseVipState(const InputMessagePtr& msg); void parseVipLogout(const InputMessagePtr& msg); void parseTutorialHint(const InputMessagePtr& msg); void parseAutomapFlag(const InputMessagePtr& msg); diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index dd8e06dc..45fc43ef 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -57,7 +57,15 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) switch(opcode) { case Proto::GameServerInitGame: - parseInitGame(msg); + case Proto::GameServerAddCreature: + if(opcode == Proto::GameServerInitGame && g_game.getFeature(Otc::GameLoginPending)) + parsePendingGame(msg); + else + parseInitGame(msg); + break; + case Proto::GameServerEnterGame: + if(g_game.getFeature(Otc::GameLoginPending)) + parseEnterGame(msg); break; case Proto::GameServerGMActions: parseGMActions(msg); @@ -262,8 +270,8 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerVipAdd: parseVipAdd(msg); break; - case Proto::GameServerVipLogin: - parseVipLogin(msg); + case Proto::GameServerVipState: + parseVipState(msg); break; case Proto::GameServerVipLogout: parseVipLogout(msg); @@ -328,6 +336,13 @@ void ProtocolGame::parseInitGame(const InputMessagePtr& msg) { uint playerId = msg->getU32(); int serverBeat = msg->getU16(); + + if(g_game.getFeature(Otc::GameNewSpeedLaw)) + { + double speedA = msg->getDouble(); + double speedB = msg->getDouble(); + double speedC = msg->getDouble(); + } bool canReportBugs = msg->getU8(); m_localPlayer->setId(playerId); @@ -335,6 +350,16 @@ void ProtocolGame::parseInitGame(const InputMessagePtr& msg) g_game.setCanReportBugs(canReportBugs); } +void ProtocolGame::parsePendingGame(const InputMessagePtr& msg) +{ + //set player to pending game state +} + +void ProtocolGame::parseEnterGame(const InputMessagePtr& msg) +{ + //set player to entered game state +} + void ProtocolGame::parseGMActions(const InputMessagePtr& msg) { std::vector actions; @@ -618,7 +643,12 @@ void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg) { std::vector> goods; - int money = msg->getU32(); + int money; + if(g_game.getClientVersion() >= 980) + money = msg->getU64(); + else + money = msg->getU32(); + int size = msg->getU8(); for(int i = 0; i < size; i++) { int itemId = msg->getU16(); @@ -1259,9 +1289,9 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) void ProtocolGame::parseVipAdd(const InputMessagePtr& msg) { - uint id, markId; + uint id, markId, status; std::string name, desc; - bool online, notifyLogin; + bool notifyLogin; id = msg->getU32(); name = g_game.formatCreatureName(msg->getString()); @@ -1270,21 +1300,27 @@ void ProtocolGame::parseVipAdd(const InputMessagePtr& msg) markId = msg->getU32(); notifyLogin = msg->getU8(); } - online = msg->getU8(); + status = msg->getU8(); - g_game.processVipAdd(id, name, online); + g_game.processVipAdd(id, name, status); } -void ProtocolGame::parseVipLogin(const InputMessagePtr& msg) +void ProtocolGame::parseVipState(const InputMessagePtr& msg) { uint id = msg->getU32(); - g_game.processVipStateChange(id, true); + if(g_game.getFeature(Otc::GameLoginPending)) { + uint status = msg->getU8(); + g_game.processVipStateChange(id, status); + } + else { + g_game.processVipStateChange(id, 1); + } } void ProtocolGame::parseVipLogout(const InputMessagePtr& msg) { uint id = msg->getU32(); - g_game.processVipStateChange(id, false); + g_game.processVipStateChange(id, 0); } void ProtocolGame::parseTutorialHint(const InputMessagePtr& msg)