Пример #1
0
        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;
                }
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        internal static void OnApplicationLateStart_Mod(string name)
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateProgressFromMod(name);
            ProcessEventsAndRender();
        }
Пример #4
0
        internal static void OnApplicationLateStart_Mods()
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateProgressState(ModLoadStep.OnApplicationLateStart_Mods);
            ProcessEventsAndRender();
        }
Пример #5
0
        internal static void LoadingMods()
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateProgressState(ModLoadStep.LoadMods);
            ProcessEventsAndRender();
        }
Пример #6
0
        internal static void Finish()
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateMainProgress("Starting game...", 1f);
            ScreenRenderer.Render(); // Final render, to set the progress bar to 100%
        }
Пример #7
0
        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);
        }
Пример #8
0
        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;
                }
            }
        }
Пример #9
0
 private static void RegisterMessageCallbacks()
 {
     MelonLogger.MsgCallbackHandler += (namesection_color, txt_color, namesection, txt) => ScreenRenderer.UpdateProgressFromLog(txt);
     MelonDebug.MsgCallbackHandler  += (txt_color, txt) => ScreenRenderer.UpdateProgressFromLog(txt);
 }
Пример #10
0
 private static void TitleBarTimerUpdateCallback(IntPtr hWnd, uint uMsg, IntPtr nIDEvent, uint dwTime)
 {
     ScreenRenderer.Render();
 }