From 69839df1eb2a594b81bceb8cfac58ccbba286628 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Tue, 15 Mar 2022 01:46:58 -0500 Subject: [PATCH] VideoCommon: support dynamically updating game mods at runtime --- Source/Core/VideoCommon/RenderBase.cpp | 31 ++++++++++++++++++++ Source/Core/VideoCommon/TextureCacheBase.cpp | 9 +++++- Source/Core/VideoCommon/TextureCacheBase.h | 1 + Source/Core/VideoCommon/VideoConfig.h | 3 ++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index b13f74542c..412461d409 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -136,6 +136,22 @@ bool Renderer::Initialize() return false; } + if (g_ActiveConfig.bGraphicMods) + { + // If a config change occurred in a previous session, + // remember the old change count value. By setting + // our current change count to the old value, we + // avoid loading the stale data when we + // check for config changes. + const u32 old_game_mod_changes = g_ActiveConfig.graphics_mod_config ? + g_ActiveConfig.graphics_mod_config->GetChangeCount() : + 0; + g_ActiveConfig.graphics_mod_config = GraphicsModGroupConfig(SConfig::GetInstance().GetGameID()); + g_ActiveConfig.graphics_mod_config->Load(); + g_ActiveConfig.graphics_mod_config->SetChangeCount(old_game_mod_changes); + m_graphics_mod_manager.Load(*g_ActiveConfig.graphics_mod_config); + } + return true; } @@ -466,12 +482,27 @@ void Renderer::CheckForConfigChanges() const bool old_force_filtering = g_ActiveConfig.bForceFiltering; const bool old_vsync = g_ActiveConfig.bVSyncActive; const bool old_bbox = g_ActiveConfig.bBBoxEnable; + const u32 old_game_mod_changes = + g_ActiveConfig.graphics_mod_config ? g_ActiveConfig.graphics_mod_config->GetChangeCount() : 0; + const bool old_graphics_mods_enabled = g_ActiveConfig.bGraphicMods; UpdateActiveConfig(); FreeLook::UpdateActiveConfig(); g_freelook_camera.SetControlType(FreeLook::GetActiveConfig().camera_config.control_type); + if (g_ActiveConfig.bGraphicMods && !old_graphics_mods_enabled) + { + g_ActiveConfig.graphics_mod_config = GraphicsModGroupConfig(SConfig::GetInstance().GetGameID()); + g_ActiveConfig.graphics_mod_config->Load(); + } + + if (g_ActiveConfig.graphics_mod_config && + (old_game_mod_changes != g_ActiveConfig.graphics_mod_config->GetChangeCount())) + { + m_graphics_mod_manager.Load(*g_ActiveConfig.graphics_mod_config); + } + // Update texture cache settings with any changed options. g_texture_cache->OnConfigChanged(g_ActiveConfig); diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 3bd6e2ae52..9bbabb0252 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -154,6 +154,9 @@ void TextureCacheBase::OnConfigChanged(const VideoConfig& config) HiresTexture::Update(); } + const u32 change_count = + config.graphics_mod_config ? config.graphics_mod_config->GetChangeCount() : 0; + // TODO: Invalidating texcache is really stupid in some of these cases if (config.iSafeTextureCache_ColorSamples != backup_config.color_samples || config.bTexFmtOverlayEnable != backup_config.texfmt_overlay || @@ -161,7 +164,9 @@ void TextureCacheBase::OnConfigChanged(const VideoConfig& config) config.bHiresTextures != backup_config.hires_textures || config.bEnableGPUTextureDecoding != backup_config.gpu_texture_decoding || config.bDisableCopyToVRAM != backup_config.disable_vram_copies || - config.bArbitraryMipmapDetection != backup_config.arbitrary_mipmap_detection) + config.bArbitraryMipmapDetection != backup_config.arbitrary_mipmap_detection || + config.bGraphicMods != backup_config.graphics_mods || + change_count != backup_config.graphics_mod_change_count) { Invalidate(); TexDecoder_SetTexFmtOverlayOptions(config.bTexFmtOverlayEnable, config.bTexFmtOverlayCenter); @@ -257,6 +262,8 @@ void TextureCacheBase::SetBackupConfig(const VideoConfig& config) backup_config.disable_vram_copies = config.bDisableCopyToVRAM; backup_config.arbitrary_mipmap_detection = config.bArbitraryMipmapDetection; backup_config.graphics_mods = config.bGraphicMods; + backup_config.graphics_mod_change_count = + config.graphics_mod_config ? config.graphics_mod_config->GetChangeCount() : 0; } TextureCacheBase::TCacheEntry* diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 61cc612eed..287f3b840f 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -378,6 +378,7 @@ private: bool disable_vram_copies; bool arbitrary_mipmap_detection; bool graphics_mods; + u32 graphics_mod_change_count; }; BackupConfig backup_config = {}; diff --git a/Source/Core/VideoCommon/VideoConfig.h b/Source/Core/VideoCommon/VideoConfig.h index 7be25a6d88..6ce7bed379 100644 --- a/Source/Core/VideoCommon/VideoConfig.h +++ b/Source/Core/VideoCommon/VideoConfig.h @@ -9,10 +9,12 @@ #pragma once +#include #include #include #include "Common/CommonTypes.h" +#include "VideoCommon/GraphicsModSystem/Config/GraphicsModGroup.h" #include "VideoCommon/VideoCommon.h" // Log in two categories, and save three other options in the same byte @@ -112,6 +114,7 @@ struct VideoConfig final bool bEnableGPUTextureDecoding = false; int iBitrateKbps = 0; bool bGraphicMods = false; + std::optional graphics_mod_config; // Hacks bool bEFBAccessEnable = false;