From 562d03352084f0d7fe2e75ccf92de25913c20e60 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Mon, 24 Jan 2022 01:12:18 +0800 Subject: [PATCH] depends on liteloader, no cmake --- .gitignore | 1 - .gitmodules | 3 + LiteLoaderSDK | 1 + TrapDoor.sln | 31 ++ TrapDoor.vcxproj | 261 +++++++++++++++++ api/BDSMod.cpp | 5 + api/commands/TrapdoorCommand.cpp | 467 +++++++++++++++++++++++++++++++ api/commands/TrapdoorCommand.h | 4 + api/tools/DirtyLogger.h | 2 +- mod/dllmain.cpp | 6 + 10 files changed, 779 insertions(+), 2 deletions(-) create mode 100644 .gitmodules create mode 160000 LiteLoaderSDK create mode 100644 TrapDoor.sln create mode 100644 TrapDoor.vcxproj create mode 100644 api/commands/TrapdoorCommand.cpp create mode 100644 api/commands/TrapdoorCommand.h diff --git a/.gitignore b/.gitignore index 8632e57..b16905a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,7 +25,6 @@ log/ /x64 *.filters *.user -*.vcxproj *.zip /vsbuild /tools/sym/*.txt \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..fa7c2a8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "LiteLoaderSDK"] + path = LiteLoaderSDK + url = https://github.com/LiteLDev/LiteLoaderSDK.git \ No newline at end of file diff --git a/LiteLoaderSDK b/LiteLoaderSDK new file mode 160000 index 0000000..585d8eb --- /dev/null +++ b/LiteLoaderSDK @@ -0,0 +1 @@ +Subproject commit 585d8eb383ab8c073286e59c06999f99f616f994 diff --git a/TrapDoor.sln b/TrapDoor.sln new file mode 100644 index 0000000..005490f --- /dev/null +++ b/TrapDoor.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31919.166 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TrapDoor", "TrapDoor.vcxproj", "{5E59C2BC-C426-4006-8C65-FBDC286F228D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Debug|x64.ActiveCfg = Debug|x64 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Debug|x64.Build.0 = Debug|x64 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Debug|x86.ActiveCfg = Debug|Win32 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Debug|x86.Build.0 = Debug|Win32 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Release|x64.ActiveCfg = Release|x64 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Release|x64.Build.0 = Release|x64 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Release|x86.ActiveCfg = Release|Win32 + {5E59C2BC-C426-4006-8C65-FBDC286F228D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EEEAB9E4-793F-49F5-B465-F1968DA44C37} + EndGlobalSection +EndGlobal diff --git a/TrapDoor.vcxproj b/TrapDoor.vcxproj new file mode 100644 index 0000000..94695dd --- /dev/null +++ b/TrapDoor.vcxproj @@ -0,0 +1,261 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + {5E59C2BC-C426-4006-8C65-FBDC286F228D} + Win32Proj + 10.0 + + + + Application + true + v143 + + + Application + false + v143 + + + Application + true + v143 + + + DynamicLibrary + false + v143 + Unicode + true + + + + + + + + + + + + + + + + + + + + + true + + + true + + + $(SolutionDir)\LiteLoaderSDK\Header;$(SolutionDir)\LiteLoaderSDK;$(SolutionDir)\api;$(SolutionDir)\mod;$(SolutionDir)\api\entity;$(SolutionDir)\api\lib;$(SolutionDir)\api\block;$(SolutionDir)\api\commands;$(SolutionDir)\api\graphics;$(SolutionDir)\api\language;$(SolutionDir)\api\tools;$(SolutionDir)\api\world;$(SolutionDir)\mod\spawn;$(SolutionDir)\mod\village;$(SolutionDir)\mod\config;$(IncludePath) + $(ProjectName)_LL + + + + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + + + MachineX86 + true + Windows + + + + + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + + + MachineX86 + true + Windows + true + true + + + + + stdcpp17 + /D _SILENCE_CXX17_RESULT_OF_DEPRECATION_WARNING /D _CRT_SECURE_NO_WARNINGS /wd4828 /wd4819 /utf-8 %(AdditionalOptions) + NDEBUG;_WINDOWS;_USRDLL;_ADM64_;_AMD64_;%(PreprocessorDefinitions) + true + true + true + true + Async + + + bedrock_server.dll + + + if not exist $(SolutionDir)LiteLoaderSDK\Lib\bedrock_server_api.lib goto process +if not exist $(SolutionDir)LiteLoaderSDK\Lib\bedrock_server_var.lib goto process +goto end + +:process +cd /d $(SolutionDir)\LiteLoaderSDK\Tools\ +if exist $(LocalDebuggerWorkingDirectory)\bedrock_server.pdb ( +LibraryBuilder.exe -o ..\Lib\ $(LocalDebuggerWorkingDirectory) +) else ( +LibraryBuilder.exe -o ..\Lib\ +) + +:end + + + + if exist $(LocalDebuggerWorkingDirectory)\plugins\ ( +copy /Y $(TargetPath) $(LocalDebuggerWorkingDirectory)\plugins +) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/BDSMod.cpp b/api/BDSMod.cpp index a4d3743..27e018f 100644 --- a/api/BDSMod.cpp +++ b/api/BDSMod.cpp @@ -8,6 +8,8 @@ #include "lib/mod.h" #include "tools/DirtyLogger.h" #include "tools/Message.h" +#include "commands/TrapdoorCommand.h" + namespace trapdoor { //全局模组对象 @@ -16,6 +18,7 @@ namespace trapdoor { void initializeMod(BDSMod *BDSMod) { L_DEBUG("create BDS mod instance"); trapdoor::bdsMod = BDSMod; + registryCommand(); } Level *BDSMod::getLevel() { return this->serverLevel; } @@ -85,4 +88,6 @@ namespace trapdoor { } void BDSMod::tick() { ++this->trapdoorTick; } + + } // namespace trapdoor diff --git a/api/commands/TrapdoorCommand.cpp b/api/commands/TrapdoorCommand.cpp new file mode 100644 index 0000000..7c78986 --- /dev/null +++ b/api/commands/TrapdoorCommand.cpp @@ -0,0 +1,467 @@ + +#include +#include "TrapdoorCommand.h" + +#include "../../LiteLoaderSDK/Header/EventAPI.h" +#include "../../LiteLoaderSDK/Header/RegCommandAPI.h" + +using namespace RegisterCommandHelper; +class VillageCommand : public Command { + enum class Operation { + Help, + Bound, + Center, + List, + Nearest, + POIBound, + Spawning, + Test, + Verbels, + } mOperation; + bool mSwitch; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "village", "村庄相关功能", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("VillageAction", + {{"?", Operation::Help}, + {"list", Operation::List}, + {"n", Operation::Nearest}, + {"test", Operation::Test}}); + registry.addEnum("VillageActionSwitch", + {{"b", Operation::Bound}, + {"c", Operation::Center}, + {"p", Operation::POIBound}, + {"s", Operation::Spawning}, + {"v", Operation::Verbels}}); + auto action = makeMandatory( + &VillageCommand::mOperation, "action", "VillageAction"); + auto actionSwitch = makeMandatory( + &VillageCommand::mOperation, "action", "VillageActionSwitch"); + action.addOptions((CommandParameterOption)1); + actionSwitch.addOptions((CommandParameterOption)1); + + auto switchParam = makeMandatory(&VillageCommand::mSwitch, "activate"); + + registry.registerOverload("village", action); + registry.registerOverload("village", actionSwitch, + switchParam); + }; +}; +class ApiCfgCommand : public Command { + enum class Operation { + Help, + VisibleDistance, + PM, + } mOperation; + bool mSwitch; + int mDistance; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "apicfg", "粒子显示效果设置", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("ApiCfgAction", { + {"?", Operation::Help}, + }); + registry.addEnum("ApiCfgActionSwitch", + { + {"pvd", Operation::VisibleDistance}, + }); + registry.addEnum("ApiCfgActionInt", + { + {"pm", Operation::PM}, + }); + auto action = makeMandatory( + &ApiCfgCommand::mOperation, "action", "ApiCfgAction"); + auto actionSwitch = makeMandatory( + &ApiCfgCommand::mOperation, "action", "ApiCfgActionSwitch"); + auto actionInt = makeMandatory( + &ApiCfgCommand::mOperation, "action", "ApiCfgActionInt"); + action.addOptions((CommandParameterOption)1); + actionSwitch.addOptions((CommandParameterOption)1); + actionInt.addOptions((CommandParameterOption)1); + + auto switchParam = makeMandatory(&ApiCfgCommand::mSwitch, "switch"); + auto distanceParam = + makeMandatory(&ApiCfgCommand::mDistance, "VisibleDistance"); + + registry.registerOverload("apicfg", action); + registry.registerOverload("apicfg", actionSwitch, + switchParam); + registry.registerOverload("apicfg", actionInt, + distanceParam); + }; +}; +class TickCommand : public Command { + enum class Operation { + Help, + Frezze, + Slow, + Accelerate, + Forward, + Reset, + Qurey, + } mOperation; + int mTick; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "tick", "改变世界运行状态", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("TickActionInt", + { + {"acc", Operation::Accelerate}, + {"fw", Operation::Forward}, + {"slow", Operation::Slow}, + }); + registry.addEnum("TickAction", { + {"?", Operation::Help}, + {"fz", Operation::Frezze}, + {"q", Operation::Qurey}, + {"r", Operation::Reset}, + }); + auto actionInt = makeMandatory( + &TickCommand::mOperation, "action", "TickActionInt"); + auto action = makeMandatory( + &TickCommand::mOperation, "action", "TickAction"); + actionInt.addOptions((CommandParameterOption)1); + action.addOptions((CommandParameterOption)1); + + auto tickParam = makeMandatory(&TickCommand::mTick, "radius"); + + registry.registerOverload("tick", actionInt, tickParam); + registry.registerOverload("tick", action); + }; +}; +class ProfileCommand : public Command { + enum class Operation { + Help, + Actor, + } mOperation; + bool mOperation_isSet; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "prof", "游戏性能分析", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("ProfileAction", + { + {"?", Operation::Help}, + {"actor", Operation::Actor}, + }); + auto action = makeMandatory( + &ProfileCommand::mOperation, "action", "ProfileAction", + &ProfileCommand::mOperation_isSet); + action.addOptions((CommandParameterOption)1); + + registry.registerOverload("prof"); + registry.registerOverload("prof", action); + }; +}; +class FunctionCommand : public Command { + enum class Operation { + Help, + Draw, + Explosion, + Hopper, + NeighborChanged, + Rotate, + Spawn, + } mOperation; + bool mSwitch; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "func", "部分全局功能的开关", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("FunctionAction", + { + {"?", Operation::Help}, + }); + registry.addEnum("FunctionActionSwitch", + { + {"draw", Operation::Draw}, + {"expl", Operation::Explosion}, + {"hopper", Operation::Hopper}, + {"ncud", Operation::NeighborChanged}, + {"rotate", Operation::Rotate}, + {"spawn", Operation::Spawn}, + }); + auto action = makeMandatory( + &FunctionCommand::mOperation, "action", "FunctionAction"); + auto actionSwitch = makeMandatory( + &FunctionCommand::mOperation, "action", "FunctionActionSwitch"); + action.addOptions((CommandParameterOption)1); + actionSwitch.addOptions((CommandParameterOption)1); + + auto switchParam = makeMandatory(&FunctionCommand::mSwitch, "switch"); + + registry.registerOverload("func", action); + registry.registerOverload("func", actionSwitch, + switchParam); + }; +}; +class HSACommand : public Command { + enum class Operation { + Help, + Show, + Clear, + Draw, + Find, + List, + } mOperation; + bool mSwitch; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "hsa", "部分全局功能的开关", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("HSAActionSwitch", + { + {"show", Operation::Show}, + }); + registry.addEnum("HSAAction", + { + {"?", Operation::Help}, + {"clear", Operation::Clear}, + {"draw", Operation::Draw}, + {"find", Operation::Find}, + {"list", Operation::List}, + }); + auto actionSwitch = makeMandatory( + &HSACommand::mOperation, "action", "HSAActionSwitch"); + auto action = makeMandatory( + &HSACommand::mOperation, "action", "HSAAction"); + actionSwitch.addOptions((CommandParameterOption)1); + action.addOptions((CommandParameterOption)1); + + auto switchParam = makeMandatory(&HSACommand::mSwitch, "switch"); + + registry.registerOverload("hsa", actionSwitch, switchParam); + registry.registerOverload("hsa", action); + }; +}; +class SlimeCommand : public Command { + enum class Operation { + Help, + Show, + Clear, + Radius, + } mOperation; + bool mSwitch; + int mRadius; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "slime", "部分全局功能的开关", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("SlimeActionSwitch", + { + {"show", Operation::Show}, + }); + registry.addEnum("SlimeActionInt", + { + {"r", Operation::Radius}, + }); + registry.addEnum("SlimeAction", { + {"?", Operation::Help}, + {"c", Operation::Clear}, + }); + auto actionSwitch = makeMandatory( + &SlimeCommand::mOperation, "action", "SlimeActionSwitch"); + auto actionInt = makeMandatory( + &SlimeCommand::mOperation, "action", "SlimeActionInt"); + auto action = makeMandatory( + &SlimeCommand::mOperation, "action", "SlimeAction"); + actionSwitch.addOptions((CommandParameterOption)1); + actionInt.addOptions((CommandParameterOption)1); + action.addOptions((CommandParameterOption)1); + + auto switchParam = makeMandatory(&SlimeCommand::mSwitch, "switch"); + auto radiusParam = makeMandatory(&SlimeCommand::mRadius, "radius"); + + registry.registerOverload("slime", actionSwitch, + switchParam); + registry.registerOverload("slime", actionInt, + radiusParam); + registry.registerOverload("slime", action); + }; +}; +class SelfCommand : public Command { + enum class Operation { + Help, + Chunk, + Measuring, + RedstoneSource, + } mOperation; + bool mSwitch; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "slime", "部分全局功能的开关", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("SelfAction", { + {"?", Operation::Help}, + }); + registry.addEnum("SelfActionSwitch", + { + {"chunk", Operation::Chunk}, + {"me", Operation::Measuring}, + {"rs", Operation::RedstoneSource}, + }); + auto action = makeMandatory( + &SelfCommand::mOperation, "action", "SelfAction"); + auto actionSwitch = makeMandatory( + &SelfCommand::mOperation, "action", "SelfActionSwitch"); + action.addOptions((CommandParameterOption)1); + actionSwitch.addOptions((CommandParameterOption)1); + + auto switchParam = makeMandatory(&SelfCommand::mSwitch, "switch"); + + registry.registerOverload("slime", action); + registry.registerOverload("slime", actionSwitch, + switchParam); + }; +}; +class DrawCommand : public Command { + enum class Operation { + Help, + Chunk, + Circle, + MaxRadius, + Sphere, + } mOperation; + int mRadius; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "draw", "简单建造", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("DrawAction", { + {"?", Operation::Help}, + {"ch", Operation::Chunk}, + }); + registry.addEnum("DrawActionInt", + { + {"ci", Operation::Circle}, + {"ci", Operation::Circle}, + {"mr", Operation::MaxRadius}, + {"sp", Operation::Sphere}, + }); + auto action = makeMandatory( + &DrawCommand::mOperation, "action", "DrawAction"); + auto actionInt = makeMandatory( + &DrawCommand::mOperation, "action", "DrawActionInt"); + action.addOptions((CommandParameterOption)1); + actionInt.addOptions((CommandParameterOption)1); + + auto radiusParam = makeMandatory(&DrawCommand::mRadius, "radius"); + + registry.registerOverload("draw", action); + registry.registerOverload("draw", action, radiusParam); + }; +}; +class CounterCommand : public Command { + enum class Operation { + Help, + Print, + Reset, + } mOperation; + bool mSwitch; + int mDistance; + virtual void execute(class CommandOrigin const& origin, + class CommandOutput& output) const override { + output.error("Please install trapdoor"); + }; + + public: + static void setup(CommandRegistry& registry) { + registry.registerCommand( + "counter", "漏斗计数器", CommandPermissionLevel::Any, + {(CommandFlagValue)0}, {(CommandFlagValue)0x80}); + registry.addEnum("CounterAction", { + {"?", Operation::Help}, + }); + registry.addEnum("CounterActionInt", + { + {"p", Operation::Print}, + {"r", Operation::Reset}, + }); + auto action = makeMandatory( + &CounterCommand::mOperation, "action", "CounterAction"); + auto actionInt = makeMandatory( + &CounterCommand::mOperation, "action", "CounterActionInt"); + action.addOptions((CommandParameterOption)1); + actionInt.addOptions((CommandParameterOption)1); + + auto channelParam = + makeMandatory(&CounterCommand::mDistance, "Channel"); + + registry.registerOverload("counter", action); + registry.registerOverload("counter", actionInt, + channelParam); + }; +}; + +void registryCommand() { + Event::RegCmdEvent::subscribe([](Event::RegCmdEvent ev) { + VillageCommand::setup(*ev.mCommandRegistry); + ApiCfgCommand::setup(*ev.mCommandRegistry); + TickCommand::setup(*ev.mCommandRegistry); + ProfileCommand::setup(*ev.mCommandRegistry); + FunctionCommand::setup(*ev.mCommandRegistry); + HSACommand::setup(*ev.mCommandRegistry); + SlimeCommand::setup(*ev.mCommandRegistry); + SelfCommand::setup(*ev.mCommandRegistry); + DrawCommand::setup(*ev.mCommandRegistry); + CounterCommand::setup(*ev.mCommandRegistry); + return true; + }); +} diff --git a/api/commands/TrapdoorCommand.h b/api/commands/TrapdoorCommand.h new file mode 100644 index 0000000..8c93e01 --- /dev/null +++ b/api/commands/TrapdoorCommand.h @@ -0,0 +1,4 @@ +#pragma once + +void registryCommand(); + diff --git a/api/tools/DirtyLogger.h b/api/tools/DirtyLogger.h index 18025fa..6de549c 100644 --- a/api/tools/DirtyLogger.h +++ b/api/tools/DirtyLogger.h @@ -11,7 +11,7 @@ #define __FILENAME__ \ (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 \ : __FILE__) -#elif +#else #define __FILENAME__ \ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 \ : __FILE__) diff --git a/mod/dllmain.cpp b/mod/dllmain.cpp index f5fc129..68a19a8 100644 --- a/mod/dllmain.cpp +++ b/mod/dllmain.cpp @@ -2,6 +2,12 @@ #include +#pragma comment(lib, "LiteLoaderSDK/Lib/bedrock_server_api.lib") +#pragma comment(lib, "LiteLoaderSDK/Lib/bedrock_server_var.lib") +#pragma comment(lib, "LiteLoaderSDK/Lib/SymDBHelper.lib") +#pragma comment(lib, "LiteLoaderSDK/Lib/LiteLoader.lib") +#pragma comment(lib, "api/lib/detours.lib") + #include "BDSMod.h" #include "TrapdoorMod.h" #include "lib/Remotery.h"