diff --git a/src/ll/core/Config.h b/src/ll/core/Config.h index 2fdcb207f4..9cc8eaeded 100644 --- a/src/ll/core/Config.h +++ b/src/ll/core/Config.h @@ -7,13 +7,15 @@ #include "ll/api/base/Macro.h" #include "ll/api/reflection/Dispatcher.h" +#include "ll/core/tweak/ForceEnableCheatCommands.h" #include "ll/core/tweak/SimpleServerLogger.h" + namespace ll { struct LeviConfig { - int version = 11; + int version = 12; std::string language = "system"; struct { @@ -30,7 +32,8 @@ struct LeviConfig { } crashLogger{}; struct { - bool disableAutoCompactionLog = true; + bool disableAutoCompactionLog = true; + ll::reflection::Dispatcher forceEnableCheatCommands = true; } tweak{}; reflection::Dispatcher simpleServerLogger{}; diff --git a/src/ll/core/tweak/ForceEnableCheatCommands.cpp b/src/ll/core/tweak/ForceEnableCheatCommands.cpp new file mode 100644 index 0000000000..7b8b61d034 --- /dev/null +++ b/src/ll/core/tweak/ForceEnableCheatCommands.cpp @@ -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 +#include +#include + +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 const& enumValues, + SemanticConstraint constraint +) { + constraint = static_cast( + static_cast(constraint) & ~static_cast(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(); + } else { + impl.reset(); + } +}; + +ForceEnableCheatCommands::ForceEnableCheatCommands() = default; +ForceEnableCheatCommands::~ForceEnableCheatCommands() = default; +} // namespace ll \ No newline at end of file diff --git a/src/ll/core/tweak/ForceEnableCheatCommands.h b/src/ll/core/tweak/ForceEnableCheatCommands.h new file mode 100644 index 0000000000..3522e2c9ec --- /dev/null +++ b/src/ll/core/tweak/ForceEnableCheatCommands.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +namespace ll { + +struct ForceEnableCheatCommands { + struct Impl; + std::unique_ptr impl; + + void call(bool); + ForceEnableCheatCommands(); + ~ForceEnableCheatCommands(); +}; + +} // namespace ll \ No newline at end of file