public virtual void WriteNativeVariableDeclarationOfType(CppCodeWriter writer, string variableName) { foreach (MarshaledType type in this.MarshaledTypes) { if (type.Name.EndsWith("*") || (type.Name == "Il2CppHString")) { object[] args = new object[] { type.Name, variableName + type.VariableName }; writer.WriteLine("{0} {1} = NULL;", args); } else if ((this._typeRef.MetadataType == MetadataType.Class) && !this._typeRef.DerivesFromObject()) { object[] objArray2 = new object[] { type.Name, variableName + type.VariableName }; writer.WriteLine("{0} {1} = {0}();", objArray2); } else if (this._typeRef.MetadataType.IsPrimitiveType()) { object[] objArray3 = new object[] { type.Name, variableName + type.VariableName, CppCodeWriter.InitializerStringForPrimitiveType(this._typeRef.MetadataType) }; writer.WriteLine("{0} {1} = {2};", objArray3); } else if (type.Name.IsPrimitiveCppType()) { object[] objArray4 = new object[] { type.Name, variableName + type.VariableName, CppCodeWriter.InitializerStringForPrimitiveCppType(type.Name) }; writer.WriteLine("{0} {1} = {2};", objArray4); } else { object[] objArray5 = new object[] { type.Name, variableName + type.VariableName }; writer.WriteLine("{0} {1} = {{ }};", objArray5); } } }
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 WriteMarshalCleanupReturnValue(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess) { object[] args = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_marshal_free({0});", args); object[] objArray2 = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", objArray2); }
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 void WriteMarshalCleanupVariable(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess, string managedVariableName = null) { object[] args = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_com_destroy_safe_array({0});", args); object[] objArray2 = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", objArray2); }
private void WriteActivateThroughIActivationFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters) { WriteDeclareActivationFactory(writer, InteropMethodBodyWriter.TypeProvider.IActivationFactoryTypeReference, staticFieldsAccess); writer.WriteLine($"il2cpp_hresult_t hr = activationFactory->ActivateInstance({parameters}reinterpret_cast<Il2CppIInspectable**>(&{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 WriteReturnStatementEpilogue(CppCodeWriter writer, string unmarshaledReturnValueVariableName) { if (this.GetMethodReturnType().ReturnType.MetadataType != MetadataType.Void) { object[] args = new object[] { InteropMethodBodyWriter.Naming.ForComInterfaceReturnParameterName(), unmarshaledReturnValueVariableName }; writer.WriteLine("*{0} = {1};", args); } writer.WriteLine("return IL2CPP_S_OK;"); }
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { string decoratedName = base._marshaledReturnType.DecoratedName; object[] args = new object[] { decoratedName, InteropMethodBodyWriter.Naming.ForPInvokeFunctionPointerTypedef(), base.FormatParametersForTypedef() }; writer.WriteLine("typedef {0} (STDCALL *{1})({2});", args); object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForPInvokeFunctionPointerTypedef(), InteropMethodBodyWriter.Naming.ForPInvokeFunctionPointerVariable(), InteropMethodBodyWriter.Naming.ThisParameterName }; writer.WriteLine("{0} {1} = reinterpret_cast<{0}>(((Il2CppDelegate*){2})->method->methodPointer);", objArray2); writer.WriteLine(); }
protected void WriteAssignNullArray(CppCodeWriter writer, string destinationVariable) { if (this._arraySizeSelection == ArraySizeOptions.UseFirstMarshaledType) { object[] objArray1 = new object[] { destinationVariable, this._marshaledTypes[0].VariableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0}{1} = {2};", objArray1); } object[] args = new object[] { destinationVariable, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", args); }
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { string str = InteropMethodBodyWriter.Naming.ForWindowsRuntimeDelegateComCallableWrapperInterface(base._interfaceType); string str2 = InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(base._interfaceType); object[] args = new object[] { str, str2, InteropMethodBodyWriter.Naming.Null }; writer.WriteLine("{0}* {1} = {2};", args); object[] objArray2 = new object[] { InteropMethodBodyWriter.Naming.ForInteropHResultVariable(), InteropMethodBodyWriter.Naming.ThisParameterName, InteropMethodBodyWriter.Naming.ForIl2CppComObjectIdentityField(), str, str2 }; writer.WriteLine("il2cpp_hresult_t {0} = {1}->{2}->QueryInterface({3}::IID, reinterpret_cast<void**>(&{4}));", objArray2); writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable())); writer.WriteLine(); }
private void ActivateThroughCustomActivationFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters) { string str = InteropMethodBodyWriter.Naming.ForMethod(this.factoryMethod); string str2 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldName(Extensions.ExtractDefaultInterface(this.constructedObjectType.Resolve())); WriteDeclareActivationFactory(writer, this.factoryMethod.DeclaringType, staticFieldsAccess); writer.WriteLine(string.Format("il2cpp_hresult_t hr = activationFactory->{0}({1}&{2}->{3});", new object[] { str, parameters, this.thisParameter, str2 })); writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);"); writer.WriteLine(); writer.WriteLine(string.Format("hr = {0}->{1}->QueryInterface(Il2CppIUnknown::IID, reinterpret_cast<void**>(&{2}->{3}));", new object[] { this.thisParameter, str2, 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)); }
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)); } }
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); } }
public sealed override void WriteMarshalCleanupVariable(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess, string managedVariableName) { if (!this._isSealed) { object[] args = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("if ({0} != {1})", args); using (new BlockWriter(writer, false)) { object[] objArray2 = new object[] { variableName }; writer.WriteLine("({0})->Release();", objArray2); object[] objArray3 = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", objArray3); } } }
protected void AllocateAndStoreNativeArray(CppCodeWriter writer, string destinationVariable, string arraySize) { if (this.NeedsTrailingNullElement) { object[] args = new object[] { destinationVariable, this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName, arraySize }; writer.WriteLine("{0} = il2cpp_codegen_marshal_allocate_array<{1}>({2} + 1);", args); object[] objArray2 = new object[] { destinationVariable, arraySize, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("({0})[{1}] = {2};", objArray2); } else { object[] objArray3 = new object[] { destinationVariable, this._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName, arraySize }; writer.WriteLine("{0} = il2cpp_codegen_marshal_allocate_array<{1}>({2});", objArray3); } }
private static void WriteDeclareActivationFactory(CppCodeWriter writer, TypeReference factoryType, string staticFieldsAccess) { string str = InteropMethodBodyWriter.Naming.ForTypeNameOnly(factoryType); string str2 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldGetter(factoryType); writer.WriteLine($"{str}* activationFactory = {staticFieldsAccess}->{str2}();"); }
public override void WriteFieldDeclaration(CppCodeWriter writer, FieldReference field, string fieldNameSuffix = null) { string str = DefaultMarshalInfoWriter.Naming.ForField(field) + fieldNameSuffix; object[] args = new object[] { base._elementTypeMarshalInfoWriter.MarshaledTypes[0].DecoratedName, str, base._arraySize }; writer.WriteLine("{0} {1}[{2}];", args); }
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})"); }
protected override void WriteMarshalToNativeMethodDefinition(CppCodeWriter writer) { writer.WriteLine(base._marshalToNativeFunctionDeclaration); writer.BeginBlock(); this.WriteThrowNotSupportedException(writer); writer.EndBlock(false); }
private void WriteThrowNotSupportedException(CppCodeWriter writer) { string exception = DefaultMarshalInfoWriter.Naming.ForField(this._faultyField) + "Exception"; object[] args = new object[] { exception, this.GetMarshalingException() }; writer.WriteLine("Il2CppCodeGenException* {0} = {1};", args); writer.WriteStatement(Emit.RaiseManagedException(exception)); }
protected virtual void WriteReturnStatement(CppCodeWriter writer, string unmarshaledReturnValueVariableName, IRuntimeMetadataAccess metadataAccess) { if (this.GetMethodReturnType().ReturnType.MetadataType != MetadataType.Void) { object[] args = new object[] { unmarshaledReturnValueVariableName }; writer.WriteLine("return {0};", args); } }
public virtual void WriteFieldDeclaration(CppCodeWriter writer, FieldReference field, string fieldNameSuffix = null) { foreach (MarshaledType type in this.MarshaledTypes) { string str = Naming.ForField(field) + type.VariableName + fieldNameSuffix; object[] args = new object[] { type.DecoratedName, str }; writer.WriteLine("{0} {1};", args); } }
protected sealed override void WriteReturnStatement(CppCodeWriter writer, string unmarshaledReturnValueVariableName, IRuntimeMetadataAccess metadataAccess) { MarshaledType[] marshaledTypes = base.MarshalInfoWriterFor(this.GetMethodReturnType()).MarshaledTypes; for (int i = 0; i < (marshaledTypes.Length - 1); i++) { object[] args = new object[] { InteropMethodBodyWriter.Naming.ForComInterfaceReturnParameterName(), unmarshaledReturnValueVariableName, marshaledTypes[i].VariableName }; writer.WriteLine("*{0}{2} = {1}{2};", args); } this.WriteReturnStatementEpilogue(writer, unmarshaledReturnValueVariableName); }
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(); }
private void WriteMethodBodyImpl(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { this.WriteMethodPrologue(writer, metadataAccess); string[] localVariableNames = this.WriteMarshalInputParameters(writer, metadataAccess); string unmarshaledReturnValueVariableName = null; object[] args = new object[] { this._marshaler.GetPrettyCalleeName() }; writer.WriteLine("// {0} invocation", args); this.WriteInteropCallStatement(writer, localVariableNames, metadataAccess); writer.WriteLine(); MethodReturnType methodReturnType = this.GetMethodReturnType(); if (methodReturnType.ReturnType.MetadataType != MetadataType.Void) { unmarshaledReturnValueVariableName = this._marshaler.WriteMarshalReturnValue(writer, methodReturnType, this._parameters, metadataAccess); this._marshaler.WriteMarshalCleanupReturnValue(writer, methodReturnType, metadataAccess); } this.WriteMarshalOutputParameters(writer, localVariableNames, metadataAccess); this.WriteMethodEpilogue(writer, metadataAccess); this.WriteReturnStatement(writer, unmarshaledReturnValueVariableName, metadataAccess); }
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(); }
protected override void WriteInteropCallStatement(CppCodeWriter writer, string[] localVariableNames, IRuntimeMetadataAccess metadataAccess) { MethodReturnType methodReturnType = this.GetMethodReturnType(); if (methodReturnType.ReturnType.MetadataType != MetadataType.Void) { base.MarshalInfoWriterFor(methodReturnType).WriteNativeVariableDeclarationOfType(writer, InteropMethodBodyWriter.Naming.ForInteropReturnValue()); } writer.WriteStatement(this.GetMethodCallExpression(localVariableNames)); this.OnBeforeHResultCheck(writer); writer.WriteLine(); writer.WriteStatement(Emit.Call("il2cpp_codegen_com_raise_exception_if_failed", InteropMethodBodyWriter.Naming.ForInteropHResultVariable())); }
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)); } }
public override void WriteFieldDeclaration(CppCodeWriter writer, FieldReference field, string fieldNameSuffix = null) { if (this.IsFixedSizeString) { string str = DefaultMarshalInfoWriter.Naming.ForField(field) + fieldNameSuffix; object[] args = new object[] { this._marshaledTypeName.Replace("*", ""), str, ((FixedSysStringMarshalInfo)this._marshalInfo).Size }; writer.WriteLine("{0} {1}[{2}];", args); } else { base.WriteFieldDeclaration(writer, field, fieldNameSuffix); } }
internal static void WriteRegistrationIncludes(CppCodeWriter writer) { writer.AddInclude("il2cpp-config.h"); writer.AddInclude("class-internals.h"); writer.AddInclude("codegen/il2cpp-codegen.h"); writer.AddStdInclude("cstring"); writer.AddStdInclude("string.h"); writer.AddStdInclude("stdio.h"); writer.AddStdInclude("cmath"); writer.AddStdInclude("limits"); writer.AddStdInclude("assert.h"); writer.WriteLine(); }
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); } }
private void FreeMarshaledString(CppCodeWriter writer, string variableName) { if (!this.IsFixedSizeString) { Mono.Cecil.NativeType type = this._nativeType; if (type == Mono.Cecil.NativeType.BStr) { object[] objArray1 = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_marshal_free_bstring({0});", objArray1); } else if (type == (Mono.Cecil.NativeType.Error | Mono.Cecil.NativeType.Boolean)) { object[] objArray2 = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_marshal_free_hstring({0});", objArray2); } else { object[] objArray3 = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_marshal_free({0});", objArray3); } object[] args = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", args); } }
private void ActivateThroughCustomActivationFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters) { string str = InteropMethodBodyWriter.Naming.ForMethod(this.factoryMethod); string str2 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldName(this.constructedObjectType.Resolve().ExtractDefaultInterface()); WriteDeclareActivationFactory(writer, this.factoryMethod.DeclaringType, staticFieldsAccess); writer.WriteLine($"il2cpp_hresult_t hr = activationFactory->{str}({parameters}&{this.thisParameter}->{str2});"); writer.WriteLine("il2cpp_codegen_com_raise_exception_if_failed(hr);"); writer.WriteLine(); writer.WriteLine($"hr = {this.thisParameter}->{str2}->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});"); }
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) {
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) { 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;"); } }
public override void WriteFieldDeclaration(CppCodeWriter writer, FieldReference field, [Optional, DefaultParameterValue(null)] string fieldNameSuffix) { if (this.IsFixedSizeString) { string str = DefaultMarshalInfoWriter.Naming.ForField(field) + fieldNameSuffix; object[] args = new object[] { this._marshaledTypeName.Replace("*", ""), str, ((FixedSysStringMarshalInfo) this._marshalInfo).Size }; writer.WriteLine("{0} {1}[{2}];", args); } else { base.WriteFieldDeclaration(writer, field, fieldNameSuffix); } }
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)); } }
protected override void WriteMarshalCleanupFunction(CppCodeWriter writer) { writer.WriteLine(base._marshalCleanupFunctionDeclaration); writer.WriteLine("{"); writer.WriteLine("}"); }
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 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)); }
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); }
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(string.Format("StringMarshalInfoWriter doesn't know how to marshal {0} while maintaining reference to original managed string.", this._nativeType)); } 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) {
public override void WriteMarshalCleanupVariable(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess, [Optional, DefaultParameterValue(null)] string managedVariableName) { object[] args = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_com_destroy_variant(&({0}));", args); }
protected override void WriteMethodPrologue(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { writer.WriteLine("il2cpp_native_wrapper_vm_thread_attacher _vmThreadHelper;"); writer.WriteLine(); }
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)); } }
public override void WriteMarshalCleanupVariable(CppCodeWriter writer, string variableName, IRuntimeMetadataAccess metadataAccess, [Optional, DefaultParameterValue(null)] string managedVariableName) { object[] args = new object[] { variableName }; writer.WriteLine("il2cpp_codegen_com_destroy_safe_array({0});", args); object[] objArray2 = new object[] { variableName, DefaultMarshalInfoWriter.Naming.Null }; writer.WriteLine("{0} = {1};", objArray2); }
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)); } }
private static void WriteDeclareActivationFactory(CppCodeWriter writer, TypeReference factoryType, string staticFieldsAccess) { string str = InteropMethodBodyWriter.Naming.ForTypeNameOnly(factoryType); string str2 = InteropMethodBodyWriter.Naming.ForComTypeInterfaceFieldGetter(factoryType); writer.WriteLine(string.Format("{0}* activationFactory = {1}->{2}();", str, staticFieldsAccess, str2)); }
private void WriteActivateThroughIActivationFactory(CppCodeWriter writer, string staticFieldsAccess, string parameters) { WriteDeclareActivationFactory(writer, InteropMethodBodyWriter.TypeProvider.IActivationFactoryTypeReference, staticFieldsAccess); writer.WriteLine(string.Format("il2cpp_hresult_t hr = activationFactory->ActivateInstance({0}reinterpret_cast<Il2CppIInspectable**>(&{1}->{2}));", parameters, 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)); }