Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NetDriver support #4

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Classes/ServerObjectsBase.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Author: Marco
*/
class ServerObjectsBase extends Object
abstract;

// Types of channels.
enum EChannelType
{
CHTYPE_None, // Invalid type.
CHTYPE_Control, // Connection control.
CHTYPE_Actor, // Actor-update channel.
CHTYPE_File, // Binary file transfer.
CHTYPE_Voice // VOIP
};
21 changes: 21 additions & 0 deletions Classes/UChannel.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Author: Marco
*/
class UChannel extends ServerObjectsBase;

// Variables.
var UNetConnection Connection; // Owner connection.
var int OpenAcked; // Whether open has been acknowledged.
var int Closing; // State of the channel.
var int ChIndex; // Index of this channel.
var int OpenedLocally; // Whether channel was opened locally or by remote.
var int OpenPacketId; // Packet the spawn message was sent in.
var int OpenTemporary; // Opened temporarily.
var EChannelType ChType; // Type of this channel.
var int NumInRec; // Number of packets in InRec.
var int NumOutRec; // Number of packets in OutRec.
var int NegotiatedVer; // Negotiated version of engine = Min(client version, server version).
var int InRec; // Incoming data with queued dependencies. (FInBunch*)
var int OutRec; // Outgoing reliable unacked data. (FOutBunch*)
var int Broken; // Has encountered errors and is ignoring subsequent packets.
var int bTornOff; // Actor associated with this channel was torn off
23 changes: 23 additions & 0 deletions Classes/UFileChannel.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Author: Marco
*/
class UFileChannel extends UChannel;

// Receive Variables.
var Object Download; // UDownload when receiving.

// Send Variables.
var int SendFileAr; // File being sent. (FArchive*)
var byte SrcFilename[512]; // Filename being sent. (TCHAR)
var int PackageIndex; // Index of package in map.
var int SentData; // Number of bytes sent.

final function GetFileName(out byte N[ArrayCount(SrcFilename)])
{
local int i;

for (i = 0; i < ArrayCount(SrcFilename); ++i)
{
N[i] = SrcFilename[i];
}
}
9 changes: 9 additions & 0 deletions Classes/UFileChannelCast.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UFileChannelCast extends Object;

var UFileChannel NativeType;

final function UFileChannel Cast(UChannel type)
{
super(TypeCast).NativeCast(type);
return NativeType;
}
22 changes: 22 additions & 0 deletions Classes/ULevel.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Author: Marco
*/
class ULevel extends ServerObjectsBase;

// var byte TestOffset[10000];
var int Dummy; // Unknown data.

// Database.
var array<Actor> Actors; // 4
var Object TransArray; // 16

// Variables.
var UNetDriver NetDriver; // 20
var Engine Engine; // 24
var UNetConnection.FURL URL;
var UNetDriver DemoRecDriver;

// final function byte GetData(int i)
// {
// return TestOffset[i];
// }
9 changes: 9 additions & 0 deletions Classes/ULevelCast.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class ULevelCast extends Object;

var ULevel NativeType;

final function ULevel Cast(Level type)
{
super(TypeCast).NativeCast(type);
return NativeType;
}
165 changes: 165 additions & 0 deletions Classes/UNetConnection.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/**
* Author: Marco
*/
class UNetConnection extends Player
dependson(Unflect);

const MAX_CHANNELS=1023;

