Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Feb 7, 2023
1 parent fd1d94d commit 250a21b
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 136 deletions.
55 changes: 13 additions & 42 deletions WorldEdit/WorldEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,12 @@
#include <mc/Block.hpp>
#include <mc/Level.hpp>
#include <mc/BlockLegacy.hpp>
#include <mc/ServerNetworkHandler.hpp>
#include <mc/NetworkPacketEventCoordinator.hpp>
#include <mc/PacketHeader.hpp>
#include <mc/Packet.hpp>
#include <mc/NetworkIdentifier.hpp>
#include <mc/PlayerActionPacket.hpp>
#include <mc/Player.hpp>
#include <fstream>
#include "Version.h"
#include "Nlohmann/json.hpp"

//?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVPlayerActionPacket@@@Z
// THook(void,
// "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@"
// "AEBVPlayerActionPacket@@@Z",
// ServerNetworkHandler* serverNetworkHandler,
// NetworkIdentifier const& networkIdentifier,
// PlayerActionPacket const& playerActionPacket) {
// std::cout
// <<
// const_cast<PlayerActionPacket&>(playerActionPacket).toDebugString()
// << std::endl;
// return original(serverNetworkHandler, networkIdentifier,
// playerActionPacket);
// }
//?sendPacketReceivedFrom@NetworkPacketEventCoordinator@@QEAAXAEBVPacketHeader@@AEBVPacket@@@Z
// THook(void,
// "?sendPacketReceivedFrom@NetworkPacketEventCoordinator@@"
// "QEAAXAEBVPacketHeader@@AEBVPacket@@@Z",
// NetworkPacketEventCoordinator* networkPacketEventCoordinator,
// PacketHeader const& packetHeader,
// Packet const& packet) {
// std::cout << fmt::format("{}({})->{}", packet.getName(), packet.getId(),
// packet.clientSubId)
// << std::endl;
// return original(networkPacketEventCoordinator, packetHeader, packet);
// }

// std::unordered_map<std::string, std::string>& getBlockColorssMap() {
// static std::unordered_map<std::string, std::string> sb;
// return sb;
// }

THook(void, "?setRuntimeId@Block@@IEBAXAEBI@Z", Block* block, unsigned int const& id) {
auto& blockName = worldedit::getBlockNameMap();
auto& blockId = worldedit::getBlockIdMap();
Expand All @@ -73,13 +36,21 @@ THook(void, "?setRuntimeId@Block@@IEBAXAEBI@Z", Block* block, unsigned int const

namespace worldedit {

Logger& logger(){
static Logger l(PLUGIN_NAME);
Logger& logger() {
static Logger l(PLUGIN_NAME);
#if PLUGIN_VERSION_STATUS == PLUGIN_VERSION_DEV
l.consoleLevel = 8;
l.consoleLevel = 8;
#endif
return l;
}
return l;
}

void clearBlockEntity(class BlockActor* be) {
void* unknown = VirtualCall<void*>(be, 256);
// logger().info("{}", (long long)unknown);
if (unknown != nullptr) {
VirtualCall<void>(unknown, 96);
}
}

std::unordered_map<std::string, class PlayerData>& getPlayersDataMap() {
static std::unordered_map<std::string, class PlayerData> data;
Expand Down
2 changes: 1 addition & 1 deletion WorldEdit/WorldEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace worldedit {

Logger& logger();

void clearBlockEntity(class BlockActor* be);
std::unordered_map<std::string,class PlayerData>& getPlayersDataMap();
class PlayerData& getPlayersData(std::string xuid);
std::unordered_map<int, std::string>& getBlockNameMap();
Expand Down
4 changes: 2 additions & 2 deletions core/command/HistoryCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace worldedit {
res.first->forEachBlockInClipboard([&](const BlockPos& pos) {
auto worldPos = pos + res.first->playerPos;

i += res.first->blockslist[res.first->getIter(pos)].setBlockForHistory(worldPos, blockSource,
i += res.first->blockslist[res.first->getIter(pos)].setBlockWithoutcheckGMask(worldPos, blockSource,
playerData);
});
*res.first = tmp;
Expand Down Expand Up @@ -131,7 +131,7 @@ namespace worldedit {

res.first->forEachBlockInClipboard([&](const BlockPos& pos) {
auto worldPos = pos + res.first->playerPos;
i += res.first->blockslist[res.first->getIter(pos)].setBlockForHistory(worldPos, blockSource,
i += res.first->blockslist[res.first->getIter(pos)].setBlockWithoutcheckGMask(worldPos, blockSource,
playerData);
});
*res.first = tmp;
Expand Down
8 changes: 5 additions & 3 deletions core/command/RegionOperationCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2103,7 +2103,7 @@ namespace worldedit {
"removeitem", // command name
tr("worldedit.command.description.removeitem"), // command description
{},
{ParamData("item", ParamType::Item, "item"), ParamData("num", ParamType::Int, true, "num"),
{ParamData("item", ParamType::Item, true, "item"), ParamData("num", ParamType::Int, true, "num"),
ParamData("data", ParamType::Int, true, "data")},
{{"item", "num", "data"}},
// dynamic command callback
Expand Down Expand Up @@ -2179,7 +2179,9 @@ namespace worldedit {
auto* shulkItem = ItemStack::create(mItem->asCompoundTag()->clone());
int count2 = shulkItem->getCount();

if (count2 <= 0 || !(shulkItem->sameItem(cmdItem)) ||
if (count2 <= 0 ||
!(cmdItem == ItemInstance::EMPTY_ITEM ||
shulkItem->sameItem(cmdItem)) ||
(data >= -2140000000 && data != shulkItem->getAuxValue())) {
continue;
}
Expand Down Expand Up @@ -2209,7 +2211,7 @@ namespace worldedit {
}
}

if (!(item->sameItem(cmdItem)) ||
if (!(cmdItem == ItemInstance::EMPTY_ITEM || item->sameItem(cmdItem)) ||
(data >= -2140000000 && data != item->getAuxValue())) {
continue;
}
Expand Down
95 changes: 58 additions & 37 deletions core/data/PlayerData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
//
#pragma once
#include "PlayerData.h"
#include "WorldEdit.h"
#include "eval/Eval.h"
#include "eval/CppEval.h"
#include <mc/Player.hpp>
#include <mc/Block.hpp>
#include <mc/StaticVanillaBlocks.hpp>
#include <mc/BlockSource.hpp>
#include <mc/ChunkSource.hpp>
#include <mc/LevelChunk.hpp>
#include <mc/SubChunk.hpp>
#include <mc/Dimension.hpp>
#include <mc/SubChunkPos.hpp>
#include <mc/CommandUtils.hpp>
#include <mc/Level.hpp>
#include "region/Regions.h"
Expand Down Expand Up @@ -107,27 +113,62 @@ namespace worldedit {
variables["pt"] = playerRot.y;
}

bool PlayerData::setBlockForHistory(BlockSource* blockSource, const BlockPos& pos, Block* block, Block* exblock) {
CommandUtils::clearBlockEntityContents(*blockSource, pos);
blockSource->setExtraBlock(pos, *BedrockBlocks::mAir, 16 + updateArg);
if (updateExArg % 2 == 1) {
blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr);
} else {
blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block);
bool PlayerData::setBlockWithoutcheckGMask(BlockSource* blockSource,
const BlockPos& pos,
Block* block,
Block* exblock) {
bool res = false;
BlockActor* be = blockSource->getBlockEntity(pos);
if (be != nullptr) {
clearBlockEntity(be);
}
if (block != StaticVanillaBlocks::mBubbleColumn) {
if (exblock != BedrockBlocks::mAir) {
blockSource->setExtraBlock(pos, *exblock, 16 + updateArg);
if (updateExArg % 2 == 1) {
res |= blockSource->setExtraBlock(pos, *BedrockBlocks::mAir, updateArg);
res |= blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr);
if (block != StaticVanillaBlocks::mBubbleColumn) {
if (exblock != BedrockBlocks::mAir) {
res |= blockSource->setExtraBlock(pos, *exblock, updateArg);
}
if (res) {
blockSource->getDimension().forEachPlayer([&](Player& player) -> bool {
player.sendUpdateBlockPacket(pos, *exblock, UpdateBlockFlags::BlockUpdateAll,
UpdateBlockLayer::UpdateBlockLiquid);
return true;
});
}
} else {
res |= blockSource->setExtraBlock(pos, *StaticVanillaBlocks::mFlowingWater, updateArg);
res |= blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr);
}
} else {
blockSource->setExtraBlock(pos, *StaticVanillaBlocks::mFlowingWater, 16 + updateArg);
if (updateExArg % 2 == 1) {
blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr);
} else {
blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block);
auto& dim = blockSource->getDimension();
ChunkBlockPos cpos(pos, dim.getMinHeight());
SubChunkPos scpos(pos);
LevelChunk* chunk = blockSource->getChunkAt(pos);
if (chunk == nullptr || chunk->isReadOnly()) {
return false;
}
auto* sc = chunk->getSubChunk(scpos.y);
auto index = cpos.toLegacyIndex();
if (&chunk->getBlock(cpos) != block) {
res = true;
sc->_setBlock(0, index, *block);
}
if (&chunk->getExtraBlock(cpos) != exblock) {
res = true;
sc->_setBlock(1, index, *exblock);
}
if (res) {
dim.forEachPlayer([&](Player& player) -> bool {
player.sendUpdateBlockPacket(pos, *block, UpdateBlockFlags::BlockUpdateAll,
UpdateBlockLayer::UpdateBlockDefault);
player.sendUpdateBlockPacket(pos, *exblock, UpdateBlockFlags::BlockUpdateAll,
UpdateBlockLayer::UpdateBlockLiquid);
return true;
});
}
}
return true;
return res;
}

bool PlayerData::setBlockSimple(BlockSource* blockSource,
Expand All @@ -141,27 +182,7 @@ namespace worldedit {
return false;
}
}

CommandUtils::clearBlockEntityContents(*blockSource, pos);
blockSource->setExtraBlock(pos, *BedrockBlocks::mAir, 16 + updateArg);
if (updateExArg % 2 == 1) {
blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr);
} else {
blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block);
}
if (block != StaticVanillaBlocks::mBubbleColumn) {
if (exblock != BedrockBlocks::mAir) {
blockSource->setExtraBlock(pos, *exblock, 16 + updateArg);
}
} else {
blockSource->setExtraBlock(pos, *StaticVanillaBlocks::mFlowingWater, 16 + updateArg);
if (updateExArg % 2 == 1) {
blockSource->setBlock(pos, *block, updateArg, nullptr, nullptr);
} else {
blockSource->setBlockNoUpdate(pos.x, pos.y, pos.z, *block);
}
}
return true;
return setBlockWithoutcheckGMask(blockSource, pos, block, exblock);
}

Clipboard* PlayerData::getNextHistory() {
Expand Down
27 changes: 12 additions & 15 deletions core/data/PlayerData.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace worldedit {
class PlayerData {
public:
std::string xuid="";
std::string xuid = "";
int maxHistoryLength = 20;
int updateArg = 2;
int updateExArg = 1;
Expand Down Expand Up @@ -39,20 +39,17 @@ namespace worldedit {
std::pair<class Clipboard*, int> getRedoHistory();
bool changeMainPos(BlockInstance blockInstance, bool output = true);
bool changeVicePos(BlockInstance blockInstance, bool output = true);
void setVarByPlayer(
std::unordered_map<::std::string, double>& variables);
bool setBlockSimple(
class BlockSource* blockSource,
class EvalFunctions& funcs,
std::unordered_map<std::string, double> const& var,
const BlockPos& pos,
class Block* block = const_cast<Block*>(BedrockBlocks::mAir),
class Block* exblock = const_cast<Block*>(BedrockBlocks::mAir));
bool setBlockForHistory(
class BlockSource* blockSource,
const BlockPos& pos,
class Block* block ,
class Block* exblock);
void setVarByPlayer(std::unordered_map<::std::string, double>& variables);
bool setBlockSimple(class BlockSource* blockSource,
class EvalFunctions& funcs,
std::unordered_map<std::string, double> const& var,
const BlockPos& pos,
class Block* block = const_cast<Block*>(BedrockBlocks::mAir),
class Block* exblock = const_cast<Block*>(BedrockBlocks::mAir));
bool setBlockWithoutcheckGMask(class BlockSource* blockSource,
const BlockPos& pos,
class Block* block,
class Block* exblock);
~PlayerData();
};

Expand Down
21 changes: 16 additions & 5 deletions core/store/BlockListPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "BlockNBTSet.hpp"
#include "mc/BlockPalette.hpp"
#include <mc/LevelChunk.hpp>
#include "mc/Level.hpp"
#include "utils/StringHelper.h"
#include <mc/Block.hpp>
Expand Down Expand Up @@ -100,15 +101,25 @@ namespace worldedit {
return false;
}
auto* block = rawBlock->getBlock(variables, funcs);
playerData->setBlockSimple(blockSource, funcs, variables, pos, block, rawBlock->exBlock);
bool res = playerData->setBlockSimple(blockSource, funcs, variables, pos, block, rawBlock->exBlock);

if (rawBlock->hasBE && block->hasBlockEntity()) {
if (rawBlock->hasBE && block->hasBlockEntity() && rawBlock->blockEntity != "") {
auto be = blockSource->getBlockEntity(pos);
if (be != nullptr && rawBlock->blockEntity != "") {
be->setNbt(CompoundTag::fromBinaryNBT(rawBlock->blockEntity).get());
if (be != nullptr) {
return be->setNbt(CompoundTag::fromBinaryNBT(rawBlock->blockEntity).get());
} else {
LevelChunk* chunk = blockSource->getChunkAt(pos);
void* vtbl = dlsym("??_7DefaultDataLoadHelper@@6B@");
auto b =
BlockActor::loadStatic(*Global<Level>, *CompoundTag::fromBinaryNBT(rawBlock->blockEntity).get(),
(class DataLoadHelper&)vtbl);
if (b != nullptr) {
b->moveTo(pos);
chunk->_placeBlockEntity(b);
}
}
}
return true;
return res;
}

BlockListPattern::BlockListPattern(std::string str, std::string xuid) : Pattern(xuid) {
Expand Down
Loading

0 comments on commit 250a21b

Please sign in to comment.