Example #1
0
        unsafe static Graphics()
        {
            InternalClassPointerStore <Graphics> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.CoreModule.dll", "UnityEngine", "Graphics");
            fd_Internal_DrawTexture = UnityInternals.ResolveICall <Internal_DrawTextureDelegate>("UnityEngine.Graphics::Internal_DrawTexture");

            if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2018.2.0", "2019.1.0" }))
            {
                fd_Internal_DrawMeshNow1_Injected = UnityInternals.ResolveICall <Internal_DrawMeshNow1_InjectedDelegate>("UnityEngine.Graphics::Internal_DrawMeshNow1_Injected");
            }
            else
            {
                fd_Internal_DrawMeshNow1_Injected = UnityInternals.ResolveICall <Internal_DrawMeshNow1_InjectedDelegate>("UnityEngine.Graphics::INTERNAL_CALL_Internal_DrawMeshNow1");
            }

            if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2019.3.0", "2020.1.0" }))
            {
                m_DrawTexture_Internal_struct = 3;
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2018.2.0", "2019.1.0" }))
            {
                m_DrawTexture_Internal_struct = 2;
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2017.3.0", "2018.1.0" }))
            {
                m_DrawTexture_Internal_struct = 1;
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2017.2.0" }))
            {
                m_DrawTexture_Internal_struct = 0;
            }
        }
Example #2
0
        static Mesh()
        {
            InternalClassPointerStore <Mesh> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.CoreModule.dll", "UnityEngine", "Mesh");
            UnityInternals.runtime_class_init(InternalClassPointerStore <Mesh> .NativeClassPtr);

            m_ctor = UnityInternals.GetMethod(InternalClassPointerStore <Mesh> .NativeClassPtr, ".ctor", "System.Void");

            m_set_triangles     = UnityInternals.GetMethod(InternalClassPointerStore <Mesh> .NativeClassPtr, "set_triangles", "System.Void", "System.Int32[]");
            m_RecalculateBounds = UnityInternals.GetMethod(InternalClassPointerStore <Mesh> .NativeClassPtr, "RecalculateBounds", "System.Void");

            if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2020.1.0" }))
            {
                m_SetArrayForChannelImpl_2020 = UnityInternals.ResolveICall <SetArrayForChannelImpl_2020>("UnityEngine.Mesh::SetArrayForChannelImpl");
                type_SetArrayForChannelImpl   = 2;
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2019.3.0" }))
            {
                m_SetArrayForChannelImpl_2019 = UnityInternals.ResolveICall <SetArrayForChannelImpl_2019>("UnityEngine.Mesh::SetArrayForChannelImpl");
                type_SetArrayForChannelImpl   = 1;
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2017.1.0" }))
            {
                m_SetArrayForChannelImpl_2017 = UnityInternals.ResolveICall <SetArrayForChannelImpl_2017>("UnityEngine.Mesh::SetArrayForChannelImpl");
                type_SetArrayForChannelImpl   = 0;
            }
        }
Example #3
0
        public unsafe static bool LoadImage(Texture2D tex, byte[] data, bool markNonReadable)
        {
            if (method_LoadImage_ptr == IntPtr.Zero)
            {
                method_LoadImage_ptr = UnityInternals.ResolveICall("UnityEngine.ImageConversion::LoadImage(UnityEngine.Texture2D,System.Byte[],System.Boolean)");
                if (method_LoadImage_ptr == IntPtr.Zero)
                {
                    MelonLogger.Error("Failed to resolve icall UnityEngine.ImageConversion::LoadImage(UnityEngine.Texture2D,System.Byte[],System.Boolean)");
                    return(false);
                }
                if (method_LoadImage_ptr != IntPtr.Zero)
                {
                    ImageConversion_LoadImage = (ImageConversion_LoadImage_Delegate)Marshal.GetDelegateForFunctionPointer(method_LoadImage_ptr, typeof(ImageConversion_LoadImage_Delegate));
                }
            }
            if (ImageConversion_LoadImage != null)
            {
                IntPtr dataPtr = UnityInternals.array_new(InternalClassPointerStore <byte> .NativeClassPtr, (uint)data.Length);
                for (var i = 0; i < data.Length; i++)
                {
                    IntPtr arrayStartPointer = (IntPtr)((long)dataPtr + 4 * IntPtr.Size);
                    ((byte *)arrayStartPointer.ToPointer())[i] = data[i];
                }

                return(ImageConversion_LoadImage(tex.Pointer, dataPtr, markNonReadable));
            }
            MelonLogger.Error("Failed to run UnityEngine.ImageConversion::LoadImage(UnityEngine.Texture2D,System.Byte[],System.Boolean)");
            return(false);
        }
Example #4
0
        unsafe static Material()
        {
            InternalClassPointerStore <Material> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.CoreModule.dll", "UnityEngine", "Material");
            UnityInternals.runtime_class_init(InternalClassPointerStore <Material> .NativeClassPtr);

            //m_SetPass = UnityInternals.GetMethod(InternalClassPointerStore<Material>.NativeClassPtr, "SetPass", "System.Boolean", "System.Int32");
            m_SetPass = UnityInternals.ResolveICall <d_SetPass>("UnityEngine.Material::SetPass");
        }
Example #5
0
 static GfxDevice()
 {
     if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonUtils.GetUnityVersion(), new[] { "2020.2.7", "2020.3.0", "2021.1.0" }))
     {
         // `FrameTimingManager_CUSTOM_CaptureFrameTimings()` calls `GetRealGfxDevice()` after 4 bytes.
         m_GetRealGfxDevice = (GetRealGfxDeviceDelegate)Marshal.GetDelegateForFunctionPointer(
             CppUtils.ResolveRelativeInstruction(
                 (IntPtr)((long)UnityInternals.ResolveICall("UnityEngine.FrameTimingManager::CaptureFrameTimings") + (MelonUtils.IsGame32Bit() ? 0 : 4))),
             typeof(GetRealGfxDeviceDelegate));
     }
 }
Example #6
0
 unsafe static SystemInfo()
 {
     if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2018.1.0" }))
     {
         m_GetGraphicsDeviceType = UnityInternals.ResolveICall <d_GetGraphicsDeviceType>("UnityEngine.SystemInfo::GetGraphicsDeviceType");
     }
     else
     {
         m_GetGraphicsDeviceType = UnityInternals.ResolveICall <d_GetGraphicsDeviceType>("UnityEngine.SystemInfo::get_graphicsDeviceType");
     }
 }
Example #7
0
        unsafe static UnityObject()
        {
            InternalClassPointerStore <UnityObject> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.CoreModule.dll", "UnityEngine", "Object");
            //UnityInternals.runtime_class_init(InternalClassPointerStore<UnityObject>.NativeClassPtr);

            m_DestroyImmediate  = UnityInternals.GetMethod(InternalClassPointerStore <UnityObject> .NativeClassPtr, "DestroyImmediate", "System.Void", "UnityEngine.Object");
            m_DontDestroyOnLoad = UnityInternals.GetMethod(InternalClassPointerStore <UnityObject> .NativeClassPtr, "DontDestroyOnLoad", "System.Void", "UnityEngine.Object");

            m_get_hideFlags = UnityInternals.ResolveICall <get_hideFlags_Delegate>("UnityEngine.Object::get_hideFlags(UnityEngine.Object)");
            m_set_hideFlags = UnityInternals.ResolveICall <set_hideFlags_Delegate>("UnityEngine.Object::set_hideFlags(UnityEngine.Object)");
        }
Example #8
0
        static TextGenerator()
        {
            InternalClassPointerStore <TextGenerator> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.TextRenderingModule.dll", "UnityEngine", "TextGenerator");
            UnityInternals.runtime_class_init(InternalClassPointerStore <TextGenerator> .NativeClassPtr);

            m_ctor = UnityInternals.GetMethod(InternalClassPointerStore <TextGenerator> .NativeClassPtr, ".ctor", "System.Void");

            m_Populate = UnityInternals.GetMethod(InternalClassPointerStore <TextGenerator> .NativeClassPtr, "Populate", "System.Boolean", "System.String", "UnityEngine.TextGenerationSettings");

            fd_get_vertexCount  = UnityInternals.ResolveICall <get_vertexCountDelegate>("UnityEngine.TextGenerator::get_vertexCount");
            fd_GetVerticesArray = UnityInternals.ResolveICall <GetVerticesArrayDelegate>("UnityEngine.TextGenerator::GetVerticesArray");
        }
Example #9
0
        static ImageConversion()
        {
            IntPtr ptr = UnityInternals.ResolveICall("UnityEngine.ImageConversion::LoadImage(UnityEngine.Texture2D,System.Byte[],System.Boolean)");

            if (ptr != IntPtr.Zero)
            {
                ImageConversion_LoadImage = (ImageConversion_LoadImage_Delegate)Marshal.GetDelegateForFunctionPointer(ptr, typeof(ImageConversion_LoadImage_Delegate));
            }
            else
            {
                MelonLogger.Error("Failed to resolve icall UnityEngine.ImageConversion::LoadImage(UnityEngine.Texture2D,System.Byte[],System.Boolean)");
            }
        }
Example #10
0
        static Texture()
        {
            InternalClassPointerStore <Texture> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.CoreModule.dll", "UnityEngine", "Texture");

            if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2018.1.0" }))
            {
                getDataWidth  = UnityInternals.ResolveICall <GetDataWidthDelegate>("UnityEngine.Texture::GetDataWidth");
                getDataHeight = UnityInternals.ResolveICall <GetDataHeightDelegate>("UnityEngine.Texture::GetDataHeight");
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2017.1.0" }))
            {
                getDataWidth  = UnityInternals.ResolveICall <GetDataWidthDelegate>("UnityEngine.Texture::Internal_GetWidth");
                getDataHeight = UnityInternals.ResolveICall <GetDataHeightDelegate>("UnityEngine.Texture::Internal_GetHeight");
            }
            set_filterMode_ = UnityInternals.ResolveICall <set_filterModeDelegate>("UnityEngine.Texture::set_filterMode");
        }
Example #11
0
        static Texture2D()
        {
            InternalClassPointerStore <Texture2D> .NativeClassPtr = UnityInternals.GetClass("UnityEngine.CoreModule.dll", "UnityEngine", "Texture2D");
            UnityInternals.runtime_class_init(InternalClassPointerStore <Texture2D> .NativeClassPtr);

            m_ctor = UnityInternals.GetMethod(InternalClassPointerStore <Texture2D> .NativeClassPtr, ".ctor", "System.Void", "System.Int32", "System.Int32");

            m_get_whiteTexture = UnityInternals.GetMethod(InternalClassPointerStore <Texture2D> .NativeClassPtr, "get_whiteTexture", "UnityEngine.Texture2D");

            if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2018.1.0" }))
            {
                type_SetPixelsImpl   = 1;
                m_SetPixelsImpl_2018 = UnityInternals.ResolveICall <SetPixelsImplDelegate_2018>("UnityEngine.Texture2D::SetPixelsImpl");
            }
            else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2017.1.0" }))
            {
                type_SetPixelsImpl   = 0;
                m_SetPixelsImpl_2017 = UnityInternals.ResolveICall <SetPixelsImplDelegate_2017>("UnityEngine.Texture2D::SetPixels");
            }

            m_Apply = UnityInternals.GetMethod(InternalClassPointerStore <Texture2D> .NativeClassPtr, "Apply", "System.Void");
        }
Example #12
0
 unsafe static GL()
 {
     m_get_sRGBWrite = UnityInternals.ResolveICall <d_get_sRGBWrite>("UnityEngine.GL::get_sRGBWrite");
 }
Example #13
0
 unsafe static SystemInfo()
 {
     m_GetGraphicsDeviceType = UnityInternals.ResolveICall <d_GetGraphicsDeviceType>("UnityEngine.SystemInfo::GetGraphicsDeviceType");
 }