Ejemplo n.º 1
0
        public void TestObjectSerialize()
        {
            var testObject = new PSOObject
            {
                Name = "testobj",
                Header = new ObjectHeader { ID = 1337, EntityType = EntityType.Object },
                Position = new PSOLocation
                {
                    RotX = (float)3.3,
                    RotY = (float)3.3,
                    RotZ = (float)3.3,
                    RotW = (float)3.3,
                    PosX = (float)3.3,
                    PosY = (float)3.3,
                    PosZ = (float)3.3
                },
                ThingFlag = 4,
                Things = new PSOObject.PSOObjectThing[2]
            };

            var thingData = BitConverter.ToUInt32(new byte[] { 0xff, 0xff, 0xff, 0xff }, 0);
            testObject.Things[0] = new PSOObject.PSOObjectThing { Data = thingData };
            var output = JsonConvert.SerializeObject(testObject);
            Console.Out.WriteLine(output);
        }
Ejemplo n.º 2
0
        internal static PSOObject FromDBObject(GameObject dbObject)
        {
            PSOObject psoObj = new PSOObject();

            psoObj.Header   = new ObjectHeader((uint)dbObject.ObjectID, EntityType.Object);
            psoObj.Name     = dbObject.ObjectName;
            psoObj.Position = new PSOLocation(dbObject.RotX, dbObject.RotY, dbObject.RotZ, dbObject.RotW, dbObject.PosX, dbObject.PosY, dbObject.PosZ);

            int thingCount = dbObject.ObjectFlags.Length / 4; // I hope this will work

            psoObj.Things = new PSOObjectThing[thingCount];
            for (int i = 0; i < psoObj.Things.Length; i++)
            {
                psoObj.Things[i] = new PSOObjectThing(BitConverter.ToUInt32(dbObject.ObjectFlags, 4 * i)); // This should work?
            }

            return(psoObj);
        }
Ejemplo n.º 3
0
        internal static PSOObject FromPacketBin(byte[] v)
        {
            PacketReader reader = new PacketReader(v);
            PSOObject    obj    = new PSOObject();

            reader.ReadStruct <PacketHeader>(); //Skip over header
            obj.Header   = reader.ReadStruct <ObjectHeader>();
            obj.Position = reader.ReadEntityPosition();
            reader.ReadUInt16(); // Seek 2
            obj.Name      = reader.ReadFixedLengthAscii(0x34);
            obj.ThingFlag = reader.ReadUInt32();
            uint thingCount = reader.ReadUInt32();

            obj.Things = new PSOObjectThing[thingCount];
            for (int i = 0; i < thingCount; i++)
            {
                obj.Things[i] = reader.ReadStruct <PSOObjectThing>();
            }

            return(obj);
        }
Ejemplo n.º 4
0
        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            PacketReader reader = new PacketReader(data);
            reader.ReadBytes(12); // Padding MAYBE???????????
            ObjectHeader srcObject = reader.ReadStruct<ObjectHeader>();
            byte[] someBytes = reader.ReadBytes(4); // Dunno what this is yet.
            ObjectHeader dstObject = reader.ReadStruct<ObjectHeader>(); // Could be wrong
            reader.ReadBytes(16); // Not sure what this is yet
            string command = reader.ReadAscii(0xD711, 0xCA);
            PSOObject srcObj;
            if(srcObject.EntityType == EntityType.Object)
            {
                srcObj = ObjectManager.Instance.getObjectByID(context.CurrentZone.Name, srcObject.ID);
            }
            else if(srcObject.EntityType == EntityType.Player)
            {
                srcObj = new PSOObject();
                srcObj.Header = srcObject;
                srcObj.Name = "Player";
            }
            else
            {
                srcObj = null;
            }

            Logger.WriteInternal("[OBJ] {0} (ID {1}) <{2}> --> Ent {3} (ID {4})", srcObj.Name, srcObj.Header.ID, command, (EntityType)dstObject.EntityType, dstObject.ID);

            // TODO: Delete this code and do this COMPLETELY correctly!!!
            if (command == "Transfer" && context.CurrentZone.Name == "lobby")
            {
                // Try and get the teleport definition for the object...
                using (var db = new PolarisEf())
                {
                    db.Configuration.AutoDetectChangesEnabled = true;
                    var teleporterEndpoint = db.Teleports.Find("lobby", (int)srcObject.ID);

                    if (teleporterEndpoint == null)
                    {
                        Logger.WriteError("[OBJ] Teleporter for {0} in {1} does not contain a destination!", srcObj.Header.ID, "lobby");
                        // Teleport Player to default point
                        context.SendPacket(new TeleportTransferPacket(srcObj, new PSOLocation(0f, 1f, 0f, -0.000031f, -0.417969f, 0.000031f, 134.375f)));
                        // Unhide player
                        context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new ObjectHeader(), new ObjectHeader(), "Forwarded"));
                    }
                    else
                    {
                        PSOLocation endpointLocation = new PSOLocation()
                        {
                            RotX = teleporterEndpoint.RotX,
                            RotY = teleporterEndpoint.RotY,
                            RotZ = teleporterEndpoint.RotZ,
                            RotW = teleporterEndpoint.RotW,
                            PosX = teleporterEndpoint.PosX,
                            PosY = teleporterEndpoint.PosY,
                            PosZ = teleporterEndpoint.PosZ,
                        };
                        // Teleport Player
                        context.SendPacket(new TeleportTransferPacket(srcObj, endpointLocation));
                        // Unhide player
                        context.SendPacket(new ObjectActionPacket(dstObject, srcObject, new ObjectHeader(), new ObjectHeader(), "Forwarded"));
                    }
                }
            }

            if (command == "READY")
            {
                context.SendPacket(new ObjectActionPacket(new ObjectHeader((uint)context.User.PlayerId, EntityType.Player), srcObj.Header, srcObj.Header,
                    new ObjectHeader(), "FavsNeutral"));
                context.SendPacket(new ObjectActionPacket(new ObjectHeader((uint)context.User.PlayerId, EntityType.Player), srcObj.Header, srcObj.Header,
                    new ObjectHeader(), "AP")); // Short for Appear, Thanks Zapero!
            }

            if (command == "Sit")
            {
                foreach (var client in Server.Instance.Clients)
                {
                    if (client.Character == null || client == context)
                        continue;

                    client.SendPacket(new ObjectActionPacket(new ObjectHeader((uint)client.User.PlayerId, EntityType.Player), srcObj.Header,
                        new ObjectHeader(dstObject.ID, EntityType.Player), new ObjectHeader(), "SitSuccess"));
                }
            }
        }
