mirror of
https://github.com/quizhizhe/LiteLoaderBDS-1.16.40.git
synced 2025-06-03 04:23:39 +00:00
适配runcmd
This commit is contained in:
parent
adb2a47128
commit
dce1c7c356
@ -15,6 +15,7 @@ class CommandOrigin {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
mce::UUID mUUID;
|
||||
public:
|
||||
LIAPI ServerPlayer* getPlayer() const;
|
||||
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
LIAPI static Block* getBlock(BlockPos* pos, BlockSource* blockSource);
|
||||
LIAPI static Block* getBlock(const BlockPos& pos, int dimId);
|
||||
LIAPI static Block* getBlock(const BlockPos& pos, BlockSource *blockSource);
|
||||
//LIAPI static Block* getBlockEx(const BlockPos& pos, int dimId);
|
||||
LIAPI static Block* getBlockEx(const BlockPos& pos, int dimId);
|
||||
LIAPI static BlockInstance getBlockInstance(BlockPos* pos, int dimId);
|
||||
LIAPI static BlockInstance getBlockInstance(BlockPos* pos, BlockSource* blockSource);
|
||||
LIAPI static BlockInstance getBlockInstance(const BlockPos& pos, int dimId);
|
||||
@ -98,47 +98,47 @@ public:
|
||||
|
||||
public:
|
||||
static void dummy() { ; }
|
||||
struct ServerCommandOrigin {
|
||||
void* myVTBL;
|
||||
void* UUID[2];
|
||||
ServerLevel* lvl;
|
||||
string Name;
|
||||
unsigned char Perm;
|
||||
static void* fake_vtbl[26];
|
||||
// struct ServerCommandOrigin {
|
||||
// void* myVTBL;
|
||||
// void* UUID[2];
|
||||
// ServerLevel* lvl;
|
||||
// string Name;
|
||||
// unsigned char Perm;
|
||||
// static void* fake_vtbl[26];
|
||||
//
|
||||
// [[deprecated]]
|
||||
// ServerCommandOrigin()
|
||||
// {
|
||||
// if (fake_vtbl[1] == nullptr) {
|
||||
// memcpy(fake_vtbl, (void**)(SYM("??_7ServerCommandOrigin@@6B@")) - 1, sizeof(fake_vtbl));
|
||||
// fake_vtbl[1] = (void*)dummy;
|
||||
// }
|
||||
// myVTBL = fake_vtbl + 1;
|
||||
// Name = "Server";
|
||||
// Perm = 4;
|
||||
// lvl = Global<ServerLevel>;
|
||||
// }
|
||||
// };
|
||||
|
||||
[[deprecated]]
|
||||
ServerCommandOrigin()
|
||||
{
|
||||
if (fake_vtbl[1] == nullptr) {
|
||||
memcpy(fake_vtbl, (void**)(SYM("??_7ServerCommandOrigin@@6B@")) - 1, sizeof(fake_vtbl));
|
||||
fake_vtbl[1] = (void*)dummy;
|
||||
}
|
||||
myVTBL = fake_vtbl + 1;
|
||||
Name = "Server";
|
||||
Perm = 4;
|
||||
lvl = Global<ServerLevel>;
|
||||
}
|
||||
};
|
||||
|
||||
// LIAPI static bool executeCommandAs(Player* player, const string& cmd);
|
||||
// LIAPI static std::pair<bool, string> executeCommandEx(const string& cmd);
|
||||
// LIAPI static bool executeCommand(const string& cmd);
|
||||
LIAPI static bool executeCommandAs(Player* player, const string& cmd);
|
||||
LIAPI static std::pair<bool, string> executeCommandEx(const string& cmd);
|
||||
LIAPI static bool executeCommand(const string& cmd);
|
||||
|
||||
|
||||
|
||||
//For compatibility
|
||||
// LIAPI static bool runcmdAs(Player* pl, const string& cmd)
|
||||
// {
|
||||
// return executeCommandAs(pl, cmd);
|
||||
// }
|
||||
// LIAPI static std::pair<bool, string> runcmdEx(const string& cmd)
|
||||
// {
|
||||
// return executeCommandEx(cmd);
|
||||
// }
|
||||
// LIAPI static bool runcmd(const string& cmd)
|
||||
// {
|
||||
// return executeCommand(cmd);
|
||||
// }
|
||||
LIAPI static bool runcmdAs(Player* pl, const string& cmd)
|
||||
{
|
||||
return executeCommandAs(pl, cmd);
|
||||
}
|
||||
LIAPI static std::pair<bool, string> runcmdEx(const string& cmd)
|
||||
{
|
||||
return executeCommandEx(cmd);
|
||||
}
|
||||
LIAPI static bool runcmd(const string& cmd)
|
||||
{
|
||||
return executeCommand(cmd);
|
||||
}
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_LEVEL
|
||||
|
@ -13,6 +13,9 @@ class ServerCommandOrigin : public CommandOrigin {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
|
||||
ServerLevel *mServerLevel;
|
||||
std::string mRequestID;
|
||||
CommandPermissionLevel mCommandPermissionLevel;
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_SERVERCOMMANDORIGIN
|
||||
public:
|
||||
|
@ -64,23 +64,23 @@ Block* Level::getBlock(const BlockPos& pos, BlockSource* blockSource) {
|
||||
|
||||
|
||||
// Return nullptr when failing to get block
|
||||
// Block* Level::getBlockEx(const BlockPos& pos, int dimId) {
|
||||
// auto dim = Global<Level>->getDimension(dimId);
|
||||
// if (!dim)
|
||||
// return nullptr;
|
||||
Block* Level::getBlockEx(const BlockPos& pos, int dimId) {
|
||||
auto dim = Global<Level>->getDimension(dimId);
|
||||
if (!dim)
|
||||
return nullptr;
|
||||
|
||||
// auto bs = &dim->getBlockSourceFromMainChunkSource();
|
||||
// auto lc = bs->getChunkAt(pos);
|
||||
// if (!lc)
|
||||
// return nullptr;
|
||||
auto bs = &dim->getBlockSourceFromMainChunkSource();
|
||||
auto lc = bs->getChunkAt(pos);
|
||||
if (!lc)
|
||||
return nullptr;
|
||||
|
||||
// short minHeight = dim->getMinHeight();
|
||||
// if (pos.y < minHeight || pos.y > dim->getHeight())
|
||||
// return nullptr;
|
||||
short minHeight = dim->getHeight();
|
||||
if (pos.y < minHeight || pos.y > dim->getHeight())
|
||||
return nullptr;
|
||||
|
||||
// ChunkBlockPos cbpos = ChunkBlockPos(pos, minHeight);
|
||||
// return const_cast<Block*>(&lc->getBlock(cbpos));
|
||||
// }
|
||||
ChunkBlockPos cbpos = ChunkBlockPos(pos, minHeight);
|
||||
return const_cast<Block*>(&lc->getBlock(cbpos));
|
||||
}
|
||||
|
||||
BlockInstance Level::getBlockInstance(BlockPos* pos, int dimId) {
|
||||
return {*pos, dimId};
|
||||
@ -158,7 +158,7 @@ Actor* Level::getDamageSourceEntity(ActorDamageSource* ads) {
|
||||
return Global<Level>->getEntity(v6);
|
||||
}
|
||||
|
||||
void* Level::ServerCommandOrigin::fake_vtbl[26];
|
||||
//void* Level::ServerCommandOrigin::fake_vtbl[26];
|
||||
|
||||
CompoundTag& getServerOriginTag() {
|
||||
static auto cached = CompoundTag::fromSNBT(R"({"CommandPermissionLevel":4b,"DimensionId":"Overworld","OriginType":7b,"RequestId":"00000000-0000-0000-0000-000000000000"})");
|
||||
@ -172,31 +172,35 @@ std::unique_ptr<CompoundTag> getPlayerOriginTag(Player& player) {
|
||||
return std::move(tag);
|
||||
}
|
||||
|
||||
// bool Level::executeCommand(const string& cmd) {
|
||||
// auto origin = ::ServerCommandOrigin::load(getServerOriginTag(), *Global<ServerLevel>);
|
||||
// return MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
// }
|
||||
bool Level::executeCommand(const string& cmd) {
|
||||
//auto origin = ::ServerCommandOrigin::load(getServerOriginTag(), *Global<ServerLevel>);
|
||||
std::string requestID = "00000000-0000-0000-0000-000000000000";
|
||||
std::unique_ptr<ServerCommandOrigin> origin(new ServerCommandOrigin(requestID,*Global<ServerLevel>, CommandPermissionLevel(4)));
|
||||
return MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
}
|
||||
|
||||
std::unordered_map<CommandOrigin const*, string*> resultOfOrigin = {};
|
||||
|
||||
// std::pair<bool, string> Level::executeCommandEx(const string& cmd) {
|
||||
// auto origin = ::ServerCommandOrigin::load(getServerOriginTag(), *Global<ServerLevel>);
|
||||
// string val;
|
||||
// auto ptr = origin.get();
|
||||
// resultOfOrigin[ptr] = &val;
|
||||
// bool rv = MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
// if (resultOfOrigin.count(ptr))
|
||||
// resultOfOrigin.erase(ptr);
|
||||
// return {rv, std::move(val)};
|
||||
// }
|
||||
std::pair<bool, string> Level::executeCommandEx(const string& cmd) {
|
||||
//auto origin = ::ServerCommandOrigin::load(getServerOriginTag(), *Global<ServerLevel>);
|
||||
const std::string requestID = "00000000-0000-0000-0000-000000000000";
|
||||
std::unique_ptr<ServerCommandOrigin> origin(new ServerCommandOrigin(requestID,*Global<ServerLevel>, CommandPermissionLevel(4)));
|
||||
string val;
|
||||
auto ptr = origin.get();
|
||||
resultOfOrigin[ptr] = &val;
|
||||
bool rv = MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
if (resultOfOrigin.count(ptr))
|
||||
resultOfOrigin.erase(ptr);
|
||||
return {rv, std::move(val)};
|
||||
}
|
||||
|
||||
|
||||
// static void* FAKE_PORGVTBL[26];
|
||||
// bool Level::executeCommandAs(Player* pl, const string& cmd) {
|
||||
// auto tag = getPlayerOriginTag(*pl);
|
||||
// auto origin = PlayerCommandOrigin::load(*tag, *Global<Level>);
|
||||
// return MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
// }
|
||||
bool Level::executeCommandAs(Player* pl, const string& cmd) {
|
||||
auto tag = getPlayerOriginTag(*pl);
|
||||
std::unique_ptr<PlayerCommandOrigin> origin(new PlayerCommandOrigin(*pl));
|
||||
return MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
}
|
||||
|
||||
|
||||
std::vector<Player*> Level::getAllPlayers() {
|
||||
|
Loading…
Reference in New Issue
Block a user