ModernUO/Projects/UOContent/Engines/Party/PartyPackets.cs
mark1145 053dbcbad0
fix: Fixes ignoring mobs, champions, party crash, slayer rarity, boat speedhack, etc (#1222)
* Movie ignore mobiles to Mobile class
* Allow necromancer familiars to ignore mobiles
* ChampionSpawn should not quietly fail when creating new spawn
* Fix client party crash bug: 2 people partied, the leader logs out, other client is hung
* Fix spellbooks creating with magery/meditation only and creating magery multiple times
* Fix BaseRunicTool.GetRandomSlayer() creating more undead slayers than intended
* Do not allow players to dismount each other whilst mounted
* Fix AOS onwards damage increase tooltip and wrong formula in AOS
* Fix monsters killing other monster revenants + animate dead should not attack player pets + other animates
* Fix fire steed having loot pack added twice
* Fix oaks spawn not able to create Unicorns + Kirins via Activator.CreateInstace() due to constructor having name as parametr
* Fix ignoreMobiles flag not propagated to client for non-players.
* Fix harrower tents not leeching from players
* Fix boats speedhacking around the map
* Fix bless, agility etc. not renewing duration
* Fix reveal always worked
* Fix empty constructor for steeds so they don't throw now.
2022-10-31 22:16:50 -07:00

154 lines
5.3 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: PartyPackets.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;
using System.Buffers;
using System.Runtime.CompilerServices;
using Server.Network;
namespace Server.Engines.PartySystem
{
public static class PartyPackets
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetPartyMemberListPacketLength(int partyCount) => 7 + partyCount * 4;
public static void CreatePartyMemberList(Span<byte> buffer, Party p)
{
if (buffer[0] != 0)
{
return;
}
var count = p.Count;
var length = GetPartyMemberListPacketLength(count);
var writer = new SpanWriter(buffer);
writer.Write((byte)0xBF); // Packet ID
writer.Write((ushort)length);
writer.Write((ushort)0x06); // Sub-packet
writer.Write((byte)0x01); // Command
writer.Write((byte)count);
for (var i = 0; i < count; ++i)
{
writer.Write(p[i].Mobile.Serial);
}
}
public static void SendPartyMemberList(this NetState ns, Party p)
{
if (ns.CannotSendPackets())
{
return;
}
Span<byte> buffer = stackalloc byte[GetPartyMemberListPacketLength(p.Count)];
CreatePartyMemberList(buffer, p);
ns.Send(buffer);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetPartyRemoveMemberPacketLength(int partyCount) => 11 + partyCount * 4;
public static void SendPartyRemoveMember(this NetState ns, Serial m, Party p = null)
{
if (ns.CannotSendPackets())
{
return;
}
Span<byte> buffer = stackalloc byte[GetPartyRemoveMemberPacketLength(p?.Count ?? 0)];
CreatePartyRemoveMember(buffer, m, p);
ns.Send(buffer);
}
public static void CreatePartyRemoveMember(Span<byte> buffer, Serial removed, Party p = null)
{
if (buffer[0] != 0)
{
return;
}
var count = p?.Count ?? 0;
var length = GetPartyRemoveMemberPacketLength(count);
var writer = new SpanWriter(buffer);
writer.Write((byte)0xBF); // Packet ID
writer.Write((ushort)length);
writer.Write((ushort)0x06); // Sub-packet
writer.Write((byte)0x02); // Command
writer.Write((byte)count);
writer.Write(removed);
for (var i = 0; i < count; ++i)
{
writer.Write(p![i].Mobile.Serial);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetPartyTextMessagePacketLength(string text) => 12 + (text?.Length * 2 ?? 0);
public static void SendPartyTextMessage(this NetState ns, Serial m, string text, bool toAll)
{
if (ns.CannotSendPackets())
{
return;
}
Span<byte> buffer = stackalloc byte[GetPartyTextMessagePacketLength(text)];
CreatePartyTextMessage(buffer, m, text, toAll);
ns.Send(buffer);
}
public static void CreatePartyTextMessage(Span<byte> buffer, Serial m, string text, bool toAll)
{
if (buffer[0] != 0)
{
return;
}
var length = GetPartyTextMessagePacketLength(text);
var writer = new SpanWriter(buffer);
writer.Write((byte)0xBF); // Packet ID
writer.Write((ushort)length);
writer.Write((ushort)0x06); // Sub-packet
writer.Write((byte)(toAll ? 0x04 : 0x03));
writer.Write(m);
writer.WriteBigUniNull(text);
}
public static void SendPartyInvitation(this NetState ns, Serial leader)
{
if (ns.CannotSendPackets())
{
return;
}
Span<byte> buffer = stackalloc byte[10];
var writer = new SpanWriter(buffer);
writer.Write((byte)0xBF); // Packet ID
writer.Write((ushort)10);
writer.Write((ushort)0x06); // Sub-packet
writer.Write((byte)0x07); // command
writer.Write(leader);
ns.Send(buffer);
}
}
}