diff --git a/.gitignore b/.gitignore index d164656..5466d66 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,5 @@ version/* *.zip venv/ log/ -/vsbuild \ No newline at end of file +/vsbuild +/sym \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 32185c7..a2e1bed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,6 @@ add_library(${MOD_API_NAME} STATIC api/tools/MsgBuilder.cpp api/tools/ThreadPool.h api/lib/Remotery.c - api/world/LevelChunk.cpp api/language/I18nManager.cpp api/language/I18nManager.h api/tools/CastHelper.h @@ -65,7 +64,7 @@ target_link_libraries(${MOD_API_NAME} ${PROJECT_SOURCE_DIR}/api/lib/detours.lib) ####################这里是具体功能########################## #设置插版本 -set(TRAPDOOR_VERSION 0.9.72) +set(TRAPDOOR_VERSION 0.9.80) #设置游戏版本 set(MCBE_VERSION 1.16.40.2) #是否是测试版 diff --git a/api/block/BlockSource.cpp b/api/block/BlockSource.cpp index 25c2dab..a177897 100644 --- a/api/block/BlockSource.cpp +++ b/api/block/BlockSource.cpp @@ -6,7 +6,6 @@ #include "world/Biome.h" #include "lib/mod.h" #include "lib/SymHook.h" -#include "world/LevelChunk.h" namespace trapdoor { using namespace SymHook; diff --git a/api/world/Level.cpp b/api/world/Level.cpp index 6fe5932..71ebfc9 100644 --- a/api/world/Level.cpp +++ b/api/world/Level.cpp @@ -78,6 +78,13 @@ namespace trapdoor { return *SYM_CALL(uint64_t*(*)(Level * ), MSSYM_B1QE14getCurrentTickB1AA5LevelB2AAE12QEBAAEBUTickB2AAA2XZ, this); } + bool Level::noPlayerExists() { + int num = 0; + this->forEachPlayer([&num](Actor *actor){ + ++num; + printf("num is %d",num); + }); + return num==0; + } - -} + } diff --git a/api/world/Level.h b/api/world/Level.h index 97974b2..2cbe9e6 100644 --- a/api/world/Level.h +++ b/api/world/Level.h @@ -60,6 +60,8 @@ namespace trapdoor { uint64_t getGameTick(); + + bool noPlayerExists(); }; } diff --git a/api/world/LevelChunk.cpp b/api/world/LevelChunk.cpp deleted file mode 100644 index e560ee3..0000000 --- a/api/world/LevelChunk.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by xhy on 2020/11/9. -// - -#include "LevelChunk.h" diff --git a/api/world/LevelChunk.h b/api/world/LevelChunk.h deleted file mode 100644 index 0c54f1d..0000000 --- a/api/world/LevelChunk.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// Created by xhy on 2020/11/9. -// - -#ifndef TRAPDOOR_LEVELCHUNK_H -#define TRAPDOOR_LEVELCHUNK_H - -namespace trapdoor { - class LevelChunk { - - }; -} - - -#endif //TRAPDOOR_LEVELCHUNK_H diff --git a/changelog.md b/changelog.md index b53a922..7de298f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,6 @@ +## 1.16.4.02-0.9.80 +- 当服务求处于frozen状态且服务求内没有玩家的时候会自动切换到正常状态 +- 修复仙人掌可以转蛋糕的问题 ## 1.16.4.02-0.9.72 - 修复开启village v后击杀村民闪退的问题 - 修复假人连接占用cpu过高的问题 diff --git a/mod/fakePlayer/FakePlayerClient.cpp b/mod/fakePlayer/FakePlayerClient.cpp index c6e78e0..40972ee 100644 --- a/mod/fakePlayer/FakePlayerClient.cpp +++ b/mod/fakePlayer/FakePlayerClient.cpp @@ -11,169 +11,167 @@ namespace mod { - void FakePlayerClient::registerFakePlayerCommand(CommandManager &manager) { - using namespace trapdoor; - manager.registerCmd("fakeplayer", "command.fakeplayer.desc") - ->then(ARG("conn", "command.fakeplayer.conn.desc", STR, - { this->connect(player, holder->getString()); })) - ->then(ARG("c", "command.fakeplayer.c.desc", NONE, - { this->connect(player, ""); })) - ->then(ARG("list", "command.fakeplayer.list.desc", NONE, - { - this->sendMessage(player, FakePlayerClient::buildMessage( - MessageType::PLAYER_LIST)); - })) - ->then(ARG("add", "command.fakeplayer.add.desc", STR, - { - this->sendMessage(player, FakePlayerClient::buildMessage( - MessageType::ADD_PLAYER, - holder->getString())); - })) - ->then(ARG("rm", "command.fakeplayer.remove.desc", STR, - { - this->sendMessage(player, FakePlayerClient::buildMessage( - MessageType::REMOVE_PLAYER, - holder->getString())); - })) - ->then(ARG("tp", "command.fakeplayer.tp.desc", STR, - { this->tpFakePlayer(player, holder->getString()); })); - } +void FakePlayerClient::registerFakePlayerCommand(CommandManager &manager) { + using namespace trapdoor; + manager.registerCmd("fakeplayer", "command.fakeplayer.desc") + ->then(ARG("conn", "command.fakeplayer.conn.desc", STR, + { this->connect(player, holder->getString()); })) + ->then(ARG("c", "command.fakeplayer.c.desc", NONE, + { this->connect(player, ""); })) + ->then(ARG("list", "command.fakeplayer.list.desc", NONE, + { + this->sendMessage(player, FakePlayerClient::buildMessage( + MessageType::PLAYER_LIST)); + })) + ->then(ARG("add", "command.fakeplayer.add.desc", STR, + { + this->sendMessage(player, FakePlayerClient::buildMessage( + MessageType::ADD_PLAYER, + holder->getString())); + })) + ->then(ARG("rm", "command.fakeplayer.remove.desc", STR, + { + this->sendMessage(player, FakePlayerClient::buildMessage( + MessageType::REMOVE_PLAYER, + holder->getString())); + })) + ->then(ARG("tp", "command.fakeplayer.tp.desc", STR, + { this->tpFakePlayer(player, holder->getString()); })); +} //发送消息 - bool FakePlayerClient::sendMessage(trapdoor::Actor *player, - const std::string &msg) { - //如果可以发送消息就发送,不能发送就gg - if (!webSocket || - webSocket->getReadyState() == easywsclient::WebSocket::CLOSED) { - trapdoor::error(player, trapdoor::LANG("fp.error.noConnect")); - return false; - } - if (this->clientStatus != ClientStatus::READY) { - trapdoor::error(player, trapdoor::LANG("fp.error.status")); - } - this->webSocket->send(msg); - this->source = player; - this->clientStatus = ClientStatus::WAITING_MESSAGE; - return true; - } +bool FakePlayerClient::sendMessage(trapdoor::Actor *player, + const std::string &msg) { + //如果可以发送消息就发送,不能发送就gg + if (!this->checkConn()) { + trapdoor::error(player, trapdoor::LANG("fp.error.noConnect")); + return false; + } -//在单独的线程中来进行消息的收取 - void FakePlayerClient::run() { - this->pool->enqueue([&] { - //如果socket 是处于开启状态就一直监听作为事件循环 - while (this->webSocket && this->webSocket->getReadyState() != - easywsclient::WebSocket::CLOSED) { - this->webSocket->poll(50); - this->webSocket->dispatch([&](const std::string &msg) { - if (this->clientStatus == ClientStatus::WAITING_MESSAGE) { - //改变状态来通知消息到了 - this->clientStatus = ClientStatus::NEED_CONSUME; - this->message.set(msg); - } else { - //这里可能是有超时的消息,就不处理了,防止消息出现错乱 - //也就是丢弃超时的消息 - } - }); - } - this->disconnectCallBack(); - }); - } + if (this->clientStatus != ClientStatus::READY) { + trapdoor::error(player, trapdoor::LANG("fp.error.status")); + } + this->webSocket->send(msg); + this->source = player; + this->clientStatus = ClientStatus::WAITING_MESSAGE; + return true; +} - bool FakePlayerClient::consume() { - bool status = true; - auto msg = FakePlayerClient::parseResponse(this->message.get(), status); - //处理服务端的回复消息 - if (source) { - if (status) { - trapdoor::info(this->source, "%s", msg.c_str()); - } else { - trapdoor::error(this->source, "%s", msg.c_str()); - } +//在单独的线程中来进行消息的收取 +void FakePlayerClient::run() { + this->pool->enqueue([&] { + //如果socket 是处于开启状态就一直监听作为事件循环 + while (this->webSocket && this->webSocket->getReadyState() != + easywsclient::WebSocket::CLOSED) { + this->webSocket->poll(50); + this->webSocket->dispatch([&](const std::string &msg) { + if (this->clientStatus == ClientStatus::WAITING_MESSAGE) { + //改变状态来通知消息到了 + this->clientStatus = ClientStatus::NEED_CONSUME; + this->message.set(msg); } else { - trapdoor::broadcastMsg(trapdoor::LANG("fp.error.noSource"), - msg.c_str()); + //这里可能是有超时的消息,就不处理了,防止消息出现错乱 + //也就是丢弃超时的消息 } - return true; + }); } + this->disconnectCallBack(); + }); +} - void FakePlayerClient::connect(trapdoor::Actor *player, - const std::string &url) { +bool FakePlayerClient::consume() { + bool status = true; + auto msg = FakePlayerClient::parseResponse(this->message.get(), status); + //处理服务端的回复消息 + if (source) { + if (status) { + trapdoor::info(this->source, "%s", msg.c_str()); + } else { + trapdoor::error(this->source, "%s", msg.c_str()); + } + } else { + trapdoor::broadcastMsg(trapdoor::LANG("fp.error.noSource"), msg.c_str()); + } + return true; +} - if (this->webSocket && this->webSocket->getReadyState() == easywsclient::WebSocket::OPEN) { - trapdoor::warning(player, trapdoor::LANG("fp.error.exist")); - return; - } - if (this->webSocket) { - this->webSocket->close(); - } - delete this->webSocket; +void FakePlayerClient::connect(trapdoor::Actor *player, + const std::string &url) { - auto wsUrl = url; - if (wsUrl.empty()) { - auto mod = trapdoor::bdsMod->asInstance(); - wsUrl = mod->getConfigManager().getServerConfig().wsUrl; - } + if (this->webSocket && + this->webSocket->getReadyState() == easywsclient::WebSocket::OPEN) { + trapdoor::warning(player, trapdoor::LANG("fp.error.exist")); + return; + } + if (this->webSocket) { + this->webSocket->close(); + } + delete this->webSocket; - this->webSocket = easywsclient::WebSocket::from_url(wsUrl); + auto wsUrl = url; + if (wsUrl.empty()) { + auto mod = trapdoor::bdsMod->asInstance(); + wsUrl = mod->getConfigManager().getServerConfig().wsUrl; + } - if (this->webSocket) { - this->clientStatus = ClientStatus::READY; - trapdoor::info(player, trapdoor::LANG("fp.info.connect"), - wsUrl.c_str()); - this->run(); - } else { - trapdoor::info(player, trapdoor::LANG("fp.error.connect"), - wsUrl.c_str()); - } - } + this->webSocket = easywsclient::WebSocket::from_url(wsUrl); -//更新状态,查询和消费消息队列 - void FakePlayerClient::tick() { - //如果是等待消息的状态就增加计时器如果五秒内收不到消息就说明消息发送失败 - if (this->clientStatus == ClientStatus::WAITING_MESSAGE) { - this->timer++; - //超过100gt没有回复就说明连接炸了 - if (this->timer == 100) { - this->message.set(trapdoor::LANG("fp.tick.timeout")); - this->clientStatus = ClientStatus::READY; - this->timer = 0; - return; - } - } + if (this->webSocket) { + this->clientStatus = ClientStatus::READY; + trapdoor::info(player, trapdoor::LANG("fp.info.connect"), wsUrl.c_str()); + this->run(); + } else { + trapdoor::info(player, trapdoor::LANG("fp.error.connect"), wsUrl.c_str()); + } +} - //如果有消息需要消费就消费消息 - if (this->clientStatus == ClientStatus::NEED_CONSUME) { - this->consume(); - //重置状态和计时器 - this->clientStatus = ClientStatus::READY; - this->timer = 0; - } +//更新状态,查询和消费消息队列 +void FakePlayerClient::tick() { + //如果是等待消息的状态就增加计时器如果五秒内收不到消息就说明消息发送失败 + if (this->clientStatus == ClientStatus::WAITING_MESSAGE) { + this->timer++; + //超过100gt没有回复就说明连接炸了 + if (this->timer == 100) { + this->message.set(trapdoor::LANG("fp.tick.timeout")); + this->clientStatus = ClientStatus::READY; + this->timer = 0; + return; } + } - FakePlayerClient::~FakePlayerClient() { disconnect(); } + //如果有消息需要消费就消费消息 + if (this->clientStatus == ClientStatus::NEED_CONSUME) { + this->consume(); + //重置状态和计时器 + this->clientStatus = ClientStatus::READY; + this->timer = 0; + } +} + +FakePlayerClient::~FakePlayerClient() { disconnect(); } //断开连接 - void FakePlayerClient::disconnect() { - if (webSocket) - webSocket->close(); - delete webSocket; - this->disconnectCallBack(); - } +void FakePlayerClient::disconnect() { + if (webSocket) + webSocket->close(); + delete webSocket; + this->disconnectCallBack(); +} - void FakePlayerClient::disconnectCallBack() { - trapdoor::broadcastMsg(trapdoor::LANG("fp.info.disconnectCallBack")); - this->clientStatus = ClientStatus::NOT_OPEN; - } +void FakePlayerClient::disconnectCallBack() { + trapdoor::broadcastMsg(trapdoor::LANG("fp.info.disconnectCallBack")); + this->clientStatus = ClientStatus::NOT_OPEN; +} - std::string FakePlayerClient::buildMessage(FakePlayerClient::MessageType type, - const std::string ¶m) { - switch (type) { - case MessageType::PLAYER_LIST: - return R"({ +std::string FakePlayerClient::buildMessage(FakePlayerClient::MessageType type, + const std::string ¶m) { + switch (type) { + case MessageType::PLAYER_LIST: + return R"({ "type": "list" })"; - case MessageType::ADD_PLAYER: - return trapdoor::format(R"( + case MessageType::ADD_PLAYER: + return trapdoor::format(R"( { "type": "add", "data": { @@ -182,9 +180,9 @@ namespace mod { } } )", - param.c_str()); - case MessageType::REMOVE_PLAYER: - return trapdoor::format(R"( + param.c_str()); + case MessageType::REMOVE_PLAYER: + return trapdoor::format(R"( { "type": "remove", "data": { @@ -192,72 +190,75 @@ namespace mod { } } )", - param.c_str()); - } - return "{}"; - } + param.c_str()); + } + return "{}"; +} - std::string FakePlayerClient::parseResponse(const std::string &response, - bool &status) { - using json = nlohmann::json; - try { - json jsonMsg = json::parse(response); - auto respType = jsonMsg["type"].get(); - auto respData = jsonMsg["data"]; - if (respType == "list") { - status = true; - std::string strBuilder = - trapdoor::LANG("fp.info.list"); //下面是所有的假人玩家 - this->fakePlayerList.clear(); - for (auto &i : respData["list"]) { - strBuilder += "\n"; - strBuilder += i.get(); - this->fakePlayerList.insert(i.get()); - } - return strBuilder; - } else if (respType == "add" || respType == "remove") { - const std::string type = - respType == "add" - ? trapdoor::LANG("fp.added") - : trapdoor::LANG("fp.remove"); // 添加" : "移除 - auto name = respData["name"].get(); - auto success = respData["success"].get(); - if (success) { - status = true; - return trapdoor::format(trapdoor::LANG("fp.connect.success"), - type.c_str(), - name.c_str()); // 成功%s假人[%s] - } else { - status = false; - auto reason = respData["reason"].get(); - return trapdoor::format( - trapdoor::LANG("fp.connect.fail"), type.c_str(), - name.c_str(), - reason.c_str()); //无法%s假人[%s],原因: %s - } - } else { - status = false; - return "unknown message"; - } - } catch (std::exception &e) { - status = false; - return trapdoor::format("message error: %s", e.what()); - } +std::string FakePlayerClient::parseResponse(const std::string &response, + bool &status) { + using json = nlohmann::json; + try { + json jsonMsg = json::parse(response); + auto respType = jsonMsg["type"].get(); + auto respData = jsonMsg["data"]; + if (respType == "list") { + status = true; + std::string strBuilder = + trapdoor::LANG("fp.info.list"); //下面是所有的假人玩家 + this->fakePlayerList.clear(); + for (auto &i : respData["list"]) { + strBuilder += "\n"; + strBuilder += i.get(); + this->fakePlayerList.insert(i.get()); + } + return strBuilder; + } else if (respType == "add" || respType == "remove") { + const std::string type = + respType == "add" ? trapdoor::LANG("fp.added") + : trapdoor::LANG("fp.remove"); // 添加" : "移除 + auto name = respData["name"].get(); + auto success = respData["success"].get(); + if (success) { + status = true; + return trapdoor::format(trapdoor::LANG("fp.connect.success"), + type.c_str(), + name.c_str()); // 成功%s假人[%s] + } else { + status = false; + auto reason = respData["reason"].get(); + return trapdoor::format(trapdoor::LANG("fp.connect.fail"), type.c_str(), + name.c_str(), + reason.c_str()); //无法%s假人[%s],原因: %s + } + } else { + status = false; + return "unknown message"; } + } catch (std::exception &e) { + status = false; + return trapdoor::format("message error: %s", e.what()); + } +} - void FakePlayerClient::tpFakePlayer(trapdoor::Actor *player, - const std::string &playerName) { - if (this->fakePlayerList.count(playerName)) { - const std::string tpCmd = - "tp \"" + playerName + "\" \"" + player->getNameTag() + "\""; - CommandManager::runVanillaCommand(tpCmd); - trapdoor::info(this->source, trapdoor::LANG("fp.tp.success"), - player->getNameTag().c_str()); //假人已被tp到[%s]所在位置 - } else { - trapdoor::info( - this->source, - trapdoor::LANG("fp.tp.fail")); //找不到假人,请尝试执行fakeplayer - // list指令后再试 - } - } +void FakePlayerClient::tpFakePlayer(trapdoor::Actor *player, + const std::string &playerName) { + + if (this->fakePlayerList.count(playerName)) { + const std::string tpCmd = + "tp \"" + playerName + "\" \"" + player->getNameTag() + "\""; + CommandManager::runVanillaCommand(tpCmd); + trapdoor::info(this->source, trapdoor::LANG("fp.tp.success"), + player->getNameTag().c_str()); //假人已被tp到[%s]所在位置 + } else { + trapdoor::info( + this->source, + trapdoor::LANG("fp.tp.fail")); //找不到假人,请尝试执行fakeplayer + // list指令后再试 + } +} +bool FakePlayerClient::checkConn() { + return this->webSocket && + this->webSocket->getReadyState() == easywsclient::WebSocket::OPEN; +} } // namespace mod diff --git a/mod/fakePlayer/FakePlayerClient.h b/mod/fakePlayer/FakePlayerClient.h index a9e65d9..965d014 100644 --- a/mod/fakePlayer/FakePlayerClient.h +++ b/mod/fakePlayer/FakePlayerClient.h @@ -5,99 +5,90 @@ #ifndef MOD_FAKEPLAYERCLIENT_H #define MOD_FAKEPLAYERCLIENT_H #ifdef _WIN32 -#pragma comment( lib, "ws2_32") +#pragma comment(lib, "ws2_32") #include #endif -#include "easywsclient.hpp" -#include "ThreadPool.h" #include "CommandManager.h" +#include "ThreadPool.h" +#include "easywsclient.hpp" #include #include #include -#include #include -#include #include +#include +#include namespace mod { +template class SimpleThreadSafeVal { +private: + T val; + std::mutex m; + +public: + void set(const T &v) { + std::lock_guard l(m); + this->val = v; + } - template - class SimpleThreadSafeVal { - private:; - T val; - std::mutex m; - public: - void set(const T &v) { - std::lock_guard l(m); - this->val = v; - } + T get() { + std::lock_guard l(m); + return val; + } +}; - T get() { - std::lock_guard l(m); - return val; - } +//和falePlayer进行通信的客户端 +class FakePlayerClient { + enum class ClientStatus { NOT_OPEN, READY, WAITING_MESSAGE, NEED_CONSUME }; + enum class MessageType { PLAYER_LIST, ADD_PLAYER, REMOVE_PLAYER }; - }; +private: + static std::string buildMessage(MessageType type, + const std::string ¶m = ""); - //和falePlayer进行通信的客户端 - class FakePlayerClient { - enum class ClientStatus { - NOT_OPEN, - READY, - WAITING_MESSAGE, - NEED_CONSUME - }; - enum class MessageType { - PLAYER_LIST, - ADD_PLAYER, - REMOVE_PLAYER - }; - private: - static std::string buildMessage(MessageType type, const std::string ¶m = ""); + std::string parseResponse(const std::string &response, bool &status); - std::string parseResponse(const std::string &response, bool &status); + easywsclient::WebSocket *webSocket = nullptr; + ThreadPool *pool = nullptr; + std::atomic clientStatus{ClientStatus::NOT_OPEN}; + SimpleThreadSafeVal message; + size_t timer = 0; + trapdoor::Actor *source = nullptr; + std::set fakePlayerList; - easywsclient::WebSocket *webSocket = nullptr; - ThreadPool *pool = nullptr; - std::atomic clientStatus{ClientStatus::NOT_OPEN}; - SimpleThreadSafeVal message; - size_t timer = 0; - trapdoor::Actor *source = nullptr; - std::set fakePlayerList; + //发送消息 + bool sendMessage(trapdoor::Actor *player, const std::string &msg); - //发送消息 - bool sendMessage(trapdoor::Actor *player, const std::string &msg); + //后台运行 + void run(); - //后台运行 - void run(); + bool consume(); - bool consume(); + void disconnectCallBack(); - void disconnectCallBack(); + inline void setSource(trapdoor::Actor *player) { this->source = player; } - inline void setSource(trapdoor::Actor *player) { - this->source = player; - } +public: + void registerFakePlayerCommand(trapdoor::CommandManager &manager); - public: - void registerFakePlayerCommand(trapdoor::CommandManager &manager); + explicit FakePlayerClient(ThreadPool *threadPool) : pool(threadPool) {} - explicit FakePlayerClient(ThreadPool *threadPool) : pool(threadPool) {} + void connect(trapdoor::Actor *player, const std::string &url); - void connect(trapdoor::Actor *player, const std::string &url); + void disconnect(); - void disconnect(); + void tick(); - void tick(); + void tpFakePlayer(trapdoor::Actor *player, const std::string &playerName); - void tpFakePlayer(trapdoor::Actor *player, const std::string &playerName); + bool checkConn(); - ~FakePlayerClient(); - }; + ~FakePlayerClient(); +}; -} -#endif //MOD_FAKEPLAYERCLIENT_H +} // namespace mod +#endif // MOD_FAKEPLAYERCLIENT_H diff --git a/mod/function/BlockRotationHelper.cpp b/mod/function/BlockRotationHelper.cpp index bd18b68..348935a 100644 --- a/mod/function/BlockRotationHelper.cpp +++ b/mod/function/BlockRotationHelper.cpp @@ -48,11 +48,15 @@ namespace mod { auto newBlock = block->getLegacy()->tryGetStateBlock(newState); blockSource->setBlock(&pos, air); blockSource->setBlock(&pos, newBlock); - } else if (name.find("cake") != std::string::npos) { - auto newState = (variant + 1) % 7; - auto newBlock = block->getLegacy()->tryGetStateBlock(newState); - blockSource->setBlock(&pos, newBlock); - } else if (name.find("grindstone") != std::string::npos) { + } + +// else if (name.find("cake") != std::string::npos) { +// auto newState = (variant + 1) % 7; +// auto newBlock = block->getLegacy()->tryGetStateBlock(newState); +// blockSource->setBlock(&pos, newBlock); +// } + + else if (name.find("grindstone") != std::string::npos) { auto newState = (variant + 1) % 12; auto newBlock = block->getLegacy()->tryGetStateBlock(newState); blockSource->setBlock(&pos, newBlock); @@ -115,31 +119,31 @@ namespace mod { } } - void - BlockRotationHelper::newRotate(trapdoor::BlockSource *blockSource, trapdoor::BlockPos &pos, trapdoor::FACING facing, - Vec3 *v) const { - auto block = blockSource->getBlock(pos); - auto bId = block->getLegacy()->getBlockID(); - for (const auto &action: this->actions) { - if (action.patterns.find(bId) != action.patterns.end()) { - action.action(blockSource, block, pos, facing, v); - return; - } - } - } - - void BlockRotationHelper::addActons() { -#define ROTATE_ACTION(S) [](trapdoor::BlockSource *blockSource, trapdoor::BlockPos &pos, trapdoor::FACING facing, Vec3 *v){} - using namespace trapdoor; - std::set t1{PISTON, STICKY_PISTON, DROPPER, OBSERVER, DISPENSER}; - this->actions.emplace_back(t1, ROTATE_ACTION({ - - })); - +// void +// BlockRotationHelper::newRotate(trapdoor::BlockSource *blockSource, trapdoor::BlockPos &pos, trapdoor::FACING facing, +// Vec3 *v) const { +// auto block = blockSource->getBlock(pos); +// auto bId = block->getLegacy()->getBlockID(); +// for (const auto &action: this->actions) { +// if (action.patterns.find(bId) != action.patterns.end()) { +// action.action(blockSource, block, pos, facing, v); +// return; +// } +// } +// } - - - - } +// void BlockRotationHelper::addActons() { +//#define ROTATE_ACTION(S) [](trapdoor::BlockSource *blockSource, trapdoor::BlockPos &pos, trapdoor::FACING facing, Vec3 *v){} +// using namespace trapdoor; +// std::set t1{PISTON, STICKY_PISTON, DROPPER, OBSERVER, DISPENSER}; +// this->actions.emplace_back(t1, ROTATE_ACTION({ +// +// })); +// +// +// +// +// +// } } // namespace mod diff --git a/mod/function/BlockRotationHelper.h b/mod/function/BlockRotationHelper.h index b390a74..f7bc5a3 100644 --- a/mod/function/BlockRotationHelper.h +++ b/mod/function/BlockRotationHelper.h @@ -42,10 +42,10 @@ namespace mod { void rotate(trapdoor::BlockPos &pos, trapdoor::BlockSource *blockSource) const; - void - newRotate(trapdoor::BlockSource *blockSource, trapdoor::BlockPos &pos, trapdoor::FACING facing, Vec3 *v) const; - - void addActons(); +// void +// newRotate(trapdoor::BlockSource *blockSource, trapdoor::BlockPos &pos, trapdoor::FACING facing, Vec3 *v) const; +// +// void addActons(); }; } diff --git a/mod/tick/GameTick.cpp b/mod/tick/GameTick.cpp index afe9e58..380006f 100644 --- a/mod/tick/GameTick.cpp +++ b/mod/tick/GameTick.cpp @@ -28,9 +28,23 @@ int slowDownCounter = 0; // slow down counter int forwardTickNum = 0; // forward tick num bool isMSPTing = false; +uint64_t frozenCheckTick = 0; + mod::ActorProfiler &getActorProfiler() { - static mod::ActorProfiler actorProfiler; - return actorProfiler; + static mod::ActorProfiler actorProfiler; + return actorProfiler; +} + +void checkPlayerInFrozen() { + frozenCheckTick++; + if (frozenCheckTick % 100 == 0) { + printf("check\n"); + if (trapdoor::bdsMod->getLevel()->noPlayerExists()) { + tickStatus = WorldTickStatus::Normal; + L_INFO("no player exists in server, change level status from frozen to " + "normal"); + } + } } /* @@ -38,107 +52,107 @@ mod::ActorProfiler &getActorProfiler() { */ void staticWork() { - //实体性能分析的更新 - if (mod::tick::getActorProfiler().inProfiling) { - auto &actorProfiler = mod::tick::getActorProfiler(); - actorProfiler.currentRound--; - if (actorProfiler.currentRound == 0) { - actorProfiler.print(); - actorProfiler.reset(); - } + //实体性能分析的更新 + if (mod::tick::getActorProfiler().inProfiling) { + auto &actorProfiler = mod::tick::getActorProfiler(); + actorProfiler.currentRound--; + if (actorProfiler.currentRound == 0) { + actorProfiler.print(); + actorProfiler.reset(); } + } } void sendMsptInfo(microsecond_t time, bool isRedstoneTick) { - auto mspt = (double)time / 1000; - int tps = mspt <= 50 ? 20 : (int)(1000.0 / mspt); - trapdoor::MessageBuilder builder; - auto color = MSG_COLOR::WHITE; - if (mspt > 40) { - if (mspt >= 50) { - color = MSG_COLOR::RED; - } else { - color = MSG_COLOR::YELLOW; - } + auto mspt = (double)time / 1000; + int tps = mspt <= 50 ? 20 : (int)(1000.0 / mspt); + trapdoor::MessageBuilder builder; + auto color = MSG_COLOR::WHITE; + if (mspt > 40) { + if (mspt >= 50) { + color = MSG_COLOR::RED; + } else { + color = MSG_COLOR::YELLOW; } - auto rColor = isRedstoneTick ? MSG_COLOR::RED : MSG_COLOR::WHITE; - builder.sText("#", rColor) - .text("mspt: ") - .sTextF(color, "%.3f ms ", mspt) - .text("tps: ") - .sTextF(color, "%d", tps) - .broadcast(); + } + auto rColor = isRedstoneTick ? MSG_COLOR::RED : MSG_COLOR::WHITE; + builder.sText("#", rColor) + .text("mspt: ") + .sTextF(color, "%.3f ms ", mspt) + .text("tps: ") + .sTextF(color, "%d", tps) + .broadcast(); } } // namespace void freezeTick() { - if (tickStatus == WorldTickStatus::Normal) { - // info("world has frozen"); - if (tickStatus != WorldTickStatus::Frozen) { - tickStatus = WorldTickStatus::Frozen; - L_DEBUG("freeze world"); - broadcastMsg(LANG("tick.fz.set")); - } + if (tickStatus == WorldTickStatus::Normal) { + // info("world has frozen"); + if (tickStatus != WorldTickStatus::Frozen) { + tickStatus = WorldTickStatus::Frozen; + L_DEBUG("freeze world"); + broadcastMsg(LANG("tick.fz.set")); } + } } void resetTick() { - if (tickStatus != WorldTickStatus::Normal) { - tickStatus = WorldTickStatus::Normal; - L_DEBUG("reset world"); - } - broadcastMsg(LANG("tick.r.set")); + if (tickStatus != WorldTickStatus::Normal) { + tickStatus = WorldTickStatus::Normal; + L_DEBUG("reset world"); + } + broadcastMsg(LANG("tick.r.set")); } void wrapTick(size_t speed) { - if (tickStatus == WorldTickStatus::Normal) { - broadcastMsg(LANG("tick.acc.set"), speed); - tickStatus = WorldTickStatus::Wrap; - L_DEBUG("begin accelerate world %d", speed); - wrapSpeed = speed; - } else { - broadcastMsg(LANG("tick.acc.error")); - } + if (tickStatus == WorldTickStatus::Normal) { + broadcastMsg(LANG("tick.acc.set"), speed); + tickStatus = WorldTickStatus::Wrap; + L_DEBUG("begin accelerate world %d", speed); + wrapSpeed = speed; + } else { + broadcastMsg(LANG("tick.acc.error")); + } } void forwardTick(size_t tickNum) { - if (tickStatus == WorldTickStatus::Frozen || - tickStatus == WorldTickStatus::Normal) { - forwardTickNum = tickNum; - lastTickStats = tickStatus; - tickStatus = WorldTickStatus::Forward; - if (tickNum > 1200) - broadcastMsg(LANG("tick.fw.begin"), tickNum); - L_DEBUG("begin forward %d tick", tickNum); - } else { - broadcastMsg(LANG("tick.fw.error")); - } + if (tickStatus == WorldTickStatus::Frozen || + tickStatus == WorldTickStatus::Normal) { + forwardTickNum = tickNum; + lastTickStats = tickStatus; + tickStatus = WorldTickStatus::Forward; + if (tickNum > 1200) + broadcastMsg(LANG("tick.fw.begin"), tickNum); + L_DEBUG("begin forward %d tick", tickNum); + } else { + broadcastMsg(LANG("tick.fw.error")); + } } void slowTick(size_t slowSpeed) { - if (tickStatus == WorldTickStatus::Normal) { - broadcastMsg(LANG("tick.slow.set"), slowSpeed); - L_DEBUG("slow world %d times", slowSpeed); - tickStatus = WorldTickStatus::Slow; - SlowDownTimes = slowSpeed; - } else { - broadcastMsg(LANG("tick.slow.error")); - } + if (tickStatus == WorldTickStatus::Normal) { + broadcastMsg(LANG("tick.slow.set"), slowSpeed); + L_DEBUG("slow world %d times", slowSpeed); + tickStatus = WorldTickStatus::Slow; + SlowDownTimes = slowSpeed; + } else { + broadcastMsg(LANG("tick.slow.error")); + } } void profileWorld(trapdoor::Actor *player) { - if (gameProfiler.inProfiling) { - trapdoor::warning(player, LANG("prof.error")); - return; - } - - if (tickStatus != WorldTickStatus::Normal) { - trapdoor::warning(player, LANG("prof.warning")); - } - L_DEBUG("begin profiling"); - broadcastMsg(LANG("prof.start")); - gameProfiler.inProfiling = true; - gameProfiler.currentRound = gameProfiler.totalRound; + if (gameProfiler.inProfiling) { + trapdoor::warning(player, LANG("prof.error")); + return; + } + + if (tickStatus != WorldTickStatus::Normal) { + trapdoor::warning(player, LANG("prof.warning")); + } + L_DEBUG("begin profiling"); + broadcastMsg(LANG("prof.start")); + gameProfiler.inProfiling = true; + gameProfiler.currentRound = gameProfiler.totalRound; } void mspt() { tick::isMSPTing = true; } @@ -146,76 +160,76 @@ void mspt() { tick::isMSPTing = true; } WorldTickStatus getTickStatus() { return tickStatus; } void profileEntities(trapdoor::Actor *player) { - if (getActorProfiler().inProfiling) { - trapdoor::warning(player, LANG("prof.error")); - return; - } - - if (tick::getTickStatus() != tick::WorldTickStatus::Normal) { - trapdoor::warning(player, LANG("prof.warning")); - } - L_DEBUG("begin profiling"); - info(player, LANG("prof.start")); - getActorProfiler().inProfiling = true; - getActorProfiler().currentRound = getActorProfiler().totalRound; + if (getActorProfiler().inProfiling) { + trapdoor::warning(player, LANG("prof.error")); + return; + } + + if (tick::getTickStatus() != tick::WorldTickStatus::Normal) { + trapdoor::warning(player, LANG("prof.warning")); + } + L_DEBUG("begin profiling"); + info(player, LANG("prof.start")); + getActorProfiler().inProfiling = true; + getActorProfiler().currentRound = getActorProfiler().totalRound; } void queryStatus(trapdoor::Actor *player) { - switch (tickStatus) { - case Frozen: - info(player, "frozen"); - return; - case Normal: - info(player, "normal"); - return; - case Slow: - info(player, "slow %d times", tick::SlowDownTimes); - return; - case Forward: - info(player, "forwarding"); - return; - case Wrap: - info(player, "accelerate %d times", tick::wrapSpeed); - return; - } + switch (tickStatus) { + case Frozen: + info(player, "frozen"); + return; + case Normal: + info(player, "normal"); + return; + case Slow: + info(player, "slow %d times", tick::SlowDownTimes); + return; + case Forward: + info(player, "forwarding"); + return; + case Wrap: + info(player, "accelerate %d times", tick::wrapSpeed); + return; + } } void registerTickCommand(CommandManager &commandManager) { - commandManager.registerCmd("tick", "command.tick.desc") - ->then(ARG("fz", "command.tick.fw.desc", NONE, { tick::freezeTick(); })) - ->then(ARG("slow", "command.tick.slow.desc", INT, - { - auto slowTime = holder->getInt(); - if (slowTime > 1 && slowTime <= 64) { - tick::slowTick(slowTime); - } else { - error(player, LANG("command.tick.slow.error")); - } - })) - ->then(ARG("acc", "command.tick.acc.desc", INT, - { - auto wrapTime = holder->getInt(); - if (wrapTime > 1 && wrapTime <= 10) { - tick::wrapTick(wrapTime); - } else { - error(player, LANG("command.tick.acc.error")); - } - })) - ->then(ARG("r", "command.tick.r.desc", NONE, { tick::resetTick(); })) - ->then(ARG("fw", "command.tick.fw.desc", INT, - { tick::forwardTick(holder->getInt()); })) - ->then(ARG("q", "command.tick.q.desc", NONE, - { tick::queryStatus(player); })); + commandManager.registerCmd("tick", "command.tick.desc") + ->then(ARG("fz", "command.tick.fw.desc", NONE, { tick::freezeTick(); })) + ->then(ARG("slow", "command.tick.slow.desc", INT, + { + auto slowTime = holder->getInt(); + if (slowTime > 1 && slowTime <= 64) { + tick::slowTick(slowTime); + } else { + error(player, LANG("command.tick.slow.error")); + } + })) + ->then(ARG("acc", "command.tick.acc.desc", INT, + { + auto wrapTime = holder->getInt(); + if (wrapTime > 1 && wrapTime <= 10) { + tick::wrapTick(wrapTime); + } else { + error(player, LANG("command.tick.acc.error")); + } + })) + ->then(ARG("r", "command.tick.r.desc", NONE, { tick::resetTick(); })) + ->then(ARG("fw", "command.tick.fw.desc", INT, + { tick::forwardTick(holder->getInt()); })) + ->then(ARG("q", "command.tick.q.desc", NONE, + { tick::queryStatus(player); })); } void registerProfileCommand(CommandManager &commandManager) { - commandManager.registerCmd("prof", "command.prof.desc") - ->then(ARG("actor", "command.prof.actor.desc", NONE, - { tick::profileEntities(player); })) - ->EXE({ tick::profileWorld(player); }); - commandManager.registerCmd("mspt", "command.mspt.desc")->EXE({ - tick::mspt(); - }); + commandManager.registerCmd("prof", "command.prof.desc") + ->then(ARG("actor", "command.prof.actor.desc", NONE, + { tick::profileEntities(player); })) + ->EXE({ tick::profileWorld(player); }); + commandManager.registerCmd("mspt", "command.mspt.desc")->EXE({ + tick::mspt(); + }); } } // namespace mod::tick @@ -223,114 +237,114 @@ using namespace SymHook; THook(void, MSSYM_B1QA4tickB1AE11ServerLevelB2AAA7UEAAXXZ, trapdoor::Level *serverLevel) { - if (!trapdoor::bdsMod) { - L_ERROR("mod is nullptr"); - } - if (!trapdoor::bdsMod->getLevel()) { - trapdoor::bdsMod->setLevel(serverLevel); - trapdoor::bdsMod->asInstance()->initialize(); - } - - auto modInstance = trapdoor::bdsMod->asInstance(); - bool isRedstoneTick = false; - switch (mod::tick::tickStatus) { - case mod::tick::Frozen: - return; - case mod::tick::Normal: - - if (mod::tick::gameProfiler.inProfiling || mod::tick::isMSPTing) { - TIMER_START - original(serverLevel); - modInstance->lightTick(); - modInstance->heavyTick(); - mod::tick::staticWork(); - TIMER_END - if (mod::tick::isMSPTing) { - //发送mspt信息 - isRedstoneTick = - modInstance->getLevel()->getDimFromID(0)->isRedstoneTick(); - mod::tick::sendMsptInfo(timeReslut, isRedstoneTick); - mod::tick::isMSPTing = false; - } - if (mod::tick::gameProfiler.inProfiling) { - mod::tick::gameProfiler.serverLevelTickTime += timeReslut; - mod::tick::gameProfiler.currentRound--; - if (mod::tick::gameProfiler.currentRound == 0) { - mod::tick::gameProfiler.inProfiling = false; - mod::tick::gameProfiler.print(); - mod::tick::gameProfiler.reset(); - } - } - } else { - original(serverLevel); - modInstance->lightTick(); - modInstance->heavyTick(); - mod::tick::staticWork(); - } - break; - - case mod::tick::Slow: - if (mod::tick::slowDownCounter % mod::tick::SlowDownTimes == 0) { - original(serverLevel); - modInstance->lightTick(); - modInstance->heavyTick(); - } - mod::tick::slowDownCounter = - (mod::tick::slowDownCounter + 1) % mod::tick::SlowDownTimes; - break; - case mod::tick::Forward: - for (auto i = 0; i < mod::tick::forwardTickNum; i++) { - original(serverLevel); - modInstance->lightTick(); - } + if (!trapdoor::bdsMod) { + L_ERROR("mod is nullptr"); + } + if (!trapdoor::bdsMod->getLevel()) { + trapdoor::bdsMod->setLevel(serverLevel); + trapdoor::bdsMod->asInstance()->initialize(); + } + + auto modInstance = trapdoor::bdsMod->asInstance(); + bool isRedstoneTick = false; + switch (mod::tick::tickStatus) { + case mod::tick::Frozen: + mod::tick::checkPlayerInFrozen(); + return; + case mod::tick::Normal: + + if (mod::tick::gameProfiler.inProfiling || mod::tick::isMSPTing) { + TIMER_START + original(serverLevel); + modInstance->lightTick(); + modInstance->heavyTick(); + mod::tick::staticWork(); + TIMER_END + if (mod::tick::isMSPTing) { + //发送mspt信息 isRedstoneTick = modInstance->getLevel()->getDimFromID(0)->isRedstoneTick(); - trapdoor::broadcastMsg(trapdoor::LANG("tick.fw.end"), - mod::tick::forwardTickNum, isRedstoneTick); - mod::tick::forwardTickNum = 0; - mod::tick::tickStatus = mod::tick::lastTickStats; - break; - case mod::tick::Wrap: - for (int i = 0; i < mod::tick::wrapSpeed; ++i) { - original(serverLevel); - modInstance->lightTick(); + mod::tick::sendMsptInfo(timeReslut, isRedstoneTick); + mod::tick::isMSPTing = false; + } + if (mod::tick::gameProfiler.inProfiling) { + mod::tick::gameProfiler.serverLevelTickTime += timeReslut; + mod::tick::gameProfiler.currentRound--; + if (mod::tick::gameProfiler.currentRound == 0) { + mod::tick::gameProfiler.inProfiling = false; + mod::tick::gameProfiler.print(); + mod::tick::gameProfiler.reset(); } - modInstance->heavyTick(); - break; + } + } else { + original(serverLevel); + modInstance->lightTick(); + modInstance->heavyTick(); + mod::tick::staticWork(); + } + break; + + case mod::tick::Slow: + if (mod::tick::slowDownCounter % mod::tick::SlowDownTimes == 0) { + original(serverLevel); + modInstance->lightTick(); + modInstance->heavyTick(); + } + mod::tick::slowDownCounter = + (mod::tick::slowDownCounter + 1) % mod::tick::SlowDownTimes; + break; + case mod::tick::Forward: + for (auto i = 0; i < mod::tick::forwardTickNum; i++) { + original(serverLevel); + modInstance->lightTick(); } + isRedstoneTick = modInstance->getLevel()->getDimFromID(0)->isRedstoneTick(); + trapdoor::broadcastMsg(trapdoor::LANG("tick.fw.end"), + mod::tick::forwardTickNum, isRedstoneTick); + mod::tick::forwardTickNum = 0; + mod::tick::tickStatus = mod::tick::lastTickStats; + break; + case mod::tick::Wrap: + for (int i = 0; i < mod::tick::wrapSpeed; ++i) { + original(serverLevel); + modInstance->lightTick(); + } + modInstance->heavyTick(); + break; + } } // ServerPlayer::tickWorld THook(void, MSSYM_B1QA9tickWorldB1AE12ServerPlayerB2AAE13UEAAHAEBUTickB3AAAA1Z, trapdoor::Actor *p, void *tick) { - original(p, tick); + original(p, tick); } // Dimension::tick THook(void, MSSYM_B1QA4tickB1AA9DimensionB2AAA7UEAAXXZ, void *dim) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(dim); - TIMER_END - mod::tick::gameProfiler.dimensionTickTime += timeReslut; - } else { - original(dim); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(dim); + TIMER_END + mod::tick::gameProfiler.dimensionTickTime += timeReslut; + } else { + original(dim); + } } // LevelChunk::tick THook( void, MSSYM_B1QA4tickB1AE10LevelChunkB2AAE20QEAAXAEAVBlockSourceB2AAA8AEBUTickB3AAAA1Z, void *levelChunk, trapdoor::BlockSource *blockSource, size_t *tick) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(levelChunk, blockSource, tick); - TIMER_END - mod::tick::gameProfiler.chunkTickTime += timeReslut; - mod::tick::gameProfiler.tickChunkNum++; - } else { - original(levelChunk, blockSource, tick); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(levelChunk, blockSource, tick); + TIMER_END + mod::tick::gameProfiler.chunkTickTime += timeReslut; + mod::tick::gameProfiler.tickChunkNum++; + } else { + original(levelChunk, blockSource, tick); + } } // LevelChunk::tickBlocks @@ -338,14 +352,14 @@ THook(void, MSSYM_B1QE10tickBlocksB1AE10LevelChunkB2AAE20QEAAXAEAVBlockSourceB3AAAA1Z, void *levelChunk, void *blockSource, INT64 a3, int a4) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(levelChunk, blockSource, a3, a4); - TIMER_END - mod::tick::gameProfiler.chunkRandomTickTime += timeReslut; - } else { - original(levelChunk, blockSource, a3, a4); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(levelChunk, blockSource, a3, a4); + TIMER_END + mod::tick::gameProfiler.chunkRandomTickTime += timeReslut; + } else { + original(levelChunk, blockSource, a3, a4); + } } // LevelChunk::tickBlockEntities @@ -353,14 +367,14 @@ THook( void, MSSYM_B1QE17tickBlockEntitiesB1AE10LevelChunkB2AAE20QEAAXAEAVBlockSourceB3AAAA1Z, void *levelChunk, void *blockSource) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(levelChunk, blockSource); - TIMER_END - mod::tick::gameProfiler.chunkBlockEntityTickTime += timeReslut; - } else { - original(levelChunk, blockSource); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(levelChunk, blockSource); + TIMER_END + mod::tick::gameProfiler.chunkBlockEntityTickTime += timeReslut; + } else { + original(levelChunk, blockSource); + } } ////mob actor Spawner::tick @@ -394,42 +408,42 @@ THook( MSSYM_B1QE16tickPendingTicksB1AE17BlockTickingQueueB2AAA4QEAAB1UE16NAEAVBlockSourceB2AAA8AEBUTickB2AAA1HB1UA1NB1AA1Z, void *queue, trapdoor::BlockSource *source, const int *until, int max, bool instalTick) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(queue, source, until, max, instalTick); - TIMER_END - mod::tick::gameProfiler.chunkPendingTickTime += timeReslut; - } else { - original(queue, source, until, max, instalTick); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(queue, source, until, max, instalTick); + TIMER_END + mod::tick::gameProfiler.chunkPendingTickTime += timeReslut; + } else { + original(queue, source, until, max, instalTick); + } } // Dimension::tick THook(void, MSSYM_B1QE12tickRedstoneB1AA9DimensionB2AAA7UEAAXXZ, void *dim) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(dim); - TIMER_END - mod::tick::gameProfiler.redstoneTickTime += timeReslut; - } else { - original(dim); - } - - // printf("69%d 68%d\n", v1, v2); - // printf("69:%d 68:%d\n", v1, v2); + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(dim); + TIMER_END + mod::tick::gameProfiler.redstoneTickTime += timeReslut; + } else { + original(dim); + } + + // printf("69%d 68%d\n", v1, v2); + // printf("69:%d 68:%d\n", v1, v2); } THook(void, MSSYM_B1QA4tickB1AE13EntitySystemsB2AAE23QEAAXAEAVEntityRegistryB3AAAA1Z, void *entitySystem, void *registry) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(entitySystem, registry); - TIMER_END - mod::tick::gameProfiler.levelEntitySystemTickTime += timeReslut; - } else { - original(entitySystem, registry); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(entitySystem, registry); + TIMER_END + mod::tick::gameProfiler.levelEntitySystemTickTime += timeReslut; + } else { + original(entitySystem, registry); + } } // pending update @@ -437,26 +451,26 @@ THook( void, MSSYM_B1QE21processPendingUpdatesB1AE17CircuitSceneGraphB2AAE20AEAAXPEAVBlockSourceB3AAAA1Z, void *graph, void *bs) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(graph, bs); - TIMER_END - mod::tick::gameProfiler.redstonePendingUpdateTime += timeReslut; - } else { - original(graph, bs); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(graph, bs); + TIMER_END + mod::tick::gameProfiler.redstonePendingUpdateTime += timeReslut; + } else { + original(graph, bs); + } } // pendingAdd THook(void, MSSYM_B1QE18processPendingAddsB1AE17CircuitSceneGraphB2AAA7AEAAXXZ, void *graph) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(graph); - TIMER_END - mod::tick::gameProfiler.redstonePendingAddTime += timeReslut; - } else { - original(graph); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(graph); + TIMER_END + mod::tick::gameProfiler.redstonePendingAddTime += timeReslut; + } else { + original(graph); + } } // pnding remove @@ -464,28 +478,28 @@ THook( void, MSSYM_B1QE15removeComponentB1AE17CircuitSceneGraphB2AAE17AEAAXAEBVBlockPosB3AAAA1Z, void *graph, void *bs) { - if (mod::tick::gameProfiler.inProfiling) { - TIMER_START - original(graph, bs); - TIMER_END - mod::tick::gameProfiler.redstonePendingRemoveTime += timeReslut; - } else { - original(graph, bs); - } + if (mod::tick::gameProfiler.inProfiling) { + TIMER_START + original(graph, bs); + TIMER_END + mod::tick::gameProfiler.redstonePendingRemoveTime += timeReslut; + } else { + original(graph, bs); + } } //实体性能分析的钩子函数 THook(void, MSSYM_B1QA4tickB1AA5ActorB2AAA4QEAAB1UE16NAEAVBlockSourceB3AAAA1Z, trapdoor::Actor *actor, trapdoor::BlockSource *blockSource) { - if (mod::tick::getActorProfiler().inProfiling) { - auto &profiler = mod::tick::getActorProfiler(); - TIMER_START - original(actor, blockSource); - TIMER_END - auto name = actor->getActorId(); - profiler.entitiesTickingList[name].time += timeReslut; - profiler.entitiesTickingList[name].count++; - } else { - original(actor, blockSource); - } + if (mod::tick::getActorProfiler().inProfiling) { + auto &profiler = mod::tick::getActorProfiler(); + TIMER_START + original(actor, blockSource); + TIMER_END + auto name = actor->getActorId(); + profiler.entitiesTickingList[name].time += timeReslut; + profiler.entitiesTickingList[name].count++; + } else { + original(actor, blockSource); + } }