mirror of
https://github.com/quizhizhe/LiteLoaderBDS-1.16.40.git
synced 2025-06-03 04:23:39 +00:00
这真指令真不知怎么搞,是我太菜了
This commit is contained in:
parent
c8ac025ed9
commit
be445b32d2
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@
|
||||
#include "Tick.hpp"
|
||||
#include "ActorDamageSource.hpp"
|
||||
#include "SimpleContainer.hpp"
|
||||
#include "ActorDefinitionIdentifier.hpp"
|
||||
class Actor;
|
||||
class Player;
|
||||
class NetworkIdentifier;
|
||||
@ -52,8 +53,8 @@ public:
|
||||
//LIAPI bool stopFire();
|
||||
LIAPI bool hasTag(const string& tag);
|
||||
//LIAPI bool hurtEntity(float damage, ActorDamageCause damageCause = ActorDamageCause::ActorDamageCause_Override);
|
||||
//LIAPI bool teleport(Vec3 to, int dimID, float x, float y);
|
||||
//LIAPI bool teleport(Vec3 pos,int dimid);
|
||||
LIAPI bool teleport(Vec3 to, int dimID, float x, float y);
|
||||
LIAPI bool teleport(Vec3 pos,int dimid);
|
||||
LIAPI ItemStack* getHandSlot();
|
||||
LIAPI bool rename(const string& name);
|
||||
LIAPI std::unique_ptr<CompoundTag> getNbt();
|
||||
@ -84,6 +85,15 @@ public:
|
||||
return (dAccess<ActorCategory>(this, 79) & actorCategory) !=0;
|
||||
};
|
||||
|
||||
Vec2 getRotation() const{
|
||||
// Actor::getMapDecorationRotation
|
||||
return dAccess<Vec2>(this, 65);
|
||||
};
|
||||
ActorDefinitionIdentifier getActorIdentifier() const{
|
||||
//ServerPlayer::handleActorPickRequestOnServer Line144 1048-128-8 = 912;
|
||||
return dAccess<ActorDefinitionIdentifier>(this, 912);
|
||||
}
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_ACTOR
|
||||
public:
|
||||
|
@ -4,12 +4,55 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
class Actor;
|
||||
|
||||
enum ActorDamageCause : int {
|
||||
ActorDamageCause_None = -0x01,
|
||||
ActorDamageCause_Override = 0x00,
|
||||
ActorDamageCause_Contact = 0x01,
|
||||
ActorDamageCause_EntityAttack = 0x02,
|
||||
ActorDamageCause_Projectile = 0x03,
|
||||
ActorDamageCause_Suffocation = 0x04,
|
||||
FActorDamageCause_all = 0x05,
|
||||
ActorDamageCause_Fire = 0x06,
|
||||
ActorDamageCause_FireTick = 0x07,
|
||||
ActorDamageCause_Lava = 0x08,
|
||||
ActorDamageCause_Drowning = 0x09,
|
||||
ActorDamageCause_BlockExplosion = 0x0A,
|
||||
ActorDamageCause_EntityExplosion = 0x0B,
|
||||
ActorDamageCause_Void = 0x0C,
|
||||
ActorDamageCause_Suicide = 0x0D,
|
||||
ActorDamageCause_Magic = 0x0E,
|
||||
ActorDamageCause_Wither = 0x0F,
|
||||
ActorDamageCause_Starve = 0x10,
|
||||
ActorDamageCause_Anvil = 0x11,
|
||||
ActorDamageCause_Thorns = 0x12,
|
||||
ActorDamageCause_FallingBlock = 0x13,
|
||||
ActorDamageCause_Piston = 0x14,
|
||||
ActorDamageCause_FlyIntoWall = 0x15,
|
||||
ActorDamageCause_Magma = 0x16,
|
||||
ActorDamageCause_Fireworks = 0x17,
|
||||
ActorDamageCause_Lightning = 0x18,
|
||||
ActorDamageCause_Charging = 0x19,
|
||||
ActorDamageCause_Temperature = 0x1A,
|
||||
ActorDamageCause_Freezing = 0x1B,
|
||||
ActorDamageCause_Stalactite = 0x1C,
|
||||
ActorDamageCause_Stalagmite = 0x1D,
|
||||
ActorDamageCause_All = 0x1F,
|
||||
};
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class ActorDamageSource {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
ActorDamageCause mCause;
|
||||
char filler[4];
|
||||
|
||||
public:
|
||||
LIAPI Actor* getEntity();
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_ACTORDAMAGESOURCE
|
||||
|
@ -18,7 +18,7 @@ std::string fullname; // 96
|
||||
HashedString canonicalHash; // 128
|
||||
|
||||
public:
|
||||
inline const std::string getCanonicalName(){
|
||||
inline std::string const& getCanonicalName() const{
|
||||
return this->canonicalHash.getString();
|
||||
}
|
||||
#undef AFTER_EXTRA
|
||||
|
@ -5,12 +5,111 @@
|
||||
#include "Packet.hpp"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
#include "CommandFlag.hpp"
|
||||
enum CommandPermissionLevel : char;
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class AvailableCommandsPacket : public Packet {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
public:
|
||||
struct EnumData
|
||||
{
|
||||
std::string name;
|
||||
std::vector<unsigned int> valueIndices;
|
||||
};//56
|
||||
struct ConstrainedValueData
|
||||
{
|
||||
int enumIndex;
|
||||
int enumNameIndex;
|
||||
std::vector<unsigned char> indices;
|
||||
};
|
||||
struct ParamData
|
||||
{
|
||||
std::string desc;
|
||||
unsigned int sym;
|
||||
};
|
||||
struct OverloadData
|
||||
{
|
||||
std::vector<ParamData> datas;
|
||||
};
|
||||
struct CommandData
|
||||
{
|
||||
std::string name; //0
|
||||
std::string description; //32
|
||||
CommandFlag flag; //64
|
||||
CommandPermissionLevel perm; //66
|
||||
std::vector<OverloadData> overloads; //72
|
||||
signed int aliasIndex; //96
|
||||
};//104
|
||||
struct SoftEnumData
|
||||
{
|
||||
std::string name;
|
||||
std::vector<std::string> values;
|
||||
};//56
|
||||
|
||||
std::vector<std::string> mAllEnums;//48
|
||||
std::vector<std::string> mAllSuffix;//72
|
||||
std::vector<EnumData> mEnumDatas;//96
|
||||
std::vector<CommandData> mCommandDatas;//120
|
||||
std::vector<SoftEnumData> mSoftEnums;//144
|
||||
std::vector<ConstrainedValueData> mConstrainedValueDatas; //168
|
||||
inline void test()
|
||||
{
|
||||
static_assert(sizeof(AvailableCommandsPacket) == 192);
|
||||
static_assert(sizeof(EnumData) == 56);
|
||||
static_assert(sizeof(CommandData) == 104);
|
||||
static_assert(offsetof(CommandData, perm) == 66);
|
||||
static_assert(offsetof(AvailableCommandsPacket, mAllEnums) == 48);
|
||||
static_assert(offsetof(AvailableCommandsPacket, mAllSuffix) == 72);
|
||||
static_assert(offsetof(AvailableCommandsPacket, mConstrainedValueDatas) == 168);
|
||||
}
|
||||
|
||||
public:
|
||||
inline std::vector<std::string> getEnumNames()
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
for (auto& data : mEnumDatas) {
|
||||
names.push_back(data.name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
inline std::vector<std::string> getSoftEnumNames()
|
||||
{
|
||||
std::vector<std::string> names;
|
||||
for (auto& data : mSoftEnums)
|
||||
{
|
||||
names.push_back(data.name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
inline std::vector<std::string> getEnumValues(std::string const& name)
|
||||
{
|
||||
std::vector<std::string> values;
|
||||
for (auto& data : mEnumDatas)
|
||||
{
|
||||
if (data.name == name)
|
||||
{
|
||||
for (auto& index : data.valueIndices) {
|
||||
values.push_back(mAllEnums.at(index));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
inline std::vector<std::string> getSoftEnumValues(std::string const& name)
|
||||
{
|
||||
for (auto& data : mSoftEnums)
|
||||
{
|
||||
if (data.name == name)
|
||||
return data.values;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_AVAILABLECOMMANDSPACKET
|
||||
|
@ -4,19 +4,79 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
#include "CommandRegistry.hpp"
|
||||
#include "CommandParameterData.hpp"
|
||||
#include "CommandFlag.hpp"
|
||||
class CommandRegistry;
|
||||
// class CommandRegistry::Symbol;
|
||||
enum CommandPermissionLevel : char {
|
||||
Any = 0,
|
||||
GameMasters = 1,
|
||||
Admin = 2,
|
||||
HostPlayer = 3,
|
||||
Console = 4,
|
||||
Internal = 5,
|
||||
};
|
||||
|
||||
enum class OriginType : char {
|
||||
Player = 0,
|
||||
Block = 1,
|
||||
MinecartBlock = 2,
|
||||
DevConsole = 3,
|
||||
Test = 4,
|
||||
AutomationPlayer = 5,
|
||||
ClientAutomation = 6,
|
||||
Server = 7,
|
||||
Actor = 8,
|
||||
Virtual = 9,
|
||||
GameArgument = 10,
|
||||
ActorServer = 11,
|
||||
Precompiled = 12,
|
||||
GameDirectorEntity = 13,
|
||||
Script = 14,
|
||||
ExecuteContext = 15,
|
||||
|
||||
DedicatedServer = 7, // Server
|
||||
};
|
||||
|
||||
class CommandOutput;
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class Command {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
|
||||
protected:
|
||||
int version; // 8
|
||||
CommandRegistry* registry; // 16
|
||||
CommandRegistry::Symbol symbol; // 24,
|
||||
CommandPermissionLevel permission; // 28
|
||||
CommandFlag flag; // 30
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
static bool checkHasTargets(CommandSelectorResults<T> const& a, CommandOutput& b) {
|
||||
bool (*sym)(CommandSelectorResults<T> const& a, CommandOutput& b);
|
||||
if constexpr (std::is_same<T, class Actor>()) {
|
||||
sym = (decltype(sym))dlsym("??$checkHasTargets@VActor@@@Command@@KA_NAEBV?$CommandSelectorResults@VActor@@@@AEAVCommandOutput@@@Z");
|
||||
} else {
|
||||
sym = (decltype(sym))dlsym("??$checkHasTargets@VPlayer@@@Command@@KA_NAEBV?$CommandSelectorResults@VPlayer@@@@AEAVCommandOutput@@@Z");
|
||||
}
|
||||
return sym(a, b);
|
||||
}
|
||||
std::string getCommandName() const{
|
||||
return this->registry->symbolToString(this->symbol);
|
||||
};
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMAND
|
||||
public:
|
||||
class Command& operator=(class Command const &) = delete;
|
||||
Command(class Command const &) = delete;
|
||||
Command() = delete;
|
||||
Command(){};
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
@ -4,12 +4,38 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
// Include Headers or Declare Types Here
|
||||
#include <string>
|
||||
#include "CommandOrigin.hpp"
|
||||
class CommandOrigin;
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandContext {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
|
||||
public:
|
||||
std::string command;
|
||||
std::unique_ptr<CommandOrigin> origin;
|
||||
int Version = 18;
|
||||
|
||||
std::string& getCmd() {
|
||||
return command;
|
||||
}
|
||||
class CommandOrigin& getOrigin() {
|
||||
return *origin;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[deprecated]]
|
||||
CommandContext(T&& x, CommandOrigin* o)
|
||||
: command(std::forward<T>(x))
|
||||
, origin(o){};
|
||||
template <typename T>
|
||||
CommandContext(T&& x, std::unique_ptr<CommandOrigin> ori)
|
||||
: command(std::forward<T>(x))
|
||||
, origin(std::move(ori)){};
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDCONTEXT
|
||||
|
32
LiteLoader/Header/MC/CommandFlag.hpp
Normal file
32
LiteLoader/Header/MC/CommandFlag.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
enum class CommandFlagValue : unsigned short
|
||||
{
|
||||
None = 0,
|
||||
Usage = 1,
|
||||
Visibility2 = 2,
|
||||
Visibility4 = 4,
|
||||
Visibility6 = 6,
|
||||
Sync = 8,
|
||||
Execute = 16,
|
||||
Type = 32,
|
||||
Cheat = 64,
|
||||
};
|
||||
struct CommandFlag
|
||||
{
|
||||
CommandFlagValue value;
|
||||
|
||||
constexpr bool operator==(CommandFlag const& rhs) const noexcept
|
||||
{
|
||||
return value == rhs.value;
|
||||
}
|
||||
constexpr bool operator!=(CommandFlag const& rhs) const noexcept
|
||||
{
|
||||
return value != rhs.value;
|
||||
}
|
||||
CommandFlag& operator|=(CommandFlag const& rhs)
|
||||
{
|
||||
value = (CommandFlagValue)((char)rhs.value | (char)value);
|
||||
return *this;
|
||||
}
|
||||
};
|
57
LiteLoader/Header/MC/CommandIntegerRange.hpp
Normal file
57
LiteLoader/Header/MC/CommandIntegerRange.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* @file CommandIntegerRange.hpp
|
||||
* @note This Header is auto generated by LiteLoaderBDS Toolchain.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../Global.h"
|
||||
|
||||
class CommandIntegerRange {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
public:
|
||||
int min, max;
|
||||
bool inverted;
|
||||
|
||||
CommandIntegerRange(){
|
||||
this->min = std::numeric_limits<int>::min();
|
||||
this->max = std::numeric_limits<int>::max();
|
||||
this->inverted = 0;
|
||||
}
|
||||
CommandIntegerRange(int minVal,int maxVal,bool invert){
|
||||
this->min = minVal;
|
||||
this->max = maxVal;
|
||||
this->inverted = invert;
|
||||
};
|
||||
bool isWithinRange(int value) const{
|
||||
bool temp = false;
|
||||
if(this->min <= value)
|
||||
temp = this->max >= value;
|
||||
return temp != this->inverted;
|
||||
};
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDINTEGERRANGE
|
||||
public:
|
||||
class CommandIntegerRange& operator=(class CommandIntegerRange const &) = delete;
|
||||
CommandIntegerRange(class CommandIntegerRange const &) = delete;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/**
|
||||
* @symbol ??0CommandIntegerRange@@QEAA@XZ
|
||||
* @hash -2077189482
|
||||
*/
|
||||
//MCAPI CommandIntegerRange();
|
||||
/**
|
||||
* @symbol ??0CommandIntegerRange@@QEAA@HH_N@Z
|
||||
* @hash -697074593
|
||||
*/
|
||||
//MCAPI CommandIntegerRange(int, int, bool);
|
||||
/**
|
||||
* @symbol ?isWithinRange@CommandIntegerRange@@QEBA_NH@Z
|
||||
* @hash 1413957599
|
||||
*/
|
||||
//MCAPI bool isWithinRange(int) const;
|
||||
|
||||
};
|
@ -10,13 +10,22 @@
|
||||
class CommandItem {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
int version; //0
|
||||
int itemId; //4
|
||||
|
||||
public:
|
||||
CommandItem(){
|
||||
this->version = 0;
|
||||
this->itemId = 0;
|
||||
}
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDITEM
|
||||
public:
|
||||
class CommandItem& operator=(class CommandItem const &) = delete;
|
||||
CommandItem(class CommandItem const &) = delete;
|
||||
CommandItem() = delete;
|
||||
//CommandItem() = delete;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
@ -10,13 +10,24 @@
|
||||
class CommandMessage {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
struct MessageComponent
|
||||
{
|
||||
char filler[200];
|
||||
void* unk[2];
|
||||
std::vector<void*> unk2[5];
|
||||
};
|
||||
std::vector<MessageComponent> components;
|
||||
|
||||
public:
|
||||
CommandMessage(){};
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDMESSAGE
|
||||
public:
|
||||
class CommandMessage& operator=(class CommandMessage const &) = delete;
|
||||
CommandMessage(class CommandMessage const &) = delete;
|
||||
CommandMessage() = delete;
|
||||
//CommandMessage() = delete;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
@ -3,14 +3,20 @@
|
||||
#define AUTO_GENERATED
|
||||
#include "../Global.h"
|
||||
#include "Json.hpp"
|
||||
#include "Bedrock.hpp"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
class ServerPlayer;
|
||||
class CommandArea;
|
||||
enum CommandOriginType : char;
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandOrigin {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
public:
|
||||
LIAPI ServerPlayer* getPlayer() const;
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDORIGIN
|
||||
|
@ -4,12 +4,128 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
#include "CommandOutputParameter.hpp"
|
||||
#include "CommandOrigin.hpp"
|
||||
#include "Command.hpp"
|
||||
#include "ServerPlayer.hpp"
|
||||
#include "../Utils/PluginOwnData.h"
|
||||
#include "../I18nAPI.h"
|
||||
|
||||
#define POD_COMMANDOUTPUT_LANGCODE ("_ll_plugin_cmdoutp_langcode_" + std::to_string((uint64_t)this))
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandOutput {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
public:
|
||||
|
||||
int getSuccessCount() const{
|
||||
//DayLockCommand::execute Line91
|
||||
return dAccess<int>(this,10);
|
||||
};
|
||||
|
||||
void success(){
|
||||
int successCount = dAccess<int>(this,10);
|
||||
++successCount;
|
||||
dAccess<int>(this,10) = successCount;
|
||||
};
|
||||
/**
|
||||
* @brief Output a message(without I18nBase).
|
||||
*
|
||||
* @param str The message
|
||||
*/
|
||||
LIAPI void addMessage(const std::string& str);
|
||||
/**
|
||||
* @brief Output a success message(without I18nBase).
|
||||
*
|
||||
* @param str The message
|
||||
*/
|
||||
LIAPI void success(const string& str);
|
||||
/**
|
||||
* @brief Output a success message(without I18nBase).
|
||||
*
|
||||
* @param str The message
|
||||
*/
|
||||
LIAPI void error(const string& str);
|
||||
|
||||
/**
|
||||
* @brief Set the output language code of this CommandOutput object.
|
||||
*
|
||||
* @param code The language code
|
||||
*/
|
||||
inline void setLanguageCode(const std::string& code = "") {
|
||||
PluginOwnData::set<std::string>(POD_COMMANDOUTPUT_LANGCODE, code);
|
||||
}
|
||||
/**
|
||||
* @brief Set the output language code of this CommandOutput object(convenience func).
|
||||
*
|
||||
* @param ori The command origin object for the CommandOutput object
|
||||
*/
|
||||
inline void setLanguageCode(const CommandOrigin& ori) {
|
||||
std::string code = "en_US";
|
||||
if (PluginOwnData::has(I18nBase::POD_KEY)) {
|
||||
auto& i18n = PluginOwnData::get<I18nBase>(I18nBase::POD_KEY);
|
||||
switch ((OriginType)ori.getOriginType()) {
|
||||
case OriginType::Player:
|
||||
code = ori.getPlayer()->getLanguageCode();
|
||||
break;
|
||||
default:
|
||||
code = i18n.getDefaultLocaleName();
|
||||
break;
|
||||
}
|
||||
}
|
||||
PluginOwnData::set<std::string>(POD_COMMANDOUTPUT_LANGCODE, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Output a message(I18nBase, convenience func).
|
||||
*
|
||||
* @tparam Args ...
|
||||
* @param format The str to translate and format
|
||||
* @param args The format arguments
|
||||
* @see tr
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void trAddMessage(const std::string& format, Args&&... args) {
|
||||
if (PluginOwnData::has(POD_COMMANDOUTPUT_LANGCODE))
|
||||
this->addMessage(trl(PluginOwnData::get<std::string>(POD_COMMANDOUTPUT_LANGCODE), format, std::forward<Args>(args)...));
|
||||
else
|
||||
this->addMessage(tr(format, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Output a success message(I18nBase, convenience func).
|
||||
*
|
||||
* @tparam Args ...
|
||||
* @param format The str to translate and format
|
||||
* @param args The format arguments
|
||||
* @see tr
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void trSuccess(const std::string& format, Args&&... args) {
|
||||
if (PluginOwnData::has(POD_COMMANDOUTPUT_LANGCODE))
|
||||
this->success(trl(PluginOwnData::get<std::string>(POD_COMMANDOUTPUT_LANGCODE), format, std::forward<Args>(args)...));
|
||||
else
|
||||
this->success(tr(format, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Output a error message(I18nBase, convenience func).
|
||||
*
|
||||
* @tparam Args ...
|
||||
* @param format The str to translate and format
|
||||
* @param args The format arguments
|
||||
* @see tr
|
||||
*/
|
||||
template <typename... Args>
|
||||
inline void trError(const std::string& format, Args&&... args) {
|
||||
if (PluginOwnData::has(POD_COMMANDOUTPUT_LANGCODE))
|
||||
this->error(trl(PluginOwnData::get<std::string>(POD_COMMANDOUTPUT_LANGCODE), format, std::forward<Args>(args)...));
|
||||
else
|
||||
this->error(tr(format, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDOUTPUT
|
||||
|
@ -10,12 +10,20 @@
|
||||
class CommandOutputParameter {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
enum NoCountType;
|
||||
std::string str;
|
||||
int type;
|
||||
|
||||
public:
|
||||
CommandOutputParameter(class CommandOutputParameter const & output){
|
||||
this->str = output.str;
|
||||
this->type = output.type;
|
||||
};
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDOUTPUTPARAMETER
|
||||
public:
|
||||
class CommandOutputParameter& operator=(class CommandOutputParameter const &) = delete;
|
||||
CommandOutputParameter(class CommandOutputParameter const &) = delete;
|
||||
// CommandOutputParameter(class CommandOutputParameter const &) = delete;
|
||||
CommandOutputParameter() = delete;
|
||||
#endif
|
||||
|
||||
|
@ -4,13 +4,77 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
#include <string_view>
|
||||
#include "CommandRegistry.hpp"
|
||||
|
||||
enum class CommandParameterDataType {
|
||||
NORMAL,
|
||||
ENUM,
|
||||
SOFT_ENUM,
|
||||
POSIFIX,
|
||||
};
|
||||
enum SemanticConstraint: unsigned char
|
||||
{
|
||||
NoneConstraint = 0,
|
||||
RequiresCheatsEnabled=1,
|
||||
RequiresElevatedPermissions=2,
|
||||
RequiresHostPermissions=4,
|
||||
VALUE_MASK=8,
|
||||
};
|
||||
enum CommandParameterOption : unsigned char
|
||||
{
|
||||
None = 0,
|
||||
EnumAutocompleteExpansion = 1,
|
||||
HasSemanticConstraint = 2, //be used in block or item name enum
|
||||
EnumAsChainedCommand = 4, //be used in NewExecuteCommand
|
||||
};
|
||||
class CommandRegistry;
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandParameterData {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
#define DISABLE_CONSTRUCTOR_PREVENTION_COMMANDPARAMETERDATA
|
||||
using ParseFn = bool (CommandRegistry::*)(
|
||||
void*, CommandRegistry::ParseToken const&, CommandOrigin const&, int, std::string&,
|
||||
std::vector<std::string>&) const;
|
||||
|
||||
public:
|
||||
typeid_t<CommandRegistry> tid; // 0
|
||||
ParseFn parser; // 8
|
||||
std::string name; // 16
|
||||
char const* desc; // 48
|
||||
int unk56; // 56
|
||||
CommandParameterDataType type; // 60
|
||||
int offset; // 64
|
||||
int flag_offset; // 68
|
||||
bool mand; // 72
|
||||
unsigned char options; // 73
|
||||
|
||||
CommandParameterData()
|
||||
: tid(tid){};
|
||||
|
||||
CommandParameterData(
|
||||
typeid_t<CommandRegistry> tid, ParseFn parser, std::string_view describe,
|
||||
CommandParameterDataType type, char const* enumName, int offset, bool optional, int flag_offset)
|
||||
: tid(tid)
|
||||
, parser(parser)
|
||||
, name(describe)
|
||||
, desc(enumName)
|
||||
, unk56(-1)
|
||||
, type(type)
|
||||
, offset(offset)
|
||||
, flag_offset(flag_offset)
|
||||
, mand(optional)
|
||||
, options(0){};
|
||||
|
||||
CommandParameterData & addOptions(enum CommandParameterOption options){
|
||||
this->options = this->options | options;
|
||||
return *this;
|
||||
};
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDPARAMETERDATA
|
||||
public:
|
||||
|
@ -4,13 +4,52 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
#include "CompoundTag.hpp"
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandPosition {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
#define DISABLE_CONSTRUCTOR_PREVENTION_COMMANDPOSITION
|
||||
float offsetX;
|
||||
float offsetY;
|
||||
float offsetZ;
|
||||
bool relativeX;
|
||||
bool relativeY;
|
||||
bool relativeZ;
|
||||
bool local;
|
||||
|
||||
public:
|
||||
CommandPosition(){
|
||||
this->offsetX = 0;
|
||||
this->offsetY = 0;
|
||||
this->offsetZ = 0;
|
||||
this->relativeX = 1;
|
||||
this->relativeY = 1;
|
||||
this->relativeZ = 1;
|
||||
this->local = 0;
|
||||
}
|
||||
CommandPosition(Vec3 *pos){
|
||||
this->offsetX = pos->x;
|
||||
this->offsetY = pos->y;
|
||||
this->offsetZ = pos->z;
|
||||
this->relativeX = pos->x + 2;
|
||||
this->relativeY = pos->y + 2;
|
||||
this->relativeZ = pos->z + 2;
|
||||
this->local = 0;
|
||||
}
|
||||
CompoundTag serialize() const{
|
||||
CompoundTag tag;
|
||||
tag.putFloat("OffsetX",0);
|
||||
tag.putFloat("OffsetY",0);
|
||||
tag.putFloat("OffsetZ",0);
|
||||
tag.putBoolean("RelativeX",this->relativeX);
|
||||
tag.putBoolean("RelativeY",this->relativeY);
|
||||
tag.putBoolean("RelativeZ",this->relativeZ);
|
||||
tag.putBoolean("Local",this->local);
|
||||
return tag;
|
||||
};
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDPOSITION
|
||||
public:
|
||||
|
6
LiteLoader/Header/MC/CommandPositionFloat.hpp
Normal file
6
LiteLoader/Header/MC/CommandPositionFloat.hpp
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "CommandPosition.hpp"
|
||||
|
||||
class CommandPositionFloat : public CommandPosition
|
||||
{
|
||||
};
|
32
LiteLoader/Header/MC/CommandRawText.hpp
Normal file
32
LiteLoader/Header/MC/CommandRawText.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* @file CommandRawText.hpp
|
||||
* @note This Header is auto generated by LiteLoaderBDS Toolchain.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#include "../Global.h"
|
||||
|
||||
class CommandRawText {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
std::string text;
|
||||
|
||||
public:
|
||||
inline operator std::string()const
|
||||
{
|
||||
return text;
|
||||
}
|
||||
|
||||
std::string const & getText() const{
|
||||
return this->text;
|
||||
}
|
||||
#define DISABLE_CONSTRUCTOR_PREVENTION_COMMANDRAWTEXT
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDRAWTEXT
|
||||
public:
|
||||
class CommandRawText& operator=(class CommandRawText const &) = delete;
|
||||
CommandRawText(class CommandRawText const &) = delete;
|
||||
CommandRawText() = delete;
|
||||
#endif
|
||||
};
|
@ -4,12 +4,112 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
enum CommandPermissionLevel : char;
|
||||
enum class CommandFlagValue : unsigned short;
|
||||
enum SemanticConstraint : unsigned char;
|
||||
class CommandParameterData;
|
||||
#include "CommandFlag.hpp"
|
||||
#include <memory>
|
||||
//#include "typeid_t.hpp"
|
||||
//#include "Command.hpp"
|
||||
#include "CommandPosition.hpp"
|
||||
#include "CommandPositionFloat.hpp"
|
||||
#include "CommandMessage.hpp"
|
||||
#include "CommandSelector.hpp"
|
||||
#include "CommandOrigin.hpp"
|
||||
#include "CommandVersion.hpp"
|
||||
#include "CommandRawText.hpp"
|
||||
#include "CommandItem.hpp"
|
||||
#include "CommandIntegerRange.hpp"
|
||||
#include "ActorDamageSource.hpp"
|
||||
#include "ActorDefinitionIdentifier.hpp"
|
||||
|
||||
#pragma region typeid
|
||||
|
||||
template <typename T>
|
||||
class typeid_t {
|
||||
public:
|
||||
typeid_t& operator=(typeid_t const&) = delete;
|
||||
typeid_t(typeid_t const&) = delete;
|
||||
inline static unsigned short count = 0;
|
||||
unsigned short value;
|
||||
typeid_t<T>(typeid_t<T> const& id)
|
||||
: value(id.value){};
|
||||
typeid_t<T>(unsigned short value)
|
||||
: value(value){};
|
||||
};
|
||||
template <>
|
||||
class typeid_t<CommandRegistry> {
|
||||
public:
|
||||
MCAPI static unsigned short count;
|
||||
unsigned short value;
|
||||
typeid_t<CommandRegistry>(typeid_t<CommandRegistry> const& id)
|
||||
: value(id.value){};
|
||||
typeid_t<CommandRegistry>(unsigned short value)
|
||||
: value(value){};
|
||||
};
|
||||
template <typename T, typename T2>
|
||||
typeid_t<T> type_id() {
|
||||
static typeid_t<T> id = typeid_t<T>::count++;
|
||||
return id;
|
||||
}
|
||||
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDamageCause>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, AutomaticID<class Dimension, int>>();
|
||||
// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class Block const*>();
|
||||
// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, bool>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandMessage>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, enum CommandOperator>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandPosition>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandPositionFloat>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandPositionFloat>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandSelector<class Actor>>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandSelector<class Player>>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, enum EquipmentSlot>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, float>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, int>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, Json::Value>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, enum Mirror>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class MobEffect const*>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class RelativeFloat>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, std::string>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, std::unique_ptr<class Command>>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class WildcardCommandSelector<Actor>>();
|
||||
// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, CommandItem>();
|
||||
template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, CommandIntegerRange>();
|
||||
// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDefinitionIdentifier const*>();
|
||||
|
||||
template <>
|
||||
inline typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDefinitionIdentifier const*>() {
|
||||
static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real("?id@?1???$type_id@VCommandRegistry@@PEBUActorDefinitionIdentifier@@@@YA?AV?$typeid_t@VCommandRegistry@@@@XZ@4V1@A");
|
||||
// static typeid_t<CommandRegistry> id = ([]() -> typeid_t<CommandRegistry> {
|
||||
// CommandParameterData data = SymCall("??$mandatory@VRideCommand@@PEBUActorDefinitionIdentifier@@@commands@@YA?AVCommandParameterData@@PEQRideCommand@@PEBUActorDefinitionIdentifier@@PEBDPEQ2@_N@Z",
|
||||
// CommandParameterData, void*, char const*, uintptr_t)(nullptr, "entityType", 0);
|
||||
// return data.tid;
|
||||
// })();
|
||||
return id;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline typeid_t<CommandRegistry> type_id<CommandRegistry, CommandItem>() {
|
||||
static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real("?id@?1???$type_id@VCommandRegistry@@VCommandItem@@@@YA?AV?$typeid_t@VCommandRegistry@@@@XZ@4V1@A");
|
||||
return id;
|
||||
};
|
||||
|
||||
template <>
|
||||
inline typeid_t<CommandRegistry> type_id<CommandRegistry, bool>() {
|
||||
static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real("?id@?1???$type_id@VCommandRegistry@@_N@@YA?AV?$typeid_t@VCommandRegistry@@@@XZ@4V1@A");
|
||||
return id;
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
inline typeid_t<CommandRegistry> type_id<CommandRegistry, class Block const*>() {
|
||||
static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real("?id@?1???$type_id@VCommandRegistry@@PEBVBlock@@@@YA?AV?$typeid_t@VCommandRegistry@@@@XZ@4V1@A");
|
||||
return id;
|
||||
};
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandRegistry {
|
||||
@ -18,27 +118,513 @@ class CommandRegistry {
|
||||
public:
|
||||
struct ParseTable;
|
||||
class Symbol {
|
||||
Symbol& operator=(Symbol const&) = delete;
|
||||
Symbol(Symbol const&) = delete;
|
||||
public:
|
||||
unsigned val;
|
||||
MCAPI Symbol(unsigned __int64 = -1);
|
||||
MCAPI Symbol(class Symbol const&);
|
||||
MCAPI unsigned __int64 toIndex() const;
|
||||
MCAPI int value() const;
|
||||
inline bool operator==(Symbol const& right) const {
|
||||
return val == right.val;
|
||||
}
|
||||
inline std::string toString() const {
|
||||
return Global<CommandRegistry>->symbolToString(*this);
|
||||
}
|
||||
inline std::string toDebugString() const {
|
||||
return fmt::format("<Symbol {}({})>", toString(), val);
|
||||
}
|
||||
};
|
||||
|
||||
struct ParseToken {
|
||||
ParseToken() = delete;
|
||||
ParseToken(ParseToken const&) = delete;
|
||||
ParseToken(ParseToken const&&) = delete;
|
||||
std::unique_ptr<CommandRegistry::ParseToken> child;
|
||||
std::unique_ptr<CommandRegistry::ParseToken> next;
|
||||
CommandRegistry::ParseToken* parent;
|
||||
const char* text; // 24
|
||||
uint32_t length; // 32
|
||||
Symbol type; // 36
|
||||
MCAPI std::string toString() const;
|
||||
//{
|
||||
// if (text)
|
||||
// return std::string(text, length);
|
||||
// auto v6 = child.get();
|
||||
// auto v8 = child.get();
|
||||
// while (v8->child)
|
||||
// {
|
||||
// v8 = v8->child.get();
|
||||
// }
|
||||
// while (v6->child || v6->next)
|
||||
// {
|
||||
// v6 = v6->next ? v6->next.get() : v6->child.get();
|
||||
// }
|
||||
// auto v10 = v6->text + v6->length;
|
||||
// auto v11 = v8->text;
|
||||
// return std::string(v11, v10 - v11);
|
||||
//};
|
||||
inline std::string toDebugString() const {
|
||||
return fmt::format("<ParseToken {}>", toString());
|
||||
}
|
||||
};
|
||||
static_assert(sizeof(ParseToken) == 40);
|
||||
using ParseFn = bool (CommandRegistry::*)(
|
||||
void*, ParseToken const&, CommandOrigin const&, int, std::string&,
|
||||
std::vector<std::string>&) const;
|
||||
|
||||
struct Overload {
|
||||
Overload() = delete;
|
||||
Overload(Overload const&) = delete;
|
||||
Overload(Overload const&&) = delete;
|
||||
using FactoryFn = std::unique_ptr<class Command> (*)();
|
||||
|
||||
CommandVersion version; // 0
|
||||
FactoryFn factory; // 8
|
||||
std::vector<CommandParameterData> params; // 16
|
||||
unsigned char unk; // 40
|
||||
std::vector<Symbol> syms = {}; // 48
|
||||
|
||||
LIAPI Overload(CommandVersion version,
|
||||
FactoryFn factory,
|
||||
std::vector<CommandParameterData>&& args);
|
||||
|
||||
LIAPI ~Overload();
|
||||
|
||||
inline std::string toDebugString() {
|
||||
return fmt::format("<Overload>");
|
||||
}
|
||||
};
|
||||
|
||||
struct Signature {
|
||||
Signature() = delete;
|
||||
Signature(Signature const&) = delete;
|
||||
Signature(Signature const&&) = delete;
|
||||
std::string name; // 0
|
||||
std::string desc; // 32
|
||||
std::vector<Overload> overloads; // 64
|
||||
CommandPermissionLevel perm; // 88
|
||||
Symbol main_symbol; // 92
|
||||
Symbol alt_symbol; // 96
|
||||
CommandFlag flag; // 100
|
||||
int unk72;
|
||||
int unk76;
|
||||
int unk80;
|
||||
bool b84;
|
||||
|
||||
inline Signature(std::string_view name,
|
||||
std::string_view desc,
|
||||
CommandPermissionLevel perm,
|
||||
Symbol symbol,
|
||||
CommandFlag flag)
|
||||
: name(name), desc(desc), perm(perm), main_symbol(symbol), flag(flag) {
|
||||
}
|
||||
|
||||
inline std::string toDebugString() const {
|
||||
return fmt::format("<Signature {}>", name);
|
||||
}
|
||||
};
|
||||
|
||||
struct SoftEnum {
|
||||
std::string name; // 0
|
||||
std::vector<std::string> list; // 32
|
||||
};
|
||||
|
||||
struct Enum {
|
||||
std::string name; // 0
|
||||
typeid_t<CommandRegistry> type; // 32
|
||||
ParseFn parse; // 40
|
||||
std::vector<std::tuple<unsigned long, unsigned long, unsigned long, unsigned long>> values; // 48
|
||||
|
||||
inline std::string toDebugString() const {
|
||||
return fmt::format("<Enum {}>", name);
|
||||
}
|
||||
};
|
||||
|
||||
LIAPI static std::vector<std::string> getEnumNames();
|
||||
LIAPI static std::vector<std::string> getSoftEnumNames();
|
||||
LIAPI static std::vector<std::string> getEnumValues(std::string const& name);
|
||||
LIAPI static std::vector<std::string> getSoftEnumValues(std::string const& name);
|
||||
LIAPI static std::string getCommandFullName(std::string const& name);
|
||||
// Experiment
|
||||
LIAPI bool unregisterCommand(std::string const& name);
|
||||
|
||||
template <typename Type>
|
||||
struct DefaultIdConverter {
|
||||
template <typename Target, typename Source>
|
||||
static Target convert(Source source) {
|
||||
return (Target)source;
|
||||
}
|
||||
uint64_t operator()(Type value) const {
|
||||
return convert<uint64_t, Type>(value);
|
||||
}
|
||||
Type operator()(uint64_t value) const {
|
||||
return convert<Type, uint64_t>(value);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef COMMAND_REGISTRY_EXTRA
|
||||
inline static std::string toString(std::vector<Symbol> const& syms) {
|
||||
std::ostringstream oss;
|
||||
bool first = true;
|
||||
for (auto& sym : syms) {
|
||||
if (!first)
|
||||
oss << ", ";
|
||||
oss << sym.toString();
|
||||
first = false;
|
||||
}
|
||||
return oss.str();
|
||||
}
|
||||
struct ParseRule {
|
||||
Symbol sym;
|
||||
std::function<ParseToken*(ParseToken&, Symbol)> func;
|
||||
std::vector<Symbol> syms;
|
||||
CommandVersion version;
|
||||
inline std::string toDebugString() const {
|
||||
|
||||
return fmt::format("<ParseRule {} - [{}]>", sym.toDebugString(), toString(syms));
|
||||
}
|
||||
};
|
||||
struct ParseTable {
|
||||
std::map<Symbol, std::vector<Symbol>> first;
|
||||
std::map<Symbol, std::vector<Symbol>> follow;
|
||||
std::map<std::pair<Symbol, Symbol>, int> predict;
|
||||
inline std::string toDebugString() const {
|
||||
std::ostringstream oss;
|
||||
bool f = true;
|
||||
for (auto& [k, v] : first) {
|
||||
if (!f)
|
||||
oss << ", ";
|
||||
oss << k.toString() << ":[" << toString(v) << "]";
|
||||
f = false;
|
||||
}
|
||||
oss << "\n";
|
||||
for (auto& [k, v] : follow) {
|
||||
if (!f)
|
||||
oss << ", ";
|
||||
oss << k.toString() << ":[" << toString(v) << "]";
|
||||
f = false;
|
||||
}
|
||||
return fmt::format("<ParseTable>[{}]", oss.str());
|
||||
}
|
||||
};
|
||||
struct OptionalParameterChain {
|
||||
int parameterCount;
|
||||
int followingRuleIndex;
|
||||
Symbol paramSymbol;
|
||||
inline std::string toDebugString() const {
|
||||
return fmt::format("<OptionalParameterChain {},{},{}>", parameterCount, followingRuleIndex, paramSymbol.toDebugString());
|
||||
}
|
||||
};
|
||||
struct Factorization {
|
||||
Symbol sym;
|
||||
inline std::string toDebugString() const {
|
||||
return fmt::format("<Factorization {}>", sym.toDebugString());
|
||||
}
|
||||
};
|
||||
struct RegistryState {
|
||||
int signatureCount;
|
||||
int enumValueCount;
|
||||
int postfixCount;
|
||||
int enumCount;
|
||||
int factorizationCount;
|
||||
int optionalCount;
|
||||
int ruleCount;
|
||||
int softEnumCount;
|
||||
int constraintCount;
|
||||
std::vector<unsigned int> constrainedValueCount;
|
||||
std::vector<unsigned int> softEnumValuesCount;
|
||||
};
|
||||
struct ConstrainedValue {
|
||||
Symbol mValue;
|
||||
Symbol mEnum;
|
||||
std::vector<unsigned char> mConstraints;
|
||||
inline std::string toDebugString() const {
|
||||
std::ostringstream oss;
|
||||
bool first = true;
|
||||
for (auto& i : mConstraints) {
|
||||
if (!first)
|
||||
oss << ", ";
|
||||
oss << (int)i;
|
||||
first = false;
|
||||
}
|
||||
return fmt::format("<ConstrainedValue {} - {} - [{}]>", mValue.toDebugString(), mEnum.toDebugString(), oss.str());
|
||||
}
|
||||
};
|
||||
|
||||
using CommandOverrideFunctor = std::function<void __cdecl(struct CommandFlag&, class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const&)>;
|
||||
using ParamSymbols = std::array<Symbol, 21>;
|
||||
|
||||
std::function<void(const class Packet&)> mGetScoreForObjective; // 0
|
||||
std::function<void(const class Packet&)> mNetworkUpdateCallback; // 64
|
||||
std::vector<ParseRule> mRules; // 128
|
||||
// map<command version, ParseTable>
|
||||
std::map<unsigned int, ParseTable> mParseTableMap; // 152
|
||||
std::vector<OptionalParameterChain> mOptionals; // 168
|
||||
std::vector<std::string> mEnumValues; // 192
|
||||
std::vector<Enum> mEnums; // 216
|
||||
std::vector<Factorization> mFactorizations; // 240
|
||||
std::vector<std::string> mPostfixes; // 264
|
||||
std::map<std::string, unsigned int> mEnumLookup; // 288
|
||||
std::map<std::string, unsigned long> mEnumValueLookup; // 304
|
||||
std::vector<Symbol> mCommandSymbols; // 320
|
||||
std::map<std::string, Signature> mSignatures; // 344
|
||||
std::map<typeid_t<CommandRegistry>, int> mTypeLookup; // 360
|
||||
std::map<char, char> unk376; // 376
|
||||
std::map<std::string, std::string> mAliases; // 392
|
||||
std::vector<SemanticConstraint> mSemanticConstraints; // 408
|
||||
std::map<SemanticConstraint, unsigned char> mSemanticConstraintLookup; // 432
|
||||
std::vector<ConstrainedValue> mConstrainedValues; // 448
|
||||
std::map<std::pair<unsigned long, unsigned int>, unsigned int> mConstrainedValueLookup; // 472
|
||||
std::vector<SoftEnum> mSoftEnums; // 488
|
||||
std::map<std::string, unsigned int> mSoftEnumLookup; // 512
|
||||
std::vector<RegistryState> mStateStack; // 528
|
||||
ParamSymbols mArgs; // 552
|
||||
CommandOverrideFunctor mCommandOverrideFunctor; // 640
|
||||
// 704
|
||||
|
||||
inline void printAll() const;
|
||||
inline void printSize() const;
|
||||
|
||||
void test() {
|
||||
auto mParseTableMapCopy = mParseTableMap;
|
||||
auto mEnumLookupCopy = mEnumLookup;
|
||||
auto mEnumValueLookupCopy = mEnumValueLookup;
|
||||
auto mSignaturesCopy = mSignatures;
|
||||
auto mTypeLookupCopy = mTypeLookup;
|
||||
auto unk376Copy = unk376;
|
||||
auto mAliasesCopy = mAliases;
|
||||
auto mSemanticConstraintLookupCopy = mSemanticConstraintLookup;
|
||||
auto mConstrainedValueLookupCopy = mConstrainedValueLookup;
|
||||
auto mSoftEnumLookupCopy = mSoftEnumLookup;
|
||||
|
||||
constexpr auto size = sizeof(CommandRegistry);
|
||||
|
||||
static_assert(sizeof(Enum) == 72);
|
||||
static_assert(sizeof(ParseTable) == 48);
|
||||
static_assert(sizeof(ParseRule) == 104);
|
||||
static_assert(sizeof(CommandRegistry) == 0x2c0);
|
||||
static_assert(offsetof(CommandRegistry, mGetScoreForObjective) == 0);
|
||||
static_assert(offsetof(CommandRegistry, mNetworkUpdateCallback) == 64);
|
||||
static_assert(offsetof(CommandRegistry, mRules) == 128);
|
||||
static_assert(offsetof(CommandRegistry, mParseTableMap) == 152);
|
||||
static_assert(offsetof(CommandRegistry, mOptionals) == 168);
|
||||
static_assert(offsetof(CommandRegistry, mEnumValues) == 192);
|
||||
static_assert(offsetof(CommandRegistry, mEnums) == 216);
|
||||
static_assert(offsetof(CommandRegistry, mFactorizations) == 240);
|
||||
static_assert(offsetof(CommandRegistry, mPostfixes) == 264);
|
||||
static_assert(offsetof(CommandRegistry, mEnumLookup) == 288);
|
||||
static_assert(offsetof(CommandRegistry, mEnumValueLookup) == 304);
|
||||
static_assert(offsetof(CommandRegistry, mCommandSymbols) == 320);
|
||||
static_assert(offsetof(CommandRegistry, mSignatures) == 344);
|
||||
static_assert(offsetof(CommandRegistry, mTypeLookup) == 360);
|
||||
static_assert(offsetof(CommandRegistry, unk376) == 376);
|
||||
static_assert(offsetof(CommandRegistry, mAliases) == 392);
|
||||
static_assert(offsetof(CommandRegistry, mSemanticConstraints) == 408);
|
||||
static_assert(offsetof(CommandRegistry, mSemanticConstraintLookup) == 432);
|
||||
static_assert(offsetof(CommandRegistry, mConstrainedValues) == 448);
|
||||
static_assert(offsetof(CommandRegistry, mConstrainedValueLookup) == 472);
|
||||
static_assert(offsetof(CommandRegistry, mSoftEnums) == 488);
|
||||
static_assert(offsetof(CommandRegistry, mSoftEnumLookup) == 512);
|
||||
static_assert(offsetof(CommandRegistry, mStateStack) == 528);
|
||||
static_assert(offsetof(CommandRegistry, mArgs) == 552);
|
||||
static_assert(offsetof(CommandRegistry, mCommandOverrideFunctor) == 640);
|
||||
}
|
||||
#endif COMMAND_REGISTRY_EXTRA
|
||||
|
||||
template <typename T>
|
||||
inline static std::unique_ptr<class Command> allocateCommand() {
|
||||
return std::make_unique<T>();
|
||||
}
|
||||
inline void registerOverload(
|
||||
std::string const& name, Overload::FactoryFn factory, std::vector<CommandParameterData>&& args) {
|
||||
Signature* signature = const_cast<Signature*>(findCommand(name));
|
||||
auto& overload = signature->overloads.emplace_back(CommandVersion{}, factory, std::move(args));
|
||||
registerOverloadInternal(*signature, overload);
|
||||
}
|
||||
template <typename T, typename... Params>
|
||||
inline void registerOverload(std::string const& name, Params... params) {
|
||||
registerOverload(name, &allocateCommand<T>, {params...});
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
bool
|
||||
fakeParse(void*, ParseToken const&, CommandOrigin const&, int, std::string&, std::vector<std::string>&) const {
|
||||
return false;
|
||||
}
|
||||
inline static std::unordered_map<string, void*> parse_ptr = {
|
||||
{typeid(CommandMessage).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VCommandMessage@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@"
|
||||
"@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_"
|
||||
"string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$"
|
||||
"char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(std::string).name(),
|
||||
dlsym_real("??$parse@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@"
|
||||
"CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_"
|
||||
"string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$"
|
||||
"char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(bool).name(),
|
||||
dlsym_real("??$parse@_N@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$"
|
||||
"basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_"
|
||||
"traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(float).name(),
|
||||
dlsym_real("??$parse@M@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$"
|
||||
"basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_"
|
||||
"string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(int).name(),
|
||||
dlsym_real("??$parse@H@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$"
|
||||
"basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_"
|
||||
"string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(CommandSelector<Actor>).name(),
|
||||
dlsym_real(
|
||||
"??$parse@V?$CommandSelector@VActor@@@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@"
|
||||
"AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@"
|
||||
"AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@"
|
||||
"V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(CommandSelector<Player>).name(),
|
||||
dlsym_real(
|
||||
"??$parse@V?$CommandSelector@VPlayer@@@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@"
|
||||
"AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@"
|
||||
"AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@"
|
||||
"V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(CommandPosition).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VCommandPosition@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@"
|
||||
"HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@"
|
||||
"std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(CommandPositionFloat).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VCommandPositionFloat@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@"
|
||||
"HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@"
|
||||
"V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(Json::Value).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VValue@Json@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@"
|
||||
"HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@"
|
||||
"DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@"
|
||||
"V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(std::unique_ptr<class Command>).name(),
|
||||
dlsym_real(
|
||||
"??$parse@V?$unique_ptr@VCommand@@U?$default_delete@VCommand@@@std@@@std@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(RelativeFloat).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VRelativeFloat@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(CommandRawText).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VCommandRawText@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(class Block const*).name(),
|
||||
dlsym_real(
|
||||
"??$parse@PEBVBlock@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(class MobEffect const*).name(),
|
||||
dlsym_real(
|
||||
"??$parse@PEBVMobEffect@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(CommandItem).name(),
|
||||
dlsym_real(
|
||||
"??$parse@VCommandItem@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(WildcardCommandSelector<Actor>).name(),
|
||||
dlsym_real(
|
||||
"??$parse@V?$WildcardCommandSelector@VActor@@@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
{typeid(ActorDefinitionIdentifier const*).name(),
|
||||
dlsym_real(
|
||||
"??$parse@PEBUActorDefinitionIdentifier@@@CommandRegistry@@AEBA_NPEAXAEBUParseToken@0@AEBVCommandOrigin@@HAEAV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@4@@Z")},
|
||||
};
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
bool parse(void*, ParseToken const&, CommandOrigin const&, int, std::string&, std::vector<std::string>&) const {
|
||||
|
||||
};
|
||||
|
||||
public:
|
||||
template <typename T>
|
||||
inline static ParseFn getParseFn() {
|
||||
if constexpr (!std::is_same_v<enum CommandOperator, T> && std::is_enum_v<T>)
|
||||
return &fakeParse<T>;
|
||||
// else
|
||||
// return &parse<T>;
|
||||
bool (CommandRegistry::*ptr)(void*, CommandRegistry::ParseToken const&,
|
||||
CommandOrigin const&, int, std::string&,
|
||||
std::vector<std::string>&) const;
|
||||
*(void**)&ptr = parse_ptr[typeid(T).name()];
|
||||
if (!ptr) {
|
||||
printf("Cant parse cmd data %s\n", typeid(T).name());
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
exit(1);
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
bool parseEnumInt(void* target,
|
||||
CommandRegistry::ParseToken const& token,
|
||||
CommandOrigin const&,
|
||||
int,
|
||||
std::string&,
|
||||
std::vector<std::string>&) const {
|
||||
auto data = getEnumData(token);
|
||||
*(int*)target = (int)data;
|
||||
return true;
|
||||
}
|
||||
bool parseEnumString(void* target,
|
||||
CommandRegistry::ParseToken const& token,
|
||||
CommandOrigin const&,
|
||||
int,
|
||||
std::string&,
|
||||
std::vector<std::string>&) const {
|
||||
auto data = token.toString();
|
||||
*(std::string*)target = data;
|
||||
return true;
|
||||
}
|
||||
bool parseEnumStringAndInt(void* target,
|
||||
CommandRegistry::ParseToken const& token,
|
||||
CommandOrigin const&,
|
||||
int,
|
||||
std::string&,
|
||||
std::vector<std::string>&) const {
|
||||
auto str = token.toString();
|
||||
auto data = getEnumData(token);
|
||||
*(std::pair<std::string, int>*)target = {str, (int)data};
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Type, typename IDConverter = CommandRegistry::DefaultIdConverter<Type>>
|
||||
bool parseEnum(
|
||||
void* target, CommandRegistry::ParseToken const& token, CommandOrigin const&, int, std::string&,
|
||||
std::vector<std::string>&) const {
|
||||
// fmt::print(token.toString() + '\n');
|
||||
auto data = getEnumData(token);
|
||||
*(Type*)target = IDConverter{}(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Type, typename IDConverter = CommandRegistry::DefaultIdConverter<Type>>
|
||||
unsigned addEnumValues(
|
||||
std::string const& name, typeid_t<CommandRegistry> tid,
|
||||
std::vector<std::pair<std::string, Type>> const& values) {
|
||||
std::vector<std::pair<std::string, uint64_t>> converted;
|
||||
IDConverter converter;
|
||||
for (auto& value : values)
|
||||
converted.emplace_back(value.first, converter(value.second));
|
||||
return addEnumValuesInternal(name, converted, tid, &CommandRegistry::parseEnum<Type, IDConverter>).val;
|
||||
}
|
||||
unsigned addEnumValues(std::string const& name,
|
||||
typeid_t<CommandRegistry> tid,
|
||||
std::initializer_list<std::string> const& values) {
|
||||
std::vector<std::pair<std::string, uint64_t>> converted;
|
||||
uint64_t idx = 0;
|
||||
for (auto& value : values)
|
||||
converted.emplace_back(value, ++idx);
|
||||
return addEnumValuesInternal(name, converted, tid, &CommandRegistry::parseEnumInt).val;
|
||||
}
|
||||
|
||||
// inline static typeid_t<CommandRegistry> getNextTypeId() {
|
||||
// return typeid_t<CommandRegistry>::count++;
|
||||
// }
|
||||
|
||||
template <typename T>
|
||||
CommandRegistry* addEnum(char const* name, std::vector<std::pair<std::string, T>> const& values) {
|
||||
this->addEnumValues<T>(name, type_id<CommandRegistry, T>(), values);
|
||||
return this;
|
||||
}
|
||||
|
||||
friend class DynamicCommand;
|
||||
friend class DynamicCommandInstance;
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDREGISTRY
|
||||
public:
|
||||
|
30
LiteLoader/Header/MC/CommandSelector.hpp
Normal file
30
LiteLoader/Header/MC/CommandSelector.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
#include "CommandSelectorBase.hpp"
|
||||
|
||||
// static_assert(offsetof(CommandSelectorBase, explicitIdSelector) == 165);
|
||||
template <typename T>
|
||||
class CommandSelector : public CommandSelectorBase {
|
||||
public:
|
||||
LIAPI CommandSelector() : CommandSelectorBase(std::is_same_v<T, Player>) {}
|
||||
|
||||
inline CommandSelectorResults<T> results(CommandOrigin const& a0) const
|
||||
{
|
||||
CommandSelectorResults<T> (CommandSelector<T>::*rv)(CommandOrigin const& a0) const;
|
||||
if constexpr (std::is_same_v<class Actor, T>) {
|
||||
*((void**)&rv) = dlsym("?results@?$CommandSelector@VActor@@@@QEBA?AV?$CommandSelectorResults@VActor@@@@AEBVCommandOrigin@@@Z");
|
||||
return (this->*rv)(a0);
|
||||
}
|
||||
else {
|
||||
*((void**)&rv) = dlsym("?results@?$CommandSelector@VPlayer@@@@QEBA?AV?$CommandSelectorResults@VPlayer@@@@AEBVCommandOrigin@@@Z");
|
||||
return (this->*rv)(a0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class WildcardCommandSelector : public CommandSelectorBase
|
||||
{
|
||||
public:
|
||||
WildcardCommandSelector()
|
||||
: CommandSelectorBase(std::is_same_v<T, Player>){};
|
||||
};
|
@ -4,13 +4,20 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
// Include Headers or Declare Types Here
|
||||
#include "UpdateSoftEnumPacket.hpp"
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class CommandSoftEnumRegistry {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
|
||||
// Add Member There
|
||||
class CommandRegistry* registry;
|
||||
public:
|
||||
CommandSoftEnumRegistry(class CommandRegistry *reg){
|
||||
this->registry = reg;
|
||||
};
|
||||
#define DISABLE_CONSTRUCTOR_PREVENTION_COMMANDSOFTENUMREGISTRY
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDSOFTENUMREGISTRY
|
||||
public:
|
||||
|
@ -5,13 +5,19 @@
|
||||
#include "Json.hpp"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
class Actor;
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
namespace CommandUtils {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
|
||||
// std::string getActorName(Actor &actor,int a1) {
|
||||
// //a1是没啥用的,只是为了改变符号
|
||||
// std::string (*rv)(Actor &);
|
||||
// *((void**)&rv) = dlsym("?getEntityName@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBVActor@@@Z");
|
||||
// return (*rv)(actor);
|
||||
// }
|
||||
#undef AFTER_EXTRA
|
||||
MCAPI extern std::vector<struct std::pair<std::string, char>> const CMD_INPUT_UNICODE_TRANSLATE_MAP;
|
||||
MCAPI bool addItemInstanceComponents(class ItemInstance &, class Json::Value const &, std::string &);
|
||||
|
@ -10,7 +10,12 @@
|
||||
class CommandVersion {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
public:
|
||||
int Min = 1, Max = 0x7FFFFFFF;
|
||||
CommandVersion(){};
|
||||
|
||||
#define DISABLE_CONSTRUCTOR_PREVENTION_COMMANDVERSION
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_COMMANDVERSION
|
||||
public:
|
||||
|
@ -4,12 +4,42 @@
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
// Include Headers or Declare Types Here
|
||||
#include "CommandContext.hpp"
|
||||
#include "MCRESULT.hpp"
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class MinecraftCommands {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
public:
|
||||
[[deprecated]]
|
||||
static MCRESULT _runcmd(void* origin, const std::string& cmd) {
|
||||
if (!Global<MinecraftCommands>)
|
||||
return {0};
|
||||
try
|
||||
{
|
||||
return Global<MinecraftCommands>->executeCommand(std::make_shared<CommandContext>(cmd, std::unique_ptr<CommandOrigin>((CommandOrigin*)origin)), false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return {0};
|
||||
}
|
||||
static MCRESULT _runcmd(std::unique_ptr<CommandOrigin> origin, const std::string& cmd)
|
||||
{
|
||||
if (!Global<MinecraftCommands>)
|
||||
return {0};
|
||||
try
|
||||
{
|
||||
return Global<MinecraftCommands>->executeCommand(std::make_shared<CommandContext>(cmd, std::move(origin)), false);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return {0};
|
||||
}
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_MINECRAFTCOMMANDS
|
||||
|
@ -51,6 +51,11 @@ public:
|
||||
FactorCalculationData(FactorCalculationData const&&) = delete;
|
||||
};
|
||||
|
||||
std::string const & getResourceName() const{
|
||||
//EffectCommand::execute Line247
|
||||
return dAccess<std::string>(this,80);
|
||||
};
|
||||
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_MOBEFFECT
|
||||
public:
|
||||
|
75
LiteLoader/Header/MC/RelativeFloat.hpp
Normal file
75
LiteLoader/Header/MC/RelativeFloat.hpp
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* @file RelativeFloat.hpp
|
||||
* @note This Header is auto generated by LiteLoaderBDS Toolchain.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#define AUTO_GENERATED
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
// Include Headers or Declare Types Here
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
/**
|
||||
* @brief MC class RelativeFloat.
|
||||
*
|
||||
*/
|
||||
class RelativeFloat {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
// Add Member There
|
||||
public:
|
||||
float value;
|
||||
bool is_relative;
|
||||
|
||||
RelativeFloat(float value)
|
||||
: value(value)
|
||||
, is_relative(true) {
|
||||
}
|
||||
|
||||
inline float getFloat(float center) const {
|
||||
if (is_relative)
|
||||
return center + value;
|
||||
return value;
|
||||
}
|
||||
RelativeFloat(){
|
||||
this->value = 0.0;
|
||||
this->is_relative = 1;
|
||||
};
|
||||
RelativeFloat(float base, bool relative){
|
||||
this->value = base;
|
||||
this->is_relative = relative;
|
||||
};
|
||||
float getValue(float base) const{
|
||||
if(this->is_relative)
|
||||
return base + this->value;
|
||||
else
|
||||
return this->value;
|
||||
};
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_RELATIVEFLOAT
|
||||
public:
|
||||
class RelativeFloat& operator=(class RelativeFloat const &) = delete;
|
||||
RelativeFloat(class RelativeFloat const &) = delete;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/**
|
||||
* @symbol ??0RelativeFloat@@QEAA@XZ
|
||||
* @hash 1491997340
|
||||
*/
|
||||
//MCAPI RelativeFloat();
|
||||
/**
|
||||
* @symbol ??0RelativeFloat@@QEAA@M_N@Z
|
||||
* @hash -528987998
|
||||
*/
|
||||
//MCAPI RelativeFloat(float, bool);
|
||||
/**
|
||||
* @symbol ?getValue@RelativeFloat@@QEBAMM@Z
|
||||
* @hash -802423667
|
||||
*/
|
||||
//MCAPI float getValue(float) const;
|
||||
|
||||
};
|
@ -11,7 +11,10 @@
|
||||
class TeleportCommand : public Command {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
|
||||
// Add Member There
|
||||
public:
|
||||
enum FacingResult;
|
||||
enum TeleportAnalysis;
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_TELEPORTCOMMAND
|
||||
public:
|
||||
|
42
LiteLoader/Header/MC/TeleportRotationData.hpp
Normal file
42
LiteLoader/Header/MC/TeleportRotationData.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @file TeleportRotationData.hpp
|
||||
* @note This Header is auto generated by LiteLoaderBDS Toolchain.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
#define AUTO_GENERATED
|
||||
#include "../Global.h"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
/**
|
||||
* @brief MC class TeleportRotationData.
|
||||
*
|
||||
*/
|
||||
class TeleportRotationData {
|
||||
|
||||
#define AFTER_EXTRA
|
||||
#define DISABLE_CONSTRUCTOR_PREVENTION_TELEPORTROTATIONDATA
|
||||
public:
|
||||
char filler[32];
|
||||
class TeleportRotationData& operator=(class TeleportRotationData const&) = delete;
|
||||
TeleportRotationData(class TeleportRotationData const&) = default;
|
||||
TeleportRotationData() = default;
|
||||
#undef AFTER_EXTRA
|
||||
#ifndef DISABLE_CONSTRUCTOR_PREVENTION_TELEPORTROTATIONDATA
|
||||
public:
|
||||
class TeleportRotationData& operator=(class TeleportRotationData const &) = delete;
|
||||
TeleportRotationData(class TeleportRotationData const &) = delete;
|
||||
TeleportRotationData() = delete;
|
||||
#endif
|
||||
|
||||
public:
|
||||
/**
|
||||
* @symbol ??0TeleportRotationData@@QEAA@AEBVRelativeFloat@@0AEBV?$optional@VVec2@@@std@@@Z
|
||||
* @hash 954629233
|
||||
*/
|
||||
MCAPI TeleportRotationData(class RelativeFloat const &, class RelativeFloat const &, class std::optional<class Vec2> const &);
|
||||
|
||||
};
|
29
LiteLoader/Header/MC/TeleportTarget.hpp
Normal file
29
LiteLoader/Header/MC/TeleportTarget.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
// This Header is auto generated by BDSLiteLoader Toolchain
|
||||
#pragma once
|
||||
#include "../Global.h"
|
||||
|
||||
|
||||
#define BEFORE_EXTRA //DO NOT EDIT THIS LINE
|
||||
|
||||
#undef BEFORE_EXTRA //DO NOT EDIT THIS LINE
|
||||
|
||||
class TeleportTarget {
|
||||
|
||||
#define AFTER_EXTRA //DO NOT EDIT THIS LINE
|
||||
struct UnknownStruct{
|
||||
char filler[40];
|
||||
};
|
||||
char filler[40]; // IDA TeleportCommand::computeTarget
|
||||
UnknownStruct *unk40;
|
||||
#undef AFTER_EXTRA //DO NOT EDIT THIS LINE
|
||||
|
||||
public:
|
||||
|
||||
//MCAPI ~TeleportTarget();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
@ -374,7 +374,7 @@ public:
|
||||
};
|
||||
// static_assert(std::is_pod_v<ActorRuntimeID>);
|
||||
|
||||
// #include "RelativeFloat.hpp"
|
||||
#include "RelativeFloat.hpp"
|
||||
|
||||
// namespace Core {
|
||||
//
|
||||
|
@ -5,7 +5,13 @@
|
||||
#include "Packet.hpp"
|
||||
|
||||
#define BEFORE_EXTRA
|
||||
|
||||
// Include Headers or Declare Types Here
|
||||
enum SoftEnumUpdateType : char
|
||||
{
|
||||
Add = 0,
|
||||
Remove = 1,
|
||||
Set = 2,
|
||||
};
|
||||
#undef BEFORE_EXTRA
|
||||
|
||||
class UpdateSoftEnumPacket : public Packet {
|
||||
|
@ -1,87 +1,87 @@
|
||||
//#pragma once
|
||||
//#include "Global.h"
|
||||
//#include "MC/Actor.hpp"
|
||||
//#include "MC/Player.hpp"
|
||||
//#include "MC/Command.hpp"
|
||||
//#include "MC/CommandMessage.hpp"
|
||||
//#include "MC/CommandOutput.hpp"
|
||||
//#include "MC/CommandParameterData.hpp"
|
||||
//#include "MC/CommandPosition.hpp"
|
||||
//#include "MC/CommandSelector.hpp"
|
||||
//#include "MC/CommandRegistry.hpp"
|
||||
//#include <tuple>
|
||||
//
|
||||
//namespace RegisterCommandHelper {
|
||||
//template <typename Command, typename Type>
|
||||
//static int getOffset(Type Command::*src) {
|
||||
// union {
|
||||
// Type Command::*src;
|
||||
// int value;
|
||||
// } u;
|
||||
// u.src = src;
|
||||
// return u.value;
|
||||
//}
|
||||
//
|
||||
//using ParseFn = bool (CommandRegistry::*)(
|
||||
// void*, CommandRegistry::ParseToken const&, CommandOrigin const&, int, std::string&,
|
||||
// std::vector<std::string>&) const;
|
||||
//
|
||||
//template <typename Command, typename Type>
|
||||
//static CommandParameterData makeMandatory(Type Command::*field, std::string name, bool Command::*isSet = nullptr) {
|
||||
//
|
||||
// return {
|
||||
// type_id<CommandRegistry, Type>(),
|
||||
// CommandRegistry::getParseFn<Type>(),
|
||||
// name,
|
||||
// CommandParameterDataType::NORMAL,
|
||||
// nullptr,
|
||||
// getOffset(field),
|
||||
// false,
|
||||
// isSet ? getOffset(isSet) : -1,
|
||||
// };
|
||||
//}
|
||||
//template <CommandParameterDataType DataType, typename Command, typename Type>
|
||||
//static CommandParameterData
|
||||
// makeMandatory(Type Command::*field, std::string name, char const* desc = nullptr, bool Command::*isSet = nullptr) {
|
||||
// return {
|
||||
// type_id<CommandRegistry, Type>(),
|
||||
// CommandRegistry::getParseFn<Type>(),
|
||||
// name,
|
||||
// DataType,
|
||||
// desc,
|
||||
// getOffset(field),
|
||||
// false,
|
||||
// isSet ? getOffset(isSet) : -1,
|
||||
// };
|
||||
//}
|
||||
//template <typename Command, typename Type>
|
||||
//static CommandParameterData makeOptional(Type Command::*field, std::string name, bool Command::*isSet = nullptr) {
|
||||
// typeid_t<CommandRegistry> tpid{0};
|
||||
//
|
||||
// return {
|
||||
// type_id<CommandRegistry, Type>(),
|
||||
// CommandRegistry::getParseFn<Type>(),
|
||||
// name,
|
||||
// CommandParameterDataType::NORMAL,
|
||||
// nullptr,
|
||||
// getOffset(field),
|
||||
// true,
|
||||
// isSet ? getOffset(isSet) : -1,
|
||||
// };
|
||||
//}
|
||||
//template <CommandParameterDataType DataType, typename Command, typename Type>
|
||||
//static CommandParameterData
|
||||
// makeOptional(Type Command::*field, std::string name, char const* desc = nullptr, bool Command::*isSet = nullptr) {
|
||||
//
|
||||
// return {
|
||||
// type_id<CommandRegistry, Type>(),
|
||||
// CommandRegistry::getParseFn<Type>(),
|
||||
// name,
|
||||
// DataType,
|
||||
// desc,
|
||||
// getOffset(field),
|
||||
// true,
|
||||
// isSet ? getOffset(isSet) : -1,
|
||||
// };
|
||||
//}
|
||||
//} // namespace RegisterCommandHelper
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include "MC/Actor.hpp"
|
||||
#include "MC/Player.hpp"
|
||||
#include "MC/Command.hpp"
|
||||
#include "MC/CommandMessage.hpp"
|
||||
#include "MC/CommandOutput.hpp"
|
||||
#include "MC/CommandParameterData.hpp"
|
||||
#include "MC/CommandPosition.hpp"
|
||||
#include "MC/CommandSelector.hpp"
|
||||
#include "MC/CommandRegistry.hpp"
|
||||
#include <tuple>
|
||||
|
||||
namespace RegisterCommandHelper {
|
||||
template <typename Command, typename Type>
|
||||
static int getOffset(Type Command::*src) {
|
||||
union {
|
||||
Type Command::*src;
|
||||
int value;
|
||||
} u;
|
||||
u.src = src;
|
||||
return u.value;
|
||||
}
|
||||
|
||||
using ParseFn = bool (CommandRegistry::*)(
|
||||
void*, CommandRegistry::ParseToken const&, CommandOrigin const&, int, std::string&,
|
||||
std::vector<std::string>&) const;
|
||||
|
||||
template <typename Command, typename Type>
|
||||
static CommandParameterData makeMandatory(Type Command::*field, std::string name, bool Command::*isSet = nullptr) {
|
||||
|
||||
return {
|
||||
type_id<CommandRegistry, Type>(),
|
||||
CommandRegistry::getParseFn<Type>(),
|
||||
name,
|
||||
CommandParameterDataType::NORMAL,
|
||||
nullptr,
|
||||
getOffset(field),
|
||||
false,
|
||||
isSet ? getOffset(isSet) : -1,
|
||||
};
|
||||
}
|
||||
template <CommandParameterDataType DataType, typename Command, typename Type>
|
||||
static CommandParameterData
|
||||
makeMandatory(Type Command::*field, std::string name, char const* desc = nullptr, bool Command::*isSet = nullptr) {
|
||||
return {
|
||||
type_id<CommandRegistry, Type>(),
|
||||
CommandRegistry::getParseFn<Type>(),
|
||||
name,
|
||||
DataType,
|
||||
desc,
|
||||
getOffset(field),
|
||||
false,
|
||||
isSet ? getOffset(isSet) : -1,
|
||||
};
|
||||
}
|
||||
template <typename Command, typename Type>
|
||||
static CommandParameterData makeOptional(Type Command::*field, std::string name, bool Command::*isSet = nullptr) {
|
||||
typeid_t<CommandRegistry> tpid{0};
|
||||
|
||||
return {
|
||||
type_id<CommandRegistry, Type>(),
|
||||
CommandRegistry::getParseFn<Type>(),
|
||||
name,
|
||||
CommandParameterDataType::NORMAL,
|
||||
nullptr,
|
||||
getOffset(field),
|
||||
true,
|
||||
isSet ? getOffset(isSet) : -1,
|
||||
};
|
||||
}
|
||||
template <CommandParameterDataType DataType, typename Command, typename Type>
|
||||
static CommandParameterData
|
||||
makeOptional(Type Command::*field, std::string name, char const* desc = nullptr, bool Command::*isSet = nullptr) {
|
||||
|
||||
return {
|
||||
type_id<CommandRegistry, Type>(),
|
||||
CommandRegistry::getParseFn<Type>(),
|
||||
name,
|
||||
DataType,
|
||||
desc,
|
||||
getOffset(field),
|
||||
true,
|
||||
isSet ? getOffset(isSet) : -1,
|
||||
};
|
||||
}
|
||||
} // namespace RegisterCommandHelper
|
||||
|
@ -1,7 +1,7 @@
|
||||
// #include <MC/CommandOrigin.hpp>
|
||||
// #include <MC/Actor.hpp>
|
||||
#include <MC/CommandOrigin.hpp>
|
||||
#include <MC/Actor.hpp>
|
||||
|
||||
// ServerPlayer* CommandOrigin::getPlayer() const {
|
||||
// Actor* origin = getEntity();
|
||||
// return origin->isPlayer() ? (ServerPlayer*)origin : nullptr;
|
||||
// }
|
||||
ServerPlayer* CommandOrigin::getPlayer() const {
|
||||
Actor* origin = getEntity();
|
||||
return origin->isPlayer() ? (ServerPlayer*)origin : nullptr;
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
// #include <MC/CommandOutput.hpp>
|
||||
#include <MC/CommandOutput.hpp>
|
||||
|
||||
// void CommandOutput::addMessage(const std::string& str) {
|
||||
// this->addMessage(str, {}, (CommandOutputMessageType)0);
|
||||
// }
|
||||
void CommandOutput::addMessage(const std::string& str) {
|
||||
this->addMessage(str, {}, (CommandOutputMessageType)0);
|
||||
}
|
||||
|
||||
// void CommandOutput::success(const std::string& str) {
|
||||
// this->success(str, {});
|
||||
// }
|
||||
void CommandOutput::success(const std::string& str) {
|
||||
this->success(str, {});
|
||||
}
|
||||
|
||||
// void CommandOutput::error(const std::string& str) {
|
||||
// this->error(str, {});
|
||||
// }
|
||||
void CommandOutput::error(const std::string& str) {
|
||||
this->error(str, {});
|
||||
}
|
@ -1,256 +1,256 @@
|
||||
// #define COMMAND_REGISTRY_EXTRA
|
||||
// #include <MC/CommandRegistry.hpp>
|
||||
// #include <MC/CommandParameterData.hpp>
|
||||
// #include <MC/AvailableCommandsPacket.hpp>
|
||||
// #include <vector>
|
||||
// #include <RegCommandAPI.h>
|
||||
// #include <LoggerAPI.h>
|
||||
// static_assert(offsetof(CommandParameterData, options) == 73);
|
||||
// static_assert(offsetof(CommandParameterData, name) == 16);
|
||||
// static_assert(offsetof(CommandParameterData, unk56) == 56);
|
||||
// static_assert(offsetof(CommandRegistry::Overload, unk) == 40);
|
||||
// static_assert(sizeof(CommandRegistry::Overload) == 72);
|
||||
// static_assert(offsetof(CommandRegistry::Signature, alt_symbol) == 96);
|
||||
// static_assert(sizeof(CommandRegistry::Signature) == 120);
|
||||
// /*
|
||||
// void CommandRegistry::registerOverload(std::string const& name, Overload::FactoryFn factory, std::vector<CommandParameterData>&& args)
|
||||
// {
|
||||
// Signature* signature = const_cast<Signature*>(findCommand(name));
|
||||
// auto& overload = signature->overloads.emplace_back(CommandVersion{}, factory, std::move(args));
|
||||
// registerOverloadInternal(*signature, overload);
|
||||
// }*/
|
||||
#define COMMAND_REGISTRY_EXTRA
|
||||
#include <MC/CommandRegistry.hpp>
|
||||
#include <MC/CommandParameterData.hpp>
|
||||
#include <MC/AvailableCommandsPacket.hpp>
|
||||
#include <vector>
|
||||
#include <RegCommandAPI.h>
|
||||
#include <LoggerAPI.h>
|
||||
static_assert(offsetof(CommandParameterData, options) == 73);
|
||||
static_assert(offsetof(CommandParameterData, name) == 16);
|
||||
static_assert(offsetof(CommandParameterData, unk56) == 56);
|
||||
static_assert(offsetof(CommandRegistry::Overload, unk) == 40);
|
||||
static_assert(sizeof(CommandRegistry::Overload) == 72);
|
||||
static_assert(offsetof(CommandRegistry::Signature, alt_symbol) == 96);
|
||||
static_assert(sizeof(CommandRegistry::Signature) == 120);
|
||||
/*
|
||||
void CommandRegistry::registerOverload(std::string const& name, Overload::FactoryFn factory, std::vector<CommandParameterData>&& args)
|
||||
{
|
||||
Signature* signature = const_cast<Signature*>(findCommand(name));
|
||||
auto& overload = signature->overloads.emplace_back(CommandVersion{}, factory, std::move(args));
|
||||
registerOverloadInternal(*signature, overload);
|
||||
}*/
|
||||
|
||||
// extern Logger logger;
|
||||
extern Logger logger;
|
||||
|
||||
// CommandRegistry::Overload::Overload(CommandVersion version,
|
||||
// FactoryFn factory,
|
||||
// std::vector<CommandParameterData>&& args)
|
||||
// : version(version)
|
||||
// , factory(factory)
|
||||
// , params(std::forward<std::vector<CommandParameterData>>(args))
|
||||
// , unk(255){};
|
||||
CommandRegistry::Overload::Overload(CommandVersion version,
|
||||
FactoryFn factory,
|
||||
std::vector<CommandParameterData>&& args)
|
||||
: version(version)
|
||||
, factory(factory)
|
||||
, params(std::forward<std::vector<CommandParameterData>>(args))
|
||||
, unk(255){};
|
||||
|
||||
// CommandRegistry::Overload::~Overload(){};
|
||||
CommandRegistry::Overload::~Overload(){};
|
||||
|
||||
// std::vector<std::string> CommandRegistry::getEnumNames() {
|
||||
// if (!Global<CommandRegistry>)
|
||||
// return {};
|
||||
// std::vector<std::string> results;
|
||||
// for (auto& e : Global<CommandRegistry>->mEnums)
|
||||
// results.push_back(e.name);
|
||||
// return results;
|
||||
std::vector<std::string> CommandRegistry::getEnumNames() {
|
||||
if (!Global<CommandRegistry>)
|
||||
return {};
|
||||
std::vector<std::string> results;
|
||||
for (auto& e : Global<CommandRegistry>->mEnums)
|
||||
results.push_back(e.name);
|
||||
return results;
|
||||
|
||||
// auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
// return packet.getEnumNames();
|
||||
// }
|
||||
// std::vector<std::string> CommandRegistry::getSoftEnumNames() {
|
||||
// if (!Global<CommandRegistry>)
|
||||
// return {};
|
||||
// std::vector<std::string> results;
|
||||
// for (auto& e : Global<CommandRegistry>->mSoftEnums)
|
||||
// results.push_back(e.name);
|
||||
// return results;
|
||||
auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
return packet.getEnumNames();
|
||||
}
|
||||
std::vector<std::string> CommandRegistry::getSoftEnumNames() {
|
||||
if (!Global<CommandRegistry>)
|
||||
return {};
|
||||
std::vector<std::string> results;
|
||||
for (auto& e : Global<CommandRegistry>->mSoftEnums)
|
||||
results.push_back(e.name);
|
||||
return results;
|
||||
|
||||
// auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
// return packet.getEnumNames();
|
||||
// }
|
||||
// std::vector<std::string> CommandRegistry::getEnumValues(std::string const& name) {
|
||||
// if (!Global<CommandRegistry>)
|
||||
// return {};
|
||||
// std::vector<std::string> results;
|
||||
// auto& enums = Global<CommandRegistry>->mEnums;
|
||||
// auto iter = std::find_if(enums.begin(), enums.end(), [&](CommandRegistry::Enum const& r) { return r.name == name; });
|
||||
// if (iter == enums.end())
|
||||
// return results;
|
||||
// for (auto& i : iter->values)
|
||||
// results.push_back(Global<CommandRegistry>->mEnumValues.at(std::get<3>(i)));
|
||||
// return results;
|
||||
auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
return packet.getEnumNames();
|
||||
}
|
||||
std::vector<std::string> CommandRegistry::getEnumValues(std::string const& name) {
|
||||
if (!Global<CommandRegistry>)
|
||||
return {};
|
||||
std::vector<std::string> results;
|
||||
auto& enums = Global<CommandRegistry>->mEnums;
|
||||
auto iter = std::find_if(enums.begin(), enums.end(), [&](CommandRegistry::Enum const& r) { return r.name == name; });
|
||||
if (iter == enums.end())
|
||||
return results;
|
||||
for (auto& i : iter->values)
|
||||
results.push_back(Global<CommandRegistry>->mEnumValues.at(std::get<3>(i)));
|
||||
return results;
|
||||
|
||||
// auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
// return packet.getEnumValues(name);
|
||||
// }
|
||||
// std::vector<std::string> CommandRegistry::getSoftEnumValues(std::string const& name) {
|
||||
// if (!Global<CommandRegistry>)
|
||||
// return {};
|
||||
// std::vector<std::string> results;
|
||||
// auto& enums = Global<CommandRegistry>->mSoftEnums;
|
||||
// auto iter = std::find_if(enums.begin(), enums.end(), [&](CommandRegistry::SoftEnum const& r) { return r.name == name; });
|
||||
// if (iter != enums.end())
|
||||
// return iter->list;
|
||||
// return {};
|
||||
auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
return packet.getEnumValues(name);
|
||||
}
|
||||
std::vector<std::string> CommandRegistry::getSoftEnumValues(std::string const& name) {
|
||||
if (!Global<CommandRegistry>)
|
||||
return {};
|
||||
std::vector<std::string> results;
|
||||
auto& enums = Global<CommandRegistry>->mSoftEnums;
|
||||
auto iter = std::find_if(enums.begin(), enums.end(), [&](CommandRegistry::SoftEnum const& r) { return r.name == name; });
|
||||
if (iter != enums.end())
|
||||
return iter->list;
|
||||
return {};
|
||||
|
||||
// auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
// return packet.getEnumValues(name);
|
||||
// }
|
||||
// std::string CommandRegistry::getCommandFullName(std::string const& name) {
|
||||
// if (!Global<CommandRegistry>)
|
||||
// return "";
|
||||
// auto sig = Global<CommandRegistry>->findCommand(name);
|
||||
// if (sig)
|
||||
// return sig->name;
|
||||
// return "";
|
||||
// }
|
||||
auto packet = Global<CommandRegistry>->serializeAvailableCommands();
|
||||
return packet.getEnumValues(name);
|
||||
}
|
||||
std::string CommandRegistry::getCommandFullName(std::string const& name) {
|
||||
if (!Global<CommandRegistry>)
|
||||
return "";
|
||||
auto sig = Global<CommandRegistry>->findCommand(name);
|
||||
if (sig)
|
||||
return sig->name;
|
||||
return "";
|
||||
}
|
||||
|
||||
// #include <Main/Config.h>
|
||||
// bool CommandRegistry::unregisterCommand(std::string const& name) {
|
||||
// if (!LL::globalConfig.debugMode) {
|
||||
// logger.error("unregister command is only enabled in debug mode");
|
||||
// return false;
|
||||
// }
|
||||
// logger.warn("Unregister Command \"{}\"!", name);
|
||||
// try {
|
||||
// auto command = getCommandFullName(name);
|
||||
// if (command.empty())
|
||||
// return false;
|
||||
// auto alias = getAliases(name);
|
||||
// auto aliasKey = command + "CommandAliases";
|
||||
// static size_t removeIndex = 0;
|
||||
// auto iter = std::find_if(mEnums.begin(), mEnums.end(), [](Enum const& e) { return e.name == "CommandName"; });
|
||||
// for (auto i = iter->values.begin(); i != iter->values.end();) {
|
||||
// auto& enumValue = mEnumValues.at(std::get<3>(*i));
|
||||
// if (enumValue == command || std::find(alias.begin(), alias.end(), enumValue) != alias.end()) {
|
||||
// mEnumValueLookup.erase(enumValue);
|
||||
// i = iter->values.erase(i);
|
||||
// enumValue = fmt::format("removed_{}", removeIndex++);
|
||||
// } else {
|
||||
// ++i;
|
||||
// }
|
||||
// }
|
||||
// auto aliasIter = std::find_if(mEnums.begin(), mEnums.end(), [&aliasKey](Enum const& e) { return e.name == aliasKey; });
|
||||
// if (aliasIter != mEnums.end()) {
|
||||
// aliasIter->values.clear();
|
||||
// mEnumLookup.erase(aliasIter->name);
|
||||
// aliasIter->name = fmt::format("removed_{}", removeIndex++);
|
||||
// }
|
||||
// auto sig = mSignatures.find(command);
|
||||
// if (sig == mSignatures.end())
|
||||
// return false;
|
||||
// {
|
||||
// auto iter = std::remove_if(mCommandSymbols.begin(), mCommandSymbols.end(),
|
||||
// [&](Symbol const& r) { return r == sig->second.main_symbol || r == sig->second.alt_symbol; });
|
||||
// if (iter != mCommandSymbols.end())
|
||||
// mCommandSymbols.erase(iter, mCommandSymbols.end());
|
||||
// }
|
||||
// //{
|
||||
// // auto iter = std::remove_if(mRules.begin(), mRules.end(),
|
||||
// // [&](ParseRule const& r) { return r.sym == sig->second.main_symbol || r.sym == sig->second.alt_symbol; });
|
||||
// // if (iter == mRules.end())
|
||||
// // mRules.erase(iter, mRules.end());
|
||||
// //};
|
||||
// {
|
||||
// auto iter = std::remove_if(mFactorizations.begin(), mFactorizations.end(),
|
||||
// [&](Factorization const& r) { return r.sym == sig->second.main_symbol || r.sym == sig->second.alt_symbol; });
|
||||
// if (iter != mFactorizations.end())
|
||||
// mFactorizations.erase(iter, mFactorizations.end());
|
||||
// };
|
||||
#include <Main/Config.h>
|
||||
bool CommandRegistry::unregisterCommand(std::string const& name) {
|
||||
if (!LL::globalConfig.debugMode) {
|
||||
logger.error("unregister command is only enabled in debug mode");
|
||||
return false;
|
||||
}
|
||||
logger.warn("Unregister Command \"{}\"!", name);
|
||||
try {
|
||||
auto command = getCommandFullName(name);
|
||||
if (command.empty())
|
||||
return false;
|
||||
auto alias = getAliases(name);
|
||||
auto aliasKey = command + "CommandAliases";
|
||||
static size_t removeIndex = 0;
|
||||
auto iter = std::find_if(mEnums.begin(), mEnums.end(), [](Enum const& e) { return e.name == "CommandName"; });
|
||||
for (auto i = iter->values.begin(); i != iter->values.end();) {
|
||||
auto& enumValue = mEnumValues.at(std::get<3>(*i));
|
||||
if (enumValue == command || std::find(alias.begin(), alias.end(), enumValue) != alias.end()) {
|
||||
mEnumValueLookup.erase(enumValue);
|
||||
i = iter->values.erase(i);
|
||||
enumValue = fmt::format("removed_{}", removeIndex++);
|
||||
} else {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
auto aliasIter = std::find_if(mEnums.begin(), mEnums.end(), [&aliasKey](Enum const& e) { return e.name == aliasKey; });
|
||||
if (aliasIter != mEnums.end()) {
|
||||
aliasIter->values.clear();
|
||||
mEnumLookup.erase(aliasIter->name);
|
||||
aliasIter->name = fmt::format("removed_{}", removeIndex++);
|
||||
}
|
||||
auto sig = mSignatures.find(command);
|
||||
if (sig == mSignatures.end())
|
||||
return false;
|
||||
{
|
||||
auto iter = std::remove_if(mCommandSymbols.begin(), mCommandSymbols.end(),
|
||||
[&](Symbol const& r) { return r == sig->second.main_symbol || r == sig->second.alt_symbol; });
|
||||
if (iter != mCommandSymbols.end())
|
||||
mCommandSymbols.erase(iter, mCommandSymbols.end());
|
||||
}
|
||||
//{
|
||||
// auto iter = std::remove_if(mRules.begin(), mRules.end(),
|
||||
// [&](ParseRule const& r) { return r.sym == sig->second.main_symbol || r.sym == sig->second.alt_symbol; });
|
||||
// if (iter == mRules.end())
|
||||
// mRules.erase(iter, mRules.end());
|
||||
//};
|
||||
{
|
||||
auto iter = std::remove_if(mFactorizations.begin(), mFactorizations.end(),
|
||||
[&](Factorization const& r) { return r.sym == sig->second.main_symbol || r.sym == sig->second.alt_symbol; });
|
||||
if (iter != mFactorizations.end())
|
||||
mFactorizations.erase(iter, mFactorizations.end());
|
||||
};
|
||||
|
||||
// mSignatures.erase(sig);
|
||||
// mAliases.erase(command);
|
||||
// return true;
|
||||
// } catch (...) {
|
||||
// logger.error("Error in CommandRegistry::unregisterCommand");
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
mSignatures.erase(sig);
|
||||
mAliases.erase(command);
|
||||
return true;
|
||||
} catch (...) {
|
||||
logger.error("Error in CommandRegistry::unregisterCommand");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// inline void CommandRegistry::printAll() const {
|
||||
// logger.error("mRules");
|
||||
// for (auto& rule : mRules) {
|
||||
// logger.warn("{}", rule.toDebugString());
|
||||
// }
|
||||
// logger.error("mParseTableMap");
|
||||
// for (auto& [key, table] : mParseTableMap) {
|
||||
// logger.warn("{}: {}", key, table.toDebugString());
|
||||
// }
|
||||
// logger.error("mOptionals");
|
||||
// for (auto& optional : mOptionals) {
|
||||
// logger.warn("{}", optional.toDebugString());
|
||||
// }
|
||||
// logger.error("mEnums");
|
||||
// for (auto& en : mEnums) {
|
||||
// logger.warn("{}", en.toDebugString());
|
||||
// }
|
||||
// logger.error("mFactorizations");
|
||||
// for (auto& i : mFactorizations) {
|
||||
// logger.warn("{}", i.toDebugString());
|
||||
// }
|
||||
// logger.error("mCommandSymbols");
|
||||
// for (auto& i : mCommandSymbols) {
|
||||
// logger.warn("{}", i.toDebugString());
|
||||
// }
|
||||
// logger.error("mSignatures");
|
||||
// for (auto& [k, v] : mSignatures) {
|
||||
// logger.warn("{}: {}", k, v.toDebugString());
|
||||
// }
|
||||
// logger.error("mConstrainedValues");
|
||||
// for (auto& i : mConstrainedValues) {
|
||||
// logger.warn("{}", i.toDebugString());
|
||||
// }
|
||||
// }
|
||||
// inline void CommandRegistry::printSize() const {
|
||||
// static auto log = std::unordered_map<std::string, std::string>{
|
||||
// {"mRules ", ""},
|
||||
// {"mParseTableMap ", ""},
|
||||
// {"mOptionals ", ""},
|
||||
// {"mEnumValues ", ""},
|
||||
// {"mEnums ", ""},
|
||||
// {"mFactorizations ", ""},
|
||||
// {"mPostfixes ", ""},
|
||||
// {"mEnumLookup ", ""},
|
||||
// {"mEnumValueLookup ", ""},
|
||||
// {"mCommandSymbols ", ""},
|
||||
// {"mSignatures ", ""},
|
||||
// {"mTypeLookup ", ""},
|
||||
// {"unk376 ", ""},
|
||||
// {"mAliases ", ""},
|
||||
// {"mSemanticConstraints ", ""},
|
||||
// {"mSemanticConstraintLookup", ""},
|
||||
// {"mConstrainedValues ", ""},
|
||||
// {"mConstrainedValueLookup ", ""},
|
||||
// {"mSoftEnums ", ""},
|
||||
// {"mSoftEnumLookup ", ""},
|
||||
// {"mStateStack ", ""},
|
||||
// {"mEnumsValues ", ""},
|
||||
// {"mConstrainedValuesValues ", ""},
|
||||
// };
|
||||
// auto mEnumsValuesSize = ([&]() -> size_t {
|
||||
// size_t size = 0;
|
||||
// for (auto& i : mEnums) {
|
||||
// size += i.values.size();
|
||||
// }
|
||||
// return size;
|
||||
// })();
|
||||
// auto mConstrainedValuesSize = ([&]() -> size_t {
|
||||
// size_t size = 0;
|
||||
// for (auto& i : mConstrainedValues) {
|
||||
// size += i.mConstraints.size();
|
||||
// }
|
||||
// return size;
|
||||
// })();
|
||||
// log["mRules "].append(fmt::format(", {:4}", mRules.size()));
|
||||
// log["mParseTableMap "].append(fmt::format(", {:4}", mParseTableMap.size()));
|
||||
// log["mOptionals "].append(fmt::format(", {:4}", mOptionals.size()));
|
||||
// log["mEnumValues "].append(fmt::format(", {:4}", mEnumValues.size()));
|
||||
// log["mEnums "].append(fmt::format(", {:4}", mEnums.size()));
|
||||
// log["mFactorizations "].append(fmt::format(", {:4}", mFactorizations.size()));
|
||||
// log["mPostfixes "].append(fmt::format(", {:4}", mPostfixes.size()));
|
||||
// log["mEnumLookup "].append(fmt::format(", {:4}", mEnumLookup.size()));
|
||||
// log["mEnumValueLookup "].append(fmt::format(", {:4}", mEnumValueLookup.size()));
|
||||
// log["mCommandSymbols "].append(fmt::format(", {:4}", mCommandSymbols.size()));
|
||||
// log["mSignatures "].append(fmt::format(", {:4}", mSignatures.size()));
|
||||
// log["mTypeLookup "].append(fmt::format(", {:4}", mTypeLookup.size()));
|
||||
// log["unk376 "].append(fmt::format(", {:4}", unk376.size()));
|
||||
// log["mAliases "].append(fmt::format(", {:4}", mAliases.size()));
|
||||
// log["mSemanticConstraints "].append(fmt::format(", {:4}", mSemanticConstraints.size()));
|
||||
// log["mSemanticConstraintLookup"].append(fmt::format(", {:4}", mSemanticConstraintLookup.size()));
|
||||
// log["mConstrainedValues "].append(fmt::format(", {:4}", mConstrainedValues.size()));
|
||||
// log["mConstrainedValueLookup "].append(fmt::format(", {:4}", mConstrainedValueLookup.size()));
|
||||
// log["mSoftEnums "].append(fmt::format(", {:4}", mSoftEnums.size()));
|
||||
// log["mSoftEnumLookup "].append(fmt::format(", {:4}", mSoftEnumLookup.size()));
|
||||
// log["mStateStack "].append(fmt::format(", {:4}", mStateStack.size()));
|
||||
// log["mEnumsValues "].append(fmt::format(", {:4}", mEnumsValuesSize));
|
||||
// log["mConstrainedValuesValues "].append(fmt::format(", {:4}", mConstrainedValuesSize));
|
||||
// for (auto& [k, v] : log) {
|
||||
// logger.warn("{}{}", k, v);
|
||||
// }
|
||||
// }
|
||||
inline void CommandRegistry::printAll() const {
|
||||
logger.error("mRules");
|
||||
for (auto& rule : mRules) {
|
||||
logger.warn("{}", rule.toDebugString());
|
||||
}
|
||||
logger.error("mParseTableMap");
|
||||
for (auto& [key, table] : mParseTableMap) {
|
||||
logger.warn("{}: {}", key, table.toDebugString());
|
||||
}
|
||||
logger.error("mOptionals");
|
||||
for (auto& optional : mOptionals) {
|
||||
logger.warn("{}", optional.toDebugString());
|
||||
}
|
||||
logger.error("mEnums");
|
||||
for (auto& en : mEnums) {
|
||||
logger.warn("{}", en.toDebugString());
|
||||
}
|
||||
logger.error("mFactorizations");
|
||||
for (auto& i : mFactorizations) {
|
||||
logger.warn("{}", i.toDebugString());
|
||||
}
|
||||
logger.error("mCommandSymbols");
|
||||
for (auto& i : mCommandSymbols) {
|
||||
logger.warn("{}", i.toDebugString());
|
||||
}
|
||||
logger.error("mSignatures");
|
||||
for (auto& [k, v] : mSignatures) {
|
||||
logger.warn("{}: {}", k, v.toDebugString());
|
||||
}
|
||||
logger.error("mConstrainedValues");
|
||||
for (auto& i : mConstrainedValues) {
|
||||
logger.warn("{}", i.toDebugString());
|
||||
}
|
||||
}
|
||||
inline void CommandRegistry::printSize() const {
|
||||
static auto log = std::unordered_map<std::string, std::string>{
|
||||
{"mRules ", ""},
|
||||
{"mParseTableMap ", ""},
|
||||
{"mOptionals ", ""},
|
||||
{"mEnumValues ", ""},
|
||||
{"mEnums ", ""},
|
||||
{"mFactorizations ", ""},
|
||||
{"mPostfixes ", ""},
|
||||
{"mEnumLookup ", ""},
|
||||
{"mEnumValueLookup ", ""},
|
||||
{"mCommandSymbols ", ""},
|
||||
{"mSignatures ", ""},
|
||||
{"mTypeLookup ", ""},
|
||||
{"unk376 ", ""},
|
||||
{"mAliases ", ""},
|
||||
{"mSemanticConstraints ", ""},
|
||||
{"mSemanticConstraintLookup", ""},
|
||||
{"mConstrainedValues ", ""},
|
||||
{"mConstrainedValueLookup ", ""},
|
||||
{"mSoftEnums ", ""},
|
||||
{"mSoftEnumLookup ", ""},
|
||||
{"mStateStack ", ""},
|
||||
{"mEnumsValues ", ""},
|
||||
{"mConstrainedValuesValues ", ""},
|
||||
};
|
||||
auto mEnumsValuesSize = ([&]() -> size_t {
|
||||
size_t size = 0;
|
||||
for (auto& i : mEnums) {
|
||||
size += i.values.size();
|
||||
}
|
||||
return size;
|
||||
})();
|
||||
auto mConstrainedValuesSize = ([&]() -> size_t {
|
||||
size_t size = 0;
|
||||
for (auto& i : mConstrainedValues) {
|
||||
size += i.mConstraints.size();
|
||||
}
|
||||
return size;
|
||||
})();
|
||||
log["mRules "].append(fmt::format(", {:4}", mRules.size()));
|
||||
log["mParseTableMap "].append(fmt::format(", {:4}", mParseTableMap.size()));
|
||||
log["mOptionals "].append(fmt::format(", {:4}", mOptionals.size()));
|
||||
log["mEnumValues "].append(fmt::format(", {:4}", mEnumValues.size()));
|
||||
log["mEnums "].append(fmt::format(", {:4}", mEnums.size()));
|
||||
log["mFactorizations "].append(fmt::format(", {:4}", mFactorizations.size()));
|
||||
log["mPostfixes "].append(fmt::format(", {:4}", mPostfixes.size()));
|
||||
log["mEnumLookup "].append(fmt::format(", {:4}", mEnumLookup.size()));
|
||||
log["mEnumValueLookup "].append(fmt::format(", {:4}", mEnumValueLookup.size()));
|
||||
log["mCommandSymbols "].append(fmt::format(", {:4}", mCommandSymbols.size()));
|
||||
log["mSignatures "].append(fmt::format(", {:4}", mSignatures.size()));
|
||||
log["mTypeLookup "].append(fmt::format(", {:4}", mTypeLookup.size()));
|
||||
log["unk376 "].append(fmt::format(", {:4}", unk376.size()));
|
||||
log["mAliases "].append(fmt::format(", {:4}", mAliases.size()));
|
||||
log["mSemanticConstraints "].append(fmt::format(", {:4}", mSemanticConstraints.size()));
|
||||
log["mSemanticConstraintLookup"].append(fmt::format(", {:4}", mSemanticConstraintLookup.size()));
|
||||
log["mConstrainedValues "].append(fmt::format(", {:4}", mConstrainedValues.size()));
|
||||
log["mConstrainedValueLookup "].append(fmt::format(", {:4}", mConstrainedValueLookup.size()));
|
||||
log["mSoftEnums "].append(fmt::format(", {:4}", mSoftEnums.size()));
|
||||
log["mSoftEnumLookup "].append(fmt::format(", {:4}", mSoftEnumLookup.size()));
|
||||
log["mStateStack "].append(fmt::format(", {:4}", mStateStack.size()));
|
||||
log["mEnumsValues "].append(fmt::format(", {:4}", mEnumsValuesSize));
|
||||
log["mConstrainedValuesValues "].append(fmt::format(", {:4}", mConstrainedValuesSize));
|
||||
for (auto& [k, v] : log) {
|
||||
logger.warn("{}{}", k, v);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -2017,19 +2017,19 @@ TClasslessInstanceHook(void, "?execute@StopCommand@@UEBAXAEBVCommandOrigin@@AEAV
|
||||
|
||||
|
||||
////////////// RegCmd //////////////
|
||||
// TInstanceHook(void, "?setup@ChangeSettingCommand@@SAXAEAVCommandRegistry@@@Z",
|
||||
// CommandRegistry, void* a1) {
|
||||
// Global<CommandRegistry> = this;
|
||||
// original(this, a1);
|
||||
// IF_LISTENED(RegCmdEvent) {
|
||||
// RegCmdEvent ev{};
|
||||
// ev.mCommandRegistry = this;
|
||||
// ev.call();
|
||||
// // setup dynamic command
|
||||
// DynamicCommand::onServerCommandsRegister(*this);
|
||||
// }
|
||||
// IF_LISTENED_END(RegCmdEvent)
|
||||
// }
|
||||
TInstanceHook(void, "?setup@ChangeSettingCommand@@SAXAEAVCommandRegistry@@@Z",
|
||||
CommandRegistry, void* a1) {
|
||||
Global<CommandRegistry> = this;
|
||||
original(this, a1);
|
||||
IF_LISTENED(RegCmdEvent) {
|
||||
RegCmdEvent ev{};
|
||||
ev.mCommandRegistry = this;
|
||||
ev.call();
|
||||
// setup dynamic command
|
||||
DynamicCommand::onServerCommandsRegister(*this);
|
||||
}
|
||||
IF_LISTENED_END(RegCmdEvent)
|
||||
}
|
||||
|
||||
////////////// ConsoleOutput //////////////
|
||||
THook(std::ostream&,
|
||||
|
@ -18,10 +18,10 @@
|
||||
#include <MC/StringTag.hpp>
|
||||
#include <MC/SimpleContainer.hpp>
|
||||
#include <MC/TeleportCommand.hpp>
|
||||
//#include <MC/TeleportTarget.hpp>
|
||||
#include <MC/TeleportTarget.hpp>
|
||||
//#include <MC/UserEntityIdentifierComponent.hpp>
|
||||
//#include <MC/OnFireSystem.hpp>
|
||||
//#include <MC/TeleportRotationData.hpp>
|
||||
#include <MC/TeleportRotationData.hpp>
|
||||
//#include <MC/ClipDefaults.hpp>
|
||||
#include <MC/ItemStack.hpp>
|
||||
#include <MC/ActorDefinitionIdentifier.hpp>
|
||||
@ -59,9 +59,9 @@ bool Actor::isOnGround() const {
|
||||
return (dAccess<bool, 472>(this)); // IDA DirectActorProxyImpl<IMobMovementProxy>::isOnGround
|
||||
}
|
||||
|
||||
// std::string Actor::getTypeName() const {
|
||||
// return getActorIdentifier().getCanonicalName();
|
||||
// }
|
||||
std::string Actor::getTypeName() const {
|
||||
return getActorIdentifier().getCanonicalName();
|
||||
}
|
||||
|
||||
// bool Actor::hurtEntity(float damage, ActorDamageCause damageCause) {
|
||||
// auto ads = new ActorDamageSource(damageCause);
|
||||
@ -93,23 +93,25 @@ ActorUniqueID Actor::getActorUniqueId() const {
|
||||
}
|
||||
|
||||
// static_assert(sizeof(TeleportRotationData) == 32);
|
||||
// bool Actor::teleport(Vec3 to, int dimID) {
|
||||
// if (!this->isAlive())
|
||||
// return false;
|
||||
bool Actor::teleport(Vec3 to, int dimID) {
|
||||
if (!this->isAlive())
|
||||
return false;
|
||||
// char mem[48];
|
||||
// auto computeTarget = (TeleportTarget * (*)(void*, class Actor&, class Vec3, class Vec3*, class AutomaticID<class Dimension, int>, std::optional<TeleportRotationData> const&, int))(&TeleportCommand::computeTarget);
|
||||
// auto target = computeTarget(mem, *this, to, nullptr, dimID, TeleportRotationData{getRotation().x, getRotation().y, {}}, 15);
|
||||
// TeleportCommand::applyTarget(*this, *target, false);
|
||||
// return true;
|
||||
// }
|
||||
TeleportCommand::teleport(*this,to,nullptr,dimID,getRotation().x, getRotation().y,15,this->getUniqueID());
|
||||
return true;
|
||||
}
|
||||
|
||||
// bool Actor::teleport(Vec3 to, int dimID, float x, float y) {
|
||||
bool Actor::teleport(Vec3 to, int dimID, float x, float y) {
|
||||
// char mem[48];
|
||||
// auto computeTarget = (TeleportTarget * (*)(void*, class Actor&, class Vec3, class Vec3*, class AutomaticID<class Dimension, int>, std::optional<TeleportRotationData> const&, int))(&TeleportCommand::computeTarget);
|
||||
// auto target = computeTarget(mem, *this, to, nullptr, dimID, TeleportRotationData{x, y, {}}, 15);
|
||||
// TeleportCommand::applyTarget(*this, *target, false);
|
||||
// return true;
|
||||
// }
|
||||
TeleportCommand::teleport(*this,to,nullptr,dimID,x,y,15,this->getUniqueID());
|
||||
return true;
|
||||
}
|
||||
|
||||
SimpleContainer & Actor::getHandContainer(){
|
||||
//ScriptHandContainerComponent::hasComponent actor
|
||||
|
@ -177,7 +177,7 @@ std::unique_ptr<CompoundTag> getPlayerOriginTag(Player& player) {
|
||||
// return MinecraftCommands::_runcmd(std::move(origin), cmd);
|
||||
// }
|
||||
|
||||
// std::unordered_map<CommandOrigin const*, string*> resultOfOrigin = {};
|
||||
std::unordered_map<CommandOrigin const*, string*> resultOfOrigin = {};
|
||||
|
||||
// std::pair<bool, string> Level::executeCommandEx(const string& cmd) {
|
||||
// auto origin = ::ServerCommandOrigin::load(getServerOriginTag(), *Global<ServerLevel>);
|
||||
|
@ -1,383 +1,383 @@
|
||||
//#include <filesystem>
|
||||
//#include <EventAPI.h>
|
||||
//#include <LLAPI.h>
|
||||
//#include <ServerAPI.h>
|
||||
//#include <RegCommandAPI.h>
|
||||
//#include <MC/CommandOrigin.hpp>
|
||||
//#include <MC/CommandOutput.hpp>
|
||||
//#include <MC/CommandPosition.hpp>
|
||||
//#include <MC/CommandRegistry.hpp>
|
||||
//#include <MC/Packet.hpp>
|
||||
//#include <MC/ServerPlayer.hpp>
|
||||
//#include <MC/VanillaDimensions.hpp>
|
||||
//#include <Main/Config.h>
|
||||
//#include <Main/PluginManager.h>
|
||||
//#include "../ScriptEngine/Main/Configs.h"
|
||||
//
|
||||
//using namespace RegisterCommandHelper;
|
||||
//using namespace LL;
|
||||
//
|
||||
#include <filesystem>
|
||||
#include <EventAPI.h>
|
||||
#include <LLAPI.h>
|
||||
#include <ServerAPI.h>
|
||||
#include <RegCommandAPI.h>
|
||||
#include <MC/CommandOrigin.hpp>
|
||||
#include <MC/CommandOutput.hpp>
|
||||
#include <MC/CommandPosition.hpp>
|
||||
#include <MC/CommandRegistry.hpp>
|
||||
#include <MC/Packet.hpp>
|
||||
#include <MC/ServerPlayer.hpp>
|
||||
#include <MC/VanillaDimensions.hpp>
|
||||
#include <Main/Config.h>
|
||||
#include <Main/PluginManager.h>
|
||||
#include "../ScriptEngine/Main/Configs.h"
|
||||
|
||||
using namespace RegisterCommandHelper;
|
||||
using namespace LL;
|
||||
|
||||
//static_assert(sizeof(CommandSelector<Player>) == 200);
|
||||
//
|
||||
//class TeleportDimensionCommand : public Command {
|
||||
//
|
||||
// enum class DimensionType {
|
||||
// OverWorld,
|
||||
// Nether,
|
||||
// TheEnd,
|
||||
// } DimensionId;
|
||||
// CommandSelector<Actor> Victim;
|
||||
// CommandPosition CommandPos;
|
||||
// bool Victim_isSet = false;
|
||||
// bool CommandPos_isSet = false;
|
||||
//
|
||||
// Vec3 getTargetPos(CommandOrigin const& ori, Actor* actor) const {
|
||||
// if (CommandPos_isSet)
|
||||
// return CommandPos.getPosition(ori, {0, 0, 0});
|
||||
// auto pos = actor->getPosition();
|
||||
// Vec3 result = pos;
|
||||
// int actorDimensionId = actor->getDimensionId();
|
||||
// switch (DimensionId) {
|
||||
// case TeleportDimensionCommand::DimensionType::OverWorld:
|
||||
// if (actorDimensionId == 1)
|
||||
// result = {pos.x * 8, pos.y, pos.z * 8};
|
||||
// break;
|
||||
// case TeleportDimensionCommand::DimensionType::Nether:
|
||||
// if (actorDimensionId != 1)
|
||||
// result = {pos.x / 8, pos.y, pos.z / 8};
|
||||
// break;
|
||||
// case TeleportDimensionCommand::DimensionType::TheEnd:
|
||||
// if (actorDimensionId != 2)
|
||||
// result = {100, 50, 0};
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// bool teleportTarget(CommandOrigin const& ori, CommandOutput& output, Actor* actor) const {
|
||||
// auto dim = VanillaDimensions::toString((int)DimensionId);
|
||||
// auto pos = getTargetPos(ori, actor);
|
||||
// actor->teleport(pos, (int)DimensionId);
|
||||
// output.trSuccess("ll.cmd.tpdim.success", actor->getNameTag(), dim, pos.x, pos.y, pos.z);
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// bool teleportTargets(CommandOrigin const& ori, CommandOutput& output, CommandSelectorResults<Actor>& actors) const {
|
||||
// auto dim = VanillaDimensions::toString((int)DimensionId);
|
||||
// std::string names;
|
||||
// for (auto& actor : actors) {
|
||||
// std::string actorName = actor->getNameTag();
|
||||
// if (actorName.empty()) {
|
||||
// actorName = actor->getTypeName();
|
||||
// }
|
||||
// names.append(", ").append(actorName);
|
||||
// if (actor->teleport(getTargetPos(ori, actor), (int)DimensionId)) {
|
||||
// output.success();
|
||||
// }
|
||||
// }
|
||||
// if (output.getSuccessCount() == 0) {
|
||||
// output.trError("ll.cmd.tpdim.error.noActorTeleported");
|
||||
// return false;
|
||||
// } else {
|
||||
// std::string message = fmt::format("Teleported {} to {}", names.substr(2), dim);
|
||||
// if (CommandPos_isSet) {
|
||||
// auto pos = CommandPos.getPosition(ori, {0, 0, 0});
|
||||
// message.append(fmt::format(" ({:2f}, {:2f}, {:2f})", pos.x, pos.y, pos.z));
|
||||
// }
|
||||
// output.addMessage(message);
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//public:
|
||||
// void execute(CommandOrigin const& ori, CommandOutput& output) const override {
|
||||
// output.setLanguageCode(ori);
|
||||
// if ((int)DimensionId < 0 || (int)DimensionId > 2) {
|
||||
// output.trError("ll.cmd.tpdim.invalidDimid", (int)DimensionId);
|
||||
// return;
|
||||
// }
|
||||
// if (Victim_isSet) {
|
||||
// auto result = Victim.results(ori);
|
||||
// if (result.empty())
|
||||
// output.trError("ll.cmd.tpdim.error.noActorSpecified");
|
||||
// else if (result.count() == 1)
|
||||
// teleportTarget(ori, output, *result.begin());
|
||||
// else
|
||||
// teleportTargets(ori, output, result);
|
||||
// } else {
|
||||
// auto actor = ori.getEntity();
|
||||
// if (!actor)
|
||||
// output.trError("ll.cmd.tpdim.error.noActorSpecified");
|
||||
// else
|
||||
// teleportTarget(ori, output, actor);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static void setup(CommandRegistry* registry) {
|
||||
// registry->registerCommand(
|
||||
// "tpdim", "Teleport to Dimension", CommandPermissionLevel::GameMasters,
|
||||
// {(CommandFlagValue)0}, {(CommandFlagValue)0x80});
|
||||
// registry->addEnum<DimensionType>("DimensionType",
|
||||
// {
|
||||
// {"overworld", DimensionType::OverWorld},
|
||||
// {"o", DimensionType::OverWorld},
|
||||
// {"nether", DimensionType::Nether},
|
||||
// {"n", DimensionType::Nether},
|
||||
// {"end", DimensionType::TheEnd},
|
||||
// {"e", DimensionType::TheEnd},
|
||||
// });
|
||||
// auto dimensionTypeParam = makeMandatory<CommandParameterDataType::ENUM>(&TeleportDimensionCommand::DimensionId,
|
||||
// "Dimension", "DimensionType");
|
||||
// auto dimensionIdParam = makeMandatory((int TeleportDimensionCommand::*)&TeleportDimensionCommand::DimensionId,
|
||||
// "DimensionId");
|
||||
// auto victimParam = makeMandatory(&TeleportDimensionCommand::Victim, "victim",
|
||||
// &TeleportDimensionCommand::Victim_isSet);
|
||||
// auto positionParam = makeOptional(&TeleportDimensionCommand::CommandPos,
|
||||
// "Position", &TeleportDimensionCommand::CommandPos_isSet);
|
||||
//
|
||||
// registry->registerOverload<TeleportDimensionCommand>(
|
||||
// "tpdim", victimParam, dimensionTypeParam, positionParam);
|
||||
// registry->registerOverload<TeleportDimensionCommand>(
|
||||
// "tpdim", victimParam, dimensionIdParam, positionParam);
|
||||
// // registry->registerOverload<TeleportDimensionCommand>(
|
||||
// // "tpdim", dimensionTypeParam, positionParam);
|
||||
// registry->registerOverload<TeleportDimensionCommand>(
|
||||
// "tpdim", dimensionIdParam, positionParam);
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//void LLListPluginsCommand(CommandOutput& output) {
|
||||
// auto plugins = LL::getAllPlugins();
|
||||
// output.trSuccess("ll.cmd.listPlugin.overview", plugins.size());
|
||||
//
|
||||
// std::ostringstream oss;
|
||||
// for (auto& [name, plugin] : plugins) {
|
||||
// string pluginName = name;
|
||||
// if (pluginName.find("§") == string::npos)
|
||||
// pluginName = "§b" + pluginName;
|
||||
// string desc = plugin->desc;
|
||||
// if (desc.find("§") == string::npos)
|
||||
// desc = "§7" + desc;
|
||||
//
|
||||
// auto fileName = UTF82String(std::filesystem::path(str2wstr(plugin->filePath)).filename().u8string());
|
||||
// oss << fmt::format("- {} §a[v{}] §8({})\n {}\n",
|
||||
// pluginName, plugin->version.toString(), fileName, desc);
|
||||
// }
|
||||
// output.success(oss.str() + '\n');
|
||||
// output.trAddMessage("ll.cmd.listPlugin.tip");
|
||||
//}
|
||||
//
|
||||
//void LLPluginInfoCommand(CommandOutput& output, const string& pluginName) {
|
||||
// auto plugin = LL::getPlugin(pluginName);
|
||||
// if (plugin) {
|
||||
// std::map<std::string, std::string> outs;
|
||||
// std::ostringstream oss;
|
||||
// auto fn = UTF82String(std::filesystem::path(str2wstr(plugin->filePath)).filename().u8string());
|
||||
// string pluginType = plugin->type == Plugin::PluginType::ScriptPlugin ? "Script Plugin" : "DLL Plugin";
|
||||
//
|
||||
// output.trAddMessage("ll.cmd.pluginInfo.title", pluginName);
|
||||
//
|
||||
// outs.emplace("Name", fmt::format("{} ({})", plugin->name, fn));
|
||||
// outs.emplace("Description", plugin->desc);
|
||||
// outs.emplace("Version", "v" + plugin->version.toString(true));
|
||||
// outs.emplace("Type", pluginType);
|
||||
// outs.emplace("File Path", plugin->filePath);
|
||||
// outs.merge(plugin->others);
|
||||
// size_t width = 10;
|
||||
// for (auto& [k, _] : outs)
|
||||
// width = std::max(width, k.length());
|
||||
// for (auto& [k, v] : outs) {
|
||||
// if (k != "PluginType" && k != "PluginFilePath")
|
||||
// oss << "- §l" << std::setw(width) << std::left << k << "§r: " << v << std::endl;
|
||||
// }
|
||||
// auto text = oss.str();
|
||||
// text.pop_back();
|
||||
// output.success(text, {});
|
||||
// } else {
|
||||
// output.trError("ll.cmd.pluginInfo.error.pluginNotFound", pluginName);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void LLVersionCommand(CommandOutput& output) {
|
||||
// output.trSuccess("ll.cmd.version.msg", LL::getBdsVersion(), LL::getLoaderVersionString(), LL::getServerProtocolVersion());
|
||||
//}
|
||||
//
|
||||
//void LLHelpCommand(CommandOutput& output) {
|
||||
// output.trSuccess("ll.cmd.help.msg");
|
||||
//}
|
||||
//
|
||||
//void LLLoadPluginCommand(CommandOutput& output, const string& path) {
|
||||
// // if (!LL::isDebugMode())
|
||||
// // return;
|
||||
// if (PluginManager::loadPlugin(path, true)) {
|
||||
// output.trSuccess("ll.cmd.loadPlugin.success", path);
|
||||
// } else {
|
||||
// output.trError("ll.cmd.loadPlugin.fail", path);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void LLUnloadPluginCommand(CommandOutput& output, const string& pluginName) {
|
||||
// // if (!LL::isDebugMode())
|
||||
// // return;
|
||||
// if (PluginManager::unloadPlugin(pluginName, true)) {
|
||||
// output.trSuccess("ll.cmd.unloadPlugin.success", pluginName);
|
||||
// } else {
|
||||
// output.trError("ll.cmd.unloadPlugin.fail", pluginName);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//void LLReloadPluginCommand(CommandOutput& output, const string& pluginName, bool reloadAll) {
|
||||
// // if (!LL::isDebugMode())
|
||||
// // return;
|
||||
// if (!reloadAll) {
|
||||
// if (PluginManager::reloadPlugin(pluginName, true)) {
|
||||
// output.trSuccess("ll.cmd.reloadPlugin.success", pluginName);
|
||||
// } else {
|
||||
// output.trError("ll.cmd.reloadPlugin.fail", pluginName);
|
||||
// }
|
||||
// } else {
|
||||
// int cnt = PluginManager::reloadAllPlugins(true);
|
||||
// if (cnt > 0) {
|
||||
// output.trSuccess("ll.cmd.reloadAllPlugins.success", cnt);
|
||||
// } else {
|
||||
// output.trError("ll.cmd.reloadAllPlugins.fail");
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//class LLCommand : public Command {
|
||||
//
|
||||
// enum class Operation {
|
||||
// Version,
|
||||
// List,
|
||||
// Help,
|
||||
// Load,
|
||||
// Unload,
|
||||
// Reload
|
||||
// };
|
||||
//
|
||||
// Operation operation;
|
||||
// bool hasUpgradeOption, hasPluginNameSet;
|
||||
// CommandRawText pluginNameToDoOperation;
|
||||
//
|
||||
//public:
|
||||
// void execute(CommandOrigin const& ori, CommandOutput& output) const override {
|
||||
// output.setLanguageCode(ori);
|
||||
// std::string pluginName = "";
|
||||
// if (hasPluginNameSet) {
|
||||
// pluginName = pluginNameToDoOperation;
|
||||
// if (pluginName.size() > 1 && pluginName[0] == '"' && pluginName[pluginName.size() - 1] == '"' && pluginName[pluginName.size() - 2] != '\\') {
|
||||
// pluginName.erase(0, 1);
|
||||
// pluginName.pop_back();
|
||||
// }
|
||||
// }
|
||||
// switch (operation) {
|
||||
// case Operation::Version:
|
||||
// LLVersionCommand(output);
|
||||
// break;
|
||||
// case Operation::List:
|
||||
// if (!hasPluginNameSet)
|
||||
// LLListPluginsCommand(output);
|
||||
// else
|
||||
// LLPluginInfoCommand(output, pluginName);
|
||||
// break;
|
||||
// case Operation::Load:
|
||||
// if (hasPluginNameSet)
|
||||
// LLLoadPluginCommand(output, pluginName);
|
||||
// else
|
||||
// output.trError("ll.cmd.error.noPathSpecified");
|
||||
// break;
|
||||
// case Operation::Unload:
|
||||
// if (hasPluginNameSet)
|
||||
// LLUnloadPluginCommand(output, pluginName);
|
||||
// else
|
||||
// output.trError("ll.cmd.error.noNameSpecified");
|
||||
// break;
|
||||
// case Operation::Reload:
|
||||
// if (hasPluginNameSet)
|
||||
// LLReloadPluginCommand(output, pluginName, false);
|
||||
// else
|
||||
// LLReloadPluginCommand(output, "", true);
|
||||
// break;
|
||||
// case Operation::Help:
|
||||
// LLHelpCommand(output);
|
||||
// break;
|
||||
// default:
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// static void setup(CommandRegistry* registry) {
|
||||
// // Register Cmd
|
||||
// registry->registerCommand("ll", "LiteLoaderBDS plugin operations",
|
||||
// CommandPermissionLevel::Console, {(CommandFlagValue)0}, {(CommandFlagValue)0x80});
|
||||
//
|
||||
// // Register softenum
|
||||
// vector<string> pluginList;
|
||||
// for (auto& [name, p] : LL::getAllPlugins()) {
|
||||
// pluginList.push_back(name);
|
||||
// }
|
||||
// registry->addSoftEnum("PluginName", pluginList);
|
||||
//
|
||||
// // ll version & help
|
||||
// registry->addEnum<Operation>("Operation_Common", {{"version", Operation::Version},
|
||||
// {"help", Operation::Help}});
|
||||
// registry->registerOverload<LLCommand>(
|
||||
// "ll",
|
||||
// makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_Common").addOptions((CommandParameterOption)1));
|
||||
//
|
||||
// // ll load
|
||||
// registry->addEnum<Operation>("Operation_FreeFilePath", {
|
||||
// {"load", Operation::Load},
|
||||
// });
|
||||
// registry->registerOverload<LLCommand>(
|
||||
// "ll",
|
||||
// makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_FreeFilePath").addOptions((CommandParameterOption)1),
|
||||
// makeMandatory<CommandParameterDataType::NORMAL>(&LLCommand::pluginNameToDoOperation, "pluginPath", nullptr, &LLCommand::hasPluginNameSet));
|
||||
//
|
||||
// // ll unload
|
||||
// registry->addEnum<Operation>("Operation_MustPluginName", {
|
||||
// {"unload", Operation::Unload},
|
||||
// });
|
||||
// registry->registerOverload<LLCommand>(
|
||||
// "ll",
|
||||
// makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_MustPluginName").addOptions((CommandParameterOption)1),
|
||||
// makeMandatory<CommandParameterDataType::SOFT_ENUM>((std::string LLCommand::*)&LLCommand::pluginNameToDoOperation, "pluginName", "PluginName", &LLCommand::hasPluginNameSet));
|
||||
//
|
||||
// // ll list & reload
|
||||
// registry->addEnum<Operation>("Operation_OptionalPluginName", {
|
||||
// {"list", Operation::List},
|
||||
// {"plugins", Operation::List},
|
||||
// {"reload", Operation::Reload},
|
||||
// });
|
||||
// registry->registerOverload<LLCommand>(
|
||||
// "ll",
|
||||
// makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_OptionalPluginName").addOptions((CommandParameterOption)1),
|
||||
// makeOptional<CommandParameterDataType::SOFT_ENUM>((std::string LLCommand::*)&LLCommand::pluginNameToDoOperation, "pluginName", "PluginName", &LLCommand::hasPluginNameSet));
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//class VersionCommand : public Command {
|
||||
//
|
||||
//public:
|
||||
// void execute(CommandOrigin const& ori, CommandOutput& output) const override {
|
||||
// output.setLanguageCode(ori);
|
||||
//#ifdef DEBUG
|
||||
// Logger("CommandOrigin").warn(ori.serialize().toSNBT());
|
||||
//#endif // DEBUG
|
||||
// LLVersionCommand(output);
|
||||
// }
|
||||
//
|
||||
// static void setup(CommandRegistry* registry) {
|
||||
// registry->registerCommand("version", "Get the version of this server",
|
||||
// CommandPermissionLevel::GameMasters, {(CommandFlagValue)0}, {(CommandFlagValue)0x80});
|
||||
// registry->registerOverload<VersionCommand>("version");
|
||||
// }
|
||||
//};
|
||||
//
|
||||
//void RegisterCommands() {
|
||||
|
||||
class TeleportDimensionCommand : public Command {
|
||||
|
||||
enum class DimensionType {
|
||||
OverWorld,
|
||||
Nether,
|
||||
TheEnd,
|
||||
} DimensionId;
|
||||
CommandSelector<Actor> Victim;
|
||||
CommandPosition CommandPos;
|
||||
bool Victim_isSet = false;
|
||||
bool CommandPos_isSet = false;
|
||||
|
||||
Vec3 getTargetPos(CommandOrigin const& ori, Actor* actor) const {
|
||||
if (CommandPos_isSet)
|
||||
return CommandPos.getPosition(ori, {0, 0, 0});
|
||||
auto pos = actor->getPosition();
|
||||
Vec3 result = pos;
|
||||
int actorDimensionId = actor->getDimensionId();
|
||||
switch (DimensionId) {
|
||||
case TeleportDimensionCommand::DimensionType::OverWorld:
|
||||
if (actorDimensionId == 1)
|
||||
result = {pos.x * 8, pos.y, pos.z * 8};
|
||||
break;
|
||||
case TeleportDimensionCommand::DimensionType::Nether:
|
||||
if (actorDimensionId != 1)
|
||||
result = {pos.x / 8, pos.y, pos.z / 8};
|
||||
break;
|
||||
case TeleportDimensionCommand::DimensionType::TheEnd:
|
||||
if (actorDimensionId != 2)
|
||||
result = {100, 50, 0};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool teleportTarget(CommandOrigin const& ori, CommandOutput& output, Actor* actor) const {
|
||||
auto dim = VanillaDimensions::toString((int)DimensionId);
|
||||
auto pos = getTargetPos(ori, actor);
|
||||
actor->teleport(pos, (int)DimensionId);
|
||||
output.trSuccess("ll.cmd.tpdim.success", actor->getNameTag(), dim, pos.x, pos.y, pos.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool teleportTargets(CommandOrigin const& ori, CommandOutput& output, CommandSelectorResults<Actor>& actors) const {
|
||||
auto dim = VanillaDimensions::toString((int)DimensionId);
|
||||
std::string names;
|
||||
for (auto& actor : actors) {
|
||||
std::string actorName = actor->getNameTag();
|
||||
if (actorName.empty()) {
|
||||
actorName = actor->getTypeName();
|
||||
}
|
||||
names.append(", ").append(actorName);
|
||||
if (actor->teleport(getTargetPos(ori, actor), (int)DimensionId)) {
|
||||
output.success();
|
||||
}
|
||||
}
|
||||
if (output.getSuccessCount() == 0) {
|
||||
output.trError("ll.cmd.tpdim.error.noActorTeleported");
|
||||
return false;
|
||||
} else {
|
||||
std::string message = fmt::format("Teleported {} to {}", names.substr(2), dim);
|
||||
if (CommandPos_isSet) {
|
||||
auto pos = CommandPos.getPosition(ori, {0, 0, 0});
|
||||
message.append(fmt::format(" ({:2f}, {:2f}, {:2f})", pos.x, pos.y, pos.z));
|
||||
}
|
||||
output.addMessage(message);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
void execute(CommandOrigin const& ori, CommandOutput& output) const override {
|
||||
output.setLanguageCode(ori);
|
||||
if ((int)DimensionId < 0 || (int)DimensionId > 2) {
|
||||
output.trError("ll.cmd.tpdim.invalidDimid", (int)DimensionId);
|
||||
return;
|
||||
}
|
||||
if (Victim_isSet) {
|
||||
auto result = Victim.results(ori);
|
||||
if (result.empty())
|
||||
output.trError("ll.cmd.tpdim.error.noActorSpecified");
|
||||
else if (result.count() == 1)
|
||||
teleportTarget(ori, output, *result.begin());
|
||||
else
|
||||
teleportTargets(ori, output, result);
|
||||
} else {
|
||||
auto actor = ori.getEntity();
|
||||
if (!actor)
|
||||
output.trError("ll.cmd.tpdim.error.noActorSpecified");
|
||||
else
|
||||
teleportTarget(ori, output, actor);
|
||||
}
|
||||
}
|
||||
|
||||
static void setup(CommandRegistry* registry) {
|
||||
registry->registerCommand(
|
||||
"tpdim", "Teleport to Dimension", CommandPermissionLevel::GameMasters,
|
||||
{(CommandFlagValue)0}, {(CommandFlagValue)0x80});
|
||||
registry->addEnum<DimensionType>("DimensionType",
|
||||
{
|
||||
{"overworld", DimensionType::OverWorld},
|
||||
{"o", DimensionType::OverWorld},
|
||||
{"nether", DimensionType::Nether},
|
||||
{"n", DimensionType::Nether},
|
||||
{"end", DimensionType::TheEnd},
|
||||
{"e", DimensionType::TheEnd},
|
||||
});
|
||||
auto dimensionTypeParam = makeMandatory<CommandParameterDataType::ENUM>(&TeleportDimensionCommand::DimensionId,
|
||||
"Dimension", "DimensionType");
|
||||
auto dimensionIdParam = makeMandatory((int TeleportDimensionCommand::*)&TeleportDimensionCommand::DimensionId,
|
||||
"DimensionId");
|
||||
auto victimParam = makeMandatory(&TeleportDimensionCommand::Victim, "victim",
|
||||
&TeleportDimensionCommand::Victim_isSet);
|
||||
auto positionParam = makeOptional(&TeleportDimensionCommand::CommandPos,
|
||||
"Position", &TeleportDimensionCommand::CommandPos_isSet);
|
||||
|
||||
registry->registerOverload<TeleportDimensionCommand>(
|
||||
"tpdim", victimParam, dimensionTypeParam, positionParam);
|
||||
registry->registerOverload<TeleportDimensionCommand>(
|
||||
"tpdim", victimParam, dimensionIdParam, positionParam);
|
||||
// registry->registerOverload<TeleportDimensionCommand>(
|
||||
// "tpdim", dimensionTypeParam, positionParam);
|
||||
registry->registerOverload<TeleportDimensionCommand>(
|
||||
"tpdim", dimensionIdParam, positionParam);
|
||||
}
|
||||
};
|
||||
|
||||
void LLListPluginsCommand(CommandOutput& output) {
|
||||
auto plugins = LL::getAllPlugins();
|
||||
output.trSuccess("ll.cmd.listPlugin.overview", plugins.size());
|
||||
|
||||
std::ostringstream oss;
|
||||
for (auto& [name, plugin] : plugins) {
|
||||
string pluginName = name;
|
||||
if (pluginName.find("§") == string::npos)
|
||||
pluginName = "§b" + pluginName;
|
||||
string desc = plugin->desc;
|
||||
if (desc.find("§") == string::npos)
|
||||
desc = "§7" + desc;
|
||||
|
||||
auto fileName = UTF82String(std::filesystem::path(str2wstr(plugin->filePath)).filename().u8string());
|
||||
oss << fmt::format("- {} §a[v{}] §8({})\n {}\n",
|
||||
pluginName, plugin->version.toString(), fileName, desc);
|
||||
}
|
||||
output.success(oss.str() + '\n');
|
||||
output.trAddMessage("ll.cmd.listPlugin.tip");
|
||||
}
|
||||
|
||||
void LLPluginInfoCommand(CommandOutput& output, const string& pluginName) {
|
||||
auto plugin = LL::getPlugin(pluginName);
|
||||
if (plugin) {
|
||||
std::map<std::string, std::string> outs;
|
||||
std::ostringstream oss;
|
||||
auto fn = UTF82String(std::filesystem::path(str2wstr(plugin->filePath)).filename().u8string());
|
||||
string pluginType = plugin->type == Plugin::PluginType::ScriptPlugin ? "Script Plugin" : "DLL Plugin";
|
||||
|
||||
output.trAddMessage("ll.cmd.pluginInfo.title", pluginName);
|
||||
|
||||
outs.emplace("Name", fmt::format("{} ({})", plugin->name, fn));
|
||||
outs.emplace("Description", plugin->desc);
|
||||
outs.emplace("Version", "v" + plugin->version.toString(true));
|
||||
outs.emplace("Type", pluginType);
|
||||
outs.emplace("File Path", plugin->filePath);
|
||||
outs.merge(plugin->others);
|
||||
size_t width = 10;
|
||||
for (auto& [k, _] : outs)
|
||||
width = std::max(width, k.length());
|
||||
for (auto& [k, v] : outs) {
|
||||
if (k != "PluginType" && k != "PluginFilePath")
|
||||
oss << "- §l" << std::setw(width) << std::left << k << "§r: " << v << std::endl;
|
||||
}
|
||||
auto text = oss.str();
|
||||
text.pop_back();
|
||||
output.success(text, {});
|
||||
} else {
|
||||
output.trError("ll.cmd.pluginInfo.error.pluginNotFound", pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
void LLVersionCommand(CommandOutput& output) {
|
||||
output.trSuccess("ll.cmd.version.msg", LL::getBdsVersion(), LL::getLoaderVersionString(), LL::getServerProtocolVersion());
|
||||
}
|
||||
|
||||
void LLHelpCommand(CommandOutput& output) {
|
||||
output.trSuccess("ll.cmd.help.msg");
|
||||
}
|
||||
|
||||
void LLLoadPluginCommand(CommandOutput& output, const string& path) {
|
||||
// if (!LL::isDebugMode())
|
||||
// return;
|
||||
if (PluginManager::loadPlugin(path, true)) {
|
||||
output.trSuccess("ll.cmd.loadPlugin.success", path);
|
||||
} else {
|
||||
output.trError("ll.cmd.loadPlugin.fail", path);
|
||||
}
|
||||
}
|
||||
|
||||
void LLUnloadPluginCommand(CommandOutput& output, const string& pluginName) {
|
||||
// if (!LL::isDebugMode())
|
||||
// return;
|
||||
if (PluginManager::unloadPlugin(pluginName, true)) {
|
||||
output.trSuccess("ll.cmd.unloadPlugin.success", pluginName);
|
||||
} else {
|
||||
output.trError("ll.cmd.unloadPlugin.fail", pluginName);
|
||||
}
|
||||
}
|
||||
|
||||
void LLReloadPluginCommand(CommandOutput& output, const string& pluginName, bool reloadAll) {
|
||||
// if (!LL::isDebugMode())
|
||||
// return;
|
||||
if (!reloadAll) {
|
||||
if (PluginManager::reloadPlugin(pluginName, true)) {
|
||||
output.trSuccess("ll.cmd.reloadPlugin.success", pluginName);
|
||||
} else {
|
||||
output.trError("ll.cmd.reloadPlugin.fail", pluginName);
|
||||
}
|
||||
} else {
|
||||
int cnt = PluginManager::reloadAllPlugins(true);
|
||||
if (cnt > 0) {
|
||||
output.trSuccess("ll.cmd.reloadAllPlugins.success", cnt);
|
||||
} else {
|
||||
output.trError("ll.cmd.reloadAllPlugins.fail");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LLCommand : public Command {
|
||||
|
||||
enum class Operation {
|
||||
Version,
|
||||
List,
|
||||
Help,
|
||||
Load,
|
||||
Unload,
|
||||
Reload
|
||||
};
|
||||
|
||||
Operation operation;
|
||||
bool hasUpgradeOption, hasPluginNameSet;
|
||||
CommandRawText pluginNameToDoOperation;
|
||||
|
||||
public:
|
||||
void execute(CommandOrigin const& ori, CommandOutput& output) const override {
|
||||
output.setLanguageCode(ori);
|
||||
std::string pluginName = "";
|
||||
if (hasPluginNameSet) {
|
||||
pluginName = pluginNameToDoOperation;
|
||||
if (pluginName.size() > 1 && pluginName[0] == '"' && pluginName[pluginName.size() - 1] == '"' && pluginName[pluginName.size() - 2] != '\\') {
|
||||
pluginName.erase(0, 1);
|
||||
pluginName.pop_back();
|
||||
}
|
||||
}
|
||||
switch (operation) {
|
||||
case Operation::Version:
|
||||
LLVersionCommand(output);
|
||||
break;
|
||||
case Operation::List:
|
||||
if (!hasPluginNameSet)
|
||||
LLListPluginsCommand(output);
|
||||
else
|
||||
LLPluginInfoCommand(output, pluginName);
|
||||
break;
|
||||
case Operation::Load:
|
||||
if (hasPluginNameSet)
|
||||
LLLoadPluginCommand(output, pluginName);
|
||||
else
|
||||
output.trError("ll.cmd.error.noPathSpecified");
|
||||
break;
|
||||
case Operation::Unload:
|
||||
if (hasPluginNameSet)
|
||||
LLUnloadPluginCommand(output, pluginName);
|
||||
else
|
||||
output.trError("ll.cmd.error.noNameSpecified");
|
||||
break;
|
||||
case Operation::Reload:
|
||||
if (hasPluginNameSet)
|
||||
LLReloadPluginCommand(output, pluginName, false);
|
||||
else
|
||||
LLReloadPluginCommand(output, "", true);
|
||||
break;
|
||||
case Operation::Help:
|
||||
LLHelpCommand(output);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void setup(CommandRegistry* registry) {
|
||||
// Register Cmd
|
||||
registry->registerCommand("ll", "LiteLoaderBDS plugin operations",
|
||||
CommandPermissionLevel::Console, {(CommandFlagValue)0}, {(CommandFlagValue)0x80});
|
||||
|
||||
// Register softenum
|
||||
vector<string> pluginList;
|
||||
for (auto& [name, p] : LL::getAllPlugins()) {
|
||||
pluginList.push_back(name);
|
||||
}
|
||||
registry->addSoftEnum("PluginName", pluginList);
|
||||
|
||||
// ll version & help
|
||||
registry->addEnum<Operation>("Operation_Common", {{"version", Operation::Version},
|
||||
{"help", Operation::Help}});
|
||||
registry->registerOverload<LLCommand>(
|
||||
"ll",
|
||||
makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_Common").addOptions((CommandParameterOption)1));
|
||||
|
||||
// ll load
|
||||
registry->addEnum<Operation>("Operation_FreeFilePath", {
|
||||
{"load", Operation::Load},
|
||||
});
|
||||
registry->registerOverload<LLCommand>(
|
||||
"ll",
|
||||
makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_FreeFilePath").addOptions((CommandParameterOption)1),
|
||||
makeMandatory<CommandParameterDataType::NORMAL>(&LLCommand::pluginNameToDoOperation, "pluginPath", nullptr, &LLCommand::hasPluginNameSet));
|
||||
|
||||
// ll unload
|
||||
registry->addEnum<Operation>("Operation_MustPluginName", {
|
||||
{"unload", Operation::Unload},
|
||||
});
|
||||
registry->registerOverload<LLCommand>(
|
||||
"ll",
|
||||
makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_MustPluginName").addOptions((CommandParameterOption)1),
|
||||
makeMandatory<CommandParameterDataType::SOFT_ENUM>((std::string LLCommand::*)&LLCommand::pluginNameToDoOperation, "pluginName", "PluginName", &LLCommand::hasPluginNameSet));
|
||||
|
||||
// ll list & reload
|
||||
registry->addEnum<Operation>("Operation_OptionalPluginName", {
|
||||
{"list", Operation::List},
|
||||
{"plugins", Operation::List},
|
||||
{"reload", Operation::Reload},
|
||||
});
|
||||
registry->registerOverload<LLCommand>(
|
||||
"ll",
|
||||
makeMandatory<CommandParameterDataType::ENUM>(&LLCommand::operation, "Operation", "Operation_OptionalPluginName").addOptions((CommandParameterOption)1),
|
||||
makeOptional<CommandParameterDataType::SOFT_ENUM>((std::string LLCommand::*)&LLCommand::pluginNameToDoOperation, "pluginName", "PluginName", &LLCommand::hasPluginNameSet));
|
||||
}
|
||||
};
|
||||
|
||||
class VersionCommand : public Command {
|
||||
|
||||
public:
|
||||
void execute(CommandOrigin const& ori, CommandOutput& output) const override {
|
||||
output.setLanguageCode(ori);
|
||||
#ifdef DEBUG
|
||||
Logger("CommandOrigin").warn(ori.serialize().toSNBT());
|
||||
#endif // DEBUG
|
||||
LLVersionCommand(output);
|
||||
}
|
||||
|
||||
static void setup(CommandRegistry* registry) {
|
||||
registry->registerCommand("version", "Get the version of this server",
|
||||
CommandPermissionLevel::GameMasters, {(CommandFlagValue)0}, {(CommandFlagValue)0x80});
|
||||
registry->registerOverload<VersionCommand>("version");
|
||||
}
|
||||
};
|
||||
|
||||
void RegisterCommands() {
|
||||
// Event::RegCmdEvent::subscribe([](Event::RegCmdEvent ev) { // Register commands
|
||||
// LLCommand::setup(ev.mCommandRegistry);
|
||||
// VersionCommand::setup(ev.mCommandRegistry);
|
||||
@ -386,4 +386,4 @@
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
//}
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
//#include "Global.h"
|
||||
//#include <Main/Config.h>
|
||||
//#include <MC/CommandParameterData.hpp>
|
||||
//#include <LoggerAPI.h>
|
||||
///////////////////// Built in UnlockCmd ///////////////////
|
||||
//
|
||||
//bool isUnlockCmdEnabled = true;
|
||||
//
|
||||
//// ==> LiteLoader/Main/SimpleServerLogger.cpp
|
||||
//void LogCommandRegistration(std::string const& name, char const* description, enum CommandPermissionLevel perm, short flag1, short flag2);
|
||||
//
|
||||
//TInstanceHook(void, "?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDW4CommandPermissionLevel@@UCommandFlag@@3@Z",
|
||||
// CommandRegistry, std::string const& name, char const* description, enum CommandPermissionLevel perm, short flag1, short flag2) {
|
||||
// // For #643
|
||||
// if (name.find(' ') == std::string::npos) { // If no space inside
|
||||
// // Check whether command is already exists before registering
|
||||
// if (this->findCommand(name)) {
|
||||
// // throw to prevent setup function, then this exception can be caught by event handler
|
||||
// throw std::runtime_error("There is already a command named " + name);
|
||||
// }
|
||||
// }
|
||||
// if (LL::globalConfig.enableUnlockCmd) {
|
||||
// flag1 |= 0x80;
|
||||
// }
|
||||
// if (LL::globalConfig.debugMode) {
|
||||
// LogCommandRegistration(name, description, perm, flag1, flag2);
|
||||
// }
|
||||
// return original(this, name, description, perm, flag1, flag2);
|
||||
//}
|
||||
//
|
||||
//class CommandSelectorBase;
|
||||
//class CommandOrigin;
|
||||
#include "Global.h"
|
||||
#include <Main/Config.h>
|
||||
#include <MC/CommandParameterData.hpp>
|
||||
#include <LoggerAPI.h>
|
||||
/////////////////// Built in UnlockCmd ///////////////////
|
||||
|
||||
bool isUnlockCmdEnabled = true;
|
||||
|
||||
// ==> LiteLoader/Main/SimpleServerLogger.cpp
|
||||
void LogCommandRegistration(std::string const& name, char const* description, enum CommandPermissionLevel perm, short flag1, short flag2);
|
||||
|
||||
TInstanceHook(void, "?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBDW4CommandPermissionLevel@@UCommandFlag@@3@Z",
|
||||
CommandRegistry, std::string const& name, char const* description, enum CommandPermissionLevel perm, short flag1, short flag2) {
|
||||
// For #643
|
||||
if (name.find(' ') == std::string::npos) { // If no space inside
|
||||
// Check whether command is already exists before registering
|
||||
if (this->findCommand(name)) {
|
||||
// throw to prevent setup function, then this exception can be caught by event handler
|
||||
throw std::runtime_error("There is already a command named " + name);
|
||||
}
|
||||
}
|
||||
if (LL::globalConfig.enableUnlockCmd) {
|
||||
flag1 |= 0x80;
|
||||
}
|
||||
if (LL::globalConfig.debugMode) {
|
||||
LogCommandRegistration(name, description, perm, flag1, flag2);
|
||||
}
|
||||
return original(this, name, description, perm, flag1, flag2);
|
||||
}
|
||||
|
||||
class CommandSelectorBase;
|
||||
class CommandOrigin;
|
||||
//TClasslessInstanceHook(bool, "?isExpansionAllowed@CommandSelectorBase@@AEBA_NAEBVCommandOrigin@@@Z",
|
||||
// CommandOrigin* a2) {
|
||||
// if (LL::globalConfig.enableUnlockCmd) {
|
||||
@ -38,65 +38,65 @@
|
||||
// }
|
||||
// return original(this, a2);
|
||||
//}
|
||||
//
|
||||
////#include <MC/AllowListCommand.hpp>
|
||||
////#include <MC/CommandVersion.hpp>
|
||||
////#include <MC/CommandRegistry.hpp>
|
||||
////#include <MC/CommandParameterData.hpp>
|
||||
//// inline void tryChangeStringToRawText(CommandParameterData& data)
|
||||
////{
|
||||
//// if (false /* config.xxxx*/ && data.tid.value == type_id<CommandRegistry, std::string>().value)
|
||||
//// {
|
||||
//// data.tid = type_id<CommandRegistry, CommandRawText>();
|
||||
//// data.parser = CommandRegistry::getParseFn<CommandRawText>();
|
||||
//// }
|
||||
////}
|
||||
////// allowlist
|
||||
//// TInstanceHook(CommandRegistry::Overload*, "??$_registerOverload@VAllowListCommand@@VCommandParameterData@@V2@@CommandRegistry@@AEAAPEAUOverload@0@PEBDVCommandVersion@@AEBVCommandParameterData@@2@Z",
|
||||
//// CommandRegistry, char const* unk, class CommandVersion version, class CommandParameterData const& operationParam, class CommandParameterData& nameParam)
|
||||
////{
|
||||
//// tryChangeStringToRawText(nameParam);
|
||||
//// return original(this, unk, version, operationParam, nameParam);
|
||||
//// }
|
||||
////// op
|
||||
//// TInstanceHook(CommandRegistry::Overload*, "??$_registerOverload@VOpCommand@@VCommandParameterData@@@CommandRegistry@@AEAAPEAUOverload@0@PEBDVCommandVersion@@AEBVCommandParameterData@@@Z",
|
||||
//// CommandRegistry, char const* unk, class CommandVersion version, class CommandParameterData& nameParam)
|
||||
////{
|
||||
//// tryChangeStringToRawText(nameParam);
|
||||
//// return original(this, unk, version, nameParam);
|
||||
//// }
|
||||
////// deop
|
||||
//// TInstanceHook(CommandRegistry::Overload*, "??$_registerOverload@VDeOpCommand@@VCommandParameterData@@@CommandRegistry@@AEAAPEAUOverload@0@PEBDVCommandVersion@@AEBVCommandParameterData@@@Z",
|
||||
//// CommandRegistry, char const* unk, class CommandVersion version, class CommandParameterData& nameParam)
|
||||
////{
|
||||
//// tryChangeStringToRawText(nameParam);
|
||||
//// return original(this, unk, version, nameParam);
|
||||
//// }
|
||||
//// bool unlockNewExecute = true;
|
||||
//// TClasslessInstanceHook(bool, "?isEnabled@FeatureToggles@@QEBA_NW4FeatureOptionID@@@Z",
|
||||
//// int feature)
|
||||
//// {
|
||||
//// if (feature == 54 && unlockNewExecute)
|
||||
//// return true;
|
||||
//// return original(this, feature);
|
||||
//// }
|
||||
//// TClasslessInstanceHook(void, "?addSemanticConstraint@CommandRegistry@@AEAAXW4SemanticConstraint@@@Z",
|
||||
//// enum SemanticConstraint)
|
||||
////{
|
||||
//// return;
|
||||
//// }
|
||||
//TClasslessInstanceHook(void, "?addEnumValueConstraints@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@W4SemanticConstraint@@@Z",
|
||||
// std::string const& enumName, std::vector<std::string> const& enumValues, SemanticConstraint constraint) {
|
||||
// if (!LL::globalConfig.enableUnlockCmd)
|
||||
// return original(this, enumName, enumValues, constraint);
|
||||
// if (constraint & SemanticConstraint::RequiresCheatsEnabled) {
|
||||
// constraint = (SemanticConstraint)(constraint & (~SemanticConstraint::RequiresCheatsEnabled));
|
||||
// constraint = (SemanticConstraint)(constraint | SemanticConstraint::RequiresElevatedPermissions);
|
||||
|
||||
//#include <MC/AllowListCommand.hpp>
|
||||
//#include <MC/CommandVersion.hpp>
|
||||
//#include <MC/CommandRegistry.hpp>
|
||||
//#include <MC/CommandParameterData.hpp>
|
||||
// inline void tryChangeStringToRawText(CommandParameterData& data)
|
||||
//{
|
||||
// if (false /* config.xxxx*/ && data.tid.value == type_id<CommandRegistry, std::string>().value)
|
||||
// {
|
||||
// data.tid = type_id<CommandRegistry, CommandRawText>();
|
||||
// data.parser = CommandRegistry::getParseFn<CommandRawText>();
|
||||
// }
|
||||
// // if (constraint & SemanticConstraint::RequiresHostPermissions)
|
||||
// //{
|
||||
// // constraint = (SemanticConstraint)(constraint & (~SemanticConstraint::RequiresHostPermissions));
|
||||
// // constraint = (SemanticConstraint)(constraint | SemanticConstraint::RequiresElevatedPermissions);
|
||||
// // }
|
||||
// return original(this, enumName, enumValues, constraint);
|
||||
//}
|
||||
//}
|
||||
//// allowlist
|
||||
// TInstanceHook(CommandRegistry::Overload*, "??$_registerOverload@VAllowListCommand@@VCommandParameterData@@V2@@CommandRegistry@@AEAAPEAUOverload@0@PEBDVCommandVersion@@AEBVCommandParameterData@@2@Z",
|
||||
// CommandRegistry, char const* unk, class CommandVersion version, class CommandParameterData const& operationParam, class CommandParameterData& nameParam)
|
||||
//{
|
||||
// tryChangeStringToRawText(nameParam);
|
||||
// return original(this, unk, version, operationParam, nameParam);
|
||||
// }
|
||||
//// op
|
||||
// TInstanceHook(CommandRegistry::Overload*, "??$_registerOverload@VOpCommand@@VCommandParameterData@@@CommandRegistry@@AEAAPEAUOverload@0@PEBDVCommandVersion@@AEBVCommandParameterData@@@Z",
|
||||
// CommandRegistry, char const* unk, class CommandVersion version, class CommandParameterData& nameParam)
|
||||
//{
|
||||
// tryChangeStringToRawText(nameParam);
|
||||
// return original(this, unk, version, nameParam);
|
||||
// }
|
||||
//// deop
|
||||
// TInstanceHook(CommandRegistry::Overload*, "??$_registerOverload@VDeOpCommand@@VCommandParameterData@@@CommandRegistry@@AEAAPEAUOverload@0@PEBDVCommandVersion@@AEBVCommandParameterData@@@Z",
|
||||
// CommandRegistry, char const* unk, class CommandVersion version, class CommandParameterData& nameParam)
|
||||
//{
|
||||
// tryChangeStringToRawText(nameParam);
|
||||
// return original(this, unk, version, nameParam);
|
||||
// }
|
||||
// bool unlockNewExecute = true;
|
||||
// TClasslessInstanceHook(bool, "?isEnabled@FeatureToggles@@QEBA_NW4FeatureOptionID@@@Z",
|
||||
// int feature)
|
||||
// {
|
||||
// if (feature == 54 && unlockNewExecute)
|
||||
// return true;
|
||||
// return original(this, feature);
|
||||
// }
|
||||
// TClasslessInstanceHook(void, "?addSemanticConstraint@CommandRegistry@@AEAAXW4SemanticConstraint@@@Z",
|
||||
// enum SemanticConstraint)
|
||||
//{
|
||||
// return;
|
||||
// }
|
||||
TClasslessInstanceHook(void, "?addEnumValueConstraints@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@W4SemanticConstraint@@@Z",
|
||||
std::string const& enumName, std::vector<std::string> const& enumValues, SemanticConstraint constraint) {
|
||||
if (!LL::globalConfig.enableUnlockCmd)
|
||||
return original(this, enumName, enumValues, constraint);
|
||||
if (constraint & SemanticConstraint::RequiresCheatsEnabled) {
|
||||
constraint = (SemanticConstraint)(constraint & (~SemanticConstraint::RequiresCheatsEnabled));
|
||||
constraint = (SemanticConstraint)(constraint | SemanticConstraint::RequiresElevatedPermissions);
|
||||
}
|
||||
// if (constraint & SemanticConstraint::RequiresHostPermissions)
|
||||
//{
|
||||
// constraint = (SemanticConstraint)(constraint & (~SemanticConstraint::RequiresHostPermissions));
|
||||
// constraint = (SemanticConstraint)(constraint | SemanticConstraint::RequiresElevatedPermissions);
|
||||
// }
|
||||
return original(this, enumName, enumValues, constraint);
|
||||
}
|
@ -253,7 +253,7 @@ void LLMain() {
|
||||
LL::LoadLLConfig();
|
||||
|
||||
//Unzip packed Node Modules
|
||||
UnzipNodeModules();
|
||||
//UnzipNodeModules();
|
||||
|
||||
//Decompress resource packs
|
||||
DecompressResourcePacks();
|
||||
@ -275,7 +275,7 @@ void LLMain() {
|
||||
FixPluginsLibDir();
|
||||
|
||||
// Check whether allowlist.json exists/is empty or not
|
||||
FixAllowList();
|
||||
//FixAllowList();
|
||||
|
||||
// Init LL Logger
|
||||
Logger::setDefaultFile("logs/LiteLoader-latest.log", false);
|
||||
@ -314,7 +314,7 @@ void LLMain() {
|
||||
LL::LoadMain();
|
||||
|
||||
// Register built-in commands
|
||||
//RegisterCommands();
|
||||
RegisterCommands();
|
||||
|
||||
// Register simple server logger
|
||||
RegisterSimpleServerLogger();
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include <Main/Loader.h>
|
||||
#include <Main/Loader.h>
|
||||
#include <windows.h>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
@ -80,50 +80,50 @@ THook(void, "?log@BedrockLog@@YAXW4LogCategory@1@V?$bitset@$02@std@@W4LogRule@1@
|
||||
return BedrockLog::log_va(a1, a2, a3, a4, a5, a6, a7, a8, va);
|
||||
}
|
||||
|
||||
//#include <MC/ColorFormat.hpp>
|
||||
//#include <MC/CommandOrigin.hpp>
|
||||
//#include <MC/CommandOutput.hpp>
|
||||
//extern std::unordered_map<CommandOrigin const*, string*> resultOfOrigin;
|
||||
//TClasslessInstanceHook(void*, "?send@CommandOutputSender@@UEAAXAEBVCommandOrigin@@AEBVCommandOutput@@@Z",
|
||||
// class CommandOrigin const& origin, class CommandOutput const& output) {
|
||||
// std::stringbuf tmpBuf;
|
||||
// auto oldBuf = std::cout.rdbuf();
|
||||
// std::cout.rdbuf(&tmpBuf);
|
||||
// auto rv = original(this, origin, output);
|
||||
// std::cout.rdbuf(oldBuf);
|
||||
// if (LL::isDebugMode() && LL::globalConfig.tickThreadId != std::this_thread::get_id()) {
|
||||
// logger.warn("The thread executing the CommandOutputSender::send is not the \"MC_SERVER\" thread");
|
||||
// logger.warn("Output: {}", tmpBuf.str());
|
||||
// }
|
||||
//
|
||||
// auto it = resultOfOrigin.find(&origin);
|
||||
// if (it != resultOfOrigin.end()) {
|
||||
// try {
|
||||
// // May crash for incomprehensible reasons
|
||||
// it->second->assign(tmpBuf.str());
|
||||
// while (it->second->size() && (it->second->back() == '\n' || it->second->back() == '\r'))
|
||||
// it->second->pop_back();
|
||||
// it->second = nullptr;
|
||||
// resultOfOrigin.erase(it);
|
||||
// return rv;
|
||||
// } catch (...) {
|
||||
// if (LL::isDebugMode()) {
|
||||
// logger.warn("Output: {}", tmpBuf.str());
|
||||
// logger.warn("size of resultOfOrigin: {}", resultOfOrigin.size());
|
||||
// }
|
||||
//#ifdef DEBUG
|
||||
// __debugbreak();
|
||||
//#endif // DEBUG
|
||||
// }
|
||||
// }
|
||||
// auto& log = output.getSuccessCount() > 0 ? serverLogger.info : serverLogger.error;
|
||||
// std::istringstream iss(tmpBuf.str());
|
||||
// string line;
|
||||
// while (getline(iss, line)) {
|
||||
// if (LL::globalConfig.colorLog)
|
||||
// log << ColorFormat::convertToConsole(line, false) << Logger::endl;
|
||||
// else
|
||||
// log << ColorFormat::removeColorCode(line) << Logger::endl;
|
||||
// }
|
||||
// return rv;
|
||||
//}
|
||||
#include <MC/ColorFormat.hpp>
|
||||
#include <MC/CommandOrigin.hpp>
|
||||
#include <MC/CommandOutput.hpp>
|
||||
extern std::unordered_map<CommandOrigin const*, string*> resultOfOrigin;
|
||||
TClasslessInstanceHook(void*, "?send@CommandOutputSender@@UEAAXAEBVCommandOrigin@@AEBVCommandOutput@@@Z",
|
||||
class CommandOrigin const& origin, class CommandOutput const& output) {
|
||||
std::stringbuf tmpBuf;
|
||||
auto oldBuf = std::cout.rdbuf();
|
||||
std::cout.rdbuf(&tmpBuf);
|
||||
auto rv = original(this, origin, output);
|
||||
std::cout.rdbuf(oldBuf);
|
||||
if (LL::isDebugMode() && LL::globalConfig.tickThreadId != std::this_thread::get_id()) {
|
||||
logger.warn("The thread executing the CommandOutputSender::send is not the \"MC_SERVER\" thread");
|
||||
logger.warn("Output: {}", tmpBuf.str());
|
||||
}
|
||||
|
||||
auto it = resultOfOrigin.find(&origin);
|
||||
if (it != resultOfOrigin.end()) {
|
||||
try {
|
||||
// May crash for incomprehensible reasons
|
||||
it->second->assign(tmpBuf.str());
|
||||
while (it->second->size() && (it->second->back() == '\n' || it->second->back() == '\r'))
|
||||
it->second->pop_back();
|
||||
it->second = nullptr;
|
||||
resultOfOrigin.erase(it);
|
||||
return rv;
|
||||
} catch (...) {
|
||||
if (LL::isDebugMode()) {
|
||||
logger.warn("Output: {}", tmpBuf.str());
|
||||
logger.warn("size of resultOfOrigin: {}", resultOfOrigin.size());
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__debugbreak();
|
||||
#endif // DEBUG
|
||||
}
|
||||
}
|
||||
auto& log = output.getSuccessCount() > 0 ? serverLogger.info : serverLogger.error;
|
||||
std::istringstream iss(tmpBuf.str());
|
||||
string line;
|
||||
while (getline(iss, line)) {
|
||||
if (LL::globalConfig.colorLog)
|
||||
log << ColorFormat::convertToConsole(line, false) << Logger::endl;
|
||||
else
|
||||
log << ColorFormat::removeColorCode(line) << Logger::endl;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -25,20 +25,20 @@ void RegisterSimpleServerLogger() {
|
||||
}
|
||||
|
||||
#include <MC/Command.hpp>
|
||||
//TInstanceHook(void, "?setPermissions@Player@@QEAAXW4CommandPermissionLevel@@@Z",
|
||||
// Player, CommandPermissionLevel perm) {
|
||||
// if (LL::globalConfig.enableSimpleServerLogger) {
|
||||
// static Logger logger("Permissions");
|
||||
// logger.info("<{}> {}({}) -> {}({})",
|
||||
// getRealName(), magic_enum::enum_name(getCommandPermissionLevel()), (int)getCommandPermissionLevel(), magic_enum::enum_name(perm), (int)perm);
|
||||
// }
|
||||
// return original(this, perm);
|
||||
//}
|
||||
TInstanceHook(void, "?setPermissions@Player@@QEAAXW4CommandPermissionLevel@@@Z",
|
||||
Player, CommandPermissionLevel perm) {
|
||||
if (LL::globalConfig.enableSimpleServerLogger) {
|
||||
static Logger logger("Permissions");
|
||||
logger.info("<{}> {}({}) -> {}({})",
|
||||
getRealName(), magic_enum::enum_name(getCommandPermissionLevel()), (int)getCommandPermissionLevel(), magic_enum::enum_name(perm), (int)perm);
|
||||
}
|
||||
return original(this, perm);
|
||||
}
|
||||
|
||||
// ==> LiteLoader/Main/BuiltinUnlockCmd.cpp
|
||||
#include <MC/I18n.hpp>
|
||||
//void LogCommandRegistration(std::string const& name, char const* description, enum CommandPermissionLevel perm, short flag1, short flag2) {
|
||||
// static Logger logger("RegsterCommand");
|
||||
// logger.consoleLevel = logger.debug.level;
|
||||
// logger.debug("{:<18} - {:<12} - {}", name, magic_enum::enum_name(perm), I18n::get(description));
|
||||
//}
|
||||
void LogCommandRegistration(std::string const& name, char const* description, enum CommandPermissionLevel perm, short flag1, short flag2) {
|
||||
static Logger logger("RegsterCommand");
|
||||
logger.consoleLevel = logger.debug.level;
|
||||
logger.debug("{:<18} - {:<12} - {}", name, magic_enum::enum_name(perm), I18n::get(description));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user