diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c6eeb1..3bc42bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,7 +64,7 @@ target_link_libraries(${MOD_API_NAME} ${PROJECT_SOURCE_DIR}/api/lib/detours.lib) ####################这里是具体功能########################## #设置插版本 -set(TRAPDOOR_VERSION 0.9.81) +set(TRAPDOOR_VERSION 0.11) #设置游戏版本 set(MCBE_VERSION 1.16.40.2) #是否是测试版 diff --git a/mod/TrapdoorMod.cpp b/mod/TrapdoorMod.cpp index 4467fda..5fa25f3 100644 --- a/mod/TrapdoorMod.cpp +++ b/mod/TrapdoorMod.cpp @@ -15,7 +15,6 @@ #include "tick/GameTick.h" #include "trapdoor.h" - namespace mod { void TrapdoorMod::heavyTick() { @@ -91,23 +90,43 @@ void TrapdoorMod::registerCommands() { info(player, LANG("command.func.draw.set"), holder->getBool()); })) - // ->then(ARG( - // "stat", "command.func.stat.desc", BOOL, - // { - // this->playerStatisticManager.setAble(holder->getBool()); - // info(player, - // LANG("command.func.stat.set"), - // holder->getBool()); - // })) ->then(ARG("expl", "command.func.expl.desc", BOOL, { this->singleFunctions.preventExplosion = holder->getBool(); info(player, LANG("command.func.expl.set"), holder->getBool()); })) - ->then(ARG("ncud", "command.func.ncud.desc", BOOL, { - this->singleFunctions.preventNCUpdate = holder->getBool(); - info(player, LANG("command.func.ncud.set"), holder->getBool()); + ->then(ARG("ncud", "command.func.ncud.desc", BOOL, + { + this->singleFunctions.preventNCUpdate = holder->getBool(); + info(player, LANG("command.func.ncud.set"), + holder->getBool()); + })) + //容器无开启碰撞检查 + ->then( + ARG("ncrob", "command.func.ncrob.desc", BOOL, + { + this->singleFunctions.noConatinerObstruct = holder->getBool(); + info(player, LANG("command.func.ncrob.set"), holder->getBool()); + })) + //容器无消耗 + ->then(ARG("nccost", "command.func.ncost.desc", BOOL, + { + this->singleFunctions.noContainerCost = holder->getBool(); + info(player, LANG("command.func.ncost.set"), + holder->getBool()); + })) + //强制放置 + ->then(ARG("fbld", "command.func.fbld.desc", INT, + { + this->singleFunctions.forceBuild = holder->getInt(); + info(player, LANG("command.func.fbld.set"), + holder->getInt()); + })) + //高斯随机数调整 + ->then(ARG("grng", "command.func.grng.desc", INT, { + this->singleFunctions.gaussRnd = holder->getInt(); + info(player, LANG("command.func.grng.set"), holder->getInt()); })); //史莱姆显示 diff --git a/mod/TrapdoorMod.h b/mod/TrapdoorMod.h index 8d4eb3c..6af54a6 100644 --- a/mod/TrapdoorMod.h +++ b/mod/TrapdoorMod.h @@ -21,71 +21,76 @@ namespace mod { struct SingleFunction { - bool preventExplosion = false; - bool preventNCUpdate = false; - bool enableBetterMspt = false; + bool preventExplosion = false; + bool preventNCUpdate = false; + bool enableBetterMspt = false; + bool noConatinerObstruct = false; + bool noContainerCost = false; + int forceBuild = 0; + int gaussRnd = 1; + int maxPtSize = 100; }; class TrapdoorMod : public trapdoor::BDSMod { - private: - SingleFunction singleFunctions; - HopperChannelManager hopperChannelManager; - VillageHelper villageHelper; - HsaManager hsaManager; - ConfigManager configManager; - SpawnHelper spawnHelper; - BlockRotationHelper rotationHelper; - PlayerFunction playerFunctions; - SimpleBuilder simpleBuilder; - SlimeChunkHelper slimeChunkHelper; - FakePlayerClient *fakePlayerClient = nullptr; +private: + SingleFunction singleFunctions; + HopperChannelManager hopperChannelManager; + VillageHelper villageHelper; + HsaManager hsaManager; + ConfigManager configManager; + SpawnHelper spawnHelper; + BlockRotationHelper rotationHelper; + PlayerFunction playerFunctions; + SimpleBuilder simpleBuilder; + SlimeChunkHelper slimeChunkHelper; + FakePlayerClient *fakePlayerClient = nullptr; - void initFunctionEnable(); + void initFunctionEnable(); - public: - static void printCopyRightInfo(); +public: + static void printCopyRightInfo(); - static std::string getModVersion(); + static std::string getModVersion(); - static void printOSInfo(trapdoor::Actor *player); + static void printOSInfo(trapdoor::Actor *player); - void initialize() override; + void initialize() override; - void registerCommands() override; + void registerCommands() override; - void useOnHook(Actor *player, const std::string &itemName, BlockPos &pos, - unsigned int facing, const Vec3 &) override; + void useOnHook(Actor *player, const std::string &itemName, BlockPos &pos, + unsigned int facing, const Vec3 &) override; - CommandPermissionLevel - resetVanillaCommandLevel(const std::string &name, - CommandPermissionLevel oldLevel) override; + CommandPermissionLevel + resetVanillaCommandLevel(const std::string &name, + CommandPermissionLevel oldLevel) override; - void heavyTick(); + void heavyTick(); - void lightTick(); + void lightTick(); - inline bool readConfigFile(const std::string &configFileName) { - return this->configManager.initialize(configFileName); - } + inline bool readConfigFile(const std::string &configFileName) { + return this->configManager.initialize(configFileName); + } - bool attackEntityHook(Actor *entity1, Actor *entity2) override; + bool attackEntityHook(Actor *entity1, Actor *entity2) override; - // get functions - inline HopperChannelManager &getHopperChannelManager() { - return this->hopperChannelManager; - } + // get functions + inline HopperChannelManager &getHopperChannelManager() { + return this->hopperChannelManager; + } - inline VillageHelper &getVillageHelper() { return this->villageHelper; } + inline VillageHelper &getVillageHelper() { return this->villageHelper; } - inline HsaManager &getHsaManager() { return this->hsaManager; } + inline HsaManager &getHsaManager() { return this->hsaManager; } - inline std::string getLevelName() { - return this->configManager.getServerConfig().levelName; - } + inline std::string getLevelName() { + return this->configManager.getServerConfig().levelName; + } - inline SingleFunction getSingFunction() { return this->singleFunctions; } + inline SingleFunction getSingFunction() { return this->singleFunctions; } - inline ConfigManager &getConfigManager() { return this->configManager; } + inline ConfigManager &getConfigManager() { return this->configManager; } }; } // namespace mod diff --git a/mod/function/SingleFunctions.cpp b/mod/function/SingleFunctions.cpp index ed22873..5e74bed 100644 --- a/mod/function/SingleFunctions.cpp +++ b/mod/function/SingleFunctions.cpp @@ -2,40 +2,96 @@ // Created by xhy on 2020/12/23. // -#include "lib/mod.h" -#include "lib/SymHook.h" #include "BDSMod.h" #include "TrapdoorMod.h" +#include "lib/SymHook.h" +#include "lib/mod.h" namespace mod { - using namespace SymHook; - - THook( - void, - MSSYM_B1QA7explodeB1AA9ExplosionB2AAA7QEAAXXZ, - void * exp - ) { - auto modInstance = trapdoor::bdsMod->asInstance(); - if (!modInstance->getSingFunction().preventExplosion) - original(exp); - } - - /** - * SYM_CALL( - void(*)(BlockSource * self,const BlockPos *pos), - MSSYM_B1QE17updateNeighborsAtB1AE11BlockSourceB2AAE17QEAAXAEBVBlockPosB3AAAA1Z, - this, pos - ); - */ - - THook( - void, +using namespace SymHook; + +THook(void, MSSYM_B1QA7explodeB1AA9ExplosionB2AAA7QEAAXXZ, void *exp) { + auto modInstance = trapdoor::bdsMod->asInstance(); + if (!modInstance->getSingFunction().preventExplosion) + original(exp); +} + +/** + * SYM_CALL( + void(*)(BlockSource * self,const BlockPos *pos), MSSYM_B1QE17updateNeighborsAtB1AE11BlockSourceB2AAE17QEAAXAEBVBlockPosB3AAAA1Z, - trapdoor::BlockSource *source, - trapdoor::BlockPos * pos - ) { - auto modInstance = trapdoor::bdsMod->asInstance(); - if (!modInstance->getSingFunction().preventNCUpdate) - original(source, pos); - } -} \ No newline at end of file + this, pos + ); + */ + +THook( + void, + MSSYM_B1QE17updateNeighborsAtB1AE11BlockSourceB2AAE17QEAAXAEBVBlockPosB3AAAA1Z, + trapdoor::BlockSource *source, trapdoor::BlockPos *pos) { + auto modInstance = trapdoor::bdsMod->asInstance(); + if (!modInstance->getSingFunction().preventNCUpdate) + original(source, pos); +} + +// 0X8AC060 +constexpr uint64_t Continaer_can_open = 0X8AC060; +THook(bool, Continaer_can_open, void *container, void *bs) { + auto modInstance = trapdoor::bdsMod->asInstance(); + if (modInstance->getSingFunction().noConatinerObstruct) { + return true; + } else { + return original(container, bs); + } +} + +/* +0X7425E0 +public: virtual void __cdecl Container::removeItem(int,int) __ptr64 +?removeItem@Container@@UEAAXHH@Z +*/ +constexpr uint64_t Continaer_remove_item = 0X7425E0; +THook(void, Continaer_remove_item, void *container, int slot, int count) { + auto modInstance = trapdoor::bdsMod->asInstance(); + if (!modInstance->getSingFunction().noContainerCost) { + original(container, slot, count); + } +} + +/* +0XA17390 +public: bool __cdecl BlockSource::mayPlace(class Block const & __ptr64,class +BlockPos const & __ptr64,unsigned char,class Actor * __ptr64,bool) __ptr64 +?mayPlace@BlockSource@@QEAA_NAEBVBlock@@AEBVBlockPos@@EPEAVActor@@_N@Z +*/ + +constexpr uint64_t BlockSource_mayPlace = 0XA17390; +THook(bool, BlockSource_mayPlace, void *bs, void *block, void *p, + unsigned char face, void *placer, bool ignoreEntity) { + + auto modInstance = trapdoor::bdsMod->asInstance(); + auto level = modInstance->getSingFunction().forceBuild; + if (level == 1) + return original(bs, block, p, face, placer, true); + if (level == 2) + return true; + return original(bs, block, p, face, placer, ignoreEntity); +} + +/* + +0X1CC520 +public: float __cdecl Core::Random::nextGaussian(void) __ptr64 +?nextGaussian@Random@Core@@QEAAMXZ +*/ + +constexpr uint64_t Random_nextGaussian = 0X1CC520; +THook(float, Random_nextGaussian, void *random) { + auto modInstance = trapdoor::bdsMod->asInstance(); + int gauss = modInstance->getSingFunction().gaussRnd; + if (gauss <= 0) { + return 0; + } + return original(random) / gauss; +} + +} // namespace mod \ No newline at end of file