public NetFieldExportAttribute(string name, RepLayoutCmdType type, int handle, string propertyNameUKInfo, string typeUKInfo, int bitCountUKInfo) { Name = name; Type = type; Handle = handle; Info = new UnknownFieldInfo(propertyNameUKInfo, typeUKInfo, bitCountUKInfo, (uint)handle); }
private object ReadDataType(RepLayoutCmdType replayout, NetBitReader netBitReader, Type objectType = null) { object data = null; switch (replayout) { case RepLayoutCmdType.Property: data = _linqCache.CreateObject(objectType); (data as IProperty).Serialize(netBitReader); (data as IResolvable)?.Resolve(GuidCache); break; case RepLayoutCmdType.PropertyBool: data = netBitReader.SerializePropertyBool(); break; case RepLayoutCmdType.PropertyName: data = netBitReader.SerializePropertyName(); break; case RepLayoutCmdType.PropertyFloat: data = netBitReader.SerializePropertyFloat(); break; case RepLayoutCmdType.PropertyNativeBool: data = netBitReader.SerializePropertyNativeBool(); break; case RepLayoutCmdType.PropertyNetId: data = netBitReader.SerializePropertyNetId(); break; case RepLayoutCmdType.PropertyObject: data = netBitReader.SerializePropertyObject(); break; case RepLayoutCmdType.PropertyPlane: throw new NotImplementedException("Plane RepLayoutCmdType not implemented"); case RepLayoutCmdType.PropertyRotator: data = netBitReader.SerializePropertyRotator(); break; case RepLayoutCmdType.PropertyString: data = netBitReader.SerializePropertyString(); break; case RepLayoutCmdType.PropertyVector10: data = netBitReader.SerializePropertyVector10(); break; case RepLayoutCmdType.PropertyVector100: data = netBitReader.SerializePropertyVector100(); break; case RepLayoutCmdType.PropertyVectorNormal: data = netBitReader.SerializePropertyVectorNormal(); break; case RepLayoutCmdType.PropertyVectorQ: data = netBitReader.SerializePropertyQuantizedVector(VectorQuantization.RoundWholeNumber); break; case RepLayoutCmdType.RepMovement: data = netBitReader.SerializeRepMovement(); break; case RepLayoutCmdType.Enum: data = netBitReader.SerializePropertyEnum(); break; // TODO Auto generation fix to handle 1-8 bits case RepLayoutCmdType.PropertyByte: data = netBitReader.ReadByte(); break; case RepLayoutCmdType.PropertyInt: data = netBitReader.ReadInt32(); break; case RepLayoutCmdType.PropertyInt16: data = netBitReader.ReadInt16(); break; case RepLayoutCmdType.PropertyUInt64: data = netBitReader.ReadUInt64(); break; case RepLayoutCmdType.PropertyUInt16: data = netBitReader.ReadUInt16(); break; case RepLayoutCmdType.PropertyUInt32: data = netBitReader.ReadUInt32(); break; case RepLayoutCmdType.PropertyVector: data = netBitReader.SerializePropertyVector(); break; case RepLayoutCmdType.PropertyVector2D: data = netBitReader.SerializePropertyVector2D(); break; default: netBitReader.Seek(netBitReader.GetBitsLeft(), System.IO.SeekOrigin.Current); break; } return(data); }
public NetFieldExportHandleAttribute(uint handle, RepLayoutCmdType type, ParseMode minimalParseMode) { Handle = handle; Type = type; MinimalParseMode = minimalParseMode; }
public NetFieldExportHandleAttribute(uint handle, RepLayoutCmdType type) { Handle = handle; Type = type; }
public NetFieldExportAttribute(string name, RepLayoutCmdType type, ParseMode minimalParseMode) { Name = name; Type = type; MinimalParseMode = minimalParseMode; }
public NetFieldExportAttribute(string name, RepLayoutCmdType type) { Name = name; Type = type; }
public static void GenerateFiles(string directory) { if (Directory.Exists(directory)) { Directory.Delete(directory, true); } Directory.CreateDirectory(directory); foreach (KeyValuePair <string, Type> netFieldGroundKvp in _netFieldGroups) { if (!_netFieldGroupInfo.TryGetValue(netFieldGroundKvp.Value, out NetFieldGroupInfo groupInfo)) { continue; } foreach (KeyValuePair <string, NetFieldInfo> netFieldInfo in groupInfo.Properties) { AddUnknownField(netFieldGroundKvp.Key, netFieldInfo.Value.Attribute.Info); } } foreach (KeyValuePair <string, HashSet <UnknownFieldInfo> > kvp in UnknownNetFields) { string fileName = String.Join("", kvp.Key.Split('/').Last().Split('.').Last().Split("_")).Replace("Athena", ""); fileName = FixInvalidNames(fileName); if (char.IsDigit(fileName[0])) { int firstCharacter = fileName.ToList().FindIndex(x => !char.IsDigit(x)); fileName = fileName.Substring(firstCharacter); } StringBuilder builder = new StringBuilder(); builder.AppendLine("using System.Collections.Generic;"); builder.AppendLine("using Unreal.Core.Attributes;"); builder.AppendLine("using Unreal.Core.Contracts;"); builder.AppendLine("using Unreal.Core.Models.Enums;\n"); builder.AppendLine("namespace Unreal.Core.Models"); builder.AppendLine("{"); builder.AppendLine($"\t[NetFieldExportGroup(\"{kvp.Key}\")]"); builder.AppendLine($"\tpublic class {fileName} : INetFieldExportGroup"); builder.AppendLine("\t{"); foreach (UnknownFieldInfo unknownField in kvp.Value.OrderBy(x => x.Handle)) { RepLayoutCmdType commandType = RepLayoutCmdType.Ignore; string type = "object"; if (!String.IsNullOrEmpty(unknownField.Type)) { //8, 16, or 32 if (unknownField.Type.EndsWith("*") || unknownField.Type.StartsWith("TSubclassOf")) { type = "uint?"; commandType = RepLayoutCmdType.Pointer; } else if (unknownField.Type.StartsWith("TEnumAsByte")) { type = "int?"; commandType = RepLayoutCmdType.Enum; } else if (unknownField.Type.StartsWith("E") && unknownField.Type.Length > 1 && Char.IsUpper(unknownField.Type[1])) { type = "int?"; commandType = RepLayoutCmdType.Enum; } else { switch (unknownField.Type) { case "TArray": type = "object[]"; commandType = RepLayoutCmdType.DynamicArray; break; case "FRotator": type = "FRotator"; commandType = RepLayoutCmdType.PropertyRotator; break; case "float": type = "float?"; commandType = RepLayoutCmdType.PropertyFloat; break; case "bool": type = "bool?"; commandType = RepLayoutCmdType.PropertyBool; break; case "int8": if (unknownField.BitCount == 1) { type = "bool?"; commandType = RepLayoutCmdType.PropertyBool; } else { type = "byte?"; commandType = RepLayoutCmdType.PropertyByte; } break; case "uint8": if (unknownField.BitCount == 1) { type = "bool?"; commandType = RepLayoutCmdType.PropertyBool; } else { type = "byte?"; commandType = RepLayoutCmdType.PropertyByte; } break; case "int16": type = "ushort?"; commandType = RepLayoutCmdType.PropertyUInt16; break; case "uint16": type = "ushort?"; commandType = RepLayoutCmdType.PropertyUInt16; break; case "uint32": type = "uint?"; commandType = RepLayoutCmdType.PropertyUInt32; break; case "int32": type = "int?"; commandType = RepLayoutCmdType.PropertyInt; break; case "FUniqueNetIdRepl": type = "string"; commandType = RepLayoutCmdType.PropertyNetId; break; case "FHitResult": case "FGameplayTag": case "FText": case "FVector2D": case "FAthenaPawnReplayData": case "FDateTime": case "FName": case "FQuat": case "FVector": case "FQuantizedBuildingAttribute": type = unknownField.Type; commandType = RepLayoutCmdType.Property; break; case "FVector_NetQuantize": type = "FVector"; commandType = RepLayoutCmdType.PropertyVectorQ; break; case "FVector_NetQuantize10": type = "FVector"; commandType = RepLayoutCmdType.PropertyVector10; break; case "FVector_NetQuantizeNormal": type = "FVector"; commandType = RepLayoutCmdType.PropertyVectorNormal; break; case "FVector_NetQuantize100": type = "FVector"; commandType = RepLayoutCmdType.PropertyVector100; break; case "FString": type = "string"; commandType = RepLayoutCmdType.PropertyString; break; case "FRepMovement": type = "FRepMovement"; commandType = RepLayoutCmdType.RepMovement; break; case "FMinimalGameplayCueReplicationProxy": type = "int?"; commandType = RepLayoutCmdType.Enum; break; default: //Console.WriteLine(unknownField.Type); break; } } } else { switch (unknownField.BitCount) { case 1: type = "bool?"; commandType = RepLayoutCmdType.PropertyBool; break; case 8: //Can't determine if it's a pointer that can have 8, 16, or 32 bits case 16: case 32: type = "uint?"; commandType = RepLayoutCmdType.PropertyUInt32; break; } } string fixedPropertyName = FixInvalidNames(unknownField.PropertyName); builder.AppendLine($"\t\t[NetFieldExport(\"{unknownField.PropertyName}\", RepLayoutCmdType.{commandType.ToString()}, {unknownField.Handle}, \"{unknownField.PropertyName}\", \"{unknownField.Type}\", {unknownField.BitCount})]"); builder.AppendLine($"\t\tpublic {type} {fixedPropertyName} {{ get; set; }} //Type: {unknownField.Type} Bits: {unknownField.BitCount}\n"); } builder.AppendLine("\t}"); builder.AppendLine("}"); string cSharpFile = builder.ToString(); File.WriteAllText(Path.Combine(directory, fileName) + ".cs", cSharpFile); } }
private static Array ReadArrayField(object obj, NetFieldExportGroup netfieldExportGroup, NetFieldInfo fieldInfo, NetBitReader netBitReader) { uint arrayIndexes = netBitReader.ReadIntPacked(); Type elementType = fieldInfo.PropertyInfo.PropertyType.GetElementType(); RepLayoutCmdType replayout = RepLayoutCmdType.Ignore; NetFieldGroupInfo groupInfo = null; if (_netFieldGroupInfo.ContainsKey(elementType)) { groupInfo = _netFieldGroupInfo[elementType]; } else { if (!_primitiveTypeLayout.TryGetValue(elementType, out replayout)) { replayout = RepLayoutCmdType.Ignore; } else { if (elementType == typeof(DebuggingObject)) { } } } Array arr = Array.CreateInstance(elementType, arrayIndexes); while (true) { uint index = netBitReader.ReadIntPacked(); if (index == 0) { if (netBitReader.GetBitsLeft() == 8) { uint terminator = netBitReader.ReadIntPacked(); if (terminator != 0x00) { //Log error return(arr); } } return(arr); } --index; if (index >= arrayIndexes) { //Log error return(arr); } object data = null; if (groupInfo != null) { data = Activator.CreateInstance(elementType); } while (true) { uint handle = netBitReader.ReadIntPacked(); if (handle == 0) { break; } handle--; if (netfieldExportGroup.NetFieldExports.Length < handle) { return(arr); } NetFieldExport export = netfieldExportGroup.NetFieldExports[handle]; uint numBits = netBitReader.ReadIntPacked(); if (numBits == 0) { continue; } if (export == null) { netBitReader.SkipBits((int)numBits); continue; } NetBitReader cmdReader = new NetBitReader(netBitReader.ReadBits(numBits)) { EngineNetworkVersion = netBitReader.EngineNetworkVersion, NetworkVersion = netBitReader.NetworkVersion }; //Uses the same type for the array if (groupInfo != null) { ReadField(data, export, netfieldExportGroup, handle, cmdReader); } else //Probably primitive values { data = ReadDataType(replayout, cmdReader, elementType); } } arr.SetValue(data, index); } }
private static object ReadDataType(RepLayoutCmdType replayout, NetBitReader netBitReader, Type objectType = null) { object data = null; switch (replayout) { case RepLayoutCmdType.Property: data = Activator.CreateInstance(objectType); (data as IProperty).Serialize(netBitReader); break; case RepLayoutCmdType.PropertyBool: data = netBitReader.SerializePropertyBool(); break; case RepLayoutCmdType.PropertyName: netBitReader.Seek(netBitReader.Position + netBitReader.GetBitsLeft()); break; case RepLayoutCmdType.PropertyFloat: data = netBitReader.SerializePropertyFloat(); break; case RepLayoutCmdType.PropertyNativeBool: data = netBitReader.SerializePropertyNativeBool(); break; case RepLayoutCmdType.PropertyNetId: data = netBitReader.SerializePropertyNetId(); break; case RepLayoutCmdType.PropertyObject: data = netBitReader.SerializePropertyObject(); break; case RepLayoutCmdType.PropertyPlane: throw new NotImplementedException("Plane RepLayoutCmdType not implemented"); case RepLayoutCmdType.PropertyRotator: data = netBitReader.SerializePropertyRotator(); break; case RepLayoutCmdType.PropertyString: data = netBitReader.SerializePropertyString(); break; case RepLayoutCmdType.PropertyVector10: data = netBitReader.SerializePropertyVector10(); break; case RepLayoutCmdType.PropertyVector100: data = netBitReader.SerializePropertyVector100(); break; case RepLayoutCmdType.PropertyVectorNormal: data = netBitReader.SerializePropertyVectorNormal(); break; case RepLayoutCmdType.PropertyVectorQ: data = netBitReader.SerializePropertyQuantizeVector(); break; case RepLayoutCmdType.RepMovement: data = netBitReader.SerializeRepMovement(); break; case RepLayoutCmdType.Enum: data = netBitReader.SerializeEnum(); break; //Auto generation fix to handle 1-8 bits case RepLayoutCmdType.PropertyByte: data = (byte)netBitReader.ReadBitsToInt(netBitReader.GetBitsLeft()); break; //Auto generation fix to handle 1-32 bits. case RepLayoutCmdType.PropertyInt: data = netBitReader.ReadBitsToInt(netBitReader.GetBitsLeft()); break; case RepLayoutCmdType.PropertyUInt64: data = netBitReader.ReadUInt64(); break; case RepLayoutCmdType.PropertyUInt16: data = (ushort)netBitReader.ReadBitsToInt(netBitReader.GetBitsLeft()); break; case RepLayoutCmdType.PropertyUInt32: data = netBitReader.ReadUInt32(); break; case RepLayoutCmdType.Pointer: switch (netBitReader.GetBitsLeft()) { case 8: data = (uint)netBitReader.ReadByte(); break; case 16: data = (uint)netBitReader.ReadUInt16(); break; case 32: data = netBitReader.ReadUInt32(); break; } break; case RepLayoutCmdType.PropertyVector: data = new FVector(netBitReader.ReadSingle(), netBitReader.ReadSingle(), netBitReader.ReadSingle()); break; case RepLayoutCmdType.Ignore: netBitReader.Seek(netBitReader.Position + netBitReader.GetBitsLeft()); break; } return(data); }
public RepLayoutAttribute(RepLayoutCmdType type) { Type = type; }