├── .clang-format ├── .github └── workflows │ └── build.yml ├── .gitignore ├── .gitmodules ├── .vscode ├── .gitignore ├── c_cpp_properties.json └── settings.json ├── LICENSE ├── NameYourProject.exe ├── README.md ├── include └── myplugin │ ├── Plugin.h │ └── Resource.h ├── script └── UpdateSDK.cmd ├── src ├── DllMain.cpp ├── Plugin.cpp └── Resource.rc └── xmake.lua /.clang-format: -------------------------------------------------------------------------------- 1 | # Documents: https://clang.llvm.org/docs/ClangFormatStyleOptions.html 2 | Language: Cpp 3 | BasedOnStyle: LLVM 4 | AccessModifierOffset: -4 5 | AlignAfterOpenBracket: Align 6 | AlignConsecutiveAssignments: None 7 | AlignConsecutiveDeclarations: None 8 | AlignOperands: Align 9 | AlwaysBreakTemplateDeclarations: Yes 10 | AlignTrailingComments: true 11 | AllowAllArgumentsOnNextLine: true 12 | AllowAllParametersOfDeclarationOnNextLine: true 13 | AllowShortBlocksOnASingleLine: Always 14 | AllowShortCaseLabelsOnASingleLine: false 15 | AllowShortIfStatementsOnASingleLine: false 16 | AllowShortLoopsOnASingleLine: false 17 | AllowShortFunctionsOnASingleLine: Empty 18 | AllowShortLambdasOnASingleLine: All 19 | AllowShortEnumsOnASingleLine: false 20 | AlwaysBreakAfterDefinitionReturnType: None 21 | BinPackArguments: true 22 | BinPackParameters: true 23 | ConstructorInitializerIndentWidth: 0 24 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 25 | BreakBeforeConceptDeclarations: Always 26 | RequiresClausePosition: OwnLine 27 | ColumnLimit: 120 28 | CommentPragmas: '^ IWYU pragma:' 29 | PointerAlignment: Left 30 | IndentWidth: 4 31 | SortIncludes: Never 32 | MaxEmptyLinesToKeep: 2 33 | SpacesInSquareBrackets: false 34 | SpacesInParentheses: false 35 | SpaceBeforeAssignmentOperators: true 36 | SpacesInContainerLiterals: true 37 | IndentWrappedFunctionNames: true 38 | KeepEmptyLinesAtTheStartOfBlocks: true 39 | SeparateDefinitionBlocks: Always 40 | BreakConstructorInitializersBeforeComma: true 41 | SpaceAfterCStyleCast: false 42 | IndentCaseLabels: true 43 | TabWidth: 4 44 | UseTab: Never 45 | BreakBeforeBraces: Custom 46 | BraceWrapping: 47 | AfterCaseLabel: false 48 | AfterClass: false 49 | AfterEnum: false 50 | AfterFunction: false 51 | AfterNamespace: false 52 | AfterStruct: false 53 | AfterUnion: false 54 | AfterExternBlock: false 55 | BeforeCatch: false 56 | BeforeElse: false 57 | IndentBraces: false 58 | SplitEmptyFunction: true 59 | SplitEmptyRecord: true 60 | SplitEmptyNamespace: true -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [workflow_dispatch, pull_request, push] 3 | 4 | jobs: 5 | build: 6 | name: Build 7 | runs-on: windows-2022 8 | steps: 9 | - name: Checkout repository 10 | uses: actions/checkout@v3.2.0 11 | with: 12 | fetch-depth: 1 13 | submodules: 'true' 14 | - name: Setup XMake 15 | uses: xmake-io/github-action-setup-xmake@v1 16 | with: 17 | xmake-version: latest 18 | - name: Download BDS 19 | run: | 20 | curl -L -o LINK.txt https://raw.githubusercontent.com/LiteLDev/LiteLoaderBDS/main/scripts/LINK.txt 21 | ServerLink=$(cat 'LINK.txt') 22 | curl -L -o bds.zip "$ServerLink" 23 | unzip bds.zip -d bds/ > /dev/null 24 | shell: bash 25 | - name: Build Library 26 | run: | 27 | cd SDK/tools 28 | ./PeEditor.exe -l --pdb ../../bds/bedrock_server.pdb -o ../lib 29 | shell: bash 30 | - name: Complete Version Info 31 | run: | 32 | export sha_short=$(git rev-parse --short HEAD) 33 | sed -r -i "s/#define\s+PLUGIN_VERSION_COMMIT_SHA\s+.*/#define PLUGIN_VERSION_COMMIT_SHA $sha_short\r/" include/myplugin/Plugin.h 34 | sed -r -i "s/#define\s+PLUGIN_VERSION_BUILD\s+.*/#define PLUGIN_VERSION_BUILD ${{ github.run_number }}\r/" include/myplugin/Plugin.h 35 | shell: bash 36 | - name: Build 37 | run: | 38 | xmake build -a -v 39 | shell: bash 40 | - name: Upload Artifact 41 | uses: actions/upload-artifact@v3 42 | with: 43 | name: MyPlugin-build.${{ github.run_number }} 44 | path: ${{ github.workspace }}\release -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.xmake/ 2 | /build/ 3 | /*.pdb 4 | /release/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "SDK"] 2 | path = SDK 3 | url = https://github.com/LiteLDev/SDK-cpp.git 4 | -------------------------------------------------------------------------------- /.vscode/.gitignore: -------------------------------------------------------------------------------- 1 | compile_commands.json -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${default}", 7 | "${workspaceFolder}/SDK/include", 8 | "${workspaceFolder}/include" 9 | ], 10 | "defines": [ 11 | "_DEBUG", 12 | "UNICODE", 13 | "_UNICODE" 14 | ], 15 | "windowsSdkVersion": "10.0.19041.0", 16 | "compilerPath": "cl.exe", 17 | "intelliSenseMode": "windows-msvc-x64" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.default.includePath": [ 3 | "${WorkspaceFolder}/include", 4 | "${WorkspaceFolder}/SDK/include" 5 | ], 6 | "c-cpp-flylint.clang.includePaths": [ 7 | "${WorkspaceFolder}/include", 8 | "${WorkspaceFolder}/SDK/include" 9 | ] 10 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS 10 | PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM 11 | THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED 12 | HEREUNDER. 13 | 14 | Statement of Purpose 15 | 16 | The laws of most jurisdictions throughout the world automatically confer 17 | exclusive Copyright and Related Rights (defined below) upon the creator 18 | and subsequent owner(s) (each and all, an "owner") of an original work of 19 | authorship and/or a database (each, a "Work"). 20 | 21 | Certain owners wish to permanently relinquish those rights to a Work for 22 | the purpose of contributing to a commons of creative, cultural and 23 | scientific works ("Commons") that the public can reliably and without fear 24 | of later claims of infringement build upon, modify, incorporate in other 25 | works, reuse and redistribute as freely as possible in any form whatsoever 26 | and for any purposes, including without limitation commercial purposes. 27 | These owners may contribute to the Commons to promote the ideal of a free 28 | culture and the further production of creative, cultural and scientific 29 | works, or to gain reputation or greater distribution for their Work in 30 | part through the use and efforts of others. 31 | 32 | For these and/or other purposes and motivations, and without any 33 | expectation of additional consideration or compensation, the person 34 | associating CC0 with a Work (the "Affirmer"), to the extent that he or she 35 | is an owner of Copyright and Related Rights in the Work, voluntarily 36 | elects to apply CC0 to the Work and publicly distribute the Work under its 37 | terms, with knowledge of his or her Copyright and Related Rights in the 38 | Work and the meaning and intended legal effect of CC0 on those rights. 39 | 40 | 1. Copyright and Related Rights. A Work made available under CC0 may be 41 | protected by copyright and related or neighboring rights ("Copyright and 42 | Related Rights"). Copyright and Related Rights include, but are not 43 | limited to, the following: 44 | 45 | i. the right to reproduce, adapt, distribute, perform, display, 46 | communicate, and translate a Work; 47 | ii. moral rights retained by the original author(s) and/or performer(s); 48 | iii. publicity and privacy rights pertaining to a person's image or 49 | likeness depicted in a Work; 50 | iv. rights protecting against unfair competition in regards to a Work, 51 | subject to the limitations in paragraph 4(a), below; 52 | v. rights protecting the extraction, dissemination, use and reuse of data 53 | in a Work; 54 | vi. database rights (such as those arising under Directive 96/9/EC of the 55 | European Parliament and of the Council of 11 March 1996 on the legal 56 | protection of databases, and under any national implementation 57 | thereof, including any amended or successor version of such 58 | directive); and 59 | vii. other similar, equivalent or corresponding rights throughout the 60 | world based on applicable law or treaty, and any national 61 | implementations thereof. 62 | 63 | 2. Waiver. To the greatest extent permitted by, but not in contravention 64 | of, applicable law, Affirmer hereby overtly, fully, permanently, 65 | irrevocably and unconditionally waives, abandons, and surrenders all of 66 | Affirmer's Copyright and Related Rights and associated claims and causes 67 | of action, whether now known or unknown (including existing as well as 68 | future claims and causes of action), in the Work (i) in all territories 69 | worldwide, (ii) for the maximum duration provided by applicable law or 70 | treaty (including future time extensions), (iii) in any current or future 71 | medium and for any number of copies, and (iv) for any purpose whatsoever, 72 | including without limitation commercial, advertising or promotional 73 | purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each 74 | member of the public at large and to the detriment of Affirmer's heirs and 75 | successors, fully intending that such Waiver shall not be subject to 76 | revocation, rescission, cancellation, termination, or any other legal or 77 | equitable action to disrupt the quiet enjoyment of the Work by the public 78 | as contemplated by Affirmer's express Statement of Purpose. 79 | 80 | 3. Public License Fallback. Should any part of the Waiver for any reason 81 | be judged legally invalid or ineffective under applicable law, then the 82 | Waiver shall be preserved to the maximum extent permitted taking into 83 | account Affirmer's express Statement of Purpose. In addition, to the 84 | extent the Waiver is so judged Affirmer hereby grants to each affected 85 | person a royalty-free, non transferable, non sublicensable, non exclusive, 86 | irrevocable and unconditional license to exercise Affirmer's Copyright and 87 | Related Rights in the Work (i) in all territories worldwide, (ii) for the 88 | maximum duration provided by applicable law or treaty (including future 89 | time extensions), (iii) in any current or future medium and for any number 90 | of copies, and (iv) for any purpose whatsoever, including without 91 | limitation commercial, advertising or promotional purposes (the 92 | "License"). The License shall be deemed effective as of the date CC0 was 93 | applied by Affirmer to the Work. Should any part of the License for any 94 | reason be judged legally invalid or ineffective under applicable law, such 95 | partial invalidity or ineffectiveness shall not invalidate the remainder 96 | of the License, and in such case Affirmer hereby affirms that he or she 97 | will not (i) exercise any of his or her remaining Copyright and Related 98 | Rights in the Work or (ii) assert any associated claims and causes of 99 | action with respect to the Work, in either case contrary to Affirmer's 100 | express Statement of Purpose. 101 | 102 | 4. Limitations and Disclaimers. 103 | 104 | a. No trademark or patent rights held by Affirmer are waived, abandoned, 105 | surrendered, licensed or otherwise affected by this document. 106 | b. Affirmer offers the Work as-is and makes no representations or 107 | warranties of any kind concerning the Work, express, implied, 108 | statutory or otherwise, including without limitation warranties of 109 | title, merchantability, fitness for a particular purpose, non 110 | infringement, or the absence of latent or other defects, accuracy, or 111 | the present or absence of errors, whether or not discoverable, all to 112 | the greatest extent permissible under applicable law. 113 | c. Affirmer disclaims responsibility for clearing rights of other persons 114 | that may apply to the Work or any use thereof, including without 115 | limitation any person's Copyright and Related Rights in the Work. 116 | Further, Affirmer disclaims responsibility for obtaining any necessary 117 | consents, permissions or other rights required for any use of the 118 | Work. 119 | d. Affirmer understands and acknowledges that Creative Commons is not a 120 | party to this document and has no duty or obligation with respect to 121 | this CC0 or use of the Work. 122 | -------------------------------------------------------------------------------- /NameYourProject.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jasonzyt/ll2-plugin-template-xmake/a56b4629725d338c0f3f998e26829d8642f5b2ca/NameYourProject.exe -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [English](#LiteLoaderBDS-Plugin-Template-for-XMake) | [中文](#LiteLoaderBDS-插件模板使用XMake--C) 2 | 3 | ![CC0](https://licensebuttons.net/l/zero/1.0/88x31.png) 4 | 5 | --- 6 | 7 | **This template is for LiteLoaderBDS(v2), which have been archived.** 8 | **For LeviLamina plugin template, please visit https://github.com/LiteLDev/levilamina-plugin-template** 9 | 10 | # LiteLoaderBDS Plugin Template for XMake 11 | 12 | [XMake](https://xmake.io) is a lightweight cross-platform build utility based on Lua. It is very easy to use. 13 | 14 | What's more, it has modern C/C++ build tools, powerful dependency package integration. 15 | 16 | Instead of the traditional `cmake` or `make`, it is more suitable for the development of small and medium-sized projects. 17 | (You can even use XMake to generate CMakeLists.) 18 | 19 | So I strongly recommend you to have a try! 20 | 21 | > Though the official name is xmake, I prefer to call it XMake to follow UpperCamel case. 22 | > 23 | 24 | ## Usage 25 | 26 | With IDE: Visual Studio Code 27 | 28 | ### 0x0 Set Up Environment 29 | 30 | #### 0x00 Install MSVC Toolchain & Windows SDK 31 | 32 | MSVC Toolchain is required to build LiteLoaderBDS plugin. 33 | 34 | I suggest using Visual Studio Installer to install it so that you don't need to browse the web for the download links. 35 | And Visual Studio 2022 is also a powerful IDE & debugger. You might use it for debugging in the future. 36 | 37 | Download Visual Studio Installer [here](https://visualstudio.microsoft.com/downloads/). 38 | (You can install Visual Studio Code at the same page. We will use it later.) 39 | 40 | Then, install the installer. (This might heard a little bit weird xD.) 41 | 42 | Wait for the installation to complete. 43 | 44 | Open Visual Studio Installer. Install Visual Studio 2022 IDE and select `Desktop development with C++` workload. 45 | ![image](https://github.com/Jasonzyt/LLPluginTemplate-XMake/assets/66063199/12584dbb-e69c-46a9-aa86-ef3d22774591) 46 | At last, click `Install`. 47 | 48 | > By the way, if you want to use [vcpkg](https://github.com/microsoft/vcpkg), you must install the English language pack. 49 | > 50 | 51 | #### 0x01 Install XMake 52 | 53 | Download XMake installer for windows-x64 from [release](https://github.com/xmake-io/xmake/releases/latest) page. 54 | Then double-click to install it. 55 | 56 | #### 0x02 Install Git 57 | 58 | Git is a distributed version control system. We will use it to manage our project and host it on GitHub. 59 | 60 | Download Git from [here](https://git-scm.com/downloads) and install it. 61 | 62 | #### 0x02 Install Visual Studio Code and Extensions 63 | 64 | First, let me explain why I suggest VSCode instead of CLion or VS2022. 65 | 66 | VS2022 is bound with MSBuild or CMake and CLion is bound with CMake or Make. 67 | They don't have a highly-custom interface for non-mainstream build tools. 68 | If you use CLion to develop LiteLoaderBDS plugin, you will have to generate CMakeLists.txt(XMake provided this feature!) every time you add new files or modify the build script. 69 | 70 | VSCode is a lightweight IDE. It has a highly-custom interface for build tools. 71 | 72 | Download VSCode from [here](https://code.visualstudio.com/) and install it. 73 | Then, install `XMake` extension and `C/C++ Extension Pack` in Marketplace(Ctrl+Shift+X to open it. it's on sidebar). 74 | ![image](https://github.com/Jasonzyt/LLPluginTemplate-XMake/assets/66063199/ca59f627-9aba-4d77-88e5-9809fd1ea93c) 75 | 76 | Well done! You have set up the environment for LiteLoaderBDS plugin development. 77 | 78 | ### 0x1 Create Your Project Using This Template 79 | 80 | Scroll up to the top of this page. Click `Use this template` button. 81 | ![image](https://github.com/Jasonzyt/LLPluginTemplate-XMake/assets/66063199/a10a89a0-61a1-4cc3-a6f6-11961f742f54) 82 | 83 | Then, fill in the form and click `Create repository from template`. 84 | 85 | > Choose `Private` if you don't want to share your code with others. 86 | > 87 | 88 | Copy the URL of your project. 89 | 90 | Open terminal and cd to a directory you want to put your project in. 91 | Then, run the following command to clone your project. 92 | 93 | ```bash 94 | git clone --recursive 95 | ``` 96 | > Use `--recursive` option to clone the LiteLoaderBDS SDK submodule. 97 | > 98 | 99 | ### 0x2 Name Your Project 100 | 101 | Run `NameYourProject.exe` to name your project. 102 | You can delete this executable after naming your project. 103 | 104 | ### 0x3 Build Your Project 105 | 106 | Build with XMake is very simple, just run `xmake build` in the root directory of your project. 107 | 108 | An after-build script is provided. It will copy the built plugin to `release/` and rename it. 109 | You can modify `xmake.lua` to do more things like copying the dlls to BDS path. 110 | 111 | [Here](https://xmake.io/#/getting_started) is the official guide. 112 | 113 | When build for the first time or the SDK updated, it will ask you to select a pdb file to generate bedrock_server_api.lib and bedrock_server_var.lib. 114 | 115 | ### 0x4 Run BDS 116 | 117 | Put the built dlls from `build/windows/x64/release` or `release/` into `plugins/` folder of your BDS installation directory. 118 | Then, run `bedrock_server_mod.exe` to start your server. 119 | 120 | ### 0x5 Update SDK 121 | 122 | Run `script/UpdateSDK.cmd` to update SDK. 123 | ```bash 124 | # At the root directory of your project 125 | script/UpdateSDK.cmd 126 | ``` 127 | 128 | ## License 129 | 130 | Licensed under [CC0](LICENSE) 131 | 132 | ## Aknowledgements 133 | 134 | - [XMake](https://xmake.io) 135 | - [LiteLoaderBDS](https://github.com/LiteLDev/LiteLoaderBDS) 136 | 137 | --- 138 | 139 | [English](#LiteLoaderBDS-Plugin-Template-for-XMake) | [中文](#LiteLoaderBDS-插件模板使用XMake--C) 140 | 141 | --- 142 | 143 | # LiteLoaderBDS 插件模板(使用XMake & C++) 144 | 145 | [XMake](https://xmake.io/#/zh-cn/) 是一个基于 Lua 的轻量级跨平台构建工具,它非常易于使用。 146 | 147 | 更重要的是,它具有现代 C/C++ 构建工具,强大的依赖包集成,与传统 `cmake` 或 `make` 不同,它更适合中小型项目的开发。(你甚至可以用XMake来生成CMakeLists) 148 | 149 | 所以我强烈推荐你试一试! 150 | 151 | ## 使用方法 152 | 153 | IDE: Visual Studio Code 154 | 155 | ### 0x0 环境搭建 156 | 157 | #### 0x00 安装 MSVC 工具链 & Windows SDK 158 | 159 | 构建 LiteLoaderBDS 插件需要 MSVC 工具链。 160 | 161 | 我建议使用 Visual Studio Installer 来安装它,这样你就不需要在网上寻找下载链接了。 162 | 163 | Visual Studio 2022 是一个强大的 IDE 和调试器,你以后可能会用它来调试。 164 | 165 | 下载 Visual Studio Installer [here](https://visualstudio.microsoft.com/downloads/)。 166 | 167 | 然后安装这个安装器。(这听起来可能有点奇怪 xD.) 168 | 169 | 等待安装完成。 170 | 171 | 打开 Visual Studio Installer。安装 Visual Studio 2022 IDE 并选择 `使用C++的桌面开发`。 172 | 173 | ![image](https://github.com/Jasonzyt/LLPluginTemplate-XMake/assets/66063199/12584dbb-e69c-46a9-aa86-ef3d22774591) 174 | 175 | 最后,点击 `安装`。 176 | 177 | > 顺便说一句,如果你想使用 [vcpkg](https://github.com/microsoft/vcpkg),你必须安装英文语言包。 178 | 179 | #### 0x01 安装 XMake 180 | 181 | 从 [release](https://github.com/xmake-io/xmake/releases/latest) 页面下载 Windows-x64 版本的 XMake 安装器。 182 | 183 | 然后双击安装它。 184 | 185 | #### 0x02 安装 Git 186 | 187 | Git 是一个分布式版本控制系统。我们将使用它来管理我们的项目并将其托管在 GitHub 上。 188 | 189 | 从 [这里](https://git-scm.com/downloads) 下载 Git 并安装它。 190 | 191 | #### 0x02 安装 Visual Studio Code 和扩展 192 | 193 | 首先,让我解释一下为什么我建议使用 VSCode 而不是 CLion 或 VS2022。 194 | 195 | VS2022 绑定了 MSBuild 或 CMake,CLion 绑定了 CMake 或 Make。 196 | 197 | 它们没有一个高度自定义的界面来支持非主流的构建工具。 198 | 199 | 如果你使用 CLion 来开发 LiteLoaderBDS 插件,你将不得不每次添加新文件或修改构建脚本时都要生成 CMakeLists.txt(XMake 提供了这个功能!)。 200 | 201 | VSCode 是一个轻量级的 IDE。它有一个高度自定义的接口来支持构建工具。 202 | 203 | 从 [这里](https://code.visualstudio.com/) 下载 VSCode 并安装它。 204 | 205 | 然后,在扩展市场中安装 `XMake` 扩展和 `C/C++ Extension Pack` 扩展(Ctrl+Shift+X 打开扩展市场,它在侧边栏上)。 206 | 207 | ![image](https://github.com/Jasonzyt/LLPluginTemplate-XMake/assets/66063199/ca59f627-9aba-4d77-88e5-9809fd1ea93c) 208 | 209 | ### 0x1 使用这个模板创建你的项目 210 | 211 | 滚动到本页顶部。点击 `Use this template` 按钮。 212 | 213 | ![image](https://github.com/Jasonzyt/LLPluginTemplate-XMake/assets/66063199/a10a89a0-61a1-4cc3-a6f6-11961f742f54) 214 | 215 | 然后,填写表单并点击 `Create repository from template`。 216 | 217 | > 如果你不想与他人分享你的代码,请选择 `Private`。 218 | 219 | 复制你的项目的 URL。 220 | 221 | 打开终端并 cd 到你想要放置你的项目的目录。 222 | 223 | 然后,运行以下命令来clone你的项目至本地。 224 | 225 | ```bash 226 | git clone --recursive 227 | ``` 228 | 229 | > 使用 `--recursive` 选项来克隆 LiteLoaderBDS SDK 子模块。 230 | 231 | ### 0x2 给你的项目命名 232 | 233 | 运行 `NameYourProject.exe` 来给你的项目命名。 234 | 你可以在命名后删除这个可执行文件。 235 | 236 | ### 0x3 构建你的项目 237 | 238 | 使用 XMake 构建非常简单,只需在你的项目的根目录运行 `xmake build`。 239 | 240 | 本模板提供了一个 after-build 脚本,它会自动将构建好的插件dll复制到 `release/` 目录并按照版本号重命名。 241 | 你可以修改 `xmake.lua` 来自定义构建逻辑,例如,你可以将构建好的插件dll复制到你的 BDS 服务器目录。 242 | 243 | 关于 XMake 的详细接口文档和使用教程在 [这里](https://xmake.io/#/zh-cn/getting_started) 244 | 245 | ### 0x4 运行BDS 246 | 247 | 把构建好的插件dll从 `build/windows/x64/release` 或 `release/` 复制到你的 BDS 安装目录的 `plugins/` 文件夹。 248 | 然后,运行 `bedrock_server_mod.exe` 来启动你的服务器。 249 | 250 | ### 0x5 更新SDK 251 | 252 | 运行 `script/UpdateSDK.cmd` 来更新 LiteLoaderBDS SDK。 253 | ```bash 254 | # At the root directory of your project 255 | script/UpdateSDK.cmd 256 | ``` 257 | 258 | ## 开源许可证 259 | 260 | 本项目使用 [CC0](LICENSE) 许可证。 261 | 262 | ## 致谢 263 | 264 | - [XMake](https://xmake.io) 265 | - [LiteLoaderBDS](https://github.com/LiteLDev/LiteLoaderBDS) 266 | -------------------------------------------------------------------------------- /include/myplugin/Plugin.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Logger; 4 | 5 | namespace my_plugin { 6 | extern Logger logger; 7 | } -------------------------------------------------------------------------------- /include/myplugin/Resource.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Plugin.h" 3 | 4 | #define PLUGIN_NAME "MyPlugin" 5 | #define PLUGIN_DESCRIPTION "My plugin description" 6 | #define PLUGIN_AUTHOR "My name" 7 | #define PLUGIN_VERSION_MAJOR 0 8 | #define PLUGIN_VERSION_MINOR 1 9 | #define PLUGIN_VERSION_PATCH 0 10 | #define PLUGIN_VERSION_BUILD 0 11 | #define PLUGIN_VERSION_STATUS Dev // Dev, Beta or Release 12 | #define PLUGIN_VERSION_IS_RELEASE false 13 | #define PLUGIN_VERSION_COMMIT_SHA Unknown 14 | #define __TO_VERSION_STRING(ver) #ver 15 | #define TO_VERSION_STRING(ver) __TO_VERSION_STRING(ver) 16 | // clang-format off 17 | #if PLUGIN_VERSION_BUILD > 0 && PLUGIN_VERSION_IS_RELEASE // Actions Build 18 | #define PLUGIN_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_PATCH-build.PLUGIN_VERSION_BUILD-PLUGIN_VERSION_COMMIT_SHA) 19 | #elif PLUGIN_VERSION_BUILD > 0 && !PLUGIN_VERSION_IS_RELEASE // Actions Build 20 | #define PLUGIN_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_PATCH-PLUGIN_VERSION_STATUS-build.PLUGIN_VERSION_BUILD-PLUGIN_VERSION_COMMIT_SHA) 21 | #elif PLUGIN_VERSION_BUILD == 0 && PLUGIN_VERSION_IS_RELEASE 22 | #define PLUGIN_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_PATCH) 23 | #elif PLUGIN_VERSION_BUILD == 0 && !PLUGIN_VERSION_IS_RELEASE 24 | #define PLUGIN_VERSION_STRING TO_VERSION_STRING(PLUGIN_VERSION_MAJOR.PLUGIN_VERSION_MINOR.PLUGIN_VERSION_PATCH-PLUGIN_VERSION_STATUS) 25 | #endif 26 | // clang-format on 27 | 28 | #if PLUGIN_VERSION_IS_RELEASE 29 | #define PLUGIN_FILE_VERSION_FLAG VS_FF_DEBUG 30 | #else 31 | #define PLUGIN_FILE_VERSION_FLAG 0x0L 32 | #endif 33 | 34 | #define FILE_VERSION_BLOCK_HEADER 0x04004B0L 35 | #define FILE_VERSION_COMPANY_NAME PLUGIN_AUTHOR 36 | #define FILE_VERSION_LEGAL_COPYRIGHT "Copyright " PLUGIN_AUTHOR " (c) 2023" 37 | #define FILE_VERSION_FILE_DESCRIPTION PLUGIN_DESCRIPTION 38 | #define FILE_VERSION_FILE_VERSION_STRING PLUGIN_VERSION_STRING 39 | #define FILE_VERSION_INTERNAL_NAME PLUGIN_NAME 40 | #define FILE_VERSION_ORIGINAL_FILENAME PLUGIN_NAME ".dll" 41 | #define FILE_VERSION_PRODUCT_NAME FILE_VERSION_INTERNAL_NAME 42 | #define FILE_VERSION_PRODUCT_VERSION_STRING PLUGIN_VERSION_STRING 43 | #define FILE_VERSION_FILE_VERSION PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR, PLUGIN_VERSION_PATCH, PLUGIN_VERSION_BUILD 44 | #define FILE_VERSION_PRODUCT_VERSION FILE_VERSION_FILE_VERSION 45 | -------------------------------------------------------------------------------- /script/UpdateSDK.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | rem https://github.com/LiteLDev/PluginTemplate-CPP/blob/main/update_sdk.cmd 3 | setlocal enabledelayedexpansion 4 | 5 | rem Use system proxy to access git repo if found it configured 6 | for /f "tokens=3* delims= " %%i in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable') do ( 7 | if %%i==0x1 ( 8 | echo [INFO] System Proxy enabled. Adapting proxy settings... 9 | for /f "tokens=3* delims= " %%a in ('Reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer') do set PROXY_ADDR=%%a 10 | set http_proxy=http://!PROXY_ADDR! 11 | set https_proxy=http://!PROXY_ADDR! 12 | echo [INFO] Proxy settings adapted. 13 | echo. 14 | ) 15 | ) 16 | 17 | echo [INFO] Updating SDK... 18 | 19 | git submodule update --init --remote 20 | 21 | rem Delete out-of-date BDS libs 22 | del /f SDK\Lib\bedrock_server_api.lib 2>nul 23 | del /f SDK\Lib\bedrock_server_var.lib 2>nul 24 | 25 | echo [INFO] SDK updated. 26 | pause -------------------------------------------------------------------------------- /src/DllMain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | BOOL APIENTRY DllMain(HMODULE, DWORD reasonForCall, LPVOID) { 6 | switch (reasonForCall) { 7 | case DLL_PROCESS_ATTACH: 8 | ll::registerPlugin(PLUGIN_NAME, PLUGIN_DESCRIPTION, 9 | ll::Version(PLUGIN_VERSION_MAJOR, PLUGIN_VERSION_MINOR, PLUGIN_VERSION_PATCH, 10 | ll::Version::PLUGIN_VERSION_STATUS), 11 | std::map{{"Author", PLUGIN_AUTHOR}}); 12 | break; 13 | case DLL_THREAD_ATTACH: 14 | case DLL_THREAD_DETACH: 15 | case DLL_PROCESS_DETACH: 16 | break; 17 | } 18 | return TRUE; 19 | } 20 | 21 | namespace my_plugin { 22 | void Entry(); 23 | } 24 | 25 | extern "C" _declspec(dllexport) void onPostInit() { 26 | my_plugin::Entry(); 27 | } 28 | -------------------------------------------------------------------------------- /src/Plugin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace my_plugin { 8 | 9 | Logger logger(PLUGIN_NAME); 10 | 11 | void Entry() { 12 | logger.info("Hello, world!"); 13 | Event::PlayerJoinEvent::subscribe([](const Event::PlayerJoinEvent& event) { 14 | logger.info("Player " + event.mPlayer->getName() + " joined the server!"); 15 | return true; 16 | }); 17 | } 18 | 19 | } // namespace my_plugin -------------------------------------------------------------------------------- /src/Resource.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "myplugin/Resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "winres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // 中文(简体,中国) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) 19 | LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED 20 | #pragma code_page(936) 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "Resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Version 51 | // 52 | 53 | VS_VERSION_INFO VERSIONINFO 54 | FILEVERSION FILE_VERSION_FILE_VERSION 55 | PRODUCTVERSION FILE_VERSION_PRODUCT_VERSION 56 | FILEFLAGSMASK 0x3fL 57 | FILEFLAGS PLUGIN_FILE_VERSION_FLAG 58 | FILEOS 0x40004L 59 | FILETYPE 0x0L 60 | FILESUBTYPE 0x0L 61 | BEGIN 62 | BLOCK "StringFileInfo" 63 | BEGIN 64 | BLOCK "040004b0" 65 | BEGIN 66 | VALUE "CompanyName", FILE_VERSION_COMPANY_NAME 67 | VALUE "FileDescription", FILE_VERSION_FILE_DESCRIPTION 68 | VALUE "FileVersion", FILE_VERSION_FILE_VERSION_STRING 69 | VALUE "InternalName", FILE_VERSION_INTERNAL_NAME 70 | VALUE "LegalCopyright", FILE_VERSION_LEGAL_COPYRIGHT 71 | VALUE "OriginalFilename", FILE_VERSION_ORIGINAL_FILENAME 72 | VALUE "ProductName", FILE_VERSION_PRODUCT_NAME 73 | VALUE "ProductVersion", FILE_VERSION_PRODUCT_VERSION_STRING 74 | END 75 | END 76 | BLOCK "VarFileInfo" 77 | BEGIN 78 | VALUE "Translation", 0x400, 1200 79 | END 80 | END 81 | 82 | #endif // 中文(简体,中国) resources 83 | ///////////////////////////////////////////////////////////////////////////// 84 | 85 | 86 | 87 | #ifndef APSTUDIO_INVOKED 88 | ///////////////////////////////////////////////////////////////////////////// 89 | // 90 | // Generated from the TEXTINCLUDE 3 resource. 91 | // 92 | 93 | 94 | ///////////////////////////////////////////////////////////////////////////// 95 | #endif // not APSTUDIO_INVOKED 96 | -------------------------------------------------------------------------------- /xmake.lua: -------------------------------------------------------------------------------- 1 | set_plat("windows") 2 | set_arch("x64") 3 | set_toolchains("msvc") 4 | 5 | -- add_requires(...) 6 | 7 | target("MyPlugin") 8 | set_rules("mode.release") 9 | set_kind("shared") 10 | 11 | -- add_packages(...) 12 | add_files("src/*.cpp") 13 | add_files("src/*.rc") 14 | add_headerfiles("include/*.h") 15 | add_headerfiles("include/*.hpp") 16 | add_includedirs("SDK/include") 17 | add_includedirs("include") 18 | add_defines( 19 | "UNICODE", 20 | "_UNICODE", 21 | "NDEBUG", 22 | "WIN32_LEAN_AND_MEAN", 23 | "_CRT_SECURE_NO_WARNINGS", 24 | "_WINDOWS", 25 | "_USRDLL", 26 | "_AMD64_", 27 | "NOMINMAX" 28 | ) 29 | set_warnings("all") 30 | set_optimize("fastest") 31 | set_languages("c17", "cxx20") 32 | add_linkdirs( 33 | "SDK/lib" 34 | ) 35 | add_links( 36 | "bedrock_server_api", 37 | "bedrock_server_var", 38 | "LiteLoader", 39 | "SymDBHelper", 40 | "Delayimp" 41 | -- IMPORTANT: DO NOT CHANGE THE ORDER OF THE LINKS ABOVE 42 | 43 | -- , "xxx" 44 | -- add your libs here 45 | ) 46 | add_cxflags( 47 | "/utf-8", 48 | "/EHsc", 49 | "/GL", 50 | "/permissive-", 51 | "/sdl", 52 | "/Zc:inline", 53 | "/Zi", 54 | "/FS" 55 | ) 56 | add_shflags( 57 | "/DELAYLOAD:bedrock_server.dll", 58 | "/DEBUG" 59 | ) 60 | on_load(function (target) 61 | if (not os.exists("SDK/lib/bedrock_server_api.lib") or not os.exists("SDK/lib/bedrock_server_var.lib")) then 62 | os.cd("SDK/tools") 63 | os.exec("./PeEditor.exe -c -l -o ../lib") 64 | end 65 | end) 66 | after_build(function (target) 67 | local plugin_header_file = "include/myplugin/Resource.h" 68 | local basename = target:basename() 69 | local filename = target:filename() 70 | import("lib.detect.find_tool") 71 | local cl = find_tool("cl.exe") 72 | if cl then 73 | io.writefile("preprocess.cpp", "#include \"" .. plugin_header_file .. "\"\nPLUGIN_VERSION_STRING") 74 | os.run('"' .. cl.program .. "\" /P /EP preprocess.cpp") 75 | local text = io.readfile("./preprocess.i") 76 | os.rm("./preprocess.*") 77 | local startIndex = -1 78 | local endIndex = -1 79 | for i=#text,1,-1 do 80 | local ch = string.sub(text, i, i) 81 | if ch == '"' then 82 | if endIndex == -1 then 83 | endIndex = i 84 | else 85 | startIndex = i 86 | break 87 | end 88 | end 89 | end 90 | local version = string.sub(text, startIndex + 1, endIndex - 1) 91 | filename = basename .. "-v" .. version .. ".dll" 92 | end 93 | if not os.exists("./release") then 94 | os.mkdir("./release") 95 | end 96 | os.cp(target:targetfile(), "./release/" .. filename) 97 | os.cp(target:targetdir() .. '/' .. basename .. ".pdb", "./release/") 98 | end) 99 | --------------------------------------------------------------------------------