From 1211cd827e387e8349561e908b0992bb7280cf48 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pa=CC=84vels=20Nadtoc=CC=8Cajevs?=
<7645683+bruvzg@users.noreply.github.com>
Date: Mon, 21 Jul 2025 09:16:25 +0300
Subject: [PATCH] Add project setting and build option to disable
`override.cfg` and related CLI arguments.
---
SConstruct | 4 ++++
core/config/project_settings.cpp | 40 ++++++++++++++++++++++++++------
doc/classes/ProjectSettings.xml | 3 +++
main/main.cpp | 34 +++++++++++++++++++++++----
4 files changed, 70 insertions(+), 11 deletions(-)
diff --git a/SConstruct b/SConstruct
index d2a34358363..9b7c81d28d4 100644
--- a/SConstruct
+++ b/SConstruct
@@ -239,6 +239,7 @@ opts.Add(BoolVariable("disable_physics_3d", "Disable 3D physics nodes and server
opts.Add(BoolVariable("disable_navigation_2d", "Disable 2D navigation features", False))
opts.Add(BoolVariable("disable_navigation_3d", "Disable 3D navigation features", False))
opts.Add(BoolVariable("disable_xr", "Disable XR nodes and server", False))
+opts.Add(BoolVariable("disable_overrides", "Disable project settings overrides and related CLI arguments", False))
opts.Add("build_profile", "Path to a file containing a feature build profile", "")
opts.Add("custom_modules", "A list of comma-separated directory paths containing custom modules to build.", "")
opts.Add(BoolVariable("custom_modules_recursive", "Detect custom modules recursively for each specified path.", True))
@@ -1043,6 +1044,9 @@ if env["minizip"]:
if env["brotli"]:
env.Append(CPPDEFINES=["BROTLI_ENABLED"])
+if not env["disable_overrides"]:
+ env.Append(CPPDEFINES=["OVERRIDE_ENABLED"])
+
if not env["verbose"]:
methods.no_verbose(env)
diff --git a/core/config/project_settings.cpp b/core/config/project_settings.cpp
index 4d269c6a0fb..82b19bffc00 100644
--- a/core/config/project_settings.cpp
+++ b/core/config/project_settings.cpp
@@ -643,11 +643,16 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
ERR_FAIL_COND_V_MSG(!ok, ERR_CANT_OPEN, vformat("Cannot open resource pack '%s'.", p_main_pack));
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+#ifdef OVERRIDE_ENABLED
if (err == OK && !p_ignore_override) {
// Load override from location of the main pack
// Optional, we don't mind if it fails
- _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
+ bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
+ if (!disable_override) {
+ _load_settings_text(p_main_pack.get_base_dir().path_join("override.cfg"));
+ }
}
+#endif // OVERRIDE_ENABLED
return err;
}
@@ -693,12 +698,17 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
// If we opened our package, try and load our project.
if (found) {
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+#ifdef OVERRIDE_ENABLED
if (err == OK && !p_ignore_override) {
// Load overrides from the PCK and the executable location.
// Optional, we don't mind if either fails.
- _load_settings_text("res://override.cfg");
- _load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
+ bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
+ if (!disable_override) {
+ _load_settings_text("res://override.cfg");
+ _load_settings_text(exec_path.get_base_dir().path_join("override.cfg"));
+ }
}
+#endif // OVERRIDE_ENABLED
return err;
}
}
@@ -713,10 +723,15 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
if (!OS::get_singleton()->get_resource_dir().is_empty()) {
Error err = _load_settings_text_or_binary("res://project.godot", "res://project.binary");
+#ifdef OVERRIDE_ENABLED
if (err == OK && !p_ignore_override) {
// Optional, we don't mind if it fails.
- _load_settings_text("res://override.cfg");
+ bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
+ if (!disable_override) {
+ _load_settings_text("res://override.cfg");
+ }
}
+#endif // OVERRIDE_ENABLED
return err;
}
@@ -736,11 +751,16 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
err = _load_settings_text_or_binary(resource_path.path_join("project.godot"), resource_path.path_join("project.binary"));
if (err == OK && !p_ignore_override) {
// Optional, we don't mind if it fails.
- _load_settings_text(resource_path.path_join("override.cfg"));
+#ifdef OVERRIDE_ENABLED
+ bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
+ if (!disable_override) {
+ _load_settings_text(resource_path.path_join("override.cfg"));
+ }
+#endif // OVERRIDE_ENABLED
return err;
}
}
-#endif
+#endif // MACOS_ENABLED
// Nothing was found, try to find a project file in provided path (`p_path`)
// or, if requested (`p_upwards`) in parent directories.
@@ -760,7 +780,12 @@ Error ProjectSettings::_setup(const String &p_path, const String &p_main_pack, b
err = _load_settings_text_or_binary(current_dir.path_join("project.godot"), current_dir.path_join("project.binary"));
if (err == OK && !p_ignore_override) {
// Optional, we don't mind if it fails.
- _load_settings_text(current_dir.path_join("override.cfg"));
+#ifdef OVERRIDE_ENABLED
+ bool disable_override = GLOBAL_GET("application/config/disable_project_settings_override");
+ if (!disable_override) {
+ _load_settings_text(current_dir.path_join("override.cfg"));
+ }
+#endif // OVERRIDE_ENABLED
found = true;
break;
}
@@ -1569,6 +1594,7 @@ ProjectSettings::ProjectSettings() {
GLOBAL_DEF("application/config/use_custom_user_dir", false);
GLOBAL_DEF("application/config/custom_user_dir_name", "");
GLOBAL_DEF("application/config/project_settings_override", "");
+ GLOBAL_DEF("application/config/disable_project_settings_override", false);
GLOBAL_DEF("application/run/main_loop_type", "SceneTree");
GLOBAL_DEF("application/config/auto_accept_quit", true);
diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml
index 8941c071b58..d75ab682bac 100644
--- a/doc/classes/ProjectSettings.xml
+++ b/doc/classes/ProjectSettings.xml
@@ -307,6 +307,9 @@
The project's description, displayed as a tooltip in the Project Manager when hovering the project.
+
+ If [code]true[/code], disables loading of project settings overrides (file defined in [member application/config/project_settings_override] and [code]res://override.cfg[/code]) and related CLI arguments.
+
Icon used for the project, set when project loads. Exporters will also use this icon as a fallback if necessary.
diff --git a/main/main.cpp b/main/main.cpp
index 5be591b4fe8..9e1d4145496 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -556,16 +556,20 @@ void Main::print_help(const char *p_binary) {
print_help_option("--quit-after ", "Quit after the given number of iterations. Set to 0 to disable.\n");
print_help_option("-l, --language ", "Use a specific locale ( being a two-letter code).\n");
print_help_option("--path ", "Path to a project ( must contain a \"project.godot\" file).\n");
+#ifdef OVERRIDE_ENABLED
print_help_option("--scene ", "Path or UID of a scene in the project that should be started.\n");
print_help_option("-u, --upwards", "Scan folders upwards for project.godot file.\n");
print_help_option("--main-pack ", "Path to a pack (.pck) file to load.\n");
+#endif // OVERRIDE_ENABLED
#ifdef DISABLE_DEPRECATED
print_help_option("--render-thread ", "Render thread mode (\"safe\", \"separate\").\n");
#else
print_help_option("--render-thread ", "Render thread mode (\"unsafe\" [deprecated], \"safe\", \"separate\").\n");
-#endif
+#endif // DISABLE_DEPRECATED
+#ifdef OVERRIDE_ENABLED
print_help_option("--remote-fs ", "Remote filesystem ([:] address).\n");
print_help_option("--remote-fs-password ", "Password for remote filesystem.\n");
+#endif // OVERRIDE_ENABLED
print_help_option("--audio-driver ", "Audio driver [");
for (int i = 0; i < AudioDriverManager::get_driver_count(); i++) {
@@ -662,10 +666,12 @@ void Main::print_help(const char *p_binary) {
print_help_option("--editor-pseudolocalization", "Enable pseudolocalization for the editor and the project manager.\n", CLI_OPTION_AVAILABILITY_EDITOR);
#endif
+#ifdef OVERRIDE_ENABLED
print_help_title("Standalone tools");
print_help_option("-s, --script