using ADOFAIRenderer.Localization; using ADOFAIRenderer.UI; using UnityEngine; namespace ADOFAIRenderer.Core; /// /// MonoBehaviour that runs before every other script's Update (execution order int.MinValue; scripts run from the /// lowest order to the highest). Lives on a DontDestroyOnLoad object created by RenderMod. /// It performs the start-up checks (FFmpeg libraries present, NVIDIA driver version) and then advances the render /// frame counter through RenderManager.OnPreUpdate once per Unity frame, so every other script of that frame sees /// the same render time. /// Reference: https://docs.unity3d.com/ScriptReference/DefaultExecutionOrder.html /// [DefaultExecutionOrder(int.MinValue)] internal class FirstUpdateHook : MonoBehaviour { /// True once the FFmpeg libraries were found in UserLibs (after the download UI, if it was needed). private bool _checkedFFmpeg; /// True once the NVIDIA driver version check ran (it runs once per game session). private bool _checkedNvidiaDriver; /// /// Main thread, every frame. The checks are done in order and each one blocks the following steps while its dialog /// is open: the frame counter is not advanced until both checks are done. /// private void Update() { // 1. FFmpeg libraries: while the download UI is open, wait. When the libraries are missing, open the download UI. if (!_checkedFFmpeg) { if (FFmpegDownloadUI.Instance) return; if (!FFmpegDownloadUI.CheckFFmpegExists()) { FFmpegDownloadUI.ShowDownloadUI(); return; } _checkedFFmpeg = true; } // 2. NVIDIA driver version: waits until no other warning dialog is open, then runs once. if (!_checkedNvidiaDriver) { if (CommonWarningDialogUI.Instance) return; _checkedNvidiaDriver = true; CheckNvidiaDriverWarning(); } // 3. Render frame counter (only counts while a render is in the OnScene stage or later). if (RenderManager.Instance) { RenderManager.Instance.OnPreUpdate(); } } /// /// Shows a warning dialog when the active GPU is an NVIDIA GPU with a driver version below 610.00. /// No dialog is shown when the GPU is not NVIDIA or the version cannot be determined (GPUUtil returns null). /// Buttons: open the NVIDIA driver download page and quit the game, disable the render feature for this session /// (RenderMod.IsFeatureDisabled), or continue. /// private void CheckNvidiaDriverWarning() { var driverVer = Util.GPUUtil.GetNvidiaDriverVersion(); if (driverVer is null or >= 610.00f) return; var currentVersion = driverVer.Value.ToString("F2"); CommonWarningDialogUI.ShowDialog( LocalizationManager.Get("ui.driver_warning.title"), LocalizationManager.Get("ui.driver_warning.body", currentVersion), new DialogButton(LocalizationManager.Get("ui.driver_warning.btn_update"), () => { Application.OpenURL("https://www.nvidia.com/Download/index.aspx"); Application.Quit(); }, new Color(0.0f, 0.8f, 1.0f, 1.0f)), new DialogButton(LocalizationManager.Get("ui.driver_warning.btn_disable"), () => { RenderMod.IsFeatureDisabled = true; }), new DialogButton(LocalizationManager.Get("ui.driver_warning.btn_continue"), () => { // ignored }) ); } }