- [X] Adds `ToSpan()` for SpanWriter.
- [X] Moves house files to UOContent/Multis/Houses
- [X] Adds house packets
### SpanWriter.ToSpan()
`ToSpan()` returns an `SpanOwner` struct which allows access to the buffer as a Span by calling `Span`.
Example:
```cs
public SpanOwner CreatePacket()
{
var writer = new SpanWriter(0x400);
// write some stuff
return writer.ToSpan();
}
```
In this example, we are creating a packet and returning the `SpanOwner` for caching. This means in the future we can do something like this:
```cs
ns.Send(_cachedPacket.Span);
```
Where `_cachedPacket` is the `SpanOwner`
Notes:
Do not use a SpanWriter, or attempt to dispose of it after calling `ToSpan()`. Doing so will probably cause an NPE.
84 lines
3 KiB
C#
84 lines
3 KiB
C#
/*************************************************************************
|
|
* ModernUO *
|
|
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
|
* Email: hi@modernuo.com *
|
|
* File: HousePackets.cs *
|
|
* *
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
* it under the terms of the GNU General Public License as published by *
|
|
* the Free Software Foundation, either version 3 of the License, or *
|
|
* (at your option) any later version. *
|
|
* *
|
|
* You should have received a copy of the GNU General Public License *
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
*************************************************************************/
|
|
|
|
using System.Buffers;
|
|
using Server.Network;
|
|
|
|
namespace Server.Multis
|
|
{
|
|
public static class HousePackets
|
|
{
|
|
private const int MaxItemsPerStairBuffer = 750;
|
|
|
|
public static void SendBeginHouseCustomization(this NetState ns, Serial house)
|
|
{
|
|
if (ns == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var writer = new SpanWriter(stackalloc byte[17]);
|
|
writer.Write((byte)0xBF); // Packet Id
|
|
writer.Write((ushort)17);
|
|
writer.Write((short)0x20); // Sub-packet
|
|
writer.Write(house);
|
|
writer.Write((byte)0x04); // command
|
|
writer.Write((ushort)0x0000);
|
|
writer.Write((ushort)0xFFFF);
|
|
writer.Write((ushort)0xFFFF);
|
|
writer.Write((byte)0xFF);
|
|
|
|
ns.Send(writer.Span);
|
|
}
|
|
|
|
public static void SendEndHouseCustomization(this NetState ns, Serial house)
|
|
{
|
|
if (ns == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var writer = new SpanWriter(stackalloc byte[17]);
|
|
writer.Write((byte)0xBF); // Packet Id
|
|
writer.Write((ushort)17);
|
|
writer.Write((short)0x20); // Sub-packet
|
|
writer.Write(house);
|
|
writer.Write((byte)0x05); // command
|
|
writer.Write((ushort)0x0000);
|
|
writer.Write((ushort)0xFFFF);
|
|
writer.Write((ushort)0xFFFF);
|
|
writer.Write((byte)0xFF);
|
|
|
|
ns.Send(writer.Span);
|
|
}
|
|
|
|
public static void SendDesignStateGeneral(this NetState ns, Serial house, int revision)
|
|
{
|
|
if (ns == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var writer = new SpanWriter(stackalloc byte[13]);
|
|
writer.Write((byte)0xBF); // Packet Id
|
|
writer.Write((ushort)13);
|
|
writer.Write((short)0x1D); // Sub-packet
|
|
writer.Write(house);
|
|
writer.Write(revision);
|
|
|
|
ns.Send(writer.Span);
|
|
}
|
|
}
|
|
}
|