private static void ProcessMessages() { while (true) { User32.PeekMessage(out Msg msg, IntPtr.Zero, 0, 0, 0); if (msg.message == WindowMessage.QUIT) { Process.GetCurrentProcess().Kill(); return; } else if (User32.PeekMessage(out msg, IntPtr.Zero, 0, 0, 1)) // If there a message pending { if (msg.message == WindowMessage.NCLBUTTONDOWN || msg.message == (WindowMessage)0x242 /* NCPOINTERDOWN */) { if (titleBarTimer == IntPtr.Zero) { titleBarTimer = User32.SetTimer(IntPtr.Zero, IntPtr.Zero, 10, TitleBarTimerUpdateCallback); } nextSetTimerIsUnity = true; } else if (msg.message == WindowMessage.PAINT) { ScreenRenderer.Render(); } User32.TranslateMessage(ref msg); User32.DispatchMessage(ref msg); } else { return; } } }
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); }
internal static void Finish() { if (!initialized) { return; } ScreenRenderer.UpdateMainProgress("Starting game...", 1f); ScreenRenderer.Render(); // Final render, to set the progress bar to 100% }
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); }
private static void ProcessEventsAndRender(bool isMainLoop = false) { ProcessMessages(); if (titleBarTimer != IntPtr.Zero) { User32.KillTimer(IntPtr.Zero, titleBarTimer); titleBarTimer = IntPtr.Zero; } ScreenRenderer.Render(); if (isMainLoop) { Thread.Sleep(16); // ~60fps } else { if (titleBarTimer != IntPtr.Zero) { User32.KillTimer(IntPtr.Zero, titleBarTimer); titleBarTimer = IntPtr.Zero; } } }
private static void TitleBarTimerUpdateCallback(IntPtr hWnd, uint uMsg, IntPtr nIDEvent, uint dwTime) { ScreenRenderer.Render(); }