Adds more packet tests (#166)

This commit is contained in:
Kamron Batman 2020-07-03 19:03:10 -07:00 • committed by GitHub
parent ee06eb4407
commit e17195ca80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 1203 additions and 277 deletions

View file

@ -37,7 +37,7 @@ namespace Server.Gumps
private static readonly byte[] m_NoDispose = StringToBuffer("{ nodispose }");
private static readonly byte[] m_NoResize = StringToBuffer("{ noresize }");
private readonly List<string> m_Strings;
public List<string> Strings { get; }
internal int m_TextEntries, m_Switches;
@ -54,7 +54,7 @@ namespace Server.Gumps
TypeID = GetTypeID(GetType());
Entries = new List<GumpEntry>();
m_Strings = new List<string>();
Strings = new List<string>();
}
public int TypeID { get; }
@ -206,13 +206,9 @@ namespace Server.Gumps
public void Add(GumpEntry g)
{
if (g.Parent != this)
{
g.Parent = this;
}
else if (!Entries.Contains(g))
{
Entries.Add(g);
}
}
public void Remove(GumpEntry g)
@ -226,12 +222,12 @@ namespace Server.Gumps
public int Intern(string value)
{
var indexOf = m_Strings.IndexOf(value);
var indexOf = Strings.IndexOf(value);
if (indexOf >= 0) return indexOf;
m_Strings.Add(value);
return m_Strings.Count - 1;
Strings.Add(value);
return Strings.Count - 1;
}
public void SendTo(NetState state)
@ -242,7 +238,7 @@ namespace Server.Gumps
public static byte[] StringToBuffer(string str) => Encoding.ASCII.GetBytes(str);
private Packet Compile(NetState ns = null)
public Packet Compile(NetState ns = null)
{
IGumpWriter disp;
@ -274,7 +270,7 @@ namespace Server.Gumps
disp.AppendLayout(m_EndLayout);
}
disp.WriteStrings(m_Strings);
disp.WriteStrings(Strings);
disp.Flush();

View file

