예제 #1
0
        private void ImportObjects(string[] args, int length, string full, Client client)
        {
            string zone = args[1];
            string folder = args[2];

            var packetList = Directory.GetFiles(folder);
            Array.Sort(packetList);

            List<GameObject> newObjects = new List<GameObject>();
            foreach (var path in packetList)
            {
                var data = File.ReadAllBytes(path);
                PacketReader reader = new PacketReader(data);
                PacketHeader header = reader.ReadStruct<PacketHeader>();
                if (header.Type != 0x8 || header.Subtype != 0xB)
                {
                    Logger.WriteWarning("[WRN] File {0} not an Object spawn packet, skipping.", path);
                    continue;
                }

                GameObject newObj = new GameObject();
                newObj.ObjectID = (int)reader.ReadStruct<ObjectHeader>().ID;
                var pos = reader.ReadEntityPosition();
                newObj.RotX = pos.RotX;
                newObj.RotY = pos.RotY;
                newObj.RotZ = pos.RotZ;
                newObj.RotW = pos.RotW;

                newObj.PosX = pos.PosX;
                newObj.PosY = pos.PosY;
                newObj.PosZ = pos.PosZ;
                reader.ReadInt16();
                newObj.ObjectName = reader.ReadFixedLengthAscii(0x2C);
                var objHeader = reader.ReadStruct<ObjectHeader>(); // Seems to always be blank...
                if (objHeader.ID != 0)
                    Logger.WriteWarning("[OBJ] It seems object {0} has a nonzero objHeader! ({1}) Investigate.", newObj.ObjectName, objHeader.ID);
                newObj.ZoneName = zone;
                var thingCount = reader.ReadUInt32();
                newObj.ObjectFlags = new byte[thingCount * 4];
                for (int i = 0; i < thingCount; i++)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(reader.ReadUInt32()), 0, newObj.ObjectFlags, i * 4, 4); // This should work
                }
                newObjects.Add(newObj);
                Logger.WriteInternal("[OBJ] Adding new Object {0} to the database for zone {1}", newObj.ObjectName, zone);
            }

            using (var db = new PolarisEf())
            {
                db.GameObjects.AddRange(newObjects);
                db.SaveChanges();
            }
        }
예제 #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;
        }