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

Commit

Permalink
hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
twoone3l committed Aug 21, 2021
1 parent b69e183 commit 9f6538c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion BDSpyrunner/Header File/PyEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct PyEntity {
Actor* actor;
};
//转换std::string为PyUnicode
PyObject* toPyUnicode(const std::string&);
PyObject* ToPyUnicode(const std::string&);

PyObject* PyEntity_FromEntity(Actor* ptr);

Expand Down
22 changes: 11 additions & 11 deletions BDSpyrunner/Source File/PyEntity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <ScoreBoard.h>

using namespace std;
PyObject* toPyUnicode(const string& str) {
PyObject* ToPyUnicode(const string& str) {
return PyUnicode_FromStringAndSize(str.c_str(), str.length());
}
Actor* PyEntity_AsActor(PyObject* self) {
Expand Down Expand Up @@ -51,7 +51,7 @@ PyObject* PyEntity_Str(PyObject* self) {
Actor* a = PyEntity_AsActor(self);
if (!a)
return nullptr;
return toPyUnicode(a->getNameTag());
return ToPyUnicode(a->getNameTag());
}

//哈希
Expand Down Expand Up @@ -88,7 +88,7 @@ PyObject* PyEntity_GetName(PyObject* self, void*) {
Actor* a = PyEntity_AsActor(self);
if (!a)
return nullptr;
return toPyUnicode(a->getNameTag());
return ToPyUnicode(a->getNameTag());
}

int PyEntity_SetName(PyObject* self, PyObject* arg, void*) {
Expand All @@ -107,15 +107,15 @@ PyObject* PyEntity_GetUuid(PyObject* self, void*) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
return toPyUnicode(p->getUuid());
return ToPyUnicode(p->getUuid());
}

//获取XUID
PyObject* PyEntity_GetXuid(PyObject* self, void*) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
return toPyUnicode(p->getXuid());
return ToPyUnicode(p->getXuid());
}

//获取坐标
Expand Down Expand Up @@ -167,15 +167,15 @@ PyObject* PyEntity_GetTypeName(PyObject* self, void*) {
Actor* a = PyEntity_AsActor(self);
if (!a)
return nullptr;
return toPyUnicode(a->getEntityTypeName());
return ToPyUnicode(a->getEntityTypeName());
}

//获取nbt数据
PyObject* PyEntity_GetNBTInfo(PyObject* self, void*) {
Actor* a = PyEntity_AsActor(self);
if (!a)
return nullptr;
return toPyUnicode(CompoundTagtoJson(a->save()).dump(4));
return ToPyUnicode(CompoundTagtoJson(a->save()).dump(4));
}

//获取生命值
Expand Down Expand Up @@ -240,7 +240,7 @@ PyObject* PyEntity_GetDeviceId(PyObject* self, void*) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
return toPyUnicode(p->getDeviceId());
return ToPyUnicode(p->getDeviceId());
}

//获取设备类型
Expand All @@ -256,7 +256,7 @@ PyObject* PyEntity_GetIP(PyObject* self, void*) {
Player* p = PyEntity_AsPlayer(self);
if (!p)
return nullptr;
return toPyUnicode(g_rak_peer->getSystemAddress(p->getClientId()).toString());
return ToPyUnicode(g_rak_peer->getSystemAddress(p->getClientId()).toString());
}

//获取/设置玩家所有物品
Expand Down Expand Up @@ -284,7 +284,7 @@ PyObject* PyEntity_GetAllItem(PyObject* self, PyObject*) {
value["OffHand"] = CompoundTagtoJson(p->getOffHand()->save());
value["Hand"] = CompoundTagtoJson(p->getSelectedItem()->save());

return toPyUnicode(value.dump(4));
return ToPyUnicode(value.dump(4));
}

PyObject* PyEntity_SetAllItem(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -603,7 +603,7 @@ PyObject* PyEntity_GetTags(PyObject* self, PyObject*) {
span<string> tags = a->getTags();
PyObject* list = PyList_New(0);
for (size_t i = 0; i < tags.size; i++) {
PyList_Append(list, toPyUnicode(tags.data[i]));
PyList_Append(list, ToPyUnicode(tags.data[i]));
}
return list;
}
Expand Down
24 changes: 10 additions & 14 deletions BDSpyrunner/Source File/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ BOOL WINAPI DllMain(HMODULE, DWORD, LPVOID) {
return TRUE;
}
//检查版本
bool checkBDSVersion(const char* str) {
string getBDSVersion() {
string version;
SymCall<string&>("?getServerVersionString@Common@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ",
&version);
//cout << version << endl;
return version == str;
return version;
}
//转宽字符
static wstring CharToWchar(const string& str) {
Expand Down Expand Up @@ -774,11 +773,8 @@ static PyObject* PyAPI_minVersionRequire(PyObject*, PyObject* args) {
Py_RETURN_NONE;
}
//获取版本(摒弃)
static PyObject* PyAPI_getVersion(PyObject* self, PyObject* args) {
self;
args;
cerr << __FUNCTION__ << "被摒弃的函数,使用minVersionRequire来代替" << endl;
return PyLong_FromLong(209);
static PyObject* PyAPI_getBDSVersion(PyObject*, PyObject*) {
return ToPyUnicode(getBDSVersion());
}
//指令输出
static PyObject* PyAPI_logout(PyObject*, PyObject* args) {
Expand Down Expand Up @@ -912,7 +908,7 @@ static PyObject* PyAPI_getStructure(PyObject*, PyObject* args) {
StructureTemplate st("tmp");
st.fillFromWorld(bs, &start, &ss);

return toPyUnicode(CompoundTagtoJson(st.save()).dump(4));
return ToPyUnicode(CompoundTagtoJson(st.save()).dump(4));
}
Py_RETURN_NONE;
}
Expand Down Expand Up @@ -979,7 +975,7 @@ static PyObject* PyAPI_spawnItem(PyObject*, PyObject* args) {
//模块方法列表
static PyMethodDef PyAPI_Methods[]{
{"minVersionRequire", PyAPI_minVersionRequire, METH_VARARGS, nullptr},
{"getVersion", (PyCFunction)PyAPI_getVersion, METH_NOARGS, nullptr},
{"getBDSVersion", PyAPI_getBDSVersion, METH_NOARGS, nullptr},
{"logout", PyAPI_logout, METH_VARARGS, nullptr},
{"runcmd", PyAPI_runcmd, METH_VARARGS, nullptr},
{"setListener", PyAPI_setListener, METH_VARARGS, nullptr},
Expand Down Expand Up @@ -1024,9 +1020,9 @@ void init() {
//如果目录不存在创建目录
if (!exists(PLUGIN_PATH))
create_directories(PLUGIN_PATH);
if (!checkBDSVersion("1.17.11.01")) {
cerr << "服务端版本非最新版,请更新" << endl;
return;
if (getBDSVersion() != "1.17.11.01") {
cerr << "[BDSpyrunner] 服务端版本非最新版,继续使用可能出现未知问题" << endl;
cerr << "[BDSpyrunner] The server version is not the latest version, unknown problems may occur if you continue to use it" << endl;
}
//将plugins/py加入模块搜索路径
Py_SetPath((wstring(PLUGIN_PATH) + L';' + Py_GetPath()).c_str());
Expand Down Expand Up @@ -1055,7 +1051,7 @@ void init() {
if (name.front() == '_')
continue;
cout << "[BDSpyrunner] loading " << name << endl;
PyImport_Import(toPyUnicode(name));
PyImport_Import(ToPyUnicode(name));
PyErr_Print();
}
}
Expand Down

0 comments on commit 9f6538c

Please sign in to comment.