Started on UE4 server, semi working handshake

This commit is contained in:
AeonLucid
2022-01-09 06:29:02 +01:00
parent e9091d7ac3
commit ed0f771df6
34 changed files with 2931 additions and 9 deletions
@@ -0,0 +1,24 @@
namespace Prospect.Unreal.Core;
public enum EEngineNetworkVersionHistory
{
HISTORY_INITIAL = 1,
HISTORY_REPLAY_BACKWARDS_COMPAT = 2, // Bump version to get rid of older replays before backwards compat was turned on officially
HISTORY_MAX_ACTOR_CHANNELS_CUSTOMIZATION = 3, // Bump version because serialization of the actor channels changed
HISTORY_REPCMD_CHECKSUM_REMOVE_PRINTF = 4, // Bump version since the way FRepLayoutCmd::CompatibleChecksum was calculated changed due to an optimization
HISTORY_NEW_ACTOR_OVERRIDE_LEVEL = 5, // Bump version since a level reference was added to the new actor information
HISTORY_CHANNEL_NAMES = 6, // Bump version since channel type is now an fname
HISTORY_CHANNEL_CLOSE_REASON = 7, // Bump version to serialize a channel close reason in bunches instead of bDormant
HISTORY_ACKS_INCLUDED_IN_HEADER = 8, // Bump version since acks are now sent as part of the header
HISTORY_NETEXPORT_SERIALIZATION = 9, // Bump version due to serialization change to FNetFieldExport
HISTORY_NETEXPORT_SERIALIZE_FIX = 10, // Bump version to fix net field export name serialization
HISTORY_FAST_ARRAY_DELTA_STRUCT = 11, // Bump version to allow fast array serialization, delta struct serialization.
HISTORY_FIX_ENUM_SERIALIZATION = 12, // Bump version to fix enum net serialization issues.
HISTORY_OPTIONALLY_QUANTIZE_SPAWN_INFO = 13, // Bump version to conditionally disable quantization for Scale, Location, and Velocity when spawning network actors.
HISTORY_JITTER_IN_HEADER = 14, // Bump version since we added jitter clock time to packet headers and removed remote saturation
HISTORY_CLASSNETCACHE_FULLNAME = 15, // Bump version to use full paths in GetNetFieldExportGroupForClassNetCache
HISTORY_REPLAY_DORMANCY = 16, // Bump version to support dormancy properly in replays
HISTORY_ENGINENETVERSION_PLUS_ONE,
HISTORY_ENGINENETVERSION_LATEST = HISTORY_ENGINENETVERSION_PLUS_ONE - 1,
}
@@ -0,0 +1,35 @@
using Prospect.Unreal.Net;
using Prospect.Unreal.Serialization;
namespace Prospect.Unreal.Core;
public class FEngineVersion
{
public ushort Major { get; private set; }
public ushort Minor { get; private set; }
public ushort Patch { get; private set; }
public uint Changelist { get; private set; }
public string Branch { get; private set; }
public void Set(ushort major, ushort minor, ushort patch, uint changelist, string branch)
{
Major = major;
Minor = minor;
Patch = patch;
Changelist = changelist;
Branch = branch;
}
public void Deserialize(FArchive archive)
{
Major = archive.ReadUInt16();
Minor = archive.ReadUInt16();
Patch = archive.ReadUInt16();
Changelist = archive.ReadUInt32();
Branch = FString.Deserialize(archive);
}
}
+14
View File
@@ -0,0 +1,14 @@
namespace Prospect.Unreal.Core;
public static class FMath
{
public static int DivideAndRoundUp(int dividend, int divisor)
{
return (dividend + divisor - 1) / divisor;
}
public static float FRandRange(float min, float max)
{
return min + (max - min) * Random.Shared.NextSingle();
}
}
+105
View File
@@ -0,0 +1,105 @@
using System.Text;
using Prospect.Unreal.Serialization;
namespace Prospect.Unreal.Core;
public static class FString
{
private const int MaxSerializeSize = 1024;
public static void Serialize(FArchive archive, string value)
{
var unicodeCount = Encoding.UTF8.GetByteCount(value);
var bSaveUnicodeChar = archive.IsForcingUnicode() || unicodeCount != value.Length;
if (bSaveUnicodeChar)
{
var num = unicodeCount + 1;
var saveNum = -num;
archive.WriteInt32(saveNum);
if (num != 0)
{
var valueBytesSize = num * 2;
var valueBytes = valueBytesSize > 128 ? new byte[valueBytesSize] : stackalloc byte[valueBytesSize];
Encoding.UTF8.GetBytes(value, valueBytes);
if (!archive.IsByteSwapping())
{
archive.Serialize(valueBytes, valueBytesSize);
}
else
{
throw new NotImplementedException();
// for (int i = 0; i < num; i++)
// {
// valueBytes[i] = archive.ByteSwap(valueBytes[i]);
// }
}
}
}
else
{
var num = value.Length + 1;
var valueBytes = num > 128 ? new byte[num] : stackalloc byte[num];
Encoding.ASCII.GetBytes(value, valueBytes);
archive.WriteInt32(num);
archive.Serialize(valueBytes, num);
}
}
public static string Deserialize(FArchive archive)
{
// > 0 for ANSICHAR, < 0 for UCS2CHAR serialization
string? result = null;
var saveNum = archive.ReadInt32();
var loadUcs2Char = saveNum < 0;
if (loadUcs2Char)
{
saveNum = -saveNum;
}
// If SaveNum is still less than 0, they must have passed in MIN_INT. Archive is corrupted.
if (saveNum < 0)
{
throw new Exception("Archive is corrupted");
}
// Protect against network packets allocating too much memory
if (MaxSerializeSize > 0 && saveNum > MaxSerializeSize)
{
throw new Exception("String is too large");
}
if (saveNum != 0)
{
if (loadUcs2Char)
{
var bytes = archive.ReadBytes(saveNum * 2);
// -2 to remove unicode null terminator.
result = Encoding.Unicode.GetString(bytes, 0, bytes.Length - 2);
}
else
{
var bytes = archive.ReadBytes(saveNum);
// -1 to remove null terminator.
result = Encoding.ASCII.GetString(bytes, 0, bytes.Length - 1);
}
// Throw away empty string.
if (saveNum == 1)
{
result = string.Empty;
}
}
return result ?? string.Empty;
}
}
+6
View File
@@ -0,0 +1,6 @@
namespace Prospect.Unreal.Core;
public class FURL
{
}