Beispiel #1
0
        private Engine(Settings settings)
        {
            Instance  = this;
            _settings = settings ?? ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, "settings.json"));

            if (_settings == null)
            {
                SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No `setting.json`", "A `settings.json` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow());
                Log.Message(LogTypes.Trace, "settings.json file not found");
                _settings = new Settings();
                _settings.Save();
                IsQuitted = true;
                return;
            }

            TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS);
            IsFixedTimeStep   = _settings.FixedTimeStep;

            _graphicDeviceManager = new GraphicsDeviceManager(this);
            _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents;

            if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef))
            {
                _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef;
            }
            _graphicDeviceManager.PreferredDepthStencilFormat    = DepthFormat.Depth24Stencil8;
            _graphicDeviceManager.SynchronizeWithVerticalRetrace = false;
            _graphicDeviceManager.ApplyChanges();

            _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1";
            _window    = Window;

            Window.ClientSizeChanged += (sender, e) =>
            {
                int width  = Window.ClientBounds.Width;
                int height = Window.ClientBounds.Height;

                if (_isHighDPI)
                {
                    width  *= 2;
                    height *= 2;
                }

                _graphicDeviceManager.PreferredBackBufferWidth  = width;
                _graphicDeviceManager.PreferredBackBufferHeight = height;
                _graphicDeviceManager.ApplyChanges();

                WorldViewportGump gump = _uiManager.GetByLocalSerial <WorldViewportGump>();

                if (gump != null && _profileManager.Current.GameWindowFullSize)
                {
                    gump.ResizeWindow(new Point(WindowWidth, WindowHeight));
                }
            };
            Window.AllowUserResizing = true;
            IsMouseVisible           = true;
        }
        private void OnKeyDown(object sender, SDL.SDL_KeyboardEvent e)
        {
            if (TargetManager.IsTargeting && e.keysym.sym == SDL.SDL_Keycode.SDLK_ESCAPE && Input.Keyboard.IsModPressed(e.keysym.mod, SDL.SDL_Keymod.KMOD_NONE))
            {
                TargetManager.CancelTarget();
            }

            _isShiftDown = Input.Keyboard.IsModPressed(e.keysym.mod, SDL.SDL_Keymod.KMOD_SHIFT);

            if (e.keysym.sym == SDL.SDL_Keycode.SDLK_TAB)
            {
                if (!World.Player.InWarMode && Engine.Profile.Current.HoldDownKeyTab)
                {
                    GameActions.SetWarMode(true);
                }
            }

            if (_keycodeDirection.TryGetValue(e.keysym.sym, out Direction dWalk))
            {
                WorldViewportGump viewport = Engine.UI.GetByLocalSerial <WorldViewportGump>();
                SystemChatControl chat     = viewport?.FindControls <SystemChatControl>().SingleOrDefault();
                if (chat != null && chat.textBox.Text.Length == 0)
                {
                    World.Player.Walk(dWalk, false);
                }
            }

            if ((e.keysym.mod & SDL2.SDL.SDL_Keymod.KMOD_NUM) != SDL2.SDL.SDL_Keymod.KMOD_NUM)
            {
                if (_keycodeDirectionNum.TryGetValue(e.keysym.sym, out Direction dWalkN))
                {
                    World.Player.Walk(dWalkN, false);
                }
            }

            bool isshift = (e.keysym.mod & SDL.SDL_Keymod.KMOD_SHIFT) != SDL.SDL_Keymod.KMOD_NONE;
            bool isalt   = (e.keysym.mod & SDL.SDL_Keymod.KMOD_ALT) != SDL.SDL_Keymod.KMOD_NONE;
            bool isctrl  = (e.keysym.mod & SDL.SDL_Keymod.KMOD_CTRL) != SDL.SDL_Keymod.KMOD_NONE;


            _useObjectHandles = isshift && isctrl;

            Macro macro = _macroManager.FindMacro(e.keysym.sym, isalt, isctrl, isshift);

            if (macro != null)
            {
                _macroManager.SetMacroToExecute(macro.FirstNode);
                _macroManager.WaitForTargetTimer = 0;
                _macroManager.Update();
            }

            //if (_hotkeysManager.TryExecuteIfBinded(e.keysym.sym, e.keysym.mod, out Action action))
            //{
            //    action();
            //}
        }
