Exemplo n.º 1
0
        private static void OnProperties(PacketReader reader)
        {
            reader.Seek(2, SeekOrigin.Current);   // word 1

            int serial = reader.ReadInt32();

            reader.Seek(2, SeekOrigin.Current);   // word 0

            int hash = reader.ReadInt32();

            List <Property> list = new List <Property>();

            int    cliloc;
            bool   first = true;
            string name  = "";

            while ((cliloc = reader.ReadInt32()) != 0)
            {
                Property property = new Property {
                    Cliloc = cliloc
                };

                int length = reader.ReadInt16();

                property.Arguments = reader.ReadUnicodeString(length)
                                     .Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

                property.Text = Cliloc.GetLocalString(cliloc, property.Arguments);

                if (first)
                {
                    name  = property.Text;
                    first = false;
                }

                list.Add(property);
            }

            if (Engine.Player?.Serial == serial)
            {
                Engine.Player.Name       = name;
                Engine.Player.Properties = list.ToArray();
                Engine.UpdateWindowTitle();
            }
            else if (UOMath.IsMobile(serial))
            {
                Mobile mobile = Engine.GetOrCreateMobile(serial);

                mobile.Name       = name;
                mobile.Properties = list.ToArray();
            }
            else
            {
                Item item = Engine.GetOrCreateItem(serial);

                item.Name       = name;
                item.Properties = list.ToArray();
            }
        }
Exemplo n.º 2
0
        private string ReadProperties(Entity obj, out string htmltext)
        {
            _sb.Clear();
            _sbHTML.Clear();

            bool hasStartColor = false;

            for (int i = 0; i < obj.Properties.Count; i++)
            {
                Property property = obj.Properties[i];

                if (property.Cliloc <= 0)
                {
                    continue;
                }

                if (i == 0 /*&& !string.IsNullOrEmpty(obj.Name)*/)
                {
                    if (obj.Serial.IsMobile)
                    {
                        Mobile mobile = (Mobile)obj;
                        //ushort hue = Notoriety.GetHue(mobile.NotorietyFlag);
                        _sbHTML.Append(Notoriety.GetHTMLHue(mobile.NotorietyFlag));
                    }
                    else
                    {
                        _sbHTML.Append("<basefont color=\"yellow\">");
                    }

                    hasStartColor = true;
                }

                string text = Cliloc.Translate((int)property.Cliloc, property.Args, true);

                if (string.IsNullOrEmpty(text))
                {
                    continue;
                }
                _sb.Append(text);
                _sbHTML.Append(text);

                if (hasStartColor)
                {
                    _sbHTML.Append("<basefont color=\"#FFFFFFFF\">");
                    hasStartColor = false;
                }

                if (i < obj.Properties.Count - 1)
                {
                    _sb.Append("\n");
                    _sbHTML.Append("\n");
                }
            }

            htmltext = _sbHTML.ToString();
            string result = _sb.ToString();

            return(string.IsNullOrEmpty(result) ? null : result);
        }
Exemplo n.º 3
0
        public void WillFilterLocalizedText()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            byte[] packet =
            {
                0xC1, 0x00, 0x32, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x07,
                0xA1, 0x96, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00
            };

            int length = packet.Length;

            const int    cliloc      = 500118;
            const string replaceText = "The quick brown fox jumped over the lazy dog.";

            AutoResetEvent are = new AutoResetEvent(false);

            void OnReceivedEvent(byte[] data, int _)
            {
                if (data[0] != 0xAE)
                {
                    Assert.Fail();
                }

                string text = Encoding.BigEndianUnicode.GetString(data, 48, data.Length - 48);

                if (text != replaceText)
                {
                    Assert.Fail();
                }

                are.Set();
            }

            Engine.InternalPacketReceivedEvent += OnReceivedEvent;

            ClilocFilter.IsEnabled = true;
            ClilocFilter.Filters.Add(cliloc, replaceText);

            IncomingPacketFilters.Initialize();
            IncomingPacketFilters.CheckPacket(ref packet, ref length);

            bool result = are.WaitOne(5000);

            Assert.IsTrue(result);

            Engine.InternalPacketReceivedEvent -= OnReceivedEvent;
        }
Exemplo n.º 4
0
        public void WillFilterLocalizedTextAffix()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            byte[] packet =
            {
                0xCC, 0x00, 0x36, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x06, 0x03, 0xB2, 0x00, 0x03, 0x00, 0x0F,
                0x62, 0x1E, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x31, 0x34, 0x00, 0x00, 0x00
            };

            int length = packet.Length;

            const int    cliloc      = 1008158;
            const string replaceText = "The value is: ";

            AutoResetEvent are = new AutoResetEvent(false);

            void OnReceivedEvent(byte[] data, int _)
            {
                if (data[0] != 0xAE)
                {
                    Assert.Fail();
                }

                string text = Encoding.BigEndianUnicode.GetString(data, 48, data.Length - 48);

                if (!text.StartsWith(replaceText))
                {
                    Assert.Fail();
                }

                are.Set();
            }

            Engine.InternalPacketReceivedEvent += OnReceivedEvent;

            ClilocFilter.IsEnabled = true;
            ClilocFilter.Filters.Add(cliloc, replaceText);

            IncomingPacketFilters.Initialize();
            IncomingPacketFilters.CheckPacket(ref packet, ref length);

            bool result = are.WaitOne(5000);

            Assert.IsTrue(result);

            Engine.InternalPacketReceivedEvent -= OnReceivedEvent;
        }
Exemplo n.º 5
0
        private LoadingGump GetLoadingScreen()
        {
            var labelText   = "No Text";
            var showButtons = LoadingGump.Buttons.None;

            if (!loginScene.LoginRejectionReason.HasValue)
            {
                switch (loginScene.CurrentLoginStep)
                {
                case LoginScene.LoginStep.Connecting:
                    labelText = Cliloc.GetString(3000002);     // "Connecting..."
                    break;

                case LoginScene.LoginStep.VerifyingAccount:
                    labelText = Cliloc.GetString(3000003);     // "Verifying Account..."
                    break;

                case LoginScene.LoginStep.LoginInToServer:
                    labelText = Cliloc.GetString(3000053);     // logging into shard
                    break;

                case LoginScene.LoginStep.EnteringBritania:
                    labelText = Cliloc.GetString(3000001);     // Entering Britania...
                    break;
                }
            }
            else
            {
                switch (loginScene.LoginRejectionReason.Value)
                {
                case LoginScene.LoginRejectionReasons.BadPassword:
                case LoginScene.LoginRejectionReasons.InvalidAccountPassword:
                    labelText = Cliloc.GetString(3000036);     // Incorrect username and/or password.
                    break;

                case LoginScene.LoginRejectionReasons.AccountInUse:
                    labelText = Cliloc.GetString(3000034);     // Someone is already using this account.
                    break;

                case LoginScene.LoginRejectionReasons.AccountBlocked:
                    labelText = Cliloc.GetString(3000035);     // Your account has been blocked / banned
                    break;

                case LoginScene.LoginRejectionReasons.IdleExceeded:
                    labelText = Cliloc.GetString(3000004);     // Login idle period exceeded (I use "Connection lost")
                    break;

                case LoginScene.LoginRejectionReasons.BadCommuncation:
                    labelText = Cliloc.GetString(3000037);     // Communication problem.
                    break;
                }

                showButtons = LoadingGump.Buttons.OK;
            }

            return(new LoadingGump(labelText, showButtons, OnLoadingGumpButtonClick));
        }
 public PropertySelectionViewModel(IEnumerable <Property> properties)
 {
     foreach (Property property in properties)
     {
         Properties.Add(new SelectProperties
         {
             Name = Cliloc.GetProperty(property.Cliloc), Property = property, Selected = false
         });
     }
 }
