Skip to content

Commit

Permalink
modify some api
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Feb 20, 2021
1 parent f02ba1b commit 77008c7
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 70 deletions.
16 changes: 8 additions & 8 deletions api/block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace trapdoor {
return debugStr.erase(0, 6);
}


//是否是空气
bool Block::isAir() {
return this->getLegacy()->getBlockID() == AIR;
Expand All @@ -42,18 +41,19 @@ namespace trapdoor {
//获取特殊值
int Block::getVariant() {
//! from BlockLegacy::getVariant(BlockLegacy *this, char *a2)
return reinterpret_cast<char *>(this)[8];
return *offset_cast<char *>(this, 8);
}


//获取方块实体的位置
BlockPos *BlockActor::getPosition() {
return reinterpret_cast<BlockPos *>(reinterpret_cast<VA>(this) + 44);
return offset_cast<BlockPos *>(this, 44);
//return reinterpret_cast<BlockPos *>(reinterpret_cast<VA>(this) + 44);
}


//获取方块实体内的方块对象
Block *BlockActor::getBlock() {
return *reinterpret_cast<Block **>(reinterpret_cast<char *>(this) + 2);
}
// //获取方块实体内的方块对象
// Block *BlockActor::getBlock() {
// return *reinterpret_cast<Block **>(reinterpret_cast<char *>(this) + 2);
// }
}

2 changes: 1 addition & 1 deletion api/block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace trapdoor {
BlockPos *getPosition();

//获取方块对象
Block *getBlock();
// Block *getBlock();
};

}
Expand Down
11 changes: 2 additions & 9 deletions api/block/BlockLegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
// }

}

//获取某个特殊值状态下的方块对象
Expand All @@ -39,7 +32,7 @@ namespace trapdoor {
}

BlockType BlockLegacy::getBlockID() {
return (BlockType) *offset_cast<short>(this, 268);
return (BlockType) *offset_cast<short *>(this, 268);
// return (BlockType) *(short *) ((char *) this + 268);
}
}
Expand Down
68 changes: 35 additions & 33 deletions api/block/CircuitComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int *>(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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
// }


//从电路图中获取电路组件
Expand Down
12 changes: 6 additions & 6 deletions api/block/CircuitComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

//红石电路图组件
Expand Down
18 changes: 11 additions & 7 deletions api/entity/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "block/BlockSource.h"
#include "Dimension.h"
#include "tools/DirtyLogger.h"
#include "tools/CastHelper.h"

namespace trapdoor {

Expand Down Expand Up @@ -55,6 +56,7 @@ namespace trapdoor {

BlockSource *Actor::getBlockSource() {
//!from Player::tickWorld
// return offset_cast<BlockSource *>(this, 100);
return *((struct BlockSource **) this + 100);
}

Expand All @@ -68,8 +70,8 @@ namespace trapdoor {


int Actor::getDimensionID() {

return *(reinterpret_cast<int *>(this) + 51);
return *offset_cast<int *>(this, 204);
// return *(reinterpret_cast<int *>(this) + 51);
}

Dimension *Actor::getDimension() {
Expand All @@ -86,8 +88,9 @@ namespace trapdoor {
}

NetworkIdentifier *Actor::getClientID() {
// ServerPlayer::isHostingPlayer
return reinterpret_cast<NetworkIdentifier *>((char *) this + 2432);
//! from ServerPlayer::isHostingPlayer
return offset_cast<NetworkIdentifier *>(this, 2432);
// return reinterpret_cast<NetworkIdentifier *>((char *) this + 2432);
}

PlayerPermissionLevel Actor::getCommandLevel() {
Expand All @@ -113,8 +116,9 @@ namespace trapdoor {
}

//from: Actor::getLevel
Level *Actor::getLevel() {
return *reinterpret_cast<trapdoor::Level **>((VA) this + 816);
Level *Actor::getLevel() { //NOLINT
return bdsMod->getLevel();
// return *reinterpret_cast<trapdoor::Level **>((VA) this + 816);
}

std::string Actor::getActorId() {
Expand Down Expand Up @@ -146,7 +150,7 @@ namespace trapdoor {
}

std::string ActorDefinitionIdentifier::getName() {
auto str = reinterpret_cast<std::string *>((char *) this + 32);
auto str = offset_cast<std::string *>(this, 32);
return std::string(*str);
}

Expand Down
6 changes: 5 additions & 1 deletion api/entity/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +25,10 @@ namespace trapdoor {
return name;
}

int ItemStackBase::getNum() { return (int) *((unsigned char *) this + 34); }
int ItemStackBase::getNum() {
return *offset_cast<char *>(this, 34);
// return (int) *((unsigned char *) this + 34);
}

void ItemStackBase::setNull() {
SYM_CALL(void(*)(ItemStackBase * ),
Expand Down
3 changes: 3 additions & 0 deletions api/lib/Offset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace trapdoor {

}
10 changes: 8 additions & 2 deletions api/tools/CastHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@
#include <cstdint>

template<typename T>
T *offset_cast(void *ptr, size_t bytes) {
return reinterpret_cast<T *>(reinterpret_cast<uint8_t *>(ptr) + bytes);
/*
* [ ]
* |<----bytes---->|
* ^ ^
* ptr T
*/
T offset_cast(void *ptr, size_t bytes) {
return reinterpret_cast<T>(reinterpret_cast<uint8_t *>(ptr) + bytes);
}

#endif //MOD_CASTHELPER_H
2 changes: 1 addition & 1 deletion lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion mod/TrapdoorMod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
44 changes: 44 additions & 0 deletions trapdoor-disclaimer.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion 更新日志.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## 1.16.4-0.9.4
### 开发
- 增加测试
- 正事移除玩家行为统计
- 正式移除玩家行为统计
### bug修复
- 修复一堆文字错误

Expand Down

0 comments on commit 77008c7

Please sign in to comment.