Beispiel #1
0
 protected void Send(AppPacket packet)
 {
     if (packet.Size > 512 - 7)  // Fragment
     {
         WriteLine("Fragment :(");
     }
     else
     {
         if (Debug)
         {
             ForegroundColor = ConsoleColor.Green;
             WriteLine($"Sending app packet (opcode {packet.Opcode:X04}, {this}):");
             if (packet.Data == null)
             {
                 WriteLine("!Null data!");
             }
             else
             {
                 Hexdump(packet.Data);
             }
             ResetColor();
         }
         var data = new byte[packet.Size];
         data[1] = (byte)(packet.Opcode >> 8);
         data[0] = (byte)packet.Opcode;
         if (packet.Data != null)
         {
             Array.Copy(packet.Data, 0, data, 2, packet.Data.Length);
         }
         Send(new Packet(SessionOp.Single, data));
     }
 }
Beispiel #2
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            switch ((WorldOp)packet.Opcode)
            {
            case WorldOp.GuildsList:
                break;

            case WorldOp.LogServer:
            case WorldOp.ApproveWorld:
            case WorldOp.EnterWorld:
            case WorldOp.ExpansionInfo:
                break;

            case WorldOp.SendCharInfo:
                var chars = new CharacterSelect(packet.Data);
                CharacterList?.Invoke(this, chars.Characters);
                break;

            case WorldOp.MessageOfTheDay:
                MOTD?.Invoke(this, Encoding.ASCII.GetString(packet.Data));
                break;

            case WorldOp.ZoneServerInfo:
                var info = packet.Get <ZoneServerInfo>();
                ZoneServer?.Invoke(this, info);
                break;

            default:
                WriteLine($"Unhandled packet in WorldStream: {(WorldOp)packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Beispiel #3
0
        bool ProcessPacket(Packet packet, bool self = false)
        {
            switch ((SessionOp)packet.Opcode)
            {
            case SessionOp.Single:
                futurePackets[packet.Sequence] = null;
                var app = new AppPacket(packet.Data);
                HandleAppPacketProxy(app);
                InSequence = (ushort)((packet.Sequence + 1) % 65536);
                if (Debug)
                {
                    WriteLine($"Single packet updated sequence from {packet.Sequence} to {InSequence}");
                }
                break;

            case SessionOp.Fragment:
                var tlen = packet.Data.NetU32(0);
                var rlen = -4;
                for (var i = packet.Sequence; futurePackets[i] != null && rlen < tlen; ++i)
                {
                    rlen += futurePackets[i].Data.Length;
                }
                if (rlen < tlen)      // Don't have all the pieces yet
                {
                    futurePackets[packet.Sequence] = packet;
                    return(false);
                }
                var tdata = new byte[rlen];
                rlen = 0;
                var last = 0;
                for (var i = packet.Sequence; rlen < tlen; ++i)
                {
                    var off   = i == packet.Sequence ? 4 : 0;
                    var fdata = futurePackets[i % 65536].Data;
                    Array.Copy(fdata, off, tdata, rlen, fdata.Length - off);
                    rlen            += fdata.Length - off;
                    futurePackets[i] = null;
                    last             = i;
                }
                InSequence = (ushort)((last + 1) % 65536);
                if (Debug)
                {
                    WriteLine($"Fragmented packet updated our sequence from {packet.Sequence} to {InSequence} ({last - packet.Sequence} packets)");
                }
                HandleAppPacketProxy(new AppPacket(tdata));
                break;
            }
            while (!self && futurePackets[InSequence] != null)
            {
                if (!ProcessPacket(futurePackets[InSequence], self: true))
                {
                    break;
                }
            }
            return(true);
        }
Beispiel #4
0
        protected override void HandleSessionResponse(Packet packet)
        {
            Send(packet);

            var data = new byte[464];
            var str  = $"{accountID}\0{sessionKey}";

            Array.Copy(Encoding.ASCII.GetBytes(str), data, str.Length);
            Send(AppPacket.Create(WorldOp.SendLoginInfo, data));
        }
Beispiel #5
0
 public void Login(string username, string password)
 {
     cryptoBlob = Encrypt(username, password);
     if (triedOnce)
     {
         Send(AppPacket.Create(LoginOp.Login, new Login(), cryptoBlob));
     }
     else
     {
         SendSessionRequest();
     }
 }
Beispiel #6
0
        public void UpdatePosition(Tuple <float, float, float, float> Position)
        {
            var update = new ClientPlayerPositionUpdate();

            update.ID       = playerSpawnId;
            update.Sequence = updateSequence++;
            update.X        = Position.Item1;
            update.Y        = Position.Item2;
            update.Sub1     = new ClientUpdatePositionSub1();
            update.Z        = Position.Item3;
            update.Sub2     = new ClientUpdatePositionSub2(0, (ushort)(Position.Item4 * 8f * 255f));
            Send(AppPacket.Create(ZoneOp.ClientUpdate, update));
        }
Beispiel #7
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            Hexdump(packet.Data);

            switch ((LoginOp)packet.Opcode)
            {
            case LoginOp.ChatMessage:
                Send(AppPacket.Create(LoginOp.Login, new Login(), cryptoBlob));
                break;

            case LoginOp.LoginAccepted:
                if (packet.Data.Length < 80)
                {
                    LoginSuccess?.Invoke(this, false);
                }
                else
                {
                    var dec = Decrypt(packet.Data, 10);
                    var rep = new LoginReply(dec);
                    accountID  = rep.AcctID;
                    sessionKey = rep.Key;
                    LoginSuccess?.Invoke(this, true);
                }
                break;

            case LoginOp.ServerListResponse:
                var header = packet.Get <ServerListHeader>();
                ServerList?.Invoke(this, header.Servers);
                break;

            case LoginOp.PlayEverquestResponse:
                var resp = packet.Get <PlayResponse>();

                if (!resp.Allowed)
                {
                    UnityEngine.Debug.LogError("Response flagged Allowed false");
                    curPlay = null;
                }

                PlaySuccess?.Invoke(this, curPlay);
                break;

            default:
                UnityEngine.Debug.Log($"Unhandled packet in LoginStream: {(LoginOp) packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Beispiel #8
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            switch ((WorldOp)packet.Opcode)
            {
            case WorldOp.GuildsList:
                break;

            case WorldOp.LogServer:
            case WorldOp.ApproveWorld:
            case WorldOp.EnterWorld:
            case WorldOp.ExpansionInfo:
                break;

            case WorldOp.SendCharInfo:
                var chars = new CharacterSelect(packet.Data);
                CharacterList?.Invoke(this, chars.Characters);
                break;

            case WorldOp.MessageOfTheDay:
                MOTD?.Invoke(this, Encoding.ASCII.GetString(packet.Data));
                break;

            case WorldOp.ZoneServerInfo:
                var info = packet.Get <ZoneServerInfo>();
                ZoneServer?.Invoke(this, info);
                break;

            case WorldOp.SetChatServer:
            case WorldOp.SetChatServer2:
                ChatServerList?.Invoke(this, packet.Data);
                break;

            case WorldOp.PostEnterWorld:
                // The emu doesn't do anything with ApproveWorld and WorldClientReady so we may be able to just skip them both.
                Send(AppPacket.Create(WorldOp.ApproveWorld, null));
                Send(AppPacket.Create(WorldOp.WorldClientReady, null));
                break;

            case WorldOp.ApproveName:
                CharacterCreateNameApproval?.Invoke(this, packet.Data[0]);
                break;

            default:
                WriteLine($"Unhandled packet in WorldStream: {(WorldOp)packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Beispiel #9
0
        void HandleAppPacketProxy(AppPacket packet)
        {
            if (Debug)
            {
                ForegroundColor = ConsoleColor.Magenta;
                WriteLine($"Received app packet (opcode {packet.Opcode:X04}, {this}):");
                if (packet.Data == null)
                {
                    WriteLine("!Null data!");
                }
                else
                {
                    Hexdump(packet.Data);
                }
                ResetColor();
            }

            HandleAppPacket(packet);
        }
Beispiel #10
0
 public void SendNameApproval(NameApproval nameApproval)
 {
     Send(AppPacket.Create(WorldOp.ApproveName, nameApproval));
 }
Beispiel #11
0
 public void RequestServerList()
 {
     Send(AppPacket.Create(LoginOp.ServerListRequest));
 }
Beispiel #12
0
 public void EnterWorld(string name, bool tutorial, bool goHome)
 {
     Send(AppPacket.Create(WorldOp.EnterWorld, new EnterWorld(name, tutorial, goHome)));
 }
Beispiel #13
0
 //Camp requests have a 29000ms camp timer
 public void SendCamp()
 {
     Send(AppPacket.Create(ZoneOp.Camp));
 }
Beispiel #14
0
 public void SendMessage()
 {
     Send(AppPacket.Create(ZoneOp.ChannelMessage, new ChannelMessage("Shin", "Xuluu", 0, 0, 0, "Hello")));
 }
Beispiel #15
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            switch ((ZoneOp)packet.Opcode)
            {
            case ZoneOp.PlayerProfile:
                var player = packet.Get <PlayerProfile>();
                //WriteLine(player);
                break;

            case ZoneOp.CharInventory:
                var inventory = packet.Get <CharInventory>();
                //WriteLine(inventory);
                break;

            case ZoneOp.TimeOfDay:
                var timeofday = packet.Get <TimeOfDay>();
                //WriteLine(timeofday);
                break;

            case ZoneOp.TaskActivity:
                var activity = packet.Get <TaskActivity>();
                //WriteLine(activity);
                break;

            case ZoneOp.TaskDescription:
                var desc = packet.Get <TaskDescription>();
                //WriteLine(desc);
                break;

            case ZoneOp.CompletedTasks:
                var comp = packet.Get <CompletedTasks>();
                //WriteLine(comp);
                break;

            case ZoneOp.XTargetResponse:
                var xt = packet.Get <XTarget>();
                //WriteLine(xt);
                break;

            case ZoneOp.Weather:
                var weather = packet.Get <Weather>();
                //WriteLine(weather);

                if (entering)
                {
                    Send(AppPacket.Create(ZoneOp.ReqNewZone));
                }
                break;

            case ZoneOp.TributeTimer:
                var timer = packet.Get <TributeTimer>();
                //WriteLine(timer);
                break;

            case ZoneOp.TributeUpdate:
                var update = packet.Get <TributeInfo>();
                //WriteLine(update);
                break;

            case ZoneOp.ZoneEntry:
                var mob = packet.Get <Spawn>();
                //WriteLine(mob);
                break;

            case ZoneOp.NewZone:
                Send(AppPacket.Create(ZoneOp.ReqClientSpawn));

                break;

            case ZoneOp.SendExpZonein:
                if (packet.Data.Length == 0)
                {
                    Send(AppPacket.Create(ZoneOp.ClientReady));
                    entering = false;
                }
                break;

            case ZoneOp.SendFindableNPCs:
                var npc = packet.Get <FindableNPC>();
                //WriteLine(npc);
                break;

            case ZoneOp.ClientUpdate:
                break;

            case ZoneOp.HPUpdate:
                break;

            default:
                WriteLine($"Unhandled packet in ZoneStream: {(ZoneOp) packet.Opcode} (0x{packet.Opcode:X04})");
                Hexdump(packet.Data);
                break;
            }
        }
Beispiel #16
0
        protected override void HandleSessionResponse(Packet packet)
        {
            Send(packet);

            Send(AppPacket.Create(ZoneOp.ZoneEntry, new ClientZoneEntry(charName)));
        }
Beispiel #17
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            //WriteLine($"Zone app packet: {(ZoneOp) packet.Opcode}");
            switch ((ZoneOp)packet.Opcode)
            {
            case ZoneOp.PlayerProfile:
                var player = packet.Get <PlayerProfile>();
                //WriteLine(player);
                break;

            case ZoneOp.TimeOfDay:
                var timeofday = packet.Get <TimeOfDay>();
                //WriteLine(timeofday);
                break;

            case ZoneOp.TaskActivity:
                // XXX: Handle short activities!
                //var activity = packet.Get<TaskActivity>();
                //WriteLine(activity);
                break;

            case ZoneOp.TaskDescription:
                var desc = packet.Get <TaskDescription>();
                //WriteLine(desc);
                break;

            case ZoneOp.CompletedTasks:
                var comp = packet.Get <CompletedTasks>();
                //WriteLine(comp);
                break;

            case ZoneOp.XTargetResponse:
                var xt = packet.Get <XTarget>();
                //WriteLine(xt);
                break;

            case ZoneOp.Weather:
                var weather = packet.Get <Weather>();
                //WriteLine(weather);

                if (entering)
                {
                    Send(AppPacket.Create(ZoneOp.ReqNewZone));
                }
                break;

            case ZoneOp.TributeTimer:
                var timer = packet.Get <TributeTimer>();
                //WriteLine(timer);
                break;

            case ZoneOp.TributeUpdate:
                var update = packet.Get <TributeInfo>();
                //WriteLine(update);
                break;

            case ZoneOp.ZoneEntry:
                var mob = packet.Get <Spawn>();
                if (mob.Name == charName)
                {
                    playerSpawnId = (ushort)mob.SpawnID;
                }
                Spawned(this, mob);
                break;

            case ZoneOp.NewZone:
                Send(AppPacket.Create(ZoneOp.ReqClientSpawn));
                break;

            case ZoneOp.SendExpZonein:
                if (entering)
                {
                    Send(AppPacket.Create(ZoneOp.ClientReady));
                    entering = false;
                }
                break;

            case ZoneOp.CharInventory:
                break;

            case ZoneOp.SendFindableNPCs:
                var npc = packet.Get <FindableNPC>();
                //WriteLine(npc);
                break;

            case ZoneOp.ClientUpdate:
                var pu = packet.Get <PlayerPositionUpdate>();
                PositionUpdated?.Invoke(this, pu);
                break;

            case ZoneOp.HPUpdate:
                break;

            default:
                //WriteLine($"Unhandled packet in ZoneStream: {(ZoneOp) packet.Opcode} (0x{packet.Opcode:X04})");
                //Hexdump(packet.Data);
                break;
            }
        }
Beispiel #18
0
        protected override void HandleAppPacket(AppPacket packet)
        {
            try
            {
                // UnityEngine.Debug.Log($"Got packet { (ZoneOp)packet.Opcode} (0x{ packet.Opcode:X04}");
                switch ((ZoneOp)packet.Opcode)
                {
                case ZoneOp.PlayerProfile:
                    var player = packet.Get <PlayerProfile>();
                    UnityEngine.Debug.Log("Profile:" + player);
                    break;

                case ZoneOp.CharInventory:
                    //  var inventory = packet.Get<CharInventory>();
                    //  UnityEngine.Debug.Log("Inventory: "+inventory);
                    break;

                case ZoneOp.TimeOfDay:
                    //  var timeofday = packet.Get<TimeOfDay>();
                    //  UnityEngine.Debug.Log(timeofday);
                    break;

                case ZoneOp.TaskActivity:
                    //  var activity = packet.Get<TaskActivity>();
                    //    UnityEngine.Debug.Log(activity);
                    break;

                case ZoneOp.TaskDescription:
                    //  var desc = packet.Get<TaskDescription>();
                    //    UnityEngine.Debug.Log(desc);
                    break;

                case ZoneOp.CompletedTasks:
                    //  var comp = packet.Get<CompletedTasks>();
                    //   UnityEngine.Debug.Log(comp);
                    break;

                case ZoneOp.XTargetResponse:
                    // var xt = packet.Get<XTarget>();
                    //   UnityEngine.Debug.Log(xt);
                    break;

                case ZoneOp.Weather:
                    // var weather = packet.Get<Weather>();
                    //    UnityEngine.Debug.Log(weather);

                    if (entering)
                    {
                        Send(AppPacket.Create(ZoneOp.ReqNewZone));
                    }
                    break;

                case ZoneOp.TributeTimer:
                    //var timer = packet.Get<TributeTimer>();
                    //   UnityEngine.Debug.Log(timer);
                    break;

                case ZoneOp.TributeUpdate:
                    // var update = packet.Get<TributeInfo>();
                    //   UnityEngine.Debug.Log(update);
                    break;

                case ZoneOp.ZoneEntry:
                    var mob = packet.Get <Spawn>();
                    ZoneEntry.Invoke(this, mob);
                    //UnityEngine.Debug.Log(mob);
                    break;

                case ZoneOp.NewZone:
                    Send(AppPacket.Create(ZoneOp.ReqClientSpawn));

                    break;

                case ZoneOp.SendExpZonein:
                    if (packet.Data.Length == 0)
                    {
                        Send(AppPacket.Create(ZoneOp.ClientReady));
                        entering = false;
                    }
                    break;

                case ZoneOp.SendFindableNPCs:
                    //  var npc = packet.Get<FindableNPC>();
                    //   UnityEngine.Debug.Log(npc);
                    break;

                case ZoneOp.ClientUpdate:
                    UnityEngine.Debug.Log("Sending Client Update");
                    //PlayerPositionUpdateServer.Invoke(this, packet.Get<PlayerPositionUpdateServer>());
                    break;

                case ZoneOp.SpawnAppearance:
                    break;

                case ZoneOp.Stamina:
                    break;

                case ZoneOp.SpecialMesg:
                    break;

                case ZoneOp.Death:
                    break;

                case ZoneOp.DeleteSpawn:
                    DeleteSpawn.Invoke(this, packet.Get <DeleteSpawn>());
                    break;

                case ZoneOp.PlayerStateAdd:
                    break;

                case ZoneOp.PlayerStateRemove:
                    break;

                case ZoneOp.ChannelMessage:
                    UnityEngine.Debug.Log("Got channel message");

                    ChannelMessage.Invoke(this, packet.Get <ChannelMessage>());

                    break;

                case ZoneOp.HPUpdate:
                    SpawnHPUpdate.Invoke(this, packet.Get <SpawnHPUpdate>());
                    break;

                case ZoneOp.ManaUpdate:
                    break;

                case ZoneOp.EnduranceUpdate:
                    break;

                case ZoneOp.SpawnPositionUpdate:
                    SpawnPositionUpdate.Invoke(this, packet.Get <SpawnPositionUpdate>());
                    break;

                case ZoneOp.BuffCreate:
                    break;

                case ZoneOp.AltCurrency:
                    break;

                case ZoneOp.WearChange:
                    break;

                case ZoneOp.GuildMOTD:
                    break;

                case ZoneOp.RaidUpdate:
                    break;

                case ZoneOp.ExpUpdate:
                    break;

                case ZoneOp.WorldObjectsSent:
                    break;

                case 0x0:
                    //This is a catch for an empty OP that happens.. dunno
                    break;

                case ZoneOp.SendAAStats:
                    break;

                case ZoneOp.SendZonepoints:
                    break;

                case ZoneOp.GroundSpawn:
                    break;

                case ZoneOp.SpawnDoor:
                    break;

                default:
                    UnityEngine.Debug.Log($"Unhandled packet in ZoneStream: {(ZoneOp) packet.Opcode} (0x{packet.Opcode:X04})");
                    Hexdump(packet.Data);
                    break;
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogError($"Failed to process {(ZoneOp) packet.Opcode} (0x{packet.Opcode:X04}):" + e.Message);
            }
        }
Beispiel #19
0
 public void RequestServerList()
 {
     Send(AppPacket.Create(LoginOp.ServerListRequest, new byte[] { 0, 0, 0, 0 }));
 }
Beispiel #20
0
 protected abstract void HandleAppPacket(AppPacket packet);
Beispiel #21
0
 public void Play(ServerListElement server)
 {
     curPlay = server;
     Send(AppPacket.Create(LoginOp.PlayEverquestRequest, new PlayRequest(5, server.RuntimeID)));
 }
Beispiel #22
0
 public void SendCharacterCreate(CharCreate charCreate)
 {
     Send(AppPacket.Create(WorldOp.CharacterCreate, charCreate));
 }
Beispiel #23
0
 protected override void HandleSessionResponse(Packet packet)
 {
     Send(AppPacket.Create(LoginOp.SessionReady, new SessionReady()));
 }
Beispiel #24
0
 public void SendEnterWorld(EnterWorld enterWorld)
 {
     Send(AppPacket.Create(WorldOp.EnterWorld, enterWorld));
 }