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); }
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()); }
public PSOObject[] GetObjectsForZone(string zone) { if (zone == "tpmap") // Return empty object array for an tp'd map for now (We spawn in a teleporter manually) { return(new PSOObject[0]); } if (!zoneObjects.ContainsKey(zone)) { Dictionary <ulong, PSOObject> objects = new Dictionary <ulong, PSOObject>(); // Collect from db using (var db = new PolarisEf()) { var dbObjects = from dbo in db.GameObjects where dbo.ZoneName == zone select dbo; foreach (var dbObject in dbObjects) { var newObject = PSOObject.FromDBObject(dbObject); objects.Add(newObject.Header.ID, newObject); allTheObjects.Add(newObject.Header.ID, newObject); Logger.WriteInternal("[OBJ] Loaded object {0} for zone {1} from the DB.", newObject.Name, zone); } } // Fallback if (objects.Count < 1 && Directory.Exists("Resources/objects/" + zone)) { Logger.WriteWarning("[OBJ] No objects defined for zone {0} in the database, falling back to filesystem!", zone); var objectPaths = Directory.GetFiles("Resources/objects/" + zone); Array.Sort(objectPaths); foreach (var path in objectPaths) { if (Path.GetExtension(path) == ".bin") { var newObject = PSOObject.FromPacketBin(File.ReadAllBytes(path)); objects.Add(newObject.Header.ID, newObject); allTheObjects.Add(newObject.Header.ID, newObject); Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX, newObject.Position.PosY, newObject.Position.PosZ); } else if (Path.GetExtension(path) == ".json") { var newObject = JsonConvert.DeserializeObject <PSOObject>(File.ReadAllText(path)); objects.Add(newObject.Header.ID, newObject); allTheObjects.Add(newObject.Header.ID, newObject); Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX, newObject.Position.PosY, newObject.Position.PosZ); } } } zoneObjects.Add(zone, objects); } return(zoneObjects[zone].Values.ToArray()); }
public PSOObject[] GetObjectsForZone(string zone) { if (zone == "tpmap") // Return empty object array for an tp'd map for now (We spawn in a teleporter manually) { return(new PSOObject[0]); } if (!zoneObjects.ContainsKey(zone)) { Dictionary <ulong, PSOObject> objects = new Dictionary <ulong, PSOObject>(); if (Directory.Exists("Resources/objects/" + zone)) { var objectPaths = Directory.GetFiles("Resources/objects/" + zone); Array.Sort(objectPaths); foreach (var path in objectPaths) { if (Path.GetExtension(path) == ".bin") { var newObject = PSOObject.FromPacketBin(File.ReadAllBytes(path)); objects.Add(newObject.Header.ID, newObject); allObjects.Add(newObject.Header.ID, newObject); Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX, newObject.Position.PosY, newObject.Position.PosZ); } else if (Path.GetExtension(path) == ".json") { var newObject = JsonConvert.DeserializeObject <PSOObject>(File.ReadAllText(path)); objects.Add(newObject.Header.ID, newObject); allObjects.Add(newObject.Header.ID, newObject); Logger.WriteInternal("[OBJ] Loaded object ID {0} with name {1} pos: ({2}, {3}, {4})", newObject.Header.ID, newObject.Name, newObject.Position.PosX, newObject.Position.PosY, newObject.Position.PosZ); } } } zoneObjects.Add(zone, objects); } return(zoneObjects[zone].Values.ToArray()); }
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")); } } }
public TeleportTransferPacket(PSOObject srcTeleporter, PSOLocation destination) { src = srcTeleporter; dst = destination; }