Beispiel #3
0
        public void SetWindowBorderless(bool borderless)
        {
            SDL_WindowFlags flags = (SDL_WindowFlags)SDL_GetWindowFlags(Window.Handle);

            if ((flags & SDL_WindowFlags.SDL_WINDOW_BORDERLESS) != 0 && borderless)
            {
                return;
            }

            if ((flags & SDL_WindowFlags.SDL_WINDOW_BORDERLESS) == 0 && !borderless)
            {
                return;
            }

            SDL_SetWindowBordered(Window.Handle, borderless ? SDL_bool.SDL_FALSE : SDL_bool.SDL_TRUE);
            SDL_GetCurrentDisplayMode(0, out SDL_DisplayMode displayMode);

            int width  = displayMode.w;
            int height = displayMode.h;

            if (borderless)
            {
                SetWindowSize(width, height);
                SDL_SetWindowPosition(Window.Handle, 0, 0);
            }
            else
            {
                SDL_GetWindowBordersSize
                (
                    Window.Handle,
                    out int top,
                    out _,
                    out int bottom,
                    out _
                );

                SetWindowSize(width, height - (top - bottom));
                SetWindowPositionBySettings();
            }

            WorldViewportGump viewport = UIManager.GetGump <WorldViewportGump>();

            if (viewport != null && ProfileManager.CurrentProfile.GameWindowFullSize)
            {
                viewport.ResizeGameWindow(new Point(width, height));
                viewport.X = -5;
                viewport.Y = -5;
            }
        }
Beispiel #4
0
        private void WindowOnClientSizeChanged(object sender, EventArgs e)
        {
            int width  = Window.ClientBounds.Width;
            int height = Window.ClientBounds.Height;

            if (!IsWindowMaximized())
            {
                ProfileManager.CurrentProfile.WindowClientBounds = new Point(width, height);
            }

            SetWindowSize(width, height);

            WorldViewportGump viewport = UIManager.GetGump <WorldViewportGump>();

            if (viewport != null && ProfileManager.CurrentProfile.GameWindowFullSize)
            {
                viewport.ResizeGameWindow(new Point(width, height));
                viewport.X = -5;
                viewport.Y = -5;
            }
        }
Beispiel #5
0
        private Engine(string[] args)
        {
            Instance = this;

            // By default try to load settings from main settings file
            _settings = ConfigurationResolver.Load <Settings>(Path.Combine(ExePath, SettingsFile));

            // Try to apply any settings passed from the command-line/shortcut to what we loaded from file
            // NOTE: If nothing was loaded from settings file (file doesn't exist), then it will create
            //   a new settings object and populate it with the passed settings
            ArgsParser(args, _settings);

            // If no still no settings after loading a file and parsing command-line settings,
            //   then show an error, generate default settings file and exit
            if (_settings == null)
            {
                SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION, "No `" + SettingsFile + "`", "A `" + SettingsFile + "` has been created into ClassicUO main folder.\nPlease fill it!", SDL.SDL_GL_GetCurrentWindow());
                Log.Message(LogTypes.Trace, SettingsFile + " file not found");
                _settings = new Settings();
                _settings.Save();
                IsQuitted = true;

                return;
            }


            // If settings are invalid, then show an error and exit
            if (!_settings.IsValid())
            {
                SDL.SDL_ShowSimpleMessageBox(
                    SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION,
                    "Invalid settings",
                    "Please, check your settings.\nYou should at least set `ultimaonlinedirectory` and `clientversion`.",
                    SDL.SDL_GL_GetCurrentWindow()
                    );
                Log.Message(LogTypes.Trace, "Invalid settings");
                IsQuitted = true;

                return;
            }


            TargetElapsedTime = TimeSpan.FromSeconds(1.0f / MAX_FPS);
            IsFixedTimeStep   = _settings.FixedTimeStep;

            _graphicDeviceManager = new GraphicsDeviceManager(this);
            _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents;

            if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef))
            {
                _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef;
            }

            _graphicDeviceManager.PreferredDepthStencilFormat    = DepthFormat.Depth24Stencil8;
            _graphicDeviceManager.SynchronizeWithVerticalRetrace = false;
            _graphicDeviceManager.ApplyChanges();

            _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1";
            _window    = Window;

            Window.ClientSizeChanged += (sender, e) =>
            {
                int width  = Window.ClientBounds.Width;
                int height = Window.ClientBounds.Height;

                if (_isHighDPI)
                {
                    width  *= 2;
                    height *= 2;
                }

                if (!IsMaximized)
                {
                    _engine._profileManager.Current.WindowClientBounds = new Point(width, height);
                }

                SetPreferredBackBufferSize(width, height);

                WorldViewportGump gump = _uiManager.GetControl <WorldViewportGump>();

                if (gump != null && _profileManager.Current.GameWindowFullSize)
                {
                    gump.ResizeWindow(new Point(WindowWidth, WindowHeight));
                    gump.X = -5;
                    gump.Y = -5;
                }
            };

            Window.AllowUserResizing = true;
            IsMouseVisible           = true;

            Window.Title = $"ClassicUO - {Version}";
        }
