예제 #1
0
 public static string Box(TypeReference type, string value, IRuntimeMetadataAccess metadataAccess)
 {
     if (!Extensions.IsValueType(type))
     {
         return Cast(type, value);
     }
     return Call("Box", metadataAccess.TypeInfoFor(type), "&" + value);
 }
예제 #2
0
 public static string NewSZArray(ArrayType arrayType, string length, IRuntimeMetadataAccess metadataAccess)
 {
     if (arrayType.Rank != 1)
     {
         throw new ArgumentException("Attempting for create a new sz array of invalid rank.", "arrayType");
     }
     return(Cast(arrayType, Call("SZArrayNew", metadataAccess.TypeInfoFor(arrayType), length)));
 }
예제 #3
0
 public static string Box(TypeReference type, string value, IRuntimeMetadataAccess metadataAccess)
 {
     if (!type.IsValueType())
     {
         return(Cast(type, value));
     }
     return(Call("Box", metadataAccess.TypeInfoFor(type), "&" + value));
 }
예제 #4
0
        public static string NewObj(TypeReference type, IRuntimeMetadataAccess metadataAccess)
        {
            string str = Call("il2cpp_codegen_object_new", metadataAccess.TypeInfoFor(type));

            if (type.IsValueType())
            {
                return(str);
            }
            return(Cast(Naming.ForTypeNameOnly(type) + "*", str));
        }
 protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
 {
     string str = InteropMethodBodyWriter.Naming.ForTypeNameOnly(this._interfaceType);
     string str2 = InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType);
     if (this.UseQueryInterfaceToObtainInterfacePointer)
     {
         object[] args = new object[] { str, str2, InteropMethodBodyWriter.Naming.Null };
         writer.WriteLine("{0}* {1} = {2};", args);
         object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForInteropHResultVariable(), InteropMethodBodyWriter.Naming.ForVariable(InteropMethodBodyWriter.TypeProvider.Il2CppComObjectTypeReference), InteropMethodBodyWriter.Naming.ThisParameterName, InteropMethodBodyWriter.Naming.ForIl2CppComObjectIdentityField(), str, str2 };
         writer.WriteLine("il2cpp_hresult_t {0} = static_cast<{1}>({2})->{3}->QueryInterface({4}::IID, reinterpret_cast<void**>(&{5}));", objArray2);
         writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable()));
     }
     else
     {
         string str3 = !this._actualMethod.HasThis ? string.Format("(({0}*){1}->static_fields)", InteropMethodBodyWriter.Naming.ForStaticFieldsStruct(this._actualMethod.DeclaringType), metadataAccess.TypeInfoFor(this._actualMethod.DeclaringType)) : string.Format("{0}", InteropMethodBodyWriter.Naming.ThisParameterName);
         object[] objArray3 = new object[] { InteropMethodBodyWriter.Naming.ForTypeNameOnly(this._interfaceType), InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType), str3, InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldGetter(this._interfaceType) };
         writer.WriteLine("{0}* {1} = {2}->{3}();", objArray3);
     }
     writer.WriteLine();
 }
 protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess)
 {
     MethodReturnType methodReturnType = this.GetMethodReturnType();
     if (methodReturnType.ReturnType.MetadataType != MetadataType.Void)
     {
         object[] args = new object[] { InteropMethodBodyWriter.Naming.ForVariable(base._typeResolver.Resolve(methodReturnType.ReturnType)), InteropMethodBodyWriter.Naming.ForInteropReturnValue() };
         writer.WriteLine("{0} {1};", args);
     }
     writer.WriteLine("try");
     using (new BlockWriter(writer, false))
     {
         if (Extensions.IsValueType(base._managedMethod.DeclaringType))
         {
             object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForTypeNameOnly(base._managedMethod.DeclaringType), InteropMethodBodyWriter.Naming.ThisParameterName, metadataAccess.TypeInfoFor(base._managedMethod.DeclaringType) };
             writer.WriteLine("{0}* {1} = ({0}*)UnBox(GetManagedObjectInline(), {2});", objArray2);
         }
         else
         {
             object[] objArray3 = new object[] { InteropMethodBodyWriter.Naming.ForVariable(base._managedMethod.DeclaringType), InteropMethodBodyWriter.Naming.ThisParameterName };
             writer.WriteLine("{0} {1} = ({0})GetManagedObjectInline();", objArray3);
         }
         string block = base.GetMethodCallExpression(metadataAccess, InteropMethodBodyWriter.Naming.ThisParameterName, localVariableNames);
         if (methodReturnType.ReturnType.MetadataType != MetadataType.Void)
         {
             object[] objArray4 = new object[] { InteropMethodBodyWriter.Naming.ForInteropReturnValue(), block };
             writer.WriteLine("{0} = {1};", objArray4);
         }
         else
         {
             writer.WriteStatement(block);
         }
     }
     writer.WriteLine("catch (const Il2CppExceptionWrapper& ex)");
     using (new BlockWriter(writer, false))
     {
         writer.WriteLine("return ex.ex->hresult;");
     }
 }
        private void ActivateThroughCompositionFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters, IRuntimeMetadataAccess metadataAccess)
        {
            string        str           = metadataAccess.TypeInfoFor(this.constructedObjectType);
            string        str2          = InteropMethodBodyWriter.Naming.ForMethod(this.factoryMethod);
            TypeReference interfaceType = this.constructedObjectType.Resolve().ExtractDefaultInterface();
            string        str3          = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldName(interfaceType);

            writer.WriteLine($"Il2CppIInspectable* outerInstance = {InteropMethodBodyWriter.Naming.Null};");
            writer.WriteLine($"Il2CppIInspectable** innerInstance = {InteropMethodBodyWriter.Naming.Null};");
            writer.WriteLine($"bool isComposedConstruction = {this.thisParameter}->klass != {str};");
            WriteDeclareActivationFactory(writer, this.factoryMethod.DeclaringType, staticFieldsAccess);
            writer.WriteLine();
            writer.WriteLine("if (isComposedConstruction)");
            using (new BlockWriter(writer, false))
            {
                writer.WriteLine($"outerInstance = il2cpp_codegen_com_get_or_create_ccw<Il2CppIInspectable>({this.thisParameter});");
                writer.WriteLine($"innerInstance = reinterpret_cast<Il2CppIInspectable**>(&{this.thisParameter}->{this.identityField});");
            }
            writer.WriteLine();
            writer.WriteLine($"il2cpp_hresult_t hr = activationFactory->{str2}({parameters}outerInstance, innerInstance, &{this.thisParameter}->{str3});");
            writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);");
            writer.WriteLine();
            writer.WriteLine("if (isComposedConstruction)");
            using (new BlockWriter(writer, false))
            {
                writer.WriteLine("outerInstance->Release();");
                writer.WriteLine($"{this.thisParameter}->{str3}->Release();");
            }
            writer.WriteLine("else");
            using (new BlockWriter(writer, false))
            {
                writer.WriteLine($"hr = {this.thisParameter}->{str3}->QueryInterface(Il2CppIUnknown::IID, reinterpret_cast<void**>(&{this.thisParameter}->{this.identityField}));");
                writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);");
                writer.WriteLine();
                writer.WriteLine($"il2cpp_codegen_com_register_rcw({this.thisParameter});");
            }
        }
        protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess)
        {
            string str  = InteropMethodBodyWriter.Naming.ForStaticFieldsStruct(this.constructedObjectType);
            string str2 = metadataAccess.TypeInfoFor(this.constructedObjectType);
            string staticFieldsAccess = string.Format($"(({str}*){str2}->static_fields)", new object[0]);
            string functionCallParametersExpression = base.GetFunctionCallParametersExpression(localVariableNames);

            if (functionCallParametersExpression.Length > 0)
            {
                functionCallParametersExpression = functionCallParametersExpression + ", ";
            }
            if (this.factoryMethod == null)
            {
                this.WriteActivateThroughIActivationFactory(writer, staticFieldsAccess, functionCallParametersExpression);
            }
            else if (!this.isComposingConstructor)
            {
                this.ActivateThroughCustomActivationFactory(writer, staticFieldsAccess, functionCallParametersExpression);
            }
            else
            {
                this.ActivateThroughCompositionFactory(writer, staticFieldsAccess, functionCallParametersExpression, metadataAccess);
            }
        }
 private void ActivateThroughCompositionFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters, IRuntimeMetadataAccess metadataAccess)
 {
     string str = metadataAccess.TypeInfoFor(this.constructedObjectType);
     string str2 = InteropMethodBodyWriter.Naming.ForMethod(this.factoryMethod);
     TypeReference interfaceType = Extensions.ExtractDefaultInterface(this.constructedObjectType.Resolve());
     string str3 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldName(interfaceType);
     writer.WriteLine(string.Format("Il2CppIInspectable* outerInstance = {0};", InteropMethodBodyWriter.Naming.Null));
     writer.WriteLine(string.Format("Il2CppIInspectable** innerInstance = {0};", InteropMethodBodyWriter.Naming.Null));
     writer.WriteLine(string.Format("bool isComposedConstruction = {0}->klass != {1};", this.thisParameter, str));
     WriteDeclareActivationFactory(writer, this.factoryMethod.DeclaringType, staticFieldsAccess);
     writer.WriteLine();
     writer.WriteLine("if (isComposedConstruction)");
     using (new BlockWriter(writer, false))
     {
         writer.WriteLine(string.Format("outerInstance = il2cpp_codegen_com_get_or_create_ccw<Il2CppIInspectable>({0});", this.thisParameter));
         writer.WriteLine(string.Format("innerInstance = reinterpret_cast<Il2CppIInspectable**>(&{0}->{1});", this.thisParameter, this.identityField));
     }
     writer.WriteLine();
     writer.WriteLine(string.Format("il2cpp_hresult_t hr = activationFactory->{0}({1}outerInstance, innerInstance, &{2}->{3});", new object[] { str2, parameters, this.thisParameter, str3 }));
     writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);");
     writer.WriteLine();
     writer.WriteLine("if (isComposedConstruction)");
     using (new BlockWriter(writer, false))
     {
         writer.WriteLine("outerInstance->Release();");
         writer.WriteLine(string.Format("{0}->{1}->Release();", this.thisParameter, str3));
     }
     writer.WriteLine("else");
     using (new BlockWriter(writer, false))
     {
         writer.WriteLine(string.Format("hr = {0}->{1}->QueryInterface(Il2CppIUnknown::IID, reinterpret_cast<void**>(&{2}->{3}));", new object[] { this.thisParameter, str3, this.thisParameter, this.identityField }));
         writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);");
         writer.WriteLine();
         writer.WriteLine(string.Format("il2cpp_codegen_com_register_rcw({0});", this.thisParameter));
     }
 }
예제 #10
0
        protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess)
        {
            MethodReturnType methodReturnType = this.GetMethodReturnType();

            if (methodReturnType.ReturnType.MetadataType != MetadataType.Void)
            {
                object[] args = new object[] { InteropMethodBodyWriter.Naming.ForVariable(base._typeResolver.Resolve(methodReturnType.ReturnType)), InteropMethodBodyWriter.Naming.ForInteropReturnValue() };
                writer.WriteLine("{0} {1};", args);
            }
            writer.WriteLine("try");
            using (new BlockWriter(writer, false))
            {
                if (base._managedMethod.DeclaringType.IsValueType())
                {
                    object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForTypeNameOnly(base._managedMethod.DeclaringType), InteropMethodBodyWriter.Naming.ThisParameterName, metadataAccess.TypeInfoFor(base._managedMethod.DeclaringType) };
                    writer.WriteLine("{0}* {1} = ({0}*)UnBox(GetManagedObjectInline(), {2});", objArray2);
                }
                else
                {
                    object[] objArray3 = new object[] { InteropMethodBodyWriter.Naming.ForVariable(base._managedMethod.DeclaringType), InteropMethodBodyWriter.Naming.ThisParameterName };
                    writer.WriteLine("{0} {1} = ({0})GetManagedObjectInline();", objArray3);
                }
                string block = base.GetMethodCallExpression(metadataAccess, InteropMethodBodyWriter.Naming.ThisParameterName, localVariableNames);
                if (methodReturnType.ReturnType.MetadataType != MetadataType.Void)
                {
                    object[] objArray4 = new object[] { InteropMethodBodyWriter.Naming.ForInteropReturnValue(), block };
                    writer.WriteLine("{0} = {1};", objArray4);
                }
                else
                {
                    writer.WriteStatement(block);
                }
            }
            writer.WriteLine("catch (const Il2CppExceptionWrapper& ex)");
            using (new BlockWriter(writer, false))
            {
                writer.WriteLine("return ex.ex->hresult;");
            }
        }
 protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess)
 {
     string str = InteropMethodBodyWriter.Naming.ForStaticFieldsStruct(this.constructedObjectType);
     string str2 = metadataAccess.TypeInfoFor(this.constructedObjectType);
     string staticFieldsAccess = string.Format(string.Format("(({0}*){1}->static_fields)", str, str2), new object[0]);
     string functionCallParametersExpression = base.GetFunctionCallParametersExpression(localVariableNames);
     if (functionCallParametersExpression.Length > 0)
     {
         functionCallParametersExpression = functionCallParametersExpression + ", ";
     }
     if (this.factoryMethod == null)
     {
         this.WriteActivateThroughIActivationFactory(writer, staticFieldsAccess, functionCallParametersExpression);
     }
     else if (!this.isComposingConstructor)
     {
         this.ActivateThroughCustomActivationFactory(writer, staticFieldsAccess, functionCallParametersExpression);
     }
     else
     {
         this.ActivateThroughCompositionFactory(writer, staticFieldsAccess, functionCallParametersExpression, metadataAccess);
     }
 }
예제 #12
0
        private void WriteMainInvocation(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
        {
            if (this.ValidateMainMethod(writer))
            {
                writer.AddIncludeForMethodDeclarations(_entryPoint.DeclaringType);
                List <string> argumentArray = new List <string> {
                    Naming.Null
                };
                if (_entryPoint.Parameters.Count > 0)
                {
                    ArrayType parameterType = (ArrayType)_entryPoint.Parameters[0].ParameterType;
                    writer.AddIncludeForTypeDefinition(parameterType);
                    object[] args = new object[] { Naming.ForVariable(parameterType), Emit.NewSZArray(parameterType, "argc - 1", metadataAccess) };
                    writer.WriteLine("{0} args = {1};", args);
                    writer.WriteLine();
                    writer.WriteLine("for (int i = 1; i < argc; i++)");
                    using (new BlockWriter(writer, false))
                    {
                        writer.WriteLine("DECLARE_NATIVE_C_STRING_AS_STRING_VIEW_OF_IL2CPP_CHARS(argumentUtf16, argv[i]);");
                        object[] objArray2 = new object[] { Naming.ForVariable(TypeProvider.SystemString) };
                        writer.WriteLine("{0} argument = il2cpp_codegen_string_new_utf16(argumentUtf16);", objArray2);
                        writer.WriteStatement(Emit.StoreArrayElement("args", "i - 1", "argument", false));
                    }
                    writer.WriteLine();
                    argumentArray.Add("args");
                }
                if (MethodSignatureWriter.NeedsHiddenMethodInfo(_entryPoint, MethodCallType.Normal, false))
                {
                    argumentArray.Add(metadataAccess.HiddenMethodInfo(_entryPoint));
                }
                if ((_entryPoint.DeclaringType.Attributes & (TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit)) == TypeAttributes.AnsiClass)
                {
                    object[] objArray3 = new object[] { metadataAccess.TypeInfoFor(_entryPoint.DeclaringType) };
                    writer.WriteLine("IL2CPP_RUNTIME_CLASS_INIT({0});", objArray3);
                }
                Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolverForMethodToCall = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(_entryPoint.DeclaringType, _entryPoint);
                string block = MethodBodyWriter.GetMethodCallExpression(null, _entryPoint, _entryPoint, typeResolverForMethodToCall, MethodCallType.Normal, metadataAccess, new VTableBuilder(), argumentArray, false, null);
                switch (_entryPoint.ReturnType.MetadataType)
                {
                case MetadataType.Void:
                    writer.WriteStatement(block);
                    writer.WriteLine("return 0;");
                    break;

                case MetadataType.Int32:
                {
                    object[] objArray4 = new object[] { block };
                    writer.WriteLine("return {0};", objArray4);
                    break;
                }

                case MetadataType.UInt32:
                {
                    object[] objArray5 = new object[] { block };
                    writer.WriteLine("uint32_t exitCode = {0};", objArray5);
                    writer.WriteLine("return static_cast<int>(exitCode);");
                    break;
                }
                }
            }
        }
예제 #13
0
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { DefaultMarshalInfoWriter.Naming.ForType(base._typeRef), variableName, metadataAccess.TypeInfoFor(base._typeRef) };
     writer.WriteLine(destinationVariable.Store("il2cpp_codegen_marshal_function_ptr_to_delegate<{0}>({1}, {2})", args));
 }
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList<MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     if (this._marshalInfo.ElementType == VariantType.BStr)
     {
         object[] args = new object[] { DefaultMarshalInfoWriter.Naming.ForType(base._typeRef), metadataAccess.TypeInfoFor(this._elementType), variableName };
         writer.WriteLine(destinationVariable.Store("({0}*)il2cpp_codegen_com_marshal_safe_array_bstring_result({1}, {2})", args));
     }
     else
     {
         object[] objArray2 = new object[] { DefaultMarshalInfoWriter.Naming.ForType(base._typeRef), this._marshalInfo.ElementType.ToString().ToUpper(), metadataAccess.TypeInfoFor(this._elementType), variableName };
         writer.WriteLine(destinationVariable.Store("({0}*)il2cpp_codegen_com_marshal_safe_array_result(IL2CPP_VT_{1}, {2}, {3})", objArray2));
     }
 }
예제 #15
0
        private void WriteMainInvocation(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
        {
            if (this.ValidateMainMethod(writer))
            {
                writer.AddIncludeForMethodDeclarations(_entryPoint.DeclaringType);
                List<string> argumentArray = new List<string> {
                    Naming.Null
                };
                if (_entryPoint.Parameters.Count > 0)
                {
                    ArrayType parameterType = (ArrayType) _entryPoint.Parameters[0].ParameterType;
                    writer.AddIncludeForTypeDefinition(parameterType);
                    object[] args = new object[] { Naming.ForVariable(parameterType), Emit.NewSZArray(parameterType, "argc - 1", metadataAccess) };
                    writer.WriteLine("{0} args = {1};", args);
                    writer.WriteLine();
                    writer.WriteLine("for (int i = 1; i < argc; i++)");
                    using (new BlockWriter(writer, false))
                    {
                        writer.WriteLine("DECLARE_NATIVE_C_STRING_AS_STRING_VIEW_OF_IL2CPP_CHARS(argumentUtf16, argv[i]);");
                        object[] objArray2 = new object[] { Naming.ForVariable(TypeProvider.SystemString) };
                        writer.WriteLine("{0} argument = il2cpp_codegen_string_new_utf16(argumentUtf16);", objArray2);
                        writer.WriteStatement(Emit.StoreArrayElement("args", "i - 1", "argument", false));
                    }
                    writer.WriteLine();
                    argumentArray.Add("args");
                }
                if (MethodSignatureWriter.NeedsHiddenMethodInfo(_entryPoint, MethodCallType.Normal, false))
                {
                    argumentArray.Add(metadataAccess.HiddenMethodInfo(_entryPoint));
                }
                if ((_entryPoint.DeclaringType.Attributes & (TypeAttributes.AnsiClass | TypeAttributes.BeforeFieldInit)) == TypeAttributes.AnsiClass)
                {
                    object[] objArray3 = new object[] { metadataAccess.TypeInfoFor(_entryPoint.DeclaringType) };
                    writer.WriteLine("IL2CPP_RUNTIME_CLASS_INIT({0});", objArray3);
                }
                Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolverForMethodToCall = Unity.IL2CPP.ILPreProcessor.TypeResolver.For(_entryPoint.DeclaringType, _entryPoint);
                string block = MethodBodyWriter.GetMethodCallExpression(null, _entryPoint, _entryPoint, typeResolverForMethodToCall, MethodCallType.Normal, metadataAccess, new VTableBuilder(), argumentArray, false, null);
                switch (_entryPoint.ReturnType.MetadataType)
                {
                    case MetadataType.Void:
                        writer.WriteStatement(block);
                        writer.WriteLine("return 0;");
                        break;

                    case MetadataType.Int32:
                    {
                        object[] objArray4 = new object[] { block };
                        writer.WriteLine("return {0};", objArray4);
                        break;
                    }
                    case MetadataType.UInt32:
                    {
                        object[] objArray5 = new object[] { block };
                        writer.WriteLine("uint32_t exitCode = {0};", objArray5);
                        writer.WriteLine("return static_cast<int>(exitCode);");
                        break;
                    }
                }
            }
        }
예제 #16
0
 public static string NewObj(TypeReference type, IRuntimeMetadataAccess metadataAccess)
 {
     string str = Call("il2cpp_codegen_object_new", metadataAccess.TypeInfoFor(type));
     if (Extensions.IsValueType(type))
     {
         return str;
     }
     return Cast(Naming.ForTypeNameOnly(type) + "*", str);
 }
예제 #17
0
 public static string NewSZArray(ArrayType arrayType, string length, IRuntimeMetadataAccess metadataAccess)
 {
     if (arrayType.Rank != 1)
     {
         throw new ArgumentException("Attempting for create a new sz array of invalid rank.", "arrayType");
     }
     return Cast(arrayType, Call("SZArrayNew", metadataAccess.TypeInfoFor(arrayType), length));
 }
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList<MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { DefaultMarshalInfoWriter.Naming.ForType(base._typeRef), variableName, metadataAccess.TypeInfoFor(base._typeRef) };
     writer.WriteLine(destinationVariable.Store("il2cpp_codegen_marshal_function_ptr_to_delegate<{0}>({1}, {2})", args));
 }
예제 #19
0
 public sealed override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null };
     writer.WriteLine("if ({0} != {1})", args);
     using (new BlockWriter(writer, false))
     {
         TypeReference type = (!base._typeRef.IsInterface() && base._typeRef.Resolve().IsComOrWindowsRuntimeType()) ? base._typeRef : DefaultMarshalInfoWriter.TypeProvider.Il2CppComObjectTypeReference;
         if (this._isSealed)
         {
             object[] objArray2 = new object[] { this._managedTypeName, variableName, metadataAccess.TypeInfoFor(base._typeRef) };
             writer.WriteLine(destinationVariable.Store("il2cpp_codegen_com_get_or_create_rcw_for_sealed_class<{0}>({1}, {2})", objArray2));
         }
         else if (this._marshalAsInspectable)
         {
             object[] objArray3 = new object[] { this._managedTypeName, variableName, metadataAccess.TypeInfoFor(type) };
             writer.WriteLine(destinationVariable.Store("il2cpp_codegen_com_get_or_create_rcw_from_iinspectable<{0}>({1}, {2})", objArray3));
         }
         else
         {
             object[] objArray4 = new object[] { this._managedTypeName, variableName, metadataAccess.TypeInfoFor(type) };
             writer.WriteLine(destinationVariable.Store("il2cpp_codegen_com_get_or_create_rcw_from_iunknown<{0}>({1}, {2})", objArray4));
         }
     }
     writer.WriteLine("else");
     using (new BlockWriter(writer, false))
     {
         writer.WriteLine(destinationVariable.Store(DefaultMarshalInfoWriter.Naming.Null));
     }
 }
예제 #20
0
 protected void AllocateAndStoreManagedArray(CppCodeWriter writer, ManagedMarshalValue destinationVariable, IRuntimeMetadataAccess metadataAccess, string arraySizeVariable)
 {
     object[] args = new object[] { DefaultMarshalInfoWriter.Naming.ForVariable(this._arrayType), metadataAccess.TypeInfoFor(this._arrayType), arraySizeVariable };
     writer.WriteLine(destinationVariable.Store("reinterpret_cast<{0}>(SZArrayNew({1}, {2}))", args));
 }
 public sealed override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList<MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null };
     writer.WriteLine("if ({0} != {1})", args);
     using (new BlockWriter(writer, false))
     {
         TypeReference type = (!Extensions.IsInterface(base._typeRef) && Extensions.IsComOrWindowsRuntimeType(base._typeRef.Resolve())) ? base._typeRef : DefaultMarshalInfoWriter.TypeProvider.Il2CppComObjectTypeReference;
         if (this._isSealed)
         {
             object[] objArray2 = new object[] { this._managedTypeName, variableName, metadataAccess.TypeInfoFor(base._typeRef) };
             writer.WriteLine(destinationVariable.Store("il2cpp_codegen_com_get_or_create_rcw_for_sealed_class<{0}>({1}, {2})", objArray2));
         }
         else if (this._marshalAsInspectable)
         {
             object[] objArray3 = new object[] { this._managedTypeName, variableName, metadataAccess.TypeInfoFor(type) };
             writer.WriteLine(destinationVariable.Store("il2cpp_codegen_com_get_or_create_rcw_from_iinspectable<{0}>({1}, {2})", objArray3));
         }
         else
         {
             object[] objArray4 = new object[] { this._managedTypeName, variableName, metadataAccess.TypeInfoFor(type) };
             writer.WriteLine(destinationVariable.Store("il2cpp_codegen_com_get_or_create_rcw_from_iunknown<{0}>({1}, {2})", objArray4));
         }
     }
     writer.WriteLine("else");
     using (new BlockWriter(writer, false))
     {
         writer.WriteLine(destinationVariable.Store(DefaultMarshalInfoWriter.Naming.Null));
     }
 }
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     if (this._marshalInfo.ElementType == VariantType.BStr)
     {
         object[] args = new object[] { DefaultMarshalInfoWriter.Naming.ForType(base._typeRef), metadataAccess.TypeInfoFor(this._elementType), variableName };
         writer.WriteLine(destinationVariable.Store("({0}*)il2cpp_codegen_com_marshal_safe_array_bstring_result({1}, {2})", args));
     }
     else
     {
         object[] objArray2 = new object[] { DefaultMarshalInfoWriter.Naming.ForType(base._typeRef), this._marshalInfo.ElementType.ToString().ToUpper(), metadataAccess.TypeInfoFor(this._elementType), variableName };
         writer.WriteLine(destinationVariable.Store("({0}*)il2cpp_codegen_com_marshal_safe_array_result(IL2CPP_VT_{1}, {2}, {3})", objArray2));
     }
 }
예제 #23
0
        protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess)
        {
            string str  = InteropMethodBodyWriter.Naming.ForTypeNameOnly(this._interfaceType);
            string str2 = InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType);

            if (this.UseQueryInterfaceToObtainInterfacePointer)
            {
                object[] args = new object[] { str, str2, InteropMethodBodyWriter.Naming.Null };
                writer.WriteLine("{0}* {1} = {2};", args);
                object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForInteropHResultVariable(), InteropMethodBodyWriter.Naming.ForVariable(InteropMethodBodyWriter.TypeProvider.Il2CppComObjectTypeReference), InteropMethodBodyWriter.Naming.ThisParameterName, InteropMethodBodyWriter.Naming.ForIl2CppComObjectIdentityField(), str, str2 };
                writer.WriteLine("il2cpp_hresult_t {0} = static_cast<{1}>({2})->{3}->QueryInterface({4}::IID, reinterpret_cast<void**>(&{5}));", objArray2);
                writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable()));
            }
            else
            {
                string   str3      = !this._actualMethod.HasThis ? $"(({InteropMethodBodyWriter.Naming.ForStaticFieldsStruct(this._actualMethod.DeclaringType)}*){metadataAccess.TypeInfoFor(this._actualMethod.DeclaringType)}->static_fields)" : $"{InteropMethodBodyWriter.Naming.ThisParameterName}";
                object[] objArray3 = new object[] { InteropMethodBodyWriter.Naming.ForTypeNameOnly(this._interfaceType), InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType), str3, InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldGetter(this._interfaceType) };
                writer.WriteLine("{0}* {1} = {2}->{3}();", objArray3);
            }
            writer.WriteLine();
        }