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

Commit

Permalink
1.7.10 released, add CPython.h, README updated.
Browse files Browse the repository at this point in the history
  • Loading branch information
twoone3l committed Sep 11, 2021
1 parent eb3a2c0 commit c5a18ec
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 31 deletions.
1 change: 1 addition & 0 deletions BDSpyrunner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
<ClInclude Include="mc\tool.h" />
<ClInclude Include="mod\Entity.h" />
<ClInclude Include="mod\Version.h" />
<ClInclude Include="mod\CPython.h" />
</ItemGroup>
<ItemGroup>
<None Include="update_pyr.bat" />
Expand Down
3 changes: 3 additions & 0 deletions BDSpyrunner.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@
<ClInclude Include="mod\Version.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="mod\CPython.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="update_pyr.bat">
Expand Down
28 changes: 14 additions & 14 deletions DllMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ static bool EventCallBack(EventCode e, const char* format, Args... args) {
}
#pragma endregion
#pragma region Hook List
//HOOK(Level_tick, void, "?tick@Level@@UEAAXXZ",
// Level* _this) {
// original(_this);
//}
/*
HOOK(Level_tick, void, "?tick@Level@@UEAAXXZ",
Level* _this) {
original(_this);
}
*/
//将Python解释器初始化插入bds主函数
HOOK(BDS_Main, int, "main",
int argc, char* argv[], char* envp[]) {
Expand Down Expand Up @@ -202,15 +204,15 @@ HOOK(ServerNetworkHandler_construct, uintptr_t, "??0ServerNetworkHandler@@QEAA@A
}
//Scoreboard的构造函数
HOOK(ServerScoreboard_construct, Scoreboard*, "??0ServerScoreboard@@QEAA@VCommandSoftEnumRegistry@@PEAVLevelStorage@@@Z",
Scoreboard* _this, uintptr_t a2, uintptr_t a3) {
return Global<Scoreboard>::data = original(_this, a2, a3);
Scoreboard* _this, uintptr_t a1, uintptr_t a2) {
return Global<Scoreboard>::data = original(_this, a1, a2);
}
//改变设置命令的建立,用于注册命令
HOOK(ChangeSettingCommand_setup, void, "?setup@ChangeSettingCommand@@SAXAEAVCommandRegistry@@@Z",
uintptr_t _this) {
for (auto& [cmd, des] : g_commands) {
SymCall("?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDW4CommandPermissionLevel@@UCommandFlag@@3@Z",
_this, &cmd, des.first.c_str(), 0, 0, 0x80);
_this, &cmd, des.first.c_str(), 0, 0, 0x80/*CommandFlag*/);
}
original(_this);
}
Expand All @@ -221,7 +223,7 @@ HOOK(onServerStarted, void, "?startServerThread@ServerInstance@@QEAAXXZ",
thread(CheckPluginVersion).detach();
original(_this);
}
//控制台输出,实际上是cout<<xxx的底层调用
//控制台输出,实际上是ostrram::operator<<的底层调用
HOOK(onConsoleOutput, ostream&, "??$_Insert_string@DU?$char_traits@D@std@@_K@std@@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@0@AEAV10@QEBD_K@Z",
ostream& _this, const char* str, uintptr_t size) {
if (&_this == &cout) {
Expand All @@ -233,7 +235,6 @@ HOOK(onConsoleOutput, ostream&, "??$_Insert_string@DU?$char_traits@D@std@@_K@std
//控制台输入,实际上是命令队列的底层
HOOK(onConsoleInput, bool, "??$inner_enqueue@$0A@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@?$SPSCQueue@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@$0CAA@@@AEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z",
SPSCQueue* _this, string* cmd) {
//debug模式(不推荐使用)
static bool debug = false;
if (*cmd == "pydebug") {
if (debug) {
Expand All @@ -243,19 +244,18 @@ HOOK(onConsoleInput, bool, "??$inner_enqueue@$0A@AEBV?$basic_string@DU?$char_tra
debug = true;
cout << '>';
}
return 0;
return false;
}
if (debug) {
Py_BEGIN_CALL;
PyRun_SimpleString(cmd->c_str());
Py_END_CALL;
cout << '>';
return 0;
return false;
}
if (EventCallBack(EventCode::onConsoleInput, "O", ToPyUnicode(*cmd)))
return original(_this, cmd);
else
return false;
return false;
}
//玩家加入发包
HOOK(onPlayerJoin, void, "?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVSetLocalPlayerAsInitializedPacket@@@Z",
Expand Down Expand Up @@ -793,7 +793,7 @@ HOOK(onBlockExploded, void, "?onExploded@Block@@QEBAXAEAVBlockSource@@AEBVBlockP
))
return original(_this, bs, bp, actor);
}
//方块侧面放触发,点击牌子触发
//使用牌子
HOOK(onUseSingBlock, uintptr_t, "?use@SignBlock@@UEBA_NAEAVPlayer@@AEBVBlockPos@@E@Z",
uintptr_t _this, Player* a1, BlockPos* a2) {
BlockSource* bs = a1->getRegion();
Expand Down
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
![Downloads](https://img.shields.io/github/downloads/twoone-3/BDSpyrunner/total)
![Release](https://img.shields.io/github/v/release/twoone-3/BDSpyrunner)
![BDS](https://img.shields.io/badge/support--BDS--version-1.17.11.01-blue)
![Issues](https://img.shields.io/github/issues/twoone-3/BDSpyrunner)
![Telegram](https://img.shields.io/badge/telegram-BDSpyrunner-blue?&logo=telegram&link=https://t.me/bdspyrunner)

[简体中文](README_ZH.md) | English
# Introduction
Expand All @@ -13,10 +11,14 @@ It uses CPython and Detours to connect Python and BDS so that Python can operate
It greatly reduces the threshold for plug-in development and effectively simplifies the cost of plug-in development.
# Usage
1. Download `BDSpyrunner.dll` and `BDSpyrunner.pdb` in `Release` (optional).
2. Go to https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe to download and install `Python3.7.9`, remember to check add to `Environment Variables`.
2. Put the dll into the `./plugins` folder, run BDS, the py folder will be automatically generated, if you see `[BDSpyrunner] x.x.x loaded.`, the pyr has been loaded successfully.
7. Put the plug-in into `./plugins/py`, run BDS again, you can use it normally.
2. To install pyr, you need to use [LiteLoader](https://github.com/LiteLDev/LiteLoaderBDS), please make sure you have installed LiteLoader
3. Go to https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe to download and install `Python3.7.9`, remember to check add to `Environment Variables`.
4. Put the dll into the `./plugins` folder, run BDS, the py folder will be automatically generated, if you see `[BDSpyrunner] x.x.x loaded.`, the pyr has been loaded successfully.
5. Put the plug-in into `./plugins/py`, run BDS again, you can use it normally.
# Other functions
* Automatic update: Download the update_pyr.bat in the release and put it in the plugins folder to start the automatic update
# Documents
* [Wiki](https://github.com/twoone-3/BDSpyrunner/wiki/)
# Contact us
QQ group : 1167270197
* QQ group : 1167270197
* Telegram : ![Telegram](https://img.shields.io/badge/telegram-BDSpyrunner-blue?&logo=telegram&link=https://t.me/bdspyrunner)
14 changes: 8 additions & 6 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
![Downloads](https://img.shields.io/github/downloads/twoone-3/BDSpyrunner/total)
![Release](https://img.shields.io/github/v/release/twoone-3/BDSpyrunner)
![BDS](https://img.shields.io/badge/support--BDS--version-1.17.11.01-blue)
![Issues](https://img.shields.io/github/issues/twoone-3/BDSpyrunner)
![Telegram](https://img.shields.io/badge/telegram-BDSpyrunner-blue?&logo=telegram&link=https://t.me/bdspyrunner)

简体中文 | [English](README.md)
# 简介
Expand All @@ -13,10 +11,14 @@
极大的降低了插件开发门槛,有效简化了插件的开发成本。
# 用法
1. 下载`Release`中的`BDSpyrunner.dll``BDSpyrunner.pdb`(可选)
2. 前往 https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe 下载安装 `Python3.7.9`,记得勾选添加到`环境变量`
2. 将dll放入`./plugins`文件夹,运行BDS,会自动生成py文件夹,如果看到`[BDSpyrunner] x.x.x loaded.`,则pyr加载成功了
7. 将插件放入`./plugins/py`,再次运行BDS,就可以正常使用了
2. 安装pyr,需要使用[LiteLoader](https://github.com/LiteLDev/LiteLoaderBDS),请确保您已经安装了LiteLoader
3. 前往 https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe 下载安装 `Python3.7.9`,记得勾选添加到`环境变量`
4. 将dll放入`./plugins`文件夹,运行BDS,会自动生成py文件夹,如果看到`[BDSpyrunner] x.x.x loaded.`,则pyr加载成功了
5. 将插件放入`./plugins/py`,再次运行BDS,就可以正常使用了
# 其他功能
* 自动更新:下载release中的update_pyr.bat并放入plugins文件夹即可开启自动更新
# 文档
* [Wiki](https://github.com/twoone-3/BDSpyrunner/wiki/)
# 联系我们
QQ 群 : 1167270197
* QQ 群 : 1167270197
* Telegram : ![Telegram](https://img.shields.io/badge/telegram-BDSpyrunner-blue?&logo=telegram&link=https://t.me/bdspyrunner)
4 changes: 4 additions & 0 deletions mod/CPython.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#pragma comment(lib,"lib/python37.lib")
#define PY_SSIZE_T_CLEAN
#include "../include/Python.h"
4 changes: 1 addition & 3 deletions mod/Entity.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#pragma once
#pragma comment(lib,"lib/python37.lib")
#include <string>
#define PY_SSIZE_T_CLEAN
#include "../include/Python.h"
#include "CPython.h"
#include "../mc/Position.h"

#define Py_RETURN_ERROR(str) return PyErr_SetString(PyExc_Exception, str), nullptr
Expand Down
4 changes: 2 additions & 2 deletions mod/Version.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
constexpr unsigned VERSION_1 = 1;
constexpr unsigned VERSION_2 = 7;
constexpr unsigned VERSION_3 = 9;
constexpr const char* VERSION_STRING = "v1.7.9";
constexpr unsigned VERSION_3 = 10;
constexpr const char* VERSION_STRING = "v1.7.10";

0 comments on commit c5a18ec

Please sign in to comment.