Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
1.8.2 released. This is a stable version. I add some macro to simplef…
Browse files Browse the repository at this point in the history
…y code. For PyEntity, I abandon some GetSet which is not easy to understand. Player::getPlayerPermissions fixed.
  • Loading branch information
twoone3l committed Oct 2, 2021
1 parent 14480fe commit ac80624
Show file tree
Hide file tree
Showing 8 changed files with 313 additions and 269 deletions.
70 changes: 36 additions & 34 deletions mc/Actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ Container* Player::getInventory() {
//获取装备容器

Container* Player::getArmorContainer() {
return FETCH(Container*, this + 1648);//IDA Actor::_setArmorContainer 11
return SymCall<Container*>("?getArmorContainer@Actor@@QEBAAEBVSimpleContainer@@XZ",
this);
}

//获取末影箱
Expand All @@ -251,38 +252,43 @@ Container* Player::getEnderChestContainer() {
//设置一个装备

uintptr_t Player::setArmor(int i, ItemStack* item) {
return SymCall<uintptr_t>("?setArmor@ServerPlayer@@UEAAXW4ArmorSlot@@AEBVItemStack@@@Z", this, i, item);
return SymCall<uintptr_t>("?setArmor@ServerPlayer@@UEAAXW4ArmorSlot@@AEBVItemStack@@@Z",
this, i, item);
}

//设置副手

uintptr_t Player::setOffhandSlot(ItemStack* item) {
return SymCall<uintptr_t>("?setOffhandSlot@Player@@UEAAXAEBVItemStack@@@Z", this, item);
return SymCall<uintptr_t>("?setOffhandSlot@Player@@UEAAXAEBVItemStack@@@Z",
this, item);
}

//添加一个物品

void Player::addItem(ItemStack* item) {
SymCall<uintptr_t>("?addItem@@YAXAEAVPlayer@@AEAVItemStack@@@Z", this, item);
SymCall<uintptr_t>("?addItem@@YAXAEAVPlayer@@AEAVItemStack@@@Z",
this, item);
}

//增加等级

void Player::addLevel(int level) {
SymCall("?addLevels@Player@@UEAAXH@Z", this, level);
SymCall("?addLevels@Player@@UEAAXH@Z",
this, level);
}

//获取当前选中的框位置

int Player::getSelectedItemSlot() {
return SymCall<int>("?getSelectedItemSlot@Player@@QEBAHXZ", this);
//return FETCH(unsigned, FETCH(uintptr_t, this + 3208) + 16);//IDA Player::getSelectedItemSlot
return SymCall<int>("?getSelectedItemSlot@Player@@QEBAHXZ",
this);
}

//获取当前物品

ItemStack* Player::getSelectedItem() {
return SymCall<ItemStack*>("?getSelectedItem@Player@@QEBAAEBVItemStack@@XZ", this);
return SymCall<ItemStack*>("?getSelectedItem@Player@@QEBAAEBVItemStack@@XZ",
this);
}

//获取背包物品
Expand All @@ -291,42 +297,36 @@ ItemStack* Player::getInventoryItem(int slot) {
return getInventory()->getSlots()[slot];
}

//获取游戏时命令权限

char Player::getPermissions() {
return *FETCH(char*, this + 2376);//IDA ServerPlayer::setPermissions 22
//获取游戏时游玩权限
PlayerPermissionLevel Player::getPlayerPermissionLevel() {
return SymCall<PlayerPermissionLevel>("?getPlayerPermissionLevel@Player@@QEBA?AW4PlayerPermissionLevel@@XZ",
this);
}

//设置游戏时命令权限

void Player::setPermissions(char m) {
void Player::setPermissions(PlayerPermissionLevel m) {
SymCall("?setPermissions@ServerPlayer@@UEAAXW4CommandPermissionLevel@@@Z",
this, m);
}

//获取游戏时游玩权限

char Player::getPermissionLevel() {//IDA Abilities::setPlayerPermissions ?
return FETCH(char, FETCH(char*, this + 2376) + 1);
}

//设置游戏时游玩权限

void Player::setPermissionLevel(char m) {
SymCall("?setPlayerPermissions@Abilities@@QEAAXW4PlayerPermissionLevel@@@Z",
this + 2376, m);
}

//获取设备id

string Player::getDeviceId() {
return FETCH(string, this + 8352); //IDA Player::Player v13 + 8352
string Player::getPlatformOnlineId() {
string id;
SymCall<string&>("?getPlatformOnlineId@Player@@QEBAAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ",
this, &id);
return id;
//return FETCH(string, this + 8352);
//IDA Player::Player v13 + 8352
}

//获取设备系统类型

int Player::getDeviceOS() {
return FETCH(int, this + 2368); //IDA ServerNetworkHandler::createNewPlayer ConnectionRequest::getDeviceOS
unsigned Player::getPlatform() {
return SymCall<unsigned>("?getPlatform@Player@@QEBA?AW4BuildPlatform@@XZ",
this);
//return FETCH(int, this + 2336);
//IDA ServerNetworkHandler::createNewPlayer ConnectionRequest::getDeviceOS
}

//发送背包
Expand Down Expand Up @@ -415,7 +415,9 @@ void Player::sendSetScorePacket(char type, const vector<ScorePacketInfo>& slot)
}

bool IsPlayer(Actor* ptr) {
if (ptr && ptr->getEntityTypeId() == 319)
return true;
return false;
if (ptr == nullptr)
return false;
if (ptr->getEntityTypeId() != 319)
return false;
return true;
}
33 changes: 23 additions & 10 deletions mc/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ struct Tag;
struct NetworkIdentifier;
struct Container;
struct ScorePacketInfo;
struct Abilities;
enum class PlayerPermissionLevel : uint8_t {
Visitor,
Member,
Operator,
Custom
};
enum class CommandPermissionLevel : uint8_t {
Any,
GameMasters,
Admin,
Host,
Owner,
Internal
};
struct Actor {
//获取生物名称信息
std::string getNameTag();
Expand Down Expand Up @@ -71,7 +86,7 @@ struct Mob : Actor {};
struct Player : Mob {
//获取玩家uuid
std::string getUuid();
//根据地图信息获取玩家xuid
//获取玩家xuid
std::string& getXuid();
//获取网络标识符
NetworkIdentifier* getClientId();
Expand All @@ -95,18 +110,16 @@ struct Player : Mob {
ItemStack* getSelectedItem();
//获取背包物品
ItemStack* getInventoryItem(int slot);
//获取游戏时命令权限
char getPermissions();
//设置游戏时命令权限
void setPermissions(char m);
//获取游戏时游玩权限
char getPermissionLevel();
//获取游玩权限
PlayerPermissionLevel getPlayerPermissionLevel();
//设置游戏时游玩权限
void setPermissionLevel(char m);
void setPermissions(PlayerPermissionLevel m);
//获取玩家能力
Abilities* getAbilities();
//获取设备id
std::string getDeviceId();
std::string getPlatformOnlineId();
//获取设备系统类型
int getDeviceOS();
unsigned getPlatform();
//发送背包
void sendInventroy();
//刷新区块
Expand Down
5 changes: 3 additions & 2 deletions mc/ItemStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ void ItemStack::fromJson(const Json& value) {

vector<ItemStack*> Container::getSlots() {
vector<ItemStack*> s;
SymCall<uintptr_t>("?getSlots@Container@@UEBA?BV?$vector@PEBVItemStack@@V?$allocator@PEBVItemStack@@@std@@@std@@XZ",
this, &s);
VirtualCall<uintptr_t>(0x98, this, &s);
//SymCall<uintptr_t>("?getSlots@Container@@UEBA?BV?$vector@PEBVItemStack@@V?$allocator@PEBVItemStack@@@std@@@std@@XZ",
// this, &s);
return s;
}

Expand Down
4 changes: 4 additions & 0 deletions mod/CPython.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#define PY_SSIZE_T_CLEAN
#include "../include/Python.h"

#define Py_PARSE(format,...) if (!PyArg_ParseTuple(args, format ":" __FUNCTION__, __VA_ARGS__))return nullptr
#define Py_KERWORDS_LIST(...) static const char* kwlist[]{ __VA_ARGS__,nullptr }
#define Py_PARSE_WITH_KERWORDS(format,...) if (!PyArg_ParseTupleAndKeywords(args, kwds, format ":" __FUNCTION__, const_cast<char**>(kwlist), __VA_ARGS__))return nullptr

//×Ö·û´®×ªUnicode
inline PyObject* StringToPyUnicode(std::string_view str) {
return PyUnicode_FromStringAndSize(str.data(), str.length());
Expand Down
Loading

0 comments on commit ac80624

Please sign in to comment.