Exemplo n.º 7
0
        internal static bool Initialize(MainWindow mainWindow)
        {
            if (File.Exists(Path.Combine(StartupPath, "Updater_New.exe")))
            {
                try
                {
                    File.Copy(Path.Combine(StartupPath, "Updater_New.exe"), Path.Combine(StartupPath, "Updater.exe"), true);
                }
                catch (Exception)
                {
                }
            }

            string[] renameFiles = Directory.GetFiles(StartupPath, "*.new", SearchOption.AllDirectories);
            foreach (string renameFile in renameFiles)
            {
                string path     = Path.GetDirectoryName(renameFile);
                string origFile = Path.Combine(path, Path.GetFileNameWithoutExtension(renameFile));
                try
                {
                    File.Delete(origFile);
                    File.Move(renameFile, origFile);
                }
                catch (Exception)
                {
                }
            }

            if (!MainWindow.CurrentOptions.IsValid())
            {
                return(false);
            }
            //try { Config.Register( "UOM hooks", Path.Combine( StartupPath, "UOMachine.exe" ), Path.Combine( StartupPath, "ClientHook.dll" ) ); }
            //catch (Exception ex)
            //{
            //    Utility.Log.LogMessage( ex );
            //    /* Ensure EasyHook files are in output directory if you get this error */
            //    System.Windows.MessageBox.Show( Strings.ErrorwithGACinstallation );
            //    return false;
            //}
            myMainWindow = mainWindow;
            InternalEventHandler.IncomingPacketHandler.Initialize();
            InternalEventHandler.OutgoingPacketHandler.Initialize();
            Network.Initialize();
            InternalEventHandler.IPCHandler.Initialize();
            mySkillNames = Skills.GetSkills(MainWindow.CurrentOptions.UOFolder);
            TileData.Initialize(MainWindow.CurrentOptions.UOFolder);
            Map.Initialize(MainWindow.CurrentOptions.UOFolder, MainWindow.CurrentOptions.CacheLevel);
            Art.Initialize(MainWindow.CurrentOptions.UOFolder);
            Cliloc.Initialize(MainWindow.CurrentOptions.UOFolder);
            NamespaceToAssembly.Initialize();
            IncomingPacketHandlers.Initialize();
            OutgoingPacketHandlers.Initialize();
            return(true);
        }
        private bool ValidateCharacter(PlayerMobile character)
        {
            if (string.IsNullOrEmpty(character.Name))
            {
                Service.Get <CharCreationGump>().ShowMessage(Cliloc.GetString(3000612));

                return(false);
            }

            return(true);
        }
Exemplo n.º 9
0
        public ClilocSelectionViewModel()
        {
            foreach (KeyValuePair <int, string> kvp in Cliloc.GetItems())
            {
                AllClilocs.Add(new ClilocEntry {
                    Key = kvp.Key, Value = kvp.Value
                });
            }

            UpdateEntries(_filterText);
        }
Exemplo n.º 10
0
        internal static unsafe void InitializePlugin(PluginHeader *plugin)
        {
            _onConnected             = OnConnected;
            _onDisconnected          = OnDisconnected;
            _onReceive               = OnPacketReceive;
            _onSend                  = OnPacketSend;
            _onPlayerPositionChanged = OnPlayerPositionChanged;
            _onClientClosing         = OnClientClosing;
            _onHotkeyPressed         = OnHotkeyPressed;
            _onMouse                 = OnMouse;
            _onTick                  = OnTick;
            WindowHandle             = plugin->HWND;

            plugin->OnConnected             = Marshal.GetFunctionPointerForDelegate(_onConnected);
            plugin->OnDisconnected          = Marshal.GetFunctionPointerForDelegate(_onDisconnected);
            plugin->OnRecv                  = Marshal.GetFunctionPointerForDelegate(_onReceive);
            plugin->OnSend                  = Marshal.GetFunctionPointerForDelegate(_onSend);
            plugin->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onPlayerPositionChanged);
            plugin->OnClientClosing         = Marshal.GetFunctionPointerForDelegate(_onClientClosing);
            plugin->OnHotkeyPressed         = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed);
            plugin->OnMouse                 = Marshal.GetFunctionPointerForDelegate(_onMouse);
            plugin->Tick = Marshal.GetFunctionPointerForDelegate(_onTick);

            _getPacketLength = Marshal.GetDelegateForFunctionPointer <OnGetPacketLength>(plugin->GetPacketLength);
            _getUOFilePath   = Marshal.GetDelegateForFunctionPointer <OnGetUOFilePath>(plugin->GetUOFilePath);
            _sendToClient    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Recv);
            _sendToServer    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Send);
            _requestMove     = Marshal.GetDelegateForFunctionPointer <RequestMove>(plugin->RequestMove);
            _setTitle        = Marshal.GetDelegateForFunctionPointer <OnSetTitle>(plugin->SetTitle);

            ClientPath    = _getUOFilePath();
            ClientVersion = new Version((byte)(plugin->ClientVersion >> 24), (byte)(plugin->ClientVersion >> 16),
                                        (byte)(plugin->ClientVersion >> 8), (byte)plugin->ClientVersion);

            if (!Path.IsPathRooted(ClientPath))
            {
                ClientPath = Path.GetFullPath(ClientPath);
            }

            Art.Initialize(ClientPath);
            Hues.Initialize(ClientPath);
            Cliloc.Initialize(ClientPath);
            Skills.Initialize(ClientPath);
            Speech.Initialize(ClientPath);
            TileData.Initialize(ClientPath);
            Statics.Initialize(ClientPath);
            MapInfo.Initialize(ClientPath);

            ClassicAssembly = AppDomain.CurrentDomain.GetAssemblies()
                              .FirstOrDefault(a => a.FullName.StartsWith("ClassicUO,"));

            InitializeExtensions();
        }
Exemplo n.º 11
0
        public void ClilocTest70450()
        {
            string path = @"D:\Clients\7.0.45.0";

            Cliloc.Initialize(path);
            string cliloc = Cliloc.GetProperty(1061638);

            Assert.AreEqual(cliloc, "A House Sign");
            string clilocParam = Cliloc.GetLocalString(1062028, new string[] { "This structure is slightly worn." });

            Assert.AreEqual(clilocParam, "Condition: This structure is slightly worn.");
        }
