Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
v0.1.5 Add CommandRegister, add CommandBlockExecute Event
Browse files Browse the repository at this point in the history
  • Loading branch information
KawaiiNahida committed Feb 15, 2021
1 parent 1544920 commit ac1dce5
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 81 deletions.
Binary file modified LiteLoader/LiteLoader.aps
Binary file not shown.
1 change: 0 additions & 1 deletion LiteLoader/LiteLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ static void loadPlugins() {
printf(info, plugins, LiteLoaderVersion);
#endif
}

static void entry(bool fixcwd) {
loadPlugins();
}
Expand Down
8 changes: 4 additions & 4 deletions LiteLoader/LiteLoader.rc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ END
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,1,4,0
PRODUCTVERSION 0,1,4,0
FILEVERSION 0,1,5,0
PRODUCTVERSION 0,1,5,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "LiteLoaderDev"
VALUE "FileDescription", "A lightweight Bedorck Dedicated Server Plugin Loader "
VALUE "FileVersion", "0.1.4.0"
VALUE "FileVersion", "0.1.5.0"
VALUE "InternalName", "LiteLoad.dll"
VALUE "LegalCopyright", "LiteLoader Developer"
VALUE "OriginalFilename", "LiteLoad.dll"
VALUE "ProductName", "LiteLoader For BDS"
VALUE "ProductVersion", "0.1.4.0"
VALUE "ProductVersion", "0.1.5.0"
END
END
BLOCK "VarFileInfo"
Expand Down
3 changes: 3 additions & 0 deletions LiteLoader/LiteLoader.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="..\headers\api\Basic_Event.h" />
<ClInclude Include="..\headers\api\commands.h" />
<ClInclude Include="..\headers\api\serviceLocate.h" />
<ClInclude Include="..\headers\api\types\helper.h" />
<ClInclude Include="..\headers\api\types\types.h" />
Expand All @@ -171,6 +172,8 @@
<ClInclude Include="..\headers\mc\Certificate.h" />
<ClInclude Include="..\headers\mc\Command.h" />
<ClInclude Include="..\headers\mc\CommandUtils.h" />
<ClInclude Include="..\headers\mc\Command\Command.h" />
<ClInclude Include="..\headers\mc\Command\CommandReg.h" />
<ClInclude Include="..\headers\mc\Core.h" />
<ClInclude Include="..\headers\mc\Dimension.h" />
<ClInclude Include="..\headers\mc\Item.h" />
Expand Down
12 changes: 12 additions & 0 deletions LiteLoader/LiteLoader.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
<Filter Include="头文件\api\types">
<UniqueIdentifier>{2911c288-227a-404e-ae09-17b63cb54f34}</UniqueIdentifier>
</Filter>
<Filter Include="头文件\mc\CommandReg">
<UniqueIdentifier>{c56a4f7b-2ab1-43d8-8bec-c2499ff2849a}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
Expand Down Expand Up @@ -156,6 +159,15 @@
<ClInclude Include="resource.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="..\headers\mc\Command\Command.h">
<Filter>头文件\mc\CommandReg</Filter>
</ClInclude>
<ClInclude Include="..\headers\mc\Command\CommandReg.h">
<Filter>头文件\mc\CommandReg</Filter>
</ClInclude>
<ClInclude Include="..\headers\api\commands.h">
<Filter>头文件\api</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
Expand Down
31 changes: 26 additions & 5 deletions LiteLoader/api/Basic_Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,47 @@ Player* MakeSP(CommandOrigin& ori) {
return 0;
}

