diff --git a/China/HeliumClient/Commands/Commands/BindCommand.cpp b/China/HeliumClient/Commands/Commands/BindCommand.cpp index e04c5d55ad94e589faa85f55aa94ef888b37016e..08b0b91663f4a4a715f7903f33c18b2a54d77bd5 100644 --- a/China/HeliumClient/Commands/Commands/BindCommand.cpp +++ b/China/HeliumClient/Commands/Commands/BindCommand.cpp @@ -5,7 +5,7 @@ void BindCommand_onInit(ICommand* _this) { _this->aliasList.reserve(ModuleManager::NameTable.size()); for (auto& i : ModuleManager::NameTable) - _this->aliasList.push_back_unchecked(aliasList_struct{std::u8string_view{i.first}, nullptr}); + _this->aliasList.emplace_back_unchecked(stringview_Object{std::u8string_view{i.first}, nullptr}); } diff --git a/China/HeliumClient/Commands/Commands/ConfigCommand.cpp b/China/HeliumClient/Commands/Commands/ConfigCommand.cpp index 3e9ed67f142bafd9a45d545676761ec20dddc26c..293670e32dfe98eb58e8931c1ad41b87ad18f80b 100644 --- a/China/HeliumClient/Commands/Commands/ConfigCommand.cpp +++ b/China/HeliumClient/Commands/Commands/ConfigCommand.cpp @@ -5,25 +5,14 @@ #include "../../../Memory/GameData.h" #include "../../Config/ConfigManager.h" -fast_io::vector configs_ConfigCommand{}; - -void listCommand_ConfigCommand() { - static fast_io::vector configsString{}; - configsString = ConfigManager::list(); - - configs_ConfigCommand.clear(); - configs_ConfigCommand.reserve(configsString.size()); - for (auto& i : configsString) - configs_ConfigCommand.push_back_unchecked(aliasList_struct{std::u8string_view{i}, nullptr}); -} - bool ConfigCommand_onExecute(const fast_io::vector& args) { using std::operator""sv; if (args.size() > 3 || args.size() < 2) return false; else if (args.size() == 2) { if (args[1] == u8"list"sv) { - listCommand_ConfigCommand(); + + fast_io::vector configsString{ConfigManager::list()}; C_GuiData::displayClientMessageC(Utils::TextColor::GRAY, u8"========================"); switch (SettingManager::languageget) { @@ -55,8 +44,8 @@ bool ConfigCommand_onExecute(const fast_io::vector& args) { std::unreachable(); } - for (auto& i : configs_ConfigCommand) - C_GuiData::displayClientMessageC(Utils::TextColor::GRAY, i.name); + for (auto& i : configsString) + C_GuiData::displayClientMessageC(Utils::TextColor::GRAY, i); return true; } else if (args[1] == u8"save"sv) { if (configMgr.saveConfig()) { @@ -265,8 +254,8 @@ bool ConfigCommand_onExecute(const fast_io::vector& args) { } return true; } else if (args[1] == u8"create"sv) { - listCommand_ConfigCommand(); - if (args[2] == configMgr.currentConfig || std::ranges::any_of(configs_ConfigCommand, [&args](aliasList_struct& al) { return args[2] == al.name; })) { + fast_io::vector configsString{ConfigManager::list()}; + if (args[2] == configMgr.currentConfig || std::ranges::any_of(configsString, [&args](std::u8string& al) { return args[2] == al; })) { switch (SettingManager::languageget) { case 0: default: @@ -414,8 +403,8 @@ bool ConfigCommand_onExecute(const fast_io::vector& args) { } return true; } - listCommand_ConfigCommand(); - if (std::ranges::any_of(configs_ConfigCommand, [&args](aliasList_struct& al) { return args[2] == al.name; }) && configMgr.deleteConfig(args[2])) { + fast_io::vector configsString{ConfigManager::list()}; + if (std::ranges::any_of(configsString, [&args](std::u8string& al) { return args[2] == al; }) && configMgr.deleteConfig(args[2])) { switch (SettingManager::languageget) { case 0: default: @@ -498,17 +487,29 @@ bool ConfigCommand_onExecute(const fast_io::vector& args) { return false; } +fast_io::vector configs_ConfigCommand{}; + +bool listCommand_ConfigCommand(fast_io::vector*) { + fast_io::vector configsString{ConfigManager::list()}; + + configs_ConfigCommand.clear(); + configs_ConfigCommand.reserve(configsString.size()); + for (auto& i : configsString) + configs_ConfigCommand.emplace_back_unchecked(string_Object{i, nullptr}); + return true; +} + ICommand ConfigCommand{ u8"config", u8".config [load , create , save, delete , list]", {u8"Load, Create, Save, Delete or List Configuration", u8"加载, 创建, 保存, 删除或列出配置", u8"加載, 創建, 保存, 刪除或列出配置", u8"構成の読み込み、 作成、 保存、 削除、 一覧表示"}, {}, - { - {u8"load", (void*)&configs_ConfigCommand}, - {u8"create", nullptr}, - {u8"save", nullptr}, - {u8"delete", (void*)&configs_ConfigCommand /*Place and delete by mistake, please enter manually*/}, - {u8"list", nullptr}, + fast_io::vector{ + aliasList_struct{stringview_Judge{u8"load", &configs_ConfigCommand, &listCommand_ConfigCommand}}, + aliasList_struct{stringview_Object{u8"create", nullptr}}, + aliasList_struct{stringview_Object{u8"save", nullptr}}, + aliasList_struct{stringview_Judge{u8"delete", &configs_ConfigCommand, &listCommand_ConfigCommand}}, + aliasList_struct{stringview_Judge{u8"list", nullptr, &listCommand_ConfigCommand}}, }, nullptr, &ConfigCommand_onExecute}; diff --git a/China/HeliumClient/Commands/Commands/ConfigCommand.h b/China/HeliumClient/Commands/Commands/ConfigCommand.h index bcd5174f4b5e58ee4972d9577f8d4e325b864b53..9517079f795409493284d706f2174ffce83c76ca 100644 --- a/China/HeliumClient/Commands/Commands/ConfigCommand.h +++ b/China/HeliumClient/Commands/Commands/ConfigCommand.h @@ -2,6 +2,4 @@ #include "../ICommand.h" -extern fast_io::vector configs_ConfigCommand; -extern void listCommand_ConfigCommand(); extern ICommand ConfigCommand; \ No newline at end of file diff --git a/China/HeliumClient/Commands/Commands/EjectCommand.cpp b/China/HeliumClient/Commands/Commands/EjectCommand.cpp index 0e27cdb416510fb2ffa89f5f2d4008336da1dbf6..33ef22140840052bc085861ebb234ea711540180 100644 --- a/China/HeliumClient/Commands/Commands/EjectCommand.cpp +++ b/China/HeliumClient/Commands/Commands/EjectCommand.cpp @@ -23,6 +23,6 @@ ICommand EjectCommand{u8"eject", u8".eject [advance]", {u8"eject Helium from the game.", u8"从游戏中卸载Helium。", u8"從遊戲中卸載Helium。", u8"ゲームから Helium をアンインストールします。"}, {u8"uninject"}, - {{u8"advance", nullptr}}, // If empty must use fast_io::vector{} + fast_io::vector{aliasList_struct{stringview_Object{u8"advance", nullptr}}}, // If empty must use fast_io::vector{} nullptr, &EjectCommand_onExecute}; \ No newline at end of file diff --git a/China/HeliumClient/Commands/Commands/FriendCommand.cpp b/China/HeliumClient/Commands/Commands/FriendCommand.cpp index 4352da7062d9c9e0f62f7601d6cb1bb665f7244b..a87d3e362ce384077e7f5977bd127fc75b7302ae 100644 --- a/China/HeliumClient/Commands/Commands/FriendCommand.cpp +++ b/China/HeliumClient/Commands/Commands/FriendCommand.cpp @@ -194,14 +194,25 @@ bool FriendCommand_onExecute(const fast_io::vector& args) { return true; } +bool listPlayer_FriendCommand(fast_io::vector*) { + Friend_playerList.clear(); + g_Data.forEachEntity([](C_Entity* ent) { + if (ent != g_Data.getLocalPlayer() && ent->isPlayer()) + if (auto name = ent->getNameTag()->getString(); !name.empty()) [[likely]] + Friend_playerList.emplace_back(string_Object{std::u8string{name}, nullptr}); + }); + + return true; +} + ICommand FriendCommand{u8"friend", u8".friend [add/ remove] , list", {u8"Add or remove friendly players", u8"添加或删除友好玩家", u8"添加或刪除友好玩家", u8"味方プレイヤーの追加または削除"}, {}, - { - {u8"add", (void*)&Friend_playerList}, - {u8"remove", (void*)&Friend_friendList}, - {u8"list", nullptr}, + fast_io::vector{ + aliasList_struct{stringview_Judge{u8"add", &Friend_playerList, &listPlayer_FriendCommand}}, + aliasList_struct{stringview_Judge{u8"remove", &Friend_friendList, &listPlayer_FriendCommand}}, + aliasList_struct{stringview_Judge{u8"list", nullptr, &listPlayer_FriendCommand}}, }, // If empty must use fast_io::vector{} nullptr, &FriendCommand_onExecute}; \ No newline at end of file diff --git a/China/HeliumClient/Commands/Commands/SetLanguageCommand.cpp b/China/HeliumClient/Commands/Commands/SetLanguageCommand.cpp index f24de803059f3093059d689e2eae488dd6933573..04657dba9386901a3c7a3f8fc1c1907a7ed3017a 100644 --- a/China/HeliumClient/Commands/Commands/SetLanguageCommand.cpp +++ b/China/HeliumClient/Commands/Commands/SetLanguageCommand.cpp @@ -41,18 +41,18 @@ ICommand SetLanguageCommand{u8"setlanguage", u8".setlanguage [, ]", {u8"Set Language", u8"设置语言", u8"設置語言", u8"言語を設定する"}, {}, - { - {u8"en_US", nullptr}, - {u8"zh_CN", nullptr}, - {u8"zh_HK", nullptr}, - {u8"zh_SG", nullptr}, - {u8"zh_TW", nullptr}, - {u8"zh_ZA", nullptr}, - {u8"ja_JP", nullptr}, - {u8"0", nullptr}, - {u8"1", nullptr}, - {u8"2", nullptr}, - {u8"3", nullptr}, + fast_io::vector{ + aliasList_struct{stringview_Judge{u8"en_US", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh_CN", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh_HK", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh_SG", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh_TW", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh_ZA", nullptr}}, + aliasList_struct{stringview_Judge{u8"ja_JP", nullptr}}, + aliasList_struct{stringview_Judge{u8"0", nullptr}}, + aliasList_struct{stringview_Judge{u8"1", nullptr}}, + aliasList_struct{stringview_Judge{u8"2", nullptr}}, + aliasList_struct{stringview_Judge{u8"3", nullptr}}, }, // If empty must use fast_io::vector{} nullptr, &SetLanguageCommand_onExecute}; \ No newline at end of file diff --git a/China/HeliumClient/Commands/Commands/ToggleCommand.cpp b/China/HeliumClient/Commands/Commands/ToggleCommand.cpp index 41a2f25475b470d799361da6b54763194e64c0d4..e4a75ec9dbb292b734adf10250861565cc695659 100644 --- a/China/HeliumClient/Commands/Commands/ToggleCommand.cpp +++ b/China/HeliumClient/Commands/Commands/ToggleCommand.cpp @@ -5,7 +5,7 @@ void ToggleCommand_onInit(ICommand* toggleCMD) { toggleCMD->aliasList.reserve(ModuleManager::NameTable.size()); for (auto& i : ModuleManager::NameTable) - toggleCMD->aliasList.push_back_unchecked(aliasList_struct{i.first, nullptr}); + toggleCMD->aliasList.emplace_back_unchecked(stringview_Judge{i.first, nullptr}); // NameTable已经初始化完毕,string指针不会变动 } bool ToggleCommand_onExecute(const fast_io::vector& args) { diff --git a/China/HeliumClient/Commands/Commands/TranslateCommand.cpp b/China/HeliumClient/Commands/Commands/TranslateCommand.cpp index 24a16ee1af26054b010044f56b91f63b09df1f4b..895f2050550de3064f6a0a62e475a1218c82da1e 100644 --- a/China/HeliumClient/Commands/Commands/TranslateCommand.cpp +++ b/China/HeliumClient/Commands/Commands/TranslateCommand.cpp @@ -377,80 +377,80 @@ bool TranslateCommand_onExecute(const fast_io::vector& args) { } fast_io::vector languageto{ - {u8"yue", nullptr}, - {u8"kor", nullptr}, - {u8"th", nullptr}, - {u8"pt", nullptr}, - {u8"el", nullptr}, - {u8"bul", nullptr}, - {u8"fin", nullptr}, - {u8"slo", nullptr}, - {u8"cht", nullptr}, - {u8"zh", nullptr}, - {u8"wyw", nullptr}, - {u8"fra", nullptr}, - {u8"ara", nullptr}, - {u8"de", nullptr}, - {u8"nl", nullptr}, - {u8"est", nullptr}, - {u8"cs", nullptr}, - {u8"swe", nullptr}, - {u8"vie", nullptr}, - {u8"en", nullptr}, - {u8"jp", nullptr}, - {u8"spa", nullptr}, - {u8"ru", nullptr}, - {u8"it", nullptr}, - {u8"pl", nullptr}, - {u8"dan", nullptr}, - {u8"rom", nullptr}, - {u8"hu", nullptr}}; + aliasList_struct{stringview_Judge{u8"yue", nullptr}}, + aliasList_struct{stringview_Judge{u8"kor", nullptr}}, + aliasList_struct{stringview_Judge{u8"th", nullptr}}, + aliasList_struct{stringview_Judge{u8"pt", nullptr}}, + aliasList_struct{stringview_Judge{u8"el", nullptr}}, + aliasList_struct{stringview_Judge{u8"bul", nullptr}}, + aliasList_struct{stringview_Judge{u8"fin", nullptr}}, + aliasList_struct{stringview_Judge{u8"slo", nullptr}}, + aliasList_struct{stringview_Judge{u8"cht", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh", nullptr}}, + aliasList_struct{stringview_Judge{u8"wyw", nullptr}}, + aliasList_struct{stringview_Judge{u8"fra", nullptr}}, + aliasList_struct{stringview_Judge{u8"ara", nullptr}}, + aliasList_struct{stringview_Judge{u8"de", nullptr}}, + aliasList_struct{stringview_Judge{u8"nl", nullptr}}, + aliasList_struct{stringview_Judge{u8"est", nullptr}}, + aliasList_struct{stringview_Judge{u8"cs", nullptr}}, + aliasList_struct{stringview_Judge{u8"swe", nullptr}}, + aliasList_struct{stringview_Judge{u8"vie", nullptr}}, + aliasList_struct{stringview_Judge{u8"en", nullptr}}, + aliasList_struct{stringview_Judge{u8"jp", nullptr}}, + aliasList_struct{stringview_Judge{u8"spa", nullptr}}, + aliasList_struct{stringview_Judge{u8"ru", nullptr}}, + aliasList_struct{stringview_Judge{u8"it", nullptr}}, + aliasList_struct{stringview_Judge{u8"pl", nullptr}}, + aliasList_struct{stringview_Judge{u8"dan", nullptr}}, + aliasList_struct{stringview_Judge{u8"rom", nullptr}}, + aliasList_struct{stringview_Judge{u8"hu", nullptr}}}; fast_io::vector languagefrom{ - {u8"auto", &languageto}, - {u8"yue", &languageto}, - {u8"kor", &languageto}, - {u8"th", &languageto}, - {u8"pt", &languageto}, - {u8"el", &languageto}, - {u8"bul", &languageto}, - {u8"fin", &languageto}, - {u8"slo", &languageto}, - {u8"cht", &languageto}, - {u8"zh", &languageto}, - {u8"wyw", &languageto}, - {u8"fra", &languageto}, - {u8"ara", &languageto}, - {u8"de", &languageto}, - {u8"nl", &languageto}, - {u8"est", &languageto}, - {u8"cs", &languageto}, - {u8"swe", &languageto}, - {u8"vie", &languageto}, - {u8"en", &languageto}, - {u8"jp", &languageto}, - {u8"spa", &languageto}, - {u8"ru", &languageto}, - {u8"it", &languageto}, - {u8"pl", &languageto}, - {u8"dan", &languageto}, - {u8"rom", &languageto}, - {u8"hu", &languageto}}; + aliasList_struct{stringview_Judge{u8"auto", nullptr}}, + aliasList_struct{stringview_Judge{u8"yue", nullptr}}, + aliasList_struct{stringview_Judge{u8"kor", nullptr}}, + aliasList_struct{stringview_Judge{u8"th", nullptr}}, + aliasList_struct{stringview_Judge{u8"pt", nullptr}}, + aliasList_struct{stringview_Judge{u8"el", nullptr}}, + aliasList_struct{stringview_Judge{u8"bul", nullptr}}, + aliasList_struct{stringview_Judge{u8"fin", nullptr}}, + aliasList_struct{stringview_Judge{u8"slo", nullptr}}, + aliasList_struct{stringview_Judge{u8"cht", nullptr}}, + aliasList_struct{stringview_Judge{u8"zh", nullptr}}, + aliasList_struct{stringview_Judge{u8"wyw", nullptr}}, + aliasList_struct{stringview_Judge{u8"fra", nullptr}}, + aliasList_struct{stringview_Judge{u8"ara", nullptr}}, + aliasList_struct{stringview_Judge{u8"de", nullptr}}, + aliasList_struct{stringview_Judge{u8"nl", nullptr}}, + aliasList_struct{stringview_Judge{u8"est", nullptr}}, + aliasList_struct{stringview_Judge{u8"cs", nullptr}}, + aliasList_struct{stringview_Judge{u8"swe", nullptr}}, + aliasList_struct{stringview_Judge{u8"vie", nullptr}}, + aliasList_struct{stringview_Judge{u8"en", nullptr}}, + aliasList_struct{stringview_Judge{u8"jp", nullptr}}, + aliasList_struct{stringview_Judge{u8"spa", nullptr}}, + aliasList_struct{stringview_Judge{u8"ru", nullptr}}, + aliasList_struct{stringview_Judge{u8"it", nullptr}}, + aliasList_struct{stringview_Judge{u8"pl", nullptr}}, + aliasList_struct{stringview_Judge{u8"dan", nullptr}}, + aliasList_struct{stringview_Judge{u8"rom", nullptr}}, + aliasList_struct{stringview_Judge{u8"hu", nullptr}}}; fast_io::vector com{ - {u8"appid", nullptr}, - {u8"key", nullptr}, - {u8"local", &languagefrom}, - {u8"server", &languagefrom}}; + aliasList_struct{stringview_Judge{u8"appid", nullptr}}, + aliasList_struct{stringview_Judge{u8"key", nullptr}}, + aliasList_struct{stringview_Judge{u8"local", &languagefrom}}, + aliasList_struct{stringview_Judge{u8"server", &languagefrom}}}; ICommand TranslateCommand{ u8"translate", u8".translate or .transl [set [[loacl, server] , appid , key ], send , display ]", {u8"Translate with Baidu Translator", u8"使用百度翻译器翻译", u8"使用百度翻譯器翻譯", u8"Baidu Translator で翻訳する"}, {u8"transl"}, - {{u8"set", &com}, - {u8"send", nullptr}, - {u8"display", nullptr}}, // If empty must use fast_io::vector{} + fast_io::vector{aliasList_struct{stringview_Judge{u8"set", &com}}, + aliasList_struct{stringview_Judge{u8"send", nullptr}}, + aliasList_struct{stringview_Judge{u8"display", nullptr}}}, // If empty must use fast_io::vector{} nullptr, &TranslateCommand_onExecute}; diff --git a/China/HeliumClient/Commands/ICommand.h b/China/HeliumClient/Commands/ICommand.h index 4780ba5ee3d222ca598a0c2797f30f15079ff109..329bdc8a38fe9b5467798393a230f601640a9946 100644 --- a/China/HeliumClient/Commands/ICommand.h +++ b/China/HeliumClient/Commands/ICommand.h @@ -1,20 +1,413 @@ #pragma once //#include +#include #include #include #include +#include #include #include "../../Utils/Utils.h" #include "../Setting/SettingManager.h" //#include "CommandsManager.h" -struct aliasList_struct { - std::u8string_view name{}; - void* next{}; // nullptr or fast_io::vector* +namespace details { + +template +concept has_next_objects = requires(T a) { + next_objects(a, nullptr, 0); + next_complete(a); + }; + +struct auto_completion_base_impl { + virtual constexpr ~auto_completion_base_impl() = default; + virtual constexpr void* next_objects_impl(fast_io::vector* cmdlist, size_t order) const noexcept = 0; + virtual constexpr std::u8string next_complete_impl() const noexcept = 0; + virtual constexpr auto_completion_base_impl* clone() const = 0; +}; + +template +struct auto_completion_derv_impl : auto_completion_base_impl { + T t; + auto_completion_derv_impl(T&& tt) : t{std::forward(tt)} {} + virtual constexpr void* next_objects_impl(fast_io::vector* cmdlist, size_t order) const noexcept override { + return next_objects(t, cmdlist, order); + } + virtual constexpr std::u8string next_complete_impl() const noexcept override{ + return next_complete(t); + } + virtual constexpr auto_completion_base_impl* clone() const override { + return new auto_completion_derv_impl(*this); + } +}; + +} // namespace details + +class aliasList_struct { +public: + ::details::auto_completion_base_impl* ptr{}; + constexpr aliasList_struct() noexcept = default; + template + explicit constexpr aliasList_struct(T&& tt) noexcept : ptr{new ::details::auto_completion_derv_impl(std::forward(tt))} { + } + constexpr aliasList_struct(aliasList_struct const& other) : ptr{other.ptr->clone()} {} + constexpr aliasList_struct& operator=(aliasList_struct const& other) { + auto temp{other.ptr->clone()}; + delete this->ptr; + this->ptr = other.ptr; + return *this; + } + constexpr aliasList_struct(aliasList_struct&& other) noexcept : ptr{other.ptr} { + other.ptr = nullptr; + } + constexpr aliasList_struct& operator=(aliasList_struct&& other) noexcept { + delete this->ptr; + this->ptr = other.ptr; + other.ptr = nullptr; + return *this; + } + ~aliasList_struct() { + delete ptr; + } +}; + +inline constexpr void* next_objects(aliasList_struct const& p, fast_io::vector* cmdlist, size_t order) noexcept { + return p.ptr->next_objects_impl(cmdlist, order); +} + +inline constexpr std::u8string next_complete(aliasList_struct const& p) noexcept { + return p.ptr->next_complete_impl(); +} + +struct Empty_Object { + fast_io::vector* next{}; +}; + +inline constexpr void* next_objects(Empty_Object p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + return p.next; +} + +inline constexpr std::u8string next_complete(Empty_Object p) noexcept { + return std::u8string{}; +} + +struct stringview_Object { + std::u8string_view str{}; + fast_io::vector* next{}; +}; + +inline constexpr void* next_objects(stringview_Object p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + if (cmdlist->operator[](order) == p.str) + return p.next; + else + return nullptr; +} + +inline constexpr std::u8string next_complete(stringview_Object p) noexcept { + return std::u8string{p.str}; +} + +struct string_Object { + std::u8string str{}; + fast_io::vector* next{}; +}; + +inline constexpr void* next_objects(string_Object p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + if (cmdlist->operator[](order) == p.str) + return p.next; + else + return nullptr; +} + +inline constexpr std::u8string next_complete(string_Object p) noexcept { + return p.str; +} + +template +struct integral_Object { // or equal to + _Ty min{}; + _Ty max{}; + fast_io::vector* next{}; +}; + +template +inline constexpr void* next_objects(integral_Object<_Ty> p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + _Ty num{}; + try { + num = fast_io::u8to<_Ty>(cmdlist->operator[](order)); + } catch (const fast_io::error&) { + return nullptr; + } + + if (num >= p.min && num <= p.max) + return p.next; + else + return nullptr; +} + +template +inline constexpr std::u8string next_complete(integral_Object<_Ty> p) noexcept { + return fast_io::u8concat(p); +} + +template +struct floating_point_Object { // or equal to + _Ty min{}; + bool equaltomin{}; + _Ty max{}; + bool equaltomax{}; + fast_io::vector* next{}; +}; + +template +inline constexpr void* next_objects(floating_point_Object<_Ty> p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + std::u8string& str{cmdlist->operator[](order)}; + + _Ty num{}; + try { + if constexpr (std::is_same_v<_Ty, float>) { + num = std::stof(*reinterpret_cast(&str)); + } else if constexpr (std::is_same_v<_Ty, double>) { + num = std::stod(*reinterpret_cast(&str)); + } else if constexpr (std::is_same_v<_Ty, long double>) { + num = std::stold(*reinterpret_cast(&str)); + } else { + fast_io::fast_terminate(); + } + } catch (const std::exception&) { + return nullptr; + } + + if (p.equaltomin) { + if (num < p.min) + return nullptr; + } else { + if (num <= p.min) + return nullptr; + } + + if (p.equaltomax) { + if (num > p.max) + return nullptr; + } else { + if (num >= p.max) + return nullptr; + } + + return p.next; +} + +template +inline constexpr std::u8string next_complete(floating_point_Object<_Ty> p) noexcept { + return fast_io::u8concat(p); +} + +// Judge +struct Empty_Judge { + fast_io::vector* next{}; + bool (*judge)(fast_io::vector* cmdlist){}; +}; + +inline constexpr void* next_objects(Empty_Judge p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr || p.judge == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + if (p.judge(cmdlist)) + return p.next; + else + return nullptr; +} + +inline constexpr std::u8string next_complete(Empty_Judge p) noexcept { + return std::u8string{}; +} + +struct stringview_Judge { + std::u8string_view str{}; + fast_io::vector* next{}; + bool (*judge)(fast_io::vector* cmdlist){}; +}; + +inline constexpr void* next_objects(stringview_Judge p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr || p.judge == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + if (cmdlist->operator[](order) == p.str) { + if (p.judge(cmdlist)) + return p.next; + else + return nullptr; + } else + return nullptr; +} + +inline constexpr std::u8string next_complete(stringview_Judge p) noexcept { + return std::u8string{p.str}; +} + +struct string_Judge { + std::u8string str{}; + fast_io::vector* next{}; + bool (*judge)(fast_io::vector* cmdlist){}; +}; + +inline constexpr void* next_objects(string_Judge p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr || p.judge == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + if (cmdlist->operator[](order) == p.str) { + if (p.judge(cmdlist)) + return p.next; + else + return nullptr; + } else + return nullptr; +} + +inline constexpr std::u8string next_complete(string_Judge p) noexcept { + return p.str; +} + +template +struct integral_Judge { // or equal to + _Ty min{}; + _Ty max{}; + fast_io::vector* next{}; + bool (*judge)(fast_io::vector* cmdlist){}; +}; + +template +inline constexpr void* next_objects(integral_Judge<_Ty> p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr || p.judge == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + _Ty num{}; + try { + num = fast_io::u8to<_Ty>(cmdlist->operator[](order)); + } catch (const fast_io::error&) { + return nullptr; + } + + if (num >= p.min && num <= p.max) { + if (p.judge(cmdlist)) + return p.next; + else + return nullptr; + } else + return nullptr; +} + +template +inline constexpr std::u8string next_complete(integral_Judge<_Ty> p) noexcept { + return fast_io::concat(p); +} + +template +struct floating_point_Judge { // or equal to + _Ty min{}; + bool equaltomin{}; + _Ty max{}; + bool equaltomax{}; + fast_io::vector* next{}; + bool (*judge)(fast_io::vector* cmdlist){}; }; +template +inline constexpr void* next_objects(floating_point_Judge<_Ty> p, fast_io::vector* cmdlist, size_t order) noexcept { + if (cmdlist == nullptr || p.judge == nullptr) [[unlikely]] + return nullptr; + + if (order >= cmdlist->size()) [[unlikely]] + return nullptr; + + std::u8string& str{cmdlist->operator[](order)}; + + _Ty num{}; + try { + if constexpr (std::is_same_v<_Ty, float>) { + num = std::stof(*reinterpret_cast(&str)); + } else if constexpr (std::is_same_v<_Ty, double>) { + num = std::stod(*reinterpret_cast(&str)); + } else if constexpr (std::is_same_v<_Ty, long double>) { + num = std::stold(*reinterpret_cast(&str)); + } else { + fast_io::fast_terminate(); + } + } catch (const std::exception&) { + return nullptr; + } + + if (p.equaltomin) { + if (num < p.min) + return nullptr; + } else { + if (num <= p.min) + return nullptr; + } + + if (p.equaltomax) { + if (num > p.max) + return nullptr; + } else { + if (num >= p.max) + return nullptr; + } + + if (p.judge(cmdlist)) + return p.next; + else + return nullptr; +} + +template +inline constexpr std::u8string next_complete(std::is_floating_point<_Ty> p) noexcept { + return fast_io::concat(p); +} + +// i command class ICommand { public: std::u8string_view _command{}; @@ -24,8 +417,8 @@ public: std::shared_mutex iCommandLook{}; public: - void (*init)(ICommand*) = nullptr; - bool (*onExecute)(const fast_io::vector& args) = nullptr; + void (*init)(ICommand*){nullptr}; + bool (*onExecute)(const fast_io::vector& args){nullptr}; protected: static float assertFloat(std::u8string_view string); diff --git a/China/Memory/Hook.cpp b/China/Memory/Hook.cpp index a98e5c05fe73e94a3c6f13da76188e3daf646d31..15bc503736400ec1e1cc6c17876cc6e75e2bdd96 100644 --- a/China/Memory/Hook.cpp +++ b/China/Memory/Hook.cpp @@ -765,31 +765,15 @@ void Hooks::PleaseAutoComplete(__int64 _this, __int64 a2, TextHolder* text, int fast_io::vector* next = &cmd->second->aliasList; // Resolved for the first time for (size_t j = 1; j < cmdlist.size(); j++) { - for (size_t i = 0; i < next->size(); i++) { - if (cmdlist[j] == next->operator[](i).name) { - next = reinterpret_cast*>(next->operator[](i).next); - if (next == nullptr) { - concat.clear(); - return oFunc(_this, a2, text, a4); - } else if (next == &configs_ConfigCommand) { // config command !!! - listCommand_ConfigCommand(); - } else if (next == &Friend_friendList) { - Friend_friendList.clear(); - Friend_friendList.reserve(FriendList.size()); - for (auto &i : FriendList) - Friend_friendList.push_back_unchecked(aliasList_struct{i, nullptr}); - } else if (next == &Friend_playerList) { - Friend_playerList.clear(); - g_Data.forEachEntity([](C_Entity* ent) { - if (ent != g_Data.getLocalPlayer() && ent->isPlayer()) - if (auto name = ent->getNameTag()->getString(); !name.empty()) [[likely]] - Friend_playerList.push_back(aliasList_struct{name, nullptr}); - }); - } + const auto nextsize = next->size(); + for (size_t i = 0; i < nextsize; i++) { + auto newnext{reinterpret_cast*>(next_objects(next->operator[](i), &cmdlist, j))}; + if (newnext != nullptr) { + next = newnext; concat.append(fast_io::u8concat(cmdlist[j], fast_io::mnp::chvw(u8' '))); break; } - if (i == next->size() - 1) [[unlikely]] { // not found + if (i == nextsize - 1) [[unlikely]] { // not found concat.clear(); return oFunc(_this, a2, text, a4); // next = nullptr (return) } @@ -800,8 +784,8 @@ void Hooks::PleaseAutoComplete(__int64 _this, __int64 a2, TextHolder* text, int completeList.reserve(next->size()); for (auto& al : *next) { - C_GuiData::displayClientMessageC(fast_io::mnp::chvw(CommandMgr::prefix), Utils::TextColor::DARK_GRAY, cmd->first, fast_io::mnp::chvw(u8' '), concat, Utils::TextColor::GRAY, al.name); - completeList.emplace_back_unchecked(std::u8string{al.name}, 0, 0ui8); + C_GuiData::displayClientMessageC(fast_io::mnp::chvw(CommandMgr::prefix), Utils::TextColor::DARK_GRAY, cmd->first, fast_io::mnp::chvw(u8' '), concat, Utils::TextColor::GRAY, next_complete(al)); + completeList.emplace_back_unchecked(next_complete(al), 0, 0ui8); } std::u8string complete = fast_io::u8concat(fast_io::mnp::chvw(CommandMgr::prefix), cmd->first, fast_io::mnp::chvw(u8' '), concat, completeList.front().cmd); setTextAndReturn(complete); @@ -882,38 +866,22 @@ void Hooks::PleaseAutoComplete(__int64 _this, __int64 a2, TextHolder* text, int for (size_t j = 1; j < cmdlist.size(); j++) { if (j != cmdlist.size() - 1) { - for (size_t i = 0; i < next->size(); i++) { - if (cmdlist[j] == next->operator[](i).name) { - next = reinterpret_cast*>(next->operator[](i).next); - if (next == nullptr) { - concat.clear(); - return oFunc(_this, a2, text, a4); - } else if (next == &configs_ConfigCommand) { // config command !!! - listCommand_ConfigCommand(); - } else if (next == &Friend_friendList) { - Friend_friendList.clear(); - Friend_friendList.reserve(FriendList.size()); - for (auto& i : FriendList) - Friend_friendList.push_back_unchecked(aliasList_struct{i, nullptr}); - } else if (next == &Friend_playerList) { - Friend_playerList.clear(); - g_Data.forEachEntity([](C_Entity* ent) { - if (ent != g_Data.getLocalPlayer() && ent->isPlayer()) - if (auto name = ent->getNameTag()->getString(); !name.empty()) [[likely]] - Friend_playerList.push_back(aliasList_struct{name, nullptr}); - }); - } + const auto nextsize = next->size(); + for (size_t i = 0; i < nextsize; i++) { + auto newnext{reinterpret_cast*>(next_objects(next->operator[](i), &cmdlist, j))}; + if (newnext != nullptr) { + next = newnext; concat.append(fast_io::u8concat(cmdlist[j], fast_io::mnp::chvw(u8' '))); break; } - if (i == next->size() - 1) [[unlikely]] { // not found + if (i == nextsize - 1) [[unlikely]] { // not found concat.clear(); return oFunc(_this, a2, text, a4); // next = nullptr (return) } } } else { for (auto& i : *next) { - auto res = Analyze(cmdlist[j], i.name); + auto res = Analyze(cmdlist[j], next_complete(i)); if (res.type != 4) { completeList.emplace_back(std::move(res)); } diff --git a/China/include/fast_io/fast_io_dsal/impl/vector.h b/China/include/fast_io/fast_io_dsal/impl/vector.h index 6b20e350cd69500932632824094af04bed0ff496..fa5a3308bd0cc11ea92b111d5fe9f80b3560b709 100644 --- a/China/include/fast_io/fast_io_dsal/impl/vector.h +++ b/China/include/fast_io/fast_io_dsal/impl/vector.h @@ -531,7 +531,7 @@ public: else { auto const size{ ilist.size() }; - imp.curr_ptr = imp.begin_ptr = typed_allocator_type::allocator(size); + imp.curr_ptr = imp.begin_ptr = typed_allocator_type::allocate(size); auto e = imp.end_ptr = imp.begin_ptr + size; run_destroy des{ this }; assign_common_impl(ilist.begin(), ilist.end());