Exemplo n.º 12
0
        private bool ValidateValues()
        {
            var duplicated = _skills.Where(o => o.SelectedIndex != -1).GroupBy(o => o.SelectedIndex).Where(o => o.Count() > 1).Count();

            if (duplicated > 0)
            {
                Service.Get <CharCreationGump>().ShowMessage(Cliloc.GetString(1080032));

                return(false);
            }

            return(true);
        }
        public ClilocFilterConfigureViewModel()
        {
            foreach ( KeyValuePair<int, string> kvp in Cliloc.GetItems() )
            {
                AllClilocs.Add( new ClilocEntry { Key = kvp.Key, Value = kvp.Value } );
            }

            foreach ( KeyValuePair<int, string> filterFilter in ClilocFilter.Filters )
            {
                Items.Add( new FilterClilocEntry { Cliloc = filterFilter.Key, Replacement = filterFilter.Value } );
            }

            UpdateEntries( _filterText );
        }
        private static bool OnLocalizedMessageAffix(ref byte[] packet, ref int length)
        {
            PacketReader reader = new PacketReader(packet, length, false);

            int              serial      = reader.ReadInt32();
            int              graphic     = reader.ReadInt16();
            JournalSpeech    messageType = (JournalSpeech)reader.ReadByte();
            int              hue         = reader.ReadInt16();
            int              font        = reader.ReadInt16();
            int              cliloc      = reader.ReadInt32();
            MessageAffixType affixType   = (MessageAffixType)reader.ReadByte();
            string           name        = reader.ReadString(30);
            string           affix       = reader.ReadString();

            string[] arguments = reader.ReadUnicodeString()
                                 .Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

            JournalEntry journalEntry = new JournalEntry
            {
                Serial     = serial,
                ID         = graphic,
                SpeechType = messageType,
                SpeechHue  = hue,
                SpeechFont = font,
                Cliloc     = cliloc,
                Name       = name,
                Arguments  = arguments
            };

            string text = Cliloc.GetLocalString(journalEntry.Cliloc, journalEntry.Arguments);

            if (affixType.HasFlag(MessageAffixType.Prepend))
            {
                journalEntry.Text = $"{affix}{text}";
            }
            else if (affixType.HasFlag(MessageAffixType.Append))
            {
                journalEntry.Text = $"{text}{affix}";
            }

            bool block = RepeatedMessagesFilter.CheckMessage(journalEntry);

            if (block && RepeatedMessagesFilter.FilterOptions.SendToJournal)
            {
                IncomingPacketHandlers.AddToJournal(journalEntry);
            }

            return(block || ClilocFilter.CheckMessageAffix(journalEntry, affixType, affix));
        }
Exemplo n.º 15
0
        public void WillParseAuctionSafeGump()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            const string layout =
                "{ resizepic 0 0 9300 400 600 }{ xmfhtmltok 10 10 400 18 0 0 22660 1114513 @Heritage Raffle@ }{ xmfhtmltok 0 70 198 18 0 0 22660 1114514 @Can Buy Unlimited Tickets:@ }{ htmlgump 202 70 200 18 0 0 0 }{ xmfhtmltok 0 100 198 18 0 0 22660 1114514 @Currency Type:@ }{ htmlgump 202 100 200 18 1 0 0 }{ xmfhtmltok 0 130 198 18 0 0 22660 1114514 @Ticket Price:@ }{ htmlgump 202 130 200 18 2 0 0 }{ xmfhtmltok 0 160 198 18 0 0 22660 1114514 @Tickets Bought:@ }{ htmlgump 202 160 200 18 3 0 0 }{ xmfhtmltok 0 190 200 18 0 0 22660 1114514 @Odds of Winning:@ }{ htmlgump 202 190 200 18 4 0 0 }{ xmfhtmltok 0 220 198 18 0 0 22660 1114514 @Raffled Item:@ }{ xmfhtmltok 202 220 200 20 0 0 16 1114779 @The Lucky Sovereign Steed@ }{ tilepichue 90 314 8413 1152 }{ itemproperty 1074292781 }{ xmfhtmltok 200 243 200 18 0 0 22660 1154645 @Raffled Item Description:@ }{ htmlgump 202 263 197 140 5 1 1 }{ xmfhtmltok 0 450 198 18 0 0 22660 1114514 @Raffle Ticket Amount@ }{ resizepic 202 450 9350 193 22 }{ textentry 204 450 192 20 0 0 6 }{ button 168 480 4005 4007 1 0 1 }{ htmlgump 202 480 198 18 7 0 0 }{ xmfhtmltok 0 530 198 18 0 0 22660 1114514 @Raffle Ends:@ }{ htmlgump 202 530 198 18 8 0 0 }{ button 360 570 4020 4022 1 0 0 }{ xmfhtmltok 250 570 100 20 0 0 0 1114514 @#1060675@ }";

            Gump gump = GumpParser.Parse(0x01, 0x01, 1, 1, layout,
                                         new[] { "unknown", "unknown", "unknown", "unknown", "unknown", "unknown", "", "", "" });
        }
            public CustomColorPicker(Layer layer, int label, ushort[] pallet, int rows, int columns)
            {
                Width    = 121;
                Height   = 25;
                _cellW   = 125 / columns;
                _cellH   = 280 / rows;
                _columns = columns;
                _layer   = layer;

                AddChildren(new Label(Cliloc.GetString(label), false, 0x07F4, font: 9)
                {
                    X = 0, Y = 0
                });
                AddChildren(_colorPicker   = new ColorPickerBox(1, 15, 1, 1, 121, 23, pallet));
                _colorPicker.MouseClick   += ColorPicker_MouseClick;
                _colorPickerBox            = new ColorPickerBox(489, 141, rows, columns, _cellW, _cellH, pallet);
                _colorPickerBox.MouseOver += _colorPicker_MouseMove;
            }
        public void WillGetPropertyValue()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            byte[] packet =
            {
                0xD6, 0x00, 0x43, 0x00, 0x01, 0x40, 0xC5, 0xF6, 0x09, 0x00, 0x00, 0x02, 0xA0, 0x3B, 0xCF, 0x00,
                0x0F, 0x9E, 0xD5, 0x00, 0x00, 0x00, 0x10, 0x5E, 0x95, 0x00, 0x04, 0x37, 0x00, 0x34, 0x00, 0x00,
                0x10, 0x5C, 0x71, 0x00, 0x1A, 0x34, 0x00, 0x39, 0x00, 0x09, 0x00, 0x31, 0x00, 0x32, 0x00, 0x35,
                0x00, 0x09, 0x00, 0x37, 0x00, 0x31, 0x00, 0x09, 0x00, 0x35, 0x00, 0x35, 0x00, 0x30, 0x00, 0x00,
                0x00, 0x00, 0x00
            };

            Item item = new Item(0x40c5f609);

            Engine.Items.Add(item);

            IncomingPacketHandlers.Initialize();

            PacketHandler handler = IncomingPacketHandlers.GetHandler(0xD6);

            handler.OnReceive(new PacketReader(packet, packet.Length, false));

            Assert.IsNotNull(item.Properties);

            int value = PropertiesCommands.PropertyValue <int>(item.Serial, "Contents");

            Assert.AreEqual(49, value);

            value = PropertiesCommands.PropertyValue <int>(item.Serial, "Contents", 2);

            Assert.AreEqual(71, value);

            Engine.Items.Clear();
        }
Exemplo n.º 18
0
        public void WillParseXmfHtmlTokString()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            const string layout = "{ xmfhtmltok 10 10 400 18 0 0 22660 1114513 @Heritage Raffle@ }";

            Gump gump = GumpParser.Parse(0x01, 0x01, 1, 1, layout, new string[] { });

            GumpElement ge = gump.GetElementByXY(10, 10);

            Assert.AreEqual("<DIV ALIGN=CENTER>Heritage Raffle</DIV>", ge.Text);
        }
Exemplo n.º 19
0
        public void WillParseXmfHtmlTokCliloc()
        {
            const string localPath = @"C:\Users\johns\Desktop\KvG Client 2.0";

            if (!Directory.Exists(localPath))
            {
                Debug.WriteLine("Not running test, requires Cliloc.enu");
                return;
            }

            Cliloc.Initialize(localPath);

            const string layout = "{ xmfhtmltok 250 570 100 20 0 0 0 1114514 @#1060675@ }";

            Gump gump = GumpParser.Parse(0x01, 0x01, 1, 1, layout, new string[] { });

            GumpElement ge = gump.GetElementByXY(250, 570);

            Assert.AreEqual("<DIV ALIGN=RIGHT>CLOSE</DIV>", ge.Text);
        }
