Skip to content

Commit

Permalink
Merge branch 'main' into kbatman/krec_support
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Jun 17, 2022
2 parents 00bf501 + 57f81a0 commit 09d7193
Show file tree
Hide file tree
Showing 37 changed files with 1,224 additions and 1,057 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"modernuoschemagenerator": {
"version": "2.1.0",
"version": "2.1.2",
"commands": [
"ModernUOSchemaGenerator"
]
Expand Down
2 changes: 0 additions & 2 deletions Projects/Server/Buffers/SpanWriter.cs
Expand Up @@ -14,9 +14,7 @@
*************************************************************************/

using System.Buffers.Binary;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
1 change: 0 additions & 1 deletion Projects/Server/Localization/LocalizationEntry.cs
Expand Up @@ -14,7 +14,6 @@
*************************************************************************/

using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using Server.Buffers;
Expand Down
40 changes: 26 additions & 14 deletions Projects/Server/Network/EncodedPacketHandler.cs
@@ -1,20 +1,32 @@
namespace Server.Network
{
public delegate void OnEncodedPacketReceive(NetState state, IEntity ent, EncodedReader reader);
/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: EncodedPacketHandler.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/>. *
*************************************************************************/

namespace Server.Network;

public class EncodedPacketHandler
public unsafe class EncodedPacketHandler
{
public EncodedPacketHandler(int packetID, bool ingame, delegate*<NetState, IEntity, EncodedReader, void> onReceive)
{
public EncodedPacketHandler(int packetID, bool ingame, OnEncodedPacketReceive onReceive)
{
PacketID = packetID;
Ingame = ingame;
OnReceive = onReceive;
}
PacketID = packetID;
Ingame = ingame;
OnReceive = onReceive;
}

public int PacketID { get; }
public int PacketID { get; }

public OnEncodedPacketReceive OnReceive { get; }
public delegate*<NetState, IEntity, EncodedReader, void> OnReceive { get; }

public bool Ingame { get; }
}
public bool Ingame { get; }
}
47 changes: 29 additions & 18 deletions Projects/Server/Network/EncodedReader.cs
@@ -1,26 +1,37 @@
namespace Server.Network
/*************************************************************************
* ModernUO *
* Copyright 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: EncodedReader.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/>. *
*************************************************************************/

namespace Server.Network;

public ref struct EncodedReader
{
public ref struct EncodedReader
{
private CircularBufferReader m_Reader;
private CircularBufferReader _reader;

public EncodedReader(CircularBufferReader reader) => m_Reader = reader;
public EncodedReader(CircularBufferReader reader) => _reader = reader;

public void Trace(NetState state)
{
m_Reader.Trace(state);
}
public void Trace(NetState state) => _reader.Trace(state);

public int ReadInt32() => m_Reader.ReadByte() != 0 ? 0 : m_Reader.ReadInt32();
public int ReadInt32() => _reader.ReadByte() != 0 ? 0 : _reader.ReadInt32();

public Point3D ReadPoint3D() => m_Reader.ReadByte() != 3
? Point3D.Zero
: new Point3D(m_Reader.ReadInt16(), m_Reader.ReadInt16(), m_Reader.ReadByte());
public Point3D ReadPoint3D() => _reader.ReadByte() != 3
? Point3D.Zero
: new Point3D(_reader.ReadInt16(), _reader.ReadInt16(), _reader.ReadByte());

public string ReadUnicodeStringSafe() =>
m_Reader.ReadByte() != 2 ? string.Empty : m_Reader.ReadBigUniSafe(m_Reader.ReadUInt16());
public string ReadUnicodeStringSafe() =>
_reader.ReadByte() != 2 ? string.Empty : _reader.ReadBigUniSafe(_reader.ReadUInt16());

public string ReadUnicodeString() =>
m_Reader.ReadByte() != 2 ? string.Empty : m_Reader.ReadBigUni(m_Reader.ReadUInt16());
}
public string ReadUnicodeString() =>
_reader.ReadByte() != 2 ? string.Empty : _reader.ReadBigUni(_reader.ReadUInt16());
}
4 changes: 3 additions & 1 deletion Projects/Server/Network/Packets/IncomingPackets.cs
Expand Up @@ -35,7 +35,9 @@ public static void Register(PacketHandler packetHandler)

public static PacketHandler GetHandler(int packetID) => Handlers[packetID];

public static void RegisterEncoded(int packetID, bool ingame, OnEncodedPacketReceive onReceive)
public static unsafe void RegisterEncoded(
int packetID, bool ingame, delegate*<NetState, IEntity, EncodedReader, void> onReceive
)
{
if (packetID is >= 0 and < 0x100)
{
Expand Down
6 changes: 3 additions & 3 deletions Projects/Server/Network/Packets/IncomingPlayerPackets.cs
Expand Up @@ -48,8 +48,8 @@ public static unsafe void Configure()
IncomingPackets.Register(0xD7, 0, true, &EncodedCommand);
IncomingPackets.Register(0xF4, 0, false, &CrashReport);

IncomingPackets.RegisterEncoded(0x28, true, GuildGumpRequest);
IncomingPackets.RegisterEncoded(0x32, true, QuestGumpRequest);
IncomingPackets.RegisterEncoded(0x28, true, &GuildGumpRequest);
IncomingPackets.RegisterEncoded(0x32, true, &QuestGumpRequest);
}

public static void DeathStatusResponse(NetState state, CircularBufferReader reader, int packetLength)
Expand Down Expand Up @@ -593,7 +593,7 @@ public static void QuestGumpRequest(NetState state, IEntity e, EncodedReader rea
EventSink.InvokeQuestGumpRequest(state.Mobile);
}

public static void EncodedCommand(NetState state, CircularBufferReader reader, int packetLength)
public static unsafe void EncodedCommand(NetState state, CircularBufferReader reader, int packetLength)
{
var e = World.FindEntity((Serial)reader.ReadUInt32());
int packetId = reader.ReadUInt16();
Expand Down
1 change: 0 additions & 1 deletion Projects/Server/Regions/RegionLoader.cs
Expand Up @@ -13,7 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Server.csproj
Expand Up @@ -41,7 +41,7 @@
<PackageReference Include="Zlib.Bindings" Version="1.9.2" />

<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.0.2" />
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.1.0" />
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.1.2" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Migrations/*.v*.json" />
Expand Down
1 change: 0 additions & 1 deletion Projects/UOContent/Engines/Plants/PlantItem.cs
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using Server.ContextMenus;
using Server.Gumps;
Expand Down
1 change: 0 additions & 1 deletion Projects/UOContent/Items/Deeds/CommodityDeed.cs
@@ -1,6 +1,5 @@
using ModernUO.Serialization;
using Server.Targeting;
using Server.Text;

namespace Server.Items;

Expand Down
97 changes: 45 additions & 52 deletions Projects/UOContent/Items/Games/Mahjong/MahjongDealerIndicator.cs
@@ -1,69 +1,62 @@
namespace Server.Engines.Mahjong
{
public class MahjongDealerIndicator
{
public MahjongDealerIndicator(MahjongGame game, Point2D position, MahjongPieceDirection direction, MahjongWind wind)
{
Game = game;
Position = position;
Direction = direction;
Wind = wind;
}
using ModernUO.Serialization;

public MahjongDealerIndicator(MahjongGame game, IGenericReader reader)
{
Game = game;
namespace Server.Engines.Mahjong;

var version = reader.ReadInt();
[SerializationGenerator(1, false)]
public partial class MahjongDealerIndicator
{
[DirtyTrackingEntity]
private readonly MahjongGame _game;

Position = reader.ReadPoint2D();
Direction = (MahjongPieceDirection)reader.ReadInt();
Wind = (MahjongWind)reader.ReadInt();
}
[SerializableField(0, setter: "private")]
private Point2D _position;

public MahjongGame Game { get; }
[SerializableField(1, setter: "private")]
private MahjongPieceDirection _direction;

public Point2D Position { get; private set; }
[SerializableField(2, setter: "private")]
private MahjongWind _wind;

public MahjongPieceDirection Direction { get; private set; }
public MahjongDealerIndicator(MahjongGame game)
{
_game = game;
}

public MahjongWind Wind { get; private set; }
public MahjongDealerIndicator(MahjongGame game, Point2D position, MahjongPieceDirection direction, MahjongWind wind)
{
_game = game;
_position = position;
_direction = direction;
_wind = wind;
}

public MahjongPieceDim Dimensions => GetDimensions(Position, Direction);
public MahjongPieceDim Dimensions => GetDimensions(_position, _direction);

public static MahjongPieceDim GetDimensions(Point2D position, MahjongPieceDirection direction)
{
if (direction is MahjongPieceDirection.Up or MahjongPieceDirection.Down)
{
return new MahjongPieceDim(position, 40, 20);
}
public static MahjongPieceDim GetDimensions(Point2D position, MahjongPieceDirection direction) =>
direction is MahjongPieceDirection.Up or MahjongPieceDirection.Down
? new MahjongPieceDim(position, 40, 20)
: new MahjongPieceDim(position, 20, 40);

return new MahjongPieceDim(position, 20, 40);
}
public void Move(Point2D position, MahjongPieceDirection direction, MahjongWind wind)
{
var dim = GetDimensions(position, direction);

public void Move(Point2D position, MahjongPieceDirection direction, MahjongWind wind)
if (!dim.IsValid())
{
var dim = GetDimensions(position, direction);

if (!dim.IsValid())
{
return;
}

Position = position;
Direction = direction;
Wind = wind;

Game.Players.SendGeneralPacket(true, true);
return;
}

public void Save(IGenericWriter writer)
{
writer.Write(0); // version
_position = position;
_direction = direction;
_wind = wind;

writer.Write(Position);
writer.Write((int)Direction);
writer.Write((int)Wind);
}
_game.Players.SendGeneralPacket(true, true);
}

private void Deserialize(IGenericReader reader, int version)
{
_position = reader.ReadPoint2D();
_direction = (MahjongPieceDirection)reader.ReadInt();
_wind = (MahjongWind)reader.ReadInt();
}
}
65 changes: 25 additions & 40 deletions Projects/UOContent/Items/Games/Mahjong/MahjongDices.cs
@@ -1,52 +1,37 @@
namespace Server.Engines.Mahjong
{
public class MahjongDices
{
public MahjongDices(MahjongGame game)
{
Game = game;
First = Utility.Random(1, 6);
Second = Utility.Random(1, 6);
}
using ModernUO.Serialization;

public MahjongDices(MahjongGame game, IGenericReader reader)
{
Game = game;
namespace Server.Engines.Mahjong;

var version = reader.ReadInt();
[SerializationGenerator(0, false)]
public partial class MahjongDices
{
[DirtyTrackingEntity]
private readonly MahjongGame _game;

First = reader.ReadInt();
Second = reader.ReadInt();
}
[SerializableField(0, setter: "private")]
private int _first;

public MahjongGame Game { get; }
[SerializableField(1, setter: "private")]
private int _second;

public int First { get; private set; }
public MahjongDices(MahjongGame game)
{
_game = game;
_first = Utility.Random(1, 6);
_second = Utility.Random(1, 6);
}

public int Second { get; private set; }
public void RollDices(Mobile from)
{
_first = Utility.Random(1, 6);
_second = Utility.Random(1, 6);

public void RollDices(Mobile from)
{
First = Utility.Random(1, 6);
Second = Utility.Random(1, 6);

Game.Players.SendGeneralPacket(true, true);

if (from != null)
{
Game.Players.SendLocalizedMessage(
1062695,
$"{from.Name}\t{First}\t{Second}"
); // ~1_name~ rolls the dice and gets a ~2_number~ and a ~3_number~!
}
}
_game.Players.SendGeneralPacket(true, true);

public void Save(IGenericWriter writer)
if (from != null)
{
writer.Write(0); // version

writer.Write(First);
writer.Write(Second);
// ~1_name~ rolls the dice and gets a ~2_number~ and a ~3_number~!
_game.Players.SendLocalizedMessage(1062695, $"{from.Name}\t{_first}\t{_second}");
}
}
}

0 comments on commit 09d7193

Please sign in to comment.