-
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "ll/core/tweak/ForceEnableCheatCommands.h" | ||
|
||
#include "mc/enums/SemanticConstraint.h" | ||
#include "mc/server/commands/CommandFlag.h" | ||
#include "mc/server/commands/CommandOrigin.h" | ||
#include "mc/server/commands/CommandPermissionLevel.h" | ||
#include "mc/server/commands/CommandRegistry.h" | ||
#include "mc/server/commands/CommandSelectorBase.h" | ||
|
||
#include "ll/api/memory/Hook.h" | ||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace ll { | ||
|
||
namespace force_enable_cheat_commands { | ||
|
||
LL_TYPE_INSTANCE_HOOK( | ||
CommandRegistryRegisterCommandHook, | ||
ll::memory::HookPriority::Normal, | ||
CommandRegistry, | ||
&CommandRegistry::registerCommand, | ||
void, | ||
std::string const& name, | ||
char const* description, | ||
::CommandPermissionLevel requirement, | ||
CommandFlag flag1, | ||
CommandFlag flag2 | ||
) { | ||
flag1 |= CommandFlagValue::NotCheat; | ||
return origin(name, description, requirement, flag1, flag2); | ||
} | ||
|
||
LL_TYPE_INSTANCE_HOOK( | ||
CommandSelectorBaseIsExpansionAllowedHook, | ||
ll::memory::HookPriority::Normal, | ||
CommandSelectorBase, | ||
&CommandSelectorBase::isExpansionAllowed, | ||
bool, | ||
CommandOrigin const& ori | ||
) { | ||
origin(ori); | ||
return true; | ||
} | ||
|
||
LL_TYPE_INSTANCE_HOOK( | ||
CommandRegistryAddEnumValueConstraintsHook, | ||
ll::memory::HookPriority::Normal, | ||
CommandRegistry, | ||
&CommandRegistry::addEnumValueConstraints, | ||
void, | ||
std::string const& enumName, | ||
std::vector<std::string> const& enumValues, | ||
SemanticConstraint constraint | ||
) { | ||
constraint = static_cast<SemanticConstraint>( | ||
static_cast<unsigned char>(constraint) & ~static_cast<unsigned char>(SemanticConstraint::RequiresCheatsEnabled) | ||
); | ||
return origin(enumName, enumValues, constraint); | ||
} | ||
|
||
} // namespace force_enable_cheat_commands | ||
|
||
struct ForceEnableCheatCommands::Impl { | ||
memory::HookRegistrar< | ||
force_enable_cheat_commands::CommandRegistryRegisterCommandHook, | ||
force_enable_cheat_commands::CommandSelectorBaseIsExpansionAllowedHook, | ||
force_enable_cheat_commands::CommandRegistryAddEnumValueConstraintsHook> | ||
r; | ||
}; | ||
|
||
void ForceEnableCheatCommands::call(bool enable) { | ||
if (enable) { | ||
if (!impl) impl = std::make_unique<Impl>(); | ||
} else { | ||
impl.reset(); | ||
} | ||
}; | ||
|
||
ForceEnableCheatCommands::ForceEnableCheatCommands() = default; | ||
ForceEnableCheatCommands::~ForceEnableCheatCommands() = default; | ||
} // namespace ll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
namespace ll { | ||
|
||
struct ForceEnableCheatCommands { | ||
struct Impl; | ||
std::unique_ptr<Impl> impl; | ||
|
||
void call(bool); | ||
ForceEnableCheatCommands(); | ||
~ForceEnableCheatCommands(); | ||
}; | ||
|
||
} // namespace ll |