From 77008c7dd47e835e453bbf099a8d91fd0036a011 Mon Sep 17 00:00:00 2001 From: hhhxiao <1417599491@qq.com> Date: Sat, 20 Feb 2021 16:45:00 +0800 Subject: [PATCH] modify some api --- api/block/Block.cpp | 16 ++--- api/block/Block.h | 2 +- api/block/BlockLegacy.cpp | 11 +-- api/block/CircuitComponent.cpp | 68 ++++++++++--------- api/block/CircuitComponent.h | 12 ++-- api/entity/Actor.cpp | 18 +++-- api/entity/Item.cpp | 6 +- api/lib/Offset.h | 3 + api/tools/CastHelper.h | 10 ++- lang/en_us.json | 2 +- mod/TrapdoorMod.cpp | 5 +- trapdoor-disclaimer.md | 44 ++++++++++++ ...64\346\226\260\346\227\245\345\277\227.md" | 2 +- 13 files changed, 129 insertions(+), 70 deletions(-) create mode 100644 api/lib/Offset.h create mode 100644 trapdoor-disclaimer.md diff --git a/api/block/Block.cpp b/api/block/Block.cpp index 5f8522c..06b0172 100644 --- a/api/block/Block.cpp +++ b/api/block/Block.cpp @@ -33,7 +33,6 @@ namespace trapdoor { return debugStr.erase(0, 6); } - //是否是空气 bool Block::isAir() { return this->getLegacy()->getBlockID() == AIR; @@ -42,18 +41,19 @@ namespace trapdoor { //获取特殊值 int Block::getVariant() { //! from BlockLegacy::getVariant(BlockLegacy *this, char *a2) - return reinterpret_cast(this)[8]; + return *offset_cast(this, 8); } - //获取方块实体的位置 BlockPos *BlockActor::getPosition() { - return reinterpret_cast(reinterpret_cast(this) + 44); + return offset_cast(this, 44); + //return reinterpret_cast(reinterpret_cast(this) + 44); } - //获取方块实体内的方块对象 - Block *BlockActor::getBlock() { - return *reinterpret_cast(reinterpret_cast(this) + 2); - } +// //获取方块实体内的方块对象 +// Block *BlockActor::getBlock() { +// return *reinterpret_cast(reinterpret_cast(this) + 2); +// } } + diff --git a/api/block/Block.h b/api/block/Block.h index a54b557..e3a1448 100644 --- a/api/block/Block.h +++ b/api/block/Block.h @@ -42,7 +42,7 @@ namespace trapdoor { BlockPos *getPosition(); //获取方块对象 - Block *getBlock(); + // Block *getBlock(); }; } diff --git a/api/block/BlockLegacy.cpp b/api/block/BlockLegacy.cpp index ac18bf3..b5a8689 100644 --- a/api/block/BlockLegacy.cpp +++ b/api/block/BlockLegacy.cpp @@ -19,14 +19,7 @@ namespace trapdoor { this, vector ); return "this api was removed"; -// int i = 0; -// for (const auto &str:vector) { -// printf("%d: %s ", i, str.c_str()); -// ++i; -// } -// printf("\n"); -// return std::string("text"); -// } + } //获取某个特殊值状态下的方块对象 @@ -39,7 +32,7 @@ namespace trapdoor { } BlockType BlockLegacy::getBlockID() { - return (BlockType) *offset_cast(this, 268); + return (BlockType) *offset_cast(this, 268); // return (BlockType) *(short *) ((char *) this + 268); } } diff --git a/api/block/CircuitComponent.cpp b/api/block/CircuitComponent.cpp index c7b14d1..d8d35b1 100644 --- a/api/block/CircuitComponent.cpp +++ b/api/block/CircuitComponent.cpp @@ -10,19 +10,21 @@ #include "graphics/Particle.h" #include "tools/Message.h" #include "tools/MsgBuilder.h" +#include "CastHelper.h" +#include "BlockSource.h" namespace trapdoor { //获取能量等级 int BaseCircuitComponent::getStrength() { - return *((uint32_t *) this + 13); + return *offset_cast(this, 52); + //return *((uint32_t *) this + 13); } - - int BaseCircuitComponent::getVar2() { - return *((uint64_t *) this + 2); - - } +// int BaseCircuitComponent::getVar2() { +// return *((uint64_t *) this + 2); +// +// } //打印信号源等信息 void BaseCircuitComponent::basePrint(CircuitSceneGraph *graph, trapdoor::Actor *player) { @@ -53,9 +55,9 @@ namespace trapdoor { } //获取火把的燃烧情况 - int BaseCircuitComponent::getPowerCount() { - return (int) *((int *) this + 20); - } +// int BaseCircuitComponent::getPowerCount() { +// return (int) *((int *) this + 20); +// } // //是否接受半脉冲 // void BaseCircuitComponent::setAcceptHalfPulse() { @@ -64,37 +66,37 @@ namespace trapdoor { //是否接受半脉冲 - int BaseCircuitComponent::getAcceptHalfPulse() { - return (int) *((char *) this + 67); - } +// int BaseCircuitComponent::getAcceptHalfPulse() { +// return (int) *((char *) this + 67); +// } //打印中继器相关信息 - void BaseCircuitComponent::printRepeater() { - int *ptr = (int *) this; -// info("repeater: %d %d %d %d s: %d", ptr[21], ptr[20], ptr[19], ptr[18], ((char *) this)[96]); - } +// void BaseCircuitComponent::printRepeater() { +// int *ptr = (int *) this; +//// info("repeater: %d %d %d %d s: %d", ptr[21], ptr[20], ptr[19], ptr[18], ((char *) this)[96]); +// } //打印火把相关信息 - void BaseCircuitComponent::printTorch(BlockPos pos) { - int selfPowerCount = (int) *((int *) this + 20); - auto strength = (char) *((char *) this + 84); - bool flag; -// int signal = SYM_CALL( -// int(*)(BaseCircuitComponent * ,const BlockPos *pos,void *circuitSystem,bool *), -// MSSYM_B1QE21FindStrongestStrengthB1AE22RedstoneTorchCapacitorB2AAE17AEAAHAEBVBlockPosB2AAE17AEAVCircuitSystemB2AAA3AEAB1UA1NB1AA1Z, -// this, &pos, -// globalCircuitSystem, -// &flag -// ); -// info("torch: bc: %d s: %d hp: %d", selfPowerCount, strength, getHalfPulse()); - // info("%d %d", signal, flag); - } +// void BaseCircuitComponent::printTorch(BlockPos pos) { +// int selfPowerCount = (int) *((int *) this + 20); +// auto strength = (char) *((char *) this + 84); +// bool flag; +//// int signal = SYM_CALL( +//// int(*)(BaseCircuitComponent * ,const BlockPos *pos,void *circuitSystem,bool *), +//// MSSYM_B1QE21FindStrongestStrengthB1AE22RedstoneTorchCapacitorB2AAE17AEAAHAEBVBlockPosB2AAE17AEAVCircuitSystemB2AAA3AEAB1UA1NB1AA1Z, +//// this, &pos, +//// globalCircuitSystem, +//// &flag +//// ); +//// info("torch: bc: %d s: %d hp: %d", selfPowerCount, strength, getHalfPulse()); +// // info("%d %d", signal, flag); +// } //是否接受半脉冲 - int BaseCircuitComponent::getHalfPulse() { - return (int) *((char *) this + 85); - } +// int BaseCircuitComponent::getHalfPulse() { +// return (int) *((char *) this + 85); +// } //从电路图中获取电路组件 diff --git a/api/block/CircuitComponent.h b/api/block/CircuitComponent.h index 6bbe51a..4109b5f 100644 --- a/api/block/CircuitComponent.h +++ b/api/block/CircuitComponent.h @@ -15,19 +15,19 @@ namespace trapdoor { public: int getStrength(); - int getVar2(); + //int getVar2(); - int getPowerCount(); + // int getPowerCount(); - int getAcceptHalfPulse(); + // int getAcceptHalfPulse(); - int getHalfPulse(); + // int getHalfPulse(); void basePrint(CircuitSceneGraph *graph, trapdoor::Actor *player); - void printRepeater(); + // void printRepeater(); - void printTorch(BlockPos blockPos); + // void printTorch(BlockPos blockPos); }; //红石电路图组件 diff --git a/api/entity/Actor.cpp b/api/entity/Actor.cpp index 9a1a452..869a46e 100644 --- a/api/entity/Actor.cpp +++ b/api/entity/Actor.cpp @@ -15,6 +15,7 @@ #include "block/BlockSource.h" #include "Dimension.h" #include "tools/DirtyLogger.h" +#include "tools/CastHelper.h" namespace trapdoor { @@ -55,6 +56,7 @@ namespace trapdoor { BlockSource *Actor::getBlockSource() { //!from Player::tickWorld + // return offset_cast(this, 100); return *((struct BlockSource **) this + 100); } @@ -68,8 +70,8 @@ namespace trapdoor { int Actor::getDimensionID() { - - return *(reinterpret_cast(this) + 51); + return *offset_cast(this, 204); + // return *(reinterpret_cast(this) + 51); } Dimension *Actor::getDimension() { @@ -86,8 +88,9 @@ namespace trapdoor { } NetworkIdentifier *Actor::getClientID() { - // ServerPlayer::isHostingPlayer - return reinterpret_cast((char *) this + 2432); + //! from ServerPlayer::isHostingPlayer + return offset_cast(this, 2432); + // return reinterpret_cast((char *) this + 2432); } PlayerPermissionLevel Actor::getCommandLevel() { @@ -113,8 +116,9 @@ namespace trapdoor { } //from: Actor::getLevel - Level *Actor::getLevel() { - return *reinterpret_cast((VA) this + 816); + Level *Actor::getLevel() { //NOLINT + return bdsMod->getLevel(); + // return *reinterpret_cast((VA) this + 816); } std::string Actor::getActorId() { @@ -146,7 +150,7 @@ namespace trapdoor { } std::string ActorDefinitionIdentifier::getName() { - auto str = reinterpret_cast((char *) this + 32); + auto str = offset_cast(this, 32); return std::string(*str); } diff --git a/api/entity/Item.cpp b/api/entity/Item.cpp index c81c6c6..d7a9ed6 100644 --- a/api/entity/Item.cpp +++ b/api/entity/Item.cpp @@ -11,6 +11,7 @@ #include "lib/mod.h" #include "lib/SymHook.h" #include "tools/DirtyLogger.h" +#include "tools/CastHelper.h" namespace trapdoor { using namespace SymHook; @@ -24,7 +25,10 @@ namespace trapdoor { return name; } - int ItemStackBase::getNum() { return (int) *((unsigned char *) this + 34); } + int ItemStackBase::getNum() { + return *offset_cast(this, 34); + // return (int) *((unsigned char *) this + 34); + } void ItemStackBase::setNull() { SYM_CALL(void(*)(ItemStackBase * ), diff --git a/api/lib/Offset.h b/api/lib/Offset.h new file mode 100644 index 0000000..df6cbef --- /dev/null +++ b/api/lib/Offset.h @@ -0,0 +1,3 @@ +namespace trapdoor { + +} \ No newline at end of file diff --git a/api/tools/CastHelper.h b/api/tools/CastHelper.h index fe14356..6595767 100644 --- a/api/tools/CastHelper.h +++ b/api/tools/CastHelper.h @@ -8,8 +8,14 @@ #include template -T *offset_cast(void *ptr, size_t bytes) { - return reinterpret_cast(reinterpret_cast(ptr) + bytes); +/* + * [ ] + * |<----bytes---->| + * ^ ^ + * ptr T + */ +T offset_cast(void *ptr, size_t bytes) { + return reinterpret_cast(reinterpret_cast(ptr) + bytes); } #endif //MOD_CASTHELPER_H diff --git a/lang/en_us.json b/lang/en_us.json index 22485a6..e9433d1 100644 --- a/lang/en_us.json +++ b/lang/en_us.json @@ -38,7 +38,7 @@ "command.village.b.set": "Set the village border display as: %d", "command.village.p.desc": "Display POI query range", "command.village.p.set": "Set the POI query range to: %d", - "command.village.s.desc": "Display the refresh area of ​​the iron golem", + "command.village.s.desc": "Display the refresh area of spawn the iron golem", "command.village.s.set": "Set the refresh area for displaying iron golems as: %d", "command.village.c.desc": "Show Village Center", "command.village.c.set": "Set the display village center to", diff --git a/mod/TrapdoorMod.cpp b/mod/TrapdoorMod.cpp index 0fc05fc..0bbf052 100644 --- a/mod/TrapdoorMod.cpp +++ b/mod/TrapdoorMod.cpp @@ -229,10 +229,13 @@ namespace mod { // this->simpleLitematica.getSelectRegion().setPos2(pos, player); } else if (itemName == "Stick") { this->playerFunctions.printRedstoneInfo(player, pos); + auto *block = player->getBlockSource()->getBlock(pos); + printf("id:%d name:%s variant:%d\n", block->getLegacy()->getBlockID(), block->getName().c_str(), + block->getVariant()); + fflush(stdout); } } - CommandPermissionLevel TrapdoorMod::resetVanillaCommandLevel( const std::string &name, CommandPermissionLevel oldLevel) { diff --git a/trapdoor-disclaimer.md b/trapdoor-disclaimer.md new file mode 100644 index 0000000..f67d473 --- /dev/null +++ b/trapdoor-disclaimer.md @@ -0,0 +1,44 @@ +## 免责声明 + +trapdoor-mod(以下简称td)是一个利用dll远程注入技术开发的BDS辅助插件,它提供了不少 +方便玩家的功能,给生电玩家创造了便利。 + +除此之外,td本身是开源免费的,内部没有任何恶意代码,原则上也不会对存档造成任何损害。 + +但是考虑到此类软件的特殊性,开发者也不能完全保证td对用户的存档不造成任何破坏,万一发生 +意外情况,开发者不会也没有能力对td对用户造成的损失负责。 + +如果你继续使用td插件,那么就代表你同意了该声明(或者说叫用户协议),如果你不想承担此类 +风险,请停止使用td插件。 + +附录: +以下是一些使用建议: + - 及时更新插件到新版本,因为目前td还是beta版,越更新bug肯方定会越少 + - 尽量关闭不用的功能 + - 及时备份存档永远是好习惯 + +2021.1.23 + +## Disclaimer + +trapdoor-mod (hereinafter referred to as td) is a BDS auxiliary plug-in developed by dll remote injection technology, +which provides many functions that are convenient for players. + +In addition, td itself is open source and free, there is no malicious code inside, and in principle it will not cause +any damage to the archive. + +However, considering the particularity of such software, the developer cannot completely guarantee that td will not +cause any damage to the user's level, in case it happens. In unexpected circumstances, developers will not and cannot +be responsible for the losses caused by td to users. + +If you continue to use the td plug-in, then by default you agree to this disclaimer(or user agreement), if you do not +want to bear such risk, please stop using td plugin. + +appendix: +Here are some suggestions for use: + - Update the plug-in to the new version in time, because the td is still a beta version, the more you update it, the + less bugs you can expect + - Try to turn off unused functions + - Timely backup and archive is always a good habit + +2021.1.23 \ No newline at end of file diff --git "a/\346\233\264\346\226\260\346\227\245\345\277\227.md" "b/\346\233\264\346\226\260\346\227\245\345\277\227.md" index 7353c77..514784d 100644 --- "a/\346\233\264\346\226\260\346\227\245\345\277\227.md" +++ "b/\346\233\264\346\226\260\346\227\245\345\277\227.md" @@ -1,7 +1,7 @@ ## 1.16.4-0.9.4 ### 开发 - 增加测试 -- 正事移除玩家行为统计 +- 正式移除玩家行为统计 ### bug修复 - 修复一堆文字错误