-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
89 lines (71 loc) · 1.99 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <NativeFunc.hpp>
#include <NativesMain.hpp>
#include <Server/Components/Pawn/pawn.hpp>
#include <sdk.hpp>
struct HelloComponent;
HelloComponent* helloComponent = nullptr;
extern void* pAMXFunctions;
struct HelloComponent final : IComponent, PawnEventHandler {
PROVIDE_UID(0x1126fdb4780f11ec);
StringView componentName() const override
{
return "HelloWorld";
}
SemanticVersion componentVersion() const override
{
return SemanticVersion(0, 0, 1, 0);
}
void onLoad(ICore* c) override
{
core = c;
}
void onInit(IComponentList* components) override
{
pawnComponent = components->queryComponent<IPawnComponent>();
if (pawnComponent == nullptr) {
StringView name = componentName();
core->logLn(
LogLevel::Error,
"Error loading component %.*s: Pawn component not loaded",
name.length(),
name.data());
return;
}
pAMXFunctions = (void*)&pawnComponent->getAmxFunctions();
pawnComponent->getEventDispatcher().addEventHandler(this);
}
void onReady() override { }
void onAmxLoad(void* amx) override
{
pawn_natives::AmxLoad(static_cast<AMX*>(amx));
}
void onAmxUnload(void* amx) override { }
void onFree(IComponent* component) override
{
if (component == pawnComponent) {
pawnComponent = nullptr;
pAMXFunctions = nullptr;
}
}
void free() override
{
if (pawnComponent != nullptr)
pawnComponent->getEventDispatcher().removeEventHandler(this);
delete this;
}
void reset() override
{
// Nothing to reset for now.
}
ICore* core = nullptr;
IPawnComponent* pawnComponent;
};
COMPONENT_ENTRY_POINT()
{
helloComponent = new HelloComponent();
return helloComponent;
}
PAWN_NATIVE(Hello, HelloWorld, void())
{
helloComponent->core->printLn("Hello, world!");
}