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; } }
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; } }
internal static void Init() { if (disabled) { return; } try { MelonDebug.Msg("Initializing UIStyleValues"); UIStyleValues.Init(); MelonDebug.Msg("UIStyleValues Initialized"); uint graphicsDeviceType = SystemInfo.GetGraphicsDeviceType(); MelonDebug.Msg("Graphics Device Type: " + graphicsDeviceType); shouldCallWFLPAGT = NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new[] { "2020.2.7", "2020.3.0", "2021.1.0" }) && (graphicsDeviceType == /*DX11*/ 2 || graphicsDeviceType == /*DX12*/ 18) ? graphicsDeviceType : 0; } catch (Exception e) { MelonLogger.Error("Exception while init rendering: " + e); disabled = true; } }
private static int LoadAndRun(LemonFunc <int> functionToWaitForAsync) { FolderPath = Path.Combine(MelonUtils.UserDataDirectory, "MelonStartScreen"); if (!Directory.Exists(FolderPath)) { Directory.CreateDirectory(FolderPath); } ThemesFolderPath = Path.Combine(FolderPath, "Themes"); if (!Directory.Exists(ThemesFolderPath)) { Directory.CreateDirectory(ThemesFolderPath); } UIConfig.Load(); if (!UIConfig.General.Enabled) { return(functionToWaitForAsync()); } // We try to resolve all the signatures, which are available for Unity 2018.1.0+ // If we can't find them (signatures changed or <2018.1.0), then we run the function and return. try { if (!NativeSignatureResolver.Apply()) { return(functionToWaitForAsync()); } if (!ApplyUser32SetTimerPatch()) { return(functionToWaitForAsync()); } MelonDebug.Msg("Initializing Screen Renderer"); ScreenRenderer.Init(); MelonDebug.Msg("Screen Renderer initialized"); RegisterMessageCallbacks(); // Initial render ScreenRenderer.Render(); } catch (Exception e) { MelonLogger.Error(e); ScreenRenderer.disabled = true; return(functionToWaitForAsync()); } initialized = true; StartFunction(functionToWaitForAsync); MainLoop(); return(functionRunResult); }
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)); } }
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"); } }
internal static void Init() { if (disabled) { return; } try { MelonDebug.Msg("Initializing UIStyleValues"); UIStyleValues.Init(); MelonDebug.Msg("UIStyleValues Initialized"); if (UICustomization.VersionText.Enabled) { TextGenerationSettings settings = new TextGenerationSettings(); settings.textAnchor = TextAnchor.MiddleCenter; settings.color = UICustomization.VersionText.TextColor; settings.generationExtents = new Vector2(540, 47.5f); settings.richText = true; settings.font = UIStyleValues.TextFont; settings.pivot = new Vector2(0.5f, 0.5f); settings.fontSize = 24; settings.fontStyle = FontStyle.Bold; settings.verticalOverflow = VerticalWrapMode.Overflow; settings.scaleFactor = 1f; settings.lineSpacing = 1f; MelonDebug.Msg("TextGenerationSettings settings set"); string melonloaderText = (MelonLaunchOptions.Console.Mode == MelonLaunchOptions.Console.DisplayMode.LEMON) ? "<color=#FFCC4D>LemonLoader</color>" : "<color=#78f764>Melon</color><color=#ff3c6a>Loader</color>"; melonloaderversionTextmesh = TextMeshGenerator.Generate($"{melonloaderText} v{BuildInfo.Version} Open-Beta", settings); } if (UICustomization.ProgressBar.Enabled || UICustomization.ProgressText.Enabled) { progressBar = new ProgressBar(width: 540, height: 36); } uint graphicsDeviceType = SystemInfo.GetGraphicsDeviceType(); MelonDebug.Msg("Graphics Device Type: " + graphicsDeviceType); shouldCallWFLPAGT = NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new[] { "2020.2.7", "2020.3.0", "2021.1.0" }) && (graphicsDeviceType == /*DX11*/ 2 || graphicsDeviceType == /*DX12*/ 18) ? graphicsDeviceType : 0; } catch (Exception e) { MelonLogger.Error("Exception while init rendering: " + e); disabled = true; } }
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"); }
unsafe static UIVertexWrapper() { if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2020.2.0", "2021.1.0" })) { mode = 2; sizeOfElement = sizeof(UIVertex_2020); } else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2018.1.0" })) { mode = 1; sizeOfElement = sizeof(UIVertex_2018); } else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonLoader.InternalUtils.UnityInformationHandler.EngineVersion.ToStringWithoutType(), new string[] { "2017.2.0" })) { mode = 0; sizeOfElement = sizeof(UIVertex_2017); } }
unsafe static UIVertexWrapper() { if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonUtils.GetUnityVersion(), new string[] { "2020.2.0", "2021.1.0" })) { mode = 2; sizeOfElement = sizeof(UIVertex_2020); } else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonUtils.GetUnityVersion(), new string[] { "2018.1.0" })) { mode = 1; sizeOfElement = sizeof(UIVertex_2018); } else if (NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonUtils.GetUnityVersion(), new string[] { "2017.2.0" })) { mode = 0; sizeOfElement = sizeof(UIVertex_2017); } }
internal static void Init() { if (disabled) { return; } MelonDebug.Msg("Initializing UIStyleValues"); UIStyleValues.Init(); MelonDebug.Msg("UIStyleValues Initialized"); TextGenerationSettings settings = new TextGenerationSettings(); settings.textAnchor = TextAnchor.MiddleCenter; settings.color = new Color(1, 1, 1); settings.generationExtents = new Vector2(540, 47.5f); settings.richText = true; settings.font = UIStyleValues.standardFont; settings.pivot = new Vector2(0.5f, 0.5f); settings.fontSize = 24; settings.fontStyle = FontStyle.Bold; settings.verticalOverflow = VerticalWrapMode.Overflow; settings.scaleFactor = 1f; settings.lineSpacing = 1f; MelonDebug.Msg("TextGenerationSettings settings set"); string melonloaderText = (MelonLaunchOptions.Console.Mode == MelonLaunchOptions.Console.DisplayMode.LEMON) ? "<color=#FFCC4D>LemonLoader</color>" : "<color=#78f764>Melon</color><color=#ff3c6a>Loader</color>"; melonloaderversionTextmesh = TextMeshGenerator.Generate($"{melonloaderText} v{BuildInfo.Version} Open-Beta", settings); progressBar = new ProgressBar(width: 540, height: 36); uint graphicsDeviceType = SystemInfo.GetGraphicsDeviceType(); MelonDebug.Msg("Graphics Device Type: " + graphicsDeviceType); shouldCallWFLPAGT = NativeSignatureResolver.IsUnityVersionOverOrEqual(MelonUtils.GetUnityVersion(), new[] { "2020.2.7", "2020.3.0", "2021.1.0" }) && (graphicsDeviceType == /*DX11*/ 2 || graphicsDeviceType == /*DX12*/ 18) ? graphicsDeviceType : 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"); }
private static int LoadAndRun(LemonFunc <int> functionToWaitForAsync) { // We try to resolve all the signatures, which are available for Unity 2018.1.0+ // If we can't find them (signatures changed or <2018.1.0), then we run the function and return. try { if (!NativeSignatureResolver.Apply()) { return(functionToWaitForAsync()); } if (!ApplyUser32SetTimerPatch()) { return(functionToWaitForAsync()); } MelonDebug.Msg("Initializing Screen Renderer"); ScreenRenderer.Init(); MelonDebug.Msg("Screen Renderer initialized"); RegisterMessageCallbacks(); // Initial render ScreenRenderer.Render(); } catch (Exception e) { MelonLogger.Error(e); return(functionToWaitForAsync()); } initialized = true; StartFunction(functionToWaitForAsync); MainLoop(); return(functionRunResult); }