struct FURL
{
// URL components.
var string Protocol; // Protocol, i.e. "unreal" or "http".
var string Host; // Optional hostname, i.e. "204.157.115.40" or "unreal.epicgames.com", blank if local.
var int Port; // Optional host port.
var string Map; // Map name, i.e. "SkyCity", default is "Index".
var array<string> Op; // Options.
var string Portal; // Portal to enter through, default is "".

// Status.
var int Valid; // Whether parsed successfully.
};
enum EConnectionState
{
USOCK_Invalid, // Connection is invalid, possibly uninitialized.
USOCK_Closed, // Connection permanently closed.
USOCK_Pending, // Connection is awaiting connection.
USOCK_Open, // Connection is open.
};
struct FBitWriterMark
{
var int Overflowed;
var int Num;
};
struct FArchive
{
// Status variables.
var int ArVer;
var int ArNetVer;
var int ArLicenseeVer;
var int ArIsLoading;
var int ArIsSaving;
var int ArIsTrans;
var int ArIsPersistent;
var int ArForEdit;
var int ArForClient;
var int ArForServer;
var int ArIsError;
var int ArIsCriticalError;
var int ArMaxSerializeSize;
};
struct FBitWriter extends FArchive
{
var array<byte> Buffer;
var int Num;
var int Max;
};
struct FOutBunch extends FBitWriter
{
// Variables.
var int Next;
var Object Channel;
var Unflect.Int64 Time;
var int ReceivedAck;
var int ChIndex;
var int ChType;
var int ChSequence;
var int PacketId;
var byte bOpen;
var byte bClose;
var byte bReliable;
};

// Connection information.
var UNetDriver Driver; // Owning driver.
var EConnectionState State; // State this connection is in.
var FURL URL; // URL of the other side.
var UPackageMap PackageMap; // Package map between local and remote.

// Negotiated parameters.
var int ProtocolVersion; // Protocol version we're communicating with (<=PROTOCOL_VERSION).
var int MaxPacket; // Maximum packet size.
var int PacketOverhead; // Bytes overhead per packet sent.
var int InternalAck; // Internally ack all packets, for 100% reliable connections.
var int Challenge; // Server-generated challenge.
var int NegotiatedVer; // Negotiated version for new channels.
var int UserFlags; // User-specified flags.
var string RequestURL; // URL requested by client

// CD key authentication
var string CDKeyHash; // Hash of client's CD key
var string CDKeyResponse; // Client's response to CD key challenge

// Internal.
var Unflect.Int64 LastReceiveTime; // Last time a packet was received, for timeout checking.
var Unflect.Int64 LastSendTime; // Last time a packet was sent, for keepalives.
var Unflect.Int64 LastTickTime; // Last time of polling.
var Unflect.Int64 LastRepTime; // Time of last replication.
var int QueuedBytes; // Bytes assumed to be queued up.
var int TickCount; // Count of ticks.

// Merge info.
var FBitWriterMark LastStart; // Most recently sent bunch start.
var FBitWriterMark LastEnd; // Most recently sent bunch end.
var int AllowMerge; // Whether to allow merging.
var int TimeSensitive; // Whether contents are time-sensitive.
var int LastOutBunch; // Most recent outgoing bunch.
var FOutBunch LastOut;

// Stat display.
var Unflect.Int64 StatUpdateTime; // Time of last stat update.
var float StatPeriod; // Interval between gathering stats.
var float InRate, OutRate; // Rate for last interval.
var float InPackets, OutPackets; // Packet counts.
var float InBunches, OutBunches; // Bunch counts.
var float InLoss, OutLoss; // Packet loss percent.
var float InOrder, OutOrder; // Out of order incoming packets.
var float BestLag, AvgLag; // Lag.

// 8256

// Stat accumulators.
var float LagAcc, BestLagAcc; // Previous msec lag.
var int InLossAcc, OutLossAcc; // Packet loss accumulator.
var int InPktAcc, OutPktAcc; // Packet accumulator.
var int InBunAcc, OutBunAcc; // Bunch accumulator.
var int InByteAcc, OutByteAcc; // Byte accumulator.
var int InOrdAcc, OutOrdAcc; // Out of order accumulator.
var int LagCount; // Counter for lag measurement.
var int HighLossCount; // Counts high packet loss.
var Unflect.Int64 LastTime, FrameTime; // Monitors frame time.
var Unflect.Int64 CumulativeTime, AverageFrameTime;
var int CountedFrames;

// Packet.
var FBitWriter Out; // Outgoing packet.
var Unflect.Int64 OutLagTime[256]; // For lag measuring.
// 6044
var int OutLagPacketId[256]; // For lag measuring.
var int InPacketId; // Full incoming packet index.
var int OutPacketId; // Most recently sent packet.
var int OutAckPacketId; // Most recently acked outgoing packet.

