From d55aae538294b16f3682d7ba2d3027aebbff9a08 Mon Sep 17 00:00:00 2001 From: AndreasLauvhjell Date: Wed, 28 Oct 2026 23:28:56 +0100 Subject: [PATCH 1/3] fix: restore the retail startup resolution change for the menu viewport VideoOptions::initialize ends with the scheme detection (result discarded) and applyQualityPreset(1), which selects "800x600" and "Off" (RendDX9 0x10010850 tail, 0x1000F390). VideoOptions::apply then calls the resolution change at 0x10010365 and 0x100103AE, which applies the GSWindowSizeX/Y override and posts REChangeResolution, so the SwiffHost viewport follows +szx/+szy before the login menu is built. Both pieces were skipped as [CHOSEN, not recovered] (the startup preset and the rc-login-reset-hold). Tested with a 1600x1200 window: the login and main menus fill it, and the mode change at login and on Apply survives the device reset. Co-Authored-By: Claude Opus 5.5 (1M context) --- Code/BF2/RendDX9/VideoOptions.cpp | 34 +++++++++++-------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/Code/BF2/RendDX9/VideoOptions.cpp b/Code/BF2/RendDX9/VideoOptions.cpp index 149fec8cf..7052fc096 100644 --- a/Code/BF2/RendDX9/VideoOptions.cpp +++ b/Code/BF2/RendDX9/VideoOptions.cpp @@ -148,20 +148,6 @@ int __fastcall videoOptions_getQuality(void* self, void*, int index) namespace { -// [TEMP] [CHOSEN, not recovered] Resolution changes remain a logged skip during login. -// Reports hits 1..4 and powers of two. [RETIRE-WHEN: rc-login-reset-hold] -// Restore both calls after a live device reset verifies all default-pool resources are released. -inline void noteResChangeHeld(int resIndex, int aaIndex) -{ - static unsigned int hits = 0; - ++hits; - if (hits > 4u && (hits & (hits - 1u)) != 0u) - return; - ::renddx9abi::logf("VideoOptions::apply: resolution/AA changed (res#%d, aa#%d); the resolution " - "change sub_1000F8D0 is HELD (RC, RW-251) - the device keeps its current mode; " - "the change is marked applied (hit #%u)", resIndex, aaIndex, hits); -} - // clamp(v - 1, 0, 1), the shape the original open-codes five times in a row. inline int clampMinusOne(int v) { @@ -632,18 +618,20 @@ void __fastcall videoOptions_apply(void* self, void*) if (terrain) writeRendererByte(terrain, 0x41C, 1); - // [TEMP] [CHOSEN, not recovered] [RETIRE-WHEN: rc-login-reset-hold] - // Resolution and AA resets remain held; applied-state bookkeeping still advances. - // Restore reset calls after the login path survives device reset and resource rebinding. + // A changed resolution, then a changed antialiasing, each re-applies the selected mode. Both + // calls pass the selected resolution's record; the applied indices start at -1, so the first + // apply always changes the mode and posts the resolution event the menu viewport follows. + // The second gameLoaded test is a fresh read, as shipped. + const Mode40* const modes = reinterpret_cast(vo->modeCache.first); if (!vo->gameLoaded && vo->minusOneD4 != vo->minusOneDC) { - noteResChangeHeld(vo->minusOneDC, vo->minusOneD8); // 0x10010365 held + videoOptionsChangeResolution(vo, reinterpret_cast(vo->modeCache.first) + vo->minusOneDC); vo->minusOneD4 = vo->minusOneDC; // applied resolution = selected vo->minusOneD0 = vo->minusOneD8; // applied AA = selected } if (!vo->gameLoaded && vo->minusOneD0 != vo->minusOneD8) { - noteResChangeHeld(vo->minusOneDC, vo->minusOneD8); // 0x100103AE held + videoOptionsChangeResolution(vo, reinterpret_cast(vo->modeCache.first) + vo->minusOneDC); vo->minusOneD0 = vo->minusOneD8; // applied AA = selected } @@ -1363,9 +1351,11 @@ void videoOptionsInitialize(void* base) vo->minusOneD4 = -1; vo->minusOneD0 = -1; - // [CHOSEN, not recovered] Skip automatic detection and preset 1 at initialization. - // This avoids the startup benchmark and its 800x600/AA-off reset; profile application - // supplies requested settings later. + // The detection result is discarded; preset 1 then selects "800x600" and "Off", so the first + // apply changes the mode, applies any GSWindowSizeX/Y override and posts the resolution event + // the menu viewport is sized from. + videoOptions_slot34(vo, 0); + videoOptions_applyQualityPreset(vo, 0, 1); ::renddx9abi::logf("VideoOptions::initialize: %dx%d @%dHz skipMip=%d; quality row = all 2 " "(getQuality(0)=%d terrain, getQuality(7)=%d filter); maxQuality[7]=%d", From 68d921dc4c13f0e3b2eb636ec08355783ec8d83f Mon Sep 17 00:00:00 2001 From: AndreasLauvhjell Date: Thu, 5 Nov 2026 21:09:15 +0100 Subject: [PATCH 2/3] fix: hand the profile video settings to VideoOptions at renderer startup RendDX9 initializeD3DSubsystems, right after VideoOptions::initialize, fetches the host "VideoSettings" singleton and calls its applyToOptions (+0x28) with the embedded VideoOptions (RendDX9.dll 0x1000B2EE..0x1000B31B, no null test on the singleton). This pushes the pending record loaded by LocalProfileManager::init (the Default profile's Video.con) into the options, so Renderer::initialize's first apply switches to the profile resolution, antialiasing and qualities before the first frame. The rebuild had this as a frontier, so the first apply used preset 1 (800x600) and the login menu showed 4:3 with black bars until login. An apitrace D3D9 capture of retail BF2.exe shows CreateDevice 800x600@85 followed by a single Reset to 3840x2160@165 (8x MSAA) before the first Present. Tested with the x86 client fullscreen without +szx/+szy: the first apply now resets to 3840x2160@165 and the login menu opens in 16:9. Co-Authored-By: Claude Opus 5.5 --- Code/BF2/RendDX9/RendDX9Init.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Code/BF2/RendDX9/RendDX9Init.cpp b/Code/BF2/RendDX9/RendDX9Init.cpp index e0414ad23..c7db67a63 100644 --- a/Code/BF2/RendDX9/RendDX9Init.cpp +++ b/Code/BF2/RendDX9/RendDX9Init.cpp @@ -11,6 +11,7 @@ #include "../RendMisc/IRenderView.h" // the transparency-AA probe's getViewport #if BF2_PLUGIN_ABI_NATIVE #include "../Core/SettingsRepostitory.h" +#include "../Game/VideoSettings.h" // IVideoSettings::applyToOptions, the startup handoff #endif #define WIN32_LEAN_AND_MEAN @@ -1238,7 +1239,23 @@ bool initializeD3DSubsystems(void* renderer) // constructor. videoOptionsInitialize(renderer); - // [FRONTIER] VideoSettings still lacks the VideoOptions handoff. + // The host's VideoSettings pushes its pending record (the profile's Video.con, already loaded + // by LocalProfileManager::init) into the fresh options: qualities, resolution, antialiasing and + // view distance. Renderer::initialize's first apply then switches to that mode. The singleton + // is not null-tested, as shipped. + { + IBase* const videoSettings = + classManager->getSingleton(renddx9abi::HostString("VideoSettings")); +#if BF2_PLUGIN_ABI_NATIVE + static_cast(videoSettings)->applyToOptions(b->embeddedVideoOptions()); +#else + // IVideoSettings slot +0x28, applyToOptions(IVideoOptions*). + typedef void (__thiscall* ApplyToOptionsFn)(void*, void*); + reinterpret_cast((*reinterpret_cast(videoSettings))[0x28 / 4])( + videoSettings, b->embeddedVideoOptions()); +#endif + } + // Construct StateManager before EffectManager so subsequent draws can publish state. if (!createStateManager(b->device)) return false; From 9ac6db987d081e3018cb5b141b99503988a364d2 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 9 Nov 2026 18:40:39 +0000 Subject: [PATCH 3/3] refactor: drop the raw vtable call from the VideoSettings startup handoff The non-native ABI branch called IVideoSettings::applyToOptions through a raw vtable slot (+0x28). RendDX9 is only built with BF2_PLUGIN_ABI_NATIVE=1 (docs/architecture.md), so that branch was never compiled. Replace it with an #error so a non-native build stops instead of silently skipping the handoff, and drop an unused local in VideoOptions::apply. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FQRbxcYSxJhoW8FtyQyDrv --- Code/BF2/RendDX9/RendDX9Init.cpp | 5 +---- Code/BF2/RendDX9/VideoOptions.cpp | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Code/BF2/RendDX9/RendDX9Init.cpp b/Code/BF2/RendDX9/RendDX9Init.cpp index c7db67a63..ff8bba652 100644 --- a/Code/BF2/RendDX9/RendDX9Init.cpp +++ b/Code/BF2/RendDX9/RendDX9Init.cpp @@ -1249,10 +1249,7 @@ bool initializeD3DSubsystems(void* renderer) #if BF2_PLUGIN_ABI_NATIVE static_cast(videoSettings)->applyToOptions(b->embeddedVideoOptions()); #else - // IVideoSettings slot +0x28, applyToOptions(IVideoOptions*). - typedef void (__thiscall* ApplyToOptionsFn)(void*, void*); - reinterpret_cast((*reinterpret_cast(videoSettings))[0x28 / 4])( - videoSettings, b->embeddedVideoOptions()); +#error "The VideoSettings handoff requires BF2_PLUGIN_ABI_NATIVE=1 (see docs/architecture.md)" #endif } diff --git a/Code/BF2/RendDX9/VideoOptions.cpp b/Code/BF2/RendDX9/VideoOptions.cpp index 7052fc096..f0a303b4d 100644 --- a/Code/BF2/RendDX9/VideoOptions.cpp +++ b/Code/BF2/RendDX9/VideoOptions.cpp @@ -622,7 +622,6 @@ void __fastcall videoOptions_apply(void* self, void*) // calls pass the selected resolution's record; the applied indices start at -1, so the first // apply always changes the mode and posts the resolution event the menu viewport follows. // The second gameLoaded test is a fresh read, as shipped. - const Mode40* const modes = reinterpret_cast(vo->modeCache.first); if (!vo->gameLoaded && vo->minusOneD4 != vo->minusOneDC) { videoOptionsChangeResolution(vo, reinterpret_cast(vo->modeCache.first) + vo->minusOneDC);