Beispiel #6
0
        public override void Load()
        {
            base.Load();

            ItemHold.Clear();
            Hotkeys = new HotkeysManager();
            Macros  = new MacroManager();

            // #########################################################
            // [FILE_FIX]
            // TODO: this code is a workaround to port old macros to the new xml system.
            if (ProfileManager.CurrentProfile.Macros != null)
            {
                for (int i = 0; i < ProfileManager.CurrentProfile.Macros.Length; i++)
                {
                    Macros.PushToBack(ProfileManager.CurrentProfile.Macros[i]);
                }

                Macros.Save();

                ProfileManager.CurrentProfile.Macros = null;
            }
            // #########################################################

            Macros.Load();

            InfoBars = new InfoBarManager();
            InfoBars.Load();
            _healthLinesManager = new HealthLinesManager();
            Weather             = new Weather();

            WorldViewportGump viewport = new WorldViewportGump(this);

            UIManager.Add(viewport, false);

            if (!ProfileManager.CurrentProfile.TopbarGumpIsDisabled)
            {
                TopBarGump.Create();
            }


            CommandManager.Initialize();
            NetClient.Socket.Disconnected += SocketOnDisconnected;

            MessageManager.MessageReceived += ChatOnMessageReceived;

            UIManager.ContainerScale = ProfileManager.CurrentProfile.ContainersScale / 100f;

            SDL.SDL_SetWindowMinimumSize(Client.Game.Window.Handle, 640, 480);

            if (ProfileManager.CurrentProfile.WindowBorderless)
            {
                Client.Game.SetWindowBorderless(true);
            }
            else if (Settings.GlobalSettings.IsWindowMaximized)
            {
                Client.Game.MaximizeWindow();
            }
            else if (Settings.GlobalSettings.WindowSize.HasValue)
            {
                int w = Settings.GlobalSettings.WindowSize.Value.X;
                int h = Settings.GlobalSettings.WindowSize.Value.Y;

                w = Math.Max(640, w);
                h = Math.Max(480, h);

                Client.Game.SetWindowSize(w, h);
            }


            CircleOfTransparency.Create(ProfileManager.CurrentProfile.CircleOfTransparencyRadius);
            Plugin.OnConnected();


            Camera.SetZoomValues
            (
                new[]
            {
                .5f, .6f, .7f, .8f, 0.9f, 1f, 1.1f, 1.2f, 1.3f, 1.5f, 1.6f, 1.7f, 1.8f, 1.9f, 2.0f, 2.1f, 2.2f,
                2.3f, 2.4f, 2.5f
            }
            );

            Camera.Zoom = ProfileManager.CurrentProfile.DefaultScale;
        }
Beispiel #7
0
        private int Process(MacroObject macro)
        {
            int result = 0;

            switch (macro.Code)
            {
            case MacroType.Say:
            case MacroType.Emote:
            case MacroType.Whisper:
            case MacroType.Yell:

                MacroObjectString mos = (MacroObjectString)macro;

                if (!string.IsNullOrEmpty(mos.Text))
                {
                    MessageType type = MessageType.Regular;
                    ushort      hue  = Engine.Profile.Current.SpeechHue;

                    switch (macro.Code)
                    {
                    case MacroType.Emote:
                        type = MessageType.Emote;
                        hue  = Engine.Profile.Current.EmoteHue;
                        break;

                    case MacroType.Whisper:
                        type = MessageType.Whisper;
                        hue  = Engine.Profile.Current.WhisperHue;
                        break;

                    case MacroType.Yell:
                        type = MessageType.Yell;
                        break;
                    }

                    Chat.Say(mos.Text, hue, type);
                }

                break;

            case MacroType.Walk:
                byte dt = (byte)Direction.Up;

                if (macro.SubCode != MacroSubType.NW)
                {
                    dt = (byte)(macro.SubCode - 2);

                    if (dt > 7)
                    {
                        dt = 0;
                    }
                }

                if (!Pathfinder.AutoWalking)
                {
                    World.Player.Walk((Direction)dt, false);
                }

                break;

            case MacroType.WarPeace:
                GameActions.ToggleWarMode();

                break;

            case MacroType.Paste:
                if (SDL.SDL_HasClipboardText() != SDL.SDL_bool.SDL_FALSE)
                {
                    string s = SDL.SDL_GetClipboardText();
                    if (!string.IsNullOrEmpty(s))
                    {
                        WorldViewportGump viewport = Engine.UI.GetByLocalSerial <WorldViewportGump>();
                        if (viewport != null)
                        {
                            SystemChatControl chat = viewport.FindControls <SystemChatControl>().SingleOrDefault();
                            if (chat != null)
                            {
                                chat.textBox.Text += s;
                            }
                        }
                    }
                }

                break;

            case MacroType.Open:
            case MacroType.Close:
            case MacroType.Minimize:
            case MacroType.Maximize:
                // TODO:
                break;

            case MacroType.OpenDoor:
                GameActions.OpenDoor();

                break;

            case MacroType.UseSkill:
                int skill = macro.SubCode - MacroSubType.Anatomy;

                if (skill >= 0 && skill < 24)
                {
                    skill = _skillTable[skill];

                    if (skill != 0xFF)
                    {
                        GameActions.UseSkill(skill);
                    }
                }
                break;

            case MacroType.LastSkill:
                GameActions.UseSkill(GameActions.LastSkillIndex);
                break;

            case MacroType.CastSpell:
                int spell = macro.SubCode - MacroSubType.Clumsy + 1;

                if (spell > 0 && spell <= 151)
                {
                    int totalCount = 0;
                    int spellType  = 0;

                    for (spellType = 0; spellType < 7; spellType++)
                    {
                        totalCount += _spellsCountTable[spellType];

                        if (spell < totalCount)
                        {
                            break;
                        }
                    }

                    if (spellType < 7)
                    {
                        spell += spellType * 100;

                        if (spellType > 2)
                        {
                            spell += 100;
                        }

                        GameActions.CastSpell(spell);
                    }
                }
                break;

            case MacroType.LastSpell:
                GameActions.CastSpell(GameActions.LastSpellIndex);
                break;

            case MacroType.Bow:
            case MacroType.Salute:
                int index = macro.Code - MacroType.Bow;

                const string BOW    = "bow";
                const string SALUTE = "salute";

                GameActions.EmoteAction(index == 0 ? BOW : SALUTE);
                break;

            case MacroType.QuitGame:
                Engine.SceneManager.GetScene <GameScene>()?.RequestQuitGame();
                break;

            case MacroType.AllNames:
                GameActions.AllNames();

                break;

            case MacroType.LastTarget:

                if (WaitForTargetTimer == 0)
                {
                    WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY;
                }

                if (TargetManager.IsTargeting)
                {
                    //if (TargetManager.TargetingState != TargetType.Object)
                    //{
                    //    TargetManager.TargetGameObject(TargetManager.LastGameObject);
                    //}
                    //else
                    TargetManager.TargetGameObject(World.Get(TargetManager.LastGameObject));

                    WaitForTargetTimer = 0;
                }
                else if (WaitForTargetTimer < Engine.Ticks)
                {
                    WaitForTargetTimer = 0;
                }
                else
                {
                    result = 1;
                }

                break;

            case MacroType.TargetSelf:
                if (WaitForTargetTimer == 0)
                {
                    WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY;
                }

                if (TargetManager.IsTargeting)
                {
                    TargetManager.TargetGameObject(World.Player);
                    WaitForTargetTimer = 0;
                }
                else if (WaitForTargetTimer < Engine.Ticks)
                {
                    WaitForTargetTimer = 0;
                }
                else
                {
                    result = 1;
                }

                break;

            case MacroType.ArmDisarm:
                int       handIndex = 1 - (macro.SubCode - MacroSubType.LeftHand);
                GameScene gs        = Engine.SceneManager.GetScene <GameScene>();

                if (handIndex < 0 || handIndex > 1 || gs.IsHoldingItem)
                {
                    break;
                }

                if (_itemsInHand[handIndex] != 0)
                {
                    Item item = World.Items.Get(_itemsInHand[handIndex]);

                    if (item != null)
                    {
                        GameActions.PickUp(item, 1);
                        gs.WearHeldItem(World.Player);
                    }

                    _itemsInHand[handIndex] = 0;
                }
                else
                {
                    Item backpack = World.Player.Equipment[(int)Layer.Backpack];

                    if (backpack == null)
                    {
                        break;
                    }

                    Item item = World.Player.Equipment[(int)Layer.OneHanded + handIndex];

                    if (item != null)
                    {
                        _itemsInHand[handIndex] = item.Serial;

                        GameActions.PickUp(item, 1);
                        GameActions.DropItem(item, Position.INVALID, backpack);
                    }
                }

                break;

            case MacroType.WaitForTarget:

                if (WaitForTargetTimer == 0)
                {
                    WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY;
                }

                if (TargetManager.IsTargeting || WaitForTargetTimer < Engine.Ticks)
                {
                    WaitForTargetTimer = 0;
                }
                else
                {
                    result = 1;
                }

                break;

            case MacroType.TargetNext:

                if (TargetManager.LastGameObject.IsMobile)
                {
                    Mobile mob = World.Mobiles.Get(TargetManager.LastGameObject);

                    if (mob.HitsMax == 0)
                    {
                        NetClient.Socket.Send(new PStatusRequest(mob));
                    }

                    World.LastAttack = mob.Serial;
                }

                break;

            case MacroType.AttackLast:
                GameActions.Attack(World.LastAttack);
                break;

            case MacroType.Delay:
                MacroObjectString mosss = (MacroObjectString)macro;
                string            str   = mosss.Text;

                if (!string.IsNullOrEmpty(str) && int.TryParse(str, out int rr))
                {
                    _nextTimer = Engine.Ticks + rr;
                }

                break;

            case MacroType.CircleTrans:
                Engine.Profile.Current.UseCircleOfTransparency = !Engine.Profile.Current.UseCircleOfTransparency;

                break;

            case MacroType.CloseGump:

                Engine.UI.Gumps
                .Where(s => !(s is TopBarGump) && !(s is BuffGump) && !(s is WorldViewportGump))
                .ToList()
                .ForEach(s => s.Dispose());

                break;

            case MacroType.AlwaysRun:
                Engine.Profile.Current.AlwaysRun = !Engine.Profile.Current.AlwaysRun;

                break;

            case MacroType.SaveDesktop:
                Engine.Profile.Current?.Save(Engine.UI.Gumps.OfType <Gump>().Where(s => s.CanBeSaved).Reverse().ToList());
                break;

            case MacroType.EnableRangeColor:
                Engine.Profile.Current.NoColorObjectsOutOfRange = true;
                break;

            case MacroType.DisableRangeColor:
                Engine.Profile.Current.NoColorObjectsOutOfRange = false;
                break;

            case MacroType.ToggleRangeColor:
                Engine.Profile.Current.NoColorObjectsOutOfRange = !Engine.Profile.Current.NoColorObjectsOutOfRange;
                break;

            case MacroType.AttackSelectedTarget:
                // TODO:
                break;

            case MacroType.UseSelectedTarget:
                // TODO:
                break;

            case MacroType.CurrentTarget:
                // TODO:
                break;

            case MacroType.TargetSystemOnOff:
                // TODO:
                break;

            case MacroType.BandageSelf:
            case MacroType.BandageTarget:

                if (FileManager.ClientVersion < ClientVersions.CV_5020 || Engine.Profile.Current.BandageSelfOld)
                {
                    if (WaitingBandageTarget)
                    {
                        if (WaitForTargetTimer == 0)
                        {
                            WaitForTargetTimer = Engine.Ticks + Constants.WAIT_FOR_TARGET_DELAY;
                        }

                        if (TargetManager.IsTargeting)
                        {
                            TargetManager.TargetGameObject(macro.Code == MacroType.BandageSelf ? World.Player : World.Mobiles.Get(TargetManager.LastGameObject));
                        }
                        else
                        {
                            result = 1;
                        }

                        WaitingBandageTarget = false;
                        WaitForTargetTimer   = 0;
                    }
                    else
                    {
                        var bandage = World.Player.FindBandage();
                        if (bandage != null)
                        {
                            WaitingBandageTarget = true;
                            GameActions.DoubleClick(bandage);
                            result = 1;
                        }
                    }
                }
                else
                {
                    var bandage = World.Player.FindBandage();
                    if (bandage != null)
                    {
                        if (macro.Code == MacroType.BandageSelf)
                        {
                            NetClient.Socket.Send(new PTargetSelectedObject(bandage.Serial, World.Player.Serial));
                        }
                        else
                        {
                            // TODO: NewTargetSystem
                            Log.Message(LogTypes.Warning, $"BandageTarget (NewTargetSystem) not implemented yet.");
                        }
                    }
                }

                break;

            case MacroType.SetUpdateRange:
            case MacroType.ModifyUpdateRange:

                if (macro is MacroObjectString moss && !string.IsNullOrEmpty(moss.Text) && byte.TryParse(moss.Text, out byte res))
                {
                    if (res < Constants.MIN_VIEW_RANGE)
                    {
                        res = Constants.MIN_VIEW_RANGE;
                    }
                    else if (res > Constants.MAX_VIEW_RANGE)
                    {
                        res = Constants.MAX_VIEW_RANGE;
                    }

                    World.ViewRange = res;
                }
                break;

            case MacroType.IncreaseUpdateRange:
                World.ViewRange++;
                if (World.ViewRange > Constants.MAX_VIEW_RANGE)
                {
                    World.ViewRange = Constants.MAX_VIEW_RANGE;
                }
                break;

            case MacroType.DecreaseUpdateRange:
                World.ViewRange--;
                if (World.ViewRange < Constants.MIN_VIEW_RANGE)
                {
                    World.ViewRange = Constants.MIN_VIEW_RANGE;
                }

                break;

            case MacroType.MaxUpdateRange:
                World.ViewRange = Constants.MAX_VIEW_RANGE;

                break;

            case MacroType.MinUpdateRange:
                World.ViewRange = Constants.MIN_VIEW_RANGE;

                break;

            case MacroType.DefaultUpdateRange:
                World.ViewRange = Constants.MAX_VIEW_RANGE;

                break;

            case MacroType.SelectNext:
            case MacroType.SelectPrevious:
            case MacroType.SelectNearest:
                // TODO:
                int scantype  = macro.SubCode - MacroSubType.Hostile;
                int scanRange = macro.Code - MacroType.SelectNext;


                switch (scanRange)
                {
                case 0:

                    break;

                case 1:

                    break;

                case 2:

                    break;
                }


                break;

            case MacroType.ToggleBuiconWindow:
                BuffGump buff = Engine.UI.GetByLocalSerial <BuffGump>();

                if (buff != null)
                {
                    buff.Dispose();
                }
                else
                {
                    Engine.UI.Add(new BuffGump(100, 100));
                }

                break;

            case MacroType.InvokeVirtue:
                byte id = (byte)(macro.SubCode - MacroSubType.Honor + 31);
                NetClient.Socket.Send(new PInvokeVirtueRequest(id));
                break;

            case MacroType.PrimaryAbility:
                GameActions.UsePrimaryAbility();

                break;

            case MacroType.SecondaryAbility:
                GameActions.UseSecondaryAbility();

                break;

            case MacroType.ToggleGargoyleFly:
                if (World.Player.Race == RaceType.GARGOYLE)
                {
                    NetClient.Socket.Send(new PToggleGargoyleFlying());
                }

                break;

            case MacroType.EquipLastWeapon:
                NetClient.Socket.Send(new PEquipLastWeapon());
                break;

            case MacroType.KillGumpOpen:
                // TODO:

                break;
            }


            return(result);
        }
