-
Notifications
You must be signed in to change notification settings - Fork 0
/
dllmain.cpp
158 lines (120 loc) · 4.41 KB
/
dllmain.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "std_include.hpp"
#include <plutonium_sdk.hpp>
plutonium::sdk::iinterface* plutonium_ = nullptr;
using namespace plutonium::sdk::interfaces;
using namespace plutonium::sdk::types;
void gsc_method_test([[maybe_unused]] entref entity)
{
plutonium_->logging()->info("GSC Method Test");
}
void gsc_function_test()
{
plutonium_->logging()->info("GSC Function Test");
}
void client_command_function_test([[maybe_unused]] int client_num)
{
plutonium_->logging()->info("Client Command Function Test");
}
void main_scheduler_test()
{
plutonium_->logging()->info("Main Frame Test!");
}
scheduler::evaluation game_scheduler_test()
{
plutonium_->logging()->info("Game Frame Test!");
return scheduler::reschedule;
}
void on_dvar_init()
{
plutonium_->logging()->info("Dvar System Initialized!");
}
void on_after_dvar_init()
{
plutonium_->logging()->info("Game Dvars Finished Initializing!");
}
void on_game_init([[maybe_unused]] int level_time, [[maybe_unused]] int restart)
{
plutonium_->logging()->info("Game Initialized!");
}
void on_game_shutdown([[maybe_unused]] int freeing_scripts)
{
plutonium_->logging()->info("Game Shutting Down!");
}
void on_player_pre_connect([[maybe_unused]] unsigned int client_num)
{
plutonium_->logging()->info("Player Connecting Once!");
}
void on_player_connect([[maybe_unused]] unsigned int client_num)
{
plutonium_->logging()->info("Player Connected!");
}
void on_player_disconnect([[maybe_unused]] unsigned int client_num)
{
plutonium_->logging()->info("Player Disconnected!");
}
void on_script_load()
{
plutonium_->logging()->info("Scripts are loading!");
}
void on_script_execute()
{
plutonium_->logging()->info("Scripts are executing!");
}
std::unique_ptr<plutonium::sdk::plugin> plugin_;
class plugin_impl final : public plutonium::sdk::plugin
{
public:
const char* plugin_name() override
{
return "Plutonium SDK Example";
}
bool is_game_supported(const plutonium::sdk::game game) override
{
return game == plutonium::sdk::game::iw5;
}
void on_startup(plutonium::sdk::iinterface* interface_ptr, [[maybe_unused]] plutonium::sdk::game game) override
{
plutonium_ = interface_ptr;
// Logging to the Plutonium console
plutonium_->logging()->info("Plugin Startup Called\n");
// Register a built-in GSC function
plutonium_->gsc()->register_function("testPluginFunction", gsc_function_test);
// Register a client command
plutonium_->client_command()->register_client_command("testClientCommand", client_command_function_test);
// Register a built-in GSC method
plutonium_->gsc()->register_method("testPluginMethod", gsc_method_test);
// Schedule a function to be called once on the main thread
plutonium_->scheduler()->once(main_scheduler_test);
// Schedule a function to be called on the game thread ever 1 second
plutonium_->scheduler()->every(game_scheduler_test, 1000, scheduler::thread::game);
// Add a callback when the dvar system is ready to register dvars
plutonium_->callbacks()->on_dvar_init(on_dvar_init);
// Add a callback when the dvar system is finished registering game dvars
plutonium_->callbacks()->on_after_dvar_init(on_after_dvar_init);
// Add a callback when the game server initialized
plutonium_->callbacks()->on_game_init(on_game_init);
// Add a callback when the game server shuts down
plutonium_->callbacks()->on_game_shutdown(on_game_shutdown);
// Add a callback when a player connects once
plutonium_->callbacks()->on_player_pre_connect(on_player_pre_connect);
// Add a callback when a player connects (including fast restarts)
plutonium_->callbacks()->on_player_connect(on_player_connect);
// Add a callback when a player disconnects
plutonium_->callbacks()->on_player_disconnect(on_player_disconnect);
// Add a callback when scripts are being loaded
plutonium_->callbacks()->on_scripts_load(on_script_load);
// Add a callback when scripts are being executed
plutonium_->callbacks()->on_scripts_execute(on_script_execute);
}
void on_shutdown() override
{
}
};
PLUTONIUM_API plutonium::sdk::plugin* on_initialize()
{
return (plugin_ = std::make_unique<plugin_impl>()).get();
}
BOOL APIENTRY DllMain(HMODULE, DWORD, LPVOID)
{
return TRUE;
}