Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
PluginManager.h
Go to the documentation of this file.
1#pragma once
2
3#define WIN32_LEAN_AND_MEAN
4
5#include <memory>
6#include <string>
7#include <utility>
8#include <vector>
9#include <windows.h>
10
11#include "json.hpp"
12
13namespace API
14{
15 struct Plugin
16 {
17 Plugin(HINSTANCE h_module, std::string name, std::string full_name,
18 std::string description, float version, float min_api_version, std::vector<std::string> dependencies)
19 : h_module(h_module),
20 name(std::move(name)),
21 full_name(std::move(full_name)),
22 description(std::move(description)),
23 version(version),
24 min_api_version(min_api_version),
26 {
27 }
28
29 HINSTANCE h_module;
30 std::string name;
31 std::string full_name;
33 float version;
36 };
37
39 {
40 public:
41 static PluginManager& Get();
42
43 PluginManager(const PluginManager&) = delete;
47
48 /**
49 * \brief Find and load all plugins
50 */
51 void LoadAllPlugins();
52
53 /**
54 * \brief Load plugin by it's name
55 * \param plugin_name File name of the plugin
56 * \return Loaded plugin
57 */
58 std::shared_ptr<Plugin>& LoadPlugin(const std::string& plugin_name) noexcept(false);
59
60 /**
61 * \brief Unload plugin by it's name. Plugin must free all used resources.
62 * \param plugin_name File name of the plugin
63 */
64 void UnloadPlugin(const std::string& plugin_name) noexcept(false);
65
66 /**
67 * \brief Find plugin by it's name
68 * \param plugin_name File name of the plugin
69 * \return An iterator to the loaded plugin
70 */
72
73 /**
74 * \brief Returns true if plugin was loaded, false otherwise
75 */
76 bool IsPluginLoaded(const std::string& plugin_name);
77
78 /**
79 * \brief Checks for auto plugin reloads
80 */
82 private:
83 PluginManager() = default;
84 ~PluginManager() = default;
85
88
90
92
94
95 // Plugins auto reloading
100 };
101} // namespace API
static void SetServerID(RCONClientConnection *, RCONPacket *, UWorld *)
std::string GetApiName() override
bool DownloadCacheFiles(const std::filesystem::path downloadFile, const std::filesystem::path localFile)
std::unique_ptr< AsaApi::IApiUtils > & GetApiUtils() override
static void LoadPluginCmd(APlayerController *, FString *, bool)
std::unique_ptr< AsaApi::ICommands > commands_
Definition ArkBaseApi.h:45
void RegisterCommands() override
float GetVersion() override
~ArkBaseApi() override=default
static FString LoadPlugin(FString *cmd)
static void UnloadPluginRcon(RCONClientConnection *, RCONPacket *, UWorld *)
nlohmann::json GetConfig()
std::unique_ptr< AsaApi::IApiUtils > api_utils_
Definition ArkBaseApi.h:47
bool Init() override
static void UnloadPluginCmd(APlayerController *, FString *, bool)
static void LoadPluginRcon(RCONClientConnection *, RCONPacket *, UWorld *)
static FString UnloadPlugin(FString *cmd)
std::unique_ptr< AsaApi::ICommands > & GetCommands() override
std::unique_ptr< AsaApi::IHooks > & GetHooks() override
std::unique_ptr< AsaApi::IHooks > hooks_
Definition ArkBaseApi.h:46
std::vector< std::shared_ptr< Plugin > > loaded_plugins_
std::vector< std::shared_ptr< Plugin > >::const_iterator FindPlugin(const std::string &plugin_name)
Find plugin by it's name.
PluginManager & operator=(const PluginManager &)=delete
PluginManager()=default
PluginManager(const PluginManager &)=delete
PluginManager(PluginManager &&)=delete
void LoadAllPlugins()
Find and load all plugins.
static PluginManager & Get()
static nlohmann::json ReadPluginInfo(const std::string &plugin_name)
bool IsPluginLoaded(const std::string &plugin_name)
Returns true if plugin was loaded, false otherwise.
std::shared_ptr< Plugin > & LoadPlugin(const std::string &plugin_name) noexcept(false)
Load plugin by it's name.
static void DetectPluginChangesTimerCallback()
Checks for auto plugin reloads.
void UnloadPlugin(const std::string &plugin_name) noexcept(false)
Unload plugin by it's name. Plugin must free all used resources.
PluginManager & operator=(PluginManager &&)=delete
~PluginManager()=default
static nlohmann::json ReadSettingsConfig()
static const FColor Green
Definition ColorList.h:24
UE_NODISCARD FORCEINLINE const TCHAR * operator*() const UE_LIFETIMEBOUND
Definition IBaseApi.h:9
constexpr float api_version
ARK_API std::string GetCurrentDir()
Definition Tools.cpp:8
IApiUtils & GetApiUtils()
Definition ApiUtils.cpp:206
void InitHooks()
Definition HooksImpl.cpp:43
Definition json.hpp:4518
std::string description
std::vector< std::string > dependencies
Plugin(HINSTANCE h_module, std::string name, std::string full_name, std::string description, float version, float min_api_version, std::vector< std::string > dependencies)
HINSTANCE h_module
float min_api_version
std::string full_name
std::string name
void SendMessageW(int Id, int Type, FString *OutGoingMessage)
Definition Other.h:38
int Id
Definition Other.h:13