// 5008
var int Dummy[1252]; // Unknown data...

// var byte TestOffset[20000];

// Channel table.
var UChannel Channels[MAX_CHANNELS];

var array<int> InReliable;
var array<int> QueuedAcks, ResendAcks;
var array<UChannel> OpenChannels;
var array<Actor> SentTemporaries;

// TODO test!
final function UChannel GetChannel(int i)
{
return Channels[i];
}

// final function byte GetData(int i)
// {
// return TestOffset[i];
// }
19 changes: 19 additions & 0 deletions Classes/UNetDriver.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* UnrealScript representive of TcpNetDriver
* Author: Marco
*/
class UNetDriver extends ServerObjectsBase;

var transient const int ExecVtbl;
var transient array<UNetConnection> ClientConnections;
var transient UNetConnection ServerConnection;
// 4356
// var byte TestOffset[20000];
var int Dummy[1088];
var transient ULevel Notify;
var transient UPackageMap MasterMap;

// final function byte GetData(int i)
// {
// return TestOffset[i];
// }
9 changes: 9 additions & 0 deletions Classes/UNetDriverCast.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UNetDriverCast extends Object;

var UNetDriver NativeType;

final function UNetDriver Cast(NetDriver type)
{
super(TypeCast).NativeCast(type);
return NativeType;
}
33 changes: 33 additions & 0 deletions Classes/UPackageMap.uc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Author: Marco
*/
class UPackageMap extends ServerObjectsBase;

/* PackageFlags:
PKG_AllowDownload = 0x0001, // Allow downloading package.
PKG_ClientOptional = 0x0002, // Purely optional for clients.
PKG_ServerSideOnly = 0x0004, // Only needed on the server side.
PKG_Unsecure = 0x0010, // Not trusted.
PKG_Need = 0x8000, // Client needs to download this package.
*/

struct FPackageInfo
{
// Variables.
var string URL; // URL of the package file we need to request.
var Object Linker; // Pointer to the linker, if loaded.
var Object Parent; // The parent package.
var Guid Guid; // Package identifier.
var int FileSize; // File size.
var int DownloadSize; // Download size.
var int ObjectBase; // Net index of first object.
var int ObjectCount; // Number of objects, defined by server.
var int NameBase; // Net index of first name.
var int NameCount; // Number of names, defined by server.
var int LocalGeneration; // This machine's generation of the package.
var int RemoteGeneration; // Remote machine's generation of the package.
var int PackageFlags; // Package flags.
};

// Variables.
var array<FPackageInfo> List;
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,40 @@ var int MyCommentStringProperty "Hello world!";

log("MetaData: " $ class'CoreAPI'.static.GetTypeMetaData(Property'MyCommentStringProperty'));
```

### Native Classes

#### NetDriver

```unrealscript
local UNetDriverCaster UNetDriverCaster;
local UNetDriver UNetDriver;
local UPackageMap UPackageMap;
local ULevelCast ULevelCast;
local ULevel ULevel;
local object obj;
local int i;

// retrieve UNetDriver var #1
ULevelCast = new() class'ULevelCast';
// pass `Level` reference
ULevel = ULevelCast.Cast(Level);
UNetDriver = ULevel.NetDriver;

// retrieve UNetDriver var #1
foreach level.allObjects(class'object', obj) {
if (obj.IsA('NetDriver')) {
warn("GOTCHA NetDriver!");
break;
}
}
UNetDriverCaster = new() class'UNetDriverCaster';
UNetDriver = UNetDriverCaster.Cast(NetDriver(obj));

// do something useful
UPackageMap = UNetDriver.MasterMap;
log("UPackageMap.List length: " $ UPackageMap.List.Length);
for (i = 0; i < UPackageMap.List.length; i++) {
log(i $ ". package - " $ UPackageMap.List[i].Parent.name);
}
```