Skip to content

Commit

Permalink
支持中文物品名字
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohengying committed Nov 14, 2021
1 parent 6f1d628 commit 110751a
Show file tree
Hide file tree
Showing 8 changed files with 368,962 additions and 422 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ target_link_libraries(${MOD_API_NAME} ${PROJECT_SOURCE_DIR}/api/lib/detours.lib)

####################这里是具体功能##########################
#设置插版本
set(TRAPDOOR_VERSION 0.9.80)
set(TRAPDOOR_VERSION 0.9.81)
#设置游戏版本
set(MCBE_VERSION 1.16.40.2)
#是否是测试版
Expand Down
142 changes: 90 additions & 52 deletions api/entity/Item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,108 @@
//

#include "Item.h"
#include <string>
#include "tools/Message.h"
#include "tools/MsgBuilder.h"
#include "block/Block.h"
#include "Offset.h"
#include "PlayerBuffer.h"
#include "lib/mod.h"
#include "block/Block.h"
#include "lib/SymHook.h"
#include "tools/DirtyLogger.h"
#include "lib/mod.h"
#include "tools/CastHelper.h"
#include "Offset.h"
#include "tools/DirtyLogger.h"
#include "tools/Message.h"
#include "tools/MsgBuilder.h"
#include <fstream>
#include <string>

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

std::string ItemStackBase::getItemName() {
std::string name;
SYM_CALL(
void(*)(ItemStackBase * , std::string *),
MSSYM_B1QA7getNameB1AE13ItemStackBaseB2AAA4QEBAB1QA2AVB2QDA5basicB1UA6stringB1AA2DUB2QDA4charB1UA6traitsB1AA1DB1AA3stdB2AAA1VB2QDA9allocatorB1AA1DB1AA12B2AAA3stdB2AAA2XZ,
this, &name);
return name;
}
int ItemStackBase::getNum() {
return *offset_cast<char *>(this, off::ITEM_GET_NUM);
}

int ItemStackBase::getNum() {
return *offset_cast<char *>(this, off::ITEM_GET_NUM);
void InitItemNameMap() {
const std::string bds_lang_file_path =
".\\resource_packs\\vanilla\\texts\\zh_CN.lang";
std::ifstream input(bds_lang_file_path);
if (!input.is_open()) {
L_WARNING("can not read bds lang file");
return;
}
std::string line;
while (getline(input, line)) {
if (line.find("item.") == 0 || line.find("tile.") == 0) {
// item.iron_hoe.name=铁锄 #
auto p1 = line.find("=");
auto p2 = line.find('\t');
auto key = line.substr(0, p1);
auto name = line.substr(p1 + 1, p2 - p1);
name.erase(std::remove(name.begin(), name.end(), '\t'), name.end());
item_name_map[key] = name;
}
}
}

std::string GetItemLocalName(const std::string &name) {
LCID localeID = GetUserDefaultLCID();
unsigned short lang = localeID & 0xFF;
if (lang != LANG_CHINESE) {
return name;
}
auto key = name;
for (auto &i : key) {
if (i == ' ')
i = '_';
if (i <= 'Z' && i >= 'A')
i -= ('Z' - 'z');
}

// void ItemStackBase::setNull() {
// SYM_CALL(void(*)(ItemStackBase * ),
// SymHook::MSSYM_B1QA7setNullB1AE13ItemStackBaseB2AAA7UEAAXXZ,
// this);
// }
} // namespace trapdoor
auto key1 = "item." + key + ".name";
auto iter = item_name_map.find(key1);
if (iter != item_name_map.end()) {
return iter->second;
}

auto key2 = "tile." + key + ".name";
auto iter2 = item_name_map.find(key2);
if (iter2 != item_name_map.end()) {
return iter2->second;
}
return name;
}
} // 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) {
uint64_t gameTick = player->getLevel()->getGameTick();
// L_INFO("%.2f %.2f %.2f,tick = %llu", x, y, z, gameTick);
trapdoor::RightClickCache targetCache{gameTick, x, y, z};
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 = player->getLevel()->getGameTick();
// L_INFO("%.2f %.2f %.2f,tick = %llu", x, y, z, gameTick);
trapdoor::RightClickCache targetCache{gameTick, 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);
}
20 changes: 11 additions & 9 deletions api/entity/Item.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
#ifndef TRAPDOOR_ITEM_H
#define TRAPDOOR_ITEM_H


#include <string>
#include "Block.h"
#include <string>

namespace trapdoor {
struct ItemStackBase {
std::string getItemName();
struct ItemStackBase {
std::string getItemName();

int getNum();

int getNum();
void setNull();
};

void setNull();
};
}
void InitItemNameMap();

std::string GetItemLocalName(const std::string &name);
} // namespace trapdoor

#endif //TRAPDOOR_ITEM_H
#endif // TRAPDOOR_ITEM_H
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.16.4.02-0.9.81
- 漏斗计数器支持中文名称
- 删除部分无用的标准输出

## 1.16.4.02-0.9.80
- 当服务求处于frozen状态且服务求内没有玩家的时候会自动切换到正常状态
- 修复仙人掌可以转蛋糕的问题
Expand Down
Loading

0 comments on commit 110751a

Please sign in to comment.