Esempio n. 1
0
        public static void Load()
        {
            Log.Trace(">>>>>>>>>>>>> Loading >>>>>>>>>>>>>");

            string clientPath = Settings.GlobalSettings.UltimaOnlineDirectory;

            Log.Trace($"Ultima Online installation folder: {clientPath}");

            Log.Trace("Loading files...");

            if (!string.IsNullOrWhiteSpace(Settings.GlobalSettings.ClientVersion))
            {
                // sanitize client version
                Settings.GlobalSettings.ClientVersion = Settings.GlobalSettings.ClientVersion.Replace(",", ".").Replace(" ", "").ToLower();
            }

            string clientVersionText = Settings.GlobalSettings.ClientVersion;

            // check if directory is good
            if (!Directory.Exists(clientPath))
            {
                Log.Error("Invalid client directory: " + clientPath);
                ShowErrorMessage($"'{clientPath}' is not a valid UO directory");
                throw new InvalidClientDirectory($"'{clientPath}' is not a valid directory");
            }

            // try to load the client version
            if (!ClientVersionHelper.IsClientVersionValid(clientVersionText, out ClientVersion clientVersion))
            {
                Log.Warn($"Client version [{clientVersionText}] is invalid, let's try to read the client.exe");

                // mmm something bad happened, try to load from client.exe
                if (!ClientVersionHelper.TryParseFromFile(Path.Combine(clientPath, "client.exe"), out clientVersionText) ||
                    !ClientVersionHelper.IsClientVersionValid(clientVersionText, out clientVersion))
                {
                    Log.Error("Invalid client version: " + clientVersionText);
                    ShowErrorMessage($"Impossible to define the client version.\nClient version: '{clientVersionText}'");
                    throw new InvalidClientVersion($"Invalid client version: '{clientVersionText}'");
                }

                Log.Trace($"Found a valid client.exe [{clientVersionText} - {clientVersion}]");

                // update the wrong/missing client version in settings.json
                Settings.GlobalSettings.ClientVersion = clientVersionText;
            }

            Version           = clientVersion;
            ClientPath        = clientPath;
            IsUOPInstallation = Version >= ClientVersion.CV_7000 && File.Exists(UOFileManager.GetUOFilePath("MainMisc.uop"));
            Protocol          = ClientFlags.CF_T2A;

            if (Version >= ClientVersion.CV_200)
            {
                Protocol |= ClientFlags.CF_RE;
            }
            if (Version >= ClientVersion.CV_300)
            {
                Protocol |= ClientFlags.CF_TD;
            }
            if (Version >= ClientVersion.CV_308)
            {
                Protocol |= ClientFlags.CF_LBR;
            }
            if (Version >= ClientVersion.CV_308Z)
            {
                Protocol |= ClientFlags.CF_AOS;
            }
            if (Version >= ClientVersion.CV_405A)
            {
                Protocol |= ClientFlags.CF_SE;
            }
            if (Version >= ClientVersion.CV_60144)
            {
                Protocol |= ClientFlags.CF_SA;
            }

            Log.Trace($"Client path: '{clientPath}'");
            Log.Trace($"Client version: {clientVersion}");
            Log.Trace($"Protocol: {Protocol}");
            Log.Trace("UOP? " + (IsUOPInstallation ? "yes" : "no"));

            // ok now load uo files
            UOFileManager.Load();
            StaticFilters.Load();

            Log.Trace("Network calibration...");
            PacketHandlers.Load();
            //ATTENTION: you will need to enable ALSO ultimalive server-side, or this code will have absolutely no effect!
            UltimaLive.Enable();
            PacketsTable.AdjustPacketSizeByVersion(Version);

            if (Settings.GlobalSettings.Encryption != 0)
            {
                Log.Trace("Calculating encryption by client version...");
                EncryptionHelper.CalculateEncryption(Version);
                Log.Trace($"encryption: {EncryptionHelper.Type}");

                if (EncryptionHelper.Type != (ENCRYPTION_TYPE)Settings.GlobalSettings.Encryption)
                {
                    Log.Warn($"Encryption found: {EncryptionHelper.Type}");
                    Settings.GlobalSettings.Encryption = (byte)EncryptionHelper.Type;
                }
            }

            Log.Trace("Done!");

            Log.Trace("Loading plugins...");

            foreach (var p in Settings.GlobalSettings.Plugins)
            {
                Plugin.Create(p);
            }
            Log.Trace("Done!");

            UoAssist.Start();

            Log.Trace(">>>>>>>>>>>>> DONE >>>>>>>>>>>>>");
        }
