Skip to content

Commit

Permalink
~
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed May 10, 2022
1 parent ce99e30 commit 6f5a328
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 89 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#是否是测试版
Expand Down
43 changes: 31 additions & 12 deletions mod/TrapdoorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "tick/GameTick.h"
#include "trapdoor.h"


namespace mod {

void TrapdoorMod::heavyTick() {
Expand Down Expand Up @@ -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());
}));

//史莱姆显示
Expand Down
93 changes: 49 additions & 44 deletions mod/TrapdoorMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
120 changes: 88 additions & 32 deletions mod/function/SingleFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<mod::TrapdoorMod>();
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<mod::TrapdoorMod>();
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<mod::TrapdoorMod>();
if (!modInstance->getSingFunction().preventNCUpdate)
original(source, pos);
}
}
this, pos
);
*/

THook(
void,
MSSYM_B1QE17updateNeighborsAtB1AE11BlockSourceB2AAE17QEAAXAEBVBlockPosB3AAAA1Z,
trapdoor::BlockSource *source, trapdoor::BlockPos *pos) {
auto modInstance = trapdoor::bdsMod->asInstance<mod::TrapdoorMod>();
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<mod::TrapdoorMod>();
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<mod::TrapdoorMod>();
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<mod::TrapdoorMod>();
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<mod::TrapdoorMod>();
int gauss = modInstance->getSingFunction().gaussRnd;
if (gauss <= 0) {
return 0;
}
return original(random) / gauss;
}

} // namespace mod

0 comments on commit 6f5a328

Please sign in to comment.