Exemplo n.º 20
0
        private static void OnLocalizedTextAffix(PacketReader reader)
        {
            int              serial      = reader.ReadInt32();
            int              graphic     = reader.ReadInt16();
            JournalSpeech    messageType = (JournalSpeech)reader.ReadByte();
            int              hue         = reader.ReadInt16();
            int              font        = reader.ReadInt16();
            int              cliloc      = reader.ReadInt32();
            MessageAffixType affixType   = (MessageAffixType)reader.ReadByte();
            string           name        = reader.ReadString(30);
            string           affix       = reader.ReadString();

            string[] arguments = reader.ReadUnicodeString()
                                 .Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);

            JournalEntry journalEntry = new JournalEntry
            {
                Serial     = serial,
                ID         = graphic,
                SpeechType = messageType,
                SpeechHue  = hue,
                SpeechFont = font,
                Cliloc     = cliloc,
                Name       = name,
                Arguments  = arguments
            };

            string text = Cliloc.GetLocalString(journalEntry.Cliloc, journalEntry.Arguments);

            if (affixType.HasFlag(MessageAffixType.Prepend))
            {
                journalEntry.Text = $"{affix}{text}";
            }
            else if (affixType.HasFlag(MessageAffixType.Append))
            {
                journalEntry.Text = $"{text}{affix}";
            }

            Engine.Journal.Write(journalEntry);
            JournalEntryAddedEvent?.Invoke(journalEntry);
        }
Exemplo n.º 21
0
        internal static unsafe void InitializePlugin(PluginHeader *plugin)
        {
            _onConnected             = OnConnected;
            _onDisconnected          = OnDisconnected;
            _onReceive               = OnPacketReceive;
            _onSend                  = OnPacketSend;
            _onPlayerPositionChanged = OnPlayerPositionChanged;
            _onClientClosing         = OnClientClosing;
            _onHotkeyPressed         = OnHotkeyPressed;
            _onMouse                 = OnMouse;
            _hWnd = plugin->HWND;

            plugin->OnConnected             = Marshal.GetFunctionPointerForDelegate(_onConnected);
            plugin->OnDisconnected          = Marshal.GetFunctionPointerForDelegate(_onDisconnected);
            plugin->OnRecv                  = Marshal.GetFunctionPointerForDelegate(_onReceive);
            plugin->OnSend                  = Marshal.GetFunctionPointerForDelegate(_onSend);
            plugin->OnPlayerPositionChanged = Marshal.GetFunctionPointerForDelegate(_onPlayerPositionChanged);
            plugin->OnClientClosing         = Marshal.GetFunctionPointerForDelegate(_onClientClosing);
            plugin->OnHotkeyPressed         = Marshal.GetFunctionPointerForDelegate(_onHotkeyPressed);
            plugin->OnMouse                 = Marshal.GetFunctionPointerForDelegate(_onMouse);

            _getPacketLength = Marshal.GetDelegateForFunctionPointer <OnGetPacketLength>(plugin->GetPacketLength);
            _getUOFilePath   = Marshal.GetDelegateForFunctionPointer <OnGetUOFilePath>(plugin->GetUOFilePath);
            _sendToClient    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Recv);
            _sendToServer    = Marshal.GetDelegateForFunctionPointer <OnPacketSendRecv>(plugin->Send);
            _requestMove     = Marshal.GetDelegateForFunctionPointer <RequestMove>(plugin->RequestMove);

            ClientPath = _getUOFilePath();

            if (!Path.IsPathRooted(ClientPath))
            {
                ClientPath = Path.GetFullPath(ClientPath);
            }

            Art.Initialize(ClientPath);
            Hues.Initialize(ClientPath);
            Cliloc.Initialize(ClientPath);
            Skills.Initialize(ClientPath);
            Speech.Initialize(ClientPath);
            TileData.Initialize(ClientPath);
        }
Exemplo n.º 22
0
 private void OnClickAdd(object sender, EventArgs e)
 {
     if (int.TryParse(NumberBox.Text, System.Globalization.NumberStyles.Integer, null, out int number))
     {
         if (Cliloc.IsNumberFree(number))
         {
             Cliloc.AddEntry(number);
             Close();
         }
         else
         {
             MessageBox.Show("Number not free.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                             MessageBoxDefaultButton.Button1);
         }
     }
     else
     {
         MessageBox.Show("Error reading Number", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error,
                         MessageBoxDefaultButton.Button1);
     }
 }
Exemplo n.º 23
0
        private static bool OnLocalizedMessage(byte[] packet, int length)
        {
            PacketReader reader = new PacketReader(packet, length, false);

            JournalEntry journalEntry = new JournalEntry
            {
                Serial     = reader.ReadInt32(),
                ID         = reader.ReadInt16(),
                SpeechType = (JournalSpeech)reader.ReadByte(),
                SpeechHue  = reader.ReadInt16(),
                SpeechFont = reader.ReadInt16(),
                Cliloc     = reader.ReadInt32(),
                Name       = reader.ReadString(30),
                Arguments  = reader.ReadUnicodeString((int)reader.Size - 50).Split('\t')
            };

            journalEntry.Text = Cliloc.GetLocalString(journalEntry.Cliloc, journalEntry.Arguments);

            bool block = RepeatedMessagesFilter.CheckMessage(journalEntry);

            return(block || ClilocFilter.CheckMessage(journalEntry));
        }
Exemplo n.º 24
0
        public static void UpdateProperties(int index, int serial, string name, Property[] properties, string propertyText)
        {
            ClientInfo ci;

            if (GetClient(index, out ci))
            {
                if (UOMath.IsMobile(serial))
                {
                    if (ci.Player.Serial == serial)
                    {
                        ci.Player.Name         = name;
                        ci.Player.Properties   = properties;
                        ci.Player.PropertyText = propertyText;
                        TreeViewUpdater.EditPlayerNode(index, ClientList[index].Player);
                    }
                    else
                    {
                        Mobile m;
                        if (ci.Mobiles.GetMobile(serial, out m))
                        {
                            m.Name         = name;
                            m.Properties   = properties;
                            m.PropertyText = propertyText;
                        }
                    }
                }
                else
                {
                    Item i;
                    if (ci.Items.GetItem(serial, out i))
                    {
                        i.Name         = Cliloc.GetLocalString(name);
                        i.Properties   = properties;
                        i.PropertyText = propertyText;
                    }
                }
            }
        }
Exemplo n.º 25
0
        private static void OnLocalizedText(PacketReader reader)
        {
            JournalEntry journalEntry = new JournalEntry
            {
                Serial     = reader.ReadInt32(),
                ID         = reader.ReadInt16(),
                SpeechType = (JournalSpeech)reader.ReadByte(),
                SpeechHue  = reader.ReadInt16(),
                SpeechFont = reader.ReadInt16(),
                Cliloc     = reader.ReadInt32(),
                Name       = reader.ReadString(30),
                Arguments  = reader.ReadUnicodeString((int)reader.Size - 50)
                             .Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)
            };

            journalEntry.Text = Cliloc.GetLocalString(journalEntry.Cliloc, journalEntry.Arguments);

            if (journalEntry.SpeechType == JournalSpeech.Label)
            {
                if (Engine.Player?.LastTargetSerial == journalEntry.Serial)
                {
                    MsgCommands.HeadMsg(Options.CurrentOptions.LastTargetMessage, journalEntry.Serial);
                }

                if (Engine.Player?.EnemyTargetSerial == journalEntry.Serial)
                {
                    MsgCommands.HeadMsg(Options.CurrentOptions.EnemyTargetMessage, journalEntry.Serial);
                }

                if (Engine.Player?.FriendTargetSerial == journalEntry.Serial)
                {
                    MsgCommands.HeadMsg(Options.CurrentOptions.FriendTargetMessage, journalEntry.Serial);
                }
            }

            Engine.Journal.Write(journalEntry);
            JournalEntryAddedEvent?.Invoke(journalEntry);
        }
