fix: Cleans up core code (#1187)
**Only one functional change** * Fixes a bug in LogFactory where `Warning` is being logged as `Information` Non-functional changes: * Updates/Fixes copyright headers * Removes namespace scopes for core files. View with [whitespace off](https://github.com/modernuo/ModernUO/pull/1187/files?w=1).
This commit is contained in:
parent
0138d40bda
commit
f268d5d4e2
262 changed files with 28527 additions and 28646 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright 2019-2020 - ModernUO Development Team *
|
||||
* Copyright 2019-2022 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: IGenericReader.cs *
|
||||
* *
|
||||
|
|
@ -18,107 +18,106 @@ using System.IO;
|
|||
using System.Net;
|
||||
using Server.Collections;
|
||||
|
||||
namespace Server
|
||||
namespace Server;
|
||||
|
||||
public interface IGenericReader
|
||||
{
|
||||
public interface IGenericReader
|
||||
// Used to determine valid Entity deserialization
|
||||
DateTime LastSerialized { get; init; }
|
||||
|
||||
string ReadString(bool intern = false);
|
||||
long ReadLong();
|
||||
ulong ReadULong();
|
||||
int ReadInt();
|
||||
uint ReadUInt();
|
||||
short ReadShort();
|
||||
ushort ReadUShort();
|
||||
double ReadDouble();
|
||||
float ReadFloat();
|
||||
byte ReadByte();
|
||||
sbyte ReadSByte();
|
||||
bool ReadBool();
|
||||
Serial ReadSerial();
|
||||
|
||||
DateTime ReadDateTime() => new(ReadLong(), DateTimeKind.Utc);
|
||||
TimeSpan ReadTimeSpan() => new(ReadLong());
|
||||
|
||||
DateTime ReadDeltaTime()
|
||||
{
|
||||
// Used to determine valid Entity deserialization
|
||||
DateTime LastSerialized { get; init; }
|
||||
|
||||
string ReadString(bool intern = false);
|
||||
long ReadLong();
|
||||
ulong ReadULong();
|
||||
int ReadInt();
|
||||
uint ReadUInt();
|
||||
short ReadShort();
|
||||
ushort ReadUShort();
|
||||
double ReadDouble();
|
||||
float ReadFloat();
|
||||
byte ReadByte();
|
||||
sbyte ReadSByte();
|
||||
bool ReadBool();
|
||||
Serial ReadSerial();
|
||||
|
||||
DateTime ReadDateTime() => new(ReadLong(), DateTimeKind.Utc);
|
||||
TimeSpan ReadTimeSpan() => new(ReadLong());
|
||||
|
||||
DateTime ReadDeltaTime()
|
||||
return ReadLong() switch
|
||||
{
|
||||
return ReadLong() switch
|
||||
{
|
||||
long.MinValue => DateTime.MinValue,
|
||||
long.MaxValue => DateTime.MaxValue,
|
||||
var delta => new DateTime(delta + DateTime.UtcNow.Ticks, DateTimeKind.Utc)
|
||||
};
|
||||
}
|
||||
decimal ReadDecimal() => new(stackalloc int[4] { ReadInt(), ReadInt(), ReadInt(), ReadInt() });
|
||||
int ReadEncodedInt()
|
||||
{
|
||||
int v = 0, shift = 0;
|
||||
byte b;
|
||||
|
||||
do
|
||||
{
|
||||
b = ReadByte();
|
||||
v |= (b & 0x7F) << shift;
|
||||
shift += 7;
|
||||
}
|
||||
while (b >= 0x80);
|
||||
|
||||
return v;
|
||||
}
|
||||
IPAddress ReadIPAddress()
|
||||
{
|
||||
byte length = ReadByte();
|
||||
// Either 2 ushorts, or 8 ushorts
|
||||
Span<byte> integer = stackalloc byte[length];
|
||||
Read(integer);
|
||||
return Utility.Intern(new IPAddress(integer));
|
||||
}
|
||||
Point3D ReadPoint3D() => new(ReadInt(), ReadInt(), ReadInt());
|
||||
Point2D ReadPoint2D() => new(ReadInt(), ReadInt());
|
||||
Rectangle2D ReadRect2D() => new(ReadPoint2D(), ReadPoint2D());
|
||||
Rectangle3D ReadRect3D() => new(ReadPoint3D(), ReadPoint3D());
|
||||
Map ReadMap() => Map.Maps[ReadByte()];
|
||||
Race ReadRace() => Race.Races[ReadByte()];
|
||||
int Read(Span<byte> buffer);
|
||||
unsafe T ReadEnum<T>() where T : unmanaged, Enum
|
||||
{
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
var num = ReadByte();
|
||||
return *(T*)#
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
var num = ReadShort();
|
||||
return *(T*)#
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
var num = ReadEncodedInt();
|
||||
return *(T*)#
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
var num = ReadLong();
|
||||
return *(T*)#
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
Guid ReadGuid()
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[16];
|
||||
Read(bytes);
|
||||
return new Guid(bytes);
|
||||
}
|
||||
|
||||
BitArray ReadBitArray();
|
||||
|
||||
long Seek(long offset, SeekOrigin origin);
|
||||
long.MinValue => DateTime.MinValue,
|
||||
long.MaxValue => DateTime.MaxValue,
|
||||
var delta => new DateTime(delta + DateTime.UtcNow.Ticks, DateTimeKind.Utc)
|
||||
};
|
||||
}
|
||||
decimal ReadDecimal() => new(stackalloc int[4] { ReadInt(), ReadInt(), ReadInt(), ReadInt() });
|
||||
int ReadEncodedInt()
|
||||
{
|
||||
int v = 0, shift = 0;
|
||||
byte b;
|
||||
|
||||
do
|
||||
{
|
||||
b = ReadByte();
|
||||
v |= (b & 0x7F) << shift;
|
||||
shift += 7;
|
||||
}
|
||||
while (b >= 0x80);
|
||||
|
||||
return v;
|
||||
}
|
||||
IPAddress ReadIPAddress()
|
||||
{
|
||||
byte length = ReadByte();
|
||||
// Either 2 ushorts, or 8 ushorts
|
||||
Span<byte> integer = stackalloc byte[length];
|
||||
Read(integer);
|
||||
return Utility.Intern(new IPAddress(integer));
|
||||
}
|
||||
Point3D ReadPoint3D() => new(ReadInt(), ReadInt(), ReadInt());
|
||||
Point2D ReadPoint2D() => new(ReadInt(), ReadInt());
|
||||
Rectangle2D ReadRect2D() => new(ReadPoint2D(), ReadPoint2D());
|
||||
Rectangle3D ReadRect3D() => new(ReadPoint3D(), ReadPoint3D());
|
||||
Map ReadMap() => Map.Maps[ReadByte()];
|
||||
Race ReadRace() => Race.Races[ReadByte()];
|
||||
int Read(Span<byte> buffer);
|
||||
unsafe T ReadEnum<T>() where T : unmanaged, Enum
|
||||
{
|
||||
switch (sizeof(T))
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
var num = ReadByte();
|
||||
return *(T*)#
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
var num = ReadShort();
|
||||
return *(T*)#
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
var num = ReadEncodedInt();
|
||||
return *(T*)#
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
var num = ReadLong();
|
||||
return *(T*)#
|
||||
}
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
Guid ReadGuid()
|
||||
{
|
||||
Span<byte> bytes = stackalloc byte[16];
|
||||
Read(bytes);
|
||||
return new Guid(bytes);
|
||||
}
|
||||
|
||||
BitArray ReadBitArray();
|
||||
|
||||
long Seek(long offset, SeekOrigin origin);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue