Beispiel #1
0
        protected AppearanceActions DetermineAction(Vector3 mousePosition, MouseButton mouseButton, EventModifiers eventModifiers, ObjectInstance @object, bool applyAction = false, bool updateCursor = false)
        {
            if (!@object)
            {
                return(AppearanceActions.None);
            }

            if (updateCursor)
            {
                updateCursor = OpenTibiaUnity.GameManager.ClientVersion >= 1100;
            }

            var inputHandler = OpenTibiaUnity.InputHandler;

            if (inputHandler.IsMouseButtonDragged(MouseButton.Left) || inputHandler.IsMouseButtonDragged(MouseButton.Right))
            {
                return(AppearanceActions.None);
            }

            var action        = AppearanceActions.None;
            var optionStorage = OpenTibiaUnity.OptionStorage;

            if (optionStorage.MousePreset == MousePresets.LeftSmartClick)
            {
                if (eventModifiers == EventModifiers.None || eventModifiers == EventModifiers.Control)
                {
                    if (mouseButton == MouseButton.Left || mouseButton == MouseButton.None)
                    {
                        var defaultAction = @object.Type.DefaultAction;
                        if (defaultAction == Protobuf.Shared.PlayerAction.Open)
                        {
                            action = AppearanceActions.Open;
                        }
                        else if (defaultAction == Protobuf.Shared.PlayerAction.Look)
                        {
                            action = AppearanceActions.Look;
                        }
                        else if (defaultAction == Protobuf.Shared.PlayerAction.Use)
                        {
                            action = AppearanceActions.Use;
                        }
                        else if (@object.Type.IsContainer)
                        {
                            action = AppearanceActions.Open;
                        }
                        else if (@object.Type.IsForceUse || @object.Type.IsMultiUse || @object.Type.IsUsable)
                        {
                            action = AppearanceActions.Use;
                        }
                        else
                        {
                            action = AppearanceActions.Look;
                        }
                    }
                    else if (mouseButton == MouseButton.Right && eventModifiers == EventModifiers.None)
                    {
                        action = AppearanceActions.ContextMenu;
                    }
                }
                else if (eventModifiers == EventModifiers.Shift)
                {
                    if (mouseButton == MouseButton.Left || mouseButton == MouseButton.None)
                    {
                        action = AppearanceActions.Look;
                    }
                }
            }
            else if (optionStorage.MousePreset == MousePresets.Classic)
            {
                if (mouseButton == MouseButton.Left || mouseButton == MouseButton.None)
                {
                    if (eventModifiers == EventModifiers.Shift)
                    {
                        action = AppearanceActions.Look;
                    }
                    else if (eventModifiers == EventModifiers.Control)
                    {
                        action = AppearanceActions.ContextMenu;
                    }
                    else if (eventModifiers == EventModifiers.Alt)
                    {
                        action = @object.Type.IsContainer ? AppearanceActions.Open : AppearanceActions.Use;
                    }
                }
                else if (mouseButton == MouseButton.Right)
                {
                    if (eventModifiers == EventModifiers.None)
                    {
                        action = @object.Type.IsContainer ? AppearanceActions.Open : AppearanceActions.Use;
                    }
                    else if (eventModifiers == EventModifiers.Control)
                    {
                        action = AppearanceActions.ContextMenu;
                    }
                }
                else if (mouseButton == MouseButton.Both)
                {
                    action = AppearanceActions.Look;
                }
            }
            else if (optionStorage.MousePreset == MousePresets.Regular)
            {
                if (mouseButton == MouseButton.Left || mouseButton == MouseButton.None)
                {
                    if (eventModifiers == EventModifiers.Shift)
                    {
                        action = AppearanceActions.Look;
                    }
                    else if (eventModifiers == EventModifiers.Control)
                    {
                        action = AppearanceActions.Open;
                    }
                    else if ((eventModifiers & EventModifiers.Alt) != 0 && (eventModifiers & EventModifiers.Shift) == 0)
                    {
                        action = AppearanceActions.ContextMenu;
                    }
                }
                else if (mouseButton == MouseButton.Right)
                {
                    if (eventModifiers == EventModifiers.None)
                    {
                        action = AppearanceActions.ContextMenu;
                    }
                    else if (eventModifiers == EventModifiers.Control)
                    {
                        action = AppearanceActions.Open;
                    }
                }
            }

            if (updateCursor)
            {
                OpenTibiaUnity.GameManager.CursorController.SetCursorState(action, CursorPriority.Medium);
            }

            if (applyAction)
            {
                var absolutePosition = new Vector3Int(65535, 64 + _containerView.Id, _slotUnderMouse);
                switch (action)
                {
                case AppearanceActions.None: break;

                case AppearanceActions.ContextMenu:
                    OpenTibiaUnity.CreateObjectContextMenu(absolutePosition, @object, absolutePosition.z, @object, absolutePosition.z, null)
                    .Display(mousePosition);
                    break;

                case AppearanceActions.Look:
                    new LookActionImpl(absolutePosition, @object.Type, absolutePosition.z).Perform();
                    break;

                case AppearanceActions.Use:
                    if (@object.Type.IsMultiUse)
                    {
                        ObjectMultiUseHandler.Activate(absolutePosition, @object, absolutePosition.z);
                    }
                    else
                    {
                        new UseActionImpl(absolutePosition, @object.Type, absolutePosition.z, Vector3Int.zero, null, 0, UseActionTarget.Auto).Perform();
                    }
                    break;

                case AppearanceActions.Open:
                    new UseActionImpl(absolutePosition, @object.Type, absolutePosition.z, Vector3Int.zero, null, 0, UseActionTarget.Auto).Perform();
                    break;

                case AppearanceActions.Loot:
                    new LootActionImpl(absolutePosition, @object.Type, absolutePosition.z).Perform();
                    break;

                case AppearanceActions.Unset:
                    break;
                }
            }

            return(action);
        }
Beispiel #2
0
        public void SendLogin(uint challengeTimestamp, byte challengeRandom)
        {
            var message = _packetWriter.CreateMessage();

            message.WriteEnum(GameclientMessageType.PendingGame);
            message.WriteUnsignedShort((ushort)Utils.Utility.GetCurrentOs());

            var gameManager   = OpenTibiaUnity.GameManager;
            var optionStorage = OpenTibiaUnity.OptionStorage;

            message.WriteUnsignedShort((ushort)gameManager.ProtocolVersion);

            if (gameManager.GetFeature(GameFeature.GameClientVersion))
            {
                message.WriteUnsignedInt((uint)gameManager.ClientVersion);
            }

            if (gameManager.GetFeature(GameFeature.GameContentRevision))
            {
                message.WriteUnsignedShort(OpenTibiaUnity.GetContentRevision(gameManager.ClientVersion, gameManager.BuildVersion));
            }

            if (gameManager.GetFeature(GameFeature.GamePreviewState))
            {
                message.WriteUnsignedByte(0);
            }

            if (OpenTibiaUnity.GameManager.BuildVersion >= 6018 && OpenTibiaUnity.GameManager.BuildVersion < 7695)
            {
                message.WriteBoolean(optionStorage.OptimiseConnectionStability);
            }

            int payloadStart = message.Position;

            message.WriteUnsignedByte(0); // first byte must be zero;

            if (gameManager.GetFeature(GameFeature.GameLoginPacketEncryption))
            {
                _xTEA.WriteKey(message);
                message.WriteUnsignedByte(0x00); // gm
            }

            if (gameManager.GetFeature(GameFeature.GameSessionKey))
            {
                message.WriteString(SessionKey);
                message.WriteString(CharacterName);
            }
            else
            {
                if (gameManager.GetFeature(GameFeature.GameAccountNames))
                {
                    message.WriteString(AccountName);
                }
                else
                {
                    message.WriteUnsignedInt(uint.Parse(AccountName));
                }

                message.WriteString(CharacterName);
                message.WriteString(Password);

                if (gameManager.GetFeature(GameFeature.GameAuthenticator))
                {
                    message.WriteString(Token);
                }
            }

            if (gameManager.GetFeature(GameFeature.GameChallengeOnLogin))
            {
                message.WriteUnsignedInt(challengeTimestamp);
                message.WriteUnsignedByte(challengeRandom);
            }

            if (gameManager.GetFeature(GameFeature.GameLoginPacketEncryption))
            {
                Cryptography.PublicRSA.EncryptMessage(message, payloadStart, Cryptography.PublicRSA.RSABlockSize);
            }

            _packetWriter.FinishMessage();
        }
Beispiel #3
0
        public AppearanceActions DetermineAction(Vector3 mousePosition, MouseButton mouseButton, EventModifiers eventModifiers, Vector2 point, bool applyAction = false, bool updateCursor = false, bool updateHighlight = false)
        {
            if (updateCursor)
            {
                updateCursor = OpenTibiaUnity.GameManager.ClientVersion >= 1100;
            }

            if (updateHighlight)
            {
                updateHighlight = OpenTibiaUnity.GameManager.ClientVersion >= 1100;
            }

            var inputHandler = OpenTibiaUnity.InputHandler;

            if (inputHandler.IsMouseButtonDragged(MouseButton.Left) || inputHandler.IsMouseButtonDragged(MouseButton.Right))
            {
                return(AppearanceActions.None);
            }

            var gameManager      = OpenTibiaUnity.GameManager;
            var worldMapRenderer = OpenTibiaUnity.WorldMapRenderer;
            var worldMapStorage  = OpenTibiaUnity.WorldMapStorage;
            var creatureStorage  = OpenTibiaUnity.CreatureStorage;
            var mapPosition      = worldMapRenderer.PointToMap(point, false);

            if (gameManager.ClientVersion >= 1100)
            {
                worldMapRenderer.HighlightTile = mapPosition;
            }

            if (!mapPosition.HasValue)
            {
                return(AppearanceActions.None);
            }

            var            player                = OpenTibiaUnity.Player;
            var            action                = AppearanceActions.None;
            ObjectInstance topLookObject         = null;
            ObjectInstance topUseObject          = null;
            int            topLookObjectStackPos = -1;
            int            topUseObjectStackPos  = -1;

            Creature creature = worldMapRenderer.PointToCreature(point, true);

            var optionStorage    = OpenTibiaUnity.OptionStorage;
            var absolutePosition = worldMapStorage.ToAbsolute(mapPosition.Value);

            if (optionStorage.MousePreset == MousePresets.LeftSmartClick)
            {
                bool forceLook = eventModifiers == EventModifiers.Shift;
                if (mouseButton == MouseButton.Right)
                {
                    var field = worldMapStorage.GetField(mapPosition.Value);
                    topLookObjectStackPos = field.GetTopLookObject(out topLookObject);
                    topUseObjectStackPos  = field.GetTopUseObject(out topUseObject);

                    if (!!topUseObject || !!topLookObject)
                    {
                        action = AppearanceActions.ContextMenu;
                    }
                }
                else if (mouseButton == MouseButton.Left)
                {
                    if (eventModifiers == EventModifiers.None)
                    {
                        if (mapPosition.Value.z != worldMapStorage.PlayerZPlane)
                        {
                            var field = worldMapStorage.GetField(mapPosition.Value);

                            action = AppearanceActions.SmartClick;
                            if (!!creature)
                            {
                                if (creature.Id == player.Id || forceLook)
                                {
                                    topLookObjectStackPos = field.GetCreatureObjectForCreatureId(creature.Id, out ObjectInstance creatureObject);
                                    topLookObject         = creatureObject;
                                    action = AppearanceActions.Look;
                                }
                                else if (creature.IsNPC)
                                {
                                    action = AppearanceActions.Talk;
                                }
                                else
                                {
                                    action = AppearanceActions.Attack;
                                }
                            }
                            else if ((topUseObjectStackPos = field.GetTopUseObject(out topUseObject)) != -1 && !!topUseObject && topUseObject.Type.IsUsable)
                            {
                                action = AppearanceActions.Use;
                            }
                            else if ((topLookObjectStackPos = field.GetTopLookObject(out topLookObject)) != -1 && !!topLookObject)
                            {
                                action = AppearanceActions.Look;
                            }
                            else
                            {
                                // TODO (default action)
                            }
                        }
                        else
                        {
                            action = AppearanceActions.AutoWalk;
                        }
                    }
                    else if (eventModifiers == EventModifiers.Shift)
                    {
                        topLookObjectStackPos = worldMapStorage.GetTopLookObject(mapPosition.Value, out topLookObject);
                        if (!!topLookObject)
                        {
                            action = AppearanceActions.Look;
                        }
                    }
                    else if (eventModifiers == EventModifiers.Control)
                    {
                        action = AppearanceActions.AutoWalk;
                    }
                    else if (eventModifiers == EventModifiers.Alt)
                    {
                        if (!!creature && creature.Id != player.Id && (!creature.IsNPC || gameManager.ClientVersion < 1000))
                        {
                            action = AppearanceActions.Attack;
                        }
                    }
                }
            }
            else if (optionStorage.MousePreset == MousePresets.Classic)
            {
                if (eventModifiers == EventModifiers.Alt)
                {
                    if (mouseButton == MouseButton.Left || mouseButton == MouseButton.None)
                    {
                        if (!!creature && creature.Id != player.Id && (!creature.IsNPC || gameManager.ClientVersion < 1000))
                        {
                            action = AppearanceActions.Attack;
                        }
                    }
                }
                else if (eventModifiers == EventModifiers.Control)
                {
                    if (mouseButton != MouseButton.Both && mouseButton != MouseButton.Middle)
                    {
                        topLookObjectStackPos = worldMapStorage.GetTopLookObject(mapPosition.Value, out topLookObject);
                        topUseObjectStackPos  = worldMapStorage.GetTopUseObject(mapPosition.Value, out topUseObject);

                        if (!!topUseObject || !!topLookObject)
                        {
                            action = AppearanceActions.ContextMenu;
                        }
                    }
                }
                else if (mouseButton == MouseButton.Left || mouseButton == MouseButton.None)
                {
                    if (eventModifiers == EventModifiers.None)
                    {
                        topLookObjectStackPos = worldMapStorage.GetTopLookObject(mapPosition.Value, out topLookObject);
                        if (!!topLookObject)
                        {
                            if (optionStorage.MouseLootPreset == MouseLootPresets.Left && topLookObject.Type.IsCorpse)
                            {
                                topUseObject         = topLookObject;
                                topUseObjectStackPos = topLookObjectStackPos;
                                action = AppearanceActions.Loot;
                            }
                            else if (topLookObject.Type.DefaultAction == PlayerAction.AutowalkHighlight)
                            {
                                action = AppearanceActions.AutoWalkHighlight;
                            }
                            else
                            {
                                action = AppearanceActions.AutoWalk;
                            }
                        }
                    }
                    else if (eventModifiers == EventModifiers.Shift)
                    {
                        topLookObjectStackPos = worldMapStorage.GetTopLookObject(mapPosition.Value, out topLookObject);
                        if (!!topLookObject)
                        {
                            action = AppearanceActions.Look;
                        }
                    }
                }
                else if (mouseButton == MouseButton.Right)
                {
                    if (eventModifiers == EventModifiers.None)
                    {
                        if (!!creature && creature.Id != player.Id && (!creature.IsNPC || gameManager.ClientVersion < 1000))
                        {
                            action = AppearanceActions.Attack;
                        }
                        else
                        {
                            topUseObjectStackPos = worldMapStorage.GetTopUseObject(mapPosition.Value, out topUseObject);
                            if (!!topUseObject)
                            {
                                if (optionStorage.MouseLootPreset == MouseLootPresets.Right && topUseObject.Type.IsCorpse)
                                {
                                    action = AppearanceActions.Loot;
                                }
                                else if (topUseObject.Type.IsContainer)
                                {
                                    action = AppearanceActions.Open;
                                }
                                else
                                {
                                    action = AppearanceActions.Use;
                                }
                            }
                        }
                    }
                    else if (eventModifiers == EventModifiers.Shift && optionStorage.MouseLootPreset == MouseLootPresets.ShiftPlusRight)
                    {
                        topUseObjectStackPos = worldMapStorage.GetTopUseObject(mapPosition.Value, out topUseObject);
                        if (!!topUseObject && topUseObject.Type.IsCorpse && !topUseObject.Type.IsPlayerCorpse)
                        {
                            action = AppearanceActions.Loot;
                        }
                    }
                }
                else if (mouseButton == MouseButton.Both)
                {
                    if (eventModifiers == EventModifiers.None)
                    {
                        topLookObjectStackPos = worldMapStorage.GetTopLookObject(mapPosition.Value, out topLookObject);
                        if (!!topLookObject)
                        {
                            action = AppearanceActions.Look;
                        }
                    }
                }
            }
            else if (optionStorage.MousePreset == MousePresets.Regular)
            {
                // TODO
            }

            if (updateCursor)
            {
                OpenTibiaUnity.GameManager.CursorController.SetCursorState(action, CursorPriority.Medium);
            }

            if (updateHighlight && !OpenTibiaUnity.GameManager.ActiveBlocker.gameObject.activeSelf)
            {
                switch (action)
                {
                case AppearanceActions.Talk:
                case AppearanceActions.Attack:
                    worldMapRenderer.HighlightObject = creature;
                    break;

                case AppearanceActions.Look:
                case AppearanceActions.AutoWalkHighlight:
                    worldMapRenderer.HighlightObject = topLookObject;
                    break;

                case AppearanceActions.Use:
                case AppearanceActions.Open:
                case AppearanceActions.Loot:
                    worldMapRenderer.HighlightObject = topUseObject;
                    break;

                default:
                    worldMapRenderer.HighlightObject = null;
                    break;
                }
            }
            else if (updateHighlight)
            {
                worldMapRenderer.HighlightObject = null;
            }

            if (applyAction)
            {
                switch (action)
                {
                case AppearanceActions.None: break;

                case AppearanceActions.Attack:
                    if (!!creature && creature.Id != player.Id)
                    {
                        OpenTibiaUnity.CreatureStorage.ToggleAttackTarget(creature, true);
                    }
                    break;

                case AppearanceActions.AutoWalk:
                case AppearanceActions.AutoWalkHighlight:
                    absolutePosition = worldMapRenderer.PointToAbsolute(RawMousePositionToLocalMapPosition(mousePosition), true).Value;
                    player.StartAutowalk(absolutePosition, false, true);
                    break;

                case AppearanceActions.ContextMenu:
                    OpenTibiaUnity.CreateObjectContextMenu(absolutePosition, topLookObject, topLookObjectStackPos, topUseObject, topUseObjectStackPos, creature)
                    .Display(mousePosition);
                    break;

                case AppearanceActions.Look:
                    new LookActionImpl(absolutePosition, topLookObject, topLookObjectStackPos).Perform();
                    break;

                case AppearanceActions.Use:
                    if (topUseObject.Type.IsMultiUse)
                    {
                        ObjectMultiUseHandler.Activate(absolutePosition, topUseObject, topUseObjectStackPos);
                    }
                    else
                    {
                        new UseActionImpl(absolutePosition, topUseObject.Type, topUseObjectStackPos, Vector3Int.zero, null, 0, UseActionTarget.Auto).Perform();
                    }
                    break;

                case AppearanceActions.Open:
                    new UseActionImpl(absolutePosition, topUseObject, topUseObjectStackPos, Vector3Int.zero, null, 0, UseActionTarget.Auto).Perform();
                    break;

                case AppearanceActions.Talk:
                    new GreetAction(creature).Perform();
                    break;

                case AppearanceActions.Loot:
                    new LootActionImpl(absolutePosition, topLookObject, topLookObjectStackPos).Perform();
                    break;

                case AppearanceActions.Unset:
                    break;
                }
            }

            return(action);
        }
        protected void SendLogin()
        {
            var message = m_PacketWriter.CreateMessage();

            message.WriteEnum(LoginclientMessageType.EnterAccount);
            message.WriteUnsignedShort((ushort)Utility.Utility.GetCurrentOs());

            var gameManager = OpenTibiaUnity.GameManager;

            message.WriteUnsignedShort((ushort)gameManager.ProtocolVersion);

            if (gameManager.GetFeature(GameFeature.GameClientVersion))
            {
                message.WriteUnsignedInt((uint)gameManager.ClientVersion);
            }

            if (gameManager.GetFeature(GameFeature.GameContentRevision))
            {
                message.WriteUnsignedShort(OpenTibiaUnity.GetContentRevision(gameManager.ClientVersion, gameManager.BuildVersion));
                message.WriteUnsignedShort(0);
            }
            else
            {
                message.WriteUnsignedInt(0); // DatSignature
            }

            message.WriteUnsignedInt(0); // spr signature
            message.WriteUnsignedInt(0); // pic signature

            if (gameManager.GetFeature(GameFeature.GamePreviewState))
            {
                message.WriteUnsignedByte(0x00);
            }

            int payloadStart = message.Position;
            var random       = new System.Random();

            if (gameManager.GetFeature(GameFeature.GameLoginPacketEncryption))
            {
                message.WriteUnsignedByte(0); // first byte must be zero

                m_XTEA.WriteKey(message);
            }

            if (gameManager.GetFeature(GameFeature.GameAccountEmailAddress))
            {
                message.WriteString(EmailAddress);
            }
            else if (gameManager.GetFeature(GameFeature.GameAccountNames))
            {
                message.WriteString(AccountName);
            }
            else if (uint.TryParse(AccountName, out uint accountNumber))
            {
                message.WriteUnsignedInt(accountNumber);
            }
            else
            {
                message.WriteUnsignedInt(0);
            }

            message.WriteString(Password);

            if (gameManager.GetFeature(GameFeature.GameLoginPacketEncryption))
            {
                Cryptography.PublicRSA.EncryptMessage(message, payloadStart, Cryptography.PublicRSA.RSABlockSize);
            }

            if (gameManager.GetFeature(GameFeature.GameOGLInformation))
            {
                message.WriteUnsignedByte(1);
                message.WriteUnsignedByte(1);

                if (gameManager.ClientVersion >= 1072)
                {
                    message.WriteString(string.Format("{0} {1}", OpenTibiaUnity.GraphicsVendor, OpenTibiaUnity.GraphicsDevice));
                }
                else
                {
                    message.WriteString(OpenTibiaUnity.GraphicsDevice);
                }

                message.WriteString(OpenTibiaUnity.GraphicsVersion);
            }

            if (gameManager.GetFeature(GameFeature.GameAuthenticator))
            {
                payloadStart = message.Position;

                message.WriteUnsignedByte(0);
                message.WriteString(Token);   // no auth-token

                message.WriteUnsignedByte(0); // stay logged-in for a while

                Cryptography.PublicRSA.EncryptMessage(message, payloadStart, Cryptography.PublicRSA.RSABlockSize);
            }

            m_PacketWriter.FinishMessage();
            if (gameManager.GetFeature(GameFeature.GameLoginPacketEncryption))
            {
                m_PacketReader.XTEA = m_XTEA;
                m_PacketWriter.XTEA = m_XTEA;
            }
        }