Esempio n. 2
0
        public override bool Draw(UltimaBatcher2D batcher, int posX, int posY)
        {
            if (!AllowedToDraw || IsDestroyed)
            {
                return(false);
            }

            ushort graphic = Graphic;
            ushort hue     = Hue;
            bool   partial = ItemData.IsPartialHue;

            ResetHueVector();

            if (ProfileManager.CurrentProfile.HighlightGameObjects && SelectedObject.LastObject == this)
            {
                hue     = Constants.HIGHLIGHT_CURRENT_OBJECT_HUE;
                partial = false;
            }
            else if (ProfileManager.CurrentProfile.NoColorObjectsOutOfRange && Distance > World.ClientViewRange)
            {
                hue     = Constants.OUT_RANGE_COLOR;
                partial = false;
            }
            else if (World.Player.IsDead && ProfileManager.CurrentProfile.EnableBlackWhiteEffect)
            {
                hue     = Constants.DEAD_RANGE_COLOR;
                partial = false;
            }

            ShaderHueTranslator.GetHueVector(ref HueVector, hue, partial, 0);

            bool isTree = StaticFilters.IsTree(graphic, out _);

            if (isTree && ProfileManager.CurrentProfile.TreeToStumps)
            {
                graphic = Constants.TREE_REPLACE_GRAPHIC;
            }

            if (AlphaHue != 255)
            {
                HueVector.Z = 1f - AlphaHue / 255f;
            }

            DrawStaticAnimated
            (
                batcher,
                graphic,
                posX,
                posY,
                ref HueVector,
                ref DrawTransparent,
                ProfileManager.CurrentProfile.ShadowsEnabled && ProfileManager.CurrentProfile.ShadowsStatics && (isTree || ItemData.IsFoliage || StaticFilters.IsRock(graphic))
            );

            if (ItemData.IsLight)
            {
                Client.Game.GetScene <GameScene>().AddLight(this, this, posX + 22, posY + 22);
            }

            if (!(SelectedObject.Object == this || FoliageIndex != -1 && Client.Game.GetScene <GameScene>().FoliageIndex == FoliageIndex))
            {
                if (DrawTransparent)
                {
                    return(true);
                }

                ref UOFileIndex index = ref ArtLoader.Instance.GetValidRefEntry(graphic + 0x4000);

                posX -= index.Width;
                posY -= index.Height;

                if (SelectedObject.IsPointInStatic(ArtLoader.Instance.GetTexture(graphic), posX, posY))
                {
                    SelectedObject.Object = this;
                }
            }
Esempio n. 3
0
        public override bool Draw(UltimaBatcher2D batcher, int posX, int posY, ref Vector3 hueVec)
        {
            if (!AllowedToDraw || IsDestroyed)
            {
                return(false);
            }

            //Engine.DebugInfo.ItemsRendered++;

            hueVec = Vector3.Zero;

            DrawTransparent = false;

            posX += (int)Offset.X;
            posY += (int)(Offset.Y + Offset.Z);

            if (ItemData.IsTranslucent)
            {
                hueVec.Z = 0.5f;
            }

            if (AlphaHue != 255)
            {
                hueVec.Z = 1f - AlphaHue / 255f;
            }

            if (IsCorpse)
            {
                return(DrawCorpse(batcher, posX, posY - 3, ref hueVec));
            }


            ushort hue     = Hue;
            ushort graphic = DisplayedGraphic;
            bool   partial = ItemData.IsPartialHue;

            if (OnGround)
            {
                if (ItemData.IsAnimated)
                {
                    if (ProfileManager.CurrentProfile.FieldsType == 2)
                    {
                        if (StaticFilters.IsFireField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0020;
                        }
                        else if (StaticFilters.IsParalyzeField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0058;
                        }
                        else if (StaticFilters.IsEnergyField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0070;
                        }
                        else if (StaticFilters.IsPoisonField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0044;
                        }
                        else if (StaticFilters.IsWallOfStone(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x038A;
                        }
                    }
                }

                if (ItemData.IsContainer && SelectedObject.SelectedContainer == this)
                {
                    hue     = 0x0035;
                    partial = false;
                }
            }

            if (ProfileManager.CurrentProfile.HighlightGameObjects && ReferenceEquals(SelectedObject.LastObject, this))
            {
                hue     = Constants.HIGHLIGHT_CURRENT_OBJECT_HUE;
                partial = false;
            }
            else if (ProfileManager.CurrentProfile.NoColorObjectsOutOfRange && Distance > World.ClientViewRange)
            {
                hue = Constants.OUT_RANGE_COLOR;
            }
            else if (World.Player.IsDead && ProfileManager.CurrentProfile.EnableBlackWhiteEffect)
            {
                hue = Constants.DEAD_RANGE_COLOR;
            }
            else
            {
                if (!IsLocked && !IsMulti && ReferenceEquals(SelectedObject.LastObject, this))
                {
                    // TODO: check why i put this.
                    //isPartial = ItemData.Weight == 0xFF;
                    hue = 0x0035;
                }
                else if (IsHidden)
                {
                    hue = 0x038E;
                }
            }

            ShaderHueTranslator.GetHueVector(ref hueVec, hue, partial, hueVec.Z);

            if (!IsMulti && !IsCoin && Amount > 1 && ItemData.IsStackable)
            {
                DrawStaticAnimated
                (
                    batcher,
                    graphic,
                    posX - 5,
                    posY - 5,
                    ref hueVec,
                    ref DrawTransparent,
                    false
                );
            }

            if (ItemData.IsLight || graphic >= 0x3E02 && graphic <= 0x3E0B || graphic >= 0x3914 && graphic <= 0x3929)
            {
                Client.Game.GetScene <GameScene>().AddLight(this, this, posX + 22, posY + 22);
            }

            if (!SerialHelper.IsValid(Serial) && IsMulti && TargetManager.TargetingState == CursorTarget.MultiPlacement)
            {
                hueVec.Z = 0.5f;
            }

            DrawStaticAnimated
            (
                batcher,
                graphic,
                posX,
                posY,
                ref hueVec,
                ref DrawTransparent,
                false
            );

            if (ReferenceEquals(SelectedObject.Object, this) || TargetManager.TargetingState == CursorTarget.MultiPlacement)
            {
                return(false);
            }

            ArtTexture texture = ArtLoader.Instance.GetTexture(graphic);

            if (texture != null)
            {
                ref UOFileIndex index = ref ArtLoader.Instance.GetValidRefEntry(graphic + 0x4000);

                posX -= index.Width;
                posY -= index.Height;

                if (ArtLoader.Instance.PixelCheck
                    (
                        graphic,
                        SelectedObject.TranslatedMousePositionByViewport.X - posX,
                        SelectedObject.TranslatedMousePositionByViewport.Y - posY
                    ))
                {
                    SelectedObject.Object = this;
                }
                else if (!IsMulti && !IsCoin && Amount > 1 && ItemData.IsStackable)
                {
                    if (ArtLoader.Instance.PixelCheck
                        (
                            graphic,
                            SelectedObject.TranslatedMousePositionByViewport.X - posX + 5,
                            SelectedObject.TranslatedMousePositionByViewport.Y - posY + 5
                        ))
                    {
                        SelectedObject.Object = this;
                    }
                }
            }
 public virtual void Init()
 {
     StaticFilters = CreateFilterItems(settings.StaticFilters);
     CustomFilters = CreateFilterItems(settings.CustomFilters);
     SelectedItem  = StaticFilters.FirstOrDefault();
 }
        private void AddTileToRenderList(GameObject obj, int worldX, int worldY, bool useObjectHandles, int maxZ /*, GameObject entity*/)
        {
            /*sbyte HeightChecks = 0;
             * if(entity != null)
             * {
             *  if(entity.X < worldX && entity.Y > worldY)
             *  {
             *      HeightChecks = 1;
             *  }
             *  else if (entity.Y < worldY && entity.X > worldX)
             *  {
             *      HeightChecks = -1;
             *  }
             * }*/

            for (; obj != null; obj = obj.Right)
            {
                if (obj.CurrentRenderIndex == _renderIndex || !obj.AllowedToDraw)
                {
                    continue;
                }

                if (UpdateDrawPosition && obj.CurrentRenderIndex != _renderIndex || obj.IsPositionChanged)
                {
                    obj.UpdateRealScreenPosition(_offset.X, _offset.Y);
                }

                obj.UseInRender = 0xFF;

                int drawX = obj.RealScreenPosition.X;
                int drawY = obj.RealScreenPosition.Y;

                if (drawX < _minPixel.X || drawX > _maxPixel.X)
                {
                    break;
                }

                int maxObjectZ = obj.PriorityZ;

                StaticTiles itemData = default;

                bool changinAlpha = false;
                bool island       = false;
                bool iscorpse     = false;
                bool ismobile     = false;

                switch (obj)
                {
                case Mobile _:
                    maxObjectZ += Constants.DEFAULT_CHARACTER_HEIGHT;
                    ismobile    = true;

                    break;

                case Land _:
                    island = true;
                    goto SKIP_HANDLES_CHECK;

                case Item it when it.IsCorpse:
                    iscorpse = true;
                    goto default;

                default:

                    if (GameObjectHelper.TryGetStaticData(obj, out itemData))
                    {
                        if (itemData.IsFoliage && World.Season >= Seasons.Winter)
                        {
                            continue;
                        }

                        if (obj is Static st)
                        {
                            if (StaticFilters.IsTree(st.OriginalGraphic))
                            {
                                if (Engine.Profile.Current.TreeToStumps && st.Graphic != Constants.TREE_REPLACE_GRAPHIC)
                                {
                                    if (!itemData.IsImpassable)
                                    {
                                        continue;
                                    }
                                    st.SetGraphic(Constants.TREE_REPLACE_GRAPHIC);
                                }
                                else if (st.OriginalGraphic != st.Graphic && !Engine.Profile.Current.TreeToStumps)
                                {
                                    st.RestoreOriginalGraphic();
                                }
                            }
                        }

                        if (_noDrawRoofs && itemData.IsRoof)
                        {
                            if (_alphaChanged)
                            {
                                changinAlpha = obj.ProcessAlpha(0);
                            }
                            else
                            {
                                changinAlpha = obj.AlphaHue != 0;
                            }

                            if (!changinAlpha)
                            {
                                continue;
                            }
                        }

                        //we avoid to hide impassable foliage or bushes, if present...
                        if ((Engine.Profile.Current.TreeToStumps && itemData.IsFoliage) || (Engine.Profile.Current.HideVegetation && !itemData.IsImpassable && StaticFilters.IsVegetation(obj.Graphic)))
                        {
                            continue;
                        }

                        //if (HeightChecks <= 0 && (!itemData.IsBridge || ((itemData.Flags & TileFlag.StairBack | TileFlag.StairRight) != 0) || itemData.IsWall))
                        {
                            maxObjectZ += itemData.Height;
                        }
                    }

                    break;
                }


                if (useObjectHandles && NameOverHeadManager.IsAllowed(obj as Entity))
                {
                    obj.UseObjectHandles = (ismobile ||
                                            iscorpse ||
                                            obj is Item it && (!it.IsLocked || it.IsLocked && itemData.IsContainer) && !it.IsMulti) &&
                                           !obj.ClosedObjectHandles && _objectHandlesCount <= 400;
                    if (obj.UseObjectHandles)
                    {
                        _objectHandlesCount++;
                    }
                }
                else if (obj.ClosedObjectHandles)
                {
                    obj.ClosedObjectHandles = false;
                    obj.ObjectHandlesOpened = false;
                }
                else if (obj.UseObjectHandles)
                {
                    obj.ObjectHandlesOpened = false;
                    obj.UseObjectHandles    = false;
                }


SKIP_HANDLES_CHECK:

                if (maxObjectZ > maxZ)
                {
                    break;
                }

                obj.CurrentRenderIndex = _renderIndex;

                if (!island)
                {
                    obj.UpdateTextCoordsV();
                }
                else
                {
                    goto SKIP_INTERNAL_CHECK;
                }

                if (!ismobile && !iscorpse && !island && itemData.IsInternal)
                {
                    continue;
                }

SKIP_INTERNAL_CHECK:

                int z = obj.Z;

                if (!island && z >= _maxZ)
                {
                    if (!changinAlpha)
                    {
                        if (_alphaChanged)
                        {
                            changinAlpha = obj.ProcessAlpha(0);
                        }
                        else
                        {
                            changinAlpha = obj.AlphaHue != 0;
                        }

                        if (!changinAlpha)
                        {
                            obj.UseInRender = (byte)_renderIndex;
                            continue;
                        }
                    }
                }

                int testMaxZ = drawY;

                if (testMaxZ > _maxPixel.Y)
                {
                    continue;
                }

                int testMinZ = drawY + (z << 2);

                if (island)
                {
                    Land t = obj as Land;

                    if (t.IsStretched)
                    {
                        testMinZ -= t.MinZ << 2;
                    }
                    else
                    {
                        testMinZ = testMaxZ;
                    }
                }
                else
                {
                    testMinZ = testMaxZ;
                }

                if (testMinZ < _minPixel.Y)
                {
                    continue;
                }

                if (ismobile || iscorpse)
                {
                    AddOffsetCharacterTileToRenderList(obj, useObjectHandles);
                }
                else if (!island && itemData.IsFoliage)
                {
                    bool check = World.Player.X <= worldX && World.Player.Y <= worldY;

                    if (!check)
                    {
                        check = World.Player.Y <= worldY && World.Player.X <= worldX + 1;

                        if (!check)
                        {
                            check = World.Player.X <= worldX && World.Player.Y <= worldY + 1;
                        }
                    }

                    if (check)
                    {
                        _rectangleObj.X      = drawX - obj.FrameInfo.X;
                        _rectangleObj.Y      = drawY - obj.FrameInfo.Y;
                        _rectangleObj.Width  = obj.FrameInfo.Width;
                        _rectangleObj.Height = obj.FrameInfo.Height;

                        check = Exstentions.InRect(ref _rectangleObj, ref _rectanglePlayer);
                    }

                    switch (obj)
                    {
                    case Static st:
                        st.CharacterIsBehindFoliage = check;

                        break;

                    case Multi m:
                        m.CharacterIsBehindFoliage = check;

                        break;

                    case Item it:
                        it.CharacterIsBehindFoliage = check;

                        break;
                    }
                }

                if (!island && _alphaChanged && !changinAlpha)
                {
                    if (itemData.IsTranslucent)
                    {
                        obj.ProcessAlpha(178);
                    }
                    else if (!itemData.IsFoliage && obj.AlphaHue != 0xFF)
                    {
                        obj.ProcessAlpha(0xFF);
                    }
                }

                if (_renderListCount >= _renderList.Length)
                {
                    int newsize = _renderList.Length + 1000;
                    Array.Resize(ref _renderList, newsize);
                }

                _renderList[_renderListCount++] = obj;
                obj.UseInRender = (byte)_renderIndex;
            }
        }
Esempio n. 6
0
 public override void UpdateGraphicBySeason()
 {
     SetGraphic(SeasonManager.GetSeasonGraphic(World.Season, OriginalGraphic));
     AllowedToDraw = CanBeDrawn(Graphic);
     IsVegetation  = StaticFilters.IsVegetation(Graphic);
 }
Esempio n. 7
0
 public override void UpdateGraphicBySeason()
 {
     Graphic      = SeasonManager.GetSeasonGraphic(World.Season, _originalGraphic);
     IsVegetation = StaticFilters.IsVegetation(Graphic);
 }
Esempio n. 8
0
        public override void Unload()
        {
            Client.Game.SetWindowTitle(string.Empty);

            ItemHold.Clear();

            try
            {
                Plugin.OnDisconnected();
            }
            catch
            {
            }
            // ## BEGIN - END ## //
            try
            {
                ModulesManager.Unload();
            }
            catch
            {
            }
            // ## BEGIN - END ## //
            TargetManager.Reset();

            // special case for wmap. this allow us to save settings
            UIManager.GetGump <WorldMapGump>()?.SaveSettings();

            ProfileManager.CurrentProfile?.Save(ProfileManager.ProfilePath);

            Macros.Save();
            InfoBars.Save();
            ProfileManager.UnLoadProfile();

            StaticFilters.CleanCaveTextures();
            StaticFilters.CleanTreeTextures();

            NetClient.Socket.Disconnected -= SocketOnDisconnected;
            NetClient.Socket.Disconnect();
            _lightRenderTarget?.Dispose();
            _world_render_target?.Dispose();

            CommandManager.UnRegisterAll();
            Weather.Reset();
            UIManager.Clear();
            World.Clear();
            ChatManager.Clear();
            DelayedObjectClickManager.Clear();

            _useItemQueue?.Clear();
            _useItemQueue = null;
            Hotkeys       = null;
            Macros        = null;
            MessageManager.MessageReceived -= ChatOnMessageReceived;


            Settings.GlobalSettings.WindowSize = new Point
                                                     (Client.Game.Window.ClientBounds.Width, Client.Game.Window.ClientBounds.Height);

            Settings.GlobalSettings.IsWindowMaximized = Client.Game.IsWindowMaximized();
            Client.Game.SetWindowBorderless(false);

            base.Unload();
        }
Esempio n. 9
0
        public override bool Draw(UltimaBatcher2D batcher, int posX, int posY)
        {
            if (!AllowedToDraw || IsDestroyed)
            {
                return(false);
            }

            //Engine.DebugInfo.ItemsRendered++;

            ResetHueVector();
            posX += (int)Offset.X;
            posY += (int)(Offset.Y + Offset.Z);

            if (IsCorpse)
            {
                return(DrawCorpse(batcher, posX, posY - 3));
            }


            ushort hue = Hue;

            if (ProfileManager.Current.FieldsType == 1 && StaticFilters.IsField(Graphic)) // static
            {
                unsafe
                {
                    IntPtr ptr = AnimDataLoader.Instance.GetAddressToAnim(Graphic);

                    if (ptr != IntPtr.Zero)
                    {
                        AnimDataFrame2 *animData = (AnimDataFrame2 *)ptr;

                        if (animData->FrameCount != 0)
                        {
                            _originalGraphic = (ushort)(Graphic + animData->FrameData[animData->FrameCount >> 1]);
                        }
                    }
                }

                _force = false;
            }
            else if (ProfileManager.Current.FieldsType == 2)
            {
                if (StaticFilters.IsFireField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0020;
                }
                else if (StaticFilters.IsParalyzeField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0058;
                }
                else if (StaticFilters.IsEnergyField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0070;
                }
                else if (StaticFilters.IsPoisonField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0044;
                }
                else if (StaticFilters.IsWallOfStone(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x038A;
                }
            }

            if (_originalGraphic != DisplayedGraphic || _force || Texture == null || Texture.IsDisposed)
            {
                if (_originalGraphic == 0)
                {
                    _originalGraphic = DisplayedGraphic;
                }

                Texture       = ArtLoader.Instance.GetTexture(_originalGraphic);
                Bounds.X      = (Texture.Width >> 1) - 22;
                Bounds.Y      = Texture.Height - 44;
                Bounds.Width  = Texture.Width;
                Bounds.Height = Texture.Height;

                _force = false;
            }

            if (ProfileManager.Current.HighlightGameObjects && SelectedObject.LastObject == this)
            {
                HueVector.X = 0x0023;
                HueVector.Y = 1;
            }
            else if (ProfileManager.Current.NoColorObjectsOutOfRange && Distance > World.ClientViewRange)
            {
                HueVector.X = Constants.OUT_RANGE_COLOR;
                HueVector.Y = 1;
            }
            else if (World.Player.IsDead && ProfileManager.Current.EnableBlackWhiteEffect)
            {
                HueVector.X = Constants.DEAD_RANGE_COLOR;
                HueVector.Y = 1;
            }
            else
            {
                bool isPartial = ItemData.IsPartialHue;

                if (SelectedObject.LastObject == this && !IsLocked && !IsMulti)
                {
                    isPartial = ItemData.Weight == 255;
                    hue       = 0x0035;
                }
                else if (IsHidden)
                {
                    hue = 0x038E;
                }

                ShaderHuesTraslator.GetHueVector(ref HueVector, hue, isPartial, ItemData.IsTranslucent ? .5f : 0);
            }

            if (!IsMulti && !IsCoin && Amount > 1 && ItemData.IsStackable)
            {
                base.Draw(batcher, posX - 5, posY - 5);
            }

            if (ItemData.IsLight)
            {
                Client.Game.GetScene <GameScene>()
                .AddLight(this, this, posX + 22, posY + 22);
            }

            if (!SerialHelper.IsValid(Serial) && IsMulti && TargetManager.TargetingState == CursorTarget.MultiPlacement)
            {
                HueVector.Z = 0.5f;
            }

            return(base.Draw(batcher, posX, posY));
        }
Esempio n. 10
0
 public override void UpdateGraphicBySeason()
 {
     SetGraphic(SeasonManager.GetSeasonGraphic(World.Season, OriginalGraphic));
     AllowedToDraw = !GameObjectHelper.IsNoDrawable(Graphic);
     IsVegetation  = StaticFilters.IsVegetation(Graphic);
 }
Esempio n. 11
0
        public override bool Draw(UltimaBatcher2D batcher, int posX, int posY)
        {
            if (!AllowedToDraw || IsDestroyed)
            {
                return(false);
            }

            Engine.DebugInfo.ItemsRendered++;

            ResetHueVector();

            if (IsCorpse)
            {
                return(DrawCorpse(batcher, posX, posY - 3));
            }


            ushort hue = Hue;

            if (Engine.Profile.Current.FieldsType == 1 && StaticFilters.IsField(Graphic)) // static
            {
                unsafe
                {
                    _originalGraphic = (Graphic)(Graphic + _animDataFrame.FrameData[_animDataFrame.FrameCount >> 1]);
                }

                _force = false;
            }
            else if (Engine.Profile.Current.FieldsType == 2)
            {
                if (StaticFilters.IsFireField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0020;
                }
                else if (StaticFilters.IsParalyzeField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0058;
                }
                else if (StaticFilters.IsEnergyField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0070;
                }
                else if (StaticFilters.IsPoisonField(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x0044;
                }
                else if (StaticFilters.IsWallOfStone(Graphic))
                {
                    _originalGraphic = Constants.FIELD_REPLACE_GRAPHIC;
                    hue = 0x038A;
                }
            }


            if (_originalGraphic != DisplayedGraphic || _force || Texture == null || Texture.IsDisposed)
            {
                if (_originalGraphic == 0)
                {
                    _originalGraphic = DisplayedGraphic;
                }

                Texture       = FileManager.Art.GetTexture(_originalGraphic);
                Bounds.X      = (Texture.Width >> 1) - 22;
                Bounds.Y      = Texture.Height - 44;
                Bounds.Width  = Texture.Width;
                Bounds.Height = Texture.Height;

                _force = false;
            }

            if (ItemData.IsFoliage)
            {
                if (CharacterIsBehindFoliage)
                {
                    if (AlphaHue != Constants.FOLIAGE_ALPHA)
                    {
                        ProcessAlpha(Constants.FOLIAGE_ALPHA);
                    }
                }
                else
                {
                    if (AlphaHue != 0xFF)
                    {
                        ProcessAlpha(0xFF);
                    }
                }
            }


            if (Engine.Profile.Current.HighlightGameObjects && SelectedObject.LastObject == this)
            {
                HueVector.X = 0x0023;
                HueVector.Y = 1;
            }
            else if (Engine.Profile.Current.NoColorObjectsOutOfRange && Distance > World.ClientViewRange)
            {
                HueVector.X = Constants.OUT_RANGE_COLOR;
                HueVector.Y = 1;
            }
            else if (World.Player.IsDead && Engine.Profile.Current.EnableBlackWhiteEffect)
            {
                HueVector.X = Constants.DEAD_RANGE_COLOR;
                HueVector.Y = 1;
            }
            else
            {
                bool isPartial = ItemData.IsPartialHue;

                if (SelectedObject.LastObject == this && !IsLocked)
                {
                    isPartial = false;
                    hue       = 0x0035;
                }
                else if (IsHidden)
                {
                    hue = 0x038E;
                }

                ShaderHuesTraslator.GetHueVector(ref HueVector, hue, isPartial, ItemData.IsTranslucent ? .5f : 0);
            }

            if (Amount > 1 && ItemData.IsStackable && DisplayedGraphic == Graphic && _originalGraphic == Graphic)
            {
                //SpriteRenderer.DrawStaticArt(DisplayedGraphic, Hue, (int) offsetDrawPosition.X, (int) offsetDrawPosition.Y);
                base.Draw(batcher, posX - 5, posY - 5);
            }

            if (ItemData.IsLight)
            {
                Engine.SceneManager.GetScene <GameScene>()
                .AddLight(this, this, posX + 22, posY + 22);
            }

            // SpriteRenderer.DrawStaticArt(DisplayedGraphic, Hue, (int)position.X, (int)position.Y);
            // return true;

            if (!Serial.IsValid && IsMulti && TargetManager.TargetingState == CursorTarget.MultiPlacement)
            {
                HueVector.Z = 0.5f;
            }

            return(base.Draw(batcher, posX, posY));
        }
Esempio n. 12
0
        public override bool Draw(UltimaBatcher2D batcher, int posX, int posY, float depth)
        {
            if (!AllowedToDraw || IsDestroyed)
            {
                return(false);
            }

            //Engine.DebugInfo.ItemsRendered++;
            Vector3 hueVec;

            posX += (int)Offset.X;
            posY += (int)(Offset.Y + Offset.Z);

            float alpha = AlphaHue / 255f;

            if (IsCorpse)
            {
                hueVec = ShaderHueTranslator.GetHueVector(0, false, alpha);
                return(DrawCorpse(batcher, posX, posY - 3, hueVec, depth));
            }


            ushort hue     = Hue;
            ushort graphic = DisplayedGraphic;
            bool   partial = ItemData.IsPartialHue;

            if (OnGround)
            {
                if (ItemData.IsAnimated)
                {
                    if (ProfileManager.CurrentProfile.FieldsType == 2)
                    {
                        if (StaticFilters.IsFireField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0020;
                        }
                        else if (StaticFilters.IsParalyzeField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0058;
                        }
                        else if (StaticFilters.IsEnergyField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0070;
                        }
                        else if (StaticFilters.IsPoisonField(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x0044;
                        }
                        else if (StaticFilters.IsWallOfStone(Graphic))
                        {
                            graphic = Constants.FIELD_REPLACE_GRAPHIC;
                            hue     = 0x038A;
                        }
                    }
                }

                if (ItemData.IsContainer && SelectedObject.SelectedContainer == this)
                {
                    hue     = 0x0035;
                    partial = false;
                }
            }

            if (ProfileManager.CurrentProfile.HighlightGameObjects && ReferenceEquals(SelectedObject.LastObject, this))
            {
                hue     = Constants.HIGHLIGHT_CURRENT_OBJECT_HUE;
                partial = false;
            }
            else if (ProfileManager.CurrentProfile.NoColorObjectsOutOfRange && Distance > World.ClientViewRange)
            {
                hue = Constants.OUT_RANGE_COLOR;
            }
            else if (World.Player.IsDead && ProfileManager.CurrentProfile.EnableBlackWhiteEffect)
            {
                hue = Constants.DEAD_RANGE_COLOR;
            }
            else
            {
                if (!IsLocked && !IsMulti && ReferenceEquals(SelectedObject.LastObject, this))
                {
                    // TODO: check why i put this.
                    //isPartial = ItemData.Weight == 0xFF;
                    hue = 0x0035;
                }
                else if (IsHidden)
                {
                    hue = 0x038E;
                }
            }

            hueVec = ShaderHueTranslator.GetHueVector(hue, partial, alpha);

            if (!IsMulti && !IsCoin && Amount > 1 && ItemData.IsStackable)
            {
                DrawStaticAnimated
                (
                    batcher,
                    graphic,
                    posX - 5,
                    posY - 5,
                    hueVec,
                    false,
                    depth
                );
            }

            if (ItemData.IsLight || graphic >= 0x3E02 && graphic <= 0x3E0B || graphic >= 0x3914 && graphic <= 0x3929)
            {
                Client.Game.GetScene <GameScene>().AddLight(this, this, posX + 22, posY + 22);
            }

            if (!SerialHelper.IsValid(Serial) && IsMulti && TargetManager.TargetingState == CursorTarget.MultiPlacement)
            {
                hueVec.Z = 0.5f;
            }

            DrawStaticAnimated
            (
                batcher,
                graphic,
                posX,
                posY,
                hueVec,
                false,
                depth
            );

            return(true);
        }
        private void AddTileToRenderList(GameObject obj, int worldX, int worldY, bool useObjectHandles, int maxZ)
        {
            for (; obj != null; obj = obj.Right)
            {
                if (obj.CurrentRenderIndex == _renderIndex || !obj.AllowedToDraw)
                {
                    continue;
                }

                if (UpdateDrawPosition && obj.CurrentRenderIndex != _renderIndex || obj.IsPositionChanged)
                {
                    obj.UpdateRealScreenPosition(_offset);
                }

                //obj.UseInRender = 0xFF;

                int drawX = obj.RealScreenPosition.X;
                int drawY = obj.RealScreenPosition.Y;

                if (drawX < _minPixel.X || drawX > _maxPixel.X)
                {
                    break;
                }

                int z          = obj.Z;
                int maxObjectZ = obj.PriorityZ;

                bool ismobile = false;

                StaticTiles itemData     = _emptyStaticTiles;
                bool        changinAlpha = false;
                bool        island       = false;

                switch (obj)
                {
                case Mobile _:
                    maxObjectZ += Constants.DEFAULT_CHARACTER_HEIGHT;
                    ismobile    = true;

                    break;

                case Land _:
                    island = true;
                    break;

                default:

                    if (GameObjectHelper.TryGetStaticData(obj, out itemData))
                    {
                        if (obj is Static st)
                        {
                            if (StaticFilters.IsTree(st.OriginalGraphic))
                            {
                                if (Engine.Profile.Current.TreeToStumps && st.Graphic != Constants.TREE_REPLACE_GRAPHIC)
                                {
                                    st.SetGraphic(Constants.TREE_REPLACE_GRAPHIC);
                                }
                                else if (st.OriginalGraphic != st.Graphic && !Engine.Profile.Current.TreeToStumps)
                                {
                                    st.RestoreOriginalGraphic();
                                }
                            }
                        }

                        if (_noDrawRoofs && itemData.IsRoof)
                        {
                            if (_alphaChanged)
                            {
                                changinAlpha = obj.ProcessAlpha(0);
                            }
                            else
                            {
                                changinAlpha = obj.AlphaHue != 0;
                            }


                            if (!changinAlpha)
                            {
                                continue;
                            }
                        }

                        if (Engine.Profile.Current.TreeToStumps && itemData.IsFoliage || Engine.Profile.Current.HideVegetation && StaticFilters.IsVegetation(obj.Graphic))
                        {
                            continue;
                        }

                        maxObjectZ += itemData.Height;
                    }

                    break;
                }

                if (maxObjectZ > maxZ)
                {
                    break;
                }

                obj.CurrentRenderIndex = _renderIndex;

                bool iscorpse = !ismobile && !island && obj is Item item && item.IsCorpse;

                if (!ismobile && !iscorpse && !island && itemData.IsInternal)
                {
                    continue;
                }

                if (!island && z >= _maxZ)
                {
                    if (!changinAlpha)
                    {
                        if (_alphaChanged)
                        {
                            changinAlpha = obj.ProcessAlpha(0);
                        }
                        else
                        {
                            changinAlpha = obj.AlphaHue != 0;
                        }

                        if (!changinAlpha)
                        {
                            continue;
                        }
                    }
                }

                int testMinZ = drawY + z * 4;
                int testMaxZ = drawY;

                if (island)
                {
                    Land t = obj as Land;

                    if (t.IsStretched)
                    {
                        testMinZ -= t.MinZ * 4;
                    }
                    else
                    {
                        testMinZ = testMaxZ;
                    }
                }
                else
                {
                    testMinZ = testMaxZ;
                }

                if (testMinZ < _minPixel.Y || testMaxZ > _maxPixel.Y)
                {
                    continue;
                }


                if (obj.OverheadMessageContainer != null && !obj.OverheadMessageContainer.IsEmpty)
                {
                    Overheads.AddOverhead(obj.OverheadMessageContainer);
                }

                if (ismobile || iscorpse)
                {
                    AddOffsetCharacterTileToRenderList(obj, useObjectHandles);
                }
                else if (!island && itemData.IsFoliage)
                {
                    bool check = World.Player.X <= worldX && World.Player.Y <= worldY;

                    if (!check)
                    {
                        check = World.Player.Y <= worldY && World.Player.Position.X <= worldX + 1;

                        if (!check)
                        {
                            check = World.Player.X <= worldX && World.Player.Y <= worldY + 1;
                        }
                    }

                    if (check)
                    {
                        _rectangleObj.X      = drawX - obj.FrameInfo.X;
                        _rectangleObj.Y      = drawY - obj.FrameInfo.Y;
                        _rectangleObj.Width  = obj.FrameInfo.Width;
                        _rectangleObj.Height = obj.FrameInfo.Height;

                        check = Exstentions.InRect(ref _rectangleObj, ref _rectanglePlayer);
                    }

                    switch (obj)
                    {
                    case Static st:
                        st.CharacterIsBehindFoliage = check;

                        break;

                    case Multi m:
                        m.CharacterIsBehindFoliage = check;

                        break;

                    case Item it:
                        it.CharacterIsBehindFoliage = check;

                        break;
                    }
                }

                if (_alphaChanged && !changinAlpha)
                {
                    if (itemData.IsTranslucent)
                    {
                        obj.ProcessAlpha(178);
                    }
                    else if (!itemData.IsFoliage && obj.AlphaHue != 0xFF)
                    {
                        obj.ProcessAlpha(0xFF);
                    }
                }

                if (_renderListCount >= _renderList.Length)
                {
                    int newsize = _renderList.Length + 1000;
                    //_renderList.Resize(newsize);
                    Array.Resize(ref _renderList, newsize);
                }


                if (useObjectHandles && NameOverHeadManager.IsAllowed(obj as Entity))
                {
                    obj.UseObjectHandles = (ismobile ||
                                            iscorpse ||
                                            obj is Item it && (!it.IsLocked || it.IsLocked && itemData.IsContainer) && !it.IsMulti) &&
                                           !obj.ClosedObjectHandles && _objectHandlesCount <= 400;
                    _objectHandlesCount++;
                }
                else if (obj.ClosedObjectHandles)
                {
                    obj.ClosedObjectHandles = false;
                    obj.ObjectHandlesOpened = false;
                }
                else if (obj.UseObjectHandles)
                {
                    obj.ObjectHandlesOpened = false;
                    obj.UseObjectHandles    = false;
                }

                //ref var weak = ref _renderList[_renderListCount];

                //if (weak == null)
                //    weak = new WeakReference<GameObject>(obj);
                //else
                //    weak.SetTarget(obj);

                _renderList[_renderListCount] = obj;
                //_renderList.Enqueue(obj);
                //obj.UseInRender = (byte) _renderIndex;
                _renderListCount++;
            }
        }
Esempio n. 14
0
        public override bool Draw(UltimaBatcher2D batcher, int posX, int posY, float depth)
        {
            if (!AllowedToDraw || IsDestroyed)
            {
                return(false);
            }

            ushort graphic = Graphic;
            ushort hue     = Hue;
            bool   partial = ItemData.IsPartialHue;

            if (ProfileManager.CurrentProfile.HighlightGameObjects && SelectedObject.LastObject == this)
            {
                hue     = Constants.HIGHLIGHT_CURRENT_OBJECT_HUE;
                partial = false;
            }
            else if (ProfileManager.CurrentProfile.NoColorObjectsOutOfRange && Distance > World.ClientViewRange)
            {
                hue     = Constants.OUT_RANGE_COLOR;
                partial = false;
            }
            else if (World.Player.IsDead && ProfileManager.CurrentProfile.EnableBlackWhiteEffect)
            {
                hue     = Constants.DEAD_RANGE_COLOR;
                partial = false;
            }

            Vector3 hueVec = ShaderHueTranslator.GetHueVector(hue, partial, AlphaHue / 255f);

            bool isTree = StaticFilters.IsTree(graphic, out _);

            if (isTree && ProfileManager.CurrentProfile.TreeToStumps)
            {
                graphic = Constants.TREE_REPLACE_GRAPHIC;
            }

            DrawStaticAnimated
            (
                batcher,
                graphic,
                posX,
                posY,
                hueVec,
                ProfileManager.CurrentProfile.ShadowsEnabled && ProfileManager.CurrentProfile.ShadowsStatics && (isTree || ItemData.IsFoliage || StaticFilters.IsRock(graphic)),
                depth
            );

            if (ItemData.IsLight)
            {
                Client.Game.GetScene <GameScene>().AddLight(this, this, posX + 22, posY + 22);
            }

            return(true);
        }