Beispiel #8
0
        private Engine(string[] args)
        {
            Instance = this;

            string settingsFilepath = Settings.GetSettingsFilepath();

            Console.WriteLine($"SETTINGS FILE: {settingsFilepath}");

            // Check settings file for existence
            if (!Directory.Exists(Path.GetDirectoryName(settingsFilepath)) || !File.Exists(settingsFilepath))
            {
                Log.Message(LogTypes.Trace, "Settings file not found");
                Directory.CreateDirectory(Path.GetDirectoryName(settingsFilepath)); // Make sure we have full path in place
                _settings = new Settings();
                _settings.Save();
                SDL.SDL_ShowSimpleMessageBox(
                    SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION,
                    "No settings",
                    $"A new settings file has been created: {settingsFilepath}\n\n" +
                    "Please, open it with a text editor and at least set `ultimaonlinedirectory` and `clientversion` options.",
                    SDL.SDL_GL_GetCurrentWindow()
                    );
                IsQuitted = true;

                return;
            }

            // Firstly, try to load settings from either main or custom settings file
            // TODO: Wrap it in the `try..catch` block to catch potential JSON parsing errors
            _settings = ConfigurationResolver.Load <Settings>(settingsFilepath);

            // Secondly, Try to apply any settings passed from the command-line/shortcut options over those
            // we loaded from the settings file
            // NOTE: If nothing was loaded from settings file (file doesn't exist), then it will create
            //   a new settings object and populate it with the passed settings
            ArgsParser(args, _settings);

            // If no settings loaded from file, no settings parsed from command-line options,
            //   or if settings are invalid, then show an error and exit
            if (_settings == null || !_settings.IsValid())
            {
                Log.Message(LogTypes.Trace, "Invalid settings");
                SDL.SDL_ShowSimpleMessageBox(
                    SDL.SDL_MessageBoxFlags.SDL_MESSAGEBOX_INFORMATION,
                    "Invalid settings",
                    "Please, check your settings.\n\n" +
                    "You should at least set `ultimaonlinedirectory` and `clientversion`.",
                    SDL.SDL_GL_GetCurrentWindow()
                    );
                IsQuitted = true;

                return;
            }


            TargetElapsedTime = TimeSpan.FromSeconds(1.0f / Constants.MAX_FPS);
            IsFixedTimeStep   = _settings.FixedTimeStep;

            _graphicDeviceManager = new GraphicsDeviceManager(this);
            _graphicDeviceManager.PreparingDeviceSettings += (sender, e) => e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.DiscardContents;

            if (_graphicDeviceManager.GraphicsDevice.Adapter.IsProfileSupported(GraphicsProfile.HiDef))
            {
                _graphicDeviceManager.GraphicsProfile = GraphicsProfile.HiDef;
            }

            _graphicDeviceManager.PreferredDepthStencilFormat    = DepthFormat.Depth24Stencil8;
            _graphicDeviceManager.SynchronizeWithVerticalRetrace = false;
            _graphicDeviceManager.ApplyChanges();

            _isHighDPI = Environment.GetEnvironmentVariable("FNA_GRAPHICS_ENABLE_HIGHDPI") == "1";
            _window    = Window;

            Window.ClientSizeChanged += (sender, e) =>
            {
                int width  = Window.ClientBounds.Width;
                int height = Window.ClientBounds.Height;

                if (_isHighDPI)
                {
                    width  *= 2;
                    height *= 2;
                }

                if (!IsMaximized)
                {
                    _engine._profileManager.Current.WindowClientBounds = new Point(width, height);
                }

                SetPreferredBackBufferSize(width, height);

                WorldViewportGump gump = _uiManager.GetGump <WorldViewportGump>();

                if (gump != null && _profileManager.Current.GameWindowFullSize)
                {
                    gump.ResizeWindow(new Point(WindowWidth, WindowHeight));
                    gump.X = -5;
                    gump.Y = -5;
                }
            };

            Window.AllowUserResizing = true;
            IsMouseVisible           = _settings.RunMouseInASeparateThread;

            Window.Title = $"ClassicUO - {Version}";

            if (Bootstrap.StartMinimized)
            {
                SDL.SDL_MinimizeWindow(Window.Handle);
            }
        }