Exemplo n.º 1
0
        public bool Update()
        {
            bool result = false;

            if (UOClientManager.IsAttached)
            {
                int x = 0;
                int y = 0;
                if (Global.SettingsCollection["clienttype"].ToInt() == 1) // enhanced client
                {
                    try
                    {
                        using (StreamReader reader = new StreamReader(File.Open(Global.UOPath + "\\logs\\pos.log", FileMode.Open, FileAccess.Read)))
                        {
                            string line = reader.ReadLine();
                            // [MAP]|[X]|[Y]|[HITS]|[MAXHITS]|[STAM]|[MAXSTAM]|[MANA]|[MAXMANA]
                            if (line.Length >= 3)
                            {
                                int startIdx = line.IndexOf("XY:");
                                int endIdx   = line.IndexOf("!");
                                line = line.Substring(startIdx + 3, endIdx - (startIdx + 3));
                                string[] args = line.Split('|');
                                int      map  = args[0].ToInt();
                                if (Map != map)
                                {
                                    Map = (byte)map;
                                }
                                x = args[1].ToInt();
                                y = args[2].ToInt();
                            }
                        }
                    }
                    catch
                    {
                    }
                }
                else
                {
                    int loc = Native.SendMessage(UOClientManager.hWnd, (int)MSG_SEND.GET_LOCATION_INFO, 0, 0);
                    if (loc > 0)
                    {
                        x = loc & 65535;
                        y = loc >> 16;
                    }
                }

                if (Position.X != x || Position.Y != y)
                {
                    UpdatePosition(x, y);

                    if (Global.FreeView && Global.SettingsCollection["centerplayer"].ToBool())
                    {
                        Global.FreeView = false;
                    }

                    if (Position.X == 0 && Position.Y == 0)
                    {
                        Reset();
                        return(true);
                    }

                    result = true;
                }

                if (InGame)
                {
                    int    facet      = -1;
                    int    hits       = -1;
                    int    maxhits    = -1;
                    int    stamina    = -1;
                    int    maxstamina = -1;
                    int    mana       = -1;
                    int    maxmana    = -1;
                    string status     = string.Empty;

                    if (OEUO_Manager.IsOpen)
                    {
                        facet      = OEUO_Manager.CursKind;
                        hits       = OEUO_Manager.Hits;
                        maxhits    = OEUO_Manager.MaxHits;
                        stamina    = OEUO_Manager.Stamina;
                        maxstamina = OEUO_Manager.MaxStamina;
                        mana       = OEUO_Manager.Mana;
                        maxmana    = OEUO_Manager.MaxMana;
                        status     = OEUO_Manager.CharStatus.ToLower();
                    }
                    else
                    {
                        int fmap    = Native.SendMessage(UOClientManager.hWnd, (int)MSG_SEND.GET_FACET, 0, 0); // facet
                        int allhp   = Native.SendMessage(UOClientManager.hWnd, (int)MSG_SEND.GET_HP, 0, 0);    // hp
                        int allstam = Native.SendMessage(UOClientManager.hWnd, (int)MSG_SEND.GET_STAM, 0, 0);  // stam
                        int allmana = Native.SendMessage(UOClientManager.hWnd, (int)MSG_SEND.GET_MANA, 0, 0);  // mana
                        int flags   = Native.SendMessage(UOClientManager.hWnd, (int)MSG_SEND.GET_FLAGS, 0, 0); // flags


                        if (allhp > 0)
                        {
                            hits    = allhp & 65535;
                            maxhits = allhp >> 16;
                        }

                        if (allstam > 0)
                        {
                            stamina    = allstam & 65535;
                            maxstamina = allstam >> 16;
                        }

                        if (allmana > 0)
                        {
                            mana    = allmana & 65535;
                            maxmana = allmana >> 16;
                        }
                    }

                    if (facet != -1 && facet != Map)
                    {
                        Map    = (byte)facet;
                        result = true;
                    }

                    if (hits != -1 && maxhits != -1 && (Hits.Min != hits || Hits.Max != maxhits))
                    {
                        Hits.Set((ushort)hits, (ushort)maxhits);
                        result = true;
                    }

                    if (stamina != -1 && maxstamina != -1 && (Stamina.Min != stamina || Stamina.Max != maxstamina))
                    {
                        Stamina.Set((ushort)stamina, (ushort)maxstamina);
                        result = true;
                    }

                    if (mana != -1 && maxmana != -1 && (Mana.Min != mana || Mana.Max != maxmana))
                    {
                        Mana.Set((ushort)mana, (ushort)maxmana);
                        result = true;
                    }

                    bool ispoisoned   = false;
                    bool isyellowhits = false;
                    bool isparalyzed  = false;
                    bool ishidden     = false;

                    for (int i = 0; i < status.Length; i++)
                    {
                        char c = status[i];

                        switch (c)
                        {
                        case 'c':
                            if (!IsPoisoned)
                            {
                                IsPoisoned = true;
                                result     = true;
                            }

                            ispoisoned = true;
                            break;

                        case 'd':
                            if (!IsYellowHits)
                            {
                                IsYellowHits = result = true;
                            }
                            isyellowhits = true;
                            break;

                        case 'a':
                            if (!IsParalyzed)
                            {
                                IsParalyzed = result = true;
                            }
                            isparalyzed = true;
                            break;

                        case 'h':
                            if (!IsHidden)
                            {
                                IsHidden = result = true;
                            }
                            ishidden = true;
                            break;
                        }
                    }


                    if (!ispoisoned && IsPoisoned)
                    {
                        IsPoisoned = false;
                        result     = true;
                    }

                    if (!isyellowhits & IsYellowHits)
                    {
                        IsYellowHits = false;
                        result       = true;
                    }

                    if (!isparalyzed && IsParalyzed)
                    {
                        IsParalyzed = false;
                        result      = true;
                    }

                    if (!ishidden && IsHidden)
                    {
                        IsHidden = false;
                        result   = true;
                    }

                    if (Hits.Min == 0 && Hits.Max > 0 && Mana.Min == 0 && Mana.Max > 0)
                    {
                        if (!IsDead)
                        {
                            IsDead = true;
                            result = true;
                            RenderObjectsManager.AddDeathObject(new DeathObject(this, Position, Map));
                        }
                    }
                    else if (Hits.Min > 0 && Hits.Max > 0 && Mana.Min > 0 && Mana.Max > 0 && IsDead)
                    {
                        IsDead = false;
                        result = true;
                    }
                }
                else if (OEUO_Manager.ClientHwnd != IntPtr.Zero && OEUO_Manager.CliNr == 0)
                {
                    OEUO_Manager.Attach(OEUO_Manager.ClientIndex);
                }
            }
            else
            {
                Reset();
            }

            if (result)
            {
                SendData();
            }

            return(result);
        }
