Esempio n. 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;
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 3
0
        internal static void OnApplicationLateStart_Mod(string name)
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateProgressFromMod(name);
            ProcessEventsAndRender();
        }
Esempio n. 4
0
        internal static void OnApplicationLateStart_Mods()
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateProgressState(ModLoadStep.OnApplicationLateStart_Mods);
            ProcessEventsAndRender();
        }
Esempio n. 5
0
        internal static void LoadingMods()
        {
            if (!initialized)
            {
                return;
            }

            ScreenRenderer.UpdateProgressState(ModLoadStep.LoadMods);
            ProcessEventsAndRender();
        }
Esempio n. 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%
        }
Esempio n. 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);
        }
Esempio n. 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;
                }
            }
        }
Esempio n. 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);
 }
Esempio n. 10
0
 private static void TitleBarTimerUpdateCallback(IntPtr hWnd, uint uMsg, IntPtr nIDEvent, uint dwTime)
 {
     ScreenRenderer.Render();
 }