13 #include "3rdparty/openttd_social_integration_api/openttd_social_integration_api.h"
38 this->
library = std::make_unique<LibraryLoader>(filename);
45 std::unique_ptr<LibraryLoader>
library =
nullptr;
50 static std::vector<std::unique_ptr<InternalSocialIntegrationPlugin>>
_plugins;
59 std::string extension =
"-social.dll";
60 #elif defined(__APPLE__)
61 std::string extension =
"-social.dylib";
63 std::string extension =
"-social.so";
69 bool AddFile(
const std::string &filename,
size_t basepath_length,
const std::string &)
override
71 std::string basepath = filename.substr(basepath_length);
72 Debug(misc, 1,
"[Social Integration: {}] Loading ...", basepath);
74 auto &plugin =
_plugins.emplace_back(std::make_unique<InternalSocialIntegrationPlugin>(filename, basepath));
77 if (plugin->library ==
nullptr) {
81 if (plugin->library->HasError()) {
84 Debug(misc, 0,
"[Social Integration: {}] Failed to load library: {}", basepath, plugin->library->GetLastError());
88 OpenTTD_SocialIntegration_v1_GetInfo getinfo_func = plugin->library->GetFunction(
"SocialIntegration_v1_GetInfo");
89 if (plugin->library->HasError()) {
92 Debug(misc, 0,
"[Social Integration: {}] Failed to find symbol SocialPlugin_v1_GetInfo: {}", basepath, plugin->library->GetLastError());
96 OpenTTD_SocialIntegration_v1_Init init_func = plugin->library->GetFunction(
"SocialIntegration_v1_Init");
97 if (plugin->library->HasError()) {
100 Debug(misc, 0,
"[Social Integration: {}] Failed to find symbol SocialPlugin_v1_Init: {}", basepath, plugin->library->GetLastError());
104 getinfo_func(&plugin->plugin_info);
106 plugin->external.social_platform = plugin->plugin_info.social_platform;
107 plugin->external.name = plugin->plugin_info.name;
108 plugin->external.version = plugin->plugin_info.version;
111 std::string lc_social_platform = plugin->plugin_info.social_platform;
112 strtolower(lc_social_platform);
118 Debug(misc, 0,
"[Social Integration: {}] Another plugin for {} is already loaded", basepath, plugin->plugin_info.social_platform);
123 auto state = init_func(&plugin->plugin_api, &plugin->openttd_info);
125 case OTTD_SOCIAL_INTEGRATION_V1_INIT_SUCCESS:
128 Debug(misc, 1,
"[Social Integration: {}] Loaded for {}: {} ({})", basepath, plugin->plugin_info.social_platform, plugin->plugin_info.name, plugin->plugin_info.version);
131 case OTTD_SOCIAL_INTEGRATION_V1_INIT_FAILED:
134 Debug(misc, 0,
"[Social Integration: {}] Failed to initialize", basepath);
137 case OTTD_SOCIAL_INTEGRATION_V1_INIT_PLATFORM_NOT_RUNNING:
140 Debug(misc, 1,
"[Social Integration: {}] Failed to initialize: {} is not running", basepath, plugin->plugin_info.social_platform);
151 std::vector<SocialIntegrationPlugin *> plugins;
154 plugins.push_back(&plugin->external);
172 template <
typename T,
typename... Ts>
173 static void PluginCall(std::unique_ptr<InternalSocialIntegrationPlugin> &plugin, T func, Ts... args)
179 if (func !=
nullptr) {
187 PluginCall(plugin, plugin->plugin_api.shutdown);
201 if (plugin->plugin_api.run_callbacks !=
nullptr) {
202 if (!plugin->plugin_api.run_callbacks()) {
203 Debug(misc, 1,
"[Social Plugin: {}] Requested to be unloaded", plugin->external.basepath);
207 PluginCall(plugin, plugin->plugin_api.shutdown);
216 PluginCall(plugin, plugin->plugin_api.event_enter_main_menu);
223 PluginCall(plugin, plugin->plugin_api.event_enter_scenario_editor, map_width, map_height);
230 PluginCall(plugin, plugin->plugin_api.event_enter_singleplayer, map_width, map_height);
237 PluginCall(plugin, plugin->plugin_api.event_enter_multiplayer, map_width, map_height);
244 PluginCall(plugin, plugin->plugin_api.event_joining_multiplayer);