Skip to content

Commit e1f4521

Browse files
committed
frontend: Change order of loading modules
Plugins are now required to be installed in %PROGRAMDATA%. Since its module path is added after the default module paths, the plugins in there will be loaded last. With the load modules once PR (#12285), the module added in the default path will be the only one loaded. We want the one in %PROGRAMDATA% to be the one loaded instead.
1 parent d3c5d2c commit e1f4521

2 files changed

Lines changed: 104 additions & 101 deletions

File tree

frontend/OBSApp.cpp

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include <sys/socket.h>
5252
#endif
5353

54+
#include <unordered_set>
55+
5456
#include "moc_OBSApp.cpp"
5557

5658
using namespace std;
@@ -79,6 +81,100 @@ extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 1;
7981
extern "C" __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
8082
#endif
8183

84+
namespace {
85+
void addExtraModulePaths()
86+
{
87+
string plugins_path, plugins_data_path;
88+
char *s;
89+
90+
s = getenv("OBS_PLUGINS_PATH");
91+
if (s)
92+
plugins_path = s;
93+
94+
s = getenv("OBS_PLUGINS_DATA_PATH");
95+
if (s)
96+
plugins_data_path = s;
97+
98+
if (!plugins_path.empty() && !plugins_data_path.empty()) {
99+
#if defined(__APPLE__)
100+
plugins_path += "/%module%.plugin/Contents/MacOS";
101+
plugins_data_path += "/%module%.plugin/Contents/Resources";
102+
obs_add_module_path(plugins_path.c_str(), plugins_data_path.c_str());
103+
#else
104+
string data_path_with_module_suffix;
105+
data_path_with_module_suffix += plugins_data_path;
106+
data_path_with_module_suffix += "/%module%";
107+
obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
108+
#endif
109+
}
110+
111+
if (portable_mode)
112+
return;
113+
114+
char base_module_dir[512];
115+
#if defined(_WIN32)
116+
int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
117+
#elif defined(__APPLE__)
118+
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
119+
#else
120+
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
121+
#endif
122+
123+
if (ret <= 0)
124+
return;
125+
126+
string path = base_module_dir;
127+
#if defined(__APPLE__)
128+
/* User Application Support Search Path */
129+
obs_add_module_path((path + "/Contents/MacOS").c_str(), (path + "/Contents/Resources").c_str());
130+
131+
#ifndef __aarch64__
132+
/* Legacy System Library Search Path */
133+
char system_legacy_module_dir[PATH_MAX];
134+
GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
135+
std::string path_system_legacy = system_legacy_module_dir;
136+
obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
137+
138+
/* Legacy User Application Support Search Path */
139+
char user_legacy_module_dir[PATH_MAX];
140+
GetAppConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
141+
std::string path_user_legacy = user_legacy_module_dir;
142+
obs_add_module_path((path_user_legacy + "/bin").c_str(), (path_user_legacy + "/data").c_str());
143+
#endif
144+
#else
145+
#if ARCH_BITS == 64
146+
obs_add_module_path((path + "/bin/64bit").c_str(), (path + "/data").c_str());
147+
#else
148+
obs_add_module_path((path + "/bin/32bit").c_str(), (path + "/data").c_str());
149+
#endif
150+
#endif
151+
}
152+
153+
/* First-party modules considered to be potentially unsafe to load in Safe Mode
154+
* due to them allowing external code (e.g. scripts) to modify OBS's state. */
155+
const unordered_set<string> unsafe_modules = {
156+
"frontend-tools", // Scripting
157+
"obs-websocket", // Allows outside modifications
158+
};
159+
160+
void setSafeModuleNames()
161+
{
162+
#ifndef SAFE_MODULES
163+
return;
164+
#else
165+
string module;
166+
stringstream modules(SAFE_MODULES);
167+
168+
while (getline(modules, module, '|')) {
169+
/* When only disallowing third-party plugins, still add
170+
* "unsafe" bundled modules to the safe list. */
171+
if (disable_3p_plugins || !unsafe_modules.count(module))
172+
obs_add_safe_module(module.c_str());
173+
}
174+
#endif
175+
}
176+
} // namespace
177+
82178
QObject *CreateShortcutFilter()
83179
{
84180
return new OBSEventFilter([](QObject *obj, QEvent *event) {
@@ -1086,6 +1182,14 @@ bool OBSApp::OBSInit()
10861182
setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
10871183
#endif
10881184

1185+
/* Safe Mode disables third-party plugins so we don't need to add earch
1186+
* paths outside the OBS bundle/installation. */
1187+
if (safe_mode || disable_3p_plugins) {
1188+
setSafeModuleNames();
1189+
} else {
1190+
addExtraModulePaths();
1191+
}
1192+
10891193
if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
10901194
return false;
10911195

frontend/widgets/OBSBasic.cpp

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
#include <sstream>
6161
#endif
6262
#include <string>
63-
#include <unordered_set>
6463

6564
#ifdef _WIN32
6665
#define WIN32_LEAN_AND_MEAN
@@ -103,98 +102,6 @@ extern bool cef_js_avail;
103102
extern void DestroyPanelCookieManager();
104103
extern void CheckExistingCookieId();
105104

106-
static void AddExtraModulePaths()
107-
{
108-
string plugins_path, plugins_data_path;
109-
char *s;
110-
111-
s = getenv("OBS_PLUGINS_PATH");
112-
if (s)
113-
plugins_path = s;
114-
115-
s = getenv("OBS_PLUGINS_DATA_PATH");
116-
if (s)
117-
plugins_data_path = s;
118-
119-
if (!plugins_path.empty() && !plugins_data_path.empty()) {
120-
#if defined(__APPLE__)
121-
plugins_path += "/%module%.plugin/Contents/MacOS";
122-
plugins_data_path += "/%module%.plugin/Contents/Resources";
123-
obs_add_module_path(plugins_path.c_str(), plugins_data_path.c_str());
124-
#else
125-
string data_path_with_module_suffix;
126-
data_path_with_module_suffix += plugins_data_path;
127-
data_path_with_module_suffix += "/%module%";
128-
obs_add_module_path(plugins_path.c_str(), data_path_with_module_suffix.c_str());
129-
#endif
130-
}
131-
132-
if (portable_mode)
133-
return;
134-
135-
char base_module_dir[512];
136-
#if defined(_WIN32)
137-
int ret = GetProgramDataPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
138-
#elif defined(__APPLE__)
139-
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%.plugin");
140-
#else
141-
int ret = GetAppConfigPath(base_module_dir, sizeof(base_module_dir), "obs-studio/plugins/%module%");
142-
#endif
143-
144-
if (ret <= 0)
145-
return;
146-
147-
string path = base_module_dir;
148-
#if defined(__APPLE__)
149-
/* User Application Support Search Path */
150-
obs_add_module_path((path + "/Contents/MacOS").c_str(), (path + "/Contents/Resources").c_str());
151-
152-
#ifndef __aarch64__
153-
/* Legacy System Library Search Path */
154-
char system_legacy_module_dir[PATH_MAX];
155-
GetProgramDataPath(system_legacy_module_dir, sizeof(system_legacy_module_dir), "obs-studio/plugins/%module%");
156-
std::string path_system_legacy = system_legacy_module_dir;
157-
obs_add_module_path((path_system_legacy + "/bin").c_str(), (path_system_legacy + "/data").c_str());
158-
159-
/* Legacy User Application Support Search Path */
160-
char user_legacy_module_dir[PATH_MAX];
161-
GetAppConfigPath(user_legacy_module_dir, sizeof(user_legacy_module_dir), "obs-studio/plugins/%module%");
162-
std::string path_user_legacy = user_legacy_module_dir;
163-
obs_add_module_path((path_user_legacy + "/bin").c_str(), (path_user_legacy + "/data").c_str());
164-
#endif
165-
#else
166-
#if ARCH_BITS == 64
167-
obs_add_module_path((path + "/bin/64bit").c_str(), (path + "/data").c_str());
168-
#else
169-
obs_add_module_path((path + "/bin/32bit").c_str(), (path + "/data").c_str());
170-
#endif
171-
#endif
172-
}
173-
174-
/* First-party modules considered to be potentially unsafe to load in Safe Mode
175-
* due to them allowing external code (e.g. scripts) to modify OBS's state. */
176-
static const unordered_set<string> unsafe_modules = {
177-
"frontend-tools", // Scripting
178-
"obs-websocket", // Allows outside modifications
179-
};
180-
181-
static void SetSafeModuleNames()
182-
{
183-
#ifndef SAFE_MODULES
184-
return;
185-
#else
186-
string module;
187-
stringstream modules(SAFE_MODULES);
188-
189-
while (getline(modules, module, '|')) {
190-
/* When only disallowing third-party plugins, still add
191-
* "unsafe" bundled modules to the safe list. */
192-
if (disable_3p_plugins || !unsafe_modules.count(module))
193-
obs_add_safe_module(module.c_str());
194-
}
195-
#endif
196-
}
197-
198105
extern void setupDockAction(QDockWidget *dock);
199106

200107
OBSBasic::OBSBasic(QWidget *parent) : OBSMainWindow(parent), undo_s(ui), ui(new Ui::OBSBasic)
@@ -952,14 +859,6 @@ void OBSBasic::OBSInit()
952859
#endif
953860
struct obs_module_failure_info mfi;
954861

955-
/* Safe Mode disables third-party plugins so we don't need to add earch
956-
* paths outside the OBS bundle/installation. */
957-
if (safe_mode || disable_3p_plugins) {
958-
SetSafeModuleNames();
959-
} else {
960-
AddExtraModulePaths();
961-
}
962-
963862
/* Modules can access frontend information (i.e. profile and scene collection data) during their initialization, and some modules (e.g. obs-websockets) are known to use the filesystem location of the current profile in their own code.
964863
965864
Thus the profile and scene collection discovery needs to happen before any access to that information (but after intializing global settings) to ensure legacy code gets valid path information.

0 commit comments

Comments
 (0)