本文整理汇总了C#中System.IO.PacketReader.ReadStruct方法的典型用法代码示例。如果您正苦于以下问题:C# PacketReader.ReadStruct方法的具体用法?C# PacketReader.ReadStruct怎么用?C# PacketReader.ReadStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.PacketReader
的用法示例。
在下文中一共展示了PacketReader.ReadStruct方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandlePacket
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
if (context.User == null || context.Character == null)
return;
// Looks/Jobs
if (size > 0)
{
var reader = new PacketReader(data);
reader.BaseStream.Seek(0x38, SeekOrigin.Begin);
context.Character.Looks = reader.ReadStruct<Character.LooksParam>();
context.Character.Jobs = reader.ReadStruct<Character.JobParam>();
using(var db = new PolarisEf())
db.ChangeTracker.DetectChanges();
}
Map lobbyMap = ZoneManager.Instance.MapFromInstance("lobby", "lobby");
lobbyMap.SpawnClient(context, lobbyMap.GetDefaultLocation(), "lobby");
// Unlock Controls
context.SendPacket(new NoPayloadPacket(0x03, 0x2B));
//context.SendPacket(File.ReadAllBytes("testbed/237.23-7.210.189.208.30.bin"));
// Give a blank palette
context.SendPacket(new PalettePacket());
// memset packet - Enables menus
// Also holds event items and likely other stuff too
var memSetPacket = File.ReadAllBytes("Resources/setMemoryPacket.bin");
context.SendPacket(memSetPacket);
}
示例2: ImportNPCs
private void ImportNPCs(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<NPC> newNPCs = new List<NPC>();
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 != 0xC)
{
Logger.WriteWarning("[WRN] File {0} not an NPC spawn packet, skipping.", path);
continue;
}
NPC newNPC = new NPC();
newNPC.EntityID = (int)reader.ReadStruct<ObjectHeader>().ID;
var pos = reader.ReadEntityPosition();
newNPC.RotX = pos.RotX;
newNPC.RotY = pos.RotY;
newNPC.RotZ = pos.RotZ;
newNPC.RotW = pos.RotW;
newNPC.PosX = pos.PosX;
newNPC.PosY = pos.PosY;
newNPC.PosZ = pos.PosZ;
reader.ReadInt16();
newNPC.NPCName = reader.ReadFixedLengthAscii(0x20);
newNPC.ZoneName = zone;
newNPCs.Add(newNPC);
Logger.WriteInternal("[NPC] Adding new NPC {0} to the database for zone {1}", newNPC.NPCName, zone);
}
using (var db = new PolarisEf())
{
db.NPCs.AddRange(newNPCs);
db.SaveChanges();
}
}
示例3: ImportObjects
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();
}
}
示例4: FromPacketBin
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;
}