From fc7c10a086811d680e4a0d689971b14a1371a54a Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Tue, 8 Sep 2026 08:45:09 +0200 Subject: [PATCH 1/3] Remove FILE_FLAG_NO_BUFFERING from GTA SA's IMG archive reads --- Client/game_sa/CGameSA.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Client/game_sa/CGameSA.cpp b/Client/game_sa/CGameSA.cpp index b9ef4b1fff..1be98b66c7 100644 --- a/Client/game_sa/CGameSA.cpp +++ b/Client/game_sa/CGameSA.cpp @@ -228,6 +228,10 @@ CGameSA::CGameSA() MemPut(0x05B8E55, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 MemPut(0x05B8EB0, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 + // Remove FILE_FLAG_NO_BUFFERING from GTA SA's IMG archive reads, following SilentPatch's approach. + // This allows Windows to cache file data, potentially reducing disk I/O and improving streaming performance. + MemPut(0x406BC6, 0xEB); + // Increase matrix array size MemPut(0x054F3A1, MAX_OBJECTS * 3); // Default is 900 From c8c7f72d352f36ec75e1bce21fa049e658c60d2b Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Tue, 8 Sep 2026 08:53:55 +0200 Subject: [PATCH 2/3] Add to settings --- Client/core/CClientVariables.cpp | 1 + Client/core/CSettings.cpp | 24 +++++++++++++++++++++++- Client/core/CSettings.h | 1 + Client/game_sa/CGameSA.cpp | 4 ---- Client/game_sa/gamesa_init.cpp | 6 ++++++ 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index ce823f0763..8fc102a952 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -398,6 +398,7 @@ void CClientVariables::LoadDefaults() DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function) DEFAULT("browser_enable_video_acceleration", true); // Enable hardware video decoding in CEF? DEFAULT("process_cpu_affinity", true); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games + DEFAULT("img_file_caching", true); // Let Windows cache IMG archive reads to reduce disk I/O DEFAULT("ask_before_disconnect", true); // Ask before disconnecting from a server DEFAULT("allow_steam_client", false); // Allow connecting with the local Steam client (to set GTA:SA ingame status) DEFAULT("use_mouse_sensitivity_for_aiming", diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index d956181d5c..19b361fb1c 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -1906,6 +1906,15 @@ void CSettings::CreateGUI() m_pProcessAffinityCheckbox->AutoSize(nullptr, 20.0f); vecTemp.fY += fLineHeight; + // Allow disabling cached IMG reads for users experiencing streaming issues. + m_pIMGFileCachingCheckbox = + reinterpret_cast(pManager->CreateCheckBox(pTabAdvanced, _("Cache game files in memory (requires restart)"), true)); + m_pIMGFileCachingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY)); + m_pIMGFileCachingCheckbox->AutoSize(nullptr, 20.0f); + m_pIMGFileCachingCheckbox->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this)); + m_pIMGFileCachingCheckbox->SetMouseLeaveHandler(GUI_CALLBACK(&CSettings::OnHideAdvancedSettingDescription, this)); + vecTemp.fY += fLineHeight; + // Auto updater section label m_pAdvancedUpdaterLabel = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, _("Auto updater"))); m_pAdvancedUpdaterLabel->SetPosition(CVector2D(vecTemp.fX - 10.0f, vecTemp.fY)); @@ -4162,6 +4171,9 @@ void CSettings::LoadData() CVARS_GET("photosaving", bVar); m_pPhotoSavingCheckbox->SetSelected(bVar); + CVARS_GET("img_file_caching", bVar); + m_pIMGFileCachingCheckbox->SetSelected(bVar); + // Process CPU Affinity CVARS_GET("process_cpu_affinity", bVar); m_pProcessAffinityCheckbox->SetSelected(bVar); @@ -4606,6 +4618,11 @@ void CSettings::SaveData() CVARS_SET("photosaving", photoSaving); CScreenShot::SetPhotoSavingInsideDocuments(photoSaving); + // Archive handles retain their opening flags, so save the preference and request a restart. + const bool bIMGFileCaching = m_pIMGFileCachingCheckbox->GetSelected(); + const bool bIMGFileCachingChanged = bIMGFileCaching != CVARS_GET_VALUE("img_file_caching"); + CVARS_SET("img_file_caching", bIMGFileCaching); + // Process CPU Affinity bool affinity = m_pProcessAffinityCheckbox->GetSelected(); CVARS_SET("process_cpu_affinity", affinity); @@ -4794,7 +4811,7 @@ void CSettings::SaveData() // Ask to restart? if (bIsVideoModeChanged || bIsAntiAliasingChanged || bIsCustomizedSAFilesChanged || processsDPIAwareChanged || bBrowserGPUSettingChanged || - bBrowserVideoAccelSettingChanged) + bBrowserVideoAccelSettingChanged || bIMGFileCachingChanged) ShowRestartQuestion(); else if (CModManager::GetSingleton().IsLoaded() && bBrowserSettingChanged) ShowDisconnectQuestion(); @@ -6122,6 +6139,11 @@ bool CSettings::OnShowAdvancedSettingDescription(CGUIElement* pElement) strText = std::string(_("Auto updater:")) + " " + std::string(_("Select default to automatically install important updates.")); else if (pCheckBox && pCheckBox == m_pProcessAffinityCheckbox) strText = std::string(_("CPU affinity:")) + " " + std::string(_("Only change if you're having stability issues.")); + else if (pCheckBox && pCheckBox == m_pIMGFileCachingCheckbox) + strText = + _("Lets Windows cache IMG game archives in RAM by removing FILE_FLAG_NO_BUFFERING. Enabled by default to reduce disk reads and potentially " + "reduce loading stutter on SSDs and HDDs. Older HDDs do not automatically benefit from disabling it. Try turning it off if performance worsens. " + "Requires restarting MTA."); if (strText != "") m_pAdvancedSettingDescriptionLabel->SetText(strText.c_str()); diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index 864feadb72..cbe6ce9778 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -240,6 +240,7 @@ class CSettings CGUICheckBox* m_pPhotoSavingCheckbox; CGUICheckBox* m_pCheckBoxAskBeforeDisconnect; CGUICheckBox* m_pProcessAffinityCheckbox; + CGUICheckBox* m_pIMGFileCachingCheckbox; CGUILabel* m_pUpdateBuildTypeLabel; CGUIComboBox* m_pUpdateBuildTypeCombo; CGUILabel* m_pUpdateAutoInstallLabel; diff --git a/Client/game_sa/CGameSA.cpp b/Client/game_sa/CGameSA.cpp index 1be98b66c7..b9ef4b1fff 100644 --- a/Client/game_sa/CGameSA.cpp +++ b/Client/game_sa/CGameSA.cpp @@ -228,10 +228,6 @@ CGameSA::CGameSA() MemPut(0x05B8E55, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 MemPut(0x05B8EB0, MAX_RWOBJECT_INSTANCES * 12); // Default is 1000 * 12 - // Remove FILE_FLAG_NO_BUFFERING from GTA SA's IMG archive reads, following SilentPatch's approach. - // This allows Windows to cache file data, potentially reducing disk I/O and improving streaming performance. - MemPut(0x406BC6, 0xEB); - // Increase matrix array size MemPut(0x054F3A1, MAX_OBJECTS * 3); // Default is 900 diff --git a/Client/game_sa/gamesa_init.cpp b/Client/game_sa/gamesa_init.cpp index f071433a34..2a08d20b01 100644 --- a/Client/game_sa/gamesa_init.cpp +++ b/Client/game_sa/gamesa_init.cpp @@ -36,6 +36,12 @@ MTAEXPORT CGame* GetGameInterface(CCoreInterface* pCore) pGame = new CGameSA; g_pCore = pCore; + // Remove FILE_FLAG_NO_BUFFERING to let Windows cache IMG reads and reduce disk I/O. + // Apply this before CdStreamInit opens archives; existing handles require a restart to change their flags. + bool bIMGFileCaching = true; + pCore->GetCVars()->Get("img_file_caching", bIMGFileCaching); + MemPut(0x406BC6, bIMGFileCaching ? 0xEB : 0x77); + return (CGame*)pGame; } From 682e51d84b823f869629837a3ab29f233681da47 Mon Sep 17 00:00:00 2001 From: Xenius97 Date: Tue, 8 Sep 2026 09:05:14 +0200 Subject: [PATCH 3/3] finalize --- Client/core/CClientVariables.cpp | 2 +- Client/core/CSettings.cpp | 19 +++++++++---------- Client/game_sa/gamesa_init.cpp | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index 8fc102a952..00ac9ab942 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -398,7 +398,7 @@ void CClientVariables::LoadDefaults() DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function) DEFAULT("browser_enable_video_acceleration", true); // Enable hardware video decoding in CEF? DEFAULT("process_cpu_affinity", true); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games - DEFAULT("img_file_caching", true); // Let Windows cache IMG archive reads to reduce disk I/O + DEFAULT("img_file_caching", false); // Preserve GTA's original IMG read behavior unless caching is explicitly enabled DEFAULT("ask_before_disconnect", true); // Ask before disconnecting from a server DEFAULT("allow_steam_client", false); // Allow connecting with the local Steam client (to set GTA:SA ingame status) DEFAULT("use_mouse_sensitivity_for_aiming", diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index 19b361fb1c..9fe1826e10 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -1720,7 +1720,7 @@ void CSettings::CreateGUI() vecTemp = CVector2D(12.f, 12.f); float fComboWidth = 170.f; float fHeaderHeight = 20; - float fLineHeight = 27; + float fLineHeight = 25; // Misc section label m_pAdvancedMiscLabel = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, _("Misc"))); @@ -1906,9 +1906,9 @@ void CSettings::CreateGUI() m_pProcessAffinityCheckbox->AutoSize(nullptr, 20.0f); vecTemp.fY += fLineHeight; - // Allow disabling cached IMG reads for users experiencing streaming issues. + // Let users opt into Windows caching while preserving GTA's original IMG reads by default. m_pIMGFileCachingCheckbox = - reinterpret_cast(pManager->CreateCheckBox(pTabAdvanced, _("Cache game files in memory (requires restart)"), true)); + reinterpret_cast(pManager->CreateCheckBox(pTabAdvanced, _("Enable Windows file caching for IMG archives"), false)); m_pIMGFileCachingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY)); m_pIMGFileCachingCheckbox->AutoSize(nullptr, 20.0f); m_pIMGFileCachingCheckbox->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this)); @@ -1966,11 +1966,11 @@ void CSettings::CreateGUI() vecTemp.fX -= fComboWidth + 15; // Description label - vecTemp.fY += 15.0f; + vecTemp.fY += 2.0f; m_pAdvancedSettingDescriptionLabel = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, "")); - m_pAdvancedSettingDescriptionLabel->SetPosition(CVector2D(vecTemp.fX + 10.f, vecTemp.fY)); - m_pAdvancedSettingDescriptionLabel->SetFont("default-bold-small"); - m_pAdvancedSettingDescriptionLabel->SetSize(CVector2D(500.0f, 95.0f)); + m_pAdvancedSettingDescriptionLabel->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY)); + m_pAdvancedSettingDescriptionLabel->SetFont("default"); + m_pAdvancedSettingDescriptionLabel->SetSize(CVector2D(std::max(1.0f, tabPanelSize.fX - 2.0f * vecTemp.fX), 95.0f)); m_pAdvancedSettingDescriptionLabel->SetHorizontalAlign(CGUI_ALIGN_HORIZONTALCENTER_WORDWRAP); // Set up the events @@ -6141,9 +6141,8 @@ bool CSettings::OnShowAdvancedSettingDescription(CGUIElement* pElement) strText = std::string(_("CPU affinity:")) + " " + std::string(_("Only change if you're having stability issues.")); else if (pCheckBox && pCheckBox == m_pIMGFileCachingCheckbox) strText = - _("Lets Windows cache IMG game archives in RAM by removing FILE_FLAG_NO_BUFFERING. Enabled by default to reduce disk reads and potentially " - "reduce loading stutter on SSDs and HDDs. Older HDDs do not automatically benefit from disabling it. Try turning it off if performance worsens. " - "Requires restarting MTA."); + _("Off by default to preserve GTA's original behavior. When enabled, removes FILE_FLAG_NO_BUFFERING so Windows can cache IMG game archives in RAM. " + "This may reduce disk reads and loading stutter on SSDs and HDDs. Try turning it off if performance worsens. Requires restarting MTA."); if (strText != "") m_pAdvancedSettingDescriptionLabel->SetText(strText.c_str()); diff --git a/Client/game_sa/gamesa_init.cpp b/Client/game_sa/gamesa_init.cpp index 2a08d20b01..366cc95f46 100644 --- a/Client/game_sa/gamesa_init.cpp +++ b/Client/game_sa/gamesa_init.cpp @@ -38,7 +38,7 @@ MTAEXPORT CGame* GetGameInterface(CCoreInterface* pCore) // Remove FILE_FLAG_NO_BUFFERING to let Windows cache IMG reads and reduce disk I/O. // Apply this before CdStreamInit opens archives; existing handles require a restart to change their flags. - bool bIMGFileCaching = true; + bool bIMGFileCaching = false; pCore->GetCVars()->Get("img_file_caching", bIMGFileCaching); MemPut(0x406BC6, bIMGFileCaching ? 0xEB : 0x77);