vector<function<void(PlayerUseCmdEV)>> PlayerUseCmdCallBacks;
LIAPI void Event::addEventListener(function<void(PlayerUseCmdEV)> callback) {
vector<function<bool(PlayerUseCmdEV)>> PlayerUseCmdCallBacks;
LIAPI void Event::addEventListener(function<bool(PlayerUseCmdEV)> callback) {
PlayerUseCmdCallBacks.push_back(callback);
}
THook(MCRESULT,"?executeCommand@MinecraftCommands@@QEBA?AUMCRESULT@@V?$shared_ptr@VCommandContext@@@std@@_N@Z",
THook(bool,"?executeCommand@MinecraftCommands@@QEBA?AUMCRESULT@@V?$shared_ptr@VCommandContext@@@std@@_N@Z",
MinecraftCommands* _this, unsigned int* a2, std::shared_ptr<CommandContext> x, char a4) {

Player* sp = MakeSP(x->getOrigin());
MCRESULT result = original(_this, a2, x, a4);
bool result = original(_this, a2, x, a4);
if (sp) {
string cmd = x->getCmd();
if (cmd.at(0) == '/') {
cmd = cmd.substr(1, cmd.size() - 1);
}
PlayerUseCmdEV PlayerUseCmdEV = { sp,cmd,result};
for (size_t count = 0; count < PlayerUseCmdCallBacks.size(); count++) {
PlayerUseCmdCallBacks[count](PlayerUseCmdEV);
bool ret = PlayerUseCmdCallBacks[count](PlayerUseCmdEV);
if (ret)
return true;
}
}
return result;
}
class BaseCommandBlock;
class BlockSource;

vector<function<bool(CmdBlockExeEV)>> CmdBlockExeEVCallBacks;
LIAPI void Event::addEventListener(function<bool(CmdBlockExeEV)> callback) {
CmdBlockExeEVCallBacks.push_back(callback);
}
THook(bool, "?_performCommand@BaseCommandBlock@@AEAA_NAEAVBlockSource@@AEBVCommandOrigin@@AEA_N@Z",
BaseCommandBlock* _this, BlockSource* a2, CommandOrigin* a3, bool* a4) {
CmdBlockExeEV ev = { offBaseCommandBlock::getCMD(_this),offBaseCommandBlock::getPos(_this) };
for (size_t count = 0; count < CmdBlockExeEVCallBacks.size(); count++) {
bool ret = CmdBlockExeEVCallBacks[count](ev);
if (ret)
return true;
}
return original(_this, a2, a3, a4);
}


vector<function<void(PlayerDeathEV)>> PlayerDeathCallBacks;
LIAPI void Event::addEventListener(function<void(PlayerDeathEV)> callback) {
Expand Down
16 changes: 16 additions & 0 deletions LiteLoader/mc/ServiceLocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ THook(void, "?startServerThread@ServerInstance@@QEAAXXZ", void* a) {
}
}

class CommandRegistry;
vector<function<void(RegCmdEV)>> RegCmdEVCallBacks;
LIAPI void Event::addEventListener(function<void(RegCmdEV)> callback) {
RegCmdEVCallBacks.push_back(callback);
}
THook(void, "?setup@ChangeSettingCommand@@SAXAEAVCommandRegistry@@@Z", CommandRegistry* rg, void* a1) {
LocateS<CommandRegistry>::assign(*rg);
original(rg, a1);
cout << "[LiteLoader] Registering cmds" << endl;
RegCmdEV cmdregev = {rg};
for (size_t count = 0; count < RegCmdEVCallBacks.size(); count++) {
RegCmdEVCallBacks[count](cmdregev);
}
}


//?initCoreEnums@MinecraftCommands@@QEAAX_NAEBVBaseGameVersion@@@Z
THook(void, "?initCoreEnums@MinecraftCommands@@QEAAXAEBVIWorldRegistriesProvider@@AEBVActorFactory@@AEBVExperiments@@AEBVBaseGameVersion@@@Z", MinecraftCommands* a0, void* a1, void* a2, void*a3, void*a4) {
original(a0, a1, a2, a3, a4);
Expand Down
16 changes: 15 additions & 1 deletion headers/api/Basic_Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class PlayerUseCmdEV {
MCRESULT mc_result;
};

class CmdBlockExeEV {
public:
string cmd;
BlockPos bpos;
};

class ServerStartedEV {

};
Expand All @@ -48,12 +54,20 @@ class PlayerDeathEV {
ServerPlayer* Player;
};

class CommandRegistry;
class RegCmdEV {
public:
CommandRegistry* CMDRg;
};

namespace Event {
LIAPI void addEventListener(function<void(JoinEV)> callback);
LIAPI void addEventListener(function<void(LeftEV)> callback);
LIAPI void addEventListener(function<void(ChatEV)> callback);
LIAPI void addEventListener(function<void(ChangeDimEV)> callback);
LIAPI void addEventListener(function<void(ServerStartedEV)> callback);
LIAPI void addEventListener(function<void(PlayerUseCmdEV)> callback);
LIAPI void addEventListener(function<bool(PlayerUseCmdEV)> callback);
LIAPI void addEventListener(function<bool(CmdBlockExeEV)> callback);
LIAPI void addEventListener(function<void(RegCmdEV)> callback);
LIAPI void addEventListener(function<void(PlayerDeathEV)> callback);
};
Loading

0 comments on commit ac1dce5

Please # to comment.