Skip to content

Commit

Permalink
0.9.22 update
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Jan 30, 2021
1 parent 2ddb00a commit 03b2751
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 85 deletions.
20 changes: 18 additions & 2 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ add_library(${MOD_API_NAME} STATIC
api/tools/Message.cpp
api/tools/MsgBuilder.cpp
api/tools/ThreadPool.h
api/world/LevelChunk.cpp
"api/tools/noncopyable .h")
api/world/LevelChunk.cpp)
target_include_directories(${MOD_API_NAME}
PUBLIC
api
Expand All @@ -58,7 +57,7 @@ add_library(${MOD_NAME}
SHARED
mod/dllmain.cpp
mod/TrapdoorMod.cpp
mod/function/Explosion.cpp
mod/function/SingleFunctions.cpp
mod/hopper/HopperCounter.cpp
mod/config/ConfigManager.cpp
mod/village/Village.cpp
Expand Down
2 changes: 1 addition & 1 deletion api/block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ THook(
) {
if (trapdoor::bdsMod && !trapdoor::bdsMod->getPalette()) {
trapdoor::bdsMod->setBlockPalette(palette);
L_INFO("set block palette");
// L_INFO("set block palette");
}
original(palette, id);
}
7 changes: 7 additions & 0 deletions api/world/Dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ namespace trapdoor {
uint64_t *circuitSystem = reinterpret_cast<uint64_t *>(this) + 33;
return reinterpret_cast<CircuitSceneGraph *> (*circuitSystem + 8);
}

bool Dimension::isRedstoneTick() {
//为1是红石刻2是非红石刻
return *((uint32_t *) this + 69) == 1;
// auto v2 = *((uint32_t *) this + 68); //恒定为2,也就是多少gt才过一个红石刻
// printf("%d %d\n", v1, v2);
}
}
3 changes: 2 additions & 1 deletion api/world/Dimension.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ namespace trapdoor {
void printBaseTypeLimit();

CircuitSceneGraph *getGraph();
};

bool isRedstoneTick();
};

}

Expand Down
68 changes: 31 additions & 37 deletions mod/TrapdoorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

