diff --git a/Classes/ServerObjectsBase.uc b/Classes/ServerObjectsBase.uc new file mode 100644 index 0000000..af07ea0 --- /dev/null +++ b/Classes/ServerObjectsBase.uc @@ -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 +}; \ No newline at end of file diff --git a/Classes/UChannel.uc b/Classes/UChannel.uc new file mode 100644 index 0000000..90ccc6e --- /dev/null +++ b/Classes/UChannel.uc @@ -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 \ No newline at end of file diff --git a/Classes/UFileChannel.uc b/Classes/UFileChannel.uc new file mode 100644 index 0000000..f35fd6e --- /dev/null +++ b/Classes/UFileChannel.uc @@ -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]; + } +} \ No newline at end of file diff --git a/Classes/UFileChannelCast.uc b/Classes/UFileChannelCast.uc new file mode 100644 index 0000000..29ab14f --- /dev/null +++ b/Classes/UFileChannelCast.uc @@ -0,0 +1,9 @@ +class UFileChannelCast extends Object; + +var UFileChannel NativeType; + +final function UFileChannel Cast(UChannel type) +{ + super(TypeCast).NativeCast(type); + return NativeType; +} \ No newline at end of file diff --git a/Classes/ULevel.uc b/Classes/ULevel.uc new file mode 100644 index 0000000..2cd18c4 --- /dev/null +++ b/Classes/ULevel.uc @@ -0,0 +1,22 @@ +/** + * Author: Marco + */ +class ULevel extends ServerObjectsBase; + +// var byte TestOffset[10000]; +var int Dummy; // Unknown data. + +// Database. +var array 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]; +// } \ No newline at end of file diff --git a/Classes/ULevelCast.uc b/Classes/ULevelCast.uc new file mode 100644 index 0000000..4787679 --- /dev/null +++ b/Classes/ULevelCast.uc @@ -0,0 +1,9 @@ +class ULevelCast extends Object; + +var ULevel NativeType; + +final function ULevel Cast(Level type) +{ + super(TypeCast).NativeCast(type); + return NativeType; +} \ No newline at end of file diff --git a/Classes/UNetConnection.uc b/Classes/UNetConnection.uc new file mode 100644 index 0000000..15dcc28 --- /dev/null +++ b/Classes/UNetConnection.uc @@ -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 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 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 InReliable; +var array QueuedAcks, ResendAcks; +var array OpenChannels; +var array SentTemporaries; + +// TODO test! +final function UChannel GetChannel(int i) +{ + return Channels[i]; +} + +// final function byte GetData(int i) +// { +// return TestOffset[i]; +// } \ No newline at end of file diff --git a/Classes/UNetDriver.uc b/Classes/UNetDriver.uc new file mode 100644 index 0000000..e1bbac2 --- /dev/null +++ b/Classes/UNetDriver.uc @@ -0,0 +1,19 @@ +/** + * UnrealScript representive of TcpNetDriver + * Author: Marco + */ +class UNetDriver extends ServerObjectsBase; + +var transient const int ExecVtbl; +var transient array 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]; +// } \ No newline at end of file diff --git a/Classes/UNetDriverCast.uc b/Classes/UNetDriverCast.uc new file mode 100644 index 0000000..f16be50 --- /dev/null +++ b/Classes/UNetDriverCast.uc @@ -0,0 +1,9 @@ +class UNetDriverCast extends Object; + +var UNetDriver NativeType; + +final function UNetDriver Cast(NetDriver type) +{ + super(TypeCast).NativeCast(type); + return NativeType; +} \ No newline at end of file diff --git a/Classes/UPackageMap.uc b/Classes/UPackageMap.uc new file mode 100644 index 0000000..4c71e6a --- /dev/null +++ b/Classes/UPackageMap.uc @@ -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 List; \ No newline at end of file diff --git a/README.md b/README.md index 9be5638..0991557 100644 --- a/README.md +++ b/README.md @@ -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); +} +```