-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathBDSMod.cpp
More file actions
93 lines (75 loc) · 2.88 KB
/
Copy pathBDSMod.cpp
File metadata and controls
93 lines (75 loc) · 2.88 KB
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
//
// Created by xhy on 2020/8/25.
//
#include "BDSMod.h"
#include "SymHook.h"
#include "lib/mod.h"
#include "tools/DirtyLogger.h"
#include "tools/Message.h"
#include "commands/TrapdoorCommand.h"
namespace trapdoor {
//全局模组对象
BDSMod *bdsMod = nullptr;
void initializeMod(BDSMod *BDSMod) {
L_DEBUG("create BDS mod instance");
trapdoor::bdsMod = BDSMod;
registryCommand();
}
Level *BDSMod::getLevel() { return this->serverLevel; }
void BDSMod::setCommandRegistry(void *registry) {
L_DEBUG("set commandRegistry");
this->commandRegistry = registry;
}
void *BDSMod::getCommandRegistry() { return this->commandRegistry; }
void BDSMod::setLevel(Level *level) {
L_DEBUG("init server level");
this->serverLevel = level;
}
CommandManager &BDSMod::getCommandManager() { return this->commandManager; }
void BDSMod::registerCommands() {
if (!this->commandRegistry) {
L_ERROR("fail to register command!![commandRegistry is null ptr]");
}
L_DEBUG("begin register command");
this->registerLangCommand();
getCommandManager()
.registerCmd("apicfg", "command.apicfg.desc")
->then(ARG(
"pvd", "command.apicfg.pvd.desc", INT,
{ this->getCfg().particleViewDistance = holder->getInt(); }))
->then(ARG("pm", "command.apicfg.pm.desc", BOOL, {
this->getCfg().particlePerformanceMode = holder->getBool();
}));
}
std::map<std::string, PlayerBuffer> &BDSMod::getPlayerBuffer() {
return this->playerCache;
}
void BDSMod::initialize() {
L_DEBUG("init thread pool");
this->threadPool = new ThreadPool(std::thread::hardware_concurrency());
}
trapdoor::Actor *BDSMod::fetchEntity(int64_t id, bool b) {
using namespace SymHook;
return SYM_CALL(Actor * (*)(Level *, int64_t, bool),
SymHook::Level_fetchEntity_ff3466ce, this->getLevel(),
id, b);
}
void BDSMod::registerLangCommand() {
this->commandManager.registerCmd("lang", "command.lang.desc")
->then(ARG("list", "command.lang.list.desc", NONE,
{
trapdoor::info(player,
this->i18NManager.getAllLanguages());
}))
->then(ARG("set", "command.lang.set.desc", STR, {
auto result =
this->i18NManager.tryChangeLanguage(holder->getString());
if (result) {
info(player, LANG("command.lang.set.success"));
} else {
info(player, LANG("command.lang.set.failure"));
}
}));
}
void BDSMod::tick() { ++this->trapdoorTick; }
} // namespace trapdoor