Skip to content

Commit

Permalink
add blockpattle(not in use)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhhxiao committed Jan 26, 2021
1 parent 1d45a12 commit ea8f2f3
Show file tree
Hide file tree
Showing 13 changed files with 363 additions and 284 deletions.
22 changes: 17 additions & 5 deletions .idea/workspace.xml

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

5 changes: 5 additions & 0 deletions api/BDSMod.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,17 @@ namespace trapdoor {
std::map<std::string, PlayerBuffer> playerCache;
ThreadPool *threadPool = nullptr;
ModConfig config;
BlockPalette *palette;
public:

Level *getLevel();

inline BlockPalette *getPalette() { return this->palette; }

void setLevel(Level *level);

inline void setBlockPalette(BlockPalette *p) { this->palette = p; }

CommandRegistry *getCommandRegistry();

void setCommandRegistry(CommandRegistry *registry);
Expand Down
28 changes: 25 additions & 3 deletions api/block/Block.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 "block/BlockLegacy.h"
#include "tools/DirtyLogger.h"

namespace trapdoor {
using namespace SymHook;
Expand Down Expand Up @@ -44,9 +45,6 @@ namespace trapdoor {
}





//获取方块实体的位置
BlockPos *BlockActor::getPosition() {
return reinterpret_cast<BlockPos *>(reinterpret_cast<VA>(this) + 44);
Expand All @@ -57,4 +55,28 @@ namespace trapdoor {
Block *BlockActor::getBlock() {
return *reinterpret_cast<Block **>(reinterpret_cast<VA>(this) + 16);
}

Block *BlockPalette::getBlock(unsigned int type) {
return SYM_CALL(
trapdoor::Block*(*)(trapdoor::BlockPalette * , unsigned int *),
SymHook::MSSYM_B1QA8getBlockB1AE12BlockPaletteB2AAE13QEBAAEBVBlockB2AAA4AEBIB1AA1Z,
this,
&type
);
}
}

using namespace SymHook;

THook(
void,
MSSYM_B1QA8getBlockB1AE12BlockPaletteB2AAE13QEBAAEBVBlockB2AAA4AEBIB1AA1Z,
trapdoor::BlockPalette *palette,
size_t * id
) {
if (trapdoor::bdsMod && !trapdoor::bdsMod->getPalette()) {
trapdoor::bdsMod->setBlockPalette(palette);
L_INFO("set block palette");
}
original(palette, id);
}
14 changes: 13 additions & 1 deletion api/block/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ struct Biome;


namespace trapdoor {
enum BlockType : size_t {
Air = 0,
Dirt = 4
};

/*
* 方块接口
*
*/
class BlockLegacy;

Expand All @@ -30,6 +36,7 @@ namespace trapdoor {
bool isAir();
};


/*
* 方块实体接口
*/
Expand All @@ -41,7 +48,12 @@ namespace trapdoor {
//获取方块对象
Block *getBlock();
};

class BlockPalette {
public:
Block *getBlock(unsigned int type);
};
}
typedef trapdoor::Block Block;
typedef trapdoor::BlockActor BlockActor;

typedef trapdoor::BlockType BlockType;
16 changes: 8 additions & 8 deletions api/entity/PlayerBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
#include "PlayerBuffer.h"

namespace trapdoor {
bool RightClickCache::operator==(const RightClickCache& rhs) const {
if (!(x == rhs.x && y == rhs.y && z == rhs.z))
return false;
return (gameTick - rhs.gameTick) < 4;
}
bool RightClickCache::operator==(const RightClickCache &rhs) const {
if (!(x == rhs.x && y == rhs.y && z == rhs.z))
return false;
return (gameTick - rhs.gameTick) < 4;
}

bool RightClickCache::operator!=(const RightClickCache& rhs) const {
return !(rhs == *this);
}
bool RightClickCache::operator!=(const RightClickCache &rhs) const {
return !(rhs == *this);
}
} // namespace trapdoor
27 changes: 14 additions & 13 deletions api/entity/PlayerBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,22 @@
#include "Actor.h"

namespace trapdoor {
struct RightClickCache {
uint64_t gameTick = 0;
int x = 0;
int y = 0;
int z = 0;
struct RightClickCache {
uint64_t gameTick = 0;
int x = 0;
int y = 0;
int z = 0;

bool operator==(const RightClickCache& rhs) const;
bool operator==(const RightClickCache &rhs) const;

bool operator!=(const RightClickCache& rhs) const;
};
bool operator!=(const RightClickCache &rhs) const;
};

//这个结构专门存储玩家个人相关的缓存信息(相当于玩家的一个私人空间),后面可能加新东西
struct PlayerBuffer {
RightClickCache rightClickCache; //玩家右键缓存,作为右键检测使用
};

//这个结构专门存储玩家个人相关的缓存信息(相当于玩家的一个私人空间),后面可能加新东西
struct PlayerBuffer {
RightClickCache rightClickCache; //玩家右键缓存,作为右键检测使用
};
} // namespace trapdoor

#endif // TRAPDOOR_PLAYER_BUFFER_H
#endif // TRAPDOOR_PLAYER_BUFFER_H
1 change: 1 addition & 0 deletions api/entity/PlayerInventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace trapdoor {
this
);
//这个api是有问题的
//return 0;
return *(int *) (ptr + 4);
}

Expand Down
Loading

0 comments on commit ea8f2f3

Please sign in to comment.