Ark Server API (ASE) - 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 ArkApi::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 [[deprecated]] std::wstring ConvertToWideStr(const std::string& text)
19 {
20 const size_t size = text.size();
21
22 std::wstring wstr;
23 if (size > 0)
24 {
25 wstr.resize(size);
26
27 size_t converted_chars;
28 mbstowcs_s(&converted_chars, wstr.data(), size + 1, text.c_str(), _TRUNCATE);
29 }
30
31 return wstr;
32 }
33
34 [[deprecated]] std::string ConvertToAnsiStr(const std::wstring& text)
35 {
36 const size_t length = text.size();
37
38 std::string str(length, '\0');
39 std::use_facet<std::ctype<wchar_t>>(std::locale()).narrow(text.c_str(), text.c_str() + length, '?', str.data());
40
41 return str;
42 }
43
44 std::string Utf8Encode(const std::wstring& wstr)
45 {
46 std::string converted_string;
47
48 if (wstr.empty())
49 return converted_string;
50
51 const auto size_needed = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), nullptr, 0,
52 nullptr, nullptr);
53 if (size_needed > 0)
54 {
55 converted_string.resize(size_needed);
56
57 WideCharToMultiByte(CP_UTF8, 0, wstr.data(), static_cast<int>(wstr.size()), converted_string.data(),
58 size_needed, nullptr, nullptr);
59 }
60
61 return converted_string;
62 }
63
64 std::wstring Utf8Decode(const std::string& str)
65 {
66 std::wstring converted_string;
67
68 if (str.empty())
69 {
70 return converted_string;
71 }
72
73 const auto size_needed = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), nullptr, 0);
74 if (size_needed > 0)
75 {
76 converted_string.resize(size_needed);
77
78 MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast<int>(str.size()), converted_string.data(),
79 size_needed);
80 }
81
82 return converted_string;
83 }
84
85 bool IsPluginLoaded(const std::string& plugin_name)
86 {
87 return API::PluginManager::Get().IsPluginLoaded(plugin_name);
88 }
89
91 {
92 return API::game_api->GetVersion();
93 }
94} // namespace Tools // namespace ArkApi
ARK_API std::string GetCurrentDir()
Definition Tools.cpp:7
ARK_API float GetApiVersion()
Returns Current Running Api Version.
Definition Tools.cpp:90