Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.16.4' into 1.16.4
Browse files Browse the repository at this point in the history
# Conflicts:
#	api/entity/Item.cpp
  • Loading branch information
hhhxiao committed Jan 22, 2021
2 parents b64fc74 + 634856c commit 598980a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 81 deletions.
96 changes: 44 additions & 52 deletions api/entity/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,65 +12,57 @@
#include "lib/SymHook.h"
#include "tools/DirtyLogger.h"


namespace trapdoor {
using namespace SymHook;

std::string ItemStackBase::getItemName() {
std::string name;
SYM_CALL(
void(*)(ItemStackBase * , std::string *),
MSSYM_B1QA7getNameB1AE13ItemStackBaseB2AAA4QEBAB1QA2AVB2QDA5basicB1UA6stringB1AA2DUB2QDA4charB1UA6traitsB1AA1DB1AA3stdB2AAA1VB2QDA9allocatorB1AA1DB1AA12B2AAA3stdB2AAA2XZ,
this, &name
);
return name;
}
using namespace SymHook;

int ItemStackBase::getNum() {
return (int) *((unsigned char *) this + 34);
}
std::string ItemStackBase::getItemName() {
std::string name;
SYM_CALL(
void (*)(ItemStackBase*, std::string*),
MSSYM_B1QA7getNameB1AE13ItemStackBaseB2AAA4QEBAB1QA2AVB2QDA5basicB1UA6stringB1AA2DUB2QDA4charB1UA6traitsB1AA1DB1AA3stdB2AAA1VB2QDA9allocatorB1AA1DB1AA12B2AAA3stdB2AAA2XZ,
this, &name);
return name;
}

int ItemStackBase::getNum() { return (int)*((unsigned char*)this + 34); }

void ItemStackBase::setNull() {
SYM_CALL(
void(*)(ItemStackBase * ),
SymHook::MSSYM_B1QA7setNullB1AE13ItemStackBaseB2AAA7UEAAXXZ,
this
);
}
}
void ItemStackBase::setNull() {
SYM_CALL(void (*)(ItemStackBase*),
SymHook::MSSYM_B1QA7setNullB1AE13ItemStackBaseB2AAA7UEAAXXZ,
this);
}
} // namespace trapdoor

using namespace SymHook;
//右键代理类
THook(
void,
MSSYM_B1QA5useOnB1AA4ItemB2AAA4QEBAB1UE14NAEAVItemStackB2AAA9AEAVActorB2AAA7HHHEMMMB1AA1Z,
void *item,
trapdoor::ItemStackBase *itemStack,
trapdoor::Actor *player,
int x,
int y,
int z,
unsigned int facing,
float dx,
float dy,
float dz
) {

void,
MSSYM_B1QA5useOnB1AA4ItemB2AAA4QEBAB1UE14NAEAVItemStackB2AAA9AEAVActorB2AAA7HHHEMMMB1AA1Z,
void* item,
trapdoor::ItemStackBase* itemStack,
trapdoor::Actor* player,
int x,
int y,
int z,
unsigned int facing,
float dx,
float dy,
float dz) {
uint64_t gameTick = trapdoor::bdsMod->getLevel()->getGameTick();
// L_INFO("%.2f %.2f %.2f,tick = %llu", x, y, z, gameTick);
trapdoor::RightClickCache targetCache{gameTick, x, y, z};

// L_INFO("%.2f %.2f %.2f,tick = %llu", dx, dy, dz, trapdoor::bdsMod->getLevel()->getGameTick());

trapdoor::RightClickCache targetCache{dx, dy, dz, x, y, z};

auto &playerCache = trapdoor::bdsMod->getPlayerBuffer()[player->getNameTag()].rightClickCache;
//下面用一个简单的缓存 + 判定消除重复点击
if (playerCache != targetCache) {
//响应右键事件
trapdoor::BlockPos pos(x, y, z);
const trapdoor::Vec3 vec3(dx, dy, dz);
trapdoor::bdsMod->useOnHook(player, itemStack->getItemName(), pos, facing, vec3);
playerCache = targetCache;
}
original(item, itemStack, player, x, y, z, facing, dx, dy, dz);
auto& playerCache =
trapdoor::bdsMod->getPlayerBuffer()[player->getNameTag()]
.rightClickCache;
//下面用一个简单的缓存 + 判定消除重复点击
if (playerCache != targetCache) {
//响应右键事件
trapdoor::BlockPos pos(x, y, z);
const trapdoor::Vec3 vec3(dx, dy, dz);
trapdoor::bdsMod->useOnHook(player, itemStack->getItemName(), pos,
facing, vec3);
playerCache = targetCache;
}
original(item, itemStack, player, x, y, z, facing, dx, dy, dz);
}

21 changes: 9 additions & 12 deletions api/entity/PlayerBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +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;
auto distance2 = (dx - rhs.dx) * (dx - rhs.dx) + (dy - rhs.dy) * (dy - rhs.dy) + (dz - rhs.dz) * (dz - rhs.dz);
return distance2 < 0.01f;
}
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
31 changes: 14 additions & 17 deletions api/entity/PlayerBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@
#include "Actor.h"

namespace trapdoor {
struct RightClickCache {
float dx = 0;
float dy = 0;
float dz = 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

0 comments on commit 598980a

Please sign in to comment.