internal static XDRPCArgumentInfo GenerateArgumentInfo( Type t, object o, ArgumentType at) { return(XDRPCMarshaler.GenerateArgumentInfo(t, o, at, 0)); }
internal static object GetArgumentInfoValue(Type t, XDRPCArgumentInfo argInfo) { object obj = (object)null; if (typeof(string) == t) { obj = (object)((XDRPCStringArgumentInfo)argInfo).Value; } else if (t.IsPrimitive || t.IsValueType || XDRPCMarshaler.IsValidArrayType(t)) { Type type; if (t.IsPrimitive) { type = typeof(XDRPCArgumentInfo <>).MakeGenericType(t); } else if (t.IsValueType) { type = typeof(XDRPCStructArgumentInfo <>).MakeGenericType(t); } else { type = typeof(XDRPCArrayArgumentInfo <>).MakeGenericType(t); } obj = type.GetProperty("Value").GetValue((object)argInfo, (object[])null); } return(obj); }
private void ConstructArgumentInfoArray() { Type elementType = typeof(T).GetElementType(); Array array = (object)this.Value as Array; this._arrayElementData = new XDRPCArrayArgumentInfo <T> .ArrayElementData[this.MaxArrayLength]; int index = 0; int referenceOffset = 0; for (; index < this._arrayLength; ++index) { XDRPCArgumentInfo argumentInfo = XDRPCMarshaler.GenerateArgumentInfo(elementType, array.GetValue(index), ArgumentType.ByRef); this._arrayElementData[index] = this.GenerateArrayBufferData(argumentInfo, ref referenceOffset); } for (; index < this.MaxArrayLength; ++index) { XDRPCArgumentInfo argumentInfo = XDRPCMarshaler.GenerateArgumentInfo(elementType, Activator.CreateInstance(elementType), ArgumentType.ByRef); this._arrayElementData[index] = this.GenerateArrayBufferData(argumentInfo, ref referenceOffset); } if (this.MaxArrayLength > 0) { this._referenceSize = referenceOffset; } else { this._referenceSize = 0; } }
private void ValidateType(Type t, string msg) { if (!XDRPCMarshaler.IsValidArgumentType(t)) { throw new XDRPCInvalidTypeException(t, string.Format("Invalid {0} operation: Type {1} is not supported by XDRPC.", (object)msg, (object)t.Name)); } }
private static XDRPCArgumentInfo[] GenerateArgumentInfoArray( params object[] args) { XDRPCArgumentInfo[] xdrpcArgumentInfoArray = new XDRPCArgumentInfo[args.Length]; for (int idx = 0; idx < args.Length; ++idx) { object o = args[idx]; if (o == null) { xdrpcArgumentInfoArray[idx] = (XDRPCArgumentInfo) new XDRPCNullArgumentInfo(); } else { Type type = o.GetType(); if (typeof(XDRPCArgumentInfo).IsAssignableFrom(type)) { xdrpcArgumentInfoArray[idx] = (XDRPCArgumentInfo)o; } else { if (!XDRPCMarshaler.IsValidArgumentType(type)) { throw new XDRPCInvalidArgumentTypeException(type, idx); } xdrpcArgumentInfoArray[idx] = XDRPCMarshaler.GenerateArgumentInfo(type, o); } } } return(xdrpcArgumentInfoArray); }
internal static bool IsValidArgumentType(Type t) { if (!XDRPCMarshaler.IsValidValueType(t) && !XDRPCMarshaler.IsValidArrayType(t)) { return(typeof(string) == t); } return(true); }
internal static XDRPCArgumentInfo GenerateArgumentInfo( Type t, object o, ArgumentType at, int size) { return(XDRPCMarshaler.GenerateArgumentInfo(t, o, at, size, Encoding.ASCII)); }
public static T ExecuteRPC <T>( this IXboxConsole console, XDRPCExecutionOptions options, out ulong postMethodCallReturn) where T : struct { XDRPCArgumentInfo[] xdrpcArgumentInfoArray = new XDRPCArgumentInfo[0]; return(XDRPCMarshaler.ExecuteRPC <T>(console, options, out postMethodCallReturn, xdrpcArgumentInfoArray)); }
public static T ExecuteRPC <T>( this IXboxConsole console, XDRPCExecutionOptions options, params object[] args) where T : struct { XDRPCArgumentInfo[] argumentInfoArray = XDRPCMarshaler.GenerateArgumentInfoArray(args); return(XDRPCMarshaler.ExecuteRPC <T>(console, options, argumentInfoArray)); }
internal static bool IsValidArrayType(Type t) { bool flag = false; if (t.IsArray) { flag = t.GetArrayRank() == 1 && XDRPCMarshaler.IsValidValueType(t.GetElementType()); } return(flag); }
public void Set <T>(T data) { this.ValidatePointer(nameof(Set)); Type type = typeof(T); this.ValidateType(type, nameof(Set)); int arrayElementCount = this.GetArrayElementCount(type); this.Set(XDRPCMarshaler.GenerateArgumentInfo(type, (object)data, ArgumentType.ByRef, arrayElementCount)); }
public static T ExecuteRPC <T>( this IXboxConsole console, XDRPCExecutionOptions options, params XDRPCArgumentInfo[] args) where T : struct { ulong postMethodCallReturn; return(XDRPCMarshaler.ExecuteRPC <T>(console, options, out postMethodCallReturn, args)); }
private void Get(XDRPCArgumentInfo lpvBufArg) { int num = this.ValidateSize(lpvBufArg, nameof(Get)); XDRPCExecutionOptions options = new XDRPCExecutionOptions(XDRPCMode.System, "xbdm.xex", 10); XDRPCArgumentInfo <uint> argumentInfo = this.GetArgumentInfo(); XDRPCArgumentInfo <int> xdrpcArgumentInfo1 = new XDRPCArgumentInfo <int>(num); XDRPCArgumentInfo <int> xdrpcArgumentInfo2 = new XDRPCArgumentInfo <int>(0, ArgumentType.Out); this.ValidateReturn(XDRPCMarshaler.ExecuteRPC <int>(this.XboxConsole, options, (XDRPCArgumentInfo)argumentInfo, (XDRPCArgumentInfo)xdrpcArgumentInfo1, lpvBufArg, (XDRPCArgumentInfo)xdrpcArgumentInfo2), nameof(Get)); this.ValidateReturnSize(xdrpcArgumentInfo2.Value, num, nameof(Get)); }
public T Get <T>() { this.ValidatePointer(nameof(Get)); Type type = typeof(T); this.ValidateType(type, nameof(Get)); int arrayElementCount = this.GetArrayElementCount(type); XDRPCArgumentInfo argumentInfo = XDRPCMarshaler.GenerateArgumentInfo(type, (object)default(T), ArgumentType.Out, arrayElementCount); this.Get(argumentInfo); return((T)XDRPCMarshaler.GetArgumentInfoValue(type, argumentInfo)); }
private object ValidateArgInfoNullValue(Type fieldType, XDRPCArgumentInfo argInfo) { if (argInfo.GetType().IsGenericType) { Type genericArgument = argInfo.GetType().GetGenericArguments()[0]; if (!genericArgument.Equals(fieldType) && genericArgument.Equals(typeof(uint)) && ((XDRPCArgumentInfo <uint>)argInfo).Value == 0U) { return((object)null); } } return(XDRPCMarshaler.GetArgumentInfoValue(fieldType, argInfo)); }
public static T ExecuteRPC <T>( this IXboxConsole console, string threadName, uint functionAddress, params object[] args) where T : struct { XDRPCExecutionOptions options = new XDRPCExecutionOptions(threadName, functionAddress); XDRPCArgumentInfo[] argumentInfoArray = XDRPCMarshaler.GenerateArgumentInfoArray(args); return(XDRPCMarshaler.ExecuteRPC <T>(console, options, argumentInfoArray)); }
public static T ExecuteRPC <T>( this IXboxConsole console, XDRPCMode mode, string module, int ordinal, params object[] args) where T : struct { XDRPCExecutionOptions options = new XDRPCExecutionOptions(mode, module, ordinal); XDRPCArgumentInfo[] argumentInfoArray = XDRPCMarshaler.GenerateArgumentInfoArray(args); return(XDRPCMarshaler.ExecuteRPC <T>(console, options, argumentInfoArray)); }
public static T ExecuteRPC <T>( this IXboxConsole console, string threadName, string module, int ordinal, out ulong postMethodCallReturn, params object[] args) where T : struct { XDRPCExecutionOptions options = new XDRPCExecutionOptions(threadName, module, ordinal); XDRPCArgumentInfo[] argumentInfoArray = XDRPCMarshaler.GenerateArgumentInfoArray(args); return(XDRPCMarshaler.ExecuteRPC <T>(console, options, out postMethodCallReturn, argumentInfoArray)); }
public XDRPCArgumentInfo(T v, ArgumentType t) { Type t1 = typeof(T); if (!t1.IsPrimitive) { if (XDRPCMarshaler.IsValidStructType(t1)) { throw new XDRPCInvalidTypeException(t1, string.Format("Type {0} is not supported by XDRPCArgumentInfo, use XDRPCStructArgumentInfo instead.", (object)t1.Name)); } throw new XDRPCInvalidTypeException(t1, string.Format("Type {0} is not supported by XDRPC.", (object)t1.Name)); } this.Value = v; this.PassBy = t; }
internal static int SizeOf(Type type) { int num = 0; if (MarshalingUtils.ValueTypeSizeMap.ContainsKey(type)) { num = MarshalingUtils.ValueTypeSizeMap[type]; } else if (XDRPCMarshaler.IsValidStructType(type)) { MarshalingUtils.GetStructSizes(type); num = MarshalingUtils.ValueTypeSizeMap[type]; } return(num); }
public static XDRPCReference AllocateRPC <T>( this IXboxConsole console, XDRPCMode mode) where T : struct { Type t = typeof(T); if (!XDRPCMarshaler.IsValidArgumentType(t)) { throw new XDRPCInvalidTypeException(t, string.Format("Invalid type {0}: Cannot allocate type not supported by XDRPC.", (object)t.Name)); } XDRPCArgumentInfo argumentInfo = XDRPCMarshaler.GenerateArgumentInfo(t, (object)default(T), ArgumentType.ByRef); return(console.AllocateRPC(argumentInfo, mode)); }
internal static XDRPCArgumentInfo GenerateArgumentInfo( Type t, object o, ArgumentType at, int size, Encoding encoding) { XDRPCArgumentInfo xdrpcArgumentInfo = (XDRPCArgumentInfo)null; if (t.IsPrimitive || t.IsValueType) { Type type; if (t.IsPrimitive) { type = typeof(XDRPCArgumentInfo <>).MakeGenericType(t); } else { type = typeof(XDRPCStructArgumentInfo <>).MakeGenericType(t); } xdrpcArgumentInfo = (XDRPCArgumentInfo)type.GetConstructor(new Type[2] { t, typeof(ArgumentType) }).Invoke(new object[2] { o, (object)at }); } else if (XDRPCMarshaler.IsValidArrayType(t)) { xdrpcArgumentInfo = (XDRPCArgumentInfo)typeof(XDRPCArrayArgumentInfo <>).MakeGenericType(t).GetConstructor(new Type[3] { t, typeof(ArgumentType), typeof(int) }).Invoke(new object[3] { o, (object)at, (object)size }); } else if (typeof(string) == t) { xdrpcArgumentInfo = (XDRPCArgumentInfo) new XDRPCStringArgumentInfo((string)o, encoding, at, size, XDRPCStringArgumentInfo.GetDefaultCountTypeForEncoding(encoding)); } return(xdrpcArgumentInfo); }
private void UpdateArrayValue() { if (this.MaxArrayLength <= 0) { return; } Type elementType = typeof(T).GetElementType(); Array instance = Array.CreateInstance(elementType, this.MaxArrayLength); for (int index = 0; index < this.MaxArrayLength; ++index) { instance.SetValue(XDRPCMarshaler.GetArgumentInfoValue(elementType, this._arrayElementData[index].Info), index); } this.Value = instance as T; this._arrayLength = instance.Length; }
public static T ExecuteRPC <T>( this IXboxConsole console, XDRPCExecutionOptions options, out ulong postMethodCallReturn, params XDRPCArgumentInfo[] args) where T : struct { Type t = typeof(T); postMethodCallReturn = 0UL; if (!XDRPCMarshaler.IsValidReturnType(t)) { if (!t.IsValueType) { throw new XDRPCInvalidReturnTypeException(t); } XDRPCStructArgumentInfo <T> structArgumentInfo = new XDRPCStructArgumentInfo <T>(default(T), ArgumentType.Out); XDRPCArgumentInfo[] xdrpcArgumentInfoArray = new XDRPCArgumentInfo[args.Length + 1]; xdrpcArgumentInfoArray[0] = (XDRPCArgumentInfo)structArgumentInfo; Array.Copy((Array)args, 0, (Array)xdrpcArgumentInfoArray, 1, args.Length); int num = (int)XDRPCMarshaler.ExecuteRPC <uint>(console, options, xdrpcArgumentInfoArray); return(structArgumentInfo.Value); } XDRPCExecutionState.XDRPCCallFlags flags = XDRPCExecutionState.XDRPCCallFlags.IntegerReturn; if (t == typeof(float) || t == typeof(double)) { flags = XDRPCExecutionState.XDRPCCallFlags.FloatingPointReturn; } XDRPCExecutionState xdrpcExecutionState = new XDRPCExecutionState(console, options, args, flags); xdrpcExecutionState.NoDevkit = XDRPCMarshaler.NoDevkit; xdrpcExecutionState.Invoke(); if (options.PostMethodCall != XDRPCPostMethodCall.None) { postMethodCallReturn = xdrpcExecutionState.PostMethodCallReturnValue; } object obj = XDRPCMarshaler.UnpackReturnType(t, xdrpcExecutionState.ReturnValue); if (obj == null) { return(default(T)); } return((T)obj); }
internal static int AlignmentOf(Type type) { int num = 0; if (MarshalingUtils.StructPrimitiveSizeMap.ContainsKey(type)) { num = MarshalingUtils.StructPrimitiveSizeMap[type]; } else if (XDRPCMarshaler.IsValidStructType(type)) { MarshalingUtils.GetStructSizes(type); num = MarshalingUtils.StructPrimitiveSizeMap[type]; } else if (type.IsPrimitive) { num = MarshalingUtils.SizeOf(type); } return(num); }
private static void GetStructSizes(Type type) { if (!XDRPCMarshaler.IsValidStructType(type)) { return; } Type type1 = typeof(XDRPCStructArgumentInfo <>).MakeGenericType(type); object obj = type1.GetConstructor(new Type[2] { type, typeof(ArgumentType) }).Invoke(new object[2] { Activator.CreateInstance(type), (object)ArgumentType.ByRef }); PropertyInfo property1 = type1.GetProperty("Size"); PropertyInfo property2 = type1.GetProperty("PrimitiveSize"); MarshalingUtils.ValueTypeSizeMap.Add(type, (int)property1.GetValue(obj, (object[])null)); MarshalingUtils.StructPrimitiveSizeMap.Add(type, (int)property2.GetValue(obj, (object[])null)); }
public XDRPCArrayArgumentInfo(T v, ArgumentType t, int maxArrayLength) { Type t1 = typeof(T); if (!t1.IsArray) { throw new XDRPCInvalidTypeException(t1, "Array type must be provided for XDRPCArrayArgumentInfo."); } if (!XDRPCMarshaler.IsValidArrayType(t1)) { throw new XDRPCInvalidTypeException(t1, string.Format("Array type {0} is not supported by XDRPC.", (object)t1.Name)); } this.Value = v; this._arrayLength = (object)this.Value == null ? 0 : ((object)this.Value as Array).Length; if (t == ArgumentType.Out && maxArrayLength <= 0) { throw new XDRPCException("The max array length must be specified for an Out type array."); } this.PassBy = t; this._elementSize = MarshalingUtils.SizeOf(t1.GetElementType()); this.MaxArrayLength = this.PassBy != ArgumentType.ByRef ? (this.PassBy != ArgumentType.Out ? this._arrayLength : maxArrayLength) : Math.Max(this._arrayLength, maxArrayLength); this.ConstructArgumentInfoArray(); }
private int PopulateStructBufferRecursive( Type structType, object structToMarshal, List <XDRPCStructArgumentInfo <T> .StructBufferData> bufferDataList, int depth, string unionWritingField) { if (depth > 3) { throw new XDRPCInvalidTypeException(structType, string.Format("Struct of type {0} has too many nested structs (more than {1} deep) which is not supported.", (object)typeof(T).Name, (object)3)); } if (!((IEnumerable <Type>)XDRPCStructArgumentInfo <T> .builtInStructAllowlist).Contains <Type>(structType)) { object[] customAttributes = structType.GetCustomAttributes(typeof(XDRPCStructAttribute), false); if (customAttributes == null || customAttributes.Length == 0) { throw new XDRPCInvalidTypeException(structType, string.Format("Struct of type {0} doesn't have the XDRPCStruct attribute.", (object)structType.Name)); } } FieldInfo[] fields = structType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int packAttribute = structType.StructLayoutAttribute.Value == LayoutKind.Sequential ? 8 : structType.StructLayoutAttribute.Pack; int num1 = 0; int num2 = 0; bool flag1 = false; foreach (FieldInfo fieldInfo in fields) { Type fieldType = fieldInfo.FieldType; MarshalAsAttribute marshalAsAttribute = (MarshalAsAttribute)null; XDRPCStructArgumentInfo <T> .StructBufferData data = new XDRPCStructArgumentInfo <T> .StructBufferData(); object[] customAttributes1 = fieldInfo.GetCustomAttributes(typeof(MarshalAsAttribute), false); if (customAttributes1 != null && customAttributes1.Length != 0) { marshalAsAttribute = (MarshalAsAttribute)customAttributes1[0]; } if (fieldType == typeof(string) || fieldType.IsArray) { if (marshalAsAttribute == null) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} of type {1} in struct type {2} doesn't have the required MarshalAsAttribute.", (object)fieldInfo.Name, (object)fieldType.Name, (object)structType.Name)); } if (marshalAsAttribute.Value != UnmanagedType.ByValArray && marshalAsAttribute.Value != UnmanagedType.LPArray) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} of type {1} in struct type {2} with its MarshalAs attribute not using the required UnmanagedType.ByValArray or UnmanagedType.LPArray.", (object)fieldInfo.Name, (object)fieldType.Name, (object)structType.Name)); } bool flag2 = marshalAsAttribute.Value == UnmanagedType.LPArray; int size = marshalAsAttribute.SizeConst; int num3; int cMax; if (fieldType.IsArray) { if (fieldType.GetArrayRank() > 1) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is a multidimensional array which is not supported by XDRPCStructArgumentInfo.", (object)fieldInfo.Name, (object)structType.Name)); } Type elementType = fieldType.GetElementType(); if (!XDRPCMarshaler.IsValidValueType(elementType)) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is an array of type {2} which is not supported by XDRPCStructArgumentInfo.", (object)fieldInfo.Name, (object)structType.Name, (object)elementType.Name)); } int num4 = MarshalingUtils.SizeOf(elementType); if (num4 == 0) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is an array of type {2} which is not supported by XDRPCStructArgumentInfo.", (object)fieldInfo.Name, (object)structType.Name, (object)elementType.Name)); } num3 = num4; if (XDRPCMarshaler.IsValidStructType(elementType)) { num3 = MarshalingUtils.AlignmentOf(elementType); } Array array = (Array)fieldInfo.GetValue(structToMarshal); if (flag2) { if (array != null && size < array.Length) { size = array.Length; } } else if (size == 0) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is an array being passed by value that doesn't have the required SizeConst part of the attribute defined.", (object)fieldInfo.Name, (object)structType.Name)); } cMax = num4 * size; data.Info = XDRPCMarshaler.GenerateArgumentInfo(fieldType, (object)array, ArgumentType.ByRef, size); } else { if (!XDRPCStructArgumentInfo <T> .EncodingMap.ContainsKey(marshalAsAttribute.ArraySubType)) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is a string with a MarshalAs attribute without a string UnmanagedType for its ArraySubType.", (object)fieldInfo.Name, (object)structType.Name)); } Encoding encoding = XDRPCStructArgumentInfo <T> .EncodingMap[marshalAsAttribute.ArraySubType]; int num4 = encoding == Encoding.Unicode ? 2 : 1; num3 = num4; cMax = size * num4; string v = (string)fieldInfo.GetValue(structToMarshal); if (flag2) { int num5 = 0; if (v != null) { num5 = encoding.GetByteCount(v + "\0"); } if (cMax < num5) { cMax = num5; } } else if (cMax == 0) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is a string being passed by value that doesn't have the required SizeConst part of the attribute defined.", (object)fieldInfo.Name, (object)structType.Name)); } data.Info = (XDRPCArgumentInfo) new XDRPCStringArgumentInfo(v, encoding, ArgumentType.ByRef, cMax, CountType.Byte); } int requiredReferenceSize = data.Info.GetRequiredReferenceSize(); if (requiredReferenceSize > 0) { XDRPCStructArgumentInfo <T> .StructBufferData structBufferData = new XDRPCStructArgumentInfo <T> .StructBufferData(); structBufferData.BufferOffset = this.GetCurrentOffset(this._referenceBufferDataList, 8); structBufferData.BufferSize = requiredReferenceSize; structBufferData.ReferenceIndex = -1; structBufferData.Info = (XDRPCArgumentInfo)null; data.ReferenceIndex = this._referenceBufferDataList.Count; this._referenceBufferDataList.Add(structBufferData); } else { data.ReferenceIndex = -1; } data.BufferSize = cMax; if (flag2) { if (cMax > 0) { XDRPCStructArgumentInfo <T> .StructBufferData structBufferData = data; structBufferData.BufferOffset = this.GetCurrentOffset(this._referenceBufferDataList, num3); this.FillPointerBufferData(out data, bufferDataList, packAttribute); this._referenceBufferDataList.Add(structBufferData); } else { this.FillPointerBufferData(out data, bufferDataList, packAttribute); data.Info = (XDRPCArgumentInfo) new XDRPCArgumentInfo <uint>(0U, ArgumentType.ByRef); data.ReferenceIndex = -1; } num3 = data.BufferSize; } else { int packAlignment = this.CalculatePackAlignment(packAttribute, num3); data.BufferOffset = this.GetCurrentOffset(bufferDataList, packAlignment); } num1 = Math.Max(num1, num3); num2 = Math.Max(num2, data.BufferSize); if (this.FillUnionBufferData(ref data, fieldInfo, unionWritingField)) { flag1 = true; } bufferDataList.Add(data); } else if (fieldType.IsPrimitive) { int num3 = MarshalingUtils.SizeOf(fieldType); if (num3 == 0) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Field {0} in struct type {1} is primitive type {2} which is not supported by XDRPCStructArgumentInfo.", (object)fieldInfo.Name, (object)structType.Name, (object)fieldType.Name)); } data.Info = XDRPCMarshaler.GenerateArgumentInfo(fieldType, fieldInfo.GetValue(structToMarshal), ArgumentType.ByRef); if (marshalAsAttribute != null && marshalAsAttribute.Value == UnmanagedType.LPStruct) { XDRPCStructArgumentInfo <T> .StructBufferData structBufferData = new XDRPCStructArgumentInfo <T> .StructBufferData(); structBufferData.Info = data.Info; structBufferData.BufferOffset = this.GetCurrentOffset(this._referenceBufferDataList, num3); structBufferData.BufferSize = num3; structBufferData.ReferenceIndex = -1; this.FillPointerBufferData(out data, bufferDataList, packAttribute); this._referenceBufferDataList.Add(structBufferData); } else { int packAlignment = this.CalculatePackAlignment(packAttribute, num3); data.BufferOffset = this.GetCurrentOffset(bufferDataList, packAlignment); data.BufferSize = num3; data.ReferenceIndex = -1; } num1 = Math.Max(num1, data.BufferSize); num2 = Math.Max(num2, data.BufferSize); if (this.FillUnionBufferData(ref data, fieldInfo, unionWritingField)) { flag1 = true; } bufferDataList.Add(data); } else { if (!fieldType.IsValueType) { throw new XDRPCInvalidTypeException(fieldType, string.Format("Type {0} found in struct type {1} is not supported by XDRPCStructArgumentInfo.", (object)fieldType.Name, (object)structType.Name)); } List <XDRPCStructArgumentInfo <T> .StructBufferData> bufferDataList1 = new List <XDRPCStructArgumentInfo <T> .StructBufferData>(); string empty = string.Empty; object[] customAttributes2 = fieldInfo.GetCustomAttributes(typeof(XDRPCUnionAttribute), false); if (customAttributes2 != null && customAttributes2.Length != 0) { empty = ((XDRPCUnionAttribute)customAttributes2[0]).Value; } int num3 = this.PopulateStructBufferRecursive(fieldType, fieldInfo.GetValue(structToMarshal), bufferDataList1, depth + 1, empty); if (marshalAsAttribute != null && marshalAsAttribute.Value == UnmanagedType.LPStruct) { this.FillPointerBufferData(out data, bufferDataList, packAttribute); if (this.FillUnionBufferData(ref data, fieldInfo, unionWritingField)) { flag1 = true; } bufferDataList.Add(data); int currentOffset = this.GetCurrentOffset(this._referenceBufferDataList, 8); for (int index = 0; index < bufferDataList1.Count; ++index) { XDRPCStructArgumentInfo <T> .StructBufferData structBufferData = bufferDataList1[index]; structBufferData.BufferOffset += currentOffset; if (structBufferData.NextOffset != 0) { structBufferData.NextOffset += currentOffset; } this._referenceBufferDataList.Add(structBufferData); } num1 = data.BufferSize; } else { data.BufferOffset = this.GetCurrentOffset(bufferDataList, this.CalculatePackAlignment(packAttribute, num3)); if (this.FillUnionBufferData(ref data, fieldInfo, unionWritingField)) { flag1 = true; } for (int index = 0; index < bufferDataList1.Count; ++index) { XDRPCStructArgumentInfo <T> .StructBufferData structBufferData = bufferDataList1[index]; structBufferData.BufferOffset += data.BufferOffset; if (structBufferData.NextOffset != 0) { data.BufferSize = structBufferData.NextOffset; structBufferData.NextOffset += data.BufferOffset; } if (data.Ignore) { structBufferData.Ignore = true; } bufferDataList.Add(structBufferData); } } num1 = Math.Max(num1, num3); num2 = Math.Max(num2, data.BufferSize); } } if (!string.IsNullOrEmpty(unionWritingField)) { if (!flag1) { throw new XDRPCInvalidTypeException(structType, string.Format("Struct of type {0} has the XDRPCUnion attribute with the non-existant field {1} specified, please provide a correct field name.", (object)structType.Name, (object)unionWritingField)); } this.SetNextOffset(bufferDataList, num2); } int packAlignment1 = this.CalculatePackAlignment(packAttribute, num1); this.CalculateNextOffset(bufferDataList, packAlignment1); return(packAlignment1); }
internal static XDRPCArgumentInfo GenerateArgumentInfo(Type t, object o) { return(XDRPCMarshaler.GenerateArgumentInfo(t, o, ArgumentType.ByValue)); }