Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Tools.cpp
Go to the documentation of this file.
1#include <Tools.h>
2
3#include "../IBaseApi.h"
4#include "../PluginManager/PluginManager.h"
5
6namespace AsaApi::Tools
7{
9 {
10 char buffer[MAX_PATH];
11 GetModuleFileNameA(nullptr, buffer, MAX_PATH);
12
13 const std::string::size_type pos = std::string(buffer).find_last_of("\\/");
14
15 return std::string(buffer).substr(0, pos);
16 }
17
18 std::string Utf8Encode(const std::wstring& wstr)
19 {
20 std::string converted_string;
21
22 if (wstr.empty())
23 return converted_string;
24
25 const auto size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0,
26 nullptr, nullptr);
27 if (size_needed > 0)
28 {
29 converted_string.resize(size_needed);
30
31 WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), converted_string.data(),
32 size_needed, nullptr, nullptr);
33 }
34
35 return converted_string;
36 }
37
38 std::wstring Utf8Decode(const std::string& str)
39 {
40 std::wstring converted_string;
41
42 if (str.empty())
43 {
44 return converted_string;
45 }
46
47 const auto size_needed = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), nullptr, 0);
48 if (size_needed > 0)
49 {
50 converted_string.resize(size_needed);
51
52 MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), converted_string.data(),
53 size_needed);
54 }
55
56 return converted_string;
57 }
58
59 bool IsPluginLoaded(const std::string& plugin_name)
60 {
61 return API::PluginManager::Get().IsPluginLoaded(plugin_name);
62 }
63
65 {
66 return API::game_api->GetVersion();
67 }
68} // namespace Tools // namespace AsaApi
ARK_API float GetApiVersion()
Returns Current Running Api Version.
Definition Tools.cpp:64
ARK_API std::string GetCurrentDir()
Definition Tools.cpp:8