Exemplo n.º 26
0
 private void OnClickSave(object sender, EventArgs e)
 {
     Cliloc.SaveEntry(_number, TextBox.Text);
 }
Exemplo n.º 27
0
        public CharacterSelectionGump() : base(0, 0)
        {
            bool testField  = FileManager.ClientVersion >= ClientVersions.CV_305D;
            int  posInList  = 0;
            int  yOffset    = 150;
            int  yBonus     = 0;
            int  listTitleY = 106;

            if (FileManager.ClientVersion >= ClientVersions.CV_6040)
            {
                listTitleY = 96;
                yOffset    = 125;
                yBonus     = 45;
            }

            LoginScene loginScene   = Engine.SceneManager.GetScene <LoginScene>();
            var        lastSelected = loginScene.Characters.FirstOrDefault(o => o == Service.Get <Settings>().LastCharacterName);

            if (lastSelected != null)
            {
                _selectedCharacter = (uint)Array.IndexOf(loginScene.Characters, lastSelected);
            }
            else if (loginScene.Characters.Length > 0)
            {
                _selectedCharacter = 0;
            }

            AddChildren(new ResizePic(0x0A28)
            {
                X = 160, Y = 70, Width = 408, Height = 343 + yBonus
            }, 1);

            AddChildren(new Label(Cliloc.GetString(3000050), false, 0x0386, font: 2)
            {
                X = 267, Y = listTitleY
            }, 1);

            for (int i = 0; i < loginScene.Characters.Length; i++)
            {
                string character = loginScene.Characters[i];

                if (!string.IsNullOrEmpty(character))
                {
                    AddChildren(new CharacterEntryGump((uint)i, character, SelectCharacter, LoginCharacter)
                    {
                        X   = 224,
                        Y   = yOffset + posInList * 40,
                        Hue = posInList == _selectedCharacter ? SELECTED_COLOR : NORMAL_COLOR
                    }, 1);
                    posInList++;
                }
            }

            if (loginScene.Characters.Any(string.IsNullOrEmpty))
            {
                AddChildren(new Button((int)Buttons.New, 0x159D, 0x159F, 0x159E)
                {
                    X = 224, Y = 350 + yBonus, ButtonAction = ButtonAction.Activate
                }, 1);
            }

            AddChildren(new Button((int)Buttons.Delete, 0x159A, 0x159C, 0x159B)
            {
                X = 442, Y = 350 + yBonus, ButtonAction = ButtonAction.Activate
            }, 1);

            AddChildren(new Button((int)Buttons.Prev, 0x15A1, 0x15A3, 0x15A2)
            {
                X = 586, Y = 445, ButtonAction = ButtonAction.Activate
            }, 1);

            AddChildren(new Button((int)Buttons.Next, 0x15A4, 0x15A6, 0x15A5)
            {
                X = 610, Y = 445, ButtonAction = ButtonAction.Activate
            }, 1);
            ChangePage(1);
        }
Exemplo n.º 28
0
        public ServerSelectionGump() : base(0, 0)
        {
            AddChildren(new Button((int)Buttons.Prev, 0x15A1, 0x15A3, 0x15A2)
            {
                X = 586, Y = 445, ButtonAction = ButtonAction.Activate
            });
            AddChildren(new Button((int)Buttons.Next, 0x15A4, 0x15A6, 0x15A5)
            {
                X = 610, Y = 445, ButtonAction = ButtonAction.Activate
            });

            if (FileManager.ClientVersion >= ClientVersions.CV_500A)
            {
                ushort textColor = 0xFFFF;
                AddChildren(new Label(Cliloc.GetString(1044579), true, textColor, font: 1)
                {
                    X = 155, Y = 70
                });                                                                                            // "Select which shard to play on:"
                AddChildren(new Label(Cliloc.GetString(1044577), true, textColor, font: 1)
                {
                    X = 400, Y = 70
                });                                                                                            // "Latency:"
                AddChildren(new Label(Cliloc.GetString(1044578), true, textColor, font: 1)
                {
                    X = 470, Y = 70
                });                                                                                            // "Packet Loss:"
                AddChildren(new Label(Cliloc.GetString(1044580), true, textColor, font: 1)
                {
                    X = 153, Y = 368
                });                                                                                             // "Sort by:"
            }
            else
            {
                ushort textColor = 0x0481;
                AddChildren(new Label("Select which shard to play on:", true, textColor, font: 9)
                {
                    X = 155, Y = 70
                });
                AddChildren(new Label("Latency:", true, textColor, font: 9)
                {
                    X = 400, Y = 70
                });
                AddChildren(new Label("Packet Loss:", true, textColor, font: 9)
                {
                    X = 470, Y = 70
                });
                AddChildren(new Label("Sort by:", true, textColor, font: 9)
                {
                    X = 153, Y = 368
                });
            }

            AddChildren(new Button((int)Buttons.SortTimeZone, 0x093B, 0x093C, 0x093D)
            {
                X = 230, Y = 366
            });
            AddChildren(new Button((int)Buttons.SortFull, 0x093E, 0x093F, 0x0940)
            {
                X = 338, Y = 366
            });
            AddChildren(new Button((int)Buttons.SortConnection, 0x0941, 0x0942, 0x0943)
            {
                X = 446, Y = 366
            });

            // World Pic Bg
            AddChildren(new GumpPic(150, 390, 0x0589, 0));
            // Earth
            AddChildren(new Button((int)Buttons.Earth, 0x15E8, 0x15EA, 0x15E9)
            {
                X = 160, Y = 400
            });

            // Sever Scroll Area Bg
            AddChildren(new ResizePic(0x0DAC)
            {
                X = 150, Y = 90, Width = 393 - 14, Height = 271
            });
            // Sever Scroll Area
            ScrollArea scrollArea = new ScrollArea(150, 90, 393, 271, true);
            LoginScene loginScene = Service.Get <LoginScene>();

            foreach (ServerListEntry server in loginScene.Servers)
            {
                scrollArea.AddChildren(new ServerEntryGump(server));
            }
            AddChildren(scrollArea);

            if (loginScene.Servers.Count() > 0)
            {
                if (loginScene.Servers.Last().Index < loginScene.Servers.Count())
                {
                    AddChildren(new Label(loginScene.Servers.Last().Name, false, 0x0481, font: 9)
                    {
                        X = 243, Y = 420
                    });
                }
                else
                {
                    AddChildren(new Label(loginScene.Servers.First().Name, false, 0x0481, font: 9)
                    {
                        X = 243, Y = 420
                    });
                }
            }
        }
