Example #1
0
        public override string Box(string name, bool previous = false)
        {
            if (isValueElement)
            {
                return(name);
            }

            var eType = type.GetElementType();

            if (eType.Name != "String")
            {
                ClassCacheGenerater.GetClass(type.GetElementType().Resolve());
            }

            var reName = $"mono{name}";
            var cmd    = $"MonoArray* {reName} = get_mono_array({name})";

            if (previous)
            {
                CS.Writer.WritePreviousLine(cmd);
            }
            else
            {
                CS.Writer.WriteLine(cmd);
            }
            return(reName);
        }
Example #2
0
        public override string Unbox(string name, bool previous = false)
        {
            var    reName     = $"i2{name}";
            string classCache = "NULL";

            if (type.Namespace.StartsWith("UnityEngine"))
            {
                classCache = ClassCacheGenerater.GetClass(type.Resolve(), true);
                // if (type.FullName == "UnityEngine.Object" || type.FullName == "System.Object")
                //     classCache = $"get_il2cpp_class(mono_object_get_class({name}))";
            }


            var cmd = $"Il2CppObject* {reName} = get_il2cpp_object({name},{classCache})";

            if (previous)
            {
                CS.Writer.WritePreviousLine(cmd);
            }
            else
            {
                CS.Writer.WriteLine(cmd);
            }
            return(reName);
        }
Example #3
0
        public static void Gen()
        {
            using (new CS(EventWriter))
            {
                CS.Writer.WriteLine("#include \"event_binding.h\"", false);
                CS.Writer.WriteLine("#include \"class_cache_gen.h\"", false);

                CS.Writer.WriteLine($"EventMethodDesc methods[{methodSet.Count}]");

                int index = 0;
                foreach (var m in methodSet)
                {
                    CS.Writer.Start($"{CTypeResolver.Resolve(m.ReturnType,true).TypeName()} {CUtils.ImplementMethodName(m, false) + CUtils.GetParamDefine(m, true, "const MethodInfo* imethod")} ");
                    ImplementEventMethod(m, index);
                    CS.Writer.End();
                    index++;
                }

                index = 0;
                CS.Writer.Start("void init_event_gen()");
                foreach (var m in methodSet)
                {
                    CS.Writer.WriteLine($"init_event_method(&methods[{index}],{ClassCacheGenerater.GetClass(m.DeclaringType,false)},{ClassCacheGenerater.GetClass(m.DeclaringType, true)}," +
                                        $"\"{m.Name}\",{m.Parameters.Count},(Il2CppMethodPointer) {CUtils.ImplementMethodName(m, false)})");
                    index++;
                }
                CS.Writer.End();
            }

            EventWriter.EndAll();
        }
Example #4
0
        public override string Box(string name, bool previous = false)
        {
            var reName     = $"mono{name}";
            var classCache = ClassCacheGenerater.GetClass(type.Resolve());

            if (type.FullName == "UnityEngine.Object" || type.FullName == "System.Object")
            {
                classCache = $"get_mono_class(il2cpp_object_get_class({name}))";
            }

            var cmd = $"MonoObject* {reName} = get_mono_object({name},{classCache})";

            if (previous)
            {
                CS.Writer.WritePreviousLine(cmd);
            }
            else
            {
                CS.Writer.WriteLine(cmd);
            }

            return(reName);
        }