Exemplo n.º 2
0
        public static void PlayerData(Packet p)
        {
            ushort x     = p.ReadUShort();
            ushort y     = p.ReadUShort();
            byte   facet = p.ReadByte();

            ushort hits    = p.ReadUShort();
            ushort stam    = p.ReadUShort();
            ushort mana    = p.ReadUShort();
            ushort maxhits = p.ReadUShort();
            ushort maxstam = p.ReadUShort();
            ushort maxmana = p.ReadUShort();

            byte flag = p.ReadByte();

            p.Skip(1);
            bool panic = p.ReadBool();

            Color msgCol = Color.FromArgb((int)p.ReadUInt());

            string fontName = p.ReadASCII(p.ReadByte());

            float fontSize;

            unsafe
            {
                uint n = p.ReadUInt();
                fontSize = *(float *)&n;
            }


            FontStyle fontStyle = (FontStyle)p.ReadByte();

            FontFamily f = FontFamily.Families.FirstOrDefault(s => s.Name == fontName);

            if (f == null)
            {
                fontName = "Arial";
            }
            else if (!f.IsStyleAvailable(fontStyle))
            {
                fontStyle = FontStyle.Regular;
            }

            string     username = p.ReadASCII(p.ReadByte());
            UserObject user     = RenderObjectsManager.GetUser(username);

            if (user == null)
            {
                RenderObjectsManager.AddUser(user = new UserObject(username));
            }

            user.UpdatePosition(x, y);
            user.Map = facet;
            user.Hits.Set(hits, maxhits);
            user.Stamina.Set(stam, maxstam);
            user.Mana.Set(mana, maxmana);

            switch (flag)
            {
            case 1:
                user.IsPoisoned = true;
                break;

            case 2:
                user.IsYellowHits = true;
                break;

            case 3:
                user.IsParalyzed = true;
                break;

            case 4:
                if (!user.IsDead)
                {
                    RenderObjectsManager.AddDeathObject(new DeathObject(user, user.Position, user.Map));
                }
                user.IsDead = true;
                break;

            case 5:
                user.IsHidden = true;
                break;

            default:
                user.IsHidden = user.IsPoisoned = user.IsYellowHits = user.IsParalyzed = user.IsDead = false;
                break;
            }

            if (user.InPanic && panic) // already panic, ignore
            {
                if (DateTime.Now > user.LastPanicUpdate)
                {
                    UOClientManager.SysMessage($"[Panic][{user.Name}] Needs help to: {user.Position} - Map: {user.Map}", 83);
                    user.LastPanicUpdate = DateTime.Now.AddSeconds(5);
                }
            }
            else if (!user.InPanic && panic) // receive panic signal
            {
                if (Global.SettingsCollection["panicsounds"].ToBool())
                {
                    SoundsManager.Play(SOUNDS_TYPE.PANIC);
                }
                UOClientManager.SysMessage($"[Panic][{user.Name}] Starts to panic!", 83);
                user.LastPanicUpdate = DateTime.Now.AddSeconds(5);
            }
            else if (user.InPanic && !panic) // receve remove panic signal
            {
                UOClientManager.SysMessage($"[Panic][{user.Name}] Stopped to panic.", 83);
            }

            user.InPanic = panic;
            user.Font    = new Font(fontName, fontSize, fontStyle, GraphicsUnit.Pixel);
            user.Hue     = new SolidBrush(msgCol);

            user.UpdateLifeTime();
        }