namespace mod {
void TrapdoorMod::heavyTick() {

this->villageHelper.tick();
this->hsaManager.tick();
this->spawnHelper.tick();
Expand All @@ -29,7 +28,7 @@ namespace mod {

void TrapdoorMod::lightTick() {
this->hopperChannelManager.tick();
this->spawnAnalyzer.tick();
// this->spawnAnalyzer.tick();
}

//这个函数会在初始化Level对象后执行
Expand All @@ -40,7 +39,8 @@ namespace mod {
mod::initBackup();
this->villageHelper.setConfig(this->configManager.getVillageConfig());
get_cpu_usage();
L_INFO("==== trapdoor init finish ====\n Server Start");
this->initFunctionEnable();
L_INFO("==== trapdoor init finish ====\nServer Start");
}

void TrapdoorMod::registerCommands() {
Expand All @@ -58,46 +58,34 @@ namespace mod {
//功能开关命令
commandManager.registerCmd("func", "开启/关闭部分功能")
->then(ARG("hopper", "开启/关闭漏斗计数器", BOOL, {
if (!this->configManager.getFunctionConfig().hopperCounter) {
error(player, "该功能已被关闭,请联系服主");
return;
}
this->hopperChannelManager.setAble(holder->getBool());
info(player, "设置漏斗计数器为 %d", holder->getBool());
}))
->then(ARG("spawn", "开启/关闭刷怪指示", BOOL, {
if (!this->configManager.getFunctionConfig().spawnHelper) {
error(player, "该功能已被关闭,请联系服主");
return;
}

this->spawnHelper.setAble(holder->getBool());
info(player, "设置刷怪指示器为 %d", holder->getBool());
}))
->then(ARG("rotate", "开启/关闭转方块", BOOL, {
if (!configManager.getFunctionConfig().cactusRotation) {
error(player, "该功能已被关闭,请联系服主");
return;
}
this->rotationHelper.setAble(holder->getBool());
info(player, "设置仙人掌转方块为 %d", holder->getBool());
}))
->then(ARG("draw", "开启/关闭区块draw命令", BOOL, {
if (!configManager.getFunctionConfig().simpleDraw) {
error(player, "该功能已被关闭,请联系服主");
return;
}
this->simpleBuilder.setAble(holder->getBool());
info(player, "设置简单建造为 %d", holder->getBool());
}))
->then(ARG("stat", "开启/关闭玩家行为统计", BOOL, {
if (!configManager.getFunctionConfig().playerStat) {
error(player, "该功能已被关闭,请联系服主");
return;
}
this->playerStatisticManager.setAble(holder->getBool());
info(player, "设置玩家行为统计为 %d", holder->getBool());
}))
->then(ARG("expl", "开启/关闭爆炸破坏地形", BOOL, {
this->singleFunctions.preventExplosion = holder->getBool();
info(player, "设置爆炸破坏地形 %d", holder->getBool());
}))
->then(ARG("ncud", "开启/关闭阻止NE更新", BOOL, {
this->singleFunctions.preventNCUpdate = holder->getBool();
info(player, "设置阻止NC更新为 %d", holder->getBool());
}));

//史莱姆显示
commandManager.registerCmd("slime", "史莱姆区块相关")
->then(ARG("show", "显示史莱姆区块", BOOL, {
Expand Down Expand Up @@ -133,12 +121,6 @@ namespace mod {
broadcastMsg("设置玩家[%s]为观察者模式", player->getNameTag().c_str());
});

// commandManager.registerCmd("o", "test")
// ->then(ARG("s", "cc", INT, {
// player->setGameMode(holder->getInt());
// broadcastMsg("设置玩家[%s]为模式 %d", player->getNameTag().c_str(), holder->getInt());
// }));

commandManager.registerCmd("s", "切换到生存模式")
->EXE({
player->setGameMode(0);
Expand Down Expand Up @@ -167,11 +149,11 @@ namespace mod {
}))
->then(ARG("s", "显示铁傀儡刷新区域", BOOL, {
this->villageHelper.setShowGolemSpawnArea(holder->getBool());
info(player, "设置村庄边框显示为 %d", holder->getBool());
info(player, "设置铁傀儡刷怪显示为 %d", holder->getBool());
}))
->then(ARG("c", "显示村庄中心", BOOL, {
this->villageHelper.setShowVillageCenter(holder->getBool());
info(player, "设置村庄边框显示为 %d", holder->getBool());
info(player, "设置村庄中心显示为 %d", holder->getBool());
}))
->then(ARG("v", "显示村民信息", BOOL, {
this->villageHelper.setShowDwellerStatus(holder->getBool());
Expand Down Expand Up @@ -208,7 +190,6 @@ namespace mod {
}))
->then(ARG("draw", "draw hsa", NONE, { hsaManager.draw(player); }));


commandManager.registerCmd("draw", "简单建造")
->then(ARG("ci", "画圆", INT,
{
Expand All @@ -231,6 +212,7 @@ namespace mod {
if (radius < 0) {
error(player, "参数不合法(必须>=1)");
} else {
info(player, "已设置最大半径为%d", radius);
this->simpleBuilder.setMaxRadius(radius);
}
}));
Expand Down Expand Up @@ -266,18 +248,19 @@ namespace mod {
return;
}
this->playerFunctions.getMeasureData(player->getNameTag()).enableMeasure = holder->getBool();
info(player, "设置你的测量开启/关闭 %d", holder->getBool());
info(player, "设置你的测量w为 %d", holder->getBool());
}))
->then(ARG("rs", "测量", BOOL, {
if (!configManager.getSelfEnableConfig().enableRedstoneStick) {
error(player, "该功能已被关闭,请联系服主");
return;
}
this->playerFunctions.setRedstoneHelperAble(player->getNameTag(), holder->getBool());
info(player, "设置你的信号源提示开启/关闭 %d", holder->getBool());
info(player, "设置你的信号源提示为 %d", holder->getBool());
}))
->EXE({ PlayerFunction::printInfo(player); });


commandManager.registerCmd("os", "显示服务器信息")
->EXE({ TrapdoorMod::printOSInfo(player); });
}
Expand All @@ -293,7 +276,7 @@ namespace mod {
if (slowTime > 1 && slowTime <= 64) {
tick::slowTick(slowTime);
} else {
error(player, "number must in [2-64]");
error(player, "放慢倍数必须在 [2-64] 之间");
}
}))
->then(ARG("acc", "加速世界运行[num]倍速", INT, {
Expand All @@ -309,6 +292,9 @@ namespace mod {
}))
->then(ARG("fw", "世界运行步进[num] gt", INT, {
tick::forwardTick(holder->getInt());
}))
->then(ARG("q", "查询当前世界状态", NONE, {
tick::queryStatus(player);
}));

}
Expand Down Expand Up @@ -360,7 +346,6 @@ namespace mod {
}
}


CommandPermissionLevel
TrapdoorMod::resetVanillaCommandLevel(const std::string &name, CommandPermissionLevel oldLevel) {
auto lowLevelConfig = this->configManager.getLowLevelCommands();
Expand Down Expand Up @@ -401,4 +386,13 @@ namespace mod {
return true;
}
}

void TrapdoorMod::initFunctionEnable() {
auto functionCfg = this->configManager.getFunctionConfig();
this->spawnHelper.setAble(functionCfg.spawnHelper);
this->rotationHelper.setAble(functionCfg.cactusRotation);
this->playerStatisticManager.setAble(functionCfg.playerStat);
this->simpleBuilder.setAble(functionCfg.simpleDraw);
this->hopperChannelManager.setAble(functionCfg.hopperCounter);
}
}
10 changes: 9 additions & 1 deletion mod/TrapdoorMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ namespace mod {
const std::string modVersion = "trapdoor-0.9.20";
};

struct SingleFunction {
bool preventExplosion = false;
bool preventNCUpdate = false;
};

class TrapdoorMod : public trapdoor::BDSMod {
private:
SingleFunction singleFunctions;
HopperChannelManager hopperChannelManager;
VillageHelper villageHelper;
HsaManager hsaManager;
Expand All @@ -41,6 +47,7 @@ namespace mod {

void registerTickCommand();

void initFunctionEnable();

public:
ModInfo modeInfo;
Expand All @@ -58,6 +65,7 @@ namespace mod {
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;

Expand All @@ -84,7 +92,7 @@ namespace mod {

inline std::string getLevelName() { return this->configManager.getServerConfig().levelName; }


inline SingleFunction getSingFunction() { return this->singleFunctions; }
};
}

Expand Down
2 changes: 1 addition & 1 deletion mod/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace mod {
try {
auto funcConfig = this->configJson["functionsEnable"];
this->functionConfig.hopperCounter = funcConfig["hopperCounter"].get<bool>();
this->functionConfig.explosion = funcConfig["explosion"].get<bool>();
// this->functionConfig.explosion = funcConfig["explosion"].get<bool>();
this->functionConfig.spawnHelper = funcConfig["spawnHelper"].get<bool>();
this->functionConfig.cactusRotation = funcConfig["cactusRotate"].get<bool>();
this->functionConfig.simpleDraw = funcConfig["simpleDraw"].get<bool>();
Expand Down
17 changes: 0 additions & 17 deletions mod/function/Explosion.cpp

This file was deleted.

40 changes: 40 additions & 0 deletions mod/function/SingleFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Created by xhy on 2020/12/23.
//
#include "lib/mod.h"
#include "lib/SymHook.h"
#include "BDSMod.h"
#include "TrapdoorMod.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,
MSSYM_B1QE17updateNeighborsAtB1AE11BlockSourceB2AAE17QEAAXAEBVBlockPosB3AAAA1Z,
trapdoor::BlockSource *source,
trapdoor::BlockPos * pos
) {
auto modInstance = trapdoor::bdsMod->asInstance<mod::TrapdoorMod>();
if (!modInstance->getSingFunction().preventNCUpdate)
original(source, pos);
}
}
Loading

0 comments on commit 03b2751

Please sign in to comment.