Ejemplo n.º 5
0
        private void SpawnObject(string[] args, int length, string full, Client client)
        {
            if(client == null)
            {
                var id = Helper.FindPlayerByUsername(args[1]);
                if (id == -1)
                    return;

                client = PolarisApp.Instance.Server.Clients[id];
            }
            else
            {
                string[] newargs = new string[args.Length + 1];
                newargs[0] = "";
                newargs[1] = "";
                Array.Copy(args, 1, newargs, 2, 9);
                args = newargs;
            }
            PSOObject obj = new PSOObject();
            obj.Name = args[2];
            obj.Header = new ObjectHeader((uint)Int32.Parse(args[3]), EntityType.Object);
            obj.Position = new PSOLocation(float.Parse(args[4]), float.Parse(args[5]), float.Parse(args[6]), float.Parse(args[7]), float.Parse(args[8]), float.Parse(args[9]), float.Parse(args[10]));
            obj.Things = new PSOObject.PSOObjectThing[0];

            client.SendPacket(0x8, 0xB, 0x0, obj.GenerateSpawnBlob());
        }
Ejemplo n.º 6
0
        internal static PSOObject FromDBObject(GameObject dbObject)
        {
            PSOObject psoObj = new PSOObject();
            psoObj.Header = new ObjectHeader((uint)dbObject.ObjectID, EntityType.Object);
            psoObj.Name = dbObject.ObjectName;
            psoObj.Position = new PSOLocation(dbObject.RotX, dbObject.RotY, dbObject.RotZ, dbObject.RotW, dbObject.PosX, dbObject.PosY, dbObject.PosZ);

            int thingCount = dbObject.ObjectFlags.Length / 4; // I hope this will work
            psoObj.Things = new PSOObjectThing[thingCount];
            for(int i = 0; i < psoObj.Things.Length; i++)
            {
                psoObj.Things[i] = new PSOObjectThing(BitConverter.ToUInt32(dbObject.ObjectFlags, 4 * i)); // This should work?
            }

            return psoObj;
        }
Ejemplo n.º 7
0
        internal static PSOObject FromPacketBin(byte[] v)
        {
            PacketReader reader = new PacketReader(v);
            PSOObject obj = new PSOObject();
            reader.ReadStruct<PacketHeader>(); //Skip over header
            obj.Header = reader.ReadStruct<ObjectHeader>();
            obj.Position = reader.ReadEntityPosition();
            reader.ReadUInt16(); // Seek 2
            obj.Name = reader.ReadFixedLengthAscii(0x34);
            obj.ThingFlag = reader.ReadUInt32();
            uint thingCount = reader.ReadUInt32();
            obj.Things = new PSOObjectThing[thingCount];
            for (int i = 0; i < thingCount; i++)
            {
                obj.Things[i] = reader.ReadStruct<PSOObjectThing>();
            }

            return obj;
        }
 public TeleportTransferPacket(PSOObject srcTeleporter, PSOLocation destination)
 {
     src = srcTeleporter;
     dst = destination;
 }