Updates Light Packets & World Loading (#316)
- [X] Changes light packets - [X] Updates world loading Bumps release version
This commit is contained in:
parent
313eda6a3e
commit
d2cfeb06ab
9 changed files with 112 additions and 115 deletions
|
|
@ -1,18 +1,3 @@
|
||||||
/*************************************************************************
|
|
||||||
* ModernUO *
|
|
||||||
* Copyright 2019-2020 - ModernUO Development Team *
|
|
||||||
* Email: hi@modernuo.com *
|
|
||||||
* File: EffectPackets.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
|
namespace Server.Network
|
||||||
{
|
{
|
||||||
public sealed class PlaySound : Packet
|
public sealed class PlaySound : Packet
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,3 @@
|
||||||
/*************************************************************************
|
|
||||||
* ModernUO *
|
|
||||||
* Copyright 2019-2020 - ModernUO Development Team *
|
|
||||||
* Email: hi@modernuo.com *
|
|
||||||
* File: EquipmentPackets.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;
|
||||||
|
|
||||||
namespace Server.Network
|
namespace Server.Network
|
||||||
|
|
|
||||||
|
|
@ -11,32 +11,27 @@ namespace Server.Tests.Network
|
||||||
public void TestGlobalLightLevel()
|
public void TestGlobalLightLevel()
|
||||||
{
|
{
|
||||||
byte lightLevel = 5;
|
byte lightLevel = 5;
|
||||||
var data = new GlobalLightLevel(lightLevel).Compile();
|
var expected = new GlobalLightLevel(lightLevel).Compile();
|
||||||
|
|
||||||
Span<byte> expectedData = stackalloc byte[2];
|
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||||
var pos = 0;
|
ns.SendGlobalLightLevel(lightLevel);
|
||||||
|
|
||||||
expectedData.Write(ref pos, (byte)0x4F); // Packet ID
|
var result = ns.SendPipe.Reader.TryRead();
|
||||||
expectedData.Write(ref pos, lightLevel);
|
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||||
|
|
||||||
AssertThat.Equal(data, expectedData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestPersonalLightLevel()
|
public void TestPersonalLightLevel()
|
||||||
{
|
{
|
||||||
Serial serial = 0x1;
|
Serial serial = 0x1024;
|
||||||
byte lightLevel = 5;
|
byte lightLevel = 5;
|
||||||
var data = new PersonalLightLevel(serial, lightLevel).Compile();
|
var expected = new PersonalLightLevel(serial, lightLevel).Compile();
|
||||||
|
|
||||||
Span<byte> expectedData = stackalloc byte[6];
|
using var ns = PacketTestUtilities.CreateTestNetState();
|
||||||
var pos = 0;
|
ns.SendPersonalLightLevel(serial, lightLevel);
|
||||||
|
|
||||||
expectedData.Write(ref pos, (byte)0x4E); // Packet ID
|
var result = ns.SendPipe.Reader.TryRead();
|
||||||
expectedData.Write(ref pos, serial);
|
AssertThat.Equal(result.Buffer[0].AsSpan(0), expected);
|
||||||
expectedData.Write(ref pos, lightLevel);
|
|
||||||
|
|
||||||
AssertThat.Equal(data, expectedData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
namespace Server.Network
|
||||||
|
{
|
||||||
|
public sealed class GlobalLightLevel : Packet
|
||||||
|
{
|
||||||
|
private static readonly GlobalLightLevel[] m_Cache = new GlobalLightLevel[0x100];
|
||||||
|
|
||||||
|
public GlobalLightLevel(int level) : base(0x4F, 2)
|
||||||
|
{
|
||||||
|
Stream.Write((sbyte)level);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GlobalLightLevel Instantiate(int level)
|
||||||
|
{
|
||||||
|
var lvl = (byte)level;
|
||||||
|
var p = m_Cache[lvl];
|
||||||
|
|
||||||
|
if (p == null)
|
||||||
|
{
|
||||||
|
m_Cache[lvl] = p = new GlobalLightLevel(level);
|
||||||
|
p.SetStatic();
|
||||||
|
}
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class PersonalLightLevel : Packet
|
||||||
|
{
|
||||||
|
public PersonalLightLevel(Serial mobile, int level = 0) : base(0x4E, 6)
|
||||||
|
{
|
||||||
|
Stream.Write(mobile);
|
||||||
|
Stream.Write((sbyte)level);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,18 +1,3 @@
|
||||||
/*************************************************************************
|
|
||||||
* ModernUO *
|
|
||||||
* Copyright 2019-2020 - ModernUO Development Team *
|
|
||||||
* Email: hi@modernuo.com *
|
|
||||||
* File: MobilePackets.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 Server.Network;
|
using Server.Network;
|
||||||
|
|
||||||
namespace Server.Tests.Network
|
namespace Server.Tests.Network
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* ModernUO *
|
* ModernUO *
|
||||||
* Copyright 2019-2020 - ModernUO Development Team *
|
* Copyright 2019-2020 - ModernUO Development Team *
|
||||||
* Email: hi@modernuo.com *
|
* Email: hi@modernuo.com *
|
||||||
* File: LightPackets.cs *
|
* File: OutgoingLightPackets.cs *
|
||||||
* *
|
* *
|
||||||
* This program is free software: you can redistribute it and/or modify *
|
* 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 *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
|
|
@ -13,38 +13,38 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
|
using System.Buffers;
|
||||||
|
|
||||||
namespace Server.Network
|
namespace Server.Network
|
||||||
{
|
{
|
||||||
public sealed class GlobalLightLevel : Packet
|
public static class OutgoingLightPackets
|
||||||
{
|
{
|
||||||
private static readonly GlobalLightLevel[] m_Cache = new GlobalLightLevel[0x100];
|
public static void SendPersonalLightLevel(this NetState ns, Serial serial, int level)
|
||||||
|
|
||||||
public GlobalLightLevel(int level) : base(0x4F, 2)
|
|
||||||
{
|
{
|
||||||
Stream.Write((sbyte)level);
|
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||||
}
|
|
||||||
|
|
||||||
public static GlobalLightLevel Instantiate(int level)
|
|
||||||
{
|
|
||||||
var lvl = (byte)level;
|
|
||||||
var p = m_Cache[lvl];
|
|
||||||
|
|
||||||
if (p == null)
|
|
||||||
{
|
{
|
||||||
m_Cache[lvl] = p = new GlobalLightLevel(level);
|
return;
|
||||||
p.SetStatic();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
var writer = new CircularBufferWriter(buffer);
|
||||||
}
|
writer.Write((byte)0x4E); // Packet ID
|
||||||
}
|
writer.Write(serial);
|
||||||
|
writer.Write((byte)level);
|
||||||
|
|
||||||
public sealed class PersonalLightLevel : Packet
|
ns.Send(ref buffer, 6);
|
||||||
{
|
}
|
||||||
public PersonalLightLevel(Serial mobile, int level = 0) : base(0x4E, 6)
|
|
||||||
|
public static void SendGlobalLightLevel(this NetState ns, int level = 0)
|
||||||
{
|
{
|
||||||
Stream.Write(mobile);
|
if (ns == null || !ns.GetSendBuffer(out var buffer))
|
||||||
Stream.Write((sbyte)level);
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[0] = 0x4F; // Packet ID
|
||||||
|
buffer[1] = (byte)level;
|
||||||
|
|
||||||
|
ns.Send(ref buffer, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Buffers.Binary;
|
using System.Buffers.Binary;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Server.Guilds;
|
using Server.Guilds;
|
||||||
|
|
@ -25,12 +26,12 @@ namespace Server
|
||||||
public class BufferReader : IGenericReader
|
public class BufferReader : IGenericReader
|
||||||
{
|
{
|
||||||
private readonly Encoding _encoding;
|
private readonly Encoding _encoding;
|
||||||
private ArraySegment<byte> _segment;
|
private byte[] _buffer;
|
||||||
public int Position { get; private set; }
|
public int Position { get; private set; }
|
||||||
|
|
||||||
public BufferReader(ArraySegment<byte> segment)
|
public BufferReader(byte[] buffer)
|
||||||
{
|
{
|
||||||
_segment = segment;
|
_buffer = buffer;
|
||||||
_encoding = Utility.UTF8;
|
_encoding = Utility.UTF8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,7 +43,7 @@ namespace Server
|
||||||
}
|
}
|
||||||
|
|
||||||
var length = ReadEncodedInt();
|
var length = ReadEncodedInt();
|
||||||
var s = length == 0 ? "" : _encoding.GetString(_segment.AsSpan(Position, length));
|
var s = length == 0 ? "" : _encoding.GetString(_buffer.AsSpan(Position, length));
|
||||||
Position += length;
|
Position += length;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
@ -82,65 +83,65 @@ namespace Server
|
||||||
|
|
||||||
public long ReadLong()
|
public long ReadLong()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadInt64LittleEndian(_segment.AsSpan(Position, 8));
|
var v = BinaryPrimitives.ReadInt64LittleEndian(_buffer.AsSpan(Position, 8));
|
||||||
Position += 8;
|
Position += 8;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ulong ReadULong()
|
public ulong ReadULong()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadUInt64LittleEndian(_segment.AsSpan(Position, 8));
|
var v = BinaryPrimitives.ReadUInt64LittleEndian(_buffer.AsSpan(Position, 8));
|
||||||
Position += 8;
|
Position += 8;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ReadInt()
|
public int ReadInt()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadInt32LittleEndian(_segment.AsSpan(Position, 4));
|
var v = BinaryPrimitives.ReadInt32LittleEndian(_buffer.AsSpan(Position, 4));
|
||||||
Position += 4;
|
Position += 4;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public uint ReadUInt()
|
public uint ReadUInt()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadUInt32LittleEndian(_segment.AsSpan(Position, 4));
|
var v = BinaryPrimitives.ReadUInt32LittleEndian(_buffer.AsSpan(Position, 4));
|
||||||
Position += 4;
|
Position += 4;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short ReadShort()
|
public short ReadShort()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadInt16LittleEndian(_segment.AsSpan(Position, 2));
|
var v = BinaryPrimitives.ReadInt16LittleEndian(_buffer.AsSpan(Position, 2));
|
||||||
Position += 2;
|
Position += 2;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ushort ReadUShort()
|
public ushort ReadUShort()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadUInt16LittleEndian(_segment.AsSpan(Position, 2));
|
var v = BinaryPrimitives.ReadUInt16LittleEndian(_buffer.AsSpan(Position, 2));
|
||||||
Position += 2;
|
Position += 2;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double ReadDouble()
|
public double ReadDouble()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadDoubleLittleEndian(_segment.AsSpan(Position, 8));
|
var v = BinaryPrimitives.ReadDoubleLittleEndian(_buffer.AsSpan(Position, 8));
|
||||||
Position += 8;
|
Position += 8;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float ReadFloat()
|
public float ReadFloat()
|
||||||
{
|
{
|
||||||
var v = BinaryPrimitives.ReadSingleLittleEndian(_segment.AsSpan(Position, 4));
|
var v = BinaryPrimitives.ReadSingleLittleEndian(_buffer.AsSpan(Position, 4));
|
||||||
Position += 4;
|
Position += 4;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte ReadByte() => _segment[Position++];
|
public byte ReadByte() => _buffer[Position++];
|
||||||
|
|
||||||
public sbyte ReadSByte() => (sbyte)_segment[Position++];
|
public sbyte ReadSByte() => (sbyte)_buffer[Position++];
|
||||||
|
|
||||||
public bool ReadBool() => _segment[Position++] != 0;
|
public bool ReadBool() => _buffer[Position++] != 0;
|
||||||
|
|
||||||
public int ReadEncodedInt()
|
public int ReadEncodedInt()
|
||||||
{
|
{
|
||||||
|
|
@ -310,14 +311,25 @@ namespace Server
|
||||||
public int Read(Span<byte> buffer)
|
public int Read(Span<byte> buffer)
|
||||||
{
|
{
|
||||||
var length = buffer.Length;
|
var length = buffer.Length;
|
||||||
if (length > _segment.Count - Position)
|
if (length > _buffer.Length - Position)
|
||||||
{
|
{
|
||||||
throw new OutOfMemoryException();
|
throw new OutOfMemoryException();
|
||||||
}
|
}
|
||||||
|
|
||||||
_segment.AsSpan(Position, length).CopyTo(buffer);
|
_buffer.AsSpan(Position, length).CopyTo(buffer);
|
||||||
Position += length;
|
Position += length;
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual int Seek(int offset, SeekOrigin origin)
|
||||||
|
{
|
||||||
|
return origin switch
|
||||||
|
{
|
||||||
|
SeekOrigin.Begin => Position = offset,
|
||||||
|
SeekOrigin.Current => Position += offset,
|
||||||
|
SeekOrigin.End => Position = _buffer.Length - offset,
|
||||||
|
_ => Position
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -337,30 +337,31 @@ namespace Server
|
||||||
}
|
}
|
||||||
|
|
||||||
using FileStream bin = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
using FileStream bin = new FileStream(dataPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
var fileBuffer = new byte[bin.Length];
|
var buffer = new byte[bin.Length];
|
||||||
bin.Read(fileBuffer);
|
bin.Read(buffer);
|
||||||
bin.Close();
|
bin.Close();
|
||||||
|
|
||||||
int position = 0;
|
var br = new BufferReader(buffer);
|
||||||
|
|
||||||
foreach (var entry in entities)
|
foreach (var entry in entities)
|
||||||
{
|
{
|
||||||
T t = entry.Entity;
|
T t = entry.Entity;
|
||||||
|
|
||||||
|
// Skip this entry
|
||||||
if (t == null)
|
if (t == null)
|
||||||
{
|
{
|
||||||
|
br.Seek(entry.Length, SeekOrigin.Current);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var segment = new ArraySegment<byte>(fileBuffer, position, entry.Length);
|
t.Deserialize(br);
|
||||||
var bufferReader = new BufferReader(segment);
|
var end = entry.Position + entry.Length;
|
||||||
t.Deserialize(bufferReader);
|
|
||||||
|
|
||||||
if (bufferReader.Position != entry.Length)
|
if (br.Position != end)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"***** Bad deserialize on {t.GetType()} *****");
|
Console.WriteLine($"***** Bad deserialize on {t.GetType()} *****");
|
||||||
Console.WriteLine(
|
Console.WriteLine(
|
||||||
$"Serialized object was {entry.Length} bytes, but {bufferReader.Position - entry.Position} bytes deserialized"
|
$"Serialized object was {entry.Length} bytes, but {br.Position - entry.Position} bytes deserialized"
|
||||||
);
|
);
|
||||||
|
|
||||||
Console.WriteLine("Delete the object and continue? (y/n)");
|
Console.WriteLine("Delete the object and continue? (y/n)");
|
||||||
|
|
@ -370,10 +371,9 @@ namespace Server
|
||||||
throw new Exception("Deserialization failed.");
|
throw new Exception("Deserialization failed.");
|
||||||
}
|
}
|
||||||
t.Delete();
|
t.Delete();
|
||||||
|
|
||||||
|
br.Seek((int)end, SeekOrigin.Begin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
position += entry.Length;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1253,8 +1253,8 @@ namespace Server.Mobiles
|
||||||
m_LastGlobalLight = global;
|
m_LastGlobalLight = global;
|
||||||
m_LastPersonalLight = personal;
|
m_LastPersonalLight = personal;
|
||||||
|
|
||||||
ns.Send(GlobalLightLevel.Instantiate(global));
|
ns.SendGlobalLightLevel(global);
|
||||||
ns.Send(new PersonalLightLevel(Serial, personal));
|
ns.SendPersonalLightLevel(Serial, personal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetMinResistance(ResistanceType type)
|
public override int GetMinResistance(ResistanceType type)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue