Skip to content

Commit

Permalink
Merge pull request #565 from MUnique/dev/#564-fix-socket-serialization
Browse files Browse the repository at this point in the history
Fixed socket bonus option serialization
  • Loading branch information
sven-n authored Dec 31, 2024
2 parents 0039043 + e30f071 commit 6b015c4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/GameServer/RemoteView/ItemSerializerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static void ReadSockets(Span<byte> socketBytes, IContext persistenceConte
/// <param name="item">The item.</param>
public static void ReadSocketBonus(byte socketBonusByte, IContext persistenceContext, Item item)
{
if (socketBonusByte == 0 || socketBonusByte == 0xFF)
if (socketBonusByte == 0 || socketBonusByte == 0xFF || socketBonusByte == 0xF)
{
return;
}
Expand Down
45 changes: 45 additions & 0 deletions tests/MUnique.OpenMU.Tests/ItemSerializerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,51 @@ public void AncientWithoutBonus()
}
}

/// <summary>
/// Tests if socket items are correctly (de)serialized.
/// </summary>
[Test]
public void Sockets()
{
var tuple = this.SerializeAndDeserializeFlamberge();
var item = tuple.Item1;
var deserializedItem = tuple.Item2;
Assert.That(deserializedItem.ItemOptions.Count, Is.EqualTo(item.ItemOptions.Count));
foreach (var optionLink in item.ItemOptions)
{
var deserializedOptionLink = deserializedItem.ItemOptions
.FirstOrDefault(link => link.Level == optionLink.Level
&& link.ItemOption!.OptionType == optionLink.ItemOption!.OptionType
&& link.ItemOption.Number == optionLink.ItemOption.Number);
Assert.That(deserializedOptionLink, Is.Not.Null, () => $"Option Link not found: {optionLink.ItemOption!.OptionType!.Name}, {optionLink.ItemOption.PowerUpDefinition}, Level: {optionLink.Level}");
}

Assert.That(deserializedItem.SocketCount, Is.EqualTo(item.SocketCount));
}

private Tuple<Item, Item> SerializeAndDeserializeFlamberge()
{
using var context = this._contextProvider.CreateNewContext(this._gameConfiguration);
var item = context.CreateNew<Item>();
item.Definition = this._gameConfiguration.Items.First(i => i.Group == 0 && i.Number == 26);
item.Level = 15;
item.Durability = 100;
item.HasSkill = true;
item.SocketCount = 3;

var socketOption = context.CreateNew<ItemOptionLink>();
socketOption.ItemOption = this._gameConfiguration.ItemOptions.SelectMany(o => o.PossibleOptions).FirstOrDefault(o => o.OptionType == ItemOptionTypes.SocketOption);
socketOption.Index = 1;
socketOption.Level = 1;
item.ItemOptions.Add(socketOption);

var array = new byte[this._itemSerializer.NeededSpace];
this._itemSerializer.SerializeItem(array, item);

var deserializedItem = this._itemSerializer.DeserializeItem(array, this._gameConfiguration, context);
return new Tuple<Item, Item>(item, deserializedItem);
}

private Tuple<Item, Item> SerializeAndDeserializeHyonLightingSword()
{
using var context = this._contextProvider.CreateNewContext(this._gameConfiguration);
Expand Down

0 comments on commit 6b015c4

Please sign in to comment.