private bool ValidateMainMethod(CppCodeWriter writer) { if (_entryPoint == null) { string str = string.Format("Entry point not found in assembly '{0}'.", _executable.FullName); object[] arguments = new object[] { str }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", arguments)); return false; } if (_entryPoint.HasThis) { string str2 = "Entry point must be static."; object[] objArray2 = new object[] { str2 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray2)); return false; } TypeReference returnType = _entryPoint.ReturnType; if (((returnType.MetadataType != MetadataType.Void) && (returnType.MetadataType != MetadataType.Int32)) && (returnType.MetadataType != MetadataType.UInt32)) { string str3 = "Entry point must have a return type of void, integer, or unsigned integer."; object[] objArray3 = new object[] { str3 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray3)); return false; } Collection<ParameterDefinition> parameters = _entryPoint.Parameters; bool flag2 = (parameters.Count < 2) && !_entryPoint.HasGenericParameters; if (flag2 && (parameters.Count == 1)) { ParameterDefinition definition = parameters[0]; ArrayType parameterType = definition.ParameterType as ArrayType; if ((parameterType == null) || !parameterType.IsVector) { flag2 = false; } else if (parameterType.ElementType.MetadataType != MetadataType.String) { flag2 = false; } } if (!flag2) { string str4 = string.Format("Entry point method for type '{0}' has invalid signature.", _entryPoint.DeclaringType.FullName); object[] objArray4 = new object[] { str4 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray4)); return false; } if (_entryPoint.DeclaringType.HasGenericParameters) { string str5 = string.Format("Entry point method is defined on a generic type '{0}'.", _entryPoint.DeclaringType.FullName); object[] objArray5 = new object[] { str5 }; writer.WriteStatement(Emit.RaiseManagedException("il2cpp_codegen_get_missing_method_exception(\"{0}\")", objArray5)); return false; } return true; }
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())); }
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())); }
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); } }
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 OnBeforeHResultCheck(CppCodeWriter writer) { if (this.UseQueryInterfaceToObtainInterfacePointer) { writer.WriteStatement(InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType) + "->Release()"); } }
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); } }
protected virtual void OnBeforeHResultCheck(CppCodeWriter writer) { if (this.UseQueryInterfaceToObtainInterfacePointer) { writer.WriteStatement(InteropMethodBodyWriter.Naming.ForInteropInterfaceVariable(this._interfaceType) + "->Release()"); } }
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(); }
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 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) {
public void WriteMethodBody(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { DefaultMarshalInfoWriter writer2 = this.FirstOrDefaultUnmarshalableMarshalInfoWriter(); if (writer2 != null) { writer.WriteStatement(Emit.RaiseManagedException(writer2.GetMarshalingException())); } else { foreach (MarshaledParameter parameter in this._parameters) { this.MarshalInfoWriterFor(parameter).WriteIncludesForMarshaling(writer); } this.MarshalInfoWriterFor(this.GetMethodReturnType()).WriteIncludesForMarshaling(writer); this.WriteMethodBodyImpl(writer, 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 ? 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 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) { 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;"); } }
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 void WriteMethodBody(CppCodeWriter writer, IRuntimeMetadataAccess metadataAccess) { DefaultMarshalInfoWriter writer2 = this.FirstOrDefaultUnmarshalableMarshalInfoWriter(); if (writer2 != null) { writer.WriteStatement(Emit.RaiseManagedException(writer2.GetMarshalingException())); } else { foreach (MarshaledParameter parameter in this._parameters) { this.MarshalInfoWriterFor(parameter).WriteIncludesForMarshaling(writer); } this.MarshalInfoWriterFor(this.GetMethodReturnType()).WriteIncludesForMarshaling(writer); this.WriteMethodBodyImpl(writer, metadataAccess); } }
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; } } } }