@ -634,9 +634,9 @@ namespace Server.Items
if (ns != null)
{
if (ns.HighSeas)
to.Send(new ContainerDisplayHS(this));
to.Send(new ContainerDisplayHS(Serial, GumpID));
else
to.Send(new ContainerDisplay(this));
to.Send(new ContainerDisplay(Serial, GumpID));
SendContentTo(ns);

View file

@ -47,6 +47,11 @@ namespace Server
private static bool m_Profiling;
private static DateTime m_ProfileStart;
private static TimeSpan m_ProfileTime;
private static bool? m_IsRunningFromXUnit;
public static bool IsRunningFromXUnit =>
m_IsRunningFromXUnit ??= AppDomain.CurrentDomain.GetAssemblies().Any(
a => a.FullName?.ToLowerInvariant().StartsWith("xunit") ?? false);
/*
* DateTime.Now and DateTime.UtcNow are based on actual system clock time.

View file

@ -331,14 +331,14 @@ namespace Server.Network
unknown ??= "";
caption ??= "";
EnsureCapacity(16 + unknown.Length + caption.Length);
EnsureCapacity(15 + unknown.Length + caption.Length);
Stream.Write(serial);
Stream.Write((short)gumpID);
Stream.Write((short)unknown.Length);
Stream.WriteAsciiFixed(unknown, unknown.Length);
Stream.Write((short)(unknown.Length + 1));
Stream.WriteAsciiNull(unknown);
Stream.Write((short)(caption.Length + 1));
Stream.WriteAsciiFixed(caption, caption.Length + 1);
Stream.WriteAsciiNull(caption);
}
}
}

View file

@ -105,14 +105,6 @@ namespace Server.Network
Stream.Write((short)itemID);
Stream.Write((byte)0);
/*} else if ( ) {
m_Stream.Write( (byte) 0x01 );
m_Stream.Write( (int) item.Serial );
m_Stream.Write( (short) itemID );
m_Stream.Write( (byte) item.Direction );*/
}
else
{
@ -132,10 +124,8 @@ namespace Server.Network
Stream.Write((short)amount);
var loc = item.Location;
var x = loc.m_X & 0x7FFF;
var y = loc.m_Y & 0x3FFF;
Stream.Write((short)x);
Stream.Write((short)y);
Stream.Write((short)loc.m_X);
Stream.Write((short)loc.m_Y);
Stream.Write((sbyte)loc.m_Z);
Stream.Write((byte)item.Light);
@ -163,14 +153,6 @@ namespace Server.Network
Stream.Write((ushort)itemID);
Stream.Write((byte)0);
/*} else if ( ) {
m_Stream.Write( (byte) 0x01 );
m_Stream.Write( (int) item.Serial );
m_Stream.Write( (ushort) itemID );
m_Stream.Write( (byte) item.Direction );*/
}
else
{
@ -190,10 +172,8 @@ namespace Server.Network
Stream.Write((short)amount);
var loc = item.Location;
var x = loc.m_X & 0x7FFF;
var y = loc.m_Y & 0x3FFF;
Stream.Write((short)x);
Stream.Write((short)y);
Stream.Write((short)loc.m_X);
Stream.Write((short)loc.m_Y);
Stream.Write((sbyte)loc.m_Z);
Stream.Write((byte)item.Light);
@ -206,18 +186,18 @@ namespace Server.Network
public sealed class DisplaySpellbook : Packet
{
public DisplaySpellbook(Item book) : base(0x24, 7)
public DisplaySpellbook(Serial book) : base(0x24, 7)
{
Stream.Write(book.Serial);
Stream.Write(book);
Stream.Write((short)-1);
}
}
public sealed class DisplaySpellbookHS : Packet
{
public DisplaySpellbookHS(Item book) : base(0x24, 9)
public DisplaySpellbookHS(Serial book) : base(0x24, 9)
{
Stream.Write(book.Serial);
Stream.Write(book);
Stream.Write((short)-1);
Stream.Write((short)0x7D);
}
@ -225,14 +205,14 @@ namespace Server.Network
public sealed class NewSpellbookContent : Packet
{
public NewSpellbookContent(Item item, int graphic, int offset, ulong content) : base(0xBF)
public NewSpellbookContent(Serial spellbook, int graphic, int offset, ulong content) : base(0xBF)
{
EnsureCapacity(23);
Stream.Write((short)0x1B);
Stream.Write((short)0x01);
Stream.Write(item.Serial);
Stream.Write(spellbook);
Stream.Write((short)graphic);
Stream.Write((short)offset);
@ -243,9 +223,9 @@ namespace Server.Network
public sealed class SpellbookContent : Packet
{
public SpellbookContent(int count, int offset, ulong content, Item item) : base(0x3C)
public SpellbookContent(Serial spellbook, int offset, ulong content) : base(0x3C)
{
EnsureCapacity(5 + count * 19);
EnsureCapacity(5 + 64 * 19);
var written = 0;
@ -262,7 +242,7 @@ namespace Server.Network
Stream.Write((ushort)(i + offset));
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write(item.Serial);
Stream.Write(spellbook);
Stream.Write((short)0);
++written;
@ -275,9 +255,9 @@ namespace Server.Network
public sealed class SpellbookContent6017 : Packet
{
public SpellbookContent6017(int count, int offset, ulong content, Item item) : base(0x3C)
public SpellbookContent6017(Serial spellbook, int offset, ulong content) : base(0x3C)
{
EnsureCapacity(5 + count * 20);
EnsureCapacity(5 + 64 * 20);
var written = 0;
@ -295,7 +275,7 @@ namespace Server.Network
Stream.Write((short)0);
Stream.Write((short)0);
Stream.Write((byte)0); // Grid Location?
Stream.Write(item.Serial);
Stream.Write(spellbook);
Stream.Write((short)0);
++written;
@ -308,19 +288,19 @@ namespace Server.Network
public sealed class ContainerDisplay : Packet
{
public ContainerDisplay(Container c) : base(0x24, 7)
public ContainerDisplay(Serial cont, int gumpId) : base(0x24, 7)
{
Stream.Write(c.Serial);
Stream.Write((short)c.GumpID);
Stream.Write(cont);
Stream.Write((short)gumpId);
}
}
public sealed class ContainerDisplayHS : Packet
{
public ContainerDisplayHS(Container c) : base(0x24, 9)
public ContainerDisplayHS(Serial cont, int gumpId) : base(0x24, 9)
{
Stream.Write(c.Serial);
Stream.Write((short)c.GumpID);
Stream.Write(cont);
Stream.Write((short)gumpId);
Stream.Write((short)0x7D);
}
}

View file

@ -20,6 +20,7 @@
using System;
using System.IO;
using System.Linq;
using System.Text;
namespace Server
@ -181,108 +182,56 @@ namespace Server
static TileData()
{
ItemTable = new ItemData[0x10000];
LandTable = new LandData[0x4000];
if (Core.IsRunningFromXUnit) return;
var filePath = Core.FindDataFile("tiledata.mul");
using var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
var bin = new BinaryReader(fs);
if (fs.Length == 3188736)
var is7090 = fs.Length == 3188736;
bool is7000 = fs.Length == 1644544;
for (var i = 0; i < 0x4000; i++)
{
// 7.0.9.0
LandTable = new LandData[0x4000];
for (var i = 0; i < 0x4000; ++i)
// header
if (is7090)
{
if (i == 1 || i > 0 && (i & 0x1F) == 0) bin.ReadInt32(); // header
var flags = (TileFlag)bin.ReadInt64();
bin.ReadInt16(); // skip 2 bytes -- textureID
LandTable[i] = new LandData(ReadNameString(bin), flags);
if (i == 1 || i > 0 && (i & 0x1F) == 0)
bin.ReadInt32();
}
ItemTable = new ItemData[0x10000];
for (var i = 0; i < 0x10000; ++i)
{
if ((i & 0x1F) == 0) bin.ReadInt32(); // header
var flags = (TileFlag)bin.ReadInt64();
int weight = bin.ReadByte();
int quality = bin.ReadByte();
bin.ReadInt16();
bin.ReadByte();
int quantity = bin.ReadByte();
else if ((i & 0x1F) == 0)
bin.ReadInt32();
bin.ReadByte();
int value = bin.ReadByte();
int height = bin.ReadByte();
ItemTable[i] = new ItemData(ReadNameString(bin), flags, weight, quality, quantity, value,
height);
}
var flags = (TileFlag)(is7090 ? bin.ReadInt64() : bin.ReadInt32());
bin.ReadInt16(); // skip 2 bytes -- textureID
LandTable[i] = new LandData(ReadNameString(bin), flags);
}
else
int length = is7090 ? 0x10000 : is7000 ? 0x8000 : 0x4000;
for (var i = 0; i < length; i++)
{
LandTable = new LandData[0x4000];
if ((i & 0x1F) == 0) bin.ReadInt32(); // header
for (var i = 0; i < 0x4000; ++i)
{
if ((i & 0x1F) == 0) bin.ReadInt32(); // header
var flags = (TileFlag)(is7090 ? bin.ReadInt64() : bin.ReadInt32());
int weight = bin.ReadByte();
int quality = bin.ReadByte();
bin.ReadInt16();
bin.ReadByte();
int quantity = bin.ReadByte();
bin.ReadInt32();
bin.ReadByte();
int value = bin.ReadByte();
int height = bin.ReadByte();
var flags = (TileFlag)bin.ReadInt32();
bin.ReadInt16(); // skip 2 bytes -- textureID
LandTable[i] = new LandData(ReadNameString(bin), flags);
}
if (fs.Length == 1644544)
{
// 7.0.0.0
ItemTable = new ItemData[0x8000];
for (var i = 0; i < 0x8000; ++i)
{
if ((i & 0x1F) == 0) bin.ReadInt32(); // header
var flags = (TileFlag)bin.ReadInt32();
int weight = bin.ReadByte();
int quality = bin.ReadByte();
bin.ReadInt16();
bin.ReadByte();
int quantity = bin.ReadByte();
bin.ReadInt32();
bin.ReadByte();
int value = bin.ReadByte();
int height = bin.ReadByte();
ItemTable[i] = new ItemData(ReadNameString(bin), flags, weight, quality, quantity, value,
height);
}
}
else
{
ItemTable = new ItemData[0x4000];
for (var i = 0; i < 0x4000; ++i)
{
if ((i & 0x1F) == 0) bin.ReadInt32(); // header
var flags = (TileFlag)bin.ReadInt32();
int weight = bin.ReadByte();
int quality = bin.ReadByte();
bin.ReadInt16();
bin.ReadByte();
int quantity = bin.ReadByte();
bin.ReadInt32();
bin.ReadByte();
int value = bin.ReadByte();
int height = bin.ReadByte();
ItemTable[i] = new ItemData(ReadNameString(bin), flags, weight, quality, quantity, value,
height);
}
}
ItemTable[i] = new ItemData(
ReadNameString(bin), flags, weight, quality, quantity, value, height
);
}
MaxLandValue = LandTable.Length - 1;