fix(core): Fixes packet issues with hair/beard (#669)

This commit is contained in:
Kamron Batman 2021-08-01 19:54:04 -07:00 committed by GitHub
parent ebac984543
commit f78a226321
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 37 deletions

View file

@ -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, Layer layer)
public static void SendHairEquipUpdatePacket(this NetState ns, Mobile m, Serial hairSerial, int itemId, int hue, Layer layer)
{
if (ns == null)
{
@ -18,28 +18,26 @@ namespace Server
}
Span<byte> buffer = stackalloc byte[EquipUpdatePacketLength];
CreateHairEquipUpdatePacket(buffer, m, hairSerial, layer);
CreateHairEquipUpdatePacket(buffer, m, hairSerial, itemId, hue, layer);
ns.Send(buffer);
}
public static void CreateHairEquipUpdatePacket(Span<byte> buffer, Mobile m, Serial hairSerial, Layer layer)
public static void CreateHairEquipUpdatePacket(Span<byte> buffer, Mobile m, Serial hairSerial, int itemId, int hue, Layer layer)
{
if (buffer[0] != 0)
{
return;
}
var hue = m.SolidHueOverride >= 0 ? m.SolidHueOverride : m.HairHue;
var writer = new SpanWriter(buffer);
writer.Write((byte)0x2E); // Packet ID
writer.Write(hairSerial);
writer.Write((short)m.HairItemID);
writer.Write((short)itemId);
writer.Write((byte)0);
writer.Write((byte)layer);
writer.Write(m.Serial);
writer.Write((short)hue);
writer.Write((short)(m.SolidHueOverride >= 0 ? m.SolidHueOverride : hue));
}
public static void SendRemoveHairPacket(this NetState ns, Serial hairSerial)

View file

@ -2975,6 +2975,20 @@ namespace Server
sendFacialHair = true;
}
var hairSerial = HairInfo.FakeSerial(Serial);
var hairLength = removeHair
? OutgoingVirtualHairPackets.RemovePacketLength
: OutgoingVirtualHairPackets.EquipUpdatePacketLength;
Span<byte> hairPacket = stackalloc byte[hairLength].InitializePacket();
var facialHairSerial = FacialHairInfo.FakeSerial(Serial);
var facialHairLength = removeFacialHair
? OutgoingVirtualHairPackets.RemovePacketLength
: OutgoingVirtualHairPackets.EquipUpdatePacketLength;
Span<byte> facialhairPacket = stackalloc byte[facialHairLength].InitializePacket();
const int cacheLength = OutgoingMobilePackets.MobileMovingPacketCacheByteLength;
const int width = OutgoingMobilePackets.MobileMovingPacketLength;
const int height = OutgoingMobilePackets.MobileMovingPacketCacheHeight;
@ -3060,24 +3074,41 @@ namespace Server
{
if (removeHair)
{
ourState.SendRemoveHairPacket(HairInfo.FakeSerial(Serial));
OutgoingVirtualHairPackets.CreateRemoveHairPacket(hairPacket, hairSerial);
}
else
{
ourState.SendHairEquipUpdatePacket(this, HairInfo.FakeSerial(Serial), Layer.Hair);
OutgoingVirtualHairPackets.CreateHairEquipUpdatePacket(
hairPacket,
this,
hairSerial,
HairItemID,
HairHue,
Layer.Hair
);
}
ourState.Send(hairPacket);
}
if (sendFacialHair)
{
if (removeFacialHair)
{
ourState.SendRemoveHairPacket(FacialHairInfo.FakeSerial(Serial));
OutgoingVirtualHairPackets.CreateRemoveHairPacket(facialhairPacket, facialHairSerial);
}
else
{
ourState.SendHairEquipUpdatePacket(this, FacialHairInfo.FakeSerial(Serial), Layer.FacialHair);
OutgoingVirtualHairPackets.CreateHairEquipUpdatePacket(
facialhairPacket,
this,
facialHairSerial,
FacialHairItemID,
FacialHairHue,
Layer.FacialHair
);
}
ourState.Send(facialhairPacket);
}
if (sendOPLUpdate)
@ -3113,18 +3144,6 @@ namespace Server
Span<byte> removeEntity = stackalloc byte[OutgoingEntityPackets.RemoveEntityLength].InitializePacket();
Span<byte> hitsPacket = stackalloc byte[OutgoingMobilePackets.MobileAttributePacketLength].InitializePacket();
var hairLength = removeHair
? OutgoingVirtualHairPackets.RemovePacketLength
: OutgoingVirtualHairPackets.EquipUpdatePacketLength;
Span<byte> hairPacket = stackalloc byte[hairLength].InitializePacket();
var facialHairLength = removeFacialHair
? OutgoingVirtualHairPackets.RemovePacketLength
: OutgoingVirtualHairPackets.EquipUpdatePacketLength;
Span<byte> facialhairPacket = stackalloc byte[facialHairLength].InitializePacket();
foreach (var state in eable)
{
var beholder = state.Mobile;
@ -3192,7 +3211,6 @@ namespace Server
if (sendHair)
{
var hairSerial = HairInfo.FakeSerial(Serial);
if (removeHair)
{
OutgoingVirtualHairPackets.CreateRemoveHairPacket(hairPacket, hairSerial);
@ -3203,6 +3221,8 @@ namespace Server
hairPacket,
this,
hairSerial,
HairItemID,
HairHue,
Layer.Hair
);
}
@ -3212,17 +3232,18 @@ namespace Server
if (sendFacialHair)
{
var hairSerial = HairInfo.FakeSerial(Serial);
if (removeFacialHair)
{
OutgoingVirtualHairPackets.CreateRemoveHairPacket(facialhairPacket, hairSerial);
OutgoingVirtualHairPackets.CreateRemoveHairPacket(facialhairPacket, facialHairSerial);
}
else
{
OutgoingVirtualHairPackets.CreateHairEquipUpdatePacket(
facialhairPacket,
this,
hairSerial,
facialHairSerial,
FacialHairItemID,
FacialHairHue,
Layer.FacialHair
);
}

View file

@ -46,7 +46,7 @@ namespace Server.Items
private class InternalGump : Gump
{
private readonly int[][] ElvenArray =
private static readonly int[][] ElvenArray =
{
new[] { 0 },
new[] { 1011064, 1011064, 0, 0, 0, 0 }, // bald
@ -63,7 +63,7 @@ namespace Server.Items
/*
racial arrays are: cliloc_F, cliloc_M, ItemID_F, ItemID_M, gump_img_F, gump_img_M
*/
private readonly int[][] HumanArray = /* why on earth cant these utilies be consistent with hex/dec */
private static readonly int[][] HumanArray = /* why on earth cant these utilities be consistent with hex/dec */
{
new[] { 0 },
new[] { 1011064, 1011064, 0, 0, 0, 0 }, // bald
@ -77,11 +77,11 @@ namespace Server.Items
new[] { 1011050, 1011050, 0x204A, 0x204A, 0xED29, 0xED29 }, // Topknot
new[] { 1011396, 1011396, 0x2047, 0x2047, 0xed25, 0xc618 } // Curly
};
/*
gump data: bgX, bgY, htmlX, htmlY, imgX, imgY, butX, butY
*/
private readonly int[][] LayoutArray =
private static readonly int[][] LayoutArray =
{
new[] { 0 }, /* padding: its more efficient than code to ++ the index/buttonid */
new[] { 425, 280, 342, 295, 000, 000, 310, 292 },

View file

@ -416,9 +416,9 @@ namespace Server.Mobiles
m_Vendor.PrivateOverheadMessage(
MessageType.Regular,
0x3B2,
1042293,
1042293, // You cannot afford my services for that style.
m_From.NetState
); // You cannot afford my services for that style.
);
return;
}
@ -439,9 +439,9 @@ namespace Server.Mobiles
m_Vendor.PrivateOverheadMessage(
MessageType.Regular,
0x3B2,
502623,
502623, // You have no hair to dye and you cannot use this.
m_From.NetState
); // You have no hair to dye and you cannot use this.
);
}
}
}
@ -638,9 +638,9 @@ namespace Server.Mobiles
m_Vendor.PrivateOverheadMessage(
MessageType.Regular,
0x3B2,
1042293,
1042293, // You cannot afford my services for that style.
m_From.NetState
); // You cannot afford my services for that style.
);
}
}
else