Exemplo n.º 29
0
        public static Gump Parse(int serial, uint ID, int x, int y, string layout, string[] text)
        {
            bool closable = true, movable = true, disposable = true, resizable = true;

            List <GumpPage>    pageList        = new List <GumpPage>();
            List <GumpElement> gumpElementList = new List <GumpElement>();
            GumpElement        lastGumpElement = null;
            GumpPage           currentPage     = null;

            if (string.IsNullOrEmpty(layout))
            {
                return(null);
            }

            string[] split = layout.Substring(layout.IndexOf('{')).TrimEnd('}', ' ')
                             .Split(new[] { '}' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < split.Length; i++)
            {
                split[i] = split[i].TrimStart('{', ' ').Trim();
                string[] formatted = split[i].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                for (int j = 0; j < formatted.Length; j++)
                {
                    formatted[j] = formatted[j].Trim();
                }

                switch (formatted[0])
                {
                case "noclose":
                    closable = false;
                    break;

                case "nodispose":
                    disposable = false;
                    break;

                case "nomove":
                    movable = false;
                    break;

                case "noresize":
                    resizable = false;
                    break;

                case "kr_button":
                case "button":
                    try
                    {
                        if (int.TryParse(formatted[1], out int gbX) &&
                            int.TryParse(formatted[2], out int gbY) &&
                            int.TryParse(formatted[3], out int gbNormalID) &&
                            int.TryParse(formatted[4], out int gbPressedID) &&
                            int.TryParse(formatted[5], out int gbType) &&
                            int.TryParse(formatted[6], out int gbParam) &&
                            int.TryParse(formatted[7], out int gbID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.button,
                                ParentPage = currentPage,
                                X          = gbX,
                                Y          = gbY,
                                InactiveID = gbNormalID,
                                ActiveID   = gbPressedID,
                                ElementID  = gbID,
                                ButtonType = gbType,
                                Param      = gbParam
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("button", layout);
                        }
                    }
                    catch
                    {
                        OnError("button", layout);
                    }

                    break;

                case "buttontileart":
                    try
                    {
                        if (int.TryParse(formatted[1], out int btX) &&
                            int.TryParse(formatted[2], out int btY) &&
                            int.TryParse(formatted[3], out int btNormalID) &&
                            int.TryParse(formatted[4], out int btPressedID) &&
                            int.TryParse(formatted[5], out int btType) &&
                            int.TryParse(formatted[6], out int btParam) &&
                            int.TryParse(formatted[7], out int btID) &&
                            int.TryParse(formatted[8], out int btItemID) &&
                            int.TryParse(formatted[9], out int btHue) &&
                            int.TryParse(formatted[10], out int btWidth) &&
                            int.TryParse(formatted[11], out int btHeight))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.buttontileart,
                                ParentPage = currentPage,
                                X          = btX,
                                Y          = btY,
                                ElementID  = btID,
                                ButtonType = btType,
                                Height     = btHeight,
                                Width      = btWidth,
                                Hue        = btHue,
                                ItemID     = btItemID,
                                InactiveID = btNormalID,
                                Param      = btParam,
                                ActiveID   = btPressedID
                            };
                            gumpElementList.Add(ge);
                            lastGumpElement = ge;
                        }
                        else
                        {
                            OnError("buttontileart", layout);
                        }
                    }
                    catch
                    {
                        OnError("buttontileart", layout);
                    }

                    break;

                case "checkertrans":
                    try
                    {
                        if (int.TryParse(formatted[1], out int ctX) &&
                            int.TryParse(formatted[2], out int ctY) &&
                            int.TryParse(formatted[3], out int ctWidth) &&
                            int.TryParse(formatted[4], out int ctHeight))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.checkertrans,
                                ParentPage = currentPage,
                                X          = ctX,
                                Y          = ctY,
                                Width      = ctWidth,
                                Height     = ctHeight
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("checkertrans", layout);
                        }
                    }
                    catch
                    {
                        OnError("checkertrans", layout);
                    }

                    break;

                case "croppedtext":
                    try
                    {
                        if (int.TryParse(formatted[1], out int crX) &&
                            int.TryParse(formatted[2], out int crY) &&
                            int.TryParse(formatted[3], out int crWidth) &&
                            int.TryParse(formatted[4], out int crHeight) &&
                            int.TryParse(formatted[5], out int crHue) &&
                            int.TryParse(formatted[6], out int crText))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.croppedtext,
                                ParentPage = currentPage,
                                X          = crX,
                                Y          = crY,
                                Height     = crHeight,
                                Width      = crWidth,
                                Hue        = crHue,
                                Text       = text[crText]
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("croppedtext", layout);
                        }
                    }
                    catch
                    {
                        OnError("croppedtext", layout);
                    }

                    break;

                case "checkbox":
                    try
                    {
                        if (int.TryParse(formatted[1], out int cbX) &&
                            int.TryParse(formatted[2], out int cbY) &&
                            int.TryParse(formatted[3], out int cbInactiveID) &&
                            int.TryParse(formatted[4], out int cbActiveID) &&
                            int.TryParse(formatted[5], out int cbState) &&
                            int.TryParse(formatted[6], out int cbID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type         = ElementType.checkbox,
                                ParentPage   = currentPage,
                                X            = cbX,
                                Y            = cbY,
                                InactiveID   = cbInactiveID,
                                ActiveID     = cbActiveID,
                                ElementID    = cbID,
                                InitialState = cbState == 1
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("checkbox", layout);
                        }
                    }
                    catch
                    {
                        OnError("checkbox", layout);
                    }

                    break;

                case "page":
                    if (currentPage == null)
                    {
                        currentPage = new GumpPage();
                    }
                    else
                    {
                        currentPage.GumpElements = gumpElementList.ToArray();
                        pageList.Add(currentPage);
                        currentPage     = new GumpPage();
                        gumpElementList = new List <GumpElement>();
                    }

                    if (int.TryParse(formatted[1], out int page))
                    {
                        currentPage.Page = page;
                    }
                    else
                    {
                        OnError("page", layout);
                    }

                    break;

                case "kr_gumppic":
                case "gumppic":
                    try
                    {
                        if (int.TryParse(formatted[1], out int gpX) &&
                            int.TryParse(formatted[2], out int gpY) &&
                            int.TryParse(formatted[3], out int gpID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type = ElementType.gumppic, ParentPage = currentPage
                            };

                            if (formatted.Length > 4)
                            {
                                for (int gp = 4; gp < formatted.Length; gp++)
                                {
                                    if (formatted[gp].Contains("hue"))
                                    {
                                        if (GetInt(formatted[gp], out int gpHue))
                                        {
                                            ge.Hue = gpHue;
                                        }
                                        else
                                        {
                                            OnError("gumppic", layout);
                                        }
                                    }
                                    else
                                    {
                                        ge.Args = formatted[gp];
                                    }
                                }
                            }

                            ge.X         = gpX;
                            ge.Y         = gpY;
                            ge.ElementID = gpID;
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("gumppic", layout);
                        }
                    }
                    catch
                    {
                        OnError("gumppic", layout);
                    }

                    break;

                case "gumppictiled":
                    try
                    {
                        if (int.TryParse(formatted[1], out int gtX) &&
                            int.TryParse(formatted[2], out int gtY) &&
                            int.TryParse(formatted[3], out int gtWidth) &&
                            int.TryParse(formatted[4], out int gtHeight) &&
                            int.TryParse(formatted[5], out int gtID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.gumppictiled,
                                ParentPage = currentPage,
                                X          = gtX,
                                Y          = gtY,
                                Width      = gtWidth,
                                Height     = gtHeight,
                                ElementID  = gtID
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("gumppictiled", layout);
                        }
                    }
                    catch
                    {
                        OnError("gumppictiled", layout);
                    }

                    break;

                case "kr_xmfhtmlgump":
                    try
                    {
                        if (int.TryParse(formatted[1], out int xgX) &&
                            int.TryParse(formatted[2], out int xgY) &&
                            int.TryParse(formatted[3], out int xgWidth) &&
                            int.TryParse(formatted[4], out int xgHeight) &&
                            int.TryParse(formatted[5], out int xgCliloc) &&
                            int.TryParse(formatted[6], out int xgBackground) &&
                            int.TryParse(formatted[7], out int xgScrollbar))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.kr_xmfhtmlgump,
                                ParentPage = currentPage,
                                X          = xgX,
                                Y          = xgY,
                                Width      = xgWidth,
                                Height     = xgHeight,
                                Cliloc     = xgCliloc,
                                Background = xgBackground == 1,
                                ScrollBar  = xgScrollbar == 1
                            };

                            if (xgCliloc != 0)
                            {
                                ge.Text = Cliloc.GetProperty(xgCliloc);
                            }

                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("kr_xmfhtmlgump", layout);
                        }
                    }
                    catch
                    {
                        OnError("kr_xmfhtmlgump", layout);
                    }

                    break;

                case "mastergump":
                    try
                    {
                        if (int.TryParse(formatted[1], out int mgID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type = ElementType.mastergump, ParentPage = currentPage, ElementID = mgID
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("mastergump", layout);
                        }
                    }
                    catch
                    {
                        OnError("mastergump", layout);
                    }

                    break;

                case "radio":
                    try
                    {
                        if (int.TryParse(formatted[1], out int rX) && int.TryParse(formatted[2], out int rY) &&
                            int.TryParse(formatted[3], out int rInactiveID) &&
                            int.TryParse(formatted[4], out int rActiveID) &&
                            int.TryParse(formatted[5], out int rState) &&
                            int.TryParse(formatted[6], out int rID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type         = ElementType.radio,
                                ParentPage   = currentPage,
                                X            = rX,
                                Y            = rY,
                                InactiveID   = rInactiveID,
                                ActiveID     = rActiveID,
                                ElementID    = rID,
                                InitialState = rState == 1
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("radio", layout);
                        }
                    }
                    catch
                    {
                        OnError("radio", layout);
                    }

                    break;

                case "resizepic":
                    try
                    {
                        if (int.TryParse(formatted[1], out int rpX) &&
                            int.TryParse(formatted[2], out int rpY) &&
                            int.TryParse(formatted[3], out int rpID) &&
                            int.TryParse(formatted[4], out int rpWidth) &&
                            int.TryParse(formatted[5], out int _))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.resizepic,
                                ParentPage = currentPage,
                                X          = rpX,
                                Y          = rpY,
                                Width      = rpWidth,
                                Height     = rpWidth,
                                ElementID  = rpID
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("resizepic", layout);
                        }
                    }
                    catch
                    {
                        OnError("resizepic", layout);
                    }

                    break;

                case "text":
                    try
                    {
                        if (int.TryParse(formatted[1], out int tX) && int.TryParse(formatted[2], out int tY) &&
                            int.TryParse(formatted[3], out int tHue) &&
                            int.TryParse(formatted[4], out int tText))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.text,
                                ParentPage = currentPage,
                                X          = tX,
                                Y          = tY,
                                Hue        = tHue,
                                Text       = text[tText]
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("text", layout);
                        }
                    }
                    catch
                    {
                        OnError("text", layout);
                    }

                    break;

                case "tooltip":
                    try
                    {
                        if (int.TryParse(formatted[1], out int tooltip) /* && lastGumpElement != null */)
                        {
                            if (lastGumpElement != null)
                            {
                                lastGumpElement.Tooltip = tooltip;
                                lastGumpElement.Text    = Cliloc.GetProperty(tooltip);
                            }
                        }
                        else
                        {
                            OnError("tooltip", layout);
                        }
                    }
                    catch
                    {
                        OnError("tooltip", layout);
                    }

                    break;

                case "htmlgump":
                    try
                    {
                        if (int.TryParse(formatted[1], out int hgX) &&
                            int.TryParse(formatted[2], out int hgY) &&
                            int.TryParse(formatted[3], out int hgWidth) &&
                            int.TryParse(formatted[4], out int hgHeight) &&
                            int.TryParse(formatted[5], out int hgText) &&
                            int.TryParse(formatted[6], out int hgBackground) &&
                            int.TryParse(formatted[7], out int hgScrollbar))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.htmlgump,
                                ParentPage = currentPage,
                                X          = hgX,
                                Y          = hgY,
                                Width      = hgWidth,
                                Height     = hgHeight,
                                Text       = text[hgText],
                                ScrollBar  = hgScrollbar == 1,
                                Background = hgBackground == 1
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("htmlgump", layout);
                        }
                    }
                    catch
                    {
                        OnError("htmlgump", layout);
                    }

                    break;

                case "textentry":
                    try
                    {
                        if (int.TryParse(formatted[1], out int teX) &&
                            int.TryParse(formatted[2], out int teY) &&
                            int.TryParse(formatted[3], out int teWidth) &&
                            int.TryParse(formatted[4], out int teHeight) &&
                            int.TryParse(formatted[5], out int teHue) &&
                            int.TryParse(formatted[6], out int teID) &&
                            int.TryParse(formatted[7], out int teText))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.textentry,
                                ParentPage = currentPage,
                                X          = teX,
                                Y          = teY,
                                Height     = teHeight,
                                Width      = teWidth,
                                Hue        = teHue,
                                ElementID  = teID,
                                Text       = text[teText]
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("textentry", layout);
                        }
                    }
                    catch
                    {
                        OnError("textentry", layout);
                    }

                    break;

                case "textentrylimited":
                    try
                    {
                        if (int.TryParse(formatted[1], out int tlX) &&
                            int.TryParse(formatted[2], out int tlY) &&
                            int.TryParse(formatted[3], out int tlWidth) &&
                            int.TryParse(formatted[4], out int tlHeight) &&
                            int.TryParse(formatted[5], out int tlHue) &&
                            int.TryParse(formatted[6], out int tlID) &&
                            int.TryParse(formatted[7], out int tlText) &&
                            int.TryParse(formatted[8], out int tlSize))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.textentrylimited,
                                ParentPage = currentPage,
                                X          = tlX,
                                Y          = tlY,
                                Height     = tlHeight,
                                Width      = tlWidth,
                                Hue        = tlHue,
                                ElementID  = tlID,
                                Text       = text[tlText],
                                Size       = tlSize
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("textentrylimited", layout);
                        }
                    }
                    catch
                    {
                        OnError("textentrylimited", layout);
                    }

                    break;

                case "tilepic":
                    try
                    {
                        if (int.TryParse(formatted[1], out int tpX) &&
                            int.TryParse(formatted[2], out int tpY) &&
                            int.TryParse(formatted[3], out int tpID))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.tilepic,
                                ParentPage = currentPage,
                                X          = tpX,
                                Y          = tpY,
                                ElementID  = tpID
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("tilepic", layout);
                        }
                    }
                    catch
                    {
                        OnError("tilepic", layout);
                    }

                    break;

                case "tilepichue":
                    try
                    {
                        if (int.TryParse(formatted[1], out int tpX) &&
                            int.TryParse(formatted[2], out int tpY) &&
                            int.TryParse(formatted[3], out int tpID) &&
                            int.TryParse(formatted[4], out int tpHue))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.tilepichue,
                                ParentPage = currentPage,
                                X          = tpX,
                                Y          = tpY,
                                ElementID  = tpID,
                                Hue        = tpHue
                            };
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("tilepichue", layout);
                        }
                    }
                    catch
                    {
                        OnError("tilepichue", layout);
                    }

                    break;

                case "xmfhtmlgump":
                    try
                    {
                        if (int.TryParse(formatted[1], out int xgX) &&
                            int.TryParse(formatted[2], out int xgY) &&
                            int.TryParse(formatted[3], out int xgWidth) &&
                            int.TryParse(formatted[4], out int xgHeight) &&
                            int.TryParse(formatted[5], out int xgCliloc) &&
                            int.TryParse(formatted[6], out int xgBackground) &&
                            int.TryParse(formatted[7], out int xgScrollbar))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.xmfhtmlgump,
                                ParentPage = currentPage,
                                X          = xgX,
                                Y          = xgY,
                                Width      = xgWidth,
                                Height     = xgHeight,
                                Cliloc     = xgCliloc,
                                Background = xgBackground == 1,
                                ScrollBar  = xgScrollbar == 1
                            };

                            if (xgCliloc != 0)
                            {
                                ge.Text = Cliloc.GetProperty(xgCliloc);
                            }

                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("xmfhtmlgump", layout);
                        }
                    }
                    catch
                    {
                        OnError("xmfhtmlgump", layout);
                    }

                    break;

                case "xmfhtmlgumpcolor":
                    try
                    {
                        if (int.TryParse(formatted[1], out int xcX) &&
                            int.TryParse(formatted[2], out int xcY) &&
                            int.TryParse(formatted[3], out int xcWidth) &&
                            int.TryParse(formatted[4], out int xcHeight) &&
                            int.TryParse(formatted[5], out int xcCliloc) &&
                            int.TryParse(formatted[6], out int xcBackground) &&
                            int.TryParse(formatted[7], out int xcScrollbar) &&
                            int.TryParse(formatted[8], out int xcHue))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type       = ElementType.xmfhtmlgumpcolor,
                                ParentPage = currentPage,
                                X          = xcX,
                                Y          = xcY,
                                Width      = xcWidth,
                                Height     = xcHeight,
                                Cliloc     = xcCliloc,
                                Background = xcBackground == 1,
                                ScrollBar  = xcScrollbar == 1,
                                Hue        = xcHue
                            };

                            if (xcCliloc != 0)
                            {
                                ge.Text = Cliloc.GetProperty(xcCliloc);
                            }

                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("xmfhtmlgumpcolor", layout);
                        }
                    }
                    catch
                    {
                        OnError("xmfhtmlgumpcolor", layout);
                    }

                    break;

                case "xmfhtmltok":
                    try
                    {
                        if (int.TryParse(formatted[1], out int xtX) &&
                            int.TryParse(formatted[2], out int xtY) &&
                            int.TryParse(formatted[3], out int xtWidth) &&
                            int.TryParse(formatted[4], out int xtHeight) &&
                            int.TryParse(formatted[5], out int xtBackground) &&
                            int.TryParse(formatted[6], out int xtScrollbar) &&
                            int.TryParse(formatted[7], out int xtHue) &&
                            int.TryParse(formatted[8], out int xtCliloc))
                        {
                            GumpElement ge = new GumpElement
                            {
                                Type = ElementType.xmfhtmltok, ParentPage = currentPage
                            };

                            string[]      args = null;
                            StringBuilder sb   = new StringBuilder();

                            if (formatted.Length > 9)
                            {
                                sb.Append(formatted[9]);

                                for (int a = 10; a < formatted.Length; a++)
                                {
                                    sb.Append(' ');
                                    sb.Append(formatted[a]);
                                }

                                args = GetTokens(sb.ToString());
                            }

                            ge.Text = Cliloc.GetLocalString(xtCliloc, args);
                            ge.Args = args != null?string.Join("\t", args) : string.Empty;

                            ge.X          = xtX;
                            ge.Y          = xtY;
                            ge.Width      = xtWidth;
                            ge.Height     = xtHeight;
                            ge.Hue        = xtHue;
                            ge.Cliloc     = xtCliloc;
                            ge.ScrollBar  = xtScrollbar == 1;
                            ge.Background = xtBackground == 1;
                            gumpElementList.Add(ge);
                        }
                        else
                        {
                            OnError("xmfhtmltok", layout);
                        }
                    }
                    catch
                    {
                        OnError("xmfhtmltok", layout);
                    }

                    break;

                case "itemproperty":
                    int itemserial;

                    if (int.TryParse(formatted[1], out itemserial))
                    {
                        GumpElement ge = new GumpElement {
                            Type = ElementType.itemproperty, Serial = itemserial
                        };
                        gumpElementList.Add(ge);
                    }

                    break;

                case "echandleinput":
                    //TODO
                    break;
                    //default:
                    //    throw new InvalidOperationException(
                    //        $"Unknown element \"{formatted[0]}\" in custom gump layout:\r\n\r\n{layout}" );
                }
            }

            if (currentPage != null)
            {
                currentPage.GumpElements = gumpElementList.ToArray();
                pageList.Add(currentPage);
            }

            Gump g = new Gump(x, y, ID, serial, layout, text, gumpElementList.ToArray(), pageList.ToArray())
            {
                Closable = closable, Disposable = disposable, Movable = movable, Resizable = resizable
            };

            return(g);
        }
Exemplo n.º 30
0
        private static IEnumerable <ContextMenuEntry> ParseContextMenuEntries(byte[] packet)
        {
            PacketReader reader = new PacketReader(packet, packet.Length, false);

            reader.ReadInt16();
            int type   = reader.ReadInt16();
            int serial = reader.ReadInt32();
            int len    = reader.ReadByte();

            int entry, cliloc, flags, hue;

            List <ContextMenuEntry> entries = new List <ContextMenuEntry>();

            switch (type)
            {
            case 1:     // Old Type
                for (int x = 0; x < len; x++)
                {
                    entry  = reader.ReadInt16();
                    cliloc = reader.ReadInt16() + 3000000;
                    flags  = reader.ReadInt16();
                    hue    = 0;

                    if ((flags & 0x20) == 0x20)
                    {
                        hue = reader.ReadInt16();
                    }

                    string text = Cliloc.GetProperty(cliloc);
                    entries.Add(new ContextMenuEntry
                    {
                        Index  = entry,
                        Cliloc = cliloc,
                        Flags  = (ContextMenuFlags)flags,
                        Hue    = hue,
                        Text   = text
                    });
                }

                break;

            case 2:     // KR -> SA3D -> 2D post 7.0.0.0
                for (int x = 0; x < len; x++)
                {
                    cliloc = reader.ReadInt32();
                    entry  = reader.ReadInt16();
                    flags  = reader.ReadInt16();
                    hue    = 0;

                    if ((flags & 0x20) == 0x20)
                    {
                        hue = reader.ReadInt16();
                    }

                    string text = Cliloc.GetProperty(cliloc);

                    entries.Add(new ContextMenuEntry
                    {
                        Index  = entry,
                        Cliloc = cliloc,
                        Flags  = (ContextMenuFlags)flags,
                        Hue    = hue,
                        Text   = text
                    });
                }

                break;
            }

            return(entries);
        }