[HELP] How to change nickname color in OTClient

Discussion in 'OTClient' started by Liryk, Jul 11, 2018.

  1. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Hiho, I need to change my nickname default color (green) to gold or red, i want the set groups or people to have a gold/red nickname color.
     
  2. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    Nickname and health bar uses the same color from m_informationColor, wich is updated from creature.cpp : void Creature::setHealthPercent(uint8 healthPercent). If you want to change ONLY the name color, you need to make some changes in void Creature::drawInformation to make the name to get a different color instead of m_informationColor.
     
  3. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Can u help me? :/ Im beginner in coding in OTClient
     
  4. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    Its only the nickname or health color too? And who will have a different color, all players?
     
  5. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    I want to only admins (group id 6) get GOLD nickname nad health color too i think its be good, other players will still have an old color
     
  6. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    The OTClient doesnt know the group of the player on the screen, protocol changes on server-side too is needed.
     
  7. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Hmm, what i need to do?

    I played a little bit and I came to it that I changed the color of mobs that have 100% hp, but it's an easy thing
     
    Last edited by a moderator: Jul 14, 2018
  8. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    Ok i'll help you, post your
    Code (C++):
    1.  CreaturePtr ProtocolGame::getCreature
    from protocolgameparse.cpp (OTC) and
    Code (C++):
    1. void ProtocolGame::AddCreature
    from protocolgame.cpp (Server)
     
  9. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    It's from OTC:
    Code (C++):
    1. CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
    2. {
    3.     if(type == 0)
    4.         type = msg->getU16();
    5.  
    6.     CreaturePtr creature;
    7.     bool known = (type != Proto::UnknownCreature);
    8.     if(type == Proto::OutdatedCreature || type == Proto::UnknownCreature) {
    9.         if(known) {
    10.             uint id = msg->getU32();
    11.             creature = g_map.getCreatureById(id);
    12.             if(!creature)
    13.                 g_logger.traceError("server said that a creature is known, but it's not");
    14.         } else {
    15.             uint removeId = msg->getU32();
    16.             g_map.removeCreatureById(removeId);
    17.  
    18.             uint id = msg->getU32();
    19.  
    20.             int creatureType;
    21.             if(g_game.getClientVersion() >= 910)
    22.                 creatureType = msg->getU8();
    23.             else {
    24.                 if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
    25.                     creatureType = Proto::CreatureTypePlayer;
    26.                 else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
    27.                     creatureType = Proto::CreatureTypeMonster;
    28.                 else
    29.                     creatureType = Proto::CreatureTypeNpc;
    30.             }
    31.  
    32.             std::string name = g_game.formatCreatureName(msg->getString());
    33.  
    34.             if(id == m_localPlayer->getId())
    35.                 creature = m_localPlayer;
    36.             else if(creatureType == Proto::CreatureTypePlayer) {
    37.                 // fixes a bug server side bug where GameInit is not sent and local player id is unknown
    38.                 if(m_localPlayer->getId() == 0 && name == m_localPlayer->getName())
    39.                     creature = m_localPlayer;
    40.                 else
    41.                     creature = PlayerPtr(new Player);
    42.             }
    43.             else if(creatureType == Proto::CreatureTypeMonster)
    44.                 creature = MonsterPtr(new Monster);
    45.             else if(creatureType == Proto::CreatureTypeNpc)
    46.                 creature = NpcPtr(new Npc);
    47.             else
    48.                 g_logger.traceError("creature type is invalid");
    49.  
    50.             if(creature) {
    51.                 creature->setId(id);
    52.                 creature->setName(name);
    53.  
    54.                 g_map.addCreature(creature);
    55.             }
    56.         }
    57.  
    58.         int healthPercent = msg->getU8();
    59.         Otc::Direction direction = (Otc::Direction)msg->getU8();
    60.         Outfit outfit = getOutfit(msg);
    61.  
    62.         Light light;
    63.         light.intensity = msg->getU8();
    64.         light.color = msg->getU8();
    65.  
    66.         int speed = msg->getU16();
    67.         int skull = msg->getU8();
    68.         int shield = msg->getU8();
    69.  
    70.         // emblem is sent only when the creature is not known
    71.         int8 emblem = -1;
    72.         int8 creatureType = -1;
    73.         int8 icon = -1;
    74.         bool unpass = true;
    75.         uint8 mark;
    76.  
    77.         if(g_game.getFeature(Otc::GameCreatureEmblems) && !known)
    78.             emblem = msg->getU8();
    79.  
    80.         if(g_game.getFeature(Otc::GameThingMarks)) {
    81.             creatureType = msg->getU8();
    82.         }
    83.  
    84.         if(g_game.getFeature(Otc::GameCreatureIcons)) {
    85.             icon = msg->getU8();
    86.         }
    87.  
    88.         if(g_game.getFeature(Otc::GameThingMarks)) {
    89.             mark = msg->getU8(); // mark
    90.             msg->getU16(); // helpers
    91.  
    92.             if(creature) {
    93.                 if(mark == 0xff)
    94.                     creature->hideStaticSquare();
    95.                 else
    96.                     creature->showStaticSquare(Color::from8bit(mark));
    97.             }
    98.         }
    99.  
    100.         if(g_game.getClientVersion() >= 854)
    101.             unpass = msg->getU8();
    102.  
    103.         if(creature) {
    104.             creature->setHealthPercent(healthPercent);
    105.             creature->setDirection(direction);
    106.             creature->setOutfit(outfit);
    107.             creature->setSpeed(speed);
    108.             creature->setSkull(skull);
    109.             creature->setShield(shield);
    110.             creature->setPassable(!unpass);
    111.             creature->setLight(light);
    112.  
    113.             if(emblem != -1)
    114.                 creature->setEmblem(emblem);
    115.  
    116.             if(creatureType != -1)
    117.                 creature->setType(creatureType);
    118.  
    119.             if(icon != -1)
    120.                 creature->setIcon(icon);
    121.  
    122.             if(creature == m_localPlayer && !m_localPlayer->isKnown())
    123.                 m_localPlayer->setKnown(true);
    124.         }
    125.     } else if(type == Proto::Creature) {
    126.         uint id = msg->getU32();
    127.         creature = g_map.getCreatureById(id);
    128.  
    129.         if(!creature)
    130.             g_logger.traceError("invalid creature");
    131.  
    132.         Otc::Direction direction = (Otc::Direction)msg->getU8();
    133.         if(creature)
    134.             creature->turn(direction);
    135.  
    136.         if(g_game.getClientVersion() >= 953) {
    137.             bool unpass = msg->getU8();
    138.  
    139.             if(creature)
    140.                 creature->setPassable(!unpass);
    141.         }
    142.  
    143.     } else {
    144.         stdext::throw_exception("invalid creature opcode");
    145.     }
    146.  
    147.     return creature;
    148. }
    149.  
    And lel i doesn't have a void ProtocolGame::AddCreature
    My procolgame.cpp
    Code (C++):
    1. /*
    2. * Copyright (c) 2010-2017 OTClient <https://github.com/edubart/otclient>
    3. *
    4. * Permission is hereby granted, free of charge, to any person obtaining a copy
    5. * of this software and associated documentation files (the "Software"), to deal
    6. * in the Software without restriction, including without limitation the rights
    7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    8. * copies of the Software, and to permit persons to whom the Software is
    9. * furnished to do so, subject to the following conditions:
    10. *
    11. * The above copyright notice and this permission notice shall be included in
    12. * all copies or substantial portions of the Software.
    13. *
    14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    20. * THE SOFTWARE.
    21. */
    22.  
    23. #include "protocolgame.h"
    24. #include "game.h"
    25. #include "player.h"
    26. #include "item.h"
    27. #include "localplayer.h"
    28.  
    29. void ProtocolGame::login(const std::string& accountName, const std::string& accountPassword, const std::string& host, uint16 port, const std::string& characterName, const std::string& authenticatorToken, const std::string& sessionKey)
    30. {
    31.     m_accountName = accountName;
    32.     m_accountPassword = accountPassword;
    33.     m_authenticatorToken = authenticatorToken;
    34.     m_sessionKey = sessionKey;
    35.     m_characterName = characterName;
    36.  
    37.     connect(host, port);
    38. }
    39.  
    40. void ProtocolGame::onConnect()
    41. {
    42.     m_firstRecv = true;
    43.     Protocol::onConnect();
    44.  
    45.     m_localPlayer = g_game.getLocalPlayer();
    46.  
    47.     if(g_game.getFeature(Otc::GameProtocolChecksum))
    48.         enableChecksum();
    49.  
    50.     if(!g_game.getFeature(Otc::GameChallengeOnLogin))
    51.         sendLoginPacket(0, 0);
    52.  
    53.     recv();
    54. }
    55.  
    56. void ProtocolGame::onRecv(const InputMessagePtr& inputMessage)
    57. {
    58.     if(m_firstRecv) {
    59.         m_firstRecv = false;
    60.  
    61.         if(g_game.getFeature(Otc::GameMessageSizeCheck)) {
    62.             int size = inputMessage->getU16();
    63.             if(size != inputMessage->getUnreadSize()) {
    64.                 g_logger.traceError("invalid message size");
    65.                 return;
    66.             }
    67.         }
    68.     }
    69.  
    70.     parseMessage(inputMessage);
    71.     recv();
    72. }
    73.  
    74. void ProtocolGame::onError(const boost::system::error_code& error)
    75. {
    76.     g_game.processConnectionError(error);
    77.     disconnect();
    78. }
    79.  
     
  10. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    You misunderstood me, its void ProtocolGame::AddCreature from protocolgame.cpp (Server)
     
  11. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Im totally idiot i cant find it :O my server is forgotten server, sorry for me im tottaly confused

    On internet i was find it
    Code (C++):
    1. ////////////// Add common messages
    2. void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bool known, uint32_t remove)
    3. {
    4.     CreatureType_t creatureType = creature->getType();
    5.  
    6.     const Player* otherPlayer = creature->getPlayer();
    7.  
    8.     if (known) {
    9.         msg.add<uint16_t>(0x62);
    10.         msg.add<uint32_t>(creature->getID());
    11.     } else {
    12.         msg.add<uint16_t>(0x61);
    13.         msg.add<uint32_t>(remove);
    14.         msg.add<uint32_t>(creature->getID());
    15.         msg.addByte(creatureType);
    16.         msg.addString(creature->getName());
    17.     }
    18.  
    19.     if (creature->isHealthHidden()) {
    20.         msg.addByte(0x00);
    21.     } else {
    22.         msg.addByte(std::ceil((static_cast<double>(creature->getHealth()) / std::max<int32_t>(creature->getMaxHealth(), 1)) * 100));
    23.     }
    24.  
    25.     msg.addByte(creature->getDirection());
    26.  
    27.     if (!creature->isInGhostMode() && !creature->isInvisible()) {
    28.         AddOutfit(msg, creature->getCurrentOutfit());
    29.     } else {
    30.         static Outfit_t outfit;
    31.         AddOutfit(msg, outfit);
    32.     }
    33.  
    34.     LightInfo lightInfo = creature->getCreatureLight();
    35.     msg.addByte(player->isAccessPlayer() ? 0xFF : lightInfo.level);
    36.     msg.addByte(lightInfo.color);
    37.  
    38.     msg.add<uint16_t>(creature->getStepSpeed() / 2);
    39.  
    40.     msg.addByte(player->getSkullClient(creature));
    41.     msg.addByte(player->getPartyShield(otherPlayer));
    42.  
    43.     if (!known) {
    44.         msg.addByte(player->getGuildEmblem(otherPlayer));
    45.     }
    46.  
    47.     if (creatureType == CREATURETYPE_MONSTER) {
    48.         const Creature* master = creature->getMaster();
    49.         if (master) {
    50.             const Player* masterPlayer = master->getPlayer();
    51.             if (masterPlayer) {
    52.                 if (masterPlayer == player) {
    53.                     creatureType = CREATURETYPE_SUMMON_OWN;
    54.                 } else {
    55.                     creatureType = CREATURETYPE_SUMMON_OTHERS;
    56.                 }
    57.             }
    58.         }
    59.     }
    60.  
    61.     msg.addByte(creatureType); // Type (for summons)
    62.     msg.addByte(creature->getSpeechBubble());
    63.     msg.addByte(0xFF); // MARK_UNMARKED
    64.  
    65.     if (otherPlayer) {
    66.         msg.add<uint16_t>(otherPlayer->getHelpers());
    67.     } else {
    68.         msg.add<uint16_t>(0x00);
    69.     }
    70.  
    71.     msg.addByte(player->canWalkthroughEx(creature) ? 0x00 : 0x01);
    72. }
    73.  
    74. void ProtocolGame::AddPlayerStats(NetworkMessage& msg)
    75. {
    76.     msg.addByte(0xA0);
    77.  
    78.     msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
    79.     msg.add<uint16_t>(std::min<int32_t>(player->getMaxHealth(), std::numeric_limits<uint16_t>::max()));
    80.  
    81.     msg.add<uint32_t>(player->getFreeCapacity());
    82.     msg.add<uint32_t>(player->getCapacity());
    83.  
    84.     msg.add<uint64_t>(player->getExperience());
    85.  
    86.     msg.add<uint16_t>(player->getLevel());
    87.     msg.addByte(player->getLevelPercent());
    88.  
    89.     msg.add<uint16_t>(100); // base xp gain rate
    90.     msg.add<uint16_t>(0); // xp voucher
    91.     msg.add<uint16_t>(0); // low level bonus
    92.     msg.add<uint16_t>(0); // xp boost
    93.     msg.add<uint16_t>(100); // stamina multiplier (100 = x1.0)
    94.  
    95.     msg.add<uint16_t>(std::min<int32_t>(player->getMana(), std::numeric_limits<uint16_t>::max()));
    96.     msg.add<uint16_t>(std::min<int32_t>(player->getMaxMana(), std::numeric_limits<uint16_t>::max()));
    97.  
    98.     msg.addByte(std::min<uint32_t>(player->getMagicLevel(), std::numeric_limits<uint8_t>::max()));
    99.     msg.addByte(std::min<uint32_t>(player->getBaseMagicLevel(), std::numeric_limits<uint8_t>::max()));
    100.     msg.addByte(player->getMagicLevelPercent());
    101.  
    102.     msg.addByte(player->getSoul());
    103.  
    104.     msg.add<uint16_t>(player->getStaminaMinutes());
    105.  
    106.     msg.add<uint16_t>(player->getBaseSpeed() / 2);
    107.  
    108.     Condition* condition = player->getCondition(CONDITION_REGENERATION);
    109.     msg.add<uint16_t>(condition ? condition->getTicks() / 1000 : 0x00);
    110.  
    111.     msg.add<uint16_t>(player->getOfflineTrainingTime() / 60 / 1000);
    112.  
    113.     msg.add<uint16_t>(0); // xp boost time (seconds)
    114.     msg.addByte(0); // enables exp boost in the store
    115. }
    116.  
    otland/forgottenserver
     
    Last edited by a moderator: Jul 14, 2018
  12. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    You dont have the sources from your server? To make this changes you'll need to be able to compile it..
     
  13. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Its normal fangotten server i can download src and change it
     
  14. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    Ok paste here your void Creature::draw from creature.cpp (OTC)
     
  15. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Code (C++):
    1. void Creature::draw(const Point& dest, float scaleFactor, bool animate, LightView *lightView)
    2. {
    3.     if(!canBeSeen())
    4.         return;
    5.  
    6.     Point animationOffset = animate ? m_walkOffset : Point(0,0);
    7.  
    8.     if(m_showTimedSquare && animate) {
    9.         g_painter->setColor(m_timedSquareColor);
    10.         g_painter->drawBoundingRect(Rect(dest + (animationOffset - getDisplacement() + 2)*scaleFactor, Size(28, 28)*scaleFactor), std::max<int>((int)(2*scaleFactor), 1));
    11.         g_painter->setColor(Color::white);
    12.     }
    13.  
    14.     if(m_showStaticSquare && animate) {
    15.         g_painter->setColor(m_staticSquareColor);
    16.         g_painter->drawBoundingRect(Rect(dest + (animationOffset - getDisplacement())*scaleFactor, Size(Otc::TILE_PIXELS, Otc::TILE_PIXELS)*scaleFactor), std::max<int>((int)(2*scaleFactor), 1));
    17.         g_painter->setColor(Color::white);
    18.     }
    19.  
    20.     internalDrawOutfit(dest + animationOffset * scaleFactor, scaleFactor, animate, animate, m_direction);
    21.     m_footStepDrawn = true;
    22.  
    23.     if(lightView) {
    24.         Light light = rawGetThingType()->getLight();
    25.         if(m_light.intensity != light.intensity || m_light.color != light.color)
    26.             light = m_light;
    27.  
    28.         // local player always have a minimum light in complete darkness
    29.         if(isLocalPlayer() && (g_map.getLight().intensity < 64 || m_position.z > Otc::SEA_FLOOR)) {
    30.             light.intensity = std::max<uint8>(light.intensity, 3);
    31.             if(light.color == 0 || light.color > 215)
    32.                 light.color = 215;
    33.         }
    34.  
    35.         if(light.intensity > 0)
    36.             lightView->addLightSource(dest + (animationOffset + Point(16,16)) * scaleFactor, scaleFactor, light);
    37.     }
    38. }
    39.  
     
  16. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    Oh sorry its actually your void Creature::drawInformation that i need
     
  17. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    Code (C++):
    1.  
    2. void Creature::drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags)
    3. {
    4.     if(m_healthPercent < 1) // creature is dead
    5.         return;
    6.  
    7.     Color fillColor = Color(96, 96, 96);
    8.  
    9.     if(!useGray)
    10.         fillColor = m_informationColor;
    11.  
    12.     // calculate main rects
    13.     Rect backgroundRect = Rect(point.x-(13.5), point.y, 27, 4);
    14.     backgroundRect.bind(parentRect);
    15.     Size nameSize = m_nameCache.getTextSize();
    16.     Rect textRect = Rect(point.x - nameSize.width() / 2.0, point.y-12, nameSize);
    17.     textRect.bind(parentRect);
    18.  
    19.     // distance them
    20.     uint32 offset = 12;
    21.     if(isLocalPlayer()) {
    22.         offset *= 2;
    23.     }
    24.  
    25.     if(textRect.top() == parentRect.top())
    26.         backgroundRect.moveTop(textRect.top() + offset);
    27.     if(backgroundRect.bottom() == parentRect.bottom())
    28.         textRect.moveTop(backgroundRect.top() - offset);
    29.  
    30.     // health rect is based on background rect, so no worries
    31.     Rect healthRect = backgroundRect.expanded(-1);
    32.     healthRect.setWidth((m_healthPercent / 100.0) * 25);
    33.  
    34.        
    35.  
    36.     // draw
    37.     if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray)
    38.         fillColor = Color(0x66, 0xcc, 0xff);
    39.  
    40.     if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) {
    41.         g_painter->setColor(Color::black);
    42.         g_painter->drawFilledRect(backgroundRect);
    43.  
    44.         g_painter->setColor(fillColor);
    45.         g_painter->drawFilledRect(healthRect);
    46.  
    47.         if(drawFlags & Otc::DrawManaBar && isLocalPlayer()) {
    48.             LocalPlayerPtr player = g_game.getLocalPlayer();
    49.             if(player) {
    50.                 backgroundRect.moveTop(backgroundRect.bottom());
    51.  
    52.                 g_painter->setColor(Color::black);
    53.                 g_painter->drawFilledRect(backgroundRect);
    54.  
    55.                 Rect manaRect = backgroundRect.expanded(-1);
    56.                 double maxMana = player->getMaxMana();
    57.                 if(maxMana == 0) {
    58.                     manaRect.setWidth(25);
    59.                 } else {
    60.                     manaRect.setWidth(player->getMana() / (maxMana * 1.0) * 25);
    61.                 }
    62.  
    63.                 g_painter->setColor(Color::blue);
    64.                 g_painter->drawFilledRect(manaRect);
    65.             }
    66.         }
    67.     }
    68.  
    69.     if(drawFlags & Otc::DrawNames) {
    70.         if(g_painter->getColor() != fillColor)
    71.             g_painter->setColor(fillColor);
    72.         m_nameCache.draw(textRect);
    73.     }
    74.  
    75.  
    76.     if(m_skull != Otc::SkullNone && m_skullTexture) {
    77.         g_painter->setColor(Color::white);
    78.         Rect skullRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_skullTexture->getSize());
    79.         g_painter->drawTexturedRect(skullRect, m_skullTexture);
    80.     }
    81.     if(m_shield != Otc::ShieldNone && m_shieldTexture && m_showShieldTexture) {
    82.         g_painter->setColor(Color::white);
    83.         Rect shieldRect = Rect(backgroundRect.x() + 13.5, backgroundRect.y() + 5, m_shieldTexture->getSize());
    84.         g_painter->drawTexturedRect(shieldRect, m_shieldTexture);
    85.     }
    86.     if(m_emblem != Otc::EmblemNone && m_emblemTexture) {
    87.         g_painter->setColor(Color::white);
    88.         Rect emblemRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 16, m_emblemTexture->getSize());
    89.         g_painter->drawTexturedRect(emblemRect, m_emblemTexture);
    90.     }
    91.     if(m_type != Proto::CreatureTypeUnknown && m_typeTexture) {
    92.         g_painter->setColor(Color::white);
    93.         Rect typeRect = Rect(backgroundRect.x() + 13.5 + 12 + 12, backgroundRect.y() + 16, m_typeTexture->getSize());
    94.         g_painter->drawTexturedRect(typeRect, m_typeTexture);
    95.     }
    96.     if(m_icon != Otc::NpcIconNone && m_iconTexture) {
    97.         g_painter->setColor(Color::white);
    98.         Rect iconRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_iconTexture->getSize());
    99.         g_painter->drawTexturedRect(iconRect, m_iconTexture);
    100.     }
    101. }
    102.  
     
  18. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2
    Ok try this
    OTC sources:
    - protocolgameparse.cpp
    Code (C++):
    1.  
    2. CreaturePtr ProtocolGame::getCreature(const InputMessagePtr& msg, int type)
    3. {
    4.     if(type == 0)
    5.         type = msg->getU16();
    6.     CreaturePtr creature;
    7.     bool known = (type != Proto::UnknownCreature);
    8.     if(type == Proto::OutdatedCreature || type == Proto::UnknownCreature) {
    9.         if(known) {
    10.             uint id = msg->getU32();
    11.             creature = g_map.getCreatureById(id);
    12.             if(!creature)
    13.                 g_logger.traceError("server said that a creature is known, but it's not");
    14.         } else {
    15.             uint removeId = msg->getU32();
    16.             g_map.removeCreatureById(removeId);
    17.             uint id = msg->getU32();
    18.             int creatureType;
    19.             if(g_game.getClientVersion() >= 910)
    20.                 creatureType = msg->getU8();
    21.             else {
    22.                 if(id >= Proto::PlayerStartId && id < Proto::PlayerEndId)
    23.                     creatureType = Proto::CreatureTypePlayer;
    24.                 else if(id >= Proto::MonsterStartId && id < Proto::MonsterEndId)
    25.                     creatureType = Proto::CreatureTypeMonster;
    26.                 else
    27.                     creatureType = Proto::CreatureTypeNpc;
    28.             }
    29.             std::string name = g_game.formatCreatureName(msg->getString());
    30.             if(id == m_localPlayer->getId())
    31.                 creature = m_localPlayer;
    32.             else if(creatureType == Proto::CreatureTypePlayer) {
    33.                 // fixes a bug server side bug where GameInit is not sent and local player id is unknown
    34.                 if(m_localPlayer->getId() == 0 && name == m_localPlayer->getName())
    35.                     creature = m_localPlayer;
    36.                 else
    37.                     creature = PlayerPtr(new Player);
    38.             }
    39.             else if(creatureType == Proto::CreatureTypeMonster)
    40.                 creature = MonsterPtr(new Monster);
    41.             else if(creatureType == Proto::CreatureTypeNpc)
    42.                 creature = NpcPtr(new Npc);
    43.             else
    44.                 g_logger.traceError("creature type is invalid");
    45.             if(creature) {
    46.                 creature->setId(id);
    47.                 creature->setName(name);
    48.                 g_map.addCreature(creature);
    49.             }
    50.         }
    51.         int healthPercent = msg->getU8();
    52.         Otc::Direction direction = (Otc::Direction)msg->getU8();
    53.         Outfit outfit = getOutfit(msg);
    54.         Light light;
    55.         light.intensity = msg->getU8();
    56.         light.color = msg->getU8();
    57.         int speed = msg->getU16();
    58.         int skull = msg->getU8();
    59.         int shield = msg->getU8();
    60.         bool haveGroup = msg->getU8(); // new
    61.         // emblem is sent only when the creature is not known
    62.         int8 emblem = -1;
    63.         int8 creatureType = -1;
    64.         int8 icon = -1;
    65.         bool unpass = true;
    66.         uint8 mark;
    67.         if(g_game.getFeature(Otc::GameCreatureEmblems) && !known)
    68.             emblem = msg->getU8();
    69.         if(g_game.getFeature(Otc::GameThingMarks)) {
    70.             creatureType = msg->getU8();
    71.         }
    72.         if(g_game.getFeature(Otc::GameCreatureIcons)) {
    73.             icon = msg->getU8();
    74.         }
    75.         if(g_game.getFeature(Otc::GameThingMarks)) {
    76.             mark = msg->getU8(); // mark
    77.             msg->getU16(); // helpers
    78.             if(creature) {
    79.                 if(mark == 0xff)
    80.                     creature->hideStaticSquare();
    81.                 else
    82.                     creature->showStaticSquare(Color::from8bit(mark));
    83.             }
    84.         }
    85.         if(g_game.getClientVersion() >= 854)
    86.             unpass = msg->getU8();
    87.         if(creature) {
    88.             creature->setHealthPercent(healthPercent);
    89.             creature->setDirection(direction);
    90.             creature->setOutfit(outfit);
    91.             creature->setSpeed(speed);
    92.             creature->setSkull(skull);
    93.             creature->setShield(shield);
    94.             creature->setHaveGroup(haveGroup); // new
    95.             creature->setPassable(!unpass);
    96.             creature->setLight(light);
    97.             if(emblem != -1)
    98.                 creature->setEmblem(emblem);
    99.             if(creatureType != -1)
    100.                 creature->setType(creatureType);
    101.             if(icon != -1)
    102.                 creature->setIcon(icon);
    103.             if(creature == m_localPlayer && !m_localPlayer->isKnown())
    104.                 m_localPlayer->setKnown(true);
    105.         }
    106.     } else if(type == Proto::Creature) {
    107.         uint id = msg->getU32();
    108.         creature = g_map.getCreatureById(id);
    109.         if(!creature)
    110.             g_logger.traceError("invalid creature");
    111.         Otc::Direction direction = (Otc::Direction)msg->getU8();
    112.         if(creature)
    113.             creature->turn(direction);
    114.         if(g_game.getClientVersion() >= 953) {
    115.             bool unpass = msg->getU8();
    116.             if(creature)
    117.                 creature->setPassable(!unpass);
    118.         }
    119.     } else {
    120.         stdext::throw_exception("invalid creature opcode");
    121.     }
    122.     return creature;
    123. }
    124.  
    - creature.cpp
    Code (C++):
    1.  
    2. void Creature::drawInformation(const Point& point, bool useGray, const Rect& parentRect, int drawFlags)
    3. {
    4.     if(m_healthPercent < 1) // creature is dead
    5.         return;
    6.     Color fillColor = Color(96, 96, 96);
    7.     if(!useGray)
    8.         fillColor = m_informationColor;
    9.     // calculate main rects
    10.     Rect backgroundRect = Rect(point.x-(13.5), point.y, 27, 4);
    11.     backgroundRect.bind(parentRect);
    12.     Size nameSize = m_nameCache.getTextSize();
    13.     Rect textRect = Rect(point.x - nameSize.width() / 2.0, point.y-12, nameSize);
    14.     textRect.bind(parentRect);
    15.     // distance them
    16.     uint32 offset = 12;
    17.     if(isLocalPlayer()) {
    18.         offset *= 2;
    19.     }
    20.     if(textRect.top() == parentRect.top())
    21.         backgroundRect.moveTop(textRect.top() + offset);
    22.     if(backgroundRect.bottom() == parentRect.bottom())
    23.         textRect.moveTop(backgroundRect.top() - offset);
    24.     // health rect is based on background rect, so no worries
    25.     Rect healthRect = backgroundRect.expanded(-1);
    26.     healthRect.setWidth((m_healthPercent / 100.0) * 25);
    27.  
    28.     // draw
    29.     if(g_game.getFeature(Otc::GameBlueNpcNameColor) && isNpc() && m_healthPercent == 100 && !useGray)
    30.         fillColor = Color(0x66, 0xcc, 0xff);
    31.     if(drawFlags & Otc::DrawBars && (!isNpc() || !g_game.getFeature(Otc::GameHideNpcNames))) {
    32.         g_painter->setColor(Color::black);
    33.         g_painter->drawFilledRect(backgroundRect);
    34.         g_painter->setColor(fillColor);
    35.         g_painter->drawFilledRect(healthRect);
    36.         if(drawFlags & Otc::DrawManaBar && isLocalPlayer()) {
    37.             LocalPlayerPtr player = g_game.getLocalPlayer();
    38.             if(player) {
    39.                 backgroundRect.moveTop(backgroundRect.bottom());
    40.                 g_painter->setColor(Color::black);
    41.                 g_painter->drawFilledRect(backgroundRect);
    42.                 Rect manaRect = backgroundRect.expanded(-1);
    43.                 double maxMana = player->getMaxMana();
    44.                 if(maxMana == 0) {
    45.                     manaRect.setWidth(25);
    46.                 } else {
    47.                     manaRect.setWidth(player->getMana() / (maxMana * 1.0) * 25);
    48.                 }
    49.                 g_painter->setColor(Color::blue);
    50.                 g_painter->drawFilledRect(manaRect);
    51.             }
    52.         }
    53.     }
    54.     if(drawFlags & Otc::DrawNames) {
    55.        if (m_haveGroup)
    56.            fillColor = Color(0xff, 0x6f, 0x52); // the new color for group players
    57.         if(g_painter->getColor() != fillColor)
    58.             g_painter->setColor(fillColor);
    59.         m_nameCache.draw(textRect);
    60.     }
    61.     if(m_skull != Otc::SkullNone && m_skullTexture) {
    62.         g_painter->setColor(Color::white);
    63.         Rect skullRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_skullTexture->getSize());
    64.         g_painter->drawTexturedRect(skullRect, m_skullTexture);
    65.     }
    66.     if(m_shield != Otc::ShieldNone && m_shieldTexture && m_showShieldTexture) {
    67.         g_painter->setColor(Color::white);
    68.         Rect shieldRect = Rect(backgroundRect.x() + 13.5, backgroundRect.y() + 5, m_shieldTexture->getSize());
    69.         g_painter->drawTexturedRect(shieldRect, m_shieldTexture);
    70.     }
    71.     if(m_emblem != Otc::EmblemNone && m_emblemTexture) {
    72.         g_painter->setColor(Color::white);
    73.         Rect emblemRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 16, m_emblemTexture->getSize());
    74.         g_painter->drawTexturedRect(emblemRect, m_emblemTexture);
    75.     }
    76.     if(m_type != Proto::CreatureTypeUnknown && m_typeTexture) {
    77.         g_painter->setColor(Color::white);
    78.         Rect typeRect = Rect(backgroundRect.x() + 13.5 + 12 + 12, backgroundRect.y() + 16, m_typeTexture->getSize());
    79.         g_painter->drawTexturedRect(typeRect, m_typeTexture);
    80.     }
    81.     if(m_icon != Otc::NpcIconNone && m_iconTexture) {
    82.         g_painter->setColor(Color::white);
    83.         Rect iconRect = Rect(backgroundRect.x() + 13.5 + 12, backgroundRect.y() + 5, m_iconTexture->getSize());
    84.         g_painter->drawTexturedRect(iconRect, m_iconTexture);
    85.     }
    86. }
    87.  
    in Creature::Creature() : Thing() below m_shield = Otc::ShieldNone; paste
    Code (C++):
    1. m_haveGroup = false; // new

    - creature.h
    below void setShield(uint8 shield); paste
    Code (C++):
    1.  
    2. void setHaveGroup(bool haveGroup) { m_haveGroup = haveGroup; } // new
    3.  
    below uint8 m_shield; paste
    Code (C++):
    1. bool m_haveGroup; // new
    Server side (TFS sources)
    - protocolgame.cpp

    Code (C++):
    1. void ProtocolGame::AddCreature(NetworkMessage& msg, const Creature* creature, bool known, uint32_t remove)
    2. {
    3.     CreatureType_t creatureType = creature->getType();
    4.     const Player* otherPlayer = creature->getPlayer();
    5.     if (known) {
    6.         msg.add<uint16_t>(0x62);
    7.         msg.add<uint32_t>(creature->getID());
    8.     } else {
    9.         msg.add<uint16_t>(0x61);
    10.         msg.add<uint32_t>(remove);
    11.         msg.add<uint32_t>(creature->getID());
    12.         msg.addByte(creatureType);
    13.         msg.addString(creature->getName());
    14.     }
    15.     if (creature->isHealthHidden()) {
    16.         msg.addByte(0x00);
    17.     } else {
    18.         msg.addByte(std::ceil((static_cast<double>(creature->getHealth()) / std::max<int32_t>(creature->getMaxHealth(), 1)) * 100));
    19.     }
    20.     msg.addByte(creature->getDirection());
    21.     if (!creature->isInGhostMode() && !creature->isInvisible()) {
    22.         AddOutfit(msg, creature->getCurrentOutfit());
    23.     } else {
    24.         static Outfit_t outfit;
    25.         AddOutfit(msg, outfit);
    26.     }
    27.     LightInfo lightInfo = creature->getCreatureLight();
    28.     msg.addByte(player->isAccessPlayer() ? 0xFF : lightInfo.level);
    29.     msg.addByte(lightInfo.color);
    30.     msg.add<uint16_t>(creature->getStepSpeed() / 2);
    31.     msg.addByte(player->getSkullClient(creature));
    32.     msg.addByte(player->getPartyShield(otherPlayer));
    33.     msg.addByte(otherPlayer && otherPlayer->isAccessPlayer() ? 0x01 : 0x00); // new
    34.     if (!known) {
    35.         msg.addByte(player->getGuildEmblem(otherPlayer));
    36.     }
    37.     if (creatureType == CREATURETYPE_MONSTER) {
    38.         const Creature* master = creature->getMaster();
    39.         if (master) {
    40.             const Player* masterPlayer = master->getPlayer();
    41.             if (masterPlayer) {
    42.                 if (masterPlayer == player) {
    43.                     creatureType = CREATURETYPE_SUMMON_OWN;
    44.                 } else {
    45.                     creatureType = CREATURETYPE_SUMMON_OTHERS;
    46.                 }
    47.             }
    48.         }
    49.     }
    50.     msg.addByte(creatureType); // Type (for summons)
    51.     msg.addByte(creature->getSpeechBubble());
    52.     msg.addByte(0xFF); // MARK_UNMARKED
    53.     if (otherPlayer) {
    54.         msg.add<uint16_t>(otherPlayer->getHelpers());
    55.     } else {
    56.         msg.add<uint16_t>(0x00);
    57.     }
    58.     msg.addByte(player->canWalkthroughEx(creature) ? 0x00 : 0x01);
    59. }
    60.  
     
    Last edited: Jul 15, 2018
    DJSzaman and Liryk like this.
  19. Liryk

    Liryk Member

    Joined:
    Jun 20, 2018
    Messages:
    42
    Likes Received:
    1
    Best Answers:
    0
    I try this tommorow and say results

    Everywhere, I tried to compile a clean server, forgotten, and there errors themselves, i install all
    But still there are many errors
     
    Last edited by a moderator: Jul 14, 2018
    Thanatos_ likes this.
  20. Thanatos_

    Thanatos_ Programmer Premium User

    Joined:
    Jul 10, 2018
    Messages:
    39
    Likes Received:
    17
    Best Answers:
    2

Share This Page

Loading...