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