本文整理汇总了C#中System.IO.PacketWriter.WriteStruct方法的典型用法代码示例。如果您正苦于以下问题:C# PacketWriter.WriteStruct方法的具体用法?C# PacketWriter.WriteStruct怎么用?C# PacketWriter.WriteStruct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.PacketWriter
的用法示例。
在下文中一共展示了PacketWriter.WriteStruct方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateSpawnBlob
public override byte[] GenerateSpawnBlob()
{
PacketWriter writer = new PacketWriter();
writer.WriteStruct(Header);
writer.WritePosition(Position);
writer.Write((UInt16)0);
writer.WriteFixedLengthASCII(Name, 0x20);
writer.Write(0); // Padding?
writer.Write(new byte[0xC]); // Unknown, usually zero
writer.Write((UInt16)0);
writer.Write((UInt16)0);
writer.Write((UInt32)0);
writer.Write((UInt32)0);
writer.Write((UInt32)1101004800); // Always this
writer.Write((UInt32)0);
writer.Write((UInt32)0);
writer.Write((UInt32)0);
writer.Write((UInt32)1);
writer.WriteMagic(1, 0x9FCD, 0xE7);
writer.Write((UInt32)0);
return writer.ToArray();
}
示例2: DoBlockBalance
private void DoBlockBalance(Socket socket)
{
var writer = new PacketWriter();
writer.WriteStruct(new PacketHeader(0x90, 0x11, 0x2C, 0x0, 0x0));
writer.Write(new byte[0x68 - 8]);
writer.Write(PolarisApp.BindAddress.GetAddressBytes());
writer.Write((UInt16)12205);
writer.Write(new byte[0x90 - 0x6A]);
socket.Send(writer.ToArray());
socket.Close();
}
示例3: DoShipList
private void DoShipList(Socket socket)
{
var writer = new PacketWriter();
var entries = new List<ShipEntry>();
for (var i = 1; i < 11; i++)
{
var entry = new ShipEntry
{
order = (ushort)i,
number = (uint)i,
status = ShipStatus.Online,
name = String.Format("Ship{0:0#}", i),
ip = PolarisApp.BindAddress.GetAddressBytes()
};
entries.Add(entry);
}
writer.WriteStruct(new PacketHeader(Marshal.SizeOf(typeof(ShipEntry)) * entries.Count + 12, 0x11, 0x3D, 0x4,
0x0));
writer.WriteMagic((uint)entries.Count, 0xE418, 81);
foreach (var entry in entries)
writer.WriteStruct(entry);
writer.Write((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
writer.Write(1);
socket.Send(writer.ToArray());
socket.Close();
}
示例4: SpawnClient
/// <summary>
/// Spawns a client into a map at a given location
/// </summary>
/// <param name="c">Client to spawn into map</param>
/// <param name="location">Location to spawn client at</param>
/// <param name="questOveride">If this also sets the quest data, specify the quest name here to load the spawn from the bin rather then generate it.</param>
public void SpawnClient(Client c, PSOLocation location, string questOveride = "")
{
if (Clients.Contains(c))
{
return;
}
// Set area
if (questOveride != "") // TODO: This is a temporary hack, fix me!!
{
var setAreaPacket = File.ReadAllBytes("Resources/quests/" + questOveride + ".bin");
c.SendPacket(0x03, 0x24, 4, setAreaPacket);
}
else
{
PacketWriter writer = new PacketWriter();
writer.WriteStruct(new ObjectHeader(3, EntityType.Map));
writer.WriteStruct(new ObjectHeader((uint)c.User.PlayerId, EntityType.Player));
writer.Write(0x1); // 8 Zeros
writer.Write(0); // 8 Zeros
writer.Write(~(uint)Type); // F4 FF FF FF
writer.Write(MapID); // Map ID maybe
writer.Write((uint)Flags);
writer.Write(GenerationArgs.seed); // 81 8F E6 19 (Maybe seed)
writer.Write(VariantID); // Randomgen enable / disable maybe
writer.Write(GenerationArgs.xsize); // X Size
writer.Write(GenerationArgs.ysize); // Y Size
writer.Write(1);
writer.Write(1);
writer.Write(~0); // FF FF FF FF FF FF FF FF
writer.Write(0x301);
c.SendPacket(0x3, 0x0, 0x0, writer.ToArray());
}
if (c.CurrentZone != null)
{
c.CurrentZone.RemoveClient(c);
}
var setPlayerId = new PacketWriter();
setPlayerId.WritePlayerHeader((uint)c.User.PlayerId);
c.SendPacket(0x06, 0x00, 0, setPlayerId.ToArray());
// Spawn Character
c.SendPacket(new CharacterSpawnPacket(c.Character, location));
c.CurrentLocation = location;
c.CurrentZone = this;
// Objects
foreach (PSOObject obj in Objects)
{
c.SendPacket(0x08, 0x0B, 0x0, obj.GenerateSpawnBlob());
}
// NPCs
foreach (PSONPC npc in NPCs)
{
c.SendPacket(0x08, 0xC, 0x4, npc.GenerateSpawnBlob());
}
// Spawn for others, Spawn others for me
CharacterSpawnPacket spawnMe = new CharacterSpawnPacket(c.Character, location, false);
foreach (Client other in Clients)
{
other.SendPacket(spawnMe);
c.SendPacket(new CharacterSpawnPacket(other.Character, other.CurrentLocation, false));
}
// Unlock Controls
c.SendPacket(new NoPayloadPacket(0x03, 0x2B)); // Inital spawn only, move this!
Clients.Add(c);
Logger.Write("[MAP] {0} has spawned in {1}.", c.User.Username, Name);
if (InstanceName != null && ZoneManager.Instance.playerCounter.ContainsKey(InstanceName))
{
ZoneManager.Instance.playerCounter[InstanceName] += 1;
}
}
示例5: RemoveClient
public void RemoveClient(Client c)
{
if (!Clients.Contains(c))
return;
c.CurrentZone = null;
Clients.Remove(c);
foreach (Client other in Clients)
{
PacketWriter writer = new PacketWriter();
writer.WriteStruct(new ObjectHeader((uint)other.User.PlayerId, EntityType.Player));
writer.WriteStruct(new ObjectHeader((uint)c.User.PlayerId, EntityType.Player));
other.SendPacket(0x4, 0x3B, 0x40, writer.ToArray());
}
if (InstanceName != null && ZoneManager.Instance.playerCounter.ContainsKey(InstanceName))
{
ZoneManager.Instance.playerCounter[InstanceName] -= 1;
if (ZoneManager.Instance.playerCounter[InstanceName] <= 0)
{
ZoneManager.Instance.playerCounter.Remove(InstanceName);
ZoneManager.Instance.instances.Remove(InstanceName);
}
}
}