예제 #1
0
        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;
            }
        }
예제 #2
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);
        }
예제 #3
0
 private XDRPCExecutionOptions(
     XDRPCMode mode,
     string threadName,
     string module,
     string functionName,
     int ordinal,
     uint functionAddress,
     uint processor,
     XDRPCPostMethodCall postMethodCall,
     TimeSpan executionTimeoutPeriod)
 {
     this.Mode = mode;
     if (!string.IsNullOrEmpty(module))
     {
         this.moduleInfo   = (XDRPCArgumentInfo) new XDRPCStringArgumentInfo(module, Encoding.ASCII, ArgumentType.ByRef);
         this.functionInfo = !string.IsNullOrEmpty(functionName) ? (XDRPCArgumentInfo) new XDRPCStringArgumentInfo(functionName, Encoding.ASCII, ArgumentType.ByRef) : (XDRPCArgumentInfo) new XDRPCArgumentInfo <int>(ordinal);
     }
     else
     {
         this.moduleInfo   = (XDRPCArgumentInfo) new XDRPCNullArgumentInfo();
         this.functionInfo = (XDRPCArgumentInfo) new XDRPCArgumentInfo <uint>(functionAddress);
     }
     this.FunctionName           = functionName;
     this.ModuleName             = module;
     this.Ordinal                = ordinal;
     this.FunctionAddress        = functionAddress;
     this.Processor              = processor;
     this.PostMethodCall         = postMethodCall;
     this.ThreadName             = threadName;
     this.ExecutionTimeoutPeriod = executionTimeoutPeriod;
 }
예제 #4
0
 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);
 }
예제 #5
0
 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));
 }
예제 #6
0
        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));
        }
예제 #7
0
        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));
        }
예제 #8
0
 public void UnpackBufferData(byte[] data)
 {
     if (this.PassBy != ArgumentType.ByRef && this.PassBy != ArgumentType.Out)
     {
         return;
     }
     if (BitConverter.IsLittleEndian)
     {
         MarshalingUtils.ReverseBytes(data);
     }
     this.Value = (T)(XDRPCArgumentInfo <T> .GetValue(data) ?? (object)default(T));
 }
예제 #9
0
 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));
 }
예제 #10
0
        private XDRPCArrayArgumentInfo <T> .ArrayElementData GenerateArrayBufferData(
            XDRPCArgumentInfo info,
            ref int referenceOffset)
        {
            XDRPCArrayArgumentInfo <T> .ArrayElementData arrayElementData = new XDRPCArrayArgumentInfo <T> .ArrayElementData();

            arrayElementData.Info            = info;
            arrayElementData.ReferenceOffset = referenceOffset;
            arrayElementData.ReferenceSize   = info.GetRequiredReferenceSize();
            referenceOffset += arrayElementData.ReferenceSize;
            XDRPCExecutionState.AlignBufferOffset(ref referenceOffset);
            return(arrayElementData);
        }
예제 #11
0
        public byte[] PackBufferData()
        {
            if (this.PassBy != ArgumentType.ByRef && this.PassBy != ArgumentType.Out)
            {
                return((byte[])null);
            }
            byte[] bytes = XDRPCArgumentInfo <T> .GetBytes((object)this.Value);

            if (BitConverter.IsLittleEndian)
            {
                MarshalingUtils.ReverseBytes(bytes);
            }
            return(bytes);
        }
예제 #12
0
        private int ValidateSize(XDRPCArgumentInfo lpvBufArg, string msgType)
        {
            int requiredBufferSize = lpvBufArg.GetRequiredBufferSize();

            if (requiredBufferSize > this.BufferSize)
            {
                throw new XDRPCInvalidOperationException(string.Format("Invalid {0} operation: Allocated buffer's size ({1}) is smaller than object's size ({2}).", (object)msgType, (object)this.BufferSize, (object)requiredBufferSize));
            }
            if (lpvBufArg.GetRequiredReferenceSize() > 0)
            {
                throw new XDRPCInvalidOperationException(string.Format("Invalid {0} operation: {1}", (object)msgType, (object)"Struct type containing references is not supported by the XDRPC allocation system. You will need to use the XDRPC allocation system to create the data for the references on the Xbox and change the struct to have uints filled with the XDRPCReference.Pointer values for that data instead of the references. See the How to Use XDRPC documentation for more info."));
            }
            return(requiredBufferSize);
        }
예제 #13
0
 public static XDRPCReference AllocateRPC(
     this IXboxConsole console,
     XDRPCArgumentInfo lpvBufArg,
     XDRPCMode mode)
 {
     if (lpvBufArg.PassBy == ArgumentType.ByValue)
     {
         throw new XDRPCInvalidOperationException("Allocating XDRPCArgumentInfo with ByValue argument type is not allowed.");
     }
     if (lpvBufArg.GetRequiredReferenceSize() > 0)
     {
         throw new XDRPCInvalidOperationException("Struct type containing references is not supported by the XDRPC allocation system. You will need to use the XDRPC allocation system to create the data for the references on the Xbox and change the struct to have uints filled with the XDRPCReference.Pointer values for that data instead of the references. See the How to Use XDRPC documentation for more info.");
     }
     return(console.AllocateRPC(lpvBufArg.GetRequiredBufferSize(), mode));
 }
예제 #14
0
        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));
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
 public static XDRPCReference AllocateRPC(
     this IXboxConsole console,
     XDRPCArgumentInfo lpvBufArg)
 {
     return(console.AllocateRPC(lpvBufArg, XDRPCMode.System));
 }