Skip to content

Commit

Permalink
write hardcoded mem offfset to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Mar 25, 2021
1 parent 47efe44 commit 21de1fb
Show file tree
Hide file tree
Showing 19 changed files with 252 additions and 366 deletions.
9 changes: 4 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ add_library(${MOD_API_NAME} STATIC
api/world/LevelChunk.cpp
api/language/I18nManager.cpp
api/language/I18nManager.h
api/tools/CastHelper.h)
api/tools/CastHelper.h
api/Offset.h
)

target_include_directories(${MOD_API_NAME}
PUBLIC
Expand All @@ -62,7 +64,7 @@ target_link_libraries(${MOD_API_NAME} ${PROJECT_SOURCE_DIR}/api/lib/detours.lib)
####################这里是具体功能##########################
set(TRAPDOOR_VERSION 0.9.42)
set(MCBE_VERSION 1.16.40.2)
set(BETA OFF)
set(BETA OFF)

add_definitions(-DTD_VERSION="${TRAPDOOR_VERSION}")
add_definitions(-DMC_VERSION="${MCBE_VERSION}")
Expand All @@ -86,13 +88,10 @@ add_library(${MOD_NAME}
mod/tick/SimpleProfiler.cpp
mod/tick/ActorProfiler.cpp
mod/spawn/SpawnHelper.cpp
mod/spawn/SpawnAnalyzer.cpp
mod/function/BlockRotationHelper.cpp
mod/player/PlayerFunction.cpp
mod/function/SimpleBuilder.cpp
mod/spawn/SlimeChunkHelper.cpp
mod/player/PlayerStatisticManager.cpp
mod/player/Player.cpp
mod/function/BackupHelper.cpp
mod/os/process_stat.cpp
mod/village/POIInstance.cpp
Expand Down
54 changes: 54 additions & 0 deletions api/Offset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
namespace off {


//!BlockLegacy::getVariant(BlockLegacy *this, char *a2)
constexpr uint64_t BLOCK_GET_VARIANT = 0x8;

//todo:
constexpr uint64_t BLOCKSOURCE_GET_POSITION = 0x2c;

//todo:
constexpr uint64_t BLOCKLEGACY_GET_BLOCK_ID = 0x10c;

//todo:
constexpr uint64_t BASECIRCUITCOMPONENT_GET_STRENGTH = 0x34;

//todo
constexpr std::pair<uint64_t, uint64_t> BASECIRCUITCOMPONENT_SOURCE_RANGE = {0x1, 0x2};

//todo
constexpr uint64_t COMMAND_PACKET_STR = 0x28;

//!from Player::tickWorld
constexpr uint64_t PLAYER_GET_BLOCKSOURCE = 0x64;

//todo
constexpr uint64_t ACTOR_GET_DIMENSION_ID = 0xCC;


//! from ServerPlayer::isHostingPlayer
constexpr uint64_t ACTOR_GET_CLIENT_ID = 0x980;

//todo
constexpr uint64_t ACTOR_ID_GET_NAME = 0x20;

//todo
constexpr uint64_t ITEM_GET_NUM = 0x22;

constexpr uint64_t BIOME_GET_NAME = 0x8;

constexpr uint64_t DIMENSION_GET_CIRCUIT_SYSTEM = 0x21;

constexpr uint64_t CIRCUIT_GET_GRAPH = 0x8;

constexpr uint64_t DIMENSION_IS_RS_TICK = 0x45;
//! Spawner::_spawnMobCluster
constexpr uint64_t MOB_SPAWN_DATA_GET_RULE = 0xb0;

constexpr std::pair<uint64_t, uint64_t> LEVEL_FOREACH_PLAYER = {0xB, 0xC};

//!MobSpawnData::MobSpawnData
constexpr uint64_t MOB_SPAWN_DATA_GET_ACTOR_ID = 0x8;


};
12 changes: 4 additions & 8 deletions api/block/Block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "block/BlockLegacy.h"
#include "tools/DirtyLogger.h"
#include "tools/CastHelper.h"
#include "Offset.h"

namespace trapdoor {
using namespace SymHook;
Expand Down Expand Up @@ -40,20 +41,15 @@ namespace trapdoor {

//获取特殊值
int Block::getVariant() {
//! from BlockLegacy::getVariant(BlockLegacy *this, char *a2)
return *offset_cast<char *>(this, 8);

return *offset_cast<char *>(this, off::BLOCK_GET_VARIANT);
}

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


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

4 changes: 2 additions & 2 deletions api/block/BlockLegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "lib/mod.h"
#include "lib/SymHook.h"
#include "tools/CastHelper.h"
#include "Offset.h"

namespace trapdoor {
using namespace SymHook;
Expand All @@ -32,8 +33,7 @@ namespace trapdoor {
}

BlockType BlockLegacy::getBlockID() {
return (BlockType) *offset_cast<short *>(this, 268);
// return (BlockType) *(short *) ((char *) this + 268);
return (BlockType) *offset_cast<short *>(this, off::BLOCKLEGACY_GET_BLOCK_ID);
}
}

57 changes: 5 additions & 52 deletions api/block/CircuitComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,25 @@
#include "tools/MsgBuilder.h"
#include "CastHelper.h"
#include "BlockSource.h"
#include "Offset.h"

namespace trapdoor {

//获取能量等级
int BaseCircuitComponent::getStrength() {
return *offset_cast<int *>(this, 52);
//return *((uint32_t *) this + 13);
return *offset_cast<int *>(this, off::BASECIRCUITCOMPONENT_GET_STRENGTH);
}

// int BaseCircuitComponent::getVar2() {
// return *((uint64_t *) this + 2);
//
// }

//打印信号源等信息
void BaseCircuitComponent::basePrint(CircuitSceneGraph *graph, trapdoor::Actor *player) {
MessageBuilder builder;
std::string stringBuilder;
stringBuilder += trapdoor::format("Signal " C_INT, this->getStrength());
builder.text("Signal: ").num(this->getStrength());
auto begin = (uint32_t *) *((uint64_t *) this + 1);
auto end = (uint32_t *) *((uint64_t *) this + 2);
//todo rewrite
auto begin = (uint32_t *) *((uint64_t *) this + off::BASECIRCUITCOMPONENT_SOURCE_RANGE.first);
auto end = (uint32_t *) *((uint64_t *) this + off::BASECIRCUITCOMPONENT_SOURCE_RANGE.second);
int num = 0;
std::string particleType = "minecraft:silverfish_grief_emitter";
trapdoor::Vec3 vec3{};
Expand All @@ -54,50 +51,6 @@ namespace trapdoor {
trapdoor::info(player, stringBuilder);
}

//获取火把的燃烧情况
// int BaseCircuitComponent::getPowerCount() {
// return (int) *((int *) this + 20);
// }

// //是否接受半脉冲
// void BaseCircuitComponent::setAcceptHalfPulse() {
// *((char *) this + 67) = 1;
// }


//是否接受半脉冲
// 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::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);
// }


//从电路图中获取电路组件
BaseCircuitComponent *CircuitSceneGraph::getBaseCircuitComponent(BlockPos *pos) {
Expand Down
3 changes: 2 additions & 1 deletion api/commands/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "BDSMod.h"
#include "tools/DirtyLogger.h"
#include "CommandNode.h"
#include "Offset.h"

namespace trapdoor {
//注册命令
Expand Down Expand Up @@ -92,7 +93,7 @@ THook(
}

//! 这是一处强制转换
auto *commandString = reinterpret_cast<std::string *>((char *) commandPacket + 40);
auto *commandString = reinterpret_cast<std::string *>((char *) commandPacket + off::COMMAND_PACKET_STR);
L_DEBUG("player %s execute command %s", source->getNameTag().c_str(), commandString->c_str());
//截获命令数据包,获取命令字符串,如果是插件自定义的命令就直接处理,屏蔽原版,如果不是自定义命令就转发给原版去处理
auto &commandManager = trapdoor::bdsMod->getCommandManager();
Expand Down
16 changes: 5 additions & 11 deletions api/entity/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
//

#include <bitset>
#include <map>

#include "Actor.h"
#include "lib/mod.h"
#include "tools/MsgBuilder.h"
#include "tools/Message.h"
#include "block/Block.h"
#include "world/Biome.h"
#include "PlayerInventory.h"
#include "block/BlockSource.h"
#include "Dimension.h"
#include "tools/DirtyLogger.h"
#include "tools/CastHelper.h"
#include "Offset.h"

namespace trapdoor {

Expand Down Expand Up @@ -57,7 +53,7 @@ namespace trapdoor {
BlockSource *Actor::getBlockSource() {
//!from Player::tickWorld
// return offset_cast<BlockSource *>(this, 100);
return *((struct BlockSource **) this + 100);
return *((struct BlockSource **) this + off::PLAYER_GET_BLOCKSOURCE);
}

void Actor::setGameMode(int mode) {
Expand All @@ -70,8 +66,7 @@ namespace trapdoor {


int Actor::getDimensionID() {
return *offset_cast<int *>(this, 204);
// return *(reinterpret_cast<int *>(this) + 51);
return *offset_cast<int *>(this, off::ACTOR_GET_DIMENSION_ID);
}

Dimension *Actor::getDimension() {
Expand All @@ -89,8 +84,7 @@ namespace trapdoor {

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

PlayerPermissionLevel Actor::getCommandLevel() {
Expand Down Expand Up @@ -150,7 +144,7 @@ namespace trapdoor {
}

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

Expand Down
5 changes: 2 additions & 3 deletions api/entity/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "lib/SymHook.h"
#include "tools/DirtyLogger.h"
#include "tools/CastHelper.h"

#include "Offset.h"
namespace trapdoor {
using namespace SymHook;

Expand All @@ -26,8 +26,7 @@ namespace trapdoor {
}

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

void ItemStackBase::setNull() {
Expand Down
4 changes: 1 addition & 3 deletions api/entity/PlayerInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ namespace trapdoor {
MSSYM_B1QE15getSelectedSlotB1AE15PlayerInventoryB2AAA4QEBAB1QE10AUSlotDataB1AA11B1AA2XZ,
this
);
//这个api是有问题的
//return 0;
return *(int *) (ptr + 4);
return 0;
}

void FillingContainer::clearSlot(int idx) {
Expand Down
3 changes: 0 additions & 3 deletions api/lib/Offset.h

This file was deleted.

4 changes: 2 additions & 2 deletions api/world/Biome.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

#include "lib/mod.h"
#include "lib/SymHook.h"

#include "Offset.h"

namespace trapdoor {
using namespace SymHook;

std::string Biome::getBiomeName() {
char *str = reinterpret_cast<char *>(this) + 8;
char *str = reinterpret_cast<char *>(this) + off::BIOME_GET_NAME;
return std::string(str);
}

Expand Down
12 changes: 5 additions & 7 deletions api/world/Dimension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Dimension.h"
#include <cstdio>
#include "tools/DirtyLogger.h"

#include "Offset.h"
namespace trapdoor {
//打印维度上限,目前没屌用
void Dimension::printBaseTypeLimit() {
Expand All @@ -20,15 +20,13 @@ namespace trapdoor {

CircuitSceneGraph *Dimension::getGraph() {
//这种代码真的写的人瘆得慌
//from Dimension::tickRedstone(Dimension *this)
uint64_t *circuitSystem = reinterpret_cast<uint64_t *>(this) + 33;
return reinterpret_cast<CircuitSceneGraph *> (*circuitSystem + 8);
//!from Dimension::tickRedstone(Dimension *this)
uint64_t *circuitSystem = reinterpret_cast<uint64_t *>(this) + off::DIMENSION_GET_CIRCUIT_SYSTEM;
return reinterpret_cast<CircuitSceneGraph *> (*circuitSystem + off::CIRCUIT_GET_GRAPH);
}

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);
return *((uint32_t *) this + off::DIMENSION_IS_RS_TICK) == 1;
}
}
5 changes: 3 additions & 2 deletions api/world/Level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#include "lib/SymHook.h"
#include "tools/DirtyLogger.h"
#include "Block.h"
#include "Offset.h"

namespace trapdoor {
using namespace SymHook;

void Level::forEachPlayer(const std::function<void(Actor *)> &todo) {
//!硬编码
auto begin = (uint64_t *) *((uint64_t *) this + 11);
auto end = (uint64_t *) *((uint64_t *) this + 12);
auto begin = (uint64_t *) *((uint64_t *) this + off::LEVEL_FOREACH_PLAYER.first);
auto end = (uint64_t *) *((uint64_t *) this + off::LEVEL_FOREACH_PLAYER.second);
while (begin != end) {
auto *player = (Actor *) (*begin);
if (player)todo(player);
Expand Down
Loading

0 comments on commit 21de1fb

Please sign in to comment.