fix(core): Removes implicit cast between Serial and uint (#728)
* Fixes spellbooks using serial ctor * Fixes misc items where someone thought they had an amount and it didn't * Fixes all `Food` types.
This commit is contained in:
parent
17521c9cd7
commit
0dc4acc164
74 changed files with 319 additions and 248 deletions
|
|
@ -21,6 +21,7 @@ using System.Runtime.CompilerServices;
|
|||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.Toolkit.HighPerformance;
|
||||
using Server;
|
||||
using Server.Text;
|
||||
|
||||
namespace System.Buffers
|
||||
|
|
@ -234,6 +235,9 @@ namespace System.Buffers
|
|||
Position += 4;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Write(Serial serial) => Write(serial.Value);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void WriteLE(uint value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Server.Gumps
|
|||
{
|
||||
public class Gump
|
||||
{
|
||||
private static uint m_NextSerial = 1;
|
||||
private static Serial _nextSerial = (Serial)1;
|
||||
|
||||
public static readonly byte[] NoMove = StringToBuffer("{ nomove }");
|
||||
public static readonly byte[] NoClose = StringToBuffer("{ noclose }");
|
||||
|
|
@ -20,7 +20,7 @@ namespace Server.Gumps
|
|||
{
|
||||
do
|
||||
{
|
||||
Serial = m_NextSerial++;
|
||||
Serial = _nextSerial++;
|
||||
} while (Serial == 0); // standard client apparently doesn't send a gump response packet if serial == 0
|
||||
|
||||
X = x;
|
||||
|
|
@ -186,7 +186,7 @@ namespace Server.Gumps
|
|||
Add(new GumpTextEntryLimited(x, y, width, height, hue, entryID, initialText, size));
|
||||
}
|
||||
|
||||
public void AddItemProperty(uint serial)
|
||||
public void AddItemProperty(Serial serial)
|
||||
{
|
||||
Add(new GumpItemProperty(serial));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,18 +22,18 @@ namespace Server.Gumps
|
|||
{
|
||||
public static readonly byte[] LayoutName = Gump.StringToBuffer("itemproperty");
|
||||
|
||||
public GumpItemProperty(uint serial) => Serial = serial;
|
||||
public GumpItemProperty(Serial serial) => Serial = serial;
|
||||
|
||||
public uint Serial { get; set; }
|
||||
public Serial Serial { get; set; }
|
||||
|
||||
public override string Compile(OrderedHashSet<string> strings) => $"{{ itemproperty {Serial} }}";
|
||||
public override string Compile(OrderedHashSet<string> strings) => $"{{ itemproperty {Serial.Value} }}";
|
||||
|
||||
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
|
||||
{
|
||||
writer.Write((ushort)0x7B20); // "{ "
|
||||
writer.Write(LayoutName);
|
||||
writer.WriteAscii(' ');
|
||||
writer.WriteAscii(Serial.ToString());
|
||||
writer.WriteAscii(Serial.Value.ToString());
|
||||
writer.Write((ushort)0x207D); // " }"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ namespace Server.HuePickers
|
|||
{
|
||||
public class HuePicker
|
||||
{
|
||||
private static Serial m_NextSerial = 1;
|
||||
private static Serial _nextSerial = (Serial)1;
|
||||
|
||||
public HuePicker(int itemID)
|
||||
{
|
||||
do
|
||||
{
|
||||
Serial = m_NextSerial++;
|
||||
Serial = _nextSerial++;
|
||||
} while (Serial == 0);
|
||||
|
||||
ItemID = itemID;
|
||||
|
|
|
|||
|
|
@ -114,22 +114,7 @@ namespace Server
|
|||
var loc = reader.ReadPoint3D();
|
||||
var worldLoc = reader.ReadPoint3D();
|
||||
|
||||
IEntity parent;
|
||||
|
||||
Serial serial = reader.ReadUInt();
|
||||
|
||||
if (serial.IsItem)
|
||||
{
|
||||
parent = World.FindItem(serial);
|
||||
}
|
||||
else if (serial.IsMobile)
|
||||
{
|
||||
parent = World.FindMobile(serial);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent = null;
|
||||
}
|
||||
IEntity parent = reader.ReadEntity<IEntity>();
|
||||
|
||||
return new BounceInfo(map, loc, worldLoc, parent);
|
||||
}
|
||||
|
|
@ -2651,7 +2636,7 @@ namespace Server
|
|||
|
||||
if (GetSaveFlag(flags, SaveFlag.Parent))
|
||||
{
|
||||
Serial parent = reader.ReadUInt();
|
||||
Serial parent = reader.ReadSerial();
|
||||
|
||||
if (parent.IsMobile)
|
||||
{
|
||||
|
|
@ -2812,7 +2797,7 @@ namespace Server
|
|||
|
||||
if (GetSaveFlag(flags, SaveFlag.Parent))
|
||||
{
|
||||
Serial parent = reader.ReadUInt();
|
||||
Serial parent = reader.ReadSerial();
|
||||
|
||||
if (parent.IsMobile)
|
||||
{
|
||||
|
|
@ -2930,7 +2915,7 @@ namespace Server
|
|||
AcquireCompactInfo().m_Name = name;
|
||||
}
|
||||
|
||||
Serial parent = reader.ReadUInt();
|
||||
Serial parent = reader.ReadSerial();
|
||||
|
||||
if (parent.IsMobile)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ namespace Server
|
|||
public const int EquipUpdatePacketLength = 15;
|
||||
public const int RemovePacketLength = 5;
|
||||
|
||||
public static void SendHairEquipUpdatePacket(this NetState ns, Mobile m, Serial hairSerial, int itemId, int hue, Layer layer)
|
||||
public static void SendHairEquipUpdatePacket(this NetState ns, Mobile m, uint hairSerial, int itemId, int hue, Layer layer)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
|
|
@ -22,7 +22,7 @@ namespace Server
|
|||
ns.Send(buffer);
|
||||
}
|
||||
|
||||
public static void CreateHairEquipUpdatePacket(Span<byte> buffer, Mobile m, Serial hairSerial, int itemId, int hue, Layer layer)
|
||||
public static void CreateHairEquipUpdatePacket(Span<byte> buffer, Mobile m, uint hairSerial, int itemId, int hue, Layer layer)
|
||||
{
|
||||
if (buffer[0] != 0)
|
||||
{
|
||||
|
|
@ -40,7 +40,7 @@ namespace Server
|
|||
writer.Write((short)(m.SolidHueOverride >= 0 ? m.SolidHueOverride : hue));
|
||||
}
|
||||
|
||||
public static void SendRemoveHairPacket(this NetState ns, Serial hairSerial)
|
||||
public static void SendRemoveHairPacket(this NetState ns, uint hairSerial)
|
||||
{
|
||||
if (ns == null)
|
||||
{
|
||||
|
|
@ -52,7 +52,7 @@ namespace Server
|
|||
ns.Send(buffer);
|
||||
}
|
||||
|
||||
public static void CreateRemoveHairPacket(Span<byte> buffer, Serial hairSerial)
|
||||
public static void CreateRemoveHairPacket(Span<byte> buffer, uint hairSerial)
|
||||
{
|
||||
if (buffer[0] != 0)
|
||||
{
|
||||
|
|
@ -121,7 +121,7 @@ namespace Server
|
|||
|
||||
// TODO: Can we make this higher for newer clients?
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint FakeSerial(Serial m) => 0x7FFFFFFF - 0x400 - m * 4;
|
||||
public static uint FakeSerial(Serial m) => 0x7FFFFFFF - 0x400 - m.Value * 4;
|
||||
}
|
||||
|
||||
public class FacialHairInfo : BaseHairInfo
|
||||
|
|
@ -143,6 +143,6 @@ namespace Server
|
|||
|
||||
// TODO: Can we make this higher for newer clients?
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint FakeSerial(Serial m) => 0x7FFFFFFF - 0x400 - 1 - m * 4;
|
||||
public static uint FakeSerial(Serial m) => 0x7FFFFFFF - 0x400 - 1 - m.Value* 4;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -350,12 +350,12 @@ namespace Server.Network
|
|||
var oldestID = 0;
|
||||
var oldest = DateTime.MaxValue;
|
||||
|
||||
foreach (var kvp in m_AuthIDWindow)
|
||||
foreach (var (key, authId) in m_AuthIDWindow)
|
||||
{
|
||||
if (kvp.Value.Age < oldest)
|
||||
if (authId.Age < oldest)
|
||||
{
|
||||
oldestID = kvp.Key;
|
||||
oldest = kvp.Value.Age;
|
||||
oldestID = key;
|
||||
oldest = authId.Age;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ namespace Server.Network
|
|||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int unk = reader.ReadByte();
|
||||
var lang = reader.ReadAscii(3);
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ namespace Server.Network
|
|||
}
|
||||
else
|
||||
{
|
||||
Serial s = value;
|
||||
Serial s = (Serial)value;
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
|
|
@ -104,7 +104,7 @@ namespace Server.Network
|
|||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
Serial s = reader.ReadUInt32();
|
||||
Serial s = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
|
|
@ -167,7 +167,7 @@ namespace Server.Network
|
|||
|
||||
while (reader.Remaining > 0)
|
||||
{
|
||||
Serial s = reader.ReadUInt32();
|
||||
Serial s = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -184,14 +184,14 @@ namespace Server.Network
|
|||
|
||||
public static void PartyMessage_RemoveMember(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
PartyCommands.Handler?.OnRemove(state.Mobile, World.FindMobile(reader.ReadUInt32()));
|
||||
PartyCommands.Handler?.OnRemove(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32()));
|
||||
}
|
||||
|
||||
public static void PartyMessage_PrivateMessage(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
PartyCommands.Handler?.OnPrivateMessage(
|
||||
state.Mobile,
|
||||
World.FindMobile(reader.ReadUInt32()),
|
||||
World.FindMobile((Serial)reader.ReadUInt32()),
|
||||
reader.ReadBigUniSafe()
|
||||
);
|
||||
}
|
||||
|
|
@ -208,12 +208,12 @@ namespace Server.Network
|
|||
|
||||
public static void PartyMessage_Accept(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
PartyCommands.Handler?.OnAccept(state.Mobile, World.FindMobile(reader.ReadUInt32()));
|
||||
PartyCommands.Handler?.OnAccept(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32()));
|
||||
}
|
||||
|
||||
public static void PartyMessage_Decline(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
PartyCommands.Handler?.OnDecline(state.Mobile, World.FindMobile(reader.ReadUInt32()));
|
||||
PartyCommands.Handler?.OnDecline(state.Mobile, World.FindMobile((Serial)reader.ReadUInt32()));
|
||||
}
|
||||
|
||||
public static void Animate(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
|
|
@ -249,7 +249,7 @@ namespace Server.Network
|
|||
return;
|
||||
}
|
||||
|
||||
Item spellbook = reader.ReadInt16() == 1 ? World.FindItem(reader.ReadUInt32()) : null;
|
||||
Item spellbook = reader.ReadInt16() == 1 ? World.FindItem((Serial)reader.ReadUInt32()) : null;
|
||||
|
||||
var spellID = reader.ReadInt16() - 1;
|
||||
EventSink.InvokeCastSpellRequest(from, spellID, spellbook);
|
||||
|
|
@ -317,7 +317,7 @@ namespace Server.Network
|
|||
|
||||
public static void CloseStatus(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
}
|
||||
|
||||
public static void Language(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
|
|
@ -341,7 +341,7 @@ namespace Server.Network
|
|||
|
||||
var from = state.Mobile;
|
||||
|
||||
Serial s = reader.ReadUInt32();
|
||||
Serial s = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (s.IsMobile)
|
||||
{
|
||||
|
|
@ -379,7 +379,7 @@ namespace Server.Network
|
|||
|
||||
if (menu != null && from == menu.From)
|
||||
{
|
||||
var entity = World.FindEntity(reader.ReadUInt32());
|
||||
var entity = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
|
||||
if (entity != null && entity == menu.Target && from.CanSee(entity))
|
||||
{
|
||||
|
|
@ -423,7 +423,7 @@ namespace Server.Network
|
|||
public static void ContextMenuRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var target = World.FindEntity(reader.ReadUInt32());
|
||||
var target = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
|
||||
if (from != null && target != null && from.Map == target.Map && from.CanSee(target))
|
||||
{
|
||||
|
|
@ -466,14 +466,14 @@ namespace Server.Network
|
|||
|
||||
if (from.AccessLevel >= AccessLevel.Counselor || Core.TickCount - from.NextActionTime >= 0)
|
||||
{
|
||||
var bandage = World.FindItem(reader.ReadUInt32());
|
||||
var bandage = World.FindItem((Serial)reader.ReadUInt32());
|
||||
|
||||
if (bandage == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var target = World.FindMobile(reader.ReadUInt32());
|
||||
var target = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
|
|
@ -494,19 +494,19 @@ namespace Server.Network
|
|||
{
|
||||
var spellId = (short)(reader.ReadInt16() - 1); // zero based;
|
||||
|
||||
EventSink.InvokeTargetedSpell(state.Mobile, World.FindEntity(reader.ReadUInt32()), spellId);
|
||||
EventSink.InvokeTargetedSpell(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), spellId);
|
||||
}
|
||||
|
||||
public static void TargetedSkillUse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var skillId = reader.ReadInt16();
|
||||
|
||||
EventSink.InvokeTargetedSkillUse(state.Mobile, World.FindEntity(reader.ReadUInt32()), skillId);
|
||||
EventSink.InvokeTargetedSkillUse(state.Mobile, World.FindEntity((Serial)reader.ReadUInt32()), skillId);
|
||||
}
|
||||
|
||||
public static void TargetByResourceMacro(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (serial.IsItem)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Server.Network
|
|||
|
||||
public static void LiftReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int amount = reader.ReadUInt16();
|
||||
var item = World.FindItem(serial);
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ namespace Server.Network
|
|||
}
|
||||
|
||||
reader.Seek(5, SeekOrigin.Current);
|
||||
var to = World.FindMobile(reader.ReadUInt32()) ?? from;
|
||||
var to = World.FindMobile((Serial)reader.ReadUInt32()) ?? from;
|
||||
|
||||
if (!to.AllowEquipFrom(from) || !to.EquipItem(item))
|
||||
{
|
||||
|
|
@ -79,7 +79,7 @@ namespace Server.Network
|
|||
packetLength -= 1;
|
||||
}
|
||||
|
||||
Serial dest = reader.ReadUInt32();
|
||||
Serial dest = (Serial)reader.ReadUInt32();
|
||||
|
||||
var loc = new Point3D(x, y, z);
|
||||
|
||||
|
|
@ -117,7 +117,7 @@ namespace Server.Network
|
|||
int y = reader.ReadInt16();
|
||||
int z = reader.ReadSByte();
|
||||
reader.ReadByte(); // Grid Location?
|
||||
Serial dest = reader.ReadUInt32();
|
||||
Serial dest = (Serial)reader.ReadUInt32();
|
||||
|
||||
var loc = new Point3D(x, y, z);
|
||||
|
||||
|
|
@ -154,7 +154,7 @@ namespace Server.Network
|
|||
var serialList = new List<Serial>(count);
|
||||
for (var i = 0; i < count; ++i)
|
||||
{
|
||||
serialList.Add(reader.ReadUInt32());
|
||||
serialList.Add((Serial)reader.ReadUInt32());
|
||||
}
|
||||
|
||||
EventSink.InvokeEquipMacro(state.Mobile, serialList);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Server.Network
|
|||
public static void RenameRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
var targ = World.FindMobile(reader.ReadUInt32());
|
||||
var targ = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (targ != null)
|
||||
{
|
||||
|
|
@ -40,7 +40,7 @@ namespace Server.Network
|
|||
|
||||
public static void MobileNameRequest(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var m = World.FindMobile(reader.ReadUInt32());
|
||||
var m = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (m != null && Utility.InUpdateRange(state.Mobile.Location, m.Location) && state.Mobile.CanSee(m))
|
||||
{
|
||||
|
|
@ -51,7 +51,7 @@ namespace Server.Network
|
|||
public static void ProfileReq(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
int type = reader.ReadByte();
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
|
||||
var beholder = state.Mobile;
|
||||
var beheld = World.FindMobile(serial);
|
||||
|
|
@ -94,7 +94,7 @@ namespace Server.Network
|
|||
{
|
||||
case 1: // Cancel
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (World.FindItem(serial) is SecureTradeContainer cont && cont.Trade != null &&
|
||||
(cont.Trade.From.Mobile == state.Mobile || cont.Trade.To.Mobile == state.Mobile))
|
||||
|
|
@ -106,7 +106,7 @@ namespace Server.Network
|
|||
}
|
||||
case 2: // Check
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (World.FindItem(serial) is SecureTradeContainer cont)
|
||||
{
|
||||
|
|
@ -133,7 +133,7 @@ namespace Server.Network
|
|||
}
|
||||
case 3: // Update Gold
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
|
||||
if (World.FindItem(serial) is SecureTradeContainer cont)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ namespace Server.Network
|
|||
return;
|
||||
}
|
||||
|
||||
var m = World.FindMobile(reader.ReadUInt32());
|
||||
var m = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (m != null)
|
||||
{
|
||||
|
|
@ -161,7 +161,7 @@ namespace Server.Network
|
|||
{
|
||||
var tokenizer = command.Tokenize(' ');
|
||||
var spellID = (tokenizer.MoveNext() ? Utility.ToInt32(tokenizer.Current) : 0) - 1;
|
||||
var serial = tokenizer.MoveNext() ? Utility.ToUInt32(tokenizer.Current) : (uint)Serial.MinusOne;
|
||||
var serial = tokenizer.MoveNext() ? (Serial)Utility.ToUInt32(tokenizer.Current) : Serial.MinusOne;
|
||||
|
||||
EventSink.InvokeCastSpellRequest(from, spellID, World.FindItem(serial));
|
||||
|
||||
|
|
@ -340,7 +340,7 @@ namespace Server.Network
|
|||
|
||||
public static void DisplayGumpResponse(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
var typeID = reader.ReadInt32();
|
||||
var buttonID = reader.ReadInt32();
|
||||
|
||||
|
|
@ -461,7 +461,7 @@ namespace Server.Network
|
|||
|
||||
if (buttonID == 1 && switchCount > 0)
|
||||
{
|
||||
var beheld = World.FindMobile(reader.ReadUInt32());
|
||||
var beheld = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (beheld != null)
|
||||
{
|
||||
|
|
@ -523,7 +523,7 @@ namespace Server.Network
|
|||
|
||||
reader.ReadInt32(); // 0xEDEDEDED
|
||||
int type = reader.ReadByte();
|
||||
var m = World.FindMobile(reader.ReadUInt32());
|
||||
var m = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (m == null)
|
||||
{
|
||||
|
|
@ -601,7 +601,7 @@ namespace Server.Network
|
|||
|
||||
public static void EncodedCommand(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var e = World.FindEntity(reader.ReadUInt32());
|
||||
var e = World.FindEntity((Serial)reader.ReadUInt32());
|
||||
int packetId = reader.ReadUInt16();
|
||||
|
||||
var ph = IncomingPackets.GetEncodedHandler(packetId);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ namespace Server.Network
|
|||
int type = reader.ReadByte();
|
||||
var targetID = reader.ReadInt32();
|
||||
int flags = reader.ReadByte();
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int x = reader.ReadInt16();
|
||||
int y = reader.ReadInt16();
|
||||
reader.ReadByte();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Server.Network
|
|||
|
||||
public static void VendorBuyReply(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
var vendor = World.FindMobile(reader.ReadUInt32());
|
||||
var vendor = World.FindMobile((Serial)reader.ReadUInt32());
|
||||
|
||||
if (vendor == null)
|
||||
{
|
||||
|
|
@ -49,7 +49,7 @@ namespace Server.Network
|
|||
while (msgSize > 0)
|
||||
{
|
||||
var layer = reader.ReadByte();
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
int amount = reader.ReadInt16();
|
||||
|
||||
buyList.Add(new BuyItemResponse(serial, amount));
|
||||
|
|
@ -67,7 +67,7 @@ namespace Server.Network
|
|||
|
||||
public static void VendorSellReply(NetState state, CircularBufferReader reader, ref int packetLength)
|
||||
{
|
||||
Serial serial = reader.ReadUInt32();
|
||||
var serial = (Serial)reader.ReadUInt32();
|
||||
var vendor = World.FindMobile(serial);
|
||||
|
||||
if (vendor == null)
|
||||
|
|
@ -92,7 +92,7 @@ namespace Server.Network
|
|||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var item = World.FindItem(reader.ReadUInt32());
|
||||
var item = World.FindItem((Serial)reader.ReadUInt32());
|
||||
int amount = reader.ReadInt16();
|
||||
|
||||
if (item != null && amount > 0)
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ namespace Server.Network
|
|||
var itemID = item is BaseMulti ? item.ItemID | 0x4000 : item.ItemID & 0x3FFF;
|
||||
var amount = item.Amount;
|
||||
var hasAmount = amount != 0;
|
||||
var serial = hasAmount ? item.Serial | 0x80000000 : item.Serial & 0x7FFFFFFF;
|
||||
var serial = hasAmount ? item.Serial.Value | 0x80000000 : item.Serial.Value & 0x7FFFFFFF;
|
||||
var loc = item.Location;
|
||||
var hue = item.Hue;
|
||||
var flags = item.GetPacketFlags();
|
||||
|
|
|
|||
|
|
@ -66,29 +66,65 @@ namespace Server
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Serial l, Serial r) => l.Value == r.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator ==(Serial l, uint r) => l.Value == r;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Serial l, Serial r) => l.Value != r.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator !=(Serial l, uint r) => l.Value != r;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator >(Serial l, Serial r) => l.Value > r.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator >(Serial l, uint r) => l.Value > r;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator <(Serial l, Serial r) => l.Value < r.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator <(Serial l, uint r) => l.Value < r;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator >=(Serial l, Serial r) => l.Value >= r.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator >=(Serial l, uint r) => l.Value >= r;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator <=(Serial l, Serial r) => l.Value <= r.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool operator <=(Serial l, uint r) => l.Value <= r;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Serial operator +(Serial l, Serial r) => (Serial)(l.Value + r.Value);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Serial operator +(Serial l, uint r) => (Serial)(l.Value + r);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Serial operator ++(Serial l) => (Serial)(l.Value + 1);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Serial operator -(Serial l, Serial r) => (Serial)(l.Value - r.Value);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Serial operator -(Serial l, uint r) => (Serial)(l.Value - r);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static Serial operator --(Serial l) => (Serial)(l.Value - 1);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public override string ToString() => $"0x{Value:X8}";
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator uint(Serial a) => a.Value;
|
||||
public static explicit operator uint(Serial a) => a.Value;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static implicit operator Serial(uint a) => new(a);
|
||||
public static explicit operator Serial(uint a) => new(a);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Equals(Serial other) => Value == other.Value;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Server
|
||||
{
|
||||
|
|
@ -26,40 +27,59 @@ namespace Server
|
|||
|
||||
public BinaryFileReader(Stream stream) => _reader = new BinaryReader(stream);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Close() => _reader.Close();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public string ReadString(bool intern = false)
|
||||
{
|
||||
var str = _reader.ReadString();
|
||||
return intern ? Utility.Intern(str) : str;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public long ReadLong() => _reader.ReadInt64();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ulong ReadULong() => _reader.ReadUInt64();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int ReadInt() => _reader.ReadInt32();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint ReadUInt() => _reader.ReadUInt32();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public short ReadShort() => _reader.ReadInt16();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ushort ReadUShort() => _reader.ReadUInt16();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public double ReadDouble() => _reader.ReadDouble();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float ReadFloat() => _reader.ReadSingle();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public byte ReadByte() => _reader.ReadByte();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sbyte ReadSByte() => _reader.ReadSByte();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool ReadBool() => _reader.ReadBoolean();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Serial ReadSerial() => (Serial)_reader.ReadUInt32();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int Read(Span<byte> buffer) => _reader.Read(buffer);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public long Seek(long offset, SeekOrigin origin) => _reader.BaseStream.Seek(offset, origin);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Dispose() => Close();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ using System;
|
|||
using System.Buffers.Binary;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using Server.Text;
|
||||
|
||||
|
|
@ -62,6 +63,7 @@ namespace Server
|
|||
return intern ? Utility.Intern(str) : str;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public long ReadLong()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadInt64LittleEndian(_buffer.AsSpan(_position, 8));
|
||||
|
|
@ -69,6 +71,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ulong ReadULong()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadUInt64LittleEndian(_buffer.AsSpan(_position, 8));
|
||||
|
|
@ -76,6 +79,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public int ReadInt()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadInt32LittleEndian(_buffer.AsSpan(_position, 4));
|
||||
|
|
@ -83,6 +87,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public uint ReadUInt()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadUInt32LittleEndian(_buffer.AsSpan(_position, 4));
|
||||
|
|
@ -90,6 +95,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public short ReadShort()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadInt16LittleEndian(_buffer.AsSpan(_position, 2));
|
||||
|
|
@ -97,6 +103,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public ushort ReadUShort()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadUInt16LittleEndian(_buffer.AsSpan(_position, 2));
|
||||
|
|
@ -104,6 +111,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public double ReadDouble()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadDoubleLittleEndian(_buffer.AsSpan(_position, 8));
|
||||
|
|
@ -111,6 +119,7 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public float ReadFloat()
|
||||
{
|
||||
var v = BinaryPrimitives.ReadSingleLittleEndian(_buffer.AsSpan(_position, 4));
|
||||
|
|
@ -118,12 +127,18 @@ namespace Server
|
|||
return v;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public byte ReadByte() => _buffer[_position++];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public sbyte ReadSByte() => (sbyte)_buffer[_position++];
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool ReadBool() => _buffer[_position++] != 0;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public Serial ReadSerial() => (Serial)ReadUInt();
|
||||
|
||||
public int Read(Span<byte> buffer)
|
||||
{
|
||||
var length = buffer.Length;
|
||||
|
|
|
|||
|
|
@ -286,6 +286,9 @@ namespace Server
|
|||
_buffer[Index++] = *(byte*)&value; // up to 30% faster to dereference the raw value on the stack
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Write(Serial serial) => Write(serial.Value);
|
||||
|
||||
internal void InternalWriteString(string value)
|
||||
{
|
||||
var remaining = m_Encoding.GetByteCount(value);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ namespace Server
|
|||
byte ReadByte();
|
||||
sbyte ReadSByte();
|
||||
bool ReadBool();
|
||||
Serial ReadSerial();
|
||||
|
||||
DateTime ReadDateTime() => new(ReadLong(), DateTimeKind.Utc);
|
||||
TimeSpan ReadTimeSpan() => new(ReadLong());
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ namespace Server
|
|||
void Write(byte value);
|
||||
void Write(sbyte value);
|
||||
void Write(bool value);
|
||||
void Write(Serial serial);
|
||||
|
||||
void Write(DateTime value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ namespace Server
|
|||
|
||||
public EntityTypeIndex(string typeName) => TypeName = typeName;
|
||||
|
||||
public Serial CreateIndex(uint num) => num;
|
||||
public Serial CreateIndex(uint num) => (Serial)num;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,22 +55,23 @@ namespace Server
|
|||
private const uint _maxItems = MaxItemSerial - ItemOffset + 1;
|
||||
|
||||
private static Serial _lastMobile = Serial.Zero;
|
||||
private static Serial _lastItem = ItemOffset;
|
||||
private static Serial _lastItem = (Serial)ItemOffset;
|
||||
private static Serial _lastGuild = Serial.Zero;
|
||||
|
||||
public static Serial NewMobile
|
||||
{
|
||||
get
|
||||
{
|
||||
uint last = _lastMobile;
|
||||
var last = _lastMobile;
|
||||
var maxMobile = (Serial)MaxMobileSerial;
|
||||
|
||||
for (int i = 0; i < MaxMobileSerial; i++)
|
||||
{
|
||||
last++;
|
||||
|
||||
if (last > MaxMobileSerial)
|
||||
if (last > maxMobile)
|
||||
{
|
||||
last = 1;
|
||||
last = (Serial)1;
|
||||
}
|
||||
|
||||
if (FindMobile(last) == null)
|
||||
|
|
@ -88,7 +89,7 @@ namespace Server
|
|||
{
|
||||
get
|
||||
{
|
||||
uint last = _lastItem;
|
||||
var last = _lastItem;
|
||||
|
||||
for (int i = 0; i < _maxItems; i++)
|
||||
{
|
||||
|
|
@ -96,7 +97,7 @@ namespace Server
|
|||
|
||||
if (last > MaxItemSerial)
|
||||
{
|
||||
last = ItemOffset;
|
||||
last = (Serial)ItemOffset;
|
||||
}
|
||||
|
||||
if (FindItem(last) == null)
|
||||
|
|
@ -648,7 +649,7 @@ namespace Server
|
|||
|
||||
public static T ReadEntity<T>(this IGenericReader reader) where T : class, ISerializable
|
||||
{
|
||||
Serial serial = reader.ReadUInt();
|
||||
Serial serial = reader.ReadSerial();
|
||||
var typeT = typeof(T);
|
||||
|
||||
// Add to this list when creating new serializable types
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue