Exemplo n.º 1
0
 private void WriteMarshalToNativeForNonSealedType(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable)
 {
     object[] args = new object[] { sourceVariable.Load() };
     writer.WriteLine("if (({0})->klass->is_import_or_windows_runtime)", args);
     using (new BlockWriter(writer, false))
     {
         if (this._isClass)
         {
             object[] objArray2 = new object[] { destinationVariable, sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.ForComTypeInterfaceFieldGetter(this._defaultInterface) };
             writer.WriteLine("{0} = ({1})->{2}();", objArray2);
             object[] objArray3 = new object[] { destinationVariable };
             writer.WriteLine("{0}->AddRef();", objArray3);
         }
         else
         {
             object[] objArray4 = new object[] { DefaultMarshalInfoWriter.Naming.ForInteropHResultVariable(), DefaultMarshalInfoWriter.Naming.ForVariable(DefaultMarshalInfoWriter.TypeProvider.Il2CppComObjectTypeReference), sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.ForIl2CppComObjectIdentityField(), this._interfaceTypeName, destinationVariable };
             writer.WriteLine("il2cpp_hresult_t {0} = (({1}){2})->{3}->QueryInterface({4}::IID, reinterpret_cast<void**>(&{5}));", objArray4);
             writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", DefaultMarshalInfoWriter.Naming.ForInteropHResultVariable()));
         }
     }
     writer.WriteLine("else");
     using (new BlockWriter(writer, false))
     {
         object[] objArray5 = new object[] { destinationVariable, this._interfaceTypeName, sourceVariable.Load() };
         writer.WriteLine("{0} = il2cpp_codegen_com_get_or_create_ccw<{1}>({2});", objArray5);
     }
 }
        public override string WriteMarshalReturnValueToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, IRuntimeMetadataAccess metadataAccess)
        {
            string variableName = $"_{sourceVariable.GetNiceName()}_marshaled";

            this.WriteNativeVariableDeclarationOfType(writer, variableName);
            this.WriteMarshalVariableToNative(writer, sourceVariable, variableName, null, metadataAccess, true);
            return(variableName);
        }
Exemplo n.º 3
0
 public override string WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     if (DefaultMarshalInfoWriter.Naming.ForVariable(base._typeRef) != this._marshaledTypes[0].DecoratedName)
     {
         return($"reinterpret_cast<{this._marshaledTypes[0].DecoratedName}>({sourceVariable.Load()})");
     }
     return(sourceVariable.Load());
 }
 public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     if (!this.CanMarshalTypeToNative())
     {
         throw new InvalidOperationException("Cannot marshal HandleRef by reference to native code.");
     }
     if (< > f__am$cache0 == null)
     {
 public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     if (this._marshalInfo.ElementType == VariantType.BStr)
     {
         object[] args = new object[] { destinationVariable, sourceVariable.Load() };
         writer.WriteLine("{0} = il2cpp_codegen_com_marshal_safe_array_bstring({1});", args);
     }
     else
     {
         object[] objArray2 = new object[] { destinationVariable, this._marshalInfo.ElementType.ToString().ToUpper(), sourceVariable.Load() };
         writer.WriteLine("{0} = il2cpp_codegen_com_marshal_safe_array(IL2CPP_VT_{1}, {2});", objArray2);
     }
 }
        private void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess, bool isMarshalingReturnValue)
        {
            string str;

            if (this._nativeType == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean))
            {
                object[] args = new object[] { sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.Null };
                writer.WriteLine("if ({0} == {1})", args);
                using (new BlockWriter(writer, false))
                {
                    object[] arguments = new object[] { !string.IsNullOrEmpty(managedVariableName) ? managedVariableName : sourceVariable.GetNiceName() };
                    writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_argument_null_exception(\"{0}\")", arguments));
                }
            }
            if (this.IsFixedSizeString)
            {
                str = !this.IsWideString ? "il2cpp_codegen_marshal_string_fixed" : "il2cpp_codegen_marshal_wstring_fixed";
                object[] objArray3 = new object[] { str, sourceVariable.Load(), this._marshaledTypeName, destinationVariable, ((FixedSysStringMarshalInfo)this._marshalInfo).Size };
                writer.WriteLine("{0}({1}, ({2})&{3}, {4});", objArray3);
            }
            else if (this._canReferenceOriginalManagedString && !isMarshalingReturnValue)
            {
                if (this._nativeType != Mono.Cecil.NativeType.LPWStr)
                {
                    if (this._nativeType != (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean))
                    {
                        throw new InvalidOperationException($"StringMarshalInfoWriter doesn't know how to marshal {this._nativeType} while maintaining reference to original managed string.");
                    }
                    string niceName = sourceVariable.GetNiceName();
                    string str4     = niceName + "NativeView";
                    string str5     = niceName + "HStringReference";
                    writer.WriteLine();
                    object[] objArray6 = new object[] { str4, sourceVariable.Load() };
                    writer.WriteLine("DECLARE_IL2CPP_STRING_AS_STRING_VIEW_OF_NATIVE_CHARS({0}, {1});", objArray6);
                    object[] objArray7 = new object[] { str5, str4 };
                    writer.WriteLine("il2cpp::utils::Il2CppHStringReference {0}({1});", objArray7);
                    object[] objArray8 = new object[] { destinationVariable, str5 };
                    writer.WriteLine("{0} = {1};", objArray8);
                }
                else
                {
                    string   str2      = sourceVariable.Load();
                    object[] objArray4 = new object[] { str2, DefaultMarshalInfoWriter.Naming.Null };
                    writer.WriteLine("if ({0} != {1})", objArray4);
                    using (new BlockWriter(writer, false))
                    {
                        if (< > f__am$cache0 == null)
                        {
Exemplo n.º 7
0
        protected string WriteArraySizeFromManagedArray(CppCodeWriter writer, ManagedMarshalValue managedArray, string nativeArray)
        {
            string str;

            if (this._arraySizeSelection != ArraySizeOptions.UseFirstMarshaledType)
            {
                str = $"_{managedArray.GetNiceName()}_Length";
                object[] objArray1 = new object[] { str, managedArray.Load() };
                writer.WriteLine("int32_t {0} = ({1})->max_length;", objArray1);
                return(str);
            }
            str = nativeArray + this._marshaledTypes[0].VariableName;
            object[] args = new object[] { str, managedArray.Load() };
            writer.WriteLine("{0} = static_cast<uint32_t>(({1})->max_length);", args);
            return($"static_cast<int32_t>({str})");
        }
Exemplo n.º 8
0
        protected override void WriteMarshalFromNativeMethodDefinition(CppCodeWriter writer)
        {
            string uniqueIdentifier = $"{DefaultMarshalInfoWriter.Naming.ForType(base._type)}_{MarshalingUtils.MarshalTypeToString(base._marshalType)}_FromNativeMethodDefinition";

            MethodWriter.WriteMethodWithMetadataInitialization(writer, base._marshalFromNativeFunctionDeclaration, base._marshalFromNativeFunctionName, delegate(CppCodeWriter bodyWriter, MetadataUsage metadataUsage, MethodUsage methodUsage) {
                DefaultRuntimeMetadataAccess metadataAccess = new DefaultRuntimeMetadataAccess(null, metadataUsage, methodUsage);
                for (int j = 0; j < base.Fields.Length; j++)
                {
                    FieldDefinition field = base.Fields[j];
                    ManagedMarshalValue destinationVariable = new ManagedMarshalValue("unmarshaled", field);
                    if (!field.FieldType.IsValueType())
                    {
                        base.FieldMarshalInfoWriters[j].WriteMarshalVariableFromNative(bodyWriter, base.FieldMarshalInfoWriters[j].UndecorateVariable($"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(field)}"), destinationVariable, null, false, false, metadataAccess);
                    }
                    else
                    {
                        string name = destinationVariable.GetNiceName() + "_temp_" + j;
                        bodyWriter.WriteVariable(field.FieldType, name);
                        base.FieldMarshalInfoWriters[j].WriteMarshalVariableFromNative(bodyWriter, $"marshaled.{DefaultMarshalInfoWriter.Naming.ForField(field)}", new ManagedMarshalValue(name), null, false, false, metadataAccess);
                        bodyWriter.WriteLine(destinationVariable.Store(name));
                    }
                }
            }, uniqueIdentifier);
        }
Exemplo n.º 9
0
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     writer.WriteLine(destinationVariable.Store(this.WriteMarshalVariableFromNative(writer, variableName, methodParameters, returnValue, forNativeWrapperOfManagedMethod, metadataAccess)));
 }
Exemplo n.º 10
0
 public override void WriteMarshalOutParameterToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IList <MarshaledParameter> methodParameters, IRuntimeMetadataAccess metadataAccess)
 {
     this._elementTypeMarshalInfoWriter.WriteMarshalVariableToNative(writer, sourceVariable.Dereferenced, DefaultMarshalInfoWriter.Naming.Dereference(this.UndecorateVariable(destinationVariable)), managedVariableName, metadataAccess);
 }
Exemplo n.º 11
0
 public override void WriteMarshalOutParameterFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     this._elementTypeMarshalInfoWriter.WriteMarshalVariableFromNative(writer, DefaultMarshalInfoWriter.Naming.Dereference(variableName), destinationVariable.Dereferenced, methodParameters, returnValue, forNativeWrapperOfManagedMethod, metadataAccess);
 }
Exemplo n.º 12
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));
     }
 }
Exemplo n.º 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)
        {
            string str;

            if (this._isStringBuilder)
            {
                str = !this.IsWideString ? "il2cpp_codegen_marshal_string_builder_result" : "il2cpp_codegen_marshal_wstring_builder_result";
                object[] args = new object[] { str, destinationVariable.Load(), variableName };
                writer.WriteLine("{0}({1}, {2});", args);
            }
            else
            {
                Mono.Cecil.NativeType type = this._nativeType;
                if (type == Mono.Cecil.NativeType.BStr)
                {
                    str = "il2cpp_codegen_marshal_bstring_result";
                }
                else if (type == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean))
                {
                    str = "il2cpp_codegen_marshal_hstring_result";
                }
                else
                {
                    str = !this.IsWideString ? "il2cpp_codegen_marshal_string_result" : "il2cpp_codegen_marshal_wstring_result";
                }
                object[] objArray2 = new object[] { str, variableName };
                writer.WriteLine(destinationVariable.Store("{0}({1})", objArray2));
            }
        }
 public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     this.WriteMarshalVariableToNative(writer, sourceVariable, destinationVariable, managedVariableName, metadataAccess, false);
 }
Exemplo n.º 16
0
 public virtual void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { sourceVariable.Load(), destinationVariable };
     writer.WriteLine("{1} = {0};", args);
 }
Exemplo n.º 17
0
 public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { sourceVariable.Load(), destinationVariable };
     writer.WriteLine("il2cpp_codegen_com_marshal_variant((Il2CppCodeGenObject*)({0}), &({1}));", args);
 }
Exemplo n.º 18
0
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { variableName };
     writer.WriteLine(destinationVariable.Store("(Il2CppObject*)il2cpp_codegen_com_marshal_variant_result(&({0}))", args));
 }
Exemplo n.º 19
0
 public virtual string WriteMarshalReturnValueToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, IRuntimeMetadataAccess metadataAccess) =>
 this.WriteMarshalVariableToNative(writer, sourceVariable, null, metadataAccess);
 public override void WriteMarshalVariableFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     throw new InvalidOperationException("Cannot marshal HandleRef from native code");
 }
Exemplo n.º 21
0
 public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { destinationVariable, this.WriteMarshalVariableToNative(writer, sourceVariable, managedVariableName, metadataAccess) };
     writer.WriteLine("{0} = {1};", 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));
     }
 }
Exemplo n.º 23
0
 public override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { destinationVariable, sourceVariable.Load() };
     writer.WriteLine("{0} = il2cpp_codegen_marshal_delegate(reinterpret_cast<Il2CppCodeGenMulticastDelegate*>({1}));", args);
 }
Exemplo n.º 24
0
 public virtual void WriteMarshalOutParameterToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IList <MarshaledParameter> methodParameters, IRuntimeMetadataAccess metadataAccess)
 {
 }
Exemplo n.º 25
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));
 }
Exemplo n.º 26
0
        public override string WriteMarshalEmptyVariableToNative(CppCodeWriter writer, ManagedMarshalValue variableName, IList <MarshaledParameter> methodParameters)
        {
            string str = $"_{variableName.GetNiceName()}_empty";

            this._elementTypeMarshalInfoWriter.WriteNativeVariableDeclarationOfType(writer, str);
            return(DefaultMarshalInfoWriter.Naming.AddressOf(str));
        }
Exemplo n.º 27
0
 public override string WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess) =>
 sourceVariable.LoadAddress();
Exemplo n.º 28
0
 public sealed override void WriteMarshalVariableToNative(CppCodeWriter writer, ManagedMarshalValue sourceVariable, string destinationVariable, string managedVariableName, IRuntimeMetadataAccess metadataAccess)
 {
     object[] args = new object[] { sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.Null };
     writer.WriteLine("if ({0} != {1})", args);
     using (new BlockWriter(writer, false))
     {
         if (this._isSealed)
         {
             object[] objArray2 = new object[] { destinationVariable, sourceVariable.Load(), DefaultMarshalInfoWriter.Naming.ForComTypeInterfaceFieldGetter(this._defaultInterface) };
             writer.WriteLine("{0} = ({1})->{2}();", objArray2);
         }
         else
         {
             this.WriteMarshalToNativeForNonSealedType(writer, sourceVariable, destinationVariable);
         }
     }
     writer.WriteLine("else");
     using (new BlockWriter(writer, false))
     {
         object[] objArray3 = new object[] { destinationVariable, DefaultMarshalInfoWriter.Naming.Null };
         writer.WriteLine("{0} = {1};", objArray3);
     }
 }
        public override string WriteMarshalEmptyVariableToNative(CppCodeWriter writer, ManagedMarshalValue variableName, IList <MarshaledParameter> methodParameters)
        {
            string str = $"_{variableName.GetNiceName()}_marshaled";

            this.WriteNativeVariableDeclarationOfType(writer, str);
            return(str);
        }
Exemplo n.º 30
0
 public virtual void WriteMarshalOutParameterFromNative(CppCodeWriter writer, string variableName, ManagedMarshalValue destinationVariable, IList <MarshaledParameter> methodParameters, bool returnValue, bool forNativeWrapperOfManagedMethod, IRuntimeMetadataAccess metadataAccess)
 {
     this.WriteMarshalVariableFromNative(writer, variableName, destinationVariable, methodParameters, returnValue, forNativeWrapperOfManagedMethod, metadataAccess);
 }