diff --git a/modules/client_entergame/characterlist.lua b/modules/client_entergame/characterlist.lua index 5c43f8c..dd6da80 100644 --- a/modules/client_entergame/characterlist.lua +++ b/modules/client_entergame/characterlist.lua @@ -303,9 +303,9 @@ function CharacterList.create(characters, account, otui) status = tr(' (Suspended)') end - if account.subStatus == SubscriptionStatus.Free then + if account.subStatus == SubscriptionStatus.Free and account.premDays < 1 then accountStatusLabel:setText(('%s%s'):format(tr('Free Account'), status)) - elseif account.subStatus == SubscriptionStatus.Premium then + else if account.premDays == 0 or account.premDays == 65535 then accountStatusLabel:setText(('%s%s'):format(tr('Gratis Premium Account'), status)) else diff --git a/modules/client_entergame/entergame.lua b/modules/client_entergame/entergame.lua index d3eb180..f81bead 100644 --- a/modules/client_entergame/entergame.lua +++ b/modules/client_entergame/entergame.lua @@ -166,6 +166,16 @@ local function onTibia12HTTPResult(session, playdata) end end + -- proxies + if g_proxy then + g_proxy.clear() + if playdata["proxies"] then + for i, proxy in ipairs(playdata["proxies"]) do + g_proxy.addProxy(proxy["host"], tonumber(proxy["port"]), tonumber(proxy["priority"])) + end + end + end + g_game.setCustomProtocolVersion(0) g_game.chooseRsa(G.host) g_game.setClientVersion(G.clientVersion) @@ -414,7 +424,7 @@ function EnterGame.doLogin() G.host = server_params[1] .. ":" .. server_params[2] .. ":" .. server_params[3] G.clientVersion = tonumber(server_params[4]) elseif #server_params >= 3 then - if tonumber(server_params[3]) == server_params[3] then + if tostring(tonumber(server_params[3])) == server_params[3] then G.host = server_params[1] .. ":" .. server_params[2] G.clientVersion = tonumber(server_params[3]) end diff --git a/modules/game_shaders/shaders.lua b/modules/game_shaders/shaders.lua index eca5202..e607dc0 100644 --- a/modules/game_shaders/shaders.lua +++ b/modules/game_shaders/shaders.lua @@ -1,19 +1,6 @@ function init() -- add manually your shaders from /data/shaders g_shaders.createOutfitShader("default", "/shaders/outfit_default_vertex", "/shaders/outfit_default_fragment") - ---[[ g_shaders.createOutfitShader("stars", "/shaders/outfit_stars_vertex", "/shaders/outfit_stars_fragment") - g_shaders.addTexture("stars", "/shaders/stars.png") - - g_shaders.createOutfitShader("gold", "/shaders/outfit_gold_vertex", "/shaders/outfit_gold_fragment") - g_shaders.addTexture("gold", "/data/shaders/gold.png") - - g_shaders.createOutfitShader("rainbow", "/shaders/outfit_rainbow_vertex", "/shaders/outfit_rainbow_fragment") - g_shaders.addTexture("rainbow", "/shaders/rainbow.png") - - g_shaders.createOutfitShader("line", "/shaders/outfit_line_vertex", "/shaders/outfit_line_fragment") - - g_shaders.createOutfitShader("outline", "/shaders/outfit_outline_vertex", "/shaders/outfit_outline_fragment") ]]-- end function terminate() diff --git a/modules/game_shop/shop.lua b/modules/game_shop/shop.lua index 7b47f8b..bce0046 100644 --- a/modules/game_shop/shop.lua +++ b/modules/game_shop/shop.lua @@ -486,7 +486,11 @@ function changeCategory(widget, newCategory) end if g_game.getFeature(GameIngameStore) and widget ~= newCategory and not otcv8shop then - g_game.requestStoreOffers(newCategory.name:getText()) + local serviceType = 0 + if g_game.getFeature(GameTibia12Protocol) then + serviceType = 2 + end + g_game.requestStoreOffers(newCategory.name:getText(), serviceType) end browsingHistory = false diff --git a/otclient_dx.exe b/otclient_dx.exe index 0bc6453..b9965d3 100644 Binary files a/otclient_dx.exe and b/otclient_dx.exe differ diff --git a/otclient_gl.exe b/otclient_gl.exe index c04e04a..ede23ff 100644 Binary files a/otclient_gl.exe and b/otclient_gl.exe differ diff --git a/otclient_linux b/otclient_linux index 8f28c52..264c122 100644 Binary files a/otclient_linux and b/otclient_linux differ diff --git a/otclientv8.apk b/otclientv8.apk index 871ec85..761d79c 100644 Binary files a/otclientv8.apk and b/otclientv8.apk differ diff --git a/pdb/pdb.7z b/pdb/pdb.7z index d3e913b..dc24d10 100644 Binary files a/pdb/pdb.7z and b/pdb/pdb.7z differ diff --git a/src/client/protocolcodes.h b/src/client/protocolcodes.h index 79cdbad..6ffa963 100644 --- a/src/client/protocolcodes.h +++ b/src/client/protocolcodes.h @@ -56,6 +56,8 @@ namespace Proto { GameServerPing = 30, GameServerChallenge = 31, GameServerDeath = 40, + GameServerSupplyStash = 41, + GameServerDepotState = 42, // all in game opcodes must be greater than 50 GameServerFirstGameOpcode = 50, @@ -125,7 +127,8 @@ namespace Proto { GameServerEditText = 150, GameServerEditList = 151, GameServerNews = 152, - GameServerSendBlessDialog = 155, + GameUnkown154 = 154, + GameServerBlessDialog = 155, GameServerBlessings = 156, GameServerPreset = 157, GameServerPremiumTrigger = 158, // 1038 @@ -157,6 +160,8 @@ namespace Proto { GameServerPvpSituations = 184, GameServerFloorChangeUp = 190, GameServerFloorChangeDown = 191, + GameServerLootContainers = 192, + GameServerTournamentLeaderboard = 197, GameServerChooseOutfit = 200, GameServerImpactTracker = 204, GameServerItemsPrices = 205, @@ -166,10 +171,10 @@ namespace Proto { GameServerKillTracker = 209, GameServerVipAdd = 210, GameServerVipState = 211, - GameServerVipLogout = 212, + GameServerVipLogoutOrGroupData = 212, GameServerCyclopediaNewDetails = 217, GameServerTutorialHint = 220, - GameServerAutomapFlag = 221, + GameServerCyclopediaMapData = 221, GameServerDailyRewardState = 222, GameServerCoinBalance = 223, GameServerStoreError = 224, // 1080 @@ -183,7 +188,7 @@ namespace Proto { GameServerPreyPrices = 233, GameServerStoreOfferDescription = 234, GameServerImbuementWindow = 235, - GaneServerCloseImbuementWindow = 236, + GameServerCloseImbuementWindow = 236, GameServerMessageDialog = 237, GameServerResourceBalance = 238, GameServerTime = 239, diff --git a/src/client/protocolgame.h b/src/client/protocolgame.h index 3b0e3e3..9ef076a 100644 --- a/src/client/protocolgame.h +++ b/src/client/protocolgame.h @@ -251,8 +251,9 @@ private: void parseVipAdd(const InputMessagePtr& msg); void parseVipState(const InputMessagePtr& msg); void parseVipLogout(const InputMessagePtr& msg); + void parseVipGroupData(const InputMessagePtr& msg); void parseTutorialHint(const InputMessagePtr& msg); - void parseAutomapFlag(const InputMessagePtr& msg); + void parseCyclopediaMapData(const InputMessagePtr& msg); void parseQuestLog(const InputMessagePtr& msg); void parseQuestLine(const InputMessagePtr& msg); void parseChannelEvent(const InputMessagePtr& msg); @@ -274,7 +275,11 @@ private: void parseDailyReward(const InputMessagePtr& msg); void parseDailyRewardHistory(const InputMessagePtr& msg); void parseKillTracker(const InputMessagePtr& msg); + void parseLootContainers(const InputMessagePtr& msg); + void parseSupplyStash(const InputMessagePtr& msg); + void parseDepotState(const InputMessagePtr& msg); void parseSupplyTracker(const InputMessagePtr& msg); + void parseTournamentLeaderboard(const InputMessagePtr& msg); void parseImpactTracker(const InputMessagePtr& msg); void parseItemsPrices(const InputMessagePtr& msg); void parseLootTracker(const InputMessagePtr& msg); diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index 74d361a..389a6e2 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -44,7 +44,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) int prevOpcodePos = 0; try { - while(!msg->eof()) { + while (!msg->eof()) { opcodePos = msg->getReadPos(); opcode = msg->getU8(); @@ -60,8 +60,8 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) } // must be > so extended will be enabled before GameStart. - if(!g_game.getFeature(Otc::GameLoginPending)) { - if(!m_gameInitialized && opcode > Proto::GameServerFirstGameOpcode) { + if (!g_game.getFeature(Otc::GameLoginPending)) { + if (!m_gameInitialized && opcode > Proto::GameServerFirstGameOpcode) { g_game.processGameStart(); m_gameInitialized = true; } @@ -76,9 +76,9 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) } else msg->setReadPos(readPos); // restore read pos - switch(opcode) { + switch (opcode) { case Proto::GameServerLoginOrPendingState: - if(g_game.getFeature(Otc::GameLoginPending)) + if (g_game.getFeature(Otc::GameLoginPending)) parsePendingGame(msg); else parseLogin(msg); @@ -103,8 +103,8 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) break; case Proto::GameServerPing: case Proto::GameServerPingBack: - if((opcode == Proto::GameServerPing && g_game.getFeature(Otc::GameClientPing)) || - (opcode == Proto::GameServerPingBack && !g_game.getFeature(Otc::GameClientPing))) + if ((opcode == Proto::GameServerPing && g_game.getFeature(Otc::GameClientPing)) || + (opcode == Proto::GameServerPingBack && !g_game.getFeature(Otc::GameClientPing))) parsePingBack(msg); else parsePing(msg); @@ -232,7 +232,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerEditList: parseEditList(msg); break; - // PROTOCOL>=1038 + // PROTOCOL>=1038 case Proto::GameServerPremiumTrigger: parsePremiumTrigger(msg); break; @@ -305,14 +305,17 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerVipState: parseVipState(msg); break; - case Proto::GameServerVipLogout: - parseVipLogout(msg); + case Proto::GameServerVipLogoutOrGroupData: + if (g_game.getFeature(Otc::GameTibia12Protocol)) + parseVipGroupData(msg); + else + parseVipLogout(msg); break; case Proto::GameServerTutorialHint: parseTutorialHint(msg); break; - case Proto::GameServerAutomapFlag: - parseAutomapFlag(msg); + case Proto::GameServerCyclopediaMapData: + parseCyclopediaMapData(msg); break; case Proto::GameServerQuestLog: parseQuestLog(msg); @@ -320,7 +323,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerQuestLine: parseQuestLine(msg); break; - // PROTOCOL>=870 + // PROTOCOL>=870 case Proto::GameServerSpellDelay: parseSpellCooldown(msg); break; @@ -330,7 +333,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerMultiUseDelay: parseMultiUseCooldown(msg); break; - // PROTOCOL>=910 + // PROTOCOL>=910 case Proto::GameServerChannelEvent: parseChannelEvent(msg); break; @@ -340,15 +343,15 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerPlayerInventory: parsePlayerInventory(msg); break; - // PROTOCOL>=950 + // PROTOCOL>=950 case Proto::GameServerPlayerDataBasic: parsePlayerInfo(msg); break; - // PROTOCOL>=970 + // PROTOCOL>=970 case Proto::GameServerModalDialog: parseModalDialog(msg); break; - // PROTOCOL>=980 + // PROTOCOL>=980 case Proto::GameServerLoginSuccess: parseLogin(msg); break; @@ -358,14 +361,14 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerPlayerHelpers: parsePlayerHelpers(msg); break; - // PROTOCOL>=1000 + // PROTOCOL>=1000 case Proto::GameServerCreatureMarks: parseCreaturesMark(msg); break; case Proto::GameServerCreatureType: parseCreatureType(msg); break; - // PROTOCOL>=1055 + // PROTOCOL>=1055 case Proto::GameServerBlessings: parseBlessings(msg); break; @@ -378,7 +381,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerPreset: parsePreset(msg); break; - // PROTOCOL>=1080 + // PROTOCOL>=1080 case Proto::GameServerCoinBalanceUpdate: parseCoinBalanceUpdate(msg); break; @@ -403,7 +406,7 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerStoreError: parseStoreError(msg); break; - // PROTOCOL>=1097 + // PROTOCOL>=1097 case Proto::GameServerStoreButtonIndicators: parseStoreButtonIndicators(msg); break; @@ -413,13 +416,15 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerRestingAreaState: parseRestingAreaState(msg); break; - // protocol>=1100 + // protocol>=1100 case Proto::GameServerClientCheck: parseClientCheck(msg); break; case Proto::GameServerNews: parseGameNews(msg); break; + case Proto::GameUnkown154: // spotted on skelot + break; case Proto::GameServerBlessDialog: parseBlessDialog(msg); break; @@ -486,7 +491,19 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) case Proto::GameServerDailyRewardHistory: parseDailyRewardHistory(msg); break; - // otclient ONLY + case Proto::GameServerLootContainers: + parseLootContainers(msg); + break; + case Proto::GameServerSupplyStash: + parseSupplyStash(msg); + break; + case Proto::GameServerDepotState: + parseDepotState(msg); + break; + case Proto::GameServerTournamentLeaderboard: + parseTournamentLeaderboard(msg); + break; + // otclient ONLY case Proto::GameServerExtendedOpcode: parseExtendedOpcode(msg); break; @@ -527,16 +544,16 @@ void ProtocolGame::parseMessage(const InputMessagePtr& msg) prevOpcode = opcode; prevOpcodePos = opcodePos; } - } catch(stdext::exception& e) { + } catch (stdext::exception& e) { g_logger.error(stdext::format("ProtocolGame parse message exception (%d bytes, %d unread, last opcode is 0x%02x (%d), prev opcode is 0x%02x (%d)): %s" - "\nPacket has been saved to packet.log, you can use it to find what was wrong.", - msg->getMessageSize(), msg->getUnreadSize(), opcode, opcode, prevOpcode, prevOpcode, e.what())); + "\nPacket has been saved to packet.log, you can use it to find what was wrong. (Protocol: %i)", + msg->getMessageSize(), msg->getUnreadSize(), opcode, opcode, prevOpcode, prevOpcode, e.what(), g_game.getProtocolVersion())); std::ofstream packet("packet.log", std::ifstream::app); if (!packet.is_open()) return; - packet << stdext::format("ProtocolGame parse message exception (%d bytes, %d unread, last opcode is 0x%02x (%d), prev opcode is 0x%02x (%d)): %s\n", - msg->getMessageSize(), msg->getUnreadSize(), opcode, opcode, prevOpcode, prevOpcode, e.what()); + packet << stdext::format("ProtocolGame parse message exception (%d bytes, %d unread, last opcode is 0x%02x (%d), prev opcode is 0x%02x (%d), proto: %i): %s\n", + msg->getMessageSize(), msg->getUnreadSize(), opcode, opcode, prevOpcode, prevOpcode, g_game.getProtocolVersion(), e.what()); std::string buffer = msg->getBuffer(); opcodePos -= msg->getHeaderPos(); prevOpcodePos -= msg->getHeaderPos(); @@ -555,7 +572,7 @@ void ProtocolGame::parseLogin(const InputMessagePtr& msg) uint playerId = msg->getU32(); int serverBeat = msg->getU16(); - if(g_game.getFeature(Otc::GameNewSpeedLaw)) { + if (g_game.getFeature(Otc::GameNewSpeedLaw)) { double speedA = msg->getDouble(); double speedB = msg->getDouble(); double speedC = msg->getDouble(); @@ -563,15 +580,15 @@ void ProtocolGame::parseLogin(const InputMessagePtr& msg) } bool canReportBugs = msg->getU8(); - if(g_game.getClientVersion() >= 1054) + if (g_game.getClientVersion() >= 1054) msg->getU8(); // can change pvp frame option - if(g_game.getClientVersion() >= 1058) { + if (g_game.getClientVersion() >= 1058) { int expertModeEnabled = msg->getU8(); g_game.setExpertPvpMode(expertModeEnabled); } - if(g_game.getFeature(Otc::GameIngameStore)) { + if (g_game.getFeature(Otc::GameIngameStore)) { // URL to ingame store images std::string url = msg->getString(); @@ -606,7 +623,7 @@ void ProtocolGame::parseEnterGame(const InputMessagePtr& msg) //set player to entered game state g_game.processEnterGame(); - if(!m_gameInitialized) { + if (!m_gameInitialized) { g_game.processGameStart(); m_gameInitialized = true; } @@ -652,26 +669,26 @@ void ProtocolGame::parseRequestPurchaseData(const InputMessagePtr& msg) void ProtocolGame::parseStore(const InputMessagePtr& msg) { - if(!g_game.getFeature(Otc::GameTibia12Protocol)) + if (!g_game.getFeature(Otc::GameTibia12Protocol)) msg->getU8(); // unknown std::vector categories; // Parse all categories int count = msg->getU16(); - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { StoreCategory category; - + category.name = msg->getString(); - if(!g_game.getFeature(Otc::GameTibia12Protocol)) + if (!g_game.getFeature(Otc::GameTibia12Protocol)) category.description = msg->getString(); category.state = 0; - if(g_game.getFeature(Otc::GameIngameStoreHighlights)) + if (g_game.getFeature(Otc::GameIngameStoreHighlights)) category.state = msg->getU8(); int iconCount = msg->getU8(); - for(int i = 0; i < iconCount; i++) { + for (int i = 0; i < iconCount; i++) { std::string icon = msg->getString(); category.icon = icon; } @@ -724,11 +741,11 @@ void ProtocolGame::parseCompleteStorePurchase(const InputMessagePtr& msg) } } -void ProtocolGame::parseStoreTransactionHistory(const InputMessagePtr &msg) +void ProtocolGame::parseStoreTransactionHistory(const InputMessagePtr& msg) { int currentPage; bool hasNextPage; - if(g_game.getClientVersion() <= 1096) { + if (g_game.getClientVersion() <= 1096) { currentPage = msg->getU16(); hasNextPage = msg->getU8() == 1; } else { @@ -740,7 +757,7 @@ void ProtocolGame::parseStoreTransactionHistory(const InputMessagePtr &msg) std::vector offers; int entries = msg->getU8(); - for(int i = 0; i < entries; i++) { + for (int i = 0; i < entries; i++) { StoreOffer offer; offer.id = 0; if (g_game.getFeature(Otc::GameTibia12Protocol) && g_game.getProtocolVersion() >= 1220) @@ -780,7 +797,7 @@ void ProtocolGame::parseStoreOffers(const InputMessagePtr& msg) } int offers_count = msg->getU16(); - for(int i = 0; i < offers_count; i++) { + for (int i = 0; i < offers_count; i++) { StoreOffer offer; if (g_game.getFeature(Otc::GameTibia12Protocol)) { @@ -794,7 +811,7 @@ void ProtocolGame::parseStoreOffers(const InputMessagePtr& msg) bool disabled = msg->getU8() > 0; if (disabled) { int errors = msg->getU8(); - for(int e = 0; e < errors; ++e) + for (int e = 0; e < errors; ++e) msg->getString(); // error msg } offer.state = msg->getU8(); @@ -846,7 +863,7 @@ void ProtocolGame::parseStoreOffers(const InputMessagePtr& msg) int subOffers = msg->getU16(); // this is probably incorrect for tibia 12 - for(int j = 0; j < subOffers; j++) { + for (int j = 0; j < subOffers; j++) { std::string name = msg->getString(); if (!g_game.getFeature(Otc::GameIngameStoreHighlights)) { std::string description = msg->getString(); @@ -933,8 +950,8 @@ void ProtocolGame::parsePlayerHelpers(const InputMessagePtr& msg) CreaturePtr creature = g_map.getCreatureById(id); if (!creature) return; g_game.processPlayerHelpers(helpers); -// else -// g_logger.traceError(stdext::format("could not get creature with id %d", id)); + // else + // g_logger.traceError(stdext::format("could not get creature with id %d", id)); } void ProtocolGame::parseGMActions(const InputMessagePtr& msg) @@ -943,14 +960,14 @@ void ProtocolGame::parseGMActions(const InputMessagePtr& msg) int numViolationReasons; - if(g_game.getClientVersion() >= 850) + if (g_game.getClientVersion() >= 850) numViolationReasons = 20; - else if(g_game.getClientVersion() >= 840) + else if (g_game.getClientVersion() >= 840) numViolationReasons = 23; else numViolationReasons = 32; - for(int i = 0; i < numViolationReasons; ++i) + for (int i = 0; i < numViolationReasons; ++i) actions.push_back(msg->getU8()); g_game.processGMActions(actions); } @@ -1019,10 +1036,10 @@ void ProtocolGame::parseDeath(const InputMessagePtr& msg) int penality = 100; int deathType = Otc::DeathRegular; - if(g_game.getFeature(Otc::GameDeathType)) + if (g_game.getFeature(Otc::GameDeathType)) deathType = msg->getU8(); - if(g_game.getFeature(Otc::GamePenalityOnDeath) && deathType == Otc::DeathRegular) + if (g_game.getFeature(Otc::GamePenalityOnDeath) && deathType == Otc::DeathRegular) penality = msg->getU8(); if (g_game.getFeature(Otc::GameTibia12Protocol)) @@ -1075,7 +1092,7 @@ void ProtocolGame::parseFloorDescription(const InputMessagePtr& msg) void ProtocolGame::parseMapMoveNorth(const InputMessagePtr& msg) { Position pos; - if(g_game.getFeature(Otc::GameMapMovePosition)) + if (g_game.getFeature(Otc::GameMapMovePosition)) pos = getPosition(msg); else pos = g_map.getCentralPosition(); @@ -1090,7 +1107,7 @@ void ProtocolGame::parseMapMoveNorth(const InputMessagePtr& msg) void ProtocolGame::parseMapMoveEast(const InputMessagePtr& msg) { Position pos; - if(g_game.getFeature(Otc::GameMapMovePosition)) + if (g_game.getFeature(Otc::GameMapMovePosition)) pos = getPosition(msg); else pos = g_map.getCentralPosition(); @@ -1105,7 +1122,7 @@ void ProtocolGame::parseMapMoveEast(const InputMessagePtr& msg) void ProtocolGame::parseMapMoveSouth(const InputMessagePtr& msg) { Position pos; - if(g_game.getFeature(Otc::GameMapMovePosition)) + if (g_game.getFeature(Otc::GameMapMovePosition)) pos = getPosition(msg); else pos = g_map.getCentralPosition(); @@ -1120,7 +1137,7 @@ void ProtocolGame::parseMapMoveSouth(const InputMessagePtr& msg) void ProtocolGame::parseMapMoveWest(const InputMessagePtr& msg) { Position pos; - if(g_game.getFeature(Otc::GameMapMovePosition)) + if (g_game.getFeature(Otc::GameMapMovePosition)) pos = getPosition(msg); else pos = g_map.getCentralPosition(); @@ -1143,7 +1160,7 @@ void ProtocolGame::parseTileAddThing(const InputMessagePtr& msg) Position pos = getPosition(msg); int stackPos = -1; - if(g_game.getFeature(Otc::GameTileAddThingWithStackpos)) + if (g_game.getFeature(Otc::GameTileAddThingWithStackpos)) stackPos = msg->getU8(); ThingPtr thing = getThing(msg); @@ -1155,7 +1172,7 @@ void ProtocolGame::parseTileTransformThing(const InputMessagePtr& msg) ThingPtr thing = getMappedThing(msg); ThingPtr newThing = getThing(msg); - if(!thing) { + if (!thing) { g_logger.traceError("no thing"); return; } @@ -1163,7 +1180,7 @@ void ProtocolGame::parseTileTransformThing(const InputMessagePtr& msg) Position pos = thing->getPosition(); int stackpos = thing->getStackPos(); - if(!g_map.removeThing(thing)) { + if (!g_map.removeThing(thing)) { g_logger.traceError("unable to remove thing"); return; } @@ -1174,12 +1191,12 @@ void ProtocolGame::parseTileTransformThing(const InputMessagePtr& msg) void ProtocolGame::parseTileRemoveThing(const InputMessagePtr& msg) { ThingPtr thing = getMappedThing(msg); - if(!thing) { + if (!thing) { g_logger.traceError("no thing"); return; } - if(!g_map.removeThing(thing)) + if (!g_map.removeThing(thing)) g_logger.traceError("unable to remove thing"); } @@ -1189,15 +1206,15 @@ void ProtocolGame::parseCreatureMove(const InputMessagePtr& msg) Position newPos = getPosition(msg); uint16_t stepDuration = 0; - if(g_game.getFeature(Otc::GameNewWalking)) + if (g_game.getFeature(Otc::GameNewWalking)) stepDuration = msg->getU16(); - if(!thing || !thing->isCreature()) { + if (!thing || !thing->isCreature()) { g_logger.traceError("no creature found to move"); return; } - if(!g_map.removeThing(thing)) { + if (!g_map.removeThing(thing)) { g_logger.traceError("unable to remove creature"); return; } @@ -1225,7 +1242,7 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg) int containerSize = 0; int firstIndex = 0; - if(g_game.getFeature(Otc::GameContainerPagination)) { + if (g_game.getFeature(Otc::GameContainerPagination)) { isUnlocked = (msg->getU8() != 0); // drag and drop hasPages = (msg->getU8() != 0); // pagination containerSize = msg->getU16(); // container size @@ -1235,7 +1252,7 @@ void ProtocolGame::parseOpenContainer(const InputMessagePtr& msg) int itemCount = msg->getU8(); std::vector items(itemCount); - for(int i = 0; i < itemCount; i++) + for (int i = 0; i < itemCount; i++) items[i] = getItem(msg); g_game.processOpenContainer(containerId, containerItem, name, capacity, hasParent, items, isUnlocked, hasPages, containerSize, firstIndex); @@ -1251,7 +1268,7 @@ void ProtocolGame::parseContainerAddItem(const InputMessagePtr& msg) { int containerId = msg->getU8(); int slot = 0; - if(g_game.getFeature(Otc::GameContainerPagination)) { + if (g_game.getFeature(Otc::GameContainerPagination)) { slot = msg->getU16(); // slot } ItemPtr item = getItem(msg); @@ -1262,7 +1279,7 @@ void ProtocolGame::parseContainerUpdateItem(const InputMessagePtr& msg) { int containerId = msg->getU8(); int slot; - if(g_game.getFeature(Otc::GameContainerPagination)) { + if (g_game.getFeature(Otc::GameContainerPagination)) { slot = msg->getU16(); } else { slot = msg->getU8(); @@ -1276,11 +1293,11 @@ void ProtocolGame::parseContainerRemoveItem(const InputMessagePtr& msg) int containerId = msg->getU8(); int slot; ItemPtr lastItem; - if(g_game.getFeature(Otc::GameContainerPagination)) { + if (g_game.getFeature(Otc::GameContainerPagination)) { slot = msg->getU16(); int itemId = msg->getU16(); - if(itemId != 0) + if (itemId != 0) lastItem = getItem(msg, itemId); } else { slot = msg->getU8(); @@ -1306,19 +1323,19 @@ void ProtocolGame::parseOpenNpcTrade(const InputMessagePtr& msg) std::vector> items; std::string npcName; - if(g_game.getFeature(Otc::GameNameOnNpcTrade)) + if (g_game.getFeature(Otc::GameNameOnNpcTrade)) npcName = msg->getString(); if (g_game.getFeature(Otc::GameTibia12Protocol) && g_game.getProtocolVersion() >= 1220) msg->getU16(); // shop item id int listCount; - if(g_game.getClientVersion() >= 900) + if (g_game.getClientVersion() >= 900) listCount = msg->getU16(); else listCount = msg->getU8(); - for(int i = 0; i < listCount; ++i) { + for (int i = 0; i < listCount; ++i) { uint16 itemId = msg->getU16(); uint8 count = msg->getU8(); @@ -1340,17 +1357,17 @@ void ProtocolGame::parsePlayerGoods(const InputMessagePtr& msg) std::vector> goods; uint64_t money; - if(g_game.getFeature(Otc::GameDoublePlayerGoodsMoney)) + if (g_game.getFeature(Otc::GameDoublePlayerGoodsMoney)) money = msg->getU64(); else money = msg->getU32(); int size = msg->getU8(); - for(int i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { int itemId = msg->getU16(); int amount; - if(g_game.getFeature(Otc::GameDoubleShopSellAmount)) + if (g_game.getFeature(Otc::GameDoubleShopSellAmount)) amount = msg->getU16(); else amount = msg->getU8(); @@ -1372,7 +1389,7 @@ void ProtocolGame::parseOwnTrade(const InputMessagePtr& msg) int count = msg->getU8(); std::vector items(count); - for(int i = 0; i < count; i++) + for (int i = 0; i < count; i++) items[i] = getItem(msg); g_game.processOwnTrade(name, items); @@ -1384,7 +1401,7 @@ void ProtocolGame::parseCounterTrade(const InputMessagePtr& msg) int count = msg->getU8(); std::vector items(count); - for(int i = 0; i < count; i++) + for (int i = 0; i < count; i++) items[i] = getItem(msg); g_game.processCounterTrade(name, items); @@ -1410,10 +1427,14 @@ void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg) if (g_game.getFeature(Otc::GameTibia12Protocol) && g_game.getClientVersion() >= 1203) { Otc::MagicEffectsType_t effectType = (Otc::MagicEffectsType_t)msg->getU8(); while (effectType != Otc::MAGIC_EFFECTS_END_LOOP) { - if (effectType == Otc::MAGIC_EFFECTS_CREATE_DISTANCEEFFECT) { + if (effectType == Otc::MAGIC_EFFECTS_DELTA) { + msg->getU8(); + } else if (effectType == Otc::MAGIC_EFFECTS_DELAY) { + msg->getU8(); // ? + } else if (effectType == Otc::MAGIC_EFFECTS_CREATE_DISTANCEEFFECT) { uint8_t shotId = msg->getU8(); - uint8_t offsetX = msg->getU8(); - uint8_t offsetY = msg->getU8(); + int8_t offsetX = static_cast(msg->getU8()); + int8_t offsetY = static_cast(msg->getU8()); if (!g_things.isValidDatId(shotId, ThingCategoryMissile)) { g_logger.traceError(stdext::format("invalid missile id %d", shotId)); return; @@ -1423,10 +1444,23 @@ void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg) missile->setId(shotId); missile->setPath(pos, Position(pos.x + offsetX, pos.y + offsetY, pos.z)); g_map.addThing(missile, pos); + } else if (effectType == Otc::MAGIC_EFFECTS_CREATE_DISTANCEEFFECT_REVERSED) { + uint8_t shotId = msg->getU8(); + int8_t offsetX = static_cast(msg->getU8()); + int8_t offsetY = static_cast(msg->getU8()); + if (!g_things.isValidDatId(shotId, ThingCategoryMissile)) { + g_logger.traceError(stdext::format("invalid missile id %d", shotId)); + return; + } + + MissilePtr missile = MissilePtr(new Missile()); + missile->setId(shotId); + missile->setPath(Position(pos.x + offsetX, pos.y + offsetY, pos.z), pos); + g_map.addThing(missile, pos); } else if (effectType == Otc::MAGIC_EFFECTS_CREATE_EFFECT) { uint8_t effectId = msg->getU8(); if (!g_things.isValidDatId(effectId, ThingCategoryEffect)) { - g_logger.traceError(stdext::format("invalid effect id %d", effectId)); + g_logger.traceError(stdext::format("invalid effect id %d", effectId)); continue; } EffectPtr effect = EffectPtr(new Effect()); @@ -1439,12 +1473,12 @@ void ProtocolGame::parseMagicEffect(const InputMessagePtr& msg) } int effectId; - if(g_game.getFeature(Otc::GameMagicEffectU16)) + if (g_game.getFeature(Otc::GameMagicEffectU16)) effectId = msg->getU16(); else effectId = msg->getU8(); - if(!g_things.isValidDatId(effectId, ThingCategoryEffect)) { + if (!g_things.isValidDatId(effectId, ThingCategoryEffect)) { g_logger.traceError(stdext::format("invalid effect id %d", effectId)); return; } @@ -1471,12 +1505,12 @@ void ProtocolGame::parseDistanceMissile(const InputMessagePtr& msg) Position fromPos = getPosition(msg); Position toPos = getPosition(msg); int shotId; - if(g_game.getFeature(Otc::GameDistanceEffectU16)) + if (g_game.getFeature(Otc::GameDistanceEffectU16)) shotId = msg->getU16(); else shotId = msg->getU8(); - if(!g_things.isValidDatId(shotId, ThingCategoryMissile)) { + if (!g_things.isValidDatId(shotId, ThingCategoryMissile)) { g_logger.traceError(stdext::format("invalid missile id %d", shotId)); return; } @@ -1493,7 +1527,7 @@ void ProtocolGame::parseCreatureMark(const InputMessagePtr& msg) int color = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->addTimedSquare(color); else g_logger.traceError("could not get creature"); @@ -1503,13 +1537,13 @@ void ProtocolGame::parseTrappers(const InputMessagePtr& msg) { int numTrappers = msg->getU8(); - if(numTrappers > 8) + if (numTrappers > 8) g_logger.traceError("too many trappers"); - for(int i=0;igetU32(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) { + if (creature) { //TODO: set creature as trapper } else g_logger.traceError("could not get creature"); @@ -1522,7 +1556,7 @@ void ProtocolGame::parseCreatureHealth(const InputMessagePtr& msg) int healthPercent = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setHealthPercent(healthPercent); // some servers has a bug in get spectators and sends unknown creatures updates @@ -1542,7 +1576,7 @@ void ProtocolGame::parseCreatureLight(const InputMessagePtr& msg) light.color = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setLight(light); else g_logger.traceError("could not get creature"); @@ -1554,7 +1588,7 @@ void ProtocolGame::parseCreatureOutfit(const InputMessagePtr& msg) Outfit outfit = getOutfit(msg); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setOutfit(outfit); else g_logger.traceError("could not get creature"); @@ -1565,15 +1599,15 @@ void ProtocolGame::parseCreatureSpeed(const InputMessagePtr& msg) uint id = msg->getU32(); int baseSpeed = -1; - if(g_game.getClientVersion() >= 1059) + if (g_game.getClientVersion() >= 1059) baseSpeed = msg->getU16(); int speed = msg->getU16(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) { + if (creature) { creature->setSpeed(speed); - if(baseSpeed != -1) + if (baseSpeed != -1) creature->setBaseSpeed(baseSpeed); } @@ -1591,7 +1625,7 @@ void ProtocolGame::parseCreatureSkulls(const InputMessagePtr& msg) int skull = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setSkull(skull); else g_logger.traceError("could not get creature"); @@ -1603,7 +1637,7 @@ void ProtocolGame::parseCreatureShields(const InputMessagePtr& msg) int shield = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setShield(shield); else g_logger.traceError("could not get creature"); @@ -1615,7 +1649,7 @@ void ProtocolGame::parseCreatureUnpass(const InputMessagePtr& msg) bool unpass = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setPassable(!unpass); else g_logger.traceError("could not get creature"); @@ -1626,7 +1660,7 @@ void ProtocolGame::parseEditText(const InputMessagePtr& msg) uint id = msg->getU32(); int itemId; - if(g_game.getClientVersion() >= 1010) { + if (g_game.getClientVersion() >= 1010) { // TODO: processEditText with ItemPtr as parameter ItemPtr item = getItem(msg); itemId = item->getId(); @@ -1638,7 +1672,7 @@ void ProtocolGame::parseEditText(const InputMessagePtr& msg) std::string writer = msg->getString(); std::string date = ""; - if(g_game.getFeature(Otc::GameWritableDate)) + if (g_game.getFeature(Otc::GameWritableDate)) date = msg->getString(); g_game.processEditText(id, itemId, maxLength, text, writer, date); @@ -1657,11 +1691,11 @@ void ProtocolGame::parsePremiumTrigger(const InputMessagePtr& msg) { int triggerCount = msg->getU8(); std::vector triggers; - for(int i=0;igetU8()); } - if(g_game.getClientVersion() <= 1096) { + if (g_game.getClientVersion() <= 1096) { /*bool something = */msg->getU8()/* == 1*/; } } @@ -1777,7 +1811,7 @@ void ProtocolGame::parseStoreOfferDescription(const InputMessagePtr& msg) void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg) { bool premium = msg->getU8(); // premium - if(g_game.getFeature(Otc::GamePremiumExpiration)) + if (g_game.getFeature(Otc::GamePremiumExpiration)) /*int premiumEx = */msg->getU32(); // premium expiration used for premium advertisement int vocation = msg->getU8(); // vocation @@ -1787,7 +1821,7 @@ void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg) int spellCount = msg->getU16(); std::vector spells; - for(int i=0;igetU8()); // spell id m_localPlayer->setPremium(premium); @@ -1800,7 +1834,7 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) double health; double maxHealth; - if(g_game.getFeature(Otc::GameDoubleHealth)) { + if (g_game.getFeature(Otc::GameDoubleHealth)) { health = msg->getU32(); maxHealth = msg->getU32(); } else { @@ -1809,17 +1843,17 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) } double freeCapacity; - if(g_game.getFeature(Otc::GameDoubleFreeCapacity)) + if (g_game.getFeature(Otc::GameDoubleFreeCapacity)) freeCapacity = msg->getU32() / 100.0; else freeCapacity = msg->getU16() / 100.0; - double totalCapacity = 0; - if(g_game.getFeature(Otc::GameTotalCapacity) && !g_game.getFeature(Otc::GameTibia12Protocol)) + double totalCapacity = freeCapacity; + if (g_game.getFeature(Otc::GameTotalCapacity) && !g_game.getFeature(Otc::GameTibia12Protocol)) totalCapacity = msg->getU32() / 100.0; double experience; - if(g_game.getFeature(Otc::GameDoubleExperience)) + if (g_game.getFeature(Otc::GameDoubleExperience)) experience = msg->getU64(); else experience = msg->getU32(); @@ -1827,18 +1861,19 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) double level; if (g_game.getFeature(Otc::GameDoubleLevel)) level = msg->getU32(); - else + else level = msg->getU16(); double levelPercent = msg->getU8(); - if(g_game.getFeature(Otc::GameExperienceBonus)) { - if(g_game.getClientVersion() <= 1096) { + if (g_game.getFeature(Otc::GameExperienceBonus)) { + if (g_game.getClientVersion() <= 1096) { /*double experienceBonus = */msg->getDouble(); } else { /*int baseXpGain = */msg->getU16(); - if(!g_game.getFeature(Otc::GameTibia12Protocol)) - /*int voucherAddend = */msg->getU16(); + if (!g_game.getFeature(Otc::GameTibia12Protocol)) { + /*int voucherAddend = */msg->getU16(); + } /*int grindingAddend = */msg->getU16(); /*int storeBoostAddend = */ msg->getU16(); /*int huntingBoostFactor = */ msg->getU16(); @@ -1848,7 +1883,7 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) double mana; double maxMana; - if(g_game.getFeature(Otc::GameDoubleHealth)) { + if (g_game.getFeature(Otc::GameDoubleHealth)) { mana = msg->getU32(); maxMana = msg->getU32(); } else { @@ -1873,7 +1908,7 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) } double magicLevelPercent = 0; - if(!g_game.getFeature(Otc::GameTibia12Protocol)) + if (!g_game.getFeature(Otc::GameTibia12Protocol)) magicLevelPercent = msg->getU8(); double soul; @@ -1883,21 +1918,21 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) soul = msg->getU8(); double stamina = 0; - if(g_game.getFeature(Otc::GamePlayerStamina)) + if (g_game.getFeature(Otc::GamePlayerStamina)) stamina = msg->getU16(); double baseSpeed = 0; - if(g_game.getFeature(Otc::GameSkillsBase)) + if (g_game.getFeature(Otc::GameSkillsBase)) baseSpeed = msg->getU16(); double regeneration = 0; - if(g_game.getFeature(Otc::GamePlayerRegenerationTime)) + if (g_game.getFeature(Otc::GamePlayerRegenerationTime)) regeneration = msg->getU16(); double training = 0; - if(g_game.getFeature(Otc::GameOfflineTrainingTime)) { + if (g_game.getFeature(Otc::GameOfflineTrainingTime)) { training = msg->getU16(); - if(g_game.getClientVersion() >= 1097) { + if (g_game.getClientVersion() >= 1097) { /*int remainingStoreXpBoostSeconds = */msg->getU16(); /*bool canBuyMoreStoreXpBoosts = */msg->getU8(); } @@ -1924,7 +1959,7 @@ void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg) { int lastSkill = Otc::Fishing + 1; - if(g_game.getFeature(Otc::GameAdditionalSkills)) + if (g_game.getFeature(Otc::GameAdditionalSkills)) lastSkill = Otc::LastSkill; if (g_game.getFeature(Otc::GameTibia12Protocol)) { @@ -1936,17 +1971,17 @@ void ProtocolGame::parsePlayerSkills(const InputMessagePtr& msg) m_localPlayer->setBaseMagicLevel(baseLevel); } - for(int skill = 0; skill < lastSkill; skill++) { + for (int skill = 0; skill < lastSkill; skill++) { int level; - if(g_game.getFeature(Otc::GameDoubleSkills)) + if (g_game.getFeature(Otc::GameDoubleSkills)) level = msg->getU16(); else level = msg->getU8(); int baseLevel; - if(g_game.getFeature(Otc::GameSkillsBase)) - if(g_game.getFeature(Otc::GameBaseSkillU16)) + if (g_game.getFeature(Otc::GameSkillsBase)) + if (g_game.getFeature(Otc::GameBaseSkillU16)) baseLevel = msg->getU16(); else baseLevel = msg->getU8(); @@ -1981,7 +2016,7 @@ void ProtocolGame::parsePlayerState(const InputMessagePtr& msg) int states; if (g_game.getFeature(Otc::GamePlayerStateU32)) states = msg->getU32(); - else if(g_game.getFeature(Otc::GamePlayerStateU16)) + else if (g_game.getFeature(Otc::GamePlayerStateU16)) states = msg->getU16(); else states = msg->getU8(); @@ -1992,7 +2027,7 @@ void ProtocolGame::parsePlayerState(const InputMessagePtr& msg) void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg) { uint seq = 0; - if(g_game.getFeature(Otc::GameAttackSeq)) + if (g_game.getFeature(Otc::GameAttackSeq)) seq = msg->getU32(); g_game.processAttackCancel(seq); @@ -2006,7 +2041,7 @@ void ProtocolGame::parsePlayerModes(const InputMessagePtr& msg) bool safeMode = msg->getU8(); int pvpMode = 0; - if(g_game.getFeature(Otc::GamePVPMode)) + if (g_game.getFeature(Otc::GamePVPMode)) pvpMode = msg->getU8(); g_game.processPlayerModes((Otc::FightModes)fightMode, (Otc::ChaseModes)chaseMode, safeMode, (Otc::PVPModes)pvpMode); @@ -2037,7 +2072,7 @@ void ProtocolGame::parseMultiUseCooldown(const InputMessagePtr& msg) void ProtocolGame::parseTalk(const InputMessagePtr& msg) { - if(g_game.getFeature(Otc::GameMessageStatements)) + if (g_game.getFeature(Otc::GameMessageStatements)) msg->getU32(); // channel statement guid std::string name = g_game.formatCreatureName(msg->getString()); @@ -2055,38 +2090,38 @@ void ProtocolGame::parseTalk(const InputMessagePtr& msg) int channelId = 0; Position pos; - switch(mode) { - case Otc::MessageSay: - case Otc::MessageWhisper: - case Otc::MessageYell: - case Otc::MessageMonsterSay: - case Otc::MessageMonsterYell: - case Otc::MessageNpcTo: - case Otc::MessageBarkLow: - case Otc::MessageBarkLoud: - case Otc::MessageSpell: - case Otc::MessageNpcFromStartBlock: - pos = getPosition(msg); - break; - case Otc::MessageChannel: - case Otc::MessageChannelManagement: - case Otc::MessageChannelHighlight: - case Otc::MessageGamemasterChannel: - channelId = msg->getU16(); - break; - case Otc::MessageNpcFrom: - case Otc::MessagePrivateFrom: - case Otc::MessageGamemasterBroadcast: - case Otc::MessageGamemasterPrivateFrom: - case Otc::MessageRVRAnswer: - case Otc::MessageRVRContinue: - break; - case Otc::MessageRVRChannel: - msg->getU32(); - break; - default: - stdext::throw_exception(stdext::format("unknown message mode %d", mode)); - break; + switch (mode) { + case Otc::MessageSay: + case Otc::MessageWhisper: + case Otc::MessageYell: + case Otc::MessageMonsterSay: + case Otc::MessageMonsterYell: + case Otc::MessageNpcTo: + case Otc::MessageBarkLow: + case Otc::MessageBarkLoud: + case Otc::MessageSpell: + case Otc::MessageNpcFromStartBlock: + pos = getPosition(msg); + break; + case Otc::MessageChannel: + case Otc::MessageChannelManagement: + case Otc::MessageChannelHighlight: + case Otc::MessageGamemasterChannel: + channelId = msg->getU16(); + break; + case Otc::MessageNpcFrom: + case Otc::MessagePrivateFrom: + case Otc::MessageGamemasterBroadcast: + case Otc::MessageGamemasterPrivateFrom: + case Otc::MessageRVRAnswer: + case Otc::MessageRVRContinue: + break; + case Otc::MessageRVRChannel: + msg->getU32(); + break; + default: + stdext::throw_exception(stdext::format("unknown message mode %d", mode)); + break; } std::string text = msg->getString(); @@ -2098,7 +2133,7 @@ void ProtocolGame::parseChannelList(const InputMessagePtr& msg) { int count = msg->getU8(); std::vector > channelList; - for(int i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { int id = msg->getU16(); std::string name = msg->getString(); channelList.push_back(std::make_tuple(id, name)); @@ -2112,12 +2147,12 @@ void ProtocolGame::parseOpenChannel(const InputMessagePtr& msg) int channelId = msg->getU16(); std::string name = msg->getString(); - if(g_game.getFeature(Otc::GameChannelPlayerList)) { + if (g_game.getFeature(Otc::GameChannelPlayerList)) { int joinedPlayers = msg->getU16(); - for(int i=0;igetString()); // player name int invitedPlayers = msg->getU16(); - for(int i=0;igetString()); // player name } @@ -2187,67 +2222,71 @@ void ProtocolGame::parseTextMessage(const InputMessagePtr& msg) Otc::MessageMode mode = Proto::translateMessageModeFromServer(code); std::string text; - switch(mode) { - case Otc::MessageChannelManagement: { - /*int channel = */msg->getU16(); - text = msg->getString(); - break; - } - case Otc::MessageGuild: - case Otc::MessagePartyManagement: - case Otc::MessageParty: { - /*int channel = */msg->getU16(); - text = msg->getString(); - break; - } - case Otc::MessageDamageDealed: - case Otc::MessageDamageReceived: - case Otc::MessageDamageOthers: { - Position pos = getPosition(msg); - uint value[2]; - int color[2]; + switch (mode) { + case Otc::MessageChannelManagement: + { + /*int channel = */msg->getU16(); + text = msg->getString(); + break; + } + case Otc::MessageGuild: + case Otc::MessagePartyManagement: + case Otc::MessageParty: + { + /*int channel = */msg->getU16(); + text = msg->getString(); + break; + } + case Otc::MessageDamageDealed: + case Otc::MessageDamageReceived: + case Otc::MessageDamageOthers: + { + Position pos = getPosition(msg); + uint value[2]; + int color[2]; - // physical damage - value[0] = msg->getU32(); - color[0] = msg->getU8(); + // physical damage + value[0] = msg->getU32(); + color[0] = msg->getU8(); - // magic damage - value[1] = msg->getU32(); - color[1] = msg->getU8(); - text = msg->getString(); - - for(int i=0;i<2;++i) { - if(value[i] == 0) - continue; - AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setColor(color[i]); - animatedText->setText(stdext::to_string(value[i])); - g_map.addThing(animatedText, pos); - } - break; - } - case Otc::MessageHeal: - case Otc::MessageMana: - case Otc::MessageExp: - case Otc::MessageHealOthers: - case Otc::MessageExpOthers: { - Position pos = getPosition(msg); - uint value = msg->getU32(); - int color = msg->getU8(); - text = msg->getString(); + // magic damage + value[1] = msg->getU32(); + color[1] = msg->getU8(); + text = msg->getString(); + for (int i = 0; i < 2; ++i) { + if (value[i] == 0) + continue; AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setColor(color); - animatedText->setText(stdext::to_string(value)); + animatedText->setColor(color[i]); + animatedText->setText(stdext::to_string(value[i])); g_map.addThing(animatedText, pos); - break; } - case Otc::MessageInvalid: - stdext::throw_exception(stdext::format("unknown message mode %d", mode)); - break; - default: - text = msg->getString(); - break; + break; + } + case Otc::MessageHeal: + case Otc::MessageMana: + case Otc::MessageExp: + case Otc::MessageHealOthers: + case Otc::MessageExpOthers: + { + Position pos = getPosition(msg); + uint value = msg->getU32(); + int color = msg->getU8(); + text = msg->getString(); + + AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); + animatedText->setColor(color); + animatedText->setText(stdext::to_string(value)); + g_map.addThing(animatedText, pos); + break; + } + case Otc::MessageInvalid: + stdext::throw_exception(stdext::format("unknown message mode %d", mode)); + break; + default: + text = msg->getString(); + break; } g_game.processTextMessage(mode, text); @@ -2269,7 +2308,7 @@ void ProtocolGame::parseWalkWait(const InputMessagePtr& msg) void ProtocolGame::parseFloorChangeUp(const InputMessagePtr& msg) { Position pos; - if(g_game.getFeature(Otc::GameMapMovePosition)) + if (g_game.getFeature(Otc::GameMapMovePosition)) pos = getPosition(msg); else pos = g_map.getCentralPosition(); @@ -2282,10 +2321,10 @@ void ProtocolGame::parseFloorChangeUp(const InputMessagePtr& msg) g_map.setCentralPosition(newPos); int skip = 0; - if(pos.z == Otc::SEA_FLOOR) - for(int i = Otc::SEA_FLOOR - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; i >= 0; i--) + if (pos.z == Otc::SEA_FLOOR) + for (int i = Otc::SEA_FLOOR - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; i >= 0; i--) skip = setFloorDescription(msg, pos.x - range.left, pos.y - range.top, i, range.horizontal(), range.vertical(), 8 - i, skip); - else if(pos.z > Otc::SEA_FLOOR) + else if (pos.z > Otc::SEA_FLOOR) skip = setFloorDescription(msg, pos.x - range.left, pos.y - range.top, pos.z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE, range.horizontal(), range.vertical(), 3, skip); } @@ -2293,7 +2332,7 @@ void ProtocolGame::parseFloorChangeUp(const InputMessagePtr& msg) void ProtocolGame::parseFloorChangeDown(const InputMessagePtr& msg) { Position pos; - if(g_game.getFeature(Otc::GameMapMovePosition)) + if (g_game.getFeature(Otc::GameMapMovePosition)) pos = getPosition(msg); else pos = g_map.getCentralPosition(); @@ -2306,12 +2345,11 @@ void ProtocolGame::parseFloorChangeDown(const InputMessagePtr& msg) g_map.setCentralPosition(newPos); int skip = 0; - if(pos.z == Otc::UNDERGROUND_FLOOR) { + if (pos.z == Otc::UNDERGROUND_FLOOR) { int j, i; - for(i = pos.z, j = -1; i <= pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE; ++i, --j) + for (i = pos.z, j = -1; i <= pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE; ++i, --j) skip = setFloorDescription(msg, pos.x - range.left, pos.y - range.top, i, range.horizontal(), range.vertical(), j, skip); - } - else if(pos.z > Otc::UNDERGROUND_FLOOR && pos.z < Otc::MAX_Z-1) + } else if (pos.z > Otc::UNDERGROUND_FLOOR && pos.z < Otc::MAX_Z - 1) skip = setFloorDescription(msg, pos.x - range.left, pos.y - range.top, pos.z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, range.horizontal(), range.vertical(), -3, skip); } @@ -2320,9 +2358,9 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) Outfit currentOutfit = getOutfit(msg); std::vector > outfitList; - if(g_game.getFeature(Otc::GameNewOutfitProtocol)) { + if (g_game.getFeature(Otc::GameNewOutfitProtocol)) { int outfitCount = g_game.getFeature(Otc::GameTibia12Protocol) ? msg->getU16() : msg->getU8(); - for(int i = 0; i < outfitCount; i++) { + for (int i = 0; i < outfitCount; i++) { int outfitId = msg->getU16(); std::string outfitName = msg->getString(); int outfitAddons = msg->getU8(); @@ -2336,7 +2374,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) } } else { int outfitStart, outfitEnd; - if(g_game.getFeature(Otc::GameLooktypeU16)) { + if (g_game.getFeature(Otc::GameLooktypeU16)) { outfitStart = msg->getU16(); outfitEnd = msg->getU16(); } else { @@ -2344,7 +2382,7 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) outfitEnd = msg->getU8(); } - for(int i = outfitStart; i <= outfitEnd; i++) + for (int i = outfitStart; i <= outfitEnd; i++) outfitList.push_back(std::make_tuple(i, "", 0)); } @@ -2352,9 +2390,9 @@ void ProtocolGame::parseOpenOutfitWindow(const InputMessagePtr& msg) std::vector > wingList; std::vector > auraList; std::vector > shaderList; - if(g_game.getFeature(Otc::GamePlayerMounts)) { + if (g_game.getFeature(Otc::GamePlayerMounts)) { int mountCount = g_game.getFeature(Otc::GameTibia12Protocol) ? msg->getU16() : msg->getU8(); - for(int i = 0; i < mountCount; ++i) { + for (int i = 0; i < mountCount; ++i) { int mountId = msg->getU16(); // mount type std::string mountName = msg->getString(); // mount name if (g_game.getFeature(Otc::GameTibia12Protocol)) { @@ -2408,24 +2446,29 @@ void ProtocolGame::parseVipAdd(const InputMessagePtr& msg) id = msg->getU32(); name = g_game.formatCreatureName(msg->getString()); - if(g_game.getFeature(Otc::GameAdditionalVipInfo)) { + if (g_game.getFeature(Otc::GameAdditionalVipInfo)) { desc = msg->getString(); iconId = msg->getU32(); notifyLogin = msg->getU8(); } status = msg->getU8(); + if (g_game.getFeature(Otc::GameTibia12Protocol)) { + int groups = msg->getU8(); + for (int i = 0; i < groups; ++i) + msg->getU8(); // group id + } + g_game.processVipAdd(id, name, status, desc, iconId, notifyLogin); } void ProtocolGame::parseVipState(const InputMessagePtr& msg) { uint id = msg->getU32(); - if(g_game.getFeature(Otc::GameLoginPending)) { + if (g_game.getFeature(Otc::GameLoginPending)) { uint status = msg->getU8(); g_game.processVipStateChange(id, status); - } - else { + } else { g_game.processVipStateChange(id, 1); } } @@ -2436,16 +2479,117 @@ void ProtocolGame::parseVipLogout(const InputMessagePtr& msg) g_game.processVipStateChange(id, 0); } +void ProtocolGame::parseVipGroupData(const InputMessagePtr& msg) +{ + int size = msg->getU8(); + for (int i = 0; i < size; ++i) { + msg->getU8(); // group id + msg->getString(); // group name + msg->getU8(); // unkown + } + + msg->getU8(); // max vip groups +} + void ProtocolGame::parseTutorialHint(const InputMessagePtr& msg) { int id = msg->getU8(); g_game.processTutorialHint(id); } -void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg) +void ProtocolGame::parseCyclopediaMapData(const InputMessagePtr& msg) { if (g_game.getFeature(Otc::GameTibia12Protocol)) { - msg->getU8(); // unknown + int type = msg->getU8(); + switch (type) { + case 0: + break; + case 1: + { + int count = msg->getU16(); + for (int i = 0; i < count; ++i) { + msg->getU8(); + msg->getU8(); + msg->getU8(); + msg->getU8(); + } + count = msg->getU16(); + for (int i = 0; i < count; ++i) { + msg->getU16(); + } + count = msg->getU16(); + for (int i = 0; i < count; ++i) { + msg->getU16(); + } + break; + } + case 2: // raid + { + getPosition(msg); + msg->getU8(); + break; + } + case 3: + { + msg->getU8(); + msg->getU8(); + msg->getU8(); + break; + } + case 4: + { + msg->getU8(); + msg->getU8(); + msg->getU8(); + break; + } + case 5: + { + msg->getU16(); + msg->getU8(); + int count = msg->getU8(); + for (int i = 0; i < count; ++i) { + getPosition(msg); + msg->getU8(); + } + break; + } + case 6: + { + break; + } + case 7: + { + break; + } + case 8: + { + break; + } + case 9: + { + msg->getU32(); + msg->getU32(); + int count = msg->getU8(); + for (int i = 0; i < count; ++i) { + msg->getU16(); + msg->getU32(); + msg->getU32(); + msg->getU8(); + } + } + case 10: + { + msg->getU16(); + break; + } + case 11: + { + break; + } + } + if (type != 0) + return; } Position pos = getPosition(msg); @@ -2453,10 +2597,10 @@ void ProtocolGame::parseAutomapFlag(const InputMessagePtr& msg) std::string description = msg->getString(); bool remove = false; - if(g_game.getFeature(Otc::GameMinimapRemove)) + if (g_game.getFeature(Otc::GameMinimapRemove)) remove = msg->getU8() != 0; - if(!remove) + if (!remove) g_game.processAddAutomapFlag(pos, icon, description); else g_game.processRemoveAutomapFlag(pos, icon, description); @@ -2466,7 +2610,7 @@ void ProtocolGame::parseQuestLog(const InputMessagePtr& msg) { std::vector > questList; int questsCount = msg->getU16(); - for(int i = 0; i < questsCount; i++) { + for (int i = 0; i < questsCount; i++) { int id = msg->getU16(); std::string name = msg->getString(); bool completed = msg->getU8(); @@ -2481,7 +2625,7 @@ void ProtocolGame::parseQuestLine(const InputMessagePtr& msg) std::vector> questMissions; int questId = msg->getU16(); int missionCount = msg->getU8(); - for(int i = 0; i < missionCount; i++) { + for (int i = 0; i < missionCount; i++) { if (g_game.getFeature(Otc::GameTibia12Protocol)) msg->getU16(); // mission id @@ -2506,7 +2650,7 @@ void ProtocolGame::parseItemInfo(const InputMessagePtr& msg) { std::vector> list; int size = msg->getU8(); - for(int i=0;isetId(msg->getU16()); item->setCountOrSubType(msg->getU8()); @@ -2521,7 +2665,7 @@ void ProtocolGame::parseItemInfo(const InputMessagePtr& msg) void ProtocolGame::parsePlayerInventory(const InputMessagePtr& msg) { int size = msg->getU16(); - for(int i=0;igetU16(); // id msg->getU8(); // subtype msg->getU16(); // count @@ -2536,7 +2680,7 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg) int sizeButtons = msg->getU8(); std::vector > buttonList; - for(int i = 0; i < sizeButtons; ++i) { + for (int i = 0; i < sizeButtons; ++i) { std::string value = msg->getString(); int id = msg->getU8(); buttonList.push_back(std::make_tuple(id, value)); @@ -2544,18 +2688,17 @@ void ProtocolGame::parseModalDialog(const InputMessagePtr& msg) int sizeChoices = msg->getU8(); std::vector > choiceList; - for(int i = 0; i < sizeChoices; ++i) { + for (int i = 0; i < sizeChoices; ++i) { std::string value = msg->getString(); int id = msg->getU8(); choiceList.push_back(std::make_tuple(id, value)); } int enterButton, escapeButton; - if(g_game.getClientVersion() > 970) { + if (g_game.getClientVersion() > 970) { escapeButton = msg->getU8(); enterButton = msg->getU8(); - } - else { + } else { enterButton = msg->getU8(); escapeButton = msg->getU8(); } @@ -2745,6 +2888,39 @@ Imbuement ProtocolGame::getImbuementInfo(const InputMessagePtr& msg) return i; } +void ProtocolGame::parseLootContainers(const InputMessagePtr& msg) +{ + msg->getU8(); // quickLootFallbackToMainContainer ? 1 : 0 + int containers = msg->getU8(); + for (int i = 0; i < containers; ++i) { + msg->getU8(); // id? + msg->getU16(); + } +} + +void ProtocolGame::parseSupplyStash(const InputMessagePtr& msg) +{ + int size = msg->getU16(); + for (int i = 0; i < size; ++i) { + msg->getU16(); // item id + msg->getU32(); // unknown + } + msg->getU16(); // available slots? +} + +void ProtocolGame::parseDepotState(const InputMessagePtr& msg) +{ + msg->getU8(); // unknown, true/false + if (g_game.getProtocolVersion() >= 1230) { + msg->getU8(); // unknown + } +} + +void ProtocolGame::parseTournamentLeaderboard(const InputMessagePtr& msg) +{ + msg->getU8(); + msg->getU8(); +} void ProtocolGame::parseKillTracker(const InputMessagePtr& msg) { @@ -2793,7 +2969,7 @@ void ProtocolGame::parseExtendedOpcode(const InputMessagePtr& msg) int opcode = msg->getU8(); std::string buffer = msg->getString(); - if(opcode == 0) + if (opcode == 0) m_enableSendExtendedOpcode = true; else callLuaField("onExtendedOpcode", opcode, buffer); @@ -2805,10 +2981,10 @@ void ProtocolGame::parseChangeMapAwareRange(const InputMessagePtr& msg) int yrange = msg->getU8(); AwareRange range; - range.left = xrange/2; - range.right = xrange/2 + 1; - range.top = yrange/2; - range.bottom = yrange/2 + 1; + range.left = xrange / 2; + range.right = xrange / 2 + 1; + range.top = yrange / 2; + range.bottom = yrange / 2 + 1; g_map.setAwareRange(range); g_lua.callGlobalField("g_game", "onMapChangeAwareRange", xrange, yrange); @@ -2831,21 +3007,21 @@ void ProtocolGame::parseFeatures(const InputMessagePtr& msg) void ProtocolGame::parseCreaturesMark(const InputMessagePtr& msg) { int len; - if(g_game.getClientVersion() >= 1035) { + if (g_game.getClientVersion() >= 1035) { len = 1; } else { len = msg->getU8(); } - for(int i=0; igetU32(); bool isPermanent = msg->getU8() != 1; uint8 markType = msg->getU8(); CreaturePtr creature = g_map.getCreatureById(id); - if(creature) { - if(isPermanent) { - if(markType == 0xff) + if (creature) { + if (isPermanent) { + if (markType == 0xff) creature->hideStaticSquare(); else creature->showStaticSquare(Color::from8bit(markType)); @@ -2861,8 +3037,11 @@ void ProtocolGame::parseCreatureType(const InputMessagePtr& msg) uint32 id = msg->getU32(); uint8 type = msg->getU8(); + if (g_game.getFeature(Otc::GameTibia12Protocol) && type == Proto::CreatureTypeSummonOwn) + msg->getU32(); + CreaturePtr creature = g_map.getCreatureById(id); - if(creature) + if (creature) creature->setType(type); else g_logger.traceError("could not get creature"); @@ -2906,28 +3085,27 @@ void ProtocolGame::setMapDescription(const InputMessagePtr& msg, int x, int y, i { int startz, endz, zstep; - if(z > Otc::SEA_FLOOR) { + if (z > Otc::SEA_FLOOR) { startz = z - Otc::AWARE_UNDEGROUND_FLOOR_RANGE; endz = std::min(z + Otc::AWARE_UNDEGROUND_FLOOR_RANGE, (int)Otc::MAX_Z); zstep = 1; - } - else { + } else { startz = Otc::SEA_FLOOR; endz = 0; zstep = -1; } int skip = 0; - for(int nz = startz; nz != endz + zstep; nz += zstep) + for (int nz = startz; nz != endz + zstep; nz += zstep) skip = setFloorDescription(msg, x, y, nz, width, height, z - nz, skip); } int ProtocolGame::setFloorDescription(const InputMessagePtr& msg, int x, int y, int z, int width, int height, int offset, int skip) { - for(int nx = 0; nx < width; nx++) { - for(int ny = 0; ny < height; ny++) { + for (int nx = 0; nx < width; nx++) { + for (int ny = 0; ny < height; ny++) { Position tilePos(x + nx + offset, y + ny + offset, z); - if(skip == 0) + if (skip == 0) skip = setTileDescription(msg, tilePos); else { g_map.cleanTile(tilePos); @@ -2941,7 +3119,7 @@ int ProtocolGame::setFloorDescription(const InputMessagePtr& msg, int x, int y, int ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position position) { g_map.cleanTile(position); - if(msg->peekU16() >= 0xff00) + if (msg->peekU16() >= 0xff00) return msg->getU16() & 0xff; if (g_game.getFeature(Otc::GameNewWalking)) { @@ -2950,15 +3128,15 @@ int ProtocolGame::setTileDescription(const InputMessagePtr& msg, Position positi g_map.setTileSpeed(position, groundSpeed, blocking); } - if(g_game.getFeature(Otc::GameEnvironmentEffect) && !g_game.getFeature(Otc::GameTibia12Protocol)) { + if (g_game.getFeature(Otc::GameEnvironmentEffect) && !g_game.getFeature(Otc::GameTibia12Protocol)) { msg->getU16(); } - for(int stackPos=0;stackPos<256;stackPos++) { - if(msg->peekU16() >= 0xff00) + for (int stackPos = 0; stackPos < 256; stackPos++) { + if (msg->peekU16() >= 0xff00) return msg->getU16() & 0xff; - if(stackPos > 10) + if (stackPos > 10) g_logger.traceError(stdext::format("too many things, pos=%s, stackpos=%d", stdext::to_string(position), stackPos)); ThingPtr thing = getThing(msg); @@ -2973,22 +3151,22 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg, bool ignoreMount) Outfit outfit; int lookType; - if(g_game.getFeature(Otc::GameLooktypeU16)) + if (g_game.getFeature(Otc::GameLooktypeU16)) lookType = msg->getU16(); else lookType = msg->getU8(); - if(lookType != 0) { + if (lookType != 0) { outfit.setCategory(ThingCategoryCreature); int head = msg->getU8(); int body = msg->getU8(); int legs = msg->getU8(); int feet = msg->getU8(); int addons = 0; - if(g_game.getFeature(Otc::GamePlayerAddons)) + if (g_game.getFeature(Otc::GamePlayerAddons)) addons = msg->getU8(); - if(!g_things.isValidDatId(lookType, ThingCategoryCreature)) { + if (!g_things.isValidDatId(lookType, ThingCategoryCreature)) { g_logger.traceError(stdext::format("invalid outfit looktype %d", lookType)); lookType = 0; } @@ -2999,15 +3177,13 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg, bool ignoreMount) outfit.setLegs(legs); outfit.setFeet(feet); outfit.setAddons(addons); - } - else { + } else { int lookTypeEx = msg->getU16(); - if(lookTypeEx == 0) { + if (lookTypeEx == 0) { outfit.setCategory(ThingCategoryEffect); outfit.setAuxId(13); // invisible effect id - } - else { - if(!g_things.isValidDatId(lookTypeEx, ThingCategoryItem)) { + } else { + if (!g_things.isValidDatId(lookTypeEx, ThingCategoryItem)) { g_logger.traceError(stdext::format("invalid outfit looktypeex %d", lookTypeEx)); lookTypeEx = 0; } @@ -3038,11 +3214,11 @@ ThingPtr ProtocolGame::getThing(const InputMessagePtr& msg) int id = msg->getU16(); - if(id == 0) + if (id == 0) stdext::throw_exception("invalid thing id (0)"); - else if(id == Proto::UnknownCreature || id == Proto::OutdatedCreature || id == Proto::Creature) + else if (id == Proto::UnknownCreature || id == Proto::OutdatedCreature || id == Proto::Creature) thing = getCreature(msg, id); - else if(id == Proto::StaticText) // otclient only + else if (id == Proto::StaticText) // otclient only thing = getStaticText(msg, id); else // item thing = getItem(msg, id, false); @@ -3055,7 +3231,7 @@ ThingPtr ProtocolGame::getMappedThing(const InputMessagePtr& msg) ThingPtr thing; uint16 x = msg->getU16(); - if(x != 0xffff) { + if (x != 0xffff) { Position pos; pos.x = x; pos.y = msg->getU16(); @@ -3064,12 +3240,12 @@ ThingPtr ProtocolGame::getMappedThing(const InputMessagePtr& msg) VALIDATE(stackpos != 255); thing = g_map.getThing(pos, stackpos); - if(!thing) + if (!thing) g_logger.traceError(stdext::format("no thing at pos:%s, stackpos:%d", stdext::to_string(pos), stackpos)); } else { uint32 id = msg->getU32(); thing = g_map.getCreatureById(id); - if(!thing) + if (!thing) g_logger.traceError(stdext::format("no creature with id %u", id)); } @@ -3078,16 +3254,16 @@ ThingPtr ProtocolGame::getMappedThing(const InputMessagePtr& msg) CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) { - if(type == 0) + if (type == 0) type = msg->getU16(); CreaturePtr creature; bool known = (type != Proto::UnknownCreature); - if(type == Proto::OutdatedCreature || type == Proto::UnknownCreature) { - if(known) { + if (type == Proto::OutdatedCreature || type == Proto::UnknownCreature) { + if (known) { uint id = msg->getU32(); creature = g_map.getCreatureById(id); - if(!creature) + if (!creature) g_logger.traceError("server said that a creature is known, but it's not"); } else { uint removeId = msg->getU32(); @@ -3096,12 +3272,12 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) uint id = msg->getU32(); int creatureType; - if(g_game.getClientVersion() >= 910) + if (g_game.getClientVersion() >= 910) creatureType = msg->getU8(); else { - if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId) + if (id >= Proto::PlayerStartId && id < Proto::PlayerEndId) creatureType = Proto::CreatureTypePlayer; - else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId) + else if (id >= Proto::MonsterStartId && id < Proto::MonsterEndId) creatureType = Proto::CreatureTypeMonster; else creatureType = Proto::CreatureTypeNpc; @@ -3112,16 +3288,15 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) std::string name = g_game.formatCreatureName(msg->getString()); - if(id == m_localPlayer->getId()) + if (id == m_localPlayer->getId()) creature = m_localPlayer; - else if(creatureType == Proto::CreatureTypePlayer) { + else if (creatureType == Proto::CreatureTypePlayer) { // fixes a bug server side bug where GameInit is not sent and local player id is unknown - if(m_localPlayer->getId() == 0 && name == m_localPlayer->getName()) + if (m_localPlayer->getId() == 0 && name == m_localPlayer->getName()) creature = m_localPlayer; else creature = PlayerPtr(new Player); - } - else if (creatureType == Proto::CreatureTypeMonster) + } else if (creatureType == Proto::CreatureTypeMonster) creature = MonsterPtr(new Monster); else if (creatureType == Proto::CreatureTypeNpc) creature = NpcPtr(new Npc); @@ -3130,7 +3305,7 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) } else g_logger.traceError("creature type is invalid"); - if(creature) { + if (creature) { creature->setId(id); creature->setName(name); @@ -3157,40 +3332,42 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) bool unpass = true; uint8 mark; - if(g_game.getFeature(Otc::GameCreatureEmblems) && !known) + if (g_game.getFeature(Otc::GameCreatureEmblems) && !known) emblem = msg->getU8(); - if(g_game.getFeature(Otc::GameThingMarks)) { + if (g_game.getFeature(Otc::GameThingMarks)) { creatureType = msg->getU8(); - if (creatureType == Proto::CreatureTypeSummonOwn) - msg->getU32(); // master - if (g_game.getClientVersion() >= 1220 && creatureType == Proto::CreatureTypePlayer) - msg->getU8(); // vocation id + if (g_game.getFeature(Otc::GameTibia12Protocol)) { + if (creatureType == Proto::CreatureTypeSummonOwn) + msg->getU32(); // master + if (g_game.getClientVersion() >= 1220 && creatureType == Proto::CreatureTypePlayer) + msg->getU8(); // vocation id + } } - if(g_game.getFeature(Otc::GameCreatureIcons)) { + if (g_game.getFeature(Otc::GameCreatureIcons)) { icon = msg->getU8(); } - if(g_game.getFeature(Otc::GameThingMarks)) { + if (g_game.getFeature(Otc::GameThingMarks)) { mark = msg->getU8(); // mark - if(g_game.getFeature(Otc::GameTibia12Protocol)) + if (g_game.getFeature(Otc::GameTibia12Protocol)) msg->getU8(); // inspection? else msg->getU16(); // helpers? - if(creature) { - if(mark == 0xff) + if (creature) { + if (mark == 0xff) creature->hideStaticSquare(); else creature->showStaticSquare(Color::from8bit(mark)); } } - if(g_game.getClientVersion() >= 854 || g_game.getFeature(Otc::GameCreatureWalkthrough)) + if (g_game.getClientVersion() >= 854 || g_game.getFeature(Otc::GameCreatureWalkthrough)) unpass = msg->getU8(); - if(creature) { + if (creature) { creature->setHealthPercent(healthPercent); creature->setDirection(direction); creature->setOutfit(outfit); @@ -3200,23 +3377,23 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) creature->setPassable(!unpass); creature->setLight(light); - if(emblem != -1) + if (emblem != -1) creature->setEmblem(emblem); - if(creatureType != -1) + if (creatureType != -1) creature->setType(creatureType); - if(icon != -1) + if (icon != -1) creature->setIcon(icon); - if(creature == m_localPlayer && !m_localPlayer->isKnown()) + if (creature == m_localPlayer && !m_localPlayer->isKnown()) m_localPlayer->setKnown(true); } - } else if(type == Proto::Creature) { + } else if (type == Proto::Creature) { uint id = msg->getU32(); creature = g_map.getCreatureById(id); - if(!creature) + if (!creature) g_logger.traceError("invalid creature"); Otc::Direction direction = (Otc::Direction)msg->getU8(); @@ -3226,10 +3403,10 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) } } - if(g_game.getClientVersion() >= 953) { + if (g_game.getClientVersion() >= 953) { bool unpass = msg->getU8(); - if(creature) + if (creature) creature->setPassable(!unpass); } @@ -3242,18 +3419,18 @@ CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type) ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id, bool hasDescription) { - if(id == 0) + if (id == 0) id = msg->getU16(); ItemPtr item = Item::create(id); - if(item->getId() == 0) + if (item->getId() == 0) stdext::throw_exception(stdext::format("unable to create item with invalid id %d", id)); - if(g_game.getFeature(Otc::GameThingMarks) && !g_game.getFeature(Otc::GameTibia12Protocol)) { + if (g_game.getFeature(Otc::GameThingMarks) && !g_game.getFeature(Otc::GameTibia12Protocol)) { msg->getU8(); // mark } - if(item->isStackable() || item->isFluidContainer() || item->isSplash() || item->isChargeable()) + if (item->isStackable() || item->isFluidContainer() || item->isSplash() || item->isChargeable()) item->setCountOrSubType(msg->getU8()); else if (item->rawGetThingType()->isContainer() && g_game.getFeature(Otc::GameTibia12Protocol)) { // not sure about this part @@ -3262,8 +3439,8 @@ ItemPtr ProtocolGame::getItem(const InputMessagePtr& msg, int id, bool hasDescri msg->getU32(); // quick loot flags } - if(g_game.getFeature(Otc::GameItemAnimationPhase)) { - if(item->getAnimationPhases() > 1) { + if (g_game.getFeature(Otc::GameItemAnimationPhase)) { + if (item->getAnimationPhases() > 1) { // 0x00 => automatic phase // 0xFE => random phase // 0xFF => async phase