Skip to content

Commit 1722ceb

Browse files
committed
use sdk config functions and singleton
1 parent 7ab6781 commit 1722ceb

File tree

36 files changed

+25
-412
lines changed

36 files changed

+25
-412
lines changed

SDK

Server/Components/CAPI/Impl/Actors/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

Server/Components/CAPI/Impl/Checkpoints/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

Server/Components/CAPI/Impl/Classes/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

Server/Components/CAPI/Impl/ComponentManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#pragma once
1010
#include <variant>
1111

12-
#include "../Utils/Singleton.hpp"
12+
#include <Impl/Utils/singleton.hpp>
1313
#include "../Utils/MacroMagic.hpp"
1414

1515
#include "sdk.hpp"

Server/Components/CAPI/Impl/Config/APIs.cpp

Lines changed: 5 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -7,169 +7,30 @@
77
*/
88

99
#include "../ComponentManager.hpp"
10-
11-
int getConfigOptionAsInt(const Impl::String& cvar)
12-
{
13-
IConfig* config = &ComponentManager::Get()->core->getConfig();
14-
auto res = config->getNameFromAlias(cvar);
15-
bool* v0 = nullptr;
16-
int* v1 = nullptr;
17-
if (!res.second.empty())
18-
{
19-
if (res.first)
20-
{
21-
ComponentManager::Get()->core->logLn(LogLevel::Warning, "Deprecated console variable \"%s\", use \"%.*s\" instead.", cvar.c_str(), PRINT_VIEW(res.second));
22-
}
23-
if (!(v1 = config->getInt(res.second)))
24-
{
25-
v0 = config->getBool(res.second);
26-
}
27-
}
28-
else
29-
{
30-
if (!(v1 = config->getInt(cvar)))
31-
{
32-
v0 = config->getBool(cvar);
33-
}
34-
}
35-
if (v1)
36-
{
37-
return *v1;
38-
}
39-
else if (v0)
40-
{
41-
ComponentManager::Get()->core->logLn(LogLevel::Warning, "Boolean console variable \"%s\" retreived as integer.", cvar.c_str());
42-
return *v0;
43-
}
44-
else
45-
{
46-
return 0;
47-
}
48-
}
49-
50-
bool getConfigOptionAsBool(const Impl::String& cvar)
51-
{
52-
IConfig* config = &ComponentManager::Get()->core->getConfig();
53-
auto res = config->getNameFromAlias(cvar);
54-
bool* v0 = nullptr;
55-
int* v1 = nullptr;
56-
if (!res.second.empty())
57-
{
58-
if (res.first)
59-
{
60-
ComponentManager::Get()->core->logLn(LogLevel::Warning, "Deprecated console variable \"%s\", use \"%.*s\" instead.", cvar.c_str(), PRINT_VIEW(res.second));
61-
}
62-
if (!(v0 = config->getBool(res.second)))
63-
{
64-
v1 = config->getInt(res.second);
65-
}
66-
}
67-
else
68-
{
69-
if (!(v0 = config->getBool(cvar)))
70-
{
71-
v1 = config->getInt(cvar);
72-
}
73-
}
74-
if (v0)
75-
{
76-
return *v0;
77-
}
78-
else if (v1)
79-
{
80-
ComponentManager::Get()->core->logLn(LogLevel::Warning, "Integer console variable \"%s\" retreived as boolean.", cvar.c_str());
81-
return *v1 != 0;
82-
}
83-
else
84-
{
85-
return false;
86-
}
87-
}
88-
89-
float getConfigOptionAsFloat(const Impl::String& cvar)
90-
{
91-
IConfig* config = &ComponentManager::Get()->core->getConfig();
92-
auto res = config->getNameFromAlias(cvar);
93-
float* var = nullptr;
94-
if (!res.second.empty())
95-
{
96-
if (res.first)
97-
{
98-
ComponentManager::Get()->core->logLn(LogLevel::Warning, "Deprecated console variable \"%s\", use \"%.*s\" instead.", cvar.c_str(), PRINT_VIEW(res.second));
99-
}
100-
var = config->getFloat(res.second);
101-
}
102-
else
103-
{
104-
var = config->getFloat(cvar);
105-
}
106-
if (var)
107-
{
108-
return *var;
109-
}
110-
else
111-
{
112-
return 0.0f;
113-
}
114-
}
115-
116-
int getConfigOptionAsString(const Impl::String& cvar, Impl::String& buffer)
117-
{
118-
// Special case, converting `gamemode0` to `pawn.main_scripts[0]`. It is the only string to
119-
// array change.
120-
IConfig* config = &ComponentManager::Get()->core->getConfig();
121-
bool gm = cvar.substr(0, 8) == "gamemode";
122-
auto res = config->getNameFromAlias(gm ? "gamemode" : cvar);
123-
if (!res.second.empty())
124-
{
125-
if (res.first)
126-
{
127-
ComponentManager::Get()->core->logLn(LogLevel::Warning, "Deprecated console variable \"%s\", use \"%.*s\" instead.", cvar.c_str(), PRINT_VIEW(res.second));
128-
}
129-
if (gm)
130-
{
131-
size_t i = std::stoi("0" + cvar.substr(8));
132-
Impl::DynamicArray<StringView> mainScripts(i + 1);
133-
size_t n = config->getStrings(res.second, Span<StringView>(mainScripts.data(), mainScripts.size()));
134-
if (i < n)
135-
{
136-
buffer = mainScripts[i].data();
137-
}
138-
}
139-
else
140-
{
141-
buffer = config->getString(res.second).data();
142-
}
143-
}
144-
else
145-
{
146-
buffer = config->getString(cvar).data();
147-
}
148-
return buffer.length();
149-
}
10+
#include <Impl/Utils/helpers.hpp>
15011

15112
OMP_CAPI(Config_GetAsBool, bool(StringCharPtr cvar))
15213
{
153-
bool value = getConfigOptionAsBool(cvar);
14+
bool value = getConfigOptionAsBool(ComponentManager::Get()->core, cvar);
15415
return value;
15516
}
15617

15718
OMP_CAPI(Config_GetAsInt, int(StringCharPtr cvar))
15819
{
159-
int value = getConfigOptionAsInt(cvar);
20+
int value = getConfigOptionAsInt(ComponentManager::Get()->core, cvar);
16021
return value;
16122
}
16223

16324
OMP_CAPI(Config_GetAsFloat, float(StringCharPtr cvar))
16425
{
165-
float value = getConfigOptionAsFloat(cvar);
26+
float value = getConfigOptionAsFloat(ComponentManager::Get()->core, cvar);
16627
return value;
16728
}
16829

16930
OMP_CAPI(Config_GetAsString, int(StringCharPtr cvar, OutputStringViewPtr output))
17031
{
17132
Impl::String value = Impl::String();
172-
int len = getConfigOptionAsString(cvar, value);
33+
int len = getConfigOptionAsString(ComponentManager::Get()->core, cvar, value);
17334
COPY_STRING_TO_CAPI_STRING_VIEW(output, value.data(), len);
17435
return len;
17536
}

Server/Components/CAPI/Impl/Console/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

Server/Components/CAPI/Impl/Core/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

Server/Components/CAPI/Impl/CustomModels/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

Server/Components/CAPI/Impl/Dialogs/Events.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#pragma once
1010
#include "../ComponentManager.hpp"
11-
#include "../../Utils/Singleton.hpp"
1211
#include "sdk.hpp"
1312

1413
template <EventPriorityType PRIORITY>

0 commit comments

Comments
 (0)