From 5d9a5e475c29ff6ffab995f53911d976db5ed4e3 Mon Sep 17 00:00:00 2001 From: kuangby <3091240752@qq.com> Date: Fri, 22 Aug 2025 13:11:39 +0800 Subject: [PATCH 01/45] refraction --- src/cfsp/commands/Command.h | 9 - src/cfsp/commands/Sp.cpp | 1257 ----------------- src/cfsp/core/simPlayer/SimPlayer.cpp | 7 + src/cfsp/core/simPlayer/SimPlayer.h | 39 + src/cfsp/fix/FeatureFix.cpp | 205 --- src/cfsp/fix/FeatureFix.h | 3 - src/cfsp/gui/FormPacketHelper.cpp | 198 --- src/cfsp/gui/FormPacketHelper.h | 28 - src/cfsp/gui/FormUI.cpp | 433 ------ src/cfsp/gui/FormUI.h | 329 ----- src/cfsp/gui/GuiForm.cpp | 1500 --------------------- src/cfsp/gui/GuiForm.h | 13 - src/cfsp/simplayer/CFSP.h | 792 ----------- src/cfsp/simplayer/Hooks.h | 5 - src/cfsp/simplayer/SimPlayer.cpp | 1069 --------------- src/cfsp/simplayer/luaapi/BlockInfo.cpp | 295 ---- src/cfsp/simplayer/luaapi/BlockInfo.h | 143 -- src/cfsp/simplayer/luaapi/BlockPos.cpp | 204 --- src/cfsp/simplayer/luaapi/BlockPos.h | 52 - src/cfsp/simplayer/luaapi/BlockSource.cpp | 64 - src/cfsp/simplayer/luaapi/BlockSource.h | 24 - src/cfsp/simplayer/luaapi/ItemInfo.cpp | 363 ----- src/cfsp/simplayer/luaapi/ItemInfo.h | 171 --- src/cfsp/simplayer/luaapi/Level.cpp | 90 -- src/cfsp/simplayer/luaapi/Level.h | 30 - src/cfsp/simplayer/luaapi/Log.cpp | 26 - src/cfsp/simplayer/luaapi/Log.h | 15 - src/cfsp/simplayer/luaapi/SimPlayer.cpp | 725 ---------- src/cfsp/simplayer/luaapi/SimPlayer.h | 98 -- src/cfsp/simplayer/luaapi/SpLuaApi.cpp | 157 --- src/cfsp/simplayer/luaapi/SpLuaApi.h | 23 - src/cfsp/simplayer/luaapi/Utils.cpp | 104 -- src/cfsp/simplayer/luaapi/Utils.h | 22 - src/cfsp/simplayer/luaapi/Vec2.cpp | 212 --- src/cfsp/simplayer/luaapi/Vec2.h | 56 - src/cfsp/simplayer/luaapi/Vec3.cpp | 239 ---- src/cfsp/simplayer/luaapi/Vec3.h | 62 - xmake.lua | 2 +- 38 files changed, 47 insertions(+), 9017 deletions(-) delete mode 100644 src/cfsp/commands/Command.h delete mode 100644 src/cfsp/commands/Sp.cpp create mode 100644 src/cfsp/core/simPlayer/SimPlayer.cpp create mode 100644 src/cfsp/core/simPlayer/SimPlayer.h delete mode 100644 src/cfsp/fix/FeatureFix.cpp delete mode 100644 src/cfsp/fix/FeatureFix.h delete mode 100644 src/cfsp/gui/FormPacketHelper.cpp delete mode 100644 src/cfsp/gui/FormPacketHelper.h delete mode 100644 src/cfsp/gui/FormUI.cpp delete mode 100644 src/cfsp/gui/FormUI.h delete mode 100644 src/cfsp/gui/GuiForm.cpp delete mode 100644 src/cfsp/gui/GuiForm.h delete mode 100644 src/cfsp/simplayer/CFSP.h delete mode 100644 src/cfsp/simplayer/Hooks.h delete mode 100644 src/cfsp/simplayer/SimPlayer.cpp delete mode 100644 src/cfsp/simplayer/luaapi/BlockInfo.cpp delete mode 100644 src/cfsp/simplayer/luaapi/BlockInfo.h delete mode 100644 src/cfsp/simplayer/luaapi/BlockPos.cpp delete mode 100644 src/cfsp/simplayer/luaapi/BlockPos.h delete mode 100644 src/cfsp/simplayer/luaapi/BlockSource.cpp delete mode 100644 src/cfsp/simplayer/luaapi/BlockSource.h delete mode 100644 src/cfsp/simplayer/luaapi/ItemInfo.cpp delete mode 100644 src/cfsp/simplayer/luaapi/ItemInfo.h delete mode 100644 src/cfsp/simplayer/luaapi/Level.cpp delete mode 100644 src/cfsp/simplayer/luaapi/Level.h delete mode 100644 src/cfsp/simplayer/luaapi/Log.cpp delete mode 100644 src/cfsp/simplayer/luaapi/Log.h delete mode 100644 src/cfsp/simplayer/luaapi/SimPlayer.cpp delete mode 100644 src/cfsp/simplayer/luaapi/SimPlayer.h delete mode 100644 src/cfsp/simplayer/luaapi/SpLuaApi.cpp delete mode 100644 src/cfsp/simplayer/luaapi/SpLuaApi.h delete mode 100644 src/cfsp/simplayer/luaapi/Utils.cpp delete mode 100644 src/cfsp/simplayer/luaapi/Utils.h delete mode 100644 src/cfsp/simplayer/luaapi/Vec2.cpp delete mode 100644 src/cfsp/simplayer/luaapi/Vec2.h delete mode 100644 src/cfsp/simplayer/luaapi/Vec3.cpp delete mode 100644 src/cfsp/simplayer/luaapi/Vec3.h diff --git a/src/cfsp/commands/Command.h b/src/cfsp/commands/Command.h deleted file mode 100644 index fad500d..0000000 --- a/src/cfsp/commands/Command.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "mc/server/commands/CommandPermissionLevel.h" - -namespace coral_fans::cfsp::commands { - -void registerSpCommand(CommandPermissionLevel); - -} \ No newline at end of file diff --git a/src/cfsp/commands/Sp.cpp b/src/cfsp/commands/Sp.cpp deleted file mode 100644 index 16abe00..0000000 --- a/src/cfsp/commands/Sp.cpp +++ /dev/null @@ -1,1257 +0,0 @@ -#include "cfsp/Config.h" -#include "cfsp/base/Macros.h" -#include "cfsp/base/Mod.h" -#include "cfsp/gui/GuiForm.h" -#include "cfsp/simplayer/CFSP.h" -#include "ll/api/command/CommandHandle.h" -#include "ll/api/command/CommandRegistrar.h" -#include "ll/api/command/runtime/ParamKind.h" -#include "ll/api/command/runtime/RuntimeCommand.h" -#include "ll/api/command/runtime/RuntimeOverload.h" -#include "ll/api/i18n/I18n.h" -#include "mc/server/commands/CommandOrigin.h" -#include "mc/server/commands/CommandOutput.h" -#include "mc/server/commands/CommandVersion.h" -#include "mc/world/level/dimension/Dimension.h" -#include "mc/world/phys/HitResultType.h" -#include -#include -#include -#include -#include - - -namespace { - -inline void regSubCmd( - ll::command::CommandHandle& cmd, - std::string const& tag, - std::span> const& rArgs, - std::span> const& oArgs, - std::function(Player*, ll::command::RuntimeCommand const&)> spFn, - std::function(Player*, ll::command::RuntimeCommand const&)> gFn -) { - using ll::i18n_literals::operator""_tr; - auto ro1 = std::make_unique(std::move( - cmd.runtimeOverload().text("p").required("name", ll::command::ParamKind::SoftEnum, "spname").text(tag) - )); - auto ro2 = std::make_unique( - std::move(cmd.runtimeOverload().text("g").required("name", ll::command::ParamKind::SoftEnum, "gname").text(tag)) - ); - for (const auto& i : rArgs) { - ro1 = std::make_unique(std::move(ro1->required(i.first, i.second))); - ro2 = std::make_unique(std::move(ro2->required(i.first, i.second))); - } - for (const auto& i : oArgs) { - ro1 = std::make_unique(std::move(ro1->optional(i.first, i.second))); - ro2 = std::make_unique(std::move(ro2->optional(i.first, i.second))); - } - ro1->execute([spFn](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = spFn(player, self); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - ro2->execute([gFn](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = gFn(player, self); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); -} - -inline void regSubCmd( - ll::command::CommandHandle& cmd, - std::string const& tag, - std::span> const& rArgs, - std::span> const& oArgs, - std::function(CommandOrigin const&, ll::command::RuntimeCommand const&)> spFn, - std::function(CommandOrigin const&, ll::command::RuntimeCommand const&)> gFn -) { - using ll::i18n_literals::operator""_tr; - auto ro1 = std::make_unique(std::move( - cmd.runtimeOverload().text("p").required("name", ll::command::ParamKind::SoftEnum, "spname").text(tag) - )); - auto ro2 = std::make_unique( - std::move(cmd.runtimeOverload().text("g").required("name", ll::command::ParamKind::SoftEnum, "gname").text(tag)) - ); - for (const auto& i : rArgs) { - ro1 = std::make_unique(std::move(ro1->required(i.first, i.second))); - ro2 = std::make_unique(std::move(ro2->required(i.first, i.second))); - } - for (const auto& i : oArgs) { - ro1 = std::make_unique(std::move(ro1->optional(i.first, i.second))); - ro2 = std::make_unique(std::move(ro2->optional(i.first, i.second))); - } - ro1->execute([spFn](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = spFn(origin, self); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - ro2->execute([gFn](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = gFn(origin, self); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); -} - -inline void regSubCmd2( - ll::command::CommandHandle& cmd, - std::string const& tag, - std::span> const& rArgs, - std::span> const& oArgs, - std::function(Player*, ll::command::RuntimeCommand const&)> spFn, - std::function(Player*, ll::command::RuntimeCommand const&)> gFn -) { - using ll::i18n_literals::operator""_tr; - auto ro1 = std::make_unique(std::move( - cmd.runtimeOverload().text("p").required("name", ll::command::ParamKind::SoftEnum, "spname").text(tag) - )); - auto ro2 = std::make_unique( - std::move(cmd.runtimeOverload().text("g").required("name", ll::command::ParamKind::SoftEnum, "gname").text(tag)) - ); - for (const auto& i : rArgs) { - ro1 = std::make_unique(std::move(ro1->required(i.first, i.second))); - ro2 = std::make_unique(std::move(ro2->required(i.first, i.second))); - } - for (const auto& i : oArgs) { - ro1 = std::make_unique(std::move(ro1->optional(i.first, i.second))); - ro2 = std::make_unique(std::move(ro2->optional(i.first, i.second))); - } - ro1->execute([spFn](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - Player* player; - if (entity == nullptr) player = nullptr; - else if (!entity->isType(ActorType ::Player)) { - output.error("command.sp.error.onlyplayer"_tr()); - return; - } else player = static_cast(entity); - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = spFn(player, self); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - ro2->execute([gFn](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - Player* player; - if (entity == nullptr) player = nullptr; - else if (!entity->isType(ActorType ::Player)) { - output.error("command.sp.error.onlyplayer"_tr()); - return; - } else player = static_cast(entity); - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = gFn(player, self); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); -} -} // namespace - -namespace coral_fans::cfsp::commands { - -void registerSpCommand(CommandPermissionLevel permission) { - using ll::i18n_literals::operator""_tr; - - // reg cmd - auto& spCommand = ll::command::CommandRegistrar::getInstance() - .getOrCreateCommand("sp", "command.sp.description"_tr(), permission); - - // reg softenum - ll::command::CommandRegistrar::getInstance().tryRegisterSoftEnum("spname", {}); - ll::command::CommandRegistrar::getInstance().tryRegisterSoftEnum("gname", {}); - - // sp version - spCommand.overload().text("version").execute([](CommandOrigin const&, CommandOutput& output) { -#ifdef VERSION - output.success(VERSION); -#endif -#ifdef COMMITID - output.success("Commit ID: {}", COMMITID); -#endif - output.success("SimPlayerManager Version: {}\n - SimPlayerInfo Version: {}", MANAGER_VERSION, INFO_VERSION); - }); - - // sp - spCommand.overload().execute([](CommandOrigin const& origin, CommandOutput& output) { - COMMAND_CHECK_PLAYER - if (player->getCommandPermissionLevel() >= mod().getConfig().simPlayer.adminPermission - || mod().getConfig().simPlayer.superManagerList.contains(*player->mName)) - coral_fans::cfsp::gui::sendManagerMainMenu(player); - else { - auto grouplist = SimPlayerManager::getInstance().fetchGroupList(player); - if (grouplist.size()) coral_fans::cfsp::gui::sendMainMenu(player); - else coral_fans::cfsp::gui::sendSplist(player); - } - }); - - // sp p - spCommand.runtimeOverload() - .text("p") - .optional("name", ll::command::ParamKind::SoftEnum, "spname") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - if (self["name"].has_value()) { - auto tem = - SimPlayerManager::getInstance().fetchSimPlayer(self["name"].get() - ); - if (tem.has_value()) { - std::string UUID = player->getUuid().asString(); - if (player->getCommandPermissionLevel() >= mod().getConfig().simPlayer.adminPermission - || mod().getConfig().simPlayer.superManagerList.contains(*player->mName) - || tem.value()->ownerUuid == UUID) - coral_fans::cfsp::gui::sendSpOperatorList(player, tem.value()); - else return output.error("sommand.sp.error.permissiondenied"_tr()); - } else return output.error("sommand.sp.error.spnofind"_tr()); - } else coral_fans::cfsp::gui::sendSplist(player); - return output.success("command.sp.success"_tr()); - }); - - // sp g - spCommand.runtimeOverload() - .text("g") - .optional("name", ll::command::ParamKind::SoftEnum, "gname") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - if (self["name"].has_value()) { - auto tem = - SimPlayerManager::getInstance().fetchGroup(self["name"].get()); - if (tem.has_value()) { - std::string UUID = player->getUuid().asString(); - if (player->getCommandPermissionLevel() >= mod().getConfig().simPlayer.adminPermission - || mod().getConfig().simPlayer.superManagerList.contains(*player->mName) - || tem.value()->owner == UUID || tem.value()->admin.contains(UUID)) - coral_fans::cfsp::gui::sendGroupOperatorList(player, tem.value()); - else return output.error("sommand.sp.error.permissiondenied"_tr()); - } else return output.error("sommand.sp.error.groupnofind"_tr()); - } else coral_fans::cfsp::gui::sendGroupList(player); - return output.success("command.sp.success"_tr()); - }); - - // sp c autorespawn - spCommand.runtimeOverload() - .text("c") - .text("autorespawn") - .required("isopen", ll::command::ParamKind::Bool) - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - auto& mod = coral_fans::cfsp::mod(); - if (origin.getPermissionsLevel() >= mod.getConfig().simPlayer.adminPermission) { - SimPlayerManager::getInstance().setAutoRespawn(self["isopen"].get()); - return output.success("command.sp.success"_tr()); - } else { - auto* entity = origin.getEntity(); - if (entity != nullptr || entity->isType(ActorType::Player)) { - auto* player = static_cast(entity); - if (mod.getConfig().simPlayer.superManagerList.contains(*player->mName)) { - SimPlayerManager::getInstance().setAutoRespawn(self["isopen"].get( - )); - return output.success("command.sp.success"_tr()); - } - } - } - output.error("command.sp.error.permissiondenied"_tr()); - }); - - // sp c autojoin - spCommand.runtimeOverload() - .text("c") - .text("autojoin") - .required("isopen", ll::command::ParamKind::Bool) - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - auto& mod = coral_fans::cfsp::mod(); - if (origin.getPermissionsLevel() >= mod.getConfig().simPlayer.adminPermission) { - SimPlayerManager::getInstance().setAutoJoin(self["isopen"].get()); - return output.success("command.sp.success"_tr()); - } else { - auto* entity = origin.getEntity(); - if (entity != nullptr || entity->isType(ActorType::Player)) { - auto* player = static_cast(entity); - if (mod.getConfig().simPlayer.superManagerList.contains(*player->mName)) { - SimPlayerManager::getInstance().setAutoJoin(self["isopen"].get()); - return output.success("command.sp.success"_tr()); - } - } - } - output.error("command.sp.error.permissiondenied"_tr()); - }); - - // sp c autodespawn - spCommand.runtimeOverload() - .text("c") - .text("autodespawn") - .required("isopen", ll::command::ParamKind::Bool) - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - auto& mod = coral_fans::cfsp::mod(); - if (origin.getPermissionsLevel() >= mod.getConfig().simPlayer.adminPermission) { - SimPlayerManager::getInstance().setAutoDespawn(self["isopen"].get()); - return output.success("command.sp.success"_tr()); - } else { - auto* entity = origin.getEntity(); - if (entity != nullptr || entity->isType(ActorType::Player)) { - auto* player = static_cast(entity); - if (mod.getConfig().simPlayer.superManagerList.contains(*player->mName)) { - SimPlayerManager::getInstance().setAutoDespawn(self["isopen"].get( - )); - return output.success("command.sp.success"_tr()); - } - } - } - output.error("command.sp.error.permissiondenied"_tr()); - }); - - // sp list g - spCommand.runtimeOverload().text("list").text("g").execute( - [](CommandOrigin const&, CommandOutput& output, ll::command::RuntimeCommand const&) { - output.success(coral_fans::cfsp::SimPlayerManager::getInstance().listGroup()); - } - ); - - // sp list p - spCommand.runtimeOverload().text("list").text("p").execute( - [](CommandOrigin const&, CommandOutput& output, ll::command::RuntimeCommand const&) { - output.success(coral_fans::cfsp::SimPlayerManager::getInstance().listSimPlayer()); - } - ); - - // sp g create - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("create") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - if (!player->isSimulatedPlayer()) { - auto rst = SimPlayerManager::getInstance().createGroup( - player, - self["name"].get() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - } - }); - - // sp g delete - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("delete") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().deleteGroup( - player, - self["name"].get() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp g addsp - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("addsp") - .required("simplayer", ll::command::ParamKind::SoftEnum, "spname") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().addSpToGroup( - player, - self["name"].get(), - self["simplayer"].get() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp g rmsp - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("rmsp") - .required("simplayer", ll::command::ParamKind::SoftEnum, "spname") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().rmSpFromGroup( - player, - self["name"].get(), - self["simplayer"].get() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp g addadmin - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("addadmin") - .required("player", ll::command::ParamKind::Player) - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - - auto targetPlayer = self["player"].get().results(origin).data; - if (targetPlayer->size() > 1) return output.error("command.sp.error.toomanyobj"_tr()); - if (targetPlayer->front()->isSimulatedPlayer()) return output.error("command.sp.error.nosp"_tr()); - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().addAdminToGroup( - player, - self["name"].get(), - self["player"].get().results(origin).data->front() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp g rmadmin - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("rmadmin") - .required("player", ll::command::ParamKind::Player) - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto targetPlayer = self["player"].get().results(origin).data; - if (targetPlayer->size() != 1) return output.error("command.sp.error.toomanyobj"_tr()); - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().rmAdminFromGroup( - player, - self["name"].get(), - targetPlayer->front()->getUuid().asString() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp p spawn - spCommand.runtimeOverload() - .text("p") - .required("name", ll::command::ParamKind::SoftEnum, "spname") - .text("spawn") - .optional("pos", ll::command::ParamKind::Vec3) - .optional("dim", ll::command::ParamKind::Dimension) - .optional("rotx", ll::command::ParamKind::Float) - .optional("roty", ll::command::ParamKind::Float) - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - if (entity == nullptr) { - if (!self["pos"].has_value()) { - auto& name = self["name"].get(); - if (SimPlayerManager::getInstance().fetchSimPlayer(name).has_value()) { - SimPlayerManager::getInstance().spawnSimPlayer(nullptr, name, {}, 0, {}); - return; - } - } else if (self["dim"].has_value()) { - Vec2 rot; - auto& tem3 = self["rotx"]; - if (tem3.has_value()) { - rot.x = tem3.get(); - auto& tem4 = self["roty"]; - if (tem4.has_value()) rot.y = tem4.get(); - else rot.y = 0; - } else rot = Vec2(0, 0); - auto rst = SimPlayerManager::getInstance().spawnSimPlayer( - nullptr, - self["name"].get(), - self["pos"] - .get() - .getPosition(CommandVersion::CurrentVersion(), origin, {0, 0, 0}), - self["dim"].get().id, - rot - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - return; - } - output.error("command.sp.error.paraerror"_tr()); - return; - } else if (!entity->isType(ActorType ::Player)) { - output.error("command.sp.error.onlyplayer"_tr()); - return; - } - auto* player = static_cast(entity); - COMMAND_SIMPLAYER_CHECKPERMLIST - Vec3 pos; - int dim; - Vec2 rot; - auto& tem1 = self["pos"]; - if (tem1.has_value()) { - pos = tem1.get() - .getPosition(CommandVersion::CurrentVersion(), origin, {0, 0, 0}); - auto& tem2 = self["dim"]; - if (tem2.has_value()) { - dim = tem2.get().id; - auto& tem3 = self["rotx"]; - if (tem3.has_value()) { - rot.x = tem3.get(); - auto& tem4 = self["roty"]; - if (tem4.has_value()) rot.y = tem4.get(); - else rot.y = 0; - } else rot = *player->mBuiltInComponents->mActorRotationComponent->mRotationDegree; - } else { - dim = player->getDimensionId(); - rot = *player->mBuiltInComponents->mActorRotationComponent->mRotationDegree; - } - } else { - const auto& hit = player->traceRay(5.25f); - if (hit.mType == HitResultType::Entity) pos = hit.getEntity()->getFeetPos(); - else if (hit.mType == HitResultType::Tile) pos = hit.mPos; - else pos = player->getFeetPos(); - dim = player->getDimensionId(); - rot = *player->mBuiltInComponents->mActorRotationComponent->mRotationDegree; - } - - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance() - .spawnSimPlayer(player, self["name"].get(), pos, dim, rot); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp g spawn - spCommand.runtimeOverload() - .text("g") - .required("name", ll::command::ParamKind::SoftEnum, "gname") - .text("spawn") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().spawnGroup( - player, - self["name"].get() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - - // sp p sneaking - spCommand.runtimeOverload() - .text("p") - .required("name", ll::command::ParamKind::SoftEnum, "spname") - .text("sneaking") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerSneaking(player, self["name"].get(), false); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp p swimming - spCommand.runtimeOverload() - .text("p") - .required("name", ll::command::ParamKind::SoftEnum, "spname") - .text("swimming") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerSwimming(player, self["name"].get(), false); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp p flying - spCommand.runtimeOverload() - .text("p") - .required("name", ll::command::ParamKind::SoftEnum, "spname") - .text("flying") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerFlying(player, self["name"].get(), false); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - // sp p sprinting - spCommand.runtimeOverload() - .text("p") - .required("name", ll::command::ParamKind::SoftEnum, "spname") - .text("sprinting") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerSprinting(player, self["name"].get(), false); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - ::regSubCmd2( - spCommand, - "despawn", - {}, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance() - .despawnSimPlayer(player, self["name"].get(), false); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().despawnGroup( - player, - self["name"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "rm", - {}, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance() - .rmSimPlayer(player, self["name"].get(), false); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().rmGroup( - player, - self["name"].get() - ); - } - ); - - ::regSubCmd2( - spCommand, - "respawn", - {}, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance() - .respawnSimPlayer(player, self["name"].get(), false); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().respawnGroup( - player, - self["name"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "stop", - {}, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerStop(player, self["name"].get(), false); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupStop( - player, - self["name"].get() - ); - } - ); - - std::array, 1> enableArg{ - std::make_pair("enable", ll::command::ParamKind::Bool) - }; - - ::regSubCmd( - spCommand, - "sneaking", - enableArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerSneaking( - player, - self["name"].get(), - false, - self["enable"].get() - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupSneaking( - player, - self["name"].get(), - self["enable"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "swimming", - enableArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerSwimming( - player, - self["name"].get(), - false, - self["enable"].get() - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupSwimming( - player, - self["name"].get(), - self["enable"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "flying", - enableArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerFlying( - player, - self["name"].get(), - false, - self["enable"].get() - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupFlying( - player, - self["name"].get(), - self["enable"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "sprinting", - enableArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerSprinting( - player, - self["name"].get(), - false, - self["enable"].get() - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupSprinting( - player, - self["name"].get(), - self["enable"].get() - ); - } - ); - - std::array, 2> taskArg{ - std::make_pair("interval", ll::command::ParamKind::Int), - std::make_pair("times", ll::command::ParamKind::Int) - }; - - ::regSubCmd( - spCommand, - "attack", - {}, - taskArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerAttack( - player, - self["name"].get(), - false, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupAttack( - player, - self["name"].get(), - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - } - ); - - std::array, 1> strArg{ - std::make_pair("str", ll::command::ParamKind::String) - }; - - ::regSubCmd( - spCommand, - "chat", - strArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerChat( - player, - self["name"].get(), - false, - self["str"].get() - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupChat( - player, - self["name"].get(), - self["str"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "destroy", - {}, - taskArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerDestroy( - player, - self["name"].get(), - false, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupDestroy( - player, - self["name"].get(), - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - } - ); - - ::regSubCmd( - spCommand, - "drop", - {}, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerDropSelectedItem(player, self["name"].get(), false); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupDropSelectedItem( - player, - self["name"].get() - ); - } - ); - - ::regSubCmd( - spCommand, - "dropinv", - {}, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerDropInv(player, self["name"].get(), false); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupDropInv( - player, - self["name"].get() - ); - } - ); - - spCommand.runtimeOverload() - .text("p") - .required("name", ll::command::ParamKind::SoftEnum, "spname") - .text("swap") - .execute([](CommandOrigin const& origin, CommandOutput& output, ll::command::RuntimeCommand const& self) { - COMMAND_CHECK_PLAYER - COMMAND_SIMPLAYER_CHECKPERMLIST - auto rst = coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerSwap( - player, - self["name"].get() - ); - if (rst.second) output.success(rst.first); - else output.error(rst.first); - }); - - ::regSubCmd( - spCommand, - "runcmd", - strArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerRunCmd( - player, - self["name"].get(), - false, - self["str"].get() - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupRunCmd( - player, - self["name"].get(), - self["str"].get() - ); - } - ); - - std::array, 1> itemArg{ - std::make_pair("item", ll::command::ParamKind::Item) - }; - - ::regSubCmd( - spCommand, - "select", - itemArg, - {}, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerSelect( - player, - self["name"].get(), - false, - self["item"].get().mId - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupSelect( - player, - self["name"].get(), - self["item"].get().mId - ); - } - ); - - ::regSubCmd( - spCommand, - "interact", - {}, - taskArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerInteract( - player, - self["name"].get(), - false, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupInteract( - player, - self["name"].get(), - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - } - ); - - ::regSubCmd( - spCommand, - "jump", - {}, - taskArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerJump( - player, - self["name"].get(), - false, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupJump( - player, - self["name"].get(), - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - } - ); - - std::array, 3> useTaskArg{ - std::make_pair("tick", ll::command::ParamKind::Int), - std::make_pair("interval", ll::command::ParamKind::Int), - std::make_pair("times", ll::command::ParamKind::Int) - }; - - ::regSubCmd( - spCommand, - "use", - {}, - useTaskArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerUse( - player, - self["name"].get(), - false, - self["tick"].has_value() ? self["tick"].get() : 10, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupUse( - player, - self["name"].get(), - self["tick"].has_value() ? self["tick"].get() : 10, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - } - ); - - ::regSubCmd( - spCommand, - "build", - {}, - taskArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerBuild( - player, - self["name"].get(), - false, - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupBuild( - player, - self["name"].get(), - self["interval"].has_value() ? self["interval"].get() : 20, - self["times"].has_value() ? self["times"].get() : 1 - ); - } - ); - - std::array, 1> posArg{ - std::make_pair("pos", ll::command::ParamKind::Vec3) - }; - - ::regSubCmd( - spCommand, - "lookat", - {}, - posArg, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f); - if (hit.mType == HitResultType::Entity) pos = hit.getEntity()->getPosition(); - else if (hit.mType == HitResultType::Tile) pos = hit.mPos; - else pos = player->getFeetPos(); - } - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerLookAt(player, self["name"].get(), false, pos); - }, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f); - if (hit.mType == HitResultType::Entity) pos = hit.getEntity()->getPosition(); - else if (hit.mType == HitResultType::Tile) pos = hit.mPos; - else pos = player->getPosition(); - } - return coral_fans::cfsp::SimPlayerManager::getInstance() - .groupLookAt(player, self["name"].get(), pos); - } - ); - - std::array, 2> posArgWithDim{ - std::make_pair("pos", ll::command::ParamKind::Vec3), - std::make_pair("dim", ll::command::ParamKind::Dimension) - }; - - if (mod().getConfig().simPlayer.allowTp) - ::regSubCmd( - spCommand, - "tp", - {}, - posArgWithDim, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - int dimId; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f); - if (hit.mType == HitResultType::Entity) pos = hit.getEntity()->getFeetPos(); - else if (hit.mType == HitResultType::Tile) pos = hit.mPos; - else pos = player->getFeetPos(); - } - if (self["dim"].has_value()) dimId = self["dim"].get().id; - else dimId = player->getDimensionId(); - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerTp(player, self["name"].get(), false, pos, dimId); - }, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - int dimId; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f); - if (hit.mType == HitResultType::Entity) pos = hit.getEntity()->getFeetPos(); - else if (hit.mType == HitResultType::Tile) pos = hit.mPos; - else pos = player->getFeetPos(); - } - if (self["dim"].has_value()) dimId = self["dim"].get().id; - else dimId = player->getDimensionId(); - return coral_fans::cfsp::SimPlayerManager::getInstance() - .groupTp(player, self["name"].get(), pos, dimId); - } - ); - - ::regSubCmd( - spCommand, - "moveto", - {}, - posArg, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f, false, true); - if (hit) pos = hit.mPos; - else pos = player->getFeetPos(); - } - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerMoveTo(player, self["name"].get(), false, pos); - }, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f, false, true); - if (hit) pos = hit.mPos; - else pos = player->getFeetPos(); - } - return coral_fans::cfsp::SimPlayerManager::getInstance() - .groupMoveTo(player, self["name"].get(), pos); - } - ); - - ::regSubCmd( - spCommand, - "navto", - {}, - posArg, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f, false, true); - if (hit) pos = hit.mPos; - else pos = player->getFeetPos(); - } - return coral_fans::cfsp::SimPlayerManager::getInstance() - .simPlayerNavTo(player, self["name"].get(), false, pos); - }, - [](CommandOrigin const& origin, ll::command::RuntimeCommand const& self) { - auto* entity = origin.getEntity(); - auto* player = static_cast(entity); - Vec3 pos; - if (self["pos"].has_value()) - pos = self["pos"].get().getPosition( - CommandVersion::CurrentVersion(), - origin, - {0, 0, 0} - ); - else { - const auto& hit = player->traceRay(5.25f, false, true); - if (hit) pos = hit.mPos; - else pos = player->getFeetPos(); - } - return coral_fans::cfsp::SimPlayerManager::getInstance() - .groupNavTo(player, self["name"].get(), pos); - } - ); - - std::array, 1> pathArg{ - std::make_pair("path", ll::command::ParamKind::FilePath) - }; - std::array, 2> intervalArgArg{ - std::make_pair("interval", ll::command::ParamKind::Int), - std::make_pair("arg", ll::command::ParamKind::RawText) - }; - - ::regSubCmd( - spCommand, - "script", - pathArg, - intervalArgArg, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().simPlayerScript( - player, - self["name"].get(), - false, - self["path"].get().mText, - self["interval"].has_value() ? self["interval"].get() : 20, - self["arg"].has_value() ? self["arg"].get().mText : "" - ); - }, - [](Player* player, ll::command::RuntimeCommand const& self) { - return coral_fans::cfsp::SimPlayerManager::getInstance().groupScript( - player, - self["name"].get(), - self["path"].get().mText, - self["interval"].has_value() ? self["interval"].get() : 20, - self["arg"].has_value() ? self["arg"].get().mText : "" - ); - } - ); -} - -} // namespace coral_fans::cfsp::commands \ No newline at end of file diff --git a/src/cfsp/core/simPlayer/SimPlayer.cpp b/src/cfsp/core/simPlayer/SimPlayer.cpp new file mode 100644 index 0000000..6689f1a --- /dev/null +++ b/src/cfsp/core/simPlayer/SimPlayer.cpp @@ -0,0 +1,7 @@ +#include "SimPlayer.h" + +namespace coral_fans::cfsp::simulated_player { +inline std::string SimPlayer::getName() { return this->name; } +inline std::string SimPlayer::getXuid() { return this->xuid; } +inline int SimPlayer::getStatus() { return this->status; } +} // namespace coral_fans::cfsp::simulated_player \ No newline at end of file diff --git a/src/cfsp/core/simPlayer/SimPlayer.h b/src/cfsp/core/simPlayer/SimPlayer.h new file mode 100644 index 0000000..5879d9f --- /dev/null +++ b/src/cfsp/core/simPlayer/SimPlayer.h @@ -0,0 +1,39 @@ +#include "TimeWheel.h" +#include "cfsp/base/Macros.h" +#include "ll/api/base/StdInt.h" +#include "mc/deps/core/math/Vec2.h" +#include "mc/deps/core/math/Vec3.h" +#include "mc/server/SimulatedPlayer.h" +#include "string" +#include "unordered_set" + + +namespace coral_fans::cfsp::simulated_player { +class SimPlayer { +public: + std::string name; + int64 uid; + std::string xuid; + std::string ownerUuid; + std::string lastSpawner; + std::unordered_set groups; + int status; + Vec3 offlinePos; + int offlineDim; + Vec2 offlineRot; + std::string offlineGameType; + bool offlineEmptyInv; + SimulatedPlayer* simPlayer; // no-save + std::shared_ptr scheduler; // no-save + unsigned long long taskid; // no-save + unsigned long long scriptid; // no-save + std::vector autoDespawnCount; // no-save + unsigned long long autoDespawnI; // no-save + Vec3 lookatOffPos; // no-save + +public: + CFSP_API inline std::string getName(); + CFSP_API inline std::string getXuid(); + CFSP_API inline int getStatus(); +}; +} // namespace coral_fans::cfsp::simulated_player \ No newline at end of file diff --git a/src/cfsp/fix/FeatureFix.cpp b/src/cfsp/fix/FeatureFix.cpp deleted file mode 100644 index 5a47813..0000000 --- a/src/cfsp/fix/FeatureFix.cpp +++ /dev/null @@ -1,205 +0,0 @@ -#include -#include - -#include "cfsp/CFSP.h" -#include "mc/deps/core/math/Vec3.h" -#include "mc/network/LoopbackPacketSender.h" -#include "mc/network/MinecraftPacketIds.h" -#include "mc/network/ServerNetworkHandler.h" -#include "mc/network/packet/PlayStatusPacket.h" -#include "mc/network/packet/PlayerActionPacket.h" -#include "mc/network/packet/PlayerAuthInputPacket.h" -#include "mc/network/packet/RequestChunkRadiusPacket.h" -#include "mc/network/packet/RespawnPacket.h" -#include "mc/network/packet/ShowCreditsPacket.h" -#include "mc/server/SimulatedPlayer.h" -#include "mc/world/actor/ActorInitializationMethod.h" -#include "mc/world/actor/player/Player.h" -#include "mc/world/level/BlockPos.h" -#include "mc/world/level/BlockSource.h" -#include "mc/world/level/chunk/ChunkViewSource.h" -#include "mc/world/level/dimension/Dimension.h" -#include "mc/world/level/storage/DBStorage.h" - -#include "ll/api/base/StdInt.h" -#include "ll/api/chrono/GameChrono.h" -#include "ll/api/memory/Hook.h" -#include "ll/api/service/Bedrock.h" -#include "ll/api/thread/ServerThreadExecutor.h" - -namespace coral_fans::cfsp::fix { -template -void SimulateSendPacketToServer(SimulatedPlayer& sp, T& packet) { - packet.mClientSubId = sp.getClientSubId(); - DEBUGW("({})::send - {}", sp.getNameTag(), packetToDebugString(packet)); - ll::service::getServerNetworkHandler()->handle(sp.getNetworkIdentifier(), packet); -} -template -void SimulateSendPacketToServerAfter(SimulatedPlayer& sp, T&& packet, size_t delayTicks = 1) { - packet.mSenderSubId = sp.getClientSubId(); - // DEBUGW("({})::send - {}", sp.getNameTag(), packetToDebugString(packet)); - ll::thread::ServerThreadExecutor::getDefault().executeAfter( - [&nid = sp.getNetworkIdentifier(), packet = std::move(packet)]() { - ll::service::getServerNetworkHandler()->handle(nid, packet); - }, - ll::chrono::ticks{delayTicks} - ); -} - - -// ================= Fix chunk load ================= -// fix chunk load and tick - ChunkSource load mode -LL_TYPE_INSTANCE_HOOK( - LoadChunkFix_ChunkSource_LoadMode, - ll::memory::HookPriority::Normal, - SimulatedPlayer, - &SimulatedPlayer::$_createChunkSource, - ::std::shared_ptr<::ChunkViewSource>, - ::ChunkSource& mainChunkSource -) { - // if (FixManager::shouldFix(this)) { - // auto cs = origin( mainChunkSource); - // // ChunkSource::LoadMode : None(0) -> Deferred(1) - // cs->mParentLoadMode = ::ChunkSource::LoadMode::Deferred; - // return cs; - return this->ServerPlayer::$_createChunkSource(mainChunkSource); - // } - // return origin(mainChunkSource); -} - -// ================= Fix tick ================= -// fix chunk load and tick - _updateChunkPublisherView -LL_TYPE_INSTANCE_HOOK( - LoadChunkFix__updateChunkPublisherView, - ll::memory::HookPriority::Normal, - SimulatedPlayer, - &SimulatedPlayer::$tickWorld, - void, - ::Tick const& tick -) { - origin(tick); - // _updateChunkPublisherView will be called after Player::tick in ServerPlayer::tick - // if (FixManager::shouldFix(this)) { - // Force to call the implementation of ServerPlayer - // seem this only for tell client which chunk ready in server - this->ServerPlayer::$_updateChunkPublisherView(getPosition(), 16.0f); - // } -} - -// ================== Fix Travel ================== -// First change dimension from the end -LL_TYPE_INSTANCE_HOOK( - TravelFix_ShowCredits, - ll::memory::HookPriority::Normal, - SimulatedPlayer, - &SimulatedPlayer::$changeDimensionWithCredits, - void, - ::DimensionType dimension -) { - origin(dimension); - // if (FixManager::shouldFix(this)) { - // mHasSeenCredits = true; - ShowCreditsPacket packet{}; - packet.mPlayerID = getRuntimeID(); - packet.mCreditsState = ShowCreditsPacket::CreditsState::Finished; - SimulateSendPacketToServerAfter(*this, packet); - // } -} - -[[maybe_unused]] void -SimulateHandlePacketFromServer(SimulatedPlayer& sp, [[maybe_unused]] ShowCreditsPacket const& packet) { - // DEBUGW("({})::handle - {}", sp.getNameTag(), packetToDebugString(packet)); - ShowCreditsPacket res; - res.mPlayerID = sp.getRuntimeID(); - res.mCreditsState = ShowCreditsPacket::CreditsState::Finished; - SimulateSendPacketToServerAfter(sp, res, 1); - return; -} -// fix state when changing dimension - -// ================== Fix Initialized Spawn ================== -void SimulateHandlePacketFromServer(SimulatedPlayer& sp, [[maybe_unused]] PlayStatusPacket const& packet) { - // SpawnFix chunk radius - // DEBUGW("({})::handle - {}", sp.getNameTag(), packetToDebugString(packet)); - static int ChunkRadius = 5; - - RequestChunkRadiusPacket res; - res.mChunkRadius = ChunkRadius; - res.mMaxChunkRadius = static_cast(ChunkRadius); - - SimulateSendPacketToServerAfter(sp, res, 5); -} - -bool SimulateHandlePacketFromServer(NetworkIdentifier const& nid, Packet const& packet, SubClientId subId) { - auto sp = ll::service::getServerNetworkHandler()->_getServerPlayer(nid, subId); - // if (!FixManager::shouldFix(sp)) return false; - const auto packetId = packet.getId(); - switch (packetId) { - // case MinecraftPacketIds::Respawn: - // SimulateHandlePacketFromServer(*static_cast(sp), static_cast(packet)); break; - case MinecraftPacketIds::ShowCredits: - SimulateHandlePacketFromServer( - *static_cast(sp), - static_cast(packet) - ); - break; - case MinecraftPacketIds::PlayStatus: - SimulateHandlePacketFromServer( - *static_cast(sp), - static_cast(packet) - ); - break; - default: - break; - } - return true; -} - -// ================== Hook server outgoing packet ================== -LL_TYPE_INSTANCE_HOOK( - FixByPacketHook, - ll::memory::HookPriority::Normal, - LoopbackPacketSender, - &LoopbackPacketSender::$sendToClient, - void, - ::UserEntityIdentifierComponent const* userIdentifier, - ::Packet const& packet -) { - // TODO - if (userIdentifier->mNetworkId == NetworkIdentifier::INVALID_ID()) { - try { - [[maybe_unused]] auto handled = - SimulateHandlePacketFromServer(userIdentifier->mNetworkId, packet, userIdentifier->mClientSubId); - // if (handled) return; - } catch (...) { - // lfp::LeviFakePlayer::getLogger().error( - // "Error in handle packet for SubClient<{}>", - // (int)userIdentifier->mClientSubId - // ); - } - } - origin(std::forward<::UserEntityIdentifierComponent const*>(userIdentifier), std::forward<::Packet const&>(packet)); -}; - - -void featureFix(bool bl) { - if (bl) { - LoadChunkFix__updateChunkPublisherView::hook(); - LoadChunkFix_ChunkSource_LoadMode::hook(); - // RespawnFix_onPlayerDie::hook(); - TravelFix_ShowCredits::hook(); - // SpawnFix_Temp_initSpawnPos::hook(); - // SpawnFix_respawnPos::hook(); - FixByPacketHook::hook(); - } else { - LoadChunkFix__updateChunkPublisherView::unhook(); - LoadChunkFix_ChunkSource_LoadMode::unhook(); - // RespawnFix_onPlayerDie::unhook(); - TravelFix_ShowCredits::unhook(); - // SpawnFix_Temp_initSpawnPos::hook(); - // SpawnFix_respawnPos::hook(); - FixByPacketHook::unhook(); - } -} -} // namespace coral_fans::cfsp::fix \ No newline at end of file diff --git a/src/cfsp/fix/FeatureFix.h b/src/cfsp/fix/FeatureFix.h deleted file mode 100644 index b74c78e..0000000 --- a/src/cfsp/fix/FeatureFix.h +++ /dev/null @@ -1,3 +0,0 @@ -namespace coral_fans::cfsp::fix { -void featureFix(bool bl); -} \ No newline at end of file diff --git a/src/cfsp/gui/FormPacketHelper.cpp b/src/cfsp/gui/FormPacketHelper.cpp deleted file mode 100644 index f38b5ec..0000000 --- a/src/cfsp/gui/FormPacketHelper.cpp +++ /dev/null @@ -1,198 +0,0 @@ -// from https://github.com/LiteLDev/LegacyScriptEngine/blob/v0.10.6/src/legacy/legacyapi/form -#include "FormPacketHelper.h" -#include "FormUI.h" -#include "ll/api/form/FormIdManager.h" -#include "ll/api/memory/Hook.h" -#include "mc/network/PacketHandlerDispatcherInstance.h" -#include "mc/network/ServerNetworkHandler.h" -#include "mc/network/packet/ModalFormResponsePacket.h" -#include "mc/server/ServerPlayer.h" -#include "mc/world/actor/player/Player.h" - -#include - -namespace lse::form { - -//////////////////////////////// Data //////////////////////////////// - -enum class FormType { - SimpleFormBuilder, - ModalFormBuilder, - CustomFormBuilder, - SimpleFormPacket, - ModalFormPacket, - CustomFormPacket -}; - -std::unordered_map formTypes; - -std::unordered_map> simpleFormPacketCallbacks; -std::unordered_map> modalFormPacketCallbacks; -std::unordered_map> - customFormPacketCallbacks; - -std::unordered_map> simpleFormBuilders; -std::unordered_map> modalFormBuilders; -std::unordered_map> customFormBuilders; - -//////////////////////////////// Functions //////////////////////////////// - -unsigned NewFormId() { - unsigned formId; - do { - formId = ll::form::FormIdManager::genFormId(); - } while (formTypes.find(formId) != formTypes.end()); - return formId; -} - -void SetSimpleFormPacketCallback(unsigned formId, std::function callback) { - formTypes[formId] = FormType::SimpleFormPacket; - simpleFormPacketCallbacks[formId] = callback; -} - -void SetModalFormPacketCallback(unsigned formId, std::function callback) { - formTypes[formId] = FormType::ModalFormPacket; - modalFormPacketCallbacks[formId] = callback; -} - -void SetCustomFormPacketCallback( - unsigned formId, - std::function callback -) { - formTypes[formId] = FormType::CustomFormPacket; - customFormPacketCallbacks[formId] = callback; -} - -void SetSimpleFormBuilderData(unsigned formId, std::shared_ptr data) { - formTypes[formId] = FormType::SimpleFormBuilder; - simpleFormBuilders[formId] = data; -} - -void SetModalFormBuilderData(unsigned formId, std::shared_ptr data) { - formTypes[formId] = FormType::ModalFormBuilder; - modalFormBuilders[formId] = data; -} - -void SetCustomFormBuilderData(unsigned formId, std::shared_ptr data) { - formTypes[formId] = FormType::CustomFormBuilder; - customFormBuilders[formId] = data; -} - -void HandleFormPacket(Player* player, unsigned formId, const std::string& data, FormCancelReason reason) { - if (formTypes.find(formId) == formTypes.end()) return; - - if (formTypes[formId] == FormType::SimpleFormBuilder) { - int chosen = data != "null" ? stoi(data) : -1; - - // Simple Form Builder - auto form = simpleFormBuilders[formId]; - if (form->callback) form->callback(player, chosen, reason); - // Button Callback - if (chosen >= 0) { - if ((size_t)chosen >= form->elements.size()) return; - auto button = dynamic_pointer_cast