From 7d2ccb6128cae7f66e07e5796a54849bd0c8cf2c Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Tue, 1 Mar 2022 15:55:26 +0800 Subject: [PATCH 01/23] update ActorDataIDs type comment --- LiteLoader/Header/MC/DataItem.hpp | 103 ++++++++++++++++++------------ 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/LiteLoader/Header/MC/DataItem.hpp b/LiteLoader/Header/MC/DataItem.hpp index 495c9ae5bd..c4f2176e22 100644 --- a/LiteLoader/Header/MC/DataItem.hpp +++ b/LiteLoader/Header/MC/DataItem.hpp @@ -7,7 +7,7 @@ enum class ActorDataIDs : unsigned short { FLAGS = 0, // Int64 - HEALTH = 1, // Int (minecart/boat) + HEALTH = 1, // Int VARIANT = 2, // Int COLOR = 3, // Byte NAMETAG = 4, // String @@ -16,39 +16,40 @@ enum class ActorDataIDs : unsigned short AIR = 7, // Short POTION_COLOR = 8, // Int (ARGB!) POTION_AMBIENT = 9, // Byte - JUMP_DURATION = 10, // Int64 + JUMP_DURATION = 10, // Byte (not Int64) HURT_TIME = 11, // Int (minecart/boat) HURT_DIRECTION = 12, // Int (minecart/boat) PADDLE_TIME_LEFT = 13, // Float PADDLE_TIME_RIGHT = 14, // Float EXPERIENCE_VALUE = 15, // Int (xp orb) - DISPLAY_ITEM = 16, // Int (id | (data << 16)) - HORSE_FLAGS = 16, // Int - WITHER_SKULL_IS_DANGEROUS = 16, // Byte - MINECART_DISPLAY_OFFSET = 17, // Int - ARROW_SHOOTER_ID = 17, // Int64 - MINECART_HAS_DISPLAY = 18, // Byte (must be 1 for minecart to show block inside) - HORSE_TYPE = 19, - SWELL = 19, - OLD_SWELL = 20, - SWELL_DIR = 21, - CHARGE_AMOUNT = 22, - ENDERMAN_HELD_RUNTIME_ID = 23, // Short - ACTOR_AGE = 24, // Short + DISPLAY_ITEM = 16, // Byte Int CompoundTag + HORSE_FLAGS = 16, // Int, old + WITHER_SKULL_IS_DANGEROUS = 16, // Byte, old + MINECART_DISPLAY_OFFSET = 17, // Int Int64 Vec3 + ARROW_SHOOTER_ID = 17, // Int64, old + MINECART_HAS_DISPLAY = 18, // Byte Int64 + HORSE_TYPE = 19, // Byte + SWELL = 19, // old + OLD_SWELL = 20, // old + SWELL_DIR = 21, // old + CHARGE_AMOUNT = 22, // Byte + ENDERMAN_HELD_RUNTIME_ID = 23, // Int, (not Short?) + ACTOR_AGE = 24, // Byte, (not Short?) + //UNKNOWN_25 = 25, // 25 Byte Int PLAYER_FLAGS = 26, // Byte - PLAYER_INDEX = 27, + PLAYER_INDEX = 27, // Int PLAYER_BED_POSITION = 28, // BlockPos FIREBALL_POWER_X = 29, // Float FIREBALL_POWER_Y = 30, // Float FIREBALL_POWER_Z = 31, // Float - AUX_POWER = 32, - FISH_X = 33, - FISH_Z = 34, - FISH_ANGLE = 35, + AUX_POWER = 32, // old + FISH_X = 33, // old + FISH_Z = 34, // old + FISH_ANGLE = 35, // old POTION_AUX_VALUE = 36, // Short LEAD_HOLDER = 37, // Int64 SCALE = 38, // Float - INTERACTIVE_TAG = 39, // String + INTERACTIVE_TAG = 39, // Byte, (not String?) NPC_SKIN_ID = 40, // String URL_TAG = 41, // String MAX_AIR = 42, // Short @@ -61,14 +62,15 @@ enum class ActorDataIDs : unsigned short WITHER_TARGET_1 = 49, // Int64 WITHER_TARGET_2 = 50, // Int64 WITHER_TARGET_3 = 51, // Int64 - AERIAL_ATTACK = 52, + AERIAL_ATTACK = 52, // Short BOUNDING_BOX_WIDTH = 53, // Float BOUNDING_BOX_HEIGHT = 54, // Float FUSE_LENGTH = 55, // Int RIDER_SEAT_POSITION = 56, // Vec3 RIDER_ROTATION_LOCKED = 57, // Byte RIDER_MAX_ROTATION = 58, // Float - RIDER_MIN_ROTATION = 59, // Float + RIDER_MIN_ROTATION = 59, // Byte, (not Float?) + //UNKNOWN_60 = 60, // Float AREA_EFFECT_CLOUD_RADIUS = 61, // Float AREA_EFFECT_CLOUD_WAITING = 62, // Int AREA_EFFECT_CLOUD_PARTICLE_ID = 63, // Int @@ -78,7 +80,7 @@ enum class ActorDataIDs : unsigned short SHULKER_ATTACH_POS = 67, // BlockPos TRADING_PLAYER_EID = 68, // Int64 TRADING_CAREER = 69, - HAS_COMMAND_BLOCK = 70, + HAS_COMMAND_BLOCK = 70, // Byte COMMAND_BLOCK_COMMAND = 71, // String COMMAND_BLOCK_LAST_OUTPUT = 72, // String COMMAND_BLOCK_TRACK_OUTPUT = 73, // Byte @@ -86,7 +88,7 @@ enum class ActorDataIDs : unsigned short STRENGTH = 75, // Int MAX_STRENGTH = 76, // Int SPELL_CASTING_COLOR = 77, // Int - LIMITED_LIFE = 78, + LIMITED_LIFE = 78, // Int ARMOR_STAND_POSE_INDEX = 79, // Int ENDER_CRYSTAL_TIME_OFFSET = 80, // Int ALWAYS_SHOW_NAMETAG = 81, // Byte @@ -94,35 +96,54 @@ enum class ActorDataIDs : unsigned short NAME_AUTHOR = 83, SCORE_TAG = 84, // String BALLOON_ATTACHED_ENTITY = 85, // Int64 - PUFFERFISH_SIZE = 86, + PUFFERFISH_SIZE = 86, // Byte BUBBLE_TIME = 87, - AGENT = 88, - SITTING_AMOUNT = 89, - SITTING_AMOUNT_PREVIOUS = 90, - EATING_COUNTER = 91, - FLAGS_EXTENDED = 92, - LAYING_AMOUNT = 93, - LAYING_AMOUNT_PREVIOUS = 94, + AGENT = 88, // Int64 + SITTING_AMOUNT = 89, // Float + SITTING_AMOUNT_PREVIOUS = 90, // Float + EATING_COUNTER = 91, // Int + FLAGS_EXTENDED = 92, // Int64 + LAYING_AMOUNT = 93, // Float + LAYING_AMOUNT_PREVIOUS = 94, // Float DURATION = 95, SPAWN_TIME = 96, CHANGE_RATE = 97, CHANGE_ON_PICKUP = 98, PICKUP_COUNT = 99, - INTERACT_TEXT = 100, - TRADE_TIER = 101, - MAX_TRADE_TIER = 102, - TRADE_EXPERIENCE = 103, + INTERACT_TEXT = 100, // String + TRADE_TIER = 101, // Int + MAX_TRADE_TIER = 102, // Int + TRADE_EXPERIENCE = 103, // Int SKIN_ID = 104, // Int - SPAWNING_FRAMES = 105, - COMMAND_BLOCK_TICK_DELAY = 106, - COMMAND_BLOCK_EXECUTE_ON_FIRST_TICK = 107, - AMBIENT_SOUND_INTERVAL = 108 + SPAWNING_FRAMES = 105, // Int + COMMAND_BLOCK_TICK_DELAY = 106, // Int + COMMAND_BLOCK_EXECUTE_ON_FIRST_TICK = 107, // Byte + AMBIENT_SOUND_INTERVAL = 108, // Float + //UNKNOWN_109 = 109, // Float + //UNKNOWN_110 = 110, // String + //UNKNOWN_111 = 111, // Float + //UNKNOWN_112 = 112, // String + //UNKNOWN_113 = 113, // Byte + //UNKNOWN_114 = 114, // Int + //UNKNOWN_115 = 115, // Int + //UNKNOWN_116 = 116, // Int + //UNKNOWN_117 = 117, // Int + //UNKNOWN_118 = 118, // CompoundTag + //UNKNOWN_119 = 119, // Byte + //UNKNOWN_120 = 120, // CompoundTag + //UNKNOWN_121 = 121, // Float + //UNKNOWN_122 = 122, // String + //UNKNOWN_123 = 123, // Int + //UNKNOWN_124 = 124, // String + /* AMBIENT_SOUND_EVENT_NAME = 109, FALL_DAMAGE_MULTIPLIER = 110, NAME_RAW_TEXT = 111, CAN_RIDE_TARGET = 112, */ + + }; //namespace DataItemTypes From f562ba26f12394e5ffff15a3afda7585e8a8a959 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Tue, 1 Mar 2022 15:57:55 +0800 Subject: [PATCH 02/23] fix Schedule and PerttySNBT --- LiteLoader/Kernel/NBT/CompoundTagAPI.cpp | 4 ++-- LiteLoader/Kernel/ScheduleAPI.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LiteLoader/Kernel/NBT/CompoundTagAPI.cpp b/LiteLoader/Kernel/NBT/CompoundTagAPI.cpp index 14cf65edc3..5fabf993bc 100644 --- a/LiteLoader/Kernel/NBT/CompoundTagAPI.cpp +++ b/LiteLoader/Kernel/NBT/CompoundTagAPI.cpp @@ -1422,9 +1422,9 @@ inline void __appendPrettyList(std::ostringstream& oss, ListTag& tag, unsigned i if (!first) { oss << format.mSeparator; + if (format.mExpandInList[childrenType]) + __appendPrettyReturnSpace(oss, level + 1, format); } - if (format.mExpandInList[childrenType]) - __appendPrettyReturnSpace(oss, level + 1, format); __appendPrettySNBT(oss, *static_cast(child), level + 1, format); first = false; } diff --git a/LiteLoader/Kernel/ScheduleAPI.cpp b/LiteLoader/Kernel/ScheduleAPI.cpp index 18f6e7fca8..83f4cd5040 100644 --- a/LiteLoader/Kernel/ScheduleAPI.cpp +++ b/LiteLoader/Kernel/ScheduleAPI.cpp @@ -81,7 +81,6 @@ class ScheduleTaskQueueType const ScheduleTaskData& t = top(); if (t.leftTime >= 0) break; - pop(); //timeout try { @@ -129,6 +128,7 @@ class ScheduleTaskQueueType if (auto plugin = LL::getPlugin(t.handler)) logger.error("Plugin: {}", plugin->name); } + pop(); } } catch (...) { From ad7fa9e4d1d2f8c81da38692d2b56703696497b5 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Tue, 1 Mar 2022 16:38:08 +0800 Subject: [PATCH 03/23] fix Enum Parameter --- LiteLoader/Kernel/Command/DynamicCommandAPI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp b/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp index d5dc24e3b7..3f74d5a588 100644 --- a/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp +++ b/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp @@ -886,7 +886,7 @@ ParameterIndex DynamicCommandInstance::newParameter(DynamicCommand::ParameterDat auto iter = std::find(namesInBds.begin(), namesInBds.end(), data.description); if (iter == namesInBds.end()) throw("Enum " + std::string(data.description) + "not found in command and BDS"); -#ifndef USE_PARSE_ENUM_STRING +#ifndef USE_PARSE_ENUM_STRING_ // fix Enum setEnum(*iter, CommandRegistry::getEnumValues(*iter)); #endif // USE_PARSE_ENUM_STRING } From 95d7856de1f9a0be6f3771b904aa824d80907ca6 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Tue, 1 Mar 2022 16:43:03 +0800 Subject: [PATCH 04/23] fix build --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a92cc6934b..a11806a876 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,7 +67,7 @@ jobs: working-directory: ${{env.GITHUB_WORKSPACE}} if: startsWith(github.ref, 'refs/tags/') run: | - 7z a -t zip PDB.zip PDB + 7z a -tzip PDB.zip PDB shell: bash - name: Update LiteLoaderSDK From 45a35c387d137e8b63f9d5ad0a41fb7ad8e2c9bc Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Tue, 1 Mar 2022 21:10:25 +0800 Subject: [PATCH 05/23] move hot manage command to event system --- LiteLoader/Header/EventAPI.h | 14 + LiteLoader/Kernel/EventAPI.cpp | 1 + LiteLoader/Main/BuiltinCommands.cpp | 37 +-- LiteLoader/Main/PluginManager.cpp | 301 ++++++++++++++-------- LiteLoader/Main/PluginManager.h | 2 +- ScriptEngine/API/CommandCompatibleAPI.cpp | 68 ----- ScriptEngine/API/CommandCompatibleAPI.h | 6 - ScriptEngine/API/EventAPI.cpp | 34 ++- ScriptEngine/BuiltinCommands.cpp | 130 ++++------ ScriptEngine/BuiltinCommands.h | 3 +- ScriptEngine/Configs.h | 4 - 11 files changed, 311 insertions(+), 289 deletions(-) diff --git a/LiteLoader/Header/EventAPI.h b/LiteLoader/Header/EventAPI.h index fec61c4a32..14d316dd3d 100644 --- a/LiteLoader/Header/EventAPI.h +++ b/LiteLoader/Header/EventAPI.h @@ -649,4 +649,18 @@ class PlayerBedEnterEvent : public EventTemplate BlockInstance* mBlockInstance; }; +class ScriptPluginManagerEvent : public EventTemplate +{ +public: + enum class Operation + { Load, Unload, Reload }; + + Operation operation; + std::string target; + std::string otherInfo; + std::string pluginExtention; + + bool success = false; +}; + }; // namespace Event diff --git a/LiteLoader/Kernel/EventAPI.cpp b/LiteLoader/Kernel/EventAPI.cpp index 486f6392fe..57ce030507 100644 --- a/LiteLoader/Kernel/EventAPI.cpp +++ b/LiteLoader/Kernel/EventAPI.cpp @@ -286,6 +286,7 @@ DECLARE_EVENT_DATA(ServerStartedEvent); DECLARE_EVENT_DATA(ServerStoppedEvent); DECLARE_EVENT_DATA(RegCmdEvent); DECLARE_EVENT_DATA(PlayerBedEnterEvent); +DECLARE_EVENT_DATA(ScriptPluginManagerEvent); #ifdef ENABLE_SEH_PROTECTION diff --git a/LiteLoader/Main/BuiltinCommands.cpp b/LiteLoader/Main/BuiltinCommands.cpp index b12ca84e11..8e12ebd412 100644 --- a/LiteLoader/Main/BuiltinCommands.cpp +++ b/LiteLoader/Main/BuiltinCommands.cpp @@ -248,57 +248,38 @@ void LLHelpCommand(CommandOutput& output) "Welcome to our github project to get more information ~"); } -//Helper -string RemoveInvalidPartOfPluginName(const string& name) -{ - auto pos = name.find(LLSE_COMMAND_FINISHED_SYMBOL); - if (pos != string::npos) - { - return name.substr(0, pos); - } - return name; -} - void LLLoadPluginCommand(CommandOutput& output, const string& path) { - if (path.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //ScriptPlugin & Finished - output.success(); - if (PluginManager::loadPlugin(path, true)) - output.success("Plugin " + RemoveInvalidPartOfPluginName(path) + " loaded successfully."); + output.success("Plugin <" + path + "> loaded successfully."); else output.error("Fail to load plugin " + path); } void LLUnloadPluginCommand(CommandOutput& output, const string& pluginName) { - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //ScriptPlugin & Finished - output.success(); - if (PluginManager::unloadPlugin(pluginName, true)) - output.success("Plugin " + RemoveInvalidPartOfPluginName(pluginName) + " unloaded successfully."); + output.success("Plugin <" + pluginName + "> unloaded successfully."); else - output.error("Fail to unload plugin " + RemoveInvalidPartOfPluginName(pluginName)); + output.error("Fail to unload plugin " + pluginName); } void LLReloadPluginCommand(CommandOutput& output, const string& pluginName, bool reloadAll) { if (!reloadAll) { - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //ScriptPlugin & Finished - output.success(); - if (PluginManager::reloadPlugin(pluginName, true)) - output.success("Plugin " + RemoveInvalidPartOfPluginName(pluginName) + " reloaded successfully."); + output.success("Plugin <" + pluginName + "> reloaded successfully."); else - output.error("Fail to reload plugin " + RemoveInvalidPartOfPluginName(pluginName)); + output.error("Fail to reload plugin <" + pluginName + ">"); } else { - if (PluginManager::reloadAllPlugins(true)) - output.success("Plugins reloaded successfully."); + int cnt = PluginManager::reloadAllPlugins(true); + if (cnt > 0) + output.success(std::to_string(cnt) + " plugins reloaded successfully."); else - output.error("Fail to reload all plugins"); + output.error("Fail to reload any plugin!"); } } diff --git a/LiteLoader/Main/PluginManager.cpp b/LiteLoader/Main/PluginManager.cpp index b26cfab9a3..8197f87c57 100644 --- a/LiteLoader/Main/PluginManager.cpp +++ b/LiteLoader/Main/PluginManager.cpp @@ -130,155 +130,254 @@ std::unordered_map LL::PluginManager::getAllPlugins(bo bool LL::PluginManager::loadPlugin(string pluginFilePath, bool outputResult, bool isHotLoad) { - filesystem::path path(filesystem::path(pluginFilePath).lexically_normal()); - pluginFilePath = path.u8string(); - - string ext = path.extension().u8string(); - if (ext != ".dll") + try { - if (LLSE_VALID_PLUGIN_EXTENSIONS.find(ext) != LLSE_VALID_PLUGIN_EXTENSIONS.end()) //Script Plugin + filesystem::path path(filesystem::path(pluginFilePath).lexically_normal()); + pluginFilePath = path.u8string(); + + string ext = path.extension().u8string(); + if (ext != ".dll") { - if (pluginFilePath.find(LLSE_COMMAND_FINISHED_SYMBOL) == string::npos && outputResult) //not finished + if (LLSE_VALID_PLUGIN_EXTENSIONS.find(ext) != LLSE_VALID_PLUGIN_EXTENSIONS.end()) //LLSE Script Plugin { - logger.error("Fail to load script plugin {}!", pluginFilePath); - return false; + Event::ScriptPluginManagerEvent ev; + ev.operation = Event::ScriptPluginManagerEvent::Operation::Load; + ev.target = pluginFilePath; + ev.pluginExtention = ext; + ev.call(); + + return ev.success; } - else - return true; + else if (outputResult) + logger.error("You need to give a correct type of file!"); + return false; } - else if (outputResult) - logger.error("You need to give a correct type of file!"); - return false; - } - - if (pluginFilePath.find("/") == string::npos && pluginFilePath.find("\\") == string::npos - && loadPlugin("plugins/" + pluginFilePath)) - { - if (outputResult) - logger.error("No valid plugin found at {}!", pluginFilePath); - return false; - } - string pluginFileName = path.filename().u8string(); - auto lib = LoadLibrary(str2wstr(pluginFilePath).c_str()); - if (lib) - { - if (getPlugin(lib) == nullptr) - RegisterPlugin(lib, pluginFileName, pluginFileName, LL::Version(1, 0, 0), {}); - } - else - { - if (outputResult) - logger.error("Fail to load the plugin {}!", pluginFileName); - return false; - } + if (pluginFilePath.find("/") == string::npos && pluginFilePath.find("\\") == string::npos + && loadPlugin("plugins/" + pluginFilePath)) + { + if (outputResult) + logger.error("No valid plugin found at {}!", pluginFilePath); + return false; + } - // Call onPostInit - auto fn = GetProcAddress(getPlugin(lib)->handler, "onPostInit"); - if (fn) { - try { - ((void (*)()) fn)(); - return true; + string pluginFileName = path.filename().u8string(); + auto lib = LoadLibrary(str2wstr(pluginFilePath).c_str()); + if (lib) + { + if (getPlugin(lib) == nullptr) + RegisterPlugin(lib, pluginFileName, pluginFileName, LL::Version(1, 0, 0), {}); } - catch (std::exception& e) { + else + { if (outputResult) - { - logger.error("Plugin <{}> throws an std::exception in onPostInit", pluginFileName); - logger.error("Exception: ", TextEncoding::toUTF8(e.what())); - logger.error("Fail to init this plugin!"); - } + logger.error("Fail to load the plugin {}!", pluginFileName); return false; } - catch (...) { - if (outputResult) - { - logger.error("Plugin <{}> throws an exception in onPostInit", pluginFileName); - logger.error("Fail to init this plugin!"); + + // Call onPostInit + auto fn = GetProcAddress(getPlugin(lib)->handler, "onPostInit"); + if (fn) { + try { + ((void (*)()) fn)(); + return true; + } + catch (std::exception& e) { + if (outputResult) + { + logger.error("Plugin <{}> throws an std::exception in onPostInit", pluginFileName); + logger.error("Exception: ", TextEncoding::toUTF8(e.what())); + logger.error("Fail to init this plugin!"); + } + return false; + } + catch (...) { + if (outputResult) + { + logger.error("Plugin <{}> throws an exception in onPostInit", pluginFileName); + logger.error("Fail to init this plugin!"); + } + return false; } + } + else if (outputResult) + { + logger.error("Fail to get the initialize point of the plugin {}!", pluginFileName); return false; } + + //Hot Load + if (isHotLoad) + { + callEventAtHotLoad(getPlugin(lib)->name); + } + return true; } - else if (outputResult) + catch (const std::exception& e) { - logger.error("Fail to get the initialize point of the plugin {}!", pluginFileName); + if (outputResult) + { + logger.error("Error occurred when loading plugin {}!", pluginFilePath); + logger.error(TextEncoding::toUTF8(e.what())); + } return false; } - - //Hot Load - if (isHotLoad) + catch (...) { - callEventAtHotLoad(getPlugin(lib)->name); + if (outputResult) + { + logger.error("Error occurred when loading plugin {}!", pluginFilePath); + } + return false; } - return true; } bool LL::PluginManager::unloadPlugin(string pluginName, bool outputResult) { - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //ScriptPlugin & Finished - return true; + try + { + LL::Plugin* plugin = getPlugin(pluginName); + if (!plugin) + { + if (outputResult) + logger.error("No match plugin found!"); + return false; + } - LL::Plugin* plugin = getPlugin(pluginName); - if (!plugin) + if (plugin->type == Plugin::PluginType::ScriptPlugin) //Script Plugin + { + Event::ScriptPluginManagerEvent ev; + ev.operation = Event::ScriptPluginManagerEvent::Operation::Unload; + ev.target = pluginName; + ev.pluginExtention = filesystem::path(plugin->filePath).extension().u8string(); + ev.call(); + + return ev.success; + } + + //Hot unload + //callEventAtHotUnload(pluginName); + //unRegisterPlugin(pluginName); + //removeAllEventListeners(pluginName); + + logger.warn("Unload function of dll plugins has not been finished."); //TODO + return false; + } + catch (const std::exception& e) { if (outputResult) - logger.error("No match plugin found!"); + { + logger.error("Error occurred when unloading plugin {}!", pluginName); + logger.error(TextEncoding::toUTF8(e.what())); + } return false; } - - if (plugin->type == Plugin::PluginType::ScriptPlugin) //Script Plugin + catch (...) { - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) == string::npos && outputResult) //not finished + if (outputResult) { - logger.error("Fail to unload script plugin {}!", pluginName); - return false; + logger.error("Error occurred when unloading plugin {}!", pluginName); } - else - return true; + return false; } - - //Hot unload - //callEventAtHotUnload(pluginName); - //unRegisterPlugin(pluginName); - //removeAllEventListeners(pluginName); - - logger.warn("Unload function of dll plugins has not been finished."); //TODO - return false; } bool LL::PluginManager::reloadPlugin(string pluginName, bool outputResult) { - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //ScriptPlugin & Finished - return true; + try + { + LL::Plugin* plugin = getPlugin(pluginName); + if (!plugin) + { + if (outputResult) + logger.error("No match plugin found!"); + return false; + } + + if (plugin->type == Plugin::PluginType::ScriptPlugin) //Script Plugin + { + Event::ScriptPluginManagerEvent ev; + ev.operation = Event::ScriptPluginManagerEvent::Operation::Reload; + ev.target = pluginName; + ev.pluginExtention = filesystem::path(plugin->filePath).extension().u8string(); + ev.call(); + + return ev.success; + } + + /*string path = plugin->filePath; + if (!unloadPlugin(pluginName)) + return false; + return loadPlugin(path);*/ - LL::Plugin* plugin = getPlugin(pluginName); - if (!plugin) + logger.warn("Reload function of dll plugins has not been finished."); //TODO + return false; + } + catch (const std::exception& e) { if (outputResult) - logger.error("No match plugin found!"); + { + logger.error("Error occurred when reloading plugin {}!", pluginName); + logger.error(TextEncoding::toUTF8(e.what())); + } return false; } - - /*string path = plugin->filePath; - if (!unloadPlugin(pluginName)) + catch (...) + { + if (outputResult) + { + logger.error("Error occurred when reloading plugin {}!", pluginName); + } return false; - return loadPlugin(path);*/ - - logger.warn("Reload function of dll plugins has not been finished."); //TODO - return false; + } } -bool LL::PluginManager::reloadAllPlugins(bool outputResult) +int LL::PluginManager::reloadAllPlugins(bool outputResult) { - auto plugins = getAllPlugins(false); - bool res = false; - for (auto& [name, plugin] : plugins) + try { - if (reloadPlugin(name)) - res = true; - else - logger.error("Fail to reload plugin {}!", name); + auto plugins = getAllPlugins(true); + int cnt = 0; + for (auto& [name, plugin] : plugins) + { + if (plugin->type == Plugin::PluginType::ScriptPlugin) + { + Event::ScriptPluginManagerEvent ev; + ev.operation = Event::ScriptPluginManagerEvent::Operation::Reload; + ev.target = plugin->name; + ev.pluginExtention = filesystem::path(plugin->filePath).extension().u8string(); + ev.call(); + + if (ev.success) + ++cnt; + } + else + { + if (reloadPlugin(name)) + ++cnt; + else + logger.error("Fail to reload plugin {}!", name); + } + } + return cnt; + } + catch (const std::exception& e) + { + if (outputResult) + { + logger.error("Error occurred when reloading all plugins!"); + logger.error(TextEncoding::toUTF8(e.what())); + } + return false; + } + catch (...) + { + if (outputResult) + { + logger.error("Error occurred when reloading all plugins!"); + } + return false; } - return res; } bool LL::PluginManager::callEventAtHotLoad(std::string pluginName) diff --git a/LiteLoader/Main/PluginManager.h b/LiteLoader/Main/PluginManager.h index dfe784d2e7..ebf1ad3c3c 100644 --- a/LiteLoader/Main/PluginManager.h +++ b/LiteLoader/Main/PluginManager.h @@ -27,7 +27,7 @@ namespace LL static bool loadPlugin(std::string pluginFilePath, bool outputStatus = false, bool isHotLoad = false); static bool unloadPlugin(std::string pluginName, bool outputStatus = false); static bool reloadPlugin(std::string pluginName, bool outputStatus = false); - static bool reloadAllPlugins(bool outputStatus = false); + static int reloadAllPlugins(bool outputStatus = false); static LIAPI bool unRegisterPlugin(std::string name); }; diff --git a/ScriptEngine/API/CommandCompatibleAPI.cpp b/ScriptEngine/API/CommandCompatibleAPI.cpp index 15b0834f30..dae330d4f1 100644 --- a/ScriptEngine/API/CommandCompatibleAPI.cpp +++ b/ScriptEngine/API/CommandCompatibleAPI.cpp @@ -129,24 +129,6 @@ Local McClass::sendCmdOutput(const Arguments& args) CATCH("Fail in SendCmdOutput!"); } - -//////////////////// LXL Event Callbacks //////////////////// - -void RegisterBuiltinCmds() -{ - //调试引擎 - RegisterCmd(LLSE_DEBUG_CMD, "LXL " + string(LLSE_MODULE_TYPE) + " Engine Real-time Debugging", 4); - - //热管理 - RegisterCmd("lxl list", "List current loaded LXL plugins", 4); - RegisterCmd("lxl load", "Load a new LXL plugin", 4); - RegisterCmd("lxl unload", "Unload an existing LXL plugin", 4); - RegisterCmd("lxl reload", "Reload an existing LXL plugin / all LXL plugins", 4); - RegisterCmd("lxl version", "Get the version of LiteXLoader", 4); - - logger.info("Builtin Cmds Registered."); -} - void ProcessRegCmdQueue() { for (auto& cmdData : toRegCmdQueue) @@ -156,56 +138,6 @@ void ProcessRegCmdQueue() toRegCmdQueue.clear(); } -bool ProcessDebugEngine(const string& cmd) -{ -#define OUTPUT_DEBUG_SIGN() std::cout << "> " << std::flush - extern bool globalDebug; - extern ScriptEngine *debugEngine; - - if (cmd == LLSE_DEBUG_CMD) - { - if (globalDebug) - { - //EndDebug - logger.info("Debug mode ended"); - globalDebug = false; - } - else - { - //StartDebug - logger.info("Debug mode begins"); - globalDebug = true; - OUTPUT_DEBUG_SIGN(); - } - return false; - } - if (globalDebug) - { - EngineScope enter(debugEngine); - try - { - if (cmd == "stop") - { - return true; - } - else - { - auto result = debugEngine->eval(cmd); - PrintValue(std::cout, result); - cout << endl; - OUTPUT_DEBUG_SIGN(); - } - } - catch (Exception& e) - { - PrintException(e); - OUTPUT_DEBUG_SIGN(); - } - return false; - } - return true; -} - string LxlFindCmdReg(bool isPlayerCmd, const string& cmd, vector& receiveParas, bool *fromOtherEngine) { std::unordered_map& registeredMap = diff --git a/ScriptEngine/API/CommandCompatibleAPI.h b/ScriptEngine/API/CommandCompatibleAPI.h index 436816e65c..9d4eac7912 100644 --- a/ScriptEngine/API/CommandCompatibleAPI.h +++ b/ScriptEngine/API/CommandCompatibleAPI.h @@ -9,8 +9,6 @@ class Player; //helper std::vector SplitCmdLine(const std::string& paras); -// 注册LXL内置命令 -void RegisterBuiltinCmds(); // 命令回调查询 std::string LxlFindCmdReg(bool isPlayerCmd, const std::string& cmd, std::vector& receiveParas, bool* fromOtherEngine); // 删除指定引擎的所有命令 @@ -18,10 +16,6 @@ bool LxlRemoveCmdRegister(script::ScriptEngine* engine); // 处理命令延迟注册 void ProcessRegCmdQueue(); -// 处理调试引擎事件 -bool ProcessDebugEngine(const std::string& cmd); -// 处理热管理系统 -bool ProcessHotManageCmd(std::string& cmd); // 玩家自定义命令注册回调 bool CallPlayerCmdCallback(Player* player, const std::string& cmdPrefix, const std::vector& paras); diff --git a/ScriptEngine/API/EventAPI.cpp b/ScriptEngine/API/EventAPI.cpp index 1c7a97b824..e3679d59b6 100644 --- a/ScriptEngine/API/EventAPI.cpp +++ b/ScriptEngine/API/EventAPI.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include "APIHelp.h" #include "BaseAPI.h" #include "BlockAPI.h" @@ -1165,7 +1166,7 @@ void InitBasicEventListeners() // PreProcess if (!ProcessDebugEngine(cmd)) return false; - if (!ProcessHotManageCmd(ev.mCommand)) + if (!ProcessOldHotManageCommand(ev.mCommand)) return false; //CallEvents @@ -1208,6 +1209,37 @@ void InitBasicEventListeners() return true; }); +// Plugin Hot Management + Event::ScriptPluginManagerEvent::subscribe_ref([](ScriptPluginManagerEvent& ev) + { + if (ev.success) + return true; + if (ev.pluginExtention != LLSE_PLUGINS_EXTENSION) + return true; + + switch (ev.operation) + { + case ScriptPluginManagerEvent::Operation::Load: + if (PluginManager::loadPlugin(ev.target, true, true)) + ev.success = true; + break; + + case ScriptPluginManagerEvent::Operation::Unload: + if (PluginManager::unloadPlugin(ev.target)) + ev.success = true; + break; + + case ScriptPluginManagerEvent::Operation::Reload: + if (PluginManager::reloadPlugin(ev.target)) + ev.success = true; + break; + + default: + break; + } + return true; + }); + // For RegisterCmd... Event::RegCmdEvent::subscribe([](const RegCmdEvent& ev) { diff --git a/ScriptEngine/BuiltinCommands.cpp b/ScriptEngine/BuiltinCommands.cpp index eedc988338..2b2995e2d5 100644 --- a/ScriptEngine/BuiltinCommands.cpp +++ b/ScriptEngine/BuiltinCommands.cpp @@ -1,104 +1,76 @@ #include "BuiltinCommands.h" #include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include +#include using namespace std; -#define H do_hash - - -#define FIX_OLD_COMMAND(OLDCMD,NEWCMD)\ - if (StartsWith(cmd, OLDCMD)) \ - { \ - logger.warn("* Please use command " #NEWCMD " instead."); \ - cmd.replace(0, 3, "ll"); \ - } +extern Logger logger; -bool ProcessHotManageCmd(std::string& cmd) +bool ProcessDebugEngine(const std::string& cmd) { - FIX_OLD_COMMAND("lxl list", "ll list"); - FIX_OLD_COMMAND("lxl load", "ll load"); - FIX_OLD_COMMAND("lxl unload", "ll unload"); - FIX_OLD_COMMAND("lxl reload", "ll reload"); - FIX_OLD_COMMAND("lxl version", "ll version"); - FIX_OLD_COMMAND("lxl update", "ll upgrade"); - - if (cmd.find("ll ") != 0) - return true; - - auto cmdList = SplitCmdLine(cmd); - if (cmdList.size() <= 1) - { - logger.error("Command not found! Check your input again."); - return false; - } +#define OUTPUT_DEBUG_SIGN() std::cout << "> " << std::flush + extern bool globalDebug; + extern ScriptEngine* debugEngine; - switch (H(cmdList[1].c_str())) - { - case H("version"): - //logger.info("LiteLoader-ScriptEngine-{} v{}", LLSE_BACKEND_TYPE, LLSE_VERSION.toString()); - break; - - case H("load"): + if (cmd == LLSE_DEBUG_CMD) { - if (cmdList.size() == 3) + if (globalDebug) { - string path = cmdList[2]; - if (path.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //finished - return true; - if (filesystem::path(path).extension().u8string() != LLSE_PLUGINS_EXTENSION) - return true; - if (PluginManager::loadPlugin(path, true, true)) - cmd += LLSE_COMMAND_FINISHED_SUFFIX; + //EndDebug + logger.info("Debug mode ended"); + globalDebug = false; } else - logger.error("Bad Command! Check your input again."); - break; - } - - case H("unload"): - { - if (cmdList.size() == 3) { - string pluginName = cmdList[2]; - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //finished - return true; - if(PluginManager::unloadPlugin(pluginName)) - cmd += LLSE_COMMAND_FINISHED_SUFFIX; + //StartDebug + logger.info("Debug mode begins"); + globalDebug = true; + OUTPUT_DEBUG_SIGN(); } - else - logger.error("Bad Command! Check your input again."); - break; + return false; } - - case H("reload"): + if (globalDebug) { - if (cmdList.size() == 3) + EngineScope enter(debugEngine); + try { - //Reload specific plugin - string pluginName = cmdList[2]; - if (pluginName.find(LLSE_COMMAND_FINISHED_SYMBOL) != string::npos) //finished + if (cmd == "stop") + { return true; - if (PluginManager::reloadPlugin(pluginName)) - cmd += LLSE_COMMAND_FINISHED_SUFFIX; + } + else + { + auto result = debugEngine->eval(cmd); + PrintValue(std::cout, result); + cout << endl; + OUTPUT_DEBUG_SIGN(); + } } - else + catch (Exception& e) { - //Reload All - PluginManager::reloadAllPlugins(); - logger.info("All plugins reloaded."); + PrintException(e); + OUTPUT_DEBUG_SIGN(); } - break; + return false; } + return true; +} + +#define FIX_OLD_COMMAND(OLDCMD,NEWCMD)\ + if (StartsWith(cmd, OLDCMD)) \ + { \ + logger.warn("* Please use command " #NEWCMD " instead."); \ + cmd.replace(0, 3, "ll"); \ } + +bool ProcessOldHotManageCommand(std::string& cmd) +{ + FIX_OLD_COMMAND("lxl list", "ll list"); + FIX_OLD_COMMAND("lxl load", "ll load"); + FIX_OLD_COMMAND("lxl unload", "ll unload"); + FIX_OLD_COMMAND("lxl reload", "ll reload"); + FIX_OLD_COMMAND("lxl version", "ll version"); + FIX_OLD_COMMAND("lxl update", "ll upgrade"); + return true; } \ No newline at end of file diff --git a/ScriptEngine/BuiltinCommands.h b/ScriptEngine/BuiltinCommands.h index 96bd1b1cf1..1685f4a79d 100644 --- a/ScriptEngine/BuiltinCommands.h +++ b/ScriptEngine/BuiltinCommands.h @@ -1,4 +1,5 @@ #pragma once #include -bool ProcessHotManageCmd(const std::string& cmd); \ No newline at end of file +bool ProcessDebugEngine(const std::string& cmd); +bool ProcessOldHotManageCommand(std::string& cmd); \ No newline at end of file diff --git a/ScriptEngine/Configs.h b/ScriptEngine/Configs.h index 9ef02271d3..090c5926c3 100644 --- a/ScriptEngine/Configs.h +++ b/ScriptEngine/Configs.h @@ -58,7 +58,3 @@ // 线程池 #define LLSE_POOL_THREAD_COUNT 4 - -// 内置命令 -#define LLSE_COMMAND_FINISHED_SYMBOL ".FiniShed" -#define LLSE_COMMAND_FINISHED_SUFFIX LLSE_COMMAND_FINISHED_SYMBOL LLSE_PLUGINS_EXTENSION From b51bb8406d15b76f4a4344a144c02cd1324e61cf Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Tue, 1 Mar 2022 21:23:41 +0800 Subject: [PATCH 06/23] Update EventAPI.cpp --- ScriptEngine/API/EventAPI.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/ScriptEngine/API/EventAPI.cpp b/ScriptEngine/API/EventAPI.cpp index e3679d59b6..e03dbde31e 100644 --- a/ScriptEngine/API/EventAPI.cpp +++ b/ScriptEngine/API/EventAPI.cpp @@ -1212,8 +1212,6 @@ void InitBasicEventListeners() // Plugin Hot Management Event::ScriptPluginManagerEvent::subscribe_ref([](ScriptPluginManagerEvent& ev) { - if (ev.success) - return true; if (ev.pluginExtention != LLSE_PLUGINS_EXTENSION) return true; From 9be80b3068c529064fa4aedbaa918d5bdb171f0e Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Tue, 1 Mar 2022 21:35:08 +0800 Subject: [PATCH 07/23] optimize Level::getCurrentLevelName --- LiteLoader/Kernel/MC/LevelAPI.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/LiteLoader/Kernel/MC/LevelAPI.cpp b/LiteLoader/Kernel/MC/LevelAPI.cpp index 4388ee55f4..2513910db0 100644 --- a/LiteLoader/Kernel/MC/LevelAPI.cpp +++ b/LiteLoader/Kernel/MC/LevelAPI.cpp @@ -404,22 +404,17 @@ void Level::sendPacketForAllPlayer(Packet& pkt) std::string Level::getCurrentLevelName() { - try - { + if (Global) return Global->getLevelName(); - } - catch (...) + std::ifstream fin("server.properties"); + string buf; + while (getline(fin, buf)) { - std::ifstream fin("server.properties"); - string buf; - while (getline(fin, buf)) + if (buf.find("level-name=") != string::npos) { - if (buf.find("level-name=") != string::npos) - { - if (buf.back() == '\n') buf.pop_back(); - if (buf.back() == '\r') buf.pop_back(); - return buf.substr(11); - } + if (buf.back() == '\n') buf.pop_back(); + if (buf.back() == '\r') buf.pop_back(); + return buf.substr(11); } } return ""; From 7c364ea43b708fcd3337a223a9f53169dbdc3a9d Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Tue, 1 Mar 2022 21:37:05 +0800 Subject: [PATCH 08/23] avoid EXCEPTION_BREAKPOINT to cause crash --- .../plugins/LiteLoader/CrashLogger_Daemon.exe | Bin 55808 -> 56320 bytes .../CrashLogger_Daemon/Debugger.cpp | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/RELEASE/plugins/LiteLoader/CrashLogger_Daemon.exe b/RELEASE/plugins/LiteLoader/CrashLogger_Daemon.exe index 2629dce36d90d3a849b99990b8ea4b10e48496f7..6bdcb831570f8f8554e611d5013591a667783891 100644 GIT binary patch delta 7827 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�C4PKT8~ghm}t5+SkG27 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 diff --git a/Tools/CrashLogger/CrashLogger_Daemon/Debugger.cpp b/Tools/CrashLogger/CrashLogger_Daemon/Debugger.cpp index 12b1089357..e4c8dc1db0 100644 --- a/Tools/CrashLogger/CrashLogger_Daemon/Debugger.cpp +++ b/Tools/CrashLogger/CrashLogger_Daemon/Debugger.cpp @@ -126,7 +126,7 @@ void DebuggerMain(HANDLE hPro) while (WaitForDebugEvent(&debugEvent, INFINITE)) { - DWORD continueStatus; + DWORD continueStatus = DBG_CONTINUE; switch (debugEvent.dwDebugEventCode) { case CREATE_PROCESS_DEBUG_EVENT: @@ -136,7 +136,8 @@ void DebuggerMain(HANDLE hPro) continueStatus = OnThreadCreated(&debugEvent.u.CreateThread); break; case EXCEPTION_DEBUG_EVENT: - continueStatus = OnException(&debugEvent.u.Exception, debugEvent.dwProcessId, debugEvent.dwThreadId); + if (debugEvent.u.Exception.ExceptionRecord.ExceptionCode != EXCEPTION_BREAKPOINT) + continueStatus = OnException(&debugEvent.u.Exception, debugEvent.dwProcessId, debugEvent.dwThreadId); break; case EXIT_PROCESS_DEBUG_EVENT: waitEvent = false; From 128f800092502f90646ca6f3472dbd7f40bd2a35 Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Tue, 1 Mar 2022 22:17:04 +0800 Subject: [PATCH 09/23] add protection to APIs --- LiteLoader/Kernel/LoggerAPI.cpp | 67 +++++++++++++++------------ LiteLoader/Kernel/Utils/DbgHelper.cpp | 3 ++ LiteLoader/Main/BuiltinCommands.cpp | 3 ++ ScriptEngine/API/LlAPI.cpp | 28 ++++++++--- ScriptEngine/Engine/MessageSystem.cpp | 3 ++ 5 files changed, 67 insertions(+), 37 deletions(-) diff --git a/LiteLoader/Kernel/LoggerAPI.cpp b/LiteLoader/Kernel/LoggerAPI.cpp index 7d10edb03e..fd141b66b9 100644 --- a/LiteLoader/Kernel/LoggerAPI.cpp +++ b/LiteLoader/Kernel/LoggerAPI.cpp @@ -147,43 +147,50 @@ std::string applyTextStyle(const fmt::v8::text_style& ts, const S& format_str) void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) { - std::string title = o.logger->title; - if (!title.empty()) - title = "[" + title + "]"; - if (checkLogLevel(o.logger->consoleLevel, o.level)) + try { - fmt::print( - o.consoleFormat, - applyTextStyle(LL::globalConfig.colorLog ? fg(fmt::color::light_blue) : fmt::text_style(), - fmt::format("{:%H:%M:%S}", fmt::localtime(_time64(nullptr)))), - applyTextStyle(getModeColor(o.levelPrefix), o.levelPrefix), - applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), title), - applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), o.os.str())); + std::string title = o.logger->title; + if (!title.empty()) + title = "[" + title + "]"; + if (checkLogLevel(o.logger->consoleLevel, o.level)) + { + fmt::print( + o.consoleFormat, + applyTextStyle(LL::globalConfig.colorLog ? fg(fmt::color::light_blue) : fmt::text_style(), + fmt::format("{:%H:%M:%S}", fmt::localtime(_time64(nullptr)))), + applyTextStyle(getModeColor(o.levelPrefix), o.levelPrefix), + applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), title), + applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), o.os.str())); - } + } - if (checkLogLevel(o.logger->fileLevel, o.level)) - { - if (o.logger->ofs.is_open() || PluginOwnData::hasImpl(hPlugin, LOGGER_CURRENT_FILE)) + if (checkLogLevel(o.logger->fileLevel, o.level)) { - auto fileContent = fmt::format(o.fileFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, - o.os.str()); - if (o.logger->ofs.is_open()) - o.logger->ofs << fileContent << std::flush; - else - PluginOwnData::getImpl(hPlugin, LOGGER_CURRENT_FILE) + if (o.logger->ofs.is_open() || PluginOwnData::hasImpl(hPlugin, LOGGER_CURRENT_FILE)) + { + auto fileContent = fmt::format(o.fileFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, + o.os.str()); + if (o.logger->ofs.is_open()) + o.logger->ofs << fileContent << std::flush; + else + PluginOwnData::getImpl(hPlugin, LOGGER_CURRENT_FILE) << fileContent << std::flush; + } } + if (checkLogLevel(o.logger->playerLevel, o.level) && o.logger->player && Player::isValid(o.logger->player)) + o.logger->player->sendTextPacket( + fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, + o.os.str())); + + o.locked = false; + o.os.str(""); + o.os.clear(); + unlockImpl(hPlugin); + } + catch (...) + { + unlockImpl(hPlugin); } - if (checkLogLevel(o.logger->playerLevel, o.level) && o.logger->player && Player::isValid(o.logger->player)) - o.logger->player->sendTextPacket( - fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, - o.os.str())); - - o.locked = false; - o.os.str(""); - o.os.clear(); - unlockImpl(hPlugin); } Logger::Logger(const std::string& title) diff --git a/LiteLoader/Kernel/Utils/DbgHelper.cpp b/LiteLoader/Kernel/Utils/DbgHelper.cpp index cda785ec10..f084f6e1b0 100644 --- a/LiteLoader/Kernel/Utils/DbgHelper.cpp +++ b/LiteLoader/Kernel/Utils/DbgHelper.cpp @@ -135,6 +135,9 @@ bool PrintCurrentStackTraceback(PEXCEPTION_POINTERS e, Logger* l) std::thread printThread([e,hProcess,hThread,threadId,cacheSymbol,&res,&debugLogger]() { + // Set global SEH-Exception handler + _set_se_translator(seh_exception::TranslateSEHtoCE); + LoadSymbols(); CreateModuleMap(hProcess); diff --git a/LiteLoader/Main/BuiltinCommands.cpp b/LiteLoader/Main/BuiltinCommands.cpp index 8e12ebd412..463fd6109e 100644 --- a/LiteLoader/Main/BuiltinCommands.cpp +++ b/LiteLoader/Main/BuiltinCommands.cpp @@ -170,6 +170,9 @@ class TeleportDimensionCommand : public Command void LLUpgradeCommand(CommandOutput& output, bool isForce) { std::thread([isForce]() { + // Set global SEH-Exception handler + _set_se_translator(seh_exception::TranslateSEHtoCE); + LL::CheckAutoUpdate(true, isForce); }).detach(); } diff --git a/ScriptEngine/API/LlAPI.cpp b/ScriptEngine/API/LlAPI.cpp index 5a6f9e8b68..c9529d11a9 100644 --- a/ScriptEngine/API/LlAPI.cpp +++ b/ScriptEngine/API/LlAPI.cpp @@ -185,18 +185,32 @@ Local LlClass::require(const Arguments& args) //插件目录 existing = false; - auto list = GetFileNameList(LLSE_PLUGINS_LOAD_DIR); - for (auto fileName : list) + string requirePath = ""; + + //Direct + std::error_code ec; + if (filesystem::exists(require, ec)) { - if (fileName == require) + requirePath = require; + existing = true; + } + else + { + auto list = GetFileNameList(LLSE_PLUGINS_LOAD_DIR); + for (auto fileName : list) { - existing = true; - break; + if (fileName == require) + { + requirePath = string(LLSE_PLUGINS_LOAD_DIR) + "/" + require; + existing = true; + break; + } } } + if (existing) { - bool success = PluginManager::loadPlugin(string(LLSE_PLUGINS_LOAD_DIR) + "/" + require); + bool success = PluginManager::loadPlugin(requirePath); if (success) { logger.info(thisName + tr("lxlapi.require.success") + require); @@ -211,7 +225,7 @@ Local LlClass::require(const Arguments& args) //依赖库目录 existing = false; - list = GetFileNameList(LLSE_DEPENDS_DIR); + auto list = GetFileNameList(LLSE_DEPENDS_DIR); for (auto fileName : list) { if (fileName == require) diff --git a/ScriptEngine/Engine/MessageSystem.cpp b/ScriptEngine/Engine/MessageSystem.cpp index 5050537569..4061feaaed 100644 --- a/ScriptEngine/Engine/MessageSystem.cpp +++ b/ScriptEngine/Engine/MessageSystem.cpp @@ -372,6 +372,9 @@ void InitMessageSystem() }); std::thread([]() { + // Set global SEH-Exception handler + _set_se_translator(seh_exception::TranslateSEHtoCE); + globalShareData->messageThreads[LLSE_BACKEND_TYPE] = GetCurrentThread(); while (true) { From 6eb1c79e05afef89e292d42ef3d38c6a0c8b96ec Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Wed, 2 Mar 2022 01:50:02 +0800 Subject: [PATCH 10/23] update MinecraftPacketIds --- LiteLoader/Header/MC/Types.hpp | 335 +++++++++++++++++---------------- 1 file changed, 172 insertions(+), 163 deletions(-) diff --git a/LiteLoader/Header/MC/Types.hpp b/LiteLoader/Header/MC/Types.hpp index d58bd42e31..367b80b401 100644 --- a/LiteLoader/Header/MC/Types.hpp +++ b/LiteLoader/Header/MC/Types.hpp @@ -821,170 +821,179 @@ enum class FaceID : char enum class MinecraftPacketIds : int { - Login = 0x1, - PlayStatus = 0x2, - ServerToClientHandshake = 0x3, - ClientToServerHandshake = 0x4, - Disconnect = 0x5, - ResourcePacksInfo = 0x6, - ResourcePackStack = 0x7, - ResourcePackClientResponse = 0x8, - Text = 0x9, - SetTime = 0xa, - StartGame = 0xb, - AddPlayer = 0xc, - AddActor = 0xd, - RemoveActor = 0xe, - AddItemActor = 0xf, - TakeItemActor = 0x11, - MoveActorAbsolute = 0x12, - MovePlayer = 0x13, - UpdateBlock = 0x15, - AddPainting = 0x16, - TickSync = 0x17, - BlockEvent = 0x1a, - ActorEvent = 0x1b, - MobEffect = 0x1c, - UpdateAttributes = 0x1d, - InventoryTransaction = 0x1e, - MobEquipment = 0x1f, - MobArmorEquipment = 0x20, - Interact = 0x21, - BlockPickRequest = 0x22, - ActorPickRequest = 0x23, - PlayerAction = 0x24, - HurtArmor = 0x26, - SetActorData = 0x27, - SetActorLink = 0x29, - SetHealth = 0x2a, - SetSpawnPosition = 0x2b, - Animate = 0x2c, - Respawn = 0x2d, - ContainerOpen = 0x2e, - ContainerClose = 0x2f, - PlayerHotbar = 0x30, - InventoryContent = 0x31, - InventorySlot = 0x32, - ContainerSetData = 0x33, - CraftingData = 0x34, - CraftingEvent = 0x35, - GuiDataPickItem = 0x36, - AdventureSettings = 0x37, - BlockActorData = 0x38, - PlayerInput = 0x39, - LevelChunk = 0x3a, - SetCommandsEnabled = 0x3b, - SetDifficulty = 0x3c, - ChangeDimension = 0x3d, - SetPlayerGameType = 0x3e, - PlayerList = 0x3f, - Event = 0x41, - SpawnExperienceOrb = 0x42, - ClientboundMapItemData = 0x43, - MapInfoRequest = 0x44, - ItemFrameDropItem = 0x47, - GameRulesChanged = 0x48, - Camera = 0x49, - BossEvent = 0x4a, - ShowCredits = 0x4b, - AvailableCommands = 0x4c, - CommandRequest = 0x4d, - CommandBlockUpdate = 0x4e, - CommandOutput = 0x4f, - UpdateTrade = 0x50, - UpdateEquip = 0x51, - ResourcePackDataInfo = 0x52, - ResourcePackChunkData = 0x53, - ResourcePackChunkRequest = 0x54, - Transfer = 0x55, - PlaySound = 0x56, - StopSound = 0x57, - SetTitle = 0x58, - AddBehaviorTree = 0x59, - StructureBlockUpdate = 0x5a, - ShowStoreOffer = 0x5b, - PurchaseReceipt = 0x5c, - PlayerSkin = 0x5d, - SubClientLogin = 0x5e, - AutomationClientConnect = 0x5f, - SetLastHurtBy = 0x60, - BookEdit = 0x61, - NpcRequest = 0x62, - PhotoTransfer = 0x63, - ModalFormRequest = 0x64, - ModalFormResponse = 0x65, - ServerSettingsRequest = 0x66, - ServerSettingsResponse = 0x67, - ShowProfile = 0x68, - SetDefaultGameType = 0x69, - RemoveObjective = 0x6a, - SetDisplayObjective = 0x6b, - SetScore = 0x6c, - LabTable = 0x6d, - UpdateBlockSynced = 0x6e, - MoveActorDelta = 0x6f, - SetScoreboardIdentity = 0x70, - SetLocalPlayerAsInitialized = 0x71, - UpdateSoftEnum = 0x72, - NetworkStackLatency = 0x73, - ScriptCustomEvent = 0x75, - SpawnParticleEffect = 0x76, - AvailableActorIdentifiers = 0x77, - NetworkChunkPublisherUpdate = 0x79, - BiomeDefinitionList = 0x7a, - LevelSoundEvent = 0x7b, - LevelEventGeneric = 0x7c, - LecternUpdate = 0x7d, - AddEntity = 0x7f, - ClientCacheStatus = 0x81, - OnScreenTextureAnimation = 0x82, - MapCreateLockedCopy = 0x83, - StructureTemplateDataRequest = 0x84, - StructureTemplateDataResponse = 0x85, - ClientCacheBlobStatus = 0x87, - ClientCacheMissResponse = 0x88, - EducationSettings = 0x89, - Emote = 0x8a, - MultiplayerSettings = 0x8b, - SettingsCommand = 0x8c, - AnvilDamage = 0x8d, - CompletedUsingItem = 0x8e, - NetworkSettings = 0x8f, - PlayerAuthInput = 0x90, - CreativeContent = 0x91, - PlayerEnchantOptions = 0x92, - ItemStackRequest = 0x93, - ItemStackResponse = 0x94, - PlayerArmorDamage = 0x95, - CodeBuilder = 0x96, - UpdatePlayerGameType = 0x97, - EmoteList = 0x98, + Login = 0x01, + PlayStatus = 0x02, + ServerToClientHandshake = 0x03, + ClientToServerHandshake = 0x04, + Disconnect = 0x05, + ResourcePacksInfo = 0x06, + ResourcePackStack = 0x07, + ResourcePackClientResponse = 0x08, + Text = 0x09, + SetTime = 0x0A, + StartGame = 0x0B, + AddPlayer = 0x0C, + AddActor = 0x0D, + RemoveActor = 0x0E, + AddItemActor = 0x0F, + TakeItemActor = 0x11, + MoveActorAbsolute = 0x12, + MovePlayer = 0x13, + PassengerJump = 0x14, + UpdateBlock = 0x15, + AddPainting = 0x16, + TickSync = 0x17, + LevelSoundEventV1 = 0x18, + LevelEvent = 0x19, + BlockEvent = 0x1A, + ActorEvent = 0x1B, + MobEffect = 0x1C, + UpdateAttributes = 0x1D, + InventoryTransaction = 0x1E, + MobEquipment = 0x1F, + MobArmorEquipment = 0x20, + Interact = 0x21, + BlockPickRequest = 0x22, + ActorPickRequest = 0x23, + PlayerAction = 0x24, + HurtArmor = 0x26, + SetActorData = 0x27, + SetActorMotion = 0x28, + SetActorLink = 0x29, + SetHealth = 0x2A, + SetSpawnPosition = 0x2B, + Animate = 0x2C, + Respawn = 0x2D, + ContainerOpen = 0x2E, + ContainerClose = 0x2F, + PlayerHotbar = 0x30, + InventoryContent = 0x31, + InventorySlot = 0x32, + ContainerSetData = 0x33, + CraftingData = 0x34, + CraftingEvent = 0x35, + GuiDataPickItem = 0x36, + AdventureSettings = 0x37, + BlockActorData = 0x38, + PlayerInput = 0x39, + LevelChunk = 0x3A, + SetCommandsEnabled = 0x3B, + SetDifficulty = 0x3C, + ChangeDimension = 0x3D, + SetPlayerGameType = 0x3E, + PlayerList = 0x3F, + SimpleEvent = 0x40, + Event = 0x41, + SpawnExperienceOrb = 0x42, + ClientboundMapItemData = 0x43, + MapInfoRequest = 0x44, + RequestChunkRadius = 0x45, + ChunkRadiusUpdated = 0x46, + ItemFrameDropItem = 0x47, + GameRulesChanged = 0x48, + Camera = 0x49, + BossEvent = 0x4A, + ShowCredits = 0x4B, + AvailableCommands = 0x4C, + CommandRequest = 0x4D, + CommandBlockUpdate = 0x4E, + CommandOutput = 0x4F, + UpdateTrade = 0x50, + UpdateEquip = 0x51, + ResourcePackDataInfo = 0x52, + ResourcePackChunkData = 0x53, + ResourcePackChunkRequest = 0x54, + Transfer = 0x55, + PlaySound = 0x56, + StopSound = 0x57, + SetTitle = 0x58, + AddBehaviorTree = 0x59, + StructureBlockUpdate = 0x5A, + ShowStoreOffer = 0x5B, + PurchaseReceipt = 0x5C, + PlayerSkin = 0x5D, + SubClientLogin = 0x5E, + AutomationClientConnect = 0x5F, + SetLastHurtBy = 0x60, + BookEdit = 0x61, + NpcRequest = 0x62, + PhotoTransfer = 0x63, + ModalFormRequest = 0x64, + ModalFormResponse = 0x65, + ServerSettingsRequest = 0x66, + ServerSettingsResponse = 0x67, + ShowProfile = 0x68, + SetDefaultGameType = 0x69, + RemoveObjective = 0x6A, + SetDisplayObjective = 0x6B, + SetScore = 0x6C, + LabTable = 0x6D, + UpdateBlockSynced = 0x6E, + MoveActorDelta = 0x6F, + SetScoreboardIdentity = 0x70, + SetLocalPlayerAsInitialized = 0x71, + UpdateSoftEnum = 0x72, + NetworkStackLatency = 0x73, + ScriptCustomEvent = 0x75, + SpawnParticleEffect = 0x76, + AvailableActorIdentifiers = 0x77, + LevelSoundEventV2 = 0x78, + NetworkChunkPublisherUpdate = 0x79, + BiomeDefinitionList = 0x7A, + LevelSoundEvent = 0x7B, + LevelEventGeneric = 0x7C, + LecternUpdate = 0x7D, + AddEntity = 0x7F, + RemoveEntity = 0x80, + ClientCacheStatus = 0x81, + OnScreenTextureAnimation = 0x82, + MapCreateLockedCopy = 0x83, + StructureTemplateDataRequest = 0x84, + StructureTemplateDataResponse = 0x85, + ClientCacheBlobStatus = 0x87, + ClientCacheMissResponse = 0x88, + EducationSettings = 0x89, + Emote = 0x8A, + MultiplayerSettings = 0x8B, + SettingsCommand = 0x8C, + AnvilDamage = 0x8D, + CompletedUsingItem = 0x8E, + NetworkSettings = 0x8F, + PlayerAuthInput = 0x90, + CreativeContent = 0x91, + PlayerEnchantOptions = 0x92, + ItemStackRequest = 0x93, + ItemStackResponse = 0x94, + PlayerArmorDamage = 0x95, + CodeBuilder = 0x96, + UpdatePlayerGameType = 0x97, + EmoteList = 0x98, PositionTrackingDBServerBroadcast = 0x99, - PositionTrackingDBClientRequest = 0x9a, - DebugInfo = 0x9b, - PacketViolationWarning = 0x9c, - MotionPredictionHints = 0x9d, - AnimateEntity = 0x9e, - CameraShake = 0x9f, - PlayerFog = 0xa0, - CorrectPlayerMovePrediction = 0xa1, - ItemComponent = 0xa2, - FilterText = 0xa3, - ClientboundDebugRenderer = 0xa4, - SyncActorProperty = 0xa5, - AddVolumeEntity = 0xa6, - RemoveVolumeEntity = 0xa7, - SimulationType = 0xa8, - NPCDialogue = 0xa9, - EduUriResource = 0xaa, - CreatePhoto = 0xab, - UpdateSubChunkBlocks = 0xac, - PhotoInfoRequest = 0xad, - SubChunk = 0xae, - SubChunkRequest = 0xaf, - PlayerStartItemCooldown = 0xb0, - ScriptMessage = 0xb1, - CodeBuilderSource = 0xb2, + PositionTrackingDBClientRequest = 0x9A, + DebugInfo = 0x9B, + PacketViolationWarning = 0x9C, + MotionPredictionHints = 0x9D, + AnimateEntity = 0x9E, + CameraShake = 0x9F, + PlayerFog = 0xA0, + CorrectPlayerMovePrediction = 0xA1, + ItemComponent = 0xA2, + FilterText = 0xA3, + ClientboundDebugRenderer = 0xA4, + SyncActorProperty = 0xA5, + AddVolumeEntity = 0xA6, + RemoveVolumeEntity = 0xA7, + SimulationType = 0xA8, + NpcDialogue = 0xA9, + EduUriResource = 0xAA, + CreatePhoto = 0xAB, + UpdateSubChunkBlocks = 0xAC, + PhotoInfoRequest = 0xAD,//removed + SubChunk = 0xAE, + SubChunkRequest = 0xAF, + PlayerStartItemCooldown = 0xB0, + ScriptMessage = 0xB1, + CodeBuilderSource = 0xB2, }; enum ItemStackNetResult :unsigned char { From 7a71eedb1b550a6b9418b526cb0a8570485a8b85 Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 08:35:23 +0800 Subject: [PATCH 11/23] add lock back to logger --- LiteLoader/Header/LoggerAPI.h | 62 ++++++++++-------------------- LiteLoader/Header/Utils/CsLock.h | 7 ++-- LiteLoader/Kernel/LoggerAPI.cpp | 51 ++++++++++++++---------- LiteLoader/Kernel/Utils/CsLock.cpp | 9 +++++ 4 files changed, 64 insertions(+), 65 deletions(-) diff --git a/LiteLoader/Header/LoggerAPI.h b/LiteLoader/Header/LoggerAPI.h index cdc6f61c7b..c0d797cce8 100644 --- a/LiteLoader/Header/LoggerAPI.h +++ b/LiteLoader/Header/LoggerAPI.h @@ -50,7 +50,6 @@ class Player; using std::string; #define LOGGER_CURRENT_FILE "ll_plugin_logger_file" -#define LOGGER_CURRENT_LOCK "ll_plugin_logger_lock" template using enable_if_type = typename std::enable_if::type; @@ -75,7 +74,7 @@ class Logger { fmt::text_style style; std::string levelPrefix; std::ostringstream os; - bool locked = false; + bool locked = false; //Deprecated LIAPI explicit OutputStream(Logger* logger, int level, std::string&& consoleFormat, @@ -87,35 +86,26 @@ class Logger { template OutputStream& operator<<(T t) { - if (!locked) - { - lock(); - locked = true; - } + logger->lock(); os << t; + logger->unlock(); return *this; } template <> OutputStream& operator<<(std::wstring wstr) { - if (!locked) - { - lock(); - locked = true; - } + logger->lock(); os << wstr2str(wstr); + logger->unlock(); return *this; } template <> OutputStream& operator<<(const wchar_t* wstr) { - if (!locked) - { - lock(); - locked = true; - } + logger->lock(); os << wstr2str(wstr); + logger->unlock(); return *this; } @@ -158,15 +148,8 @@ class Logger { }; private: - - LIAPI static void initLockImpl(HMODULE hPlugin); - - LIAPI static void lockImpl(HMODULE hPlugin); - - LIAPI static void unlockImpl(HMODULE hPlugin); LIAPI static bool setDefaultFileImpl(HMODULE hPlugin, const std::string& logFile, bool appendMode); - LIAPI static bool setDefaultFileImpl(HMODULE hPlugin, nullptr_t); LIAPI static void endlImpl(HMODULE hPlugin, OutputStream& o); @@ -184,21 +167,6 @@ class Logger { setFile(nullptr); } - inline static void initLock() - { - return initLockImpl(GetCurrentModule()); - }; - - inline static void lock() - { - return lockImpl(GetCurrentModule()); - }; - - inline static void unlock() - { - return unlockImpl(GetCurrentModule()); - }; - inline static bool setDefaultFile(const std::string& logFile, bool appendMode) { return setDefaultFileImpl(GetCurrentModule(), logFile, appendMode); @@ -215,9 +183,12 @@ class Logger { }; LIAPI bool setFile(const std::string& logFile, bool appendMode = true); - LIAPI bool setFile(nullptr_t); + LIAPI bool tryLock(); + LIAPI bool lock(); + LIAPI bool unlock(); + OutputStream debug; OutputStream info; OutputStream warn; @@ -225,7 +196,16 @@ class Logger { OutputStream fatal; inline Logger(): Logger("") {} - LIAPI explicit Logger(const std::string &title); +private: + LIAPI CsLock& getLocker(); + + + //For compatibility +private: + LIAPI static void initLockImpl(HMODULE hPlugin); + LIAPI static void lockImpl(HMODULE hPlugin); + LIAPI static void unlockImpl(HMODULE hPlugin); + }; \ No newline at end of file diff --git a/LiteLoader/Header/Utils/CsLock.h b/LiteLoader/Header/Utils/CsLock.h index f47094dad0..7ae9d0ec8b 100644 --- a/LiteLoader/Header/Utils/CsLock.h +++ b/LiteLoader/Header/Utils/CsLock.h @@ -12,14 +12,15 @@ class CsLock public: LIAPI CsLock(); LIAPI ~CsLock(); + LIAPI bool tryLock(); LIAPI bool lock(); LIAPI bool unlock(); }; class CsLockHolder { - CsLock lock; + CsLock &locker; public: - LIAPI CsLockHolder() { lock.lock(); } - LIAPI ~CsLockHolder() { lock.unlock(); } + LIAPI CsLockHolder(CsLock &lock) :locker(lock) { locker.lock(); } + LIAPI ~CsLockHolder() { locker.unlock(); } }; \ No newline at end of file diff --git a/LiteLoader/Kernel/LoggerAPI.cpp b/LiteLoader/Kernel/LoggerAPI.cpp index fd141b66b9..328195f39a 100644 --- a/LiteLoader/Kernel/LoggerAPI.cpp +++ b/LiteLoader/Kernel/LoggerAPI.cpp @@ -7,27 +7,12 @@ #include #include "Main/Config.h" #include +#include #define LOGGER_CURRENT_TITLE "ll_plugin_logger_title" #define LOGGER_CURRENT_FILE "ll_plugin_logger_file" -#define LOGGER_CURRENT_LOCK "ll_plugin_logger_lock" -void Logger::initLockImpl(HMODULE hPlugin) -{ - //if (!PluginOwnData::hasImpl(hPlugin, LOGGER_CURRENT_LOCK)) - // PluginOwnData::setImpl(hPlugin, LOGGER_CURRENT_LOCK); //May cause DeadLock? -} - -void Logger::lockImpl(HMODULE hPlugin) -{ - //initLockImpl(hPlugin); - //PluginOwnData::getImpl(hPlugin, LOGGER_CURRENT_LOCK).lock(); //May cause DeadLock? -} - -void Logger::unlockImpl(HMODULE hPlugin) -{ - //PluginOwnData::getImpl(hPlugin, LOGGER_CURRENT_LOCK).unlock(); //May cause DeadLock? -} +std::unordered_map lockerList; bool Logger::setDefaultFileImpl(HMODULE hPlugin, const std::string& logFile, bool appendMode = true) { @@ -79,6 +64,26 @@ bool Logger::setFile(nullptr_t) return true; } +bool Logger::tryLock() +{ + return lockerList[title].tryLock(); +} + +bool Logger::lock() +{ + return lockerList[title].lock(); +} + +bool Logger::unlock() +{ + return lockerList[title].unlock(); +} + +CsLock& Logger::getLocker() +{ + return lockerList[title]; +} + Logger::OutputStream::OutputStream() = default; Logger::OutputStream::OutputStream(Logger* logger, int level, std::string&& consoleFormat, std::string&& fileFormat, @@ -149,6 +154,8 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) { try { + CsLockHolder lock(o.logger->getLocker()); + std::string title = o.logger->title; if (!title.empty()) title = "[" + title + "]"; @@ -182,14 +189,12 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, o.os.str())); - o.locked = false; o.os.str(""); o.os.clear(); - unlockImpl(hPlugin); } catch (...) { - unlockImpl(hPlugin); + ; } } @@ -231,4 +236,8 @@ Logger::Logger(const std::string& title) "§l§4[{}{}]{} {}\n", fmt::fg(fmt::color::red) | fmt::emphasis::bold, "FATAL"}; -} \ No newline at end of file +} + +void Logger::initLockImpl(HMODULE hPlugin) { ; } +void Logger::lockImpl(HMODULE hPlugin) { ; } +void Logger::unlockImpl(HMODULE hPlugin) { ; } \ No newline at end of file diff --git a/LiteLoader/Kernel/Utils/CsLock.cpp b/LiteLoader/Kernel/Utils/CsLock.cpp index dbbd402b63..e3b3528db5 100644 --- a/LiteLoader/Kernel/Utils/CsLock.cpp +++ b/LiteLoader/Kernel/Utils/CsLock.cpp @@ -12,6 +12,15 @@ CsLock::~CsLock() { DeleteCriticalSection(&cslock); } +bool CsLock::tryLock() +{ + if (!inited) { + inited = true; + InitializeCriticalSection(&cslock); + } + return TryEnterCriticalSection(&cslock); +} + bool CsLock::lock() { if (!inited) { inited = true; From 1051dc803bda4e20d68e83ee94c6013c666a68bd Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 09:51:43 +0800 Subject: [PATCH 12/23] remove useless code --- ScriptEngine/API/GuiAPI.cpp | 48 ------------------------------------- ScriptEngine/API/GuiAPI.h | 5 +--- 2 files changed, 1 insertion(+), 52 deletions(-) diff --git a/ScriptEngine/API/GuiAPI.cpp b/ScriptEngine/API/GuiAPI.cpp index 5c0627c087..c6a322fbff 100644 --- a/ScriptEngine/API/GuiAPI.cpp +++ b/ScriptEngine/API/GuiAPI.cpp @@ -326,52 +326,4 @@ Local McClass::newSimpleForm(const Arguments& args) Local McClass::newCustomForm(const Arguments& args) { return CustomFormClass::newForm(); -} - - -//表单回调 -bool CallFormCallback(Player* player, unsigned formId, const string& data) -{ - bool passToBDS = true; - - try - { - auto engines = EngineManager::getLocalEngines(); - for (auto engine : engines) - { - EngineScope enter(engine); - FormCallbackData callback; - try - { - callback = ENGINE_GET_DATA(engine)->formCallbacks.at(formId); - } - catch (...) - { - continue; - } - - EngineScope scope(callback.engine); - Local res{}; - try - { - res = callback.func.get().call({}, PlayerClass::newPlayer(player), JsonToValue(data)); - } - catch (const Exception& e) - { - logger.error("Form Callback Failed!"); - logger.error("In Plugin: " + ENGINE_OWN_DATA()->pluginName); - logger.error << e << ::Logger::endl; - } - if (res.isNull() || (res.isBoolean() && res.asBoolean().value() == false)) - passToBDS = false; - - ENGINE_OWN_DATA()->formCallbacks.erase(formId); - } - } - catch (...) - { - ; - } - - return passToBDS; } \ No newline at end of file diff --git a/ScriptEngine/API/GuiAPI.h b/ScriptEngine/API/GuiAPI.h index 4a105037b2..cb6b388d22 100644 --- a/ScriptEngine/API/GuiAPI.h +++ b/ScriptEngine/API/GuiAPI.h @@ -54,7 +54,4 @@ class CustomFormClass : public ScriptClass Local addSlider(const Arguments& args); Local addStepSlider(const Arguments& args); }; -extern ClassDefine CustomFormClassBuilder; - -// 表单回调 -bool CallFormCallback(Player* player, unsigned formId, const std::string& data); \ No newline at end of file +extern ClassDefine CustomFormClassBuilder; \ No newline at end of file From 97c399ae0aa0ac02b3a44deef30d921b1cfbf773 Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 09:52:27 +0800 Subject: [PATCH 13/23] remove debug code & optimize performance --- ScriptEngine/API/PlayerAPI.cpp | 11 ++++---- ScriptEngine/Engine/MessageSystem.cpp | 2 +- ScriptEngine/Engine/RemoteCall.cpp | 36 ++++++++++++++++---------- ScriptEngine/Engine/TimeTaskSystem.cpp | 32 ++++++++++++++--------- ScriptEngine/PluginManager.cpp | 2 +- 5 files changed, 51 insertions(+), 32 deletions(-) diff --git a/ScriptEngine/API/PlayerAPI.cpp b/ScriptEngine/API/PlayerAPI.cpp index 40d5e2aa80..c21d3bdf8f 100644 --- a/ScriptEngine/API/PlayerAPI.cpp +++ b/ScriptEngine/API/PlayerAPI.cpp @@ -1328,11 +1328,12 @@ Local PlayerClass::getExtraData(const Arguments& args) if (key.empty()) return Local(); - return ENGINE_OWN_DATA()->playerDataDB.at(player->getRealName() + "-" + key).get(); - } - catch (const std::out_of_range& e) - { - return Local(); + auto& db = ENGINE_OWN_DATA()->playerDataDB; + auto res = db.find(player->getRealName() + "-" + key); + if (res == db.end() || res->second.isEmpty()) + return Local(); + else + return res->second.get(); } CATCH("Fail in getExtraData!"); } diff --git a/ScriptEngine/Engine/MessageSystem.cpp b/ScriptEngine/Engine/MessageSystem.cpp index 4061feaaed..16ec5d136c 100644 --- a/ScriptEngine/Engine/MessageSystem.cpp +++ b/ScriptEngine/Engine/MessageSystem.cpp @@ -359,7 +359,7 @@ void MessageSystemLoopOnce() } } //messageLoopLock.unlock(); - logger.debug("Engine-{} Message Loop.", LLSE_MODULE_TYPE); + //logger.debug("Engine-{} Message Loop.", LLSE_MODULE_TYPE); } void InitMessageSystem() diff --git a/ScriptEngine/Engine/RemoteCall.cpp b/ScriptEngine/Engine/RemoteCall.cpp index 4db555a712..4d0f2d7106 100644 --- a/ScriptEngine/Engine/RemoteCall.cpp +++ b/ScriptEngine/Engine/RemoteCall.cpp @@ -24,8 +24,8 @@ void inline StringTrim(string& str) void RemoteSyncCallRequest(ModuleMessage& msg) { - logger.debug("*** Remote call request received."); - logger.debug("*** Current Module:{}", LLSE_MODULE_TYPE); + //logger.debug("*** Remote call request received."); + //logger.debug("*** Current Module:{}", LLSE_MODULE_TYPE); istringstream sin(msg.getData()); @@ -49,17 +49,17 @@ void RemoteSyncCallRequest(ModuleMessage& msg) argsVector.push_back(JsonToValue(arg)); } - logger.debug("*** Before remote call execute"); + //logger.debug("*** Before remote call execute"); Local result = funcData->func.get().call({}, argsVector); - logger.debug("*** After remote call execute"); + //logger.debug("*** After remote call execute"); //Feedback - logger.debug("*** Before remote call result return"); + //logger.debug("*** Before remote call result return"); if (!msg.sendResult(ModuleMessage::MessageType::RemoteSyncCallReturn, ValueToJson(result))) { logger.error("Fail to post remote call result return!"); } - logger.debug("*** After remote call result return"); + //logger.debug("*** After remote call result return"); } catch (const Exception& e) { @@ -77,6 +77,16 @@ void RemoteSyncCallRequest(ModuleMessage& msg) logger.error("Fail to post remote call result return!"); } } + catch (const std::out_of_range& e) + { + logger.error(string("Fail to import! Function [") + funcName + "] has not been exported!"); + + //Feedback + if (!msg.sendResult(ModuleMessage::MessageType::RemoteSyncCallReturn, "[null]")) + { + logger.error("Fail to post remote call result return!");; + } + } catch (...) { logger.error("Error occurred in remote engine!"); @@ -91,8 +101,8 @@ void RemoteSyncCallRequest(ModuleMessage& msg) void RemoteSyncCallReturn(ModuleMessage& msg) { - logger.debug("*** Remote call result message received."); - logger.debug("*** Result: {}", msg.getData()); + //logger.debug("*** Remote call result message received."); + //logger.debug("*** Result: {}", msg.getData()); remoteResultMap[msg.getId()] = msg.getData(); OperationCount(to_string(msg.getId())).done(); } @@ -103,7 +113,7 @@ void RemoteSyncCallReturn(ModuleMessage& msg) Local MakeRemoteCall(const string& funcName, const Arguments& args) { //Remote Call - logger.debug("*** Remote Call begin"); + //logger.debug("*** Remote Call begin"); ExportedFuncData* data; try { @@ -120,23 +130,23 @@ Local MakeRemoteCall(const string& funcName, const Arguments& args) for (int i = 0; i < args.size(); ++i) sout << "\n" << ValueToJson(args[i]); - logger.debug("*** Before remote call request send"); + //logger.debug("*** Before remote call request send"); auto sendResult = ModuleMessage::sendTo(data->engine, ModuleMessage::MessageType::RemoteSyncCallRequest, sout.str()); if (!sendResult) { logger.error("Fail to send remote load request!"); return Local(); } - logger.debug("*** After remote call request send"); + //logger.debug("*** After remote call request send"); - logger.debug("*** Before wait for remote call result"); + //logger.debug("*** Before wait for remote call result"); auto returnResult = sendResult.waitForOneResult(LLSE_MAXWAIT_REMOTE_CALL); if (!returnResult) { logger.error(tr("remoteCall.timeout.fail")); return Local(); } - logger.debug("*** After wait for remote call result"); + //logger.debug("*** After wait for remote call result"); int msgId = sendResult.getMsgId(); Local res = JsonToValue(remoteResultMap[msgId]); diff --git a/ScriptEngine/Engine/TimeTaskSystem.cpp b/ScriptEngine/Engine/TimeTaskSystem.cpp index 42dc9efb26..16f9822440 100644 --- a/ScriptEngine/Engine/TimeTaskSystem.cpp +++ b/ScriptEngine/Engine/TimeTaskSystem.cpp @@ -67,12 +67,14 @@ int NewTimeout(Local func, vector> paras, int timeout) try { if (LL::isServerStopping()) return; - if (timeTaskMap.find(id) == timeTaskMap.end()) - return; if (!EngineManager::isValid(engine)) return; - auto& taskData = timeTaskMap.at(id); + auto t = timeTaskMap.find(id); + if(t == timeTaskMap.end()) + return; + + auto& taskData = t->second; if (taskData.func.isEmpty()) return; @@ -106,12 +108,14 @@ int NewTimeout(Local func, int timeout) try { if (LL::isServerStopping()) return; - if (timeTaskMap.find(id) == timeTaskMap.end()) - return; if (!EngineManager::isValid(engine)) return; - auto& taskData = timeTaskMap.at(id); + auto t = timeTaskMap.find(id); + if (t == timeTaskMap.end()) + return; + + auto& taskData = t->second; if (taskData.code.isEmpty()) return; @@ -139,8 +143,6 @@ int NewInterval(Local func, vector> paras, int timeout) try { if (LL::isServerStopping()) return; - if (timeTaskMap.find(id) == timeTaskMap.end()) - return; if (!EngineManager::isValid(engine)) { timeTaskMap[id].task.cancel(); @@ -148,7 +150,11 @@ int NewInterval(Local func, vector> paras, int timeout) return; } - auto& taskData = timeTaskMap.at(id); + auto t = timeTaskMap.find(id); + if (t == timeTaskMap.end()) + return; + + auto& taskData = t->second; if (taskData.func.isEmpty()) return; @@ -181,8 +187,6 @@ int NewInterval(Local func, int timeout) try { if (LL::isServerStopping()) return; - if (timeTaskMap.find(id) == timeTaskMap.end()) - return; if (!EngineManager::isValid(engine)) { timeTaskMap[id].task.cancel(); @@ -190,7 +194,11 @@ int NewInterval(Local func, int timeout) return; } - auto& taskData = timeTaskMap.at(id); + auto t = timeTaskMap.find(id); + if (t == timeTaskMap.end()) + return; + + auto& taskData = t->second; if (taskData.code.isEmpty()) return; diff --git a/ScriptEngine/PluginManager.cpp b/ScriptEngine/PluginManager.cpp index 29dfcd5013..cb79f84330 100644 --- a/ScriptEngine/PluginManager.cpp +++ b/ScriptEngine/PluginManager.cpp @@ -61,7 +61,7 @@ bool PluginManager::loadPlugin(const std::string& filePath, bool isHotLoad, bool } //Remote Load - logger.debug("Remote Load begin"); + //logger.debug("Remote Load begin"); ostringstream sout; sout << isHotLoad << "\n" << filePath; From bf1c6bc887f5d5e7675443a7b6b0cf6f3b9d413f Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 11:57:10 +0800 Subject: [PATCH 14/23] add builtin output filter --- LiteLoader/Kernel/LoggerAPI.cpp | 40 ++++++++++++++++++++++++++------- LiteLoader/Main/Config.cpp | 13 ++++++++++- LiteLoader/Main/Config.h | 4 ++++ 3 files changed, 48 insertions(+), 9 deletions(-) diff --git a/LiteLoader/Kernel/LoggerAPI.cpp b/LiteLoader/Kernel/LoggerAPI.cpp index 328195f39a..05365aee76 100644 --- a/LiteLoader/Kernel/LoggerAPI.cpp +++ b/LiteLoader/Kernel/LoggerAPI.cpp @@ -8,6 +8,7 @@ #include "Main/Config.h" #include #include +#include #define LOGGER_CURRENT_TITLE "ll_plugin_logger_title" #define LOGGER_CURRENT_FILE "ll_plugin_logger_file" @@ -159,7 +160,27 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) std::string title = o.logger->title; if (!title.empty()) title = "[" + title + "]"; - if (checkLogLevel(o.logger->consoleLevel, o.level)) + + auto& text = o.os.str(); + bool filterBanned = false; + //Output Filter + if (LL::globalConfig.enableOutputFilter) + for (auto& regexStr : LL::globalConfig.outputFilterRegex) + { + try + { + std::regex re(regexStr); + if (std::regex_search(text, re) || std::regex_search(title, re)) + { + filterBanned = true; + break; + } + } + catch (...) + { } + } + + if (checkLogLevel(o.logger->consoleLevel, o.level) && !filterBanned) { fmt::print( o.consoleFormat, @@ -167,16 +188,15 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) fmt::format("{:%H:%M:%S}", fmt::localtime(_time64(nullptr)))), applyTextStyle(getModeColor(o.levelPrefix), o.levelPrefix), applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), title), - applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), o.os.str())); + applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), text)); } - if (checkLogLevel(o.logger->fileLevel, o.level)) + if (checkLogLevel(o.logger->fileLevel, o.level) && (LL::globalConfig.onlyFilterConsoleOutput || !filterBanned)) { if (o.logger->ofs.is_open() || PluginOwnData::hasImpl(hPlugin, LOGGER_CURRENT_FILE)) { - auto fileContent = fmt::format(o.fileFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, - o.os.str()); + auto fileContent = fmt::format(o.fileFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, text); if (o.logger->ofs.is_open()) o.logger->ofs << fileContent << std::flush; else @@ -184,10 +204,13 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) << fileContent << std::flush; } } - if (checkLogLevel(o.logger->playerLevel, o.level) && o.logger->player && Player::isValid(o.logger->player)) + + if (checkLogLevel(o.logger->playerLevel, o.level) && o.logger->player && Player::isValid(o.logger->player) + && (LL::globalConfig.onlyFilterConsoleOutput || !filterBanned)) + { o.logger->player->sendTextPacket( - fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, - o.os.str())); + fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, text)); + } o.os.str(""); o.os.clear(); @@ -238,6 +261,7 @@ Logger::Logger(const std::string& title) "FATAL"}; } +//For compatibility void Logger::initLockImpl(HMODULE hPlugin) { ; } void Logger::lockImpl(HMODULE hPlugin) { ; } void Logger::unlockImpl(HMODULE hPlugin) { ; } \ No newline at end of file diff --git a/LiteLoader/Main/Config.cpp b/LiteLoader/Main/Config.cpp index 1fc50d7631..8ee8a8cad1 100644 --- a/LiteLoader/Main/Config.cpp +++ b/LiteLoader/Main/Config.cpp @@ -45,7 +45,12 @@ namespace LL { }}, {"UnoccupyPort19132", {{"enabled", conf.enableUnoccupyPort19132}}}, {"CheckRunningBDS", {{"enabled", conf.enableCheckRunningBDS}}}, - {"WelcomeText", {{"enabled", conf.enableWelcomeText}}} + {"WelcomeText", {{"enabled", conf.enableWelcomeText}}}, + {"OutputFilter", { + {"enabled", conf.enableOutputFilter}, + {"onlyFilterConsoleOutput", conf.onlyFilterConsoleOutput}, + {"filterRegex", conf.outputFilterRegex} + }} } } }; @@ -134,6 +139,12 @@ namespace LL { conf.enableErrorStackTraceback = setting.value("enabled", true); conf.cacheErrorStackTracebackSymbol = setting.value("cacheSymbol", false); } + if (modules.find("OutputFilter") != modules.end()) { + const nlohmann::json& setting = modules.at("OutputFilter"); + conf.enableOutputFilter = setting.value("enabled", false); + conf.onlyFilterConsoleOutput = setting.value("onlyFilterConsoleOutput", true); + conf.outputFilterRegex = setting.value("filterRegex", std::vector()); + } } } } // namespace LL diff --git a/LiteLoader/Main/Config.h b/LiteLoader/Main/Config.h index 9b8e848a73..7bc13b5afd 100644 --- a/LiteLoader/Main/Config.h +++ b/LiteLoader/Main/Config.h @@ -54,6 +54,10 @@ struct LLConfig bool enableCheckRunningBDS = true; bool enableWelcomeText = true; + bool enableOutputFilter = false; + bool onlyFilterConsoleOutput = true; + std::vector outputFilterRegex; + // Runtime Config LLServerStatus serverStatus = LLServerStatus::Starting; }; From 044dad3d6982e311aca0f9420f75031a55046a0e Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 13:38:12 +0800 Subject: [PATCH 15/23] plugin can be found by filename --- LiteLoader/Main/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LiteLoader/Main/PluginManager.cpp b/LiteLoader/Main/PluginManager.cpp index 8197f87c57..4bcaf3171d 100644 --- a/LiteLoader/Main/PluginManager.cpp +++ b/LiteLoader/Main/PluginManager.cpp @@ -77,7 +77,7 @@ bool LL::PluginManager::unRegisterPlugin(std::string name) //Helper LL::Plugin* GetPlugin_Raw(std::string name, bool includeScriptPlugin) { for (auto& it : plugins) { - if (it.second.name == name) + if (it.second.name == name || filesystem::path(it.second.filePath).filename().u8string() == name) { if (!includeScriptPlugin && it.second.type == LL::Plugin::PluginType::ScriptPlugin) continue; From 8e68783b7cefa86677a3ce3259131b656379cd91 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Wed, 2 Mar 2022 14:15:35 +0800 Subject: [PATCH 16/23] change some command API for automatic delay setup (TODO) --- LiteLoader/Header/DynamicCommandAPI.h | 6 +++--- .../Kernel/Command/CommandRegistryAPI.cpp | 10 ++++++++++ .../Kernel/Command/DynamicCommandAPI.cpp | 18 +++++++++--------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/LiteLoader/Header/DynamicCommandAPI.h b/LiteLoader/Header/DynamicCommandAPI.h index 5a8f5ce75d..559dc06c76 100644 --- a/LiteLoader/Header/DynamicCommandAPI.h +++ b/LiteLoader/Header/DynamicCommandAPI.h @@ -534,9 +534,9 @@ class DynamicCommandInstance LIAPI void setCallback(DynamicCommand::CallBackFn&& callback) const; LIAPI void removeCallback() const; //LIAPI static bool updateSoftEnum(std::string const& name = "") const; - LIAPI static std::string setSoftEnum(std::string const& name, std::vector const& values); - LIAPI static bool addSoftEnumValues(std::string const& name, std::vector const& values); - LIAPI static bool removeSoftEnumValues(std::string const& name, std::vector const& values); + LIAPI std::string setSoftEnum(std::string const& name, std::vector const& values) const; + LIAPI bool addSoftEnumValues(std::string const& name, std::vector const& values) const; + LIAPI bool removeSoftEnumValues(std::string const& name, std::vector const& values) const; LIAPI static std::vector getSoftEnumValues(std::string const& name); LIAPI static std::vector getSoftEnumNames(); diff --git a/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp b/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp index a13eebfa89..a7fdf6b557 100644 --- a/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp +++ b/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp @@ -23,6 +23,8 @@ void CommandRegistry::registerOverload(std::string const& name, Overload::Factor extern Logger logger; std::vector CommandRegistry::getEnumNames() { + if (!Global) + return {}; std::vector results; for (auto& e : Global->mEnums) results.push_back(e.name); @@ -33,6 +35,8 @@ std::vector CommandRegistry::getEnumNames() } std::vector CommandRegistry::getSoftEnumNames() { + if (!Global) + return {}; std::vector results; for (auto& e : Global->mSoftEnums) results.push_back(e.name); @@ -43,6 +47,8 @@ std::vector CommandRegistry::getSoftEnumNames() } std::vector CommandRegistry::getEnumValues(std::string const& name) { + if (!Global) + return {}; std::vector results; auto& enums = Global->mEnums; auto iter = std::find_if(enums.begin(), enums.end(), [&](CommandRegistry::Enum const& r) { return r.name == name; }); @@ -57,6 +63,8 @@ std::vector CommandRegistry::getEnumValues(std::string const& name) } std::vector CommandRegistry::getSoftEnumValues(std::string const& name) { + if (!Global) + return {}; std::vector results; auto& enums = Global->mSoftEnums; auto iter = std::find_if(enums.begin(), enums.end(), [&](CommandRegistry::SoftEnum const& r) { return r.name == name; }); @@ -69,6 +77,8 @@ std::vector CommandRegistry::getSoftEnumValues(std::string const& n } std::string CommandRegistry::getCommandFullName(std::string const& name) { + if (!Global) + return ""; auto sig = Global->findCommand(name); if (sig) return sig->name; diff --git a/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp b/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp index 3f74d5a588..902dd12e43 100644 --- a/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp +++ b/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp @@ -1010,7 +1010,7 @@ inline std::vector DynamicCommandInstance::buildOverload(s // } // } //} -std::string DynamicCommandInstance::setSoftEnum(std::string const& name, std::vector const& values) +std::string DynamicCommandInstance::setSoftEnum(std::string const& name, std::vector const& values) const { auto names = CommandRegistry::getSoftEnumNames(); if (std::find(names.begin(), names.end(), name) == names.end()) @@ -1021,7 +1021,7 @@ std::string DynamicCommandInstance::setSoftEnum(std::string const& name, std::ve CommandSoftEnumRegistry(Global).updateSoftEnum(SoftEnumUpdateType::Set, name, values); return name; } -bool DynamicCommandInstance::addSoftEnumValues(std::string const& name, std::vector const& values) +bool DynamicCommandInstance::addSoftEnumValues(std::string const& name, std::vector const& values) const { auto names = CommandRegistry::getSoftEnumNames(); if (std::find(names.begin(), names.end(), name) == names.end()) @@ -1032,7 +1032,7 @@ bool DynamicCommandInstance::addSoftEnumValues(std::string const& name, std::vec CommandSoftEnumRegistry(Global).updateSoftEnum(SoftEnumUpdateType::Add, name, values); return true; }; -bool DynamicCommandInstance::removeSoftEnumValues(std::string const& name, std::vector const& values) +bool DynamicCommandInstance::removeSoftEnumValues(std::string const& name, std::vector const& values) const { CommandSoftEnumRegistry(Global).updateSoftEnum(SoftEnumUpdateType::Remove, name, values); return true; @@ -1350,8 +1350,8 @@ void onEnumExecute(DynamicCommand const& cmd, CommandOrigin const& origin, Comma { auto enumNames = Global->getEnumNames(); auto softEnumNames = Global->getSoftEnumNames(); - DynamicCommandInstance::setSoftEnum("EnumNameList", enumNames); - DynamicCommandInstance::addSoftEnumValues("EnumNameList", softEnumNames); + cmd.getInstance()->setSoftEnum("EnumNameList", enumNames); + cmd.getInstance()->addSoftEnumValues("EnumNameList", softEnumNames); if (results["name"].isSet) { auto& enumName = results["name"].getRaw(); @@ -1400,13 +1400,13 @@ void setupEnumCommand() auto command = DynamicCommand::createCommand("enum", "get command enum names or values", CommandPermissionLevel::Any); command->setAlias("enums"); auto name = command->mandatory("name", ParamType::SoftEnum, - DynamicCommandInstance::setSoftEnum("EnumNameList", {})); + command->setSoftEnum("EnumNameList", {})); command->addOverload(name); command->addOverload(); command->setCallback(onEnumExecute); - DynamicCommand::setup(std::move(command)); - DynamicCommandInstance::setSoftEnum("EnumNameList", packet.getEnumNames()); - DynamicCommandInstance::addSoftEnumValues("EnumNameList", packet.getSoftEnumNames()); + auto cmd = DynamicCommand::setup(std::move(command)); + cmd->setSoftEnum("EnumNameList", packet.getEnumNames()); + cmd->addSoftEnumValues("EnumNameList", packet.getSoftEnumNames()); } // echo command From 91491db89b327f9773de3f7b72b95a68c0139620 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Wed, 2 Mar 2022 17:07:59 +0800 Subject: [PATCH 17/23] fix some packets and add static assert for packets --- LiteLoader/Header/DynamicCommandAPI.h | 2 + LiteLoader/Header/MC/Packet.hpp | 1 + LiteLoader/Header/MC/PlaySoundPacket.hpp | 2 +- LiteLoader/Header/MC/PlayerListEntry.hpp | 12 +- LiteLoader/Header/MC/PlayerListPacket.hpp | 20 +- LiteLoader/Header/MC/SerializedSkin.hpp | 2 +- LiteLoader/Kernel/MC/PlayerAPI.cpp | 1 - LiteLoader/Kernel/Network/PacketAPI.cpp | 1014 +++++++++++++++++++++ LiteLoader/LiteLoader.vcxproj | 1 + LiteLoader/LiteLoader.vcxproj.filters | 3 + 10 files changed, 1042 insertions(+), 16 deletions(-) create mode 100644 LiteLoader/Kernel/Network/PacketAPI.cpp diff --git a/LiteLoader/Header/DynamicCommandAPI.h b/LiteLoader/Header/DynamicCommandAPI.h index 559dc06c76..5e220c7306 100644 --- a/LiteLoader/Header/DynamicCommandAPI.h +++ b/LiteLoader/Header/DynamicCommandAPI.h @@ -4,6 +4,8 @@ class Actor; #define USE_PARSE_ENUM_STRING //#define ENABLE_PARAMETER_TYPE_POSTFIX #include "MC/Command.hpp" +#include "MC/CommandOrigin.hpp" +#include "MC/CommandOutput.hpp" #include "MC/CommandRegistry.hpp" #include "MC/CommandSelector.hpp" #include "MC/CommandPosition.hpp" diff --git a/LiteLoader/Header/MC/Packet.hpp b/LiteLoader/Header/MC/Packet.hpp index e220cc4b98..193c9d4dbc 100644 --- a/LiteLoader/Header/MC/Packet.hpp +++ b/LiteLoader/Header/MC/Packet.hpp @@ -9,6 +9,7 @@ class ReadOnlyBinaryStream; class BinaryStream; class ServerPlayer; +class NetworkIdentifier; enum StreamReadResult; enum class PacketReliability { Relible, diff --git a/LiteLoader/Header/MC/PlaySoundPacket.hpp b/LiteLoader/Header/MC/PlaySoundPacket.hpp index 2ca0af267f..186c83068f 100644 --- a/LiteLoader/Header/MC/PlaySoundPacket.hpp +++ b/LiteLoader/Header/MC/PlaySoundPacket.hpp @@ -13,7 +13,7 @@ class PlaySoundPacket : public Packet { #define AFTER_EXTRA // Add Member There - char filler[104]; + char filler[56]; #undef AFTER_EXTRA #ifndef DISABLE_CONSTRUCTOR_PREVENTION_PLAYSOUNDPACKET diff --git a/LiteLoader/Header/MC/PlayerListEntry.hpp b/LiteLoader/Header/MC/PlayerListEntry.hpp index bcd2ec642d..e0593e7d11 100644 --- a/LiteLoader/Header/MC/PlayerListEntry.hpp +++ b/LiteLoader/Header/MC/PlayerListEntry.hpp @@ -5,9 +5,7 @@ #define BEFORE_EXTRA // Include Headers or Declare Types Here - -enum PlayerListPacketType { Add, - Remove }; +#include "SerializedSkin.hpp" #undef BEFORE_EXTRA @@ -16,8 +14,12 @@ class PlayerListEntry { #define AFTER_EXTRA // Add Member There public: - std::vector entries; - enum PlayerListPacketType type; + ActorUniqueID uid; + mce::UUID uuid; + std::string name, xuid, platform_online_id; + enum BuildPlatform platform; + SerializedSkin skin; + bool teacher, host; #undef AFTER_EXTRA diff --git a/LiteLoader/Header/MC/PlayerListPacket.hpp b/LiteLoader/Header/MC/PlayerListPacket.hpp index 7be0ed7e99..29488b1728 100644 --- a/LiteLoader/Header/MC/PlayerListPacket.hpp +++ b/LiteLoader/Header/MC/PlayerListPacket.hpp @@ -5,21 +5,25 @@ #define BEFORE_EXTRA // Include Headers or Declare Types Here -class SerializedSkin; +#include "PlayerListEntry.hpp" + +enum PlayerListPacketType +{ + Add, + Remove +}; #undef BEFORE_EXTRA -class PlayerListPacket { +class PlayerListPacket : public Packet +{ #define AFTER_EXTRA // Add Member There public: - ActorUniqueID uid; - mce::UUID uuid; - std::string name, xuid, platform_online_id; - enum BuildPlatform platform; - SerializedSkin skin; - bool teacher, host; +public: + std::vector entries; + enum PlayerListPacketType type; #undef AFTER_EXTRA diff --git a/LiteLoader/Header/MC/SerializedSkin.hpp b/LiteLoader/Header/MC/SerializedSkin.hpp index e565e27405..67560a8293 100644 --- a/LiteLoader/Header/MC/SerializedSkin.hpp +++ b/LiteLoader/Header/MC/SerializedSkin.hpp @@ -12,7 +12,7 @@ class SerializedSkin { #define AFTER_EXTRA // Add Member There - + char filler[620]; #undef AFTER_EXTRA public: diff --git a/LiteLoader/Kernel/MC/PlayerAPI.cpp b/LiteLoader/Kernel/MC/PlayerAPI.cpp index b07d11ed0d..df741fd3fc 100644 --- a/LiteLoader/Kernel/MC/PlayerAPI.cpp +++ b/LiteLoader/Kernel/MC/PlayerAPI.cpp @@ -384,7 +384,6 @@ bool Player::deleteScore(const string& key) ////////////////////////// Packet ////////////////////////// static_assert(sizeof(TextPacket) == 216); -static_assert(sizeof(PlaySoundPacket) == 152); static_assert(sizeof(TransferPacket) == 88); bool Player::sendTextPacket(string text, TextType Type) const diff --git a/LiteLoader/Kernel/Network/PacketAPI.cpp b/LiteLoader/Kernel/Network/PacketAPI.cpp new file mode 100644 index 0000000000..eb247a18ca --- /dev/null +++ b/LiteLoader/Kernel/Network/PacketAPI.cpp @@ -0,0 +1,1014 @@ +#include +#include + +#define INCLUDE_ALL_PACKET +//#define SIZE_STATIC_ASSERT +#define SIZE_STATIC_ASSERT_IF_DEFINE + +#ifdef INCLUDE_ALL_PACKET + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#endif INCLUDE_ALL_PACKET + +#pragma region For Each Packet Macro + +class ShowProfilePacket; +class SetDefaultGameTypePacket; +class RemoveObjectivePacket; +class RemoveVolumeEntityPacket; +class SyncActorPropertyPacket; +class FilterTextPacket; +class CodeBuilderPacket; +class NetworkSettingsPacket; +class MultiplayerSettingsPacket; +class SettingsCommandPacket; +class MapCreateLockedCopyPacket; +class AddEntityPacket; +class RemoveEntityPacket; +class LevelSoundEventPacketV2; +class ModalFormRequestPacket; +class ModalFormResponsePacket; +class ServerSettingsRequestPacket; +class ClientToServerHandshakePacket; +class ServerToClientHandshakePacket; +class SetTimePacket; +class RemoveActorPacket; +class PassengerJumpPacket; +class LevelSoundEventPacketV1; +class SetCommandsEnabledPacket; +class SetPlayerGameTypePacket; +class RequestChunkRadiusPacket; +class ChunkRadiusUpdatedPacket; +class SetLastHurtByPacket; +class AutomationClientConnectPacket; +class StopSoundPacket; +class PlayerArmorDamagePacket; +class ActorPickRequestPacket; +class AddPaintingPacket; +class StructureTemplateDataResponsePacket; +class TransferPacket; +class UpdateEquipPacket; +class UpdateSoftEnumPacket; +class UpdateTradePacket; +class CameraPacket; +class MobArmorEquipmentPacket; +class MobEffectPacket; +class MoveActorAbsolutePacket; +class NetworkStackLatencyPacket; +class NpcRequestPacket; +class OnScreenTextureAnimationPacket; +class PacketViolationWarningPacket; +class PhotoTransferPacket; +class PlaySoundPacket; +class AnvilDamagePacket; +class BlockEventPacket; +class BookEditPacket; +class BossEventPacket; +class ClientboundMapItemDataPacket; +class CommandBlockUpdatePacket; +class CompletedUsingItemPacket; +class ContainerSetDataPacket; +class CraftingEventPacket; +class DebugInfoPacket; +class EducationSettingsPacket; +class EmoteListPacket; +class EmotePacket; +class HurtArmorPacket; +class ItemFrameDropItemPacket; +class LabTablePacket; +class LecternUpdatePacket; +class LevelEventGenericPacket; +class PlayerEnchantOptionsPacket; +class PlayerInputPacket; +class PlayerSkinPacket; +class PositionTrackingDBClientRequestPacket; +class PositionTrackingDBServerBroadcastPacket; +class PurchaseReceiptPacket; +class ResourcePackChunkDataPacket; +class ResourcePackChunkRequestPacket; +class ResourcePackDataInfoPacket; +class ScriptCustomEventPacket; +class CreatePhotoPacket; +class EduUriResourcePacket; +class NpcDialoguePacket; +class SimulationTypePacket; +class AddVolumeEntityPacket; +class AnimateEntityPacket; +class CameraShakePacket; +class CodeBuilderSourcePacket; +class ClientboundDebugRendererPacket; +class CorrectPlayerMovePredictionPacket; +class PlayerStartItemCooldownPacket; +class ScriptMessagePacket; +class SetDisplayObjectivePacket; +class SetScorePacket; +class SetScoreboardIdentityPacket; +class SetTitlePacket; +class ShowCreditsPacket; +class ShowStoreOfferPacket; +class SpawnExperienceOrbPacket; +class SpawnParticleEffectPacket; +class StructureBlockUpdatePacket; +class StructureTemplateDataRequestPacket; +class SubClientLoginPacket; +class SimpleEventPacket; +class AddBehaviorTreePacket; +class AvailableActorIdentifiersPacket; +class AvailableCommandsPacket; +class BiomeDefinitionListPacket; +class CraftingDataPacket; +class CreativeContentPacket; +class GameRulesChangedPacket; +class ResourcePackStackPacket; +class ResourcePacksInfoPacket; +class ItemComponentPacket; +class SetSpawnPositionPacket; +class StartGamePacket; +class PlayerFogPacket; +class AddPlayerPacket; +class LoginPacket; +class BlockPickRequestPacket; +class DisconnectPacket; +class GuiDataPickItemPacket; +class SetLocalPlayerAsInitializedPacket; +class TextPacket; +class PlayerListPacket; +class PlayStatusPacket; +class ClientCacheStatusPacket; +class SetDifficultyPacket; +class ChangeDimensionPacket; +class ResourcePackClientResponsePacket; +class SetActorLinkPacket; +class UpdatePlayerGameTypePacket; +class RespawnPacket; +class TakeItemActorPacket; +class PlayerHotbarPacket; +class CommandOutputPacket; +class TickSyncPacket; +class CommandRequestPacket; +class ContainerOpenPacket; +class ContainerClosePacket; +class InventoryContentPacket; +class ServerSettingsResponsePacket; +class InventorySlotPacket; +class UpdateBlockSyncedPacket; +class PlayerActionPacket; +class ItemStackRequestPacket; +class ItemStackResponsePacket; +class AdventureSettingsPacket; +class BlockActorDataPacket; +class EventPacket; +class SetHealthPacket; +class MobEquipmentPacket; +class MotionPredictionHintsPacket; +class AddItemActorPacket; +class UpdateAttributesPacket; +class InteractPacket; +class ActorEventPacket; +class LevelEventPacket; +class NetworkChunkPublisherUpdatePacket; +class AnimatePacket; +class InventoryTransactionPacket; +class AddActorPacket; +class MapInfoRequestPacket; +class UpdateSubChunkBlocksPacket; +class SetActorMotionPacket; +class LevelSoundEventPacket; +class SubChunkPacket; +class SubChunkRequestPacket; +class ClientCacheMissResponsePacket; +class ClientCacheBlobStatusPacket; +class LevelChunkPacket; +class SetActorDataPacket; +class UpdateBlockPacket; +class MoveActorDeltaPacket; +class MovePlayerPacket; +class PlayerAuthInputPacket; + +#define ForEachPacket(Func) \ + Func(ShowProfilePacket); \ + Func(SetDefaultGameTypePacket); \ + Func(RemoveObjectivePacket); \ + Func(RemoveVolumeEntityPacket); \ + Func(SyncActorPropertyPacket); \ + Func(FilterTextPacket); \ + Func(CodeBuilderPacket); \ + Func(NetworkSettingsPacket); \ + Func(MultiplayerSettingsPacket); \ + Func(SettingsCommandPacket); \ + Func(MapCreateLockedCopyPacket); \ + Func(AddEntityPacket); \ + Func(RemoveEntityPacket); \ + Func(LevelSoundEventPacketV2); \ + Func(ModalFormRequestPacket); \ + Func(ModalFormResponsePacket); \ + Func(ServerSettingsRequestPacket); \ + Func(ClientToServerHandshakePacket); \ + Func(ServerToClientHandshakePacket); \ + Func(SetTimePacket); \ + Func(RemoveActorPacket); \ + Func(PassengerJumpPacket); \ + Func(LevelSoundEventPacketV1); \ + Func(SetCommandsEnabledPacket); \ + Func(SetPlayerGameTypePacket); \ + Func(RequestChunkRadiusPacket); \ + Func(ChunkRadiusUpdatedPacket); \ + Func(SetLastHurtByPacket); \ + Func(AutomationClientConnectPacket); \ + Func(StopSoundPacket); \ + Func(PlayerArmorDamagePacket); \ + Func(ActorPickRequestPacket); \ + Func(AddPaintingPacket); \ + Func(StructureTemplateDataResponsePacket); \ + Func(TransferPacket); \ + Func(UpdateEquipPacket); \ + Func(UpdateSoftEnumPacket); \ + Func(UpdateTradePacket); \ + Func(CameraPacket); \ + Func(MobArmorEquipmentPacket); \ + Func(MobEffectPacket); \ + Func(MoveActorAbsolutePacket); \ + Func(NetworkStackLatencyPacket); \ + Func(NpcRequestPacket); \ + Func(OnScreenTextureAnimationPacket); \ + Func(PacketViolationWarningPacket); \ + Func(PhotoTransferPacket); \ + Func(PlaySoundPacket); \ + Func(AnvilDamagePacket); \ + Func(BlockEventPacket); \ + Func(BookEditPacket); \ + Func(BossEventPacket); \ + Func(ClientboundMapItemDataPacket); \ + Func(CommandBlockUpdatePacket); \ + Func(CompletedUsingItemPacket); \ + Func(ContainerSetDataPacket); \ + Func(CraftingEventPacket); \ + Func(DebugInfoPacket); \ + Func(EducationSettingsPacket); \ + Func(EmoteListPacket); \ + Func(EmotePacket); \ + Func(HurtArmorPacket); \ + Func(ItemFrameDropItemPacket); \ + Func(LabTablePacket); \ + Func(LecternUpdatePacket); \ + Func(LevelEventGenericPacket); \ + Func(PlayerEnchantOptionsPacket); \ + Func(PlayerInputPacket); \ + Func(PlayerSkinPacket); \ + Func(PositionTrackingDBClientRequestPacket); \ + Func(PositionTrackingDBServerBroadcastPacket); \ + Func(PurchaseReceiptPacket); \ + Func(ResourcePackChunkDataPacket); \ + Func(ResourcePackChunkRequestPacket); \ + Func(ResourcePackDataInfoPacket); \ + Func(ScriptCustomEventPacket); \ + Func(CreatePhotoPacket); \ + Func(EduUriResourcePacket); \ + Func(NpcDialoguePacket); \ + Func(SimulationTypePacket); \ + Func(AddVolumeEntityPacket); \ + Func(AnimateEntityPacket); \ + Func(CameraShakePacket); \ + Func(CodeBuilderSourcePacket); \ + Func(ClientboundDebugRendererPacket); \ + Func(CorrectPlayerMovePredictionPacket); \ + Func(PlayerStartItemCooldownPacket); \ + Func(ScriptMessagePacket); \ + Func(SetDisplayObjectivePacket); \ + Func(SetScorePacket); \ + Func(SetScoreboardIdentityPacket); \ + Func(SetTitlePacket); \ + Func(ShowCreditsPacket); \ + Func(ShowStoreOfferPacket); \ + Func(SpawnExperienceOrbPacket); \ + Func(SpawnParticleEffectPacket); \ + Func(StructureBlockUpdatePacket); \ + Func(StructureTemplateDataRequestPacket); \ + Func(SubClientLoginPacket); \ + Func(SimpleEventPacket); \ + Func(AddBehaviorTreePacket); \ + Func(AvailableActorIdentifiersPacket); \ + Func(AvailableCommandsPacket); \ + Func(BiomeDefinitionListPacket); \ + Func(CraftingDataPacket); \ + Func(CreativeContentPacket); \ + Func(GameRulesChangedPacket); \ + Func(ResourcePackStackPacket); \ + Func(ResourcePacksInfoPacket); \ + Func(ItemComponentPacket); \ + Func(SetSpawnPositionPacket); \ + Func(StartGamePacket); \ + Func(PlayerFogPacket); \ + Func(AddPlayerPacket); \ + Func(LoginPacket); \ + Func(BlockPickRequestPacket); \ + Func(DisconnectPacket); \ + Func(GuiDataPickItemPacket); \ + Func(SetLocalPlayerAsInitializedPacket); \ + Func(TextPacket); \ + Func(PlayerListPacket); \ + Func(PlayStatusPacket); \ + Func(ClientCacheStatusPacket); \ + Func(SetDifficultyPacket); \ + Func(ChangeDimensionPacket); \ + Func(ResourcePackClientResponsePacket); \ + Func(SetActorLinkPacket); \ + Func(UpdatePlayerGameTypePacket); \ + Func(RespawnPacket); \ + Func(TakeItemActorPacket); \ + Func(PlayerHotbarPacket); \ + Func(CommandOutputPacket); \ + Func(TickSyncPacket); \ + Func(CommandRequestPacket); \ + Func(ContainerOpenPacket); \ + Func(ContainerClosePacket); \ + Func(InventoryContentPacket); \ + Func(ServerSettingsResponsePacket); \ + Func(InventorySlotPacket); \ + Func(UpdateBlockSyncedPacket); \ + Func(PlayerActionPacket); \ + Func(ItemStackRequestPacket); \ + Func(ItemStackResponsePacket); \ + Func(AdventureSettingsPacket); \ + Func(BlockActorDataPacket); \ + Func(EventPacket); \ + Func(SetHealthPacket); \ + Func(MobEquipmentPacket); \ + Func(MotionPredictionHintsPacket); \ + Func(AddItemActorPacket); \ + Func(UpdateAttributesPacket); \ + Func(InteractPacket); \ + Func(ActorEventPacket); \ + Func(LevelEventPacket); \ + Func(NetworkChunkPublisherUpdatePacket); \ + Func(AnimatePacket); \ + Func(InventoryTransactionPacket); \ + Func(AddActorPacket); \ + Func(MapInfoRequestPacket); \ + Func(UpdateSubChunkBlocksPacket); \ + Func(SetActorMotionPacket); \ + Func(LevelSoundEventPacket); \ + Func(SubChunkPacket); \ + Func(SubChunkRequestPacket); \ + Func(ClientCacheMissResponsePacket); \ + Func(ClientCacheBlobStatusPacket); \ + Func(LevelChunkPacket); \ + Func(SetActorDataPacket); \ + Func(UpdateBlockPacket); \ + Func(MoveActorDeltaPacket); \ + Func(MovePlayerPacket); \ + Func(PlayerAuthInputPacket); + +#pragma endregion + +#ifdef GENERATE_PACKET + +template +inline void* VFTABLE_ADDR; +template +inline void* getVftableAddr() +{ +#define INIT_ADDR(type) \ + VFTABLE_ADDR = dlsym_real("??_7" #type "@@6B@"); + static bool inited = ([]() { + ForEachPacket(INIT_ADDR); + return true; + })(); + return VFTABLE_ADDR; +#undef INIT_ADDR +} + +std::string getClassName(Packet* packet) +{ +#define RETURN_IF_FIND(type) \ + if (getVftableAddr() == *(void**)packet) \ + return #type; + ForEachPacket(RETURN_IF_FIND); + return ""; +#undef RETURN_IF_FIND +} + +inline void forEachPacket(std::function callback) +{ + int packetId = 0; + while (packetId < 200) + { + auto packet = MinecraftPackets::createPacket(packetId); + if (packet) + { + auto size = _msize((void**)packet.get() - 2); + //logger.warn("Packet: {},{},{},{},{}", magic_enum::enum_name((MinecraftPacketIds)packetId), packet->getName(), getClassName(packet.get()), packetId, size); + + auto className = getClassName(packet.get()); + callback(*packet, className, size - 16); + } + packetId++; + } +} + +#pragma region Packet Command + +#include +#include +#include +using Param = DynamicCommand::ParameterData; +using ParamType = DynamicCommand::ParameterType; +using ParamIndex = DynamicCommandInstance::ParameterIndex; +using Result = DynamicCommand::Result; + +inline bool replaceString(std::string& content, std::string const& start, std::string const& end, std::string const& str, size_t offset = 0, bool exclude = true) +{ + auto startOffset = content.find(start, offset); + if (startOffset == content.npos) + return false; + if (exclude) + startOffset += start.size(); + auto endOffset = end.empty() ? content.npos : content.find(end, startOffset); + + if (endOffset != content.npos && !exclude) + { + endOffset += sizeof(end); + } + content.replace(startOffset, endOffset - startOffset, str); + return true; + +} +void onExecute(DynamicCommand const& cmd, CommandOrigin const& origin, CommandOutput& output, + std::unordered_map& results) +{ + auto file = ReadAllFile(__FILE__, false); + if (!file) + __debugbreak(); + auto& content = file.value(); + + std::ostringstream oss; + + oss << std::endl; + forEachPacket([&](Packet const& packet, std::string className, size_t size) { + oss << fmt::format("static_assert(sizeof({}) == 0x{:X}, \"size of {} should be {}\");\n", className, size, className, size); + }); + oss << std::endl; + replaceString(content, "#ifdef SIZE_STATIC_ASSERT\n", "#endif", oss.str()); + oss.clear(); + oss.str(""); + + oss << std::endl; + forEachPacket([&](Packet const& packet, std::string className, size_t size) { + oss << fmt::format("static_assert(sizeof({}) == 0x{:X} || sizeof({}) == 48, \"size of {} should be {} or 48(default)\");\n", className, size, className, className, size); + }); + oss << std::endl; + replaceString(content, "#ifdef SIZE_STATIC_ASSERT_IF_DEFINE\n", "#endif", oss.str()); + oss.clear(); + oss.str(""); + + oss << std::endl; + forEachPacket([&](Packet const& packet, std::string className, size_t size) { + oss << fmt::format("#include \n", className); + }); + oss << std::endl; + replaceString(content, "#ifdef INCLUDE_ALL_PACKET\n", "#endif", oss.str()); + oss.clear(); + oss.str(""); + WriteAllFile(__FILE__, content, false); + output.success("Pkt Command execute Success"); +} + +TClasslessInstanceHook2("SetupPacketCommand_startServerThread", void, "?startServerThread@ServerInstance@@QEAAXXZ") +{ + original(this); + Global = Global->getLevel(); + auto command = DynamicCommand::createCommand("pkt", "packet"); + command->addOverload(); + command->setCallback(onExecute); + DynamicCommand::setup(std::move(command)); +} + +#pragma endregion + +#endif // GENERATE_PACKET + +#ifdef SIZE_STATIC_ASSERT + +static_assert(sizeof(LoginPacket) == 0x40, "size of LoginPacket should be 64"); +static_assert(sizeof(PlayStatusPacket) == 0x38, "size of PlayStatusPacket should be 56"); +static_assert(sizeof(ServerToClientHandshakePacket) == 0x50, "size of ServerToClientHandshakePacket should be 80"); +static_assert(sizeof(ClientToServerHandshakePacket) == 0x30, "size of ClientToServerHandshakePacket should be 48"); +static_assert(sizeof(DisconnectPacket) == 0x58, "size of DisconnectPacket should be 88"); +static_assert(sizeof(ResourcePacksInfoPacket) == 0x68, "size of ResourcePacksInfoPacket should be 104"); +static_assert(sizeof(ResourcePackStackPacket) == 0x128, "size of ResourcePackStackPacket should be 296"); +static_assert(sizeof(ResourcePackClientResponsePacket) == 0x48, "size of ResourcePackClientResponsePacket should be 72"); +static_assert(sizeof(TextPacket) == 0xD8, "size of TextPacket should be 216"); +static_assert(sizeof(SetTimePacket) == 0x38, "size of SetTimePacket should be 56"); +static_assert(sizeof(StartGamePacket) == 0x630, "size of StartGamePacket should be 1584"); +static_assert(sizeof(AddPlayerPacket) == 0x2E8, "size of AddPlayerPacket should be 744"); +static_assert(sizeof(AddActorPacket) == 0x180, "size of AddActorPacket should be 384"); +static_assert(sizeof(RemoveActorPacket) == 0x38, "size of RemoveActorPacket should be 56"); +static_assert(sizeof(AddItemActorPacket) == 0x100, "size of AddItemActorPacket should be 256"); +static_assert(sizeof(TakeItemActorPacket) == 0x40, "size of TakeItemActorPacket should be 64"); +static_assert(sizeof(MoveActorAbsolutePacket) == 0x50, "size of MoveActorAbsolutePacket should be 80"); +static_assert(sizeof(MovePlayerPacket) == 0x70, "size of MovePlayerPacket should be 112"); +static_assert(sizeof(PassengerJumpPacket) == 0x38, "size of PassengerJumpPacket should be 56"); +static_assert(sizeof(UpdateBlockPacket) == 0x48, "size of UpdateBlockPacket should be 72"); +static_assert(sizeof(AddPaintingPacket) == 0x70, "size of AddPaintingPacket should be 112"); +static_assert(sizeof(TickSyncPacket) == 0x40, "size of TickSyncPacket should be 64"); +static_assert(sizeof(LevelSoundEventPacketV1) == 0x50, "size of LevelSoundEventPacketV1 should be 80"); +static_assert(sizeof(LevelEventPacket) == 0x48, "size of LevelEventPacket should be 72"); +static_assert(sizeof(BlockEventPacket) == 0x48, "size of BlockEventPacket should be 72"); +static_assert(sizeof(ActorEventPacket) == 0x40, "size of ActorEventPacket should be 64"); +static_assert(sizeof(MobEffectPacket) == 0x50, "size of MobEffectPacket should be 80"); +static_assert(sizeof(UpdateAttributesPacket) == 0x58, "size of UpdateAttributesPacket should be 88"); +static_assert(sizeof(InventoryTransactionPacket) == 0x60, "size of InventoryTransactionPacket should be 96"); +static_assert(sizeof(MobEquipmentPacket) == 0xC8, "size of MobEquipmentPacket should be 200"); +static_assert(sizeof(MobArmorEquipmentPacket) == 0x238, "size of MobArmorEquipmentPacket should be 568"); +static_assert(sizeof(InteractPacket) == 0x50, "size of InteractPacket should be 80"); +static_assert(sizeof(BlockPickRequestPacket) == 0x40, "size of BlockPickRequestPacket should be 64"); +static_assert(sizeof(ActorPickRequestPacket) == 0x40, "size of ActorPickRequestPacket should be 64"); +static_assert(sizeof(PlayerActionPacket) == 0x50, "size of PlayerActionPacket should be 80"); +static_assert(sizeof(HurtArmorPacket) == 0x40, "size of HurtArmorPacket should be 64"); +static_assert(sizeof(SetActorDataPacket) == 0x58, "size of SetActorDataPacket should be 88"); +static_assert(sizeof(SetActorMotionPacket) == 0x48, "size of SetActorMotionPacket should be 72"); +static_assert(sizeof(SetActorLinkPacket) == 0x50, "size of SetActorLinkPacket should be 80"); +static_assert(sizeof(SetHealthPacket) == 0x38, "size of SetHealthPacket should be 56"); +static_assert(sizeof(SetSpawnPositionPacket) == 0x50, "size of SetSpawnPositionPacket should be 80"); +static_assert(sizeof(AnimatePacket) == 0x40, "size of AnimatePacket should be 64"); +static_assert(sizeof(RespawnPacket) == 0x48, "size of RespawnPacket should be 72"); +static_assert(sizeof(ContainerOpenPacket) == 0x48, "size of ContainerOpenPacket should be 72"); +static_assert(sizeof(ContainerClosePacket) == 0x38, "size of ContainerClosePacket should be 56"); +static_assert(sizeof(PlayerHotbarPacket) == 0x38, "size of PlayerHotbarPacket should be 56"); +static_assert(sizeof(InventoryContentPacket) == 0x50, "size of InventoryContentPacket should be 80"); +static_assert(sizeof(InventorySlotPacket) == 0xB8, "size of InventorySlotPacket should be 184"); +static_assert(sizeof(ContainerSetDataPacket) == 0x40, "size of ContainerSetDataPacket should be 64"); +static_assert(sizeof(CraftingDataPacket) == 0x98, "size of CraftingDataPacket should be 152"); +static_assert(sizeof(CraftingEventPacket) == 0x78, "size of CraftingEventPacket should be 120"); +static_assert(sizeof(GuiDataPickItemPacket) == 0x78, "size of GuiDataPickItemPacket should be 120"); +static_assert(sizeof(AdventureSettingsPacket) == 0x50, "size of AdventureSettingsPacket should be 80"); +static_assert(sizeof(BlockActorDataPacket) == 0x58, "size of BlockActorDataPacket should be 88"); +static_assert(sizeof(PlayerInputPacket) == 0x40, "size of PlayerInputPacket should be 64"); +static_assert(sizeof(LevelChunkPacket) == 0x88, "size of LevelChunkPacket should be 136"); +static_assert(sizeof(SetCommandsEnabledPacket) == 0x38, "size of SetCommandsEnabledPacket should be 56"); +static_assert(sizeof(SetDifficultyPacket) == 0x38, "size of SetDifficultyPacket should be 56"); +static_assert(sizeof(ChangeDimensionPacket) == 0x48, "size of ChangeDimensionPacket should be 72"); +static_assert(sizeof(SetPlayerGameTypePacket) == 0x38, "size of SetPlayerGameTypePacket should be 56"); +static_assert(sizeof(PlayerListPacket) == 0x50, "size of PlayerListPacket should be 80"); +static_assert(sizeof(SimpleEventPacket) == 0x38, "size of SimpleEventPacket should be 56"); +static_assert(sizeof(EventPacket) == 0x140, "size of EventPacket should be 320"); +static_assert(sizeof(SpawnExperienceOrbPacket) == 0x40, "size of SpawnExperienceOrbPacket should be 64"); +static_assert(sizeof(ClientboundMapItemDataPacket) == 0xB8, "size of ClientboundMapItemDataPacket should be 184"); +static_assert(sizeof(MapInfoRequestPacket) == 0x38, "size of MapInfoRequestPacket should be 56"); +static_assert(sizeof(RequestChunkRadiusPacket) == 0x38, "size of RequestChunkRadiusPacket should be 56"); +static_assert(sizeof(ChunkRadiusUpdatedPacket) == 0x38, "size of ChunkRadiusUpdatedPacket should be 56"); +static_assert(sizeof(ItemFrameDropItemPacket) == 0x40, "size of ItemFrameDropItemPacket should be 64"); +static_assert(sizeof(GameRulesChangedPacket) == 0x48, "size of GameRulesChangedPacket should be 72"); +static_assert(sizeof(CameraPacket) == 0x40, "size of CameraPacket should be 64"); +static_assert(sizeof(BossEventPacket) == 0x80, "size of BossEventPacket should be 128"); +static_assert(sizeof(ShowCreditsPacket) == 0x40, "size of ShowCreditsPacket should be 64"); +static_assert(sizeof(AvailableCommandsPacket) == 0xC0, "size of AvailableCommandsPacket should be 192"); +static_assert(sizeof(CommandRequestPacket) == 0x98, "size of CommandRequestPacket should be 152"); +static_assert(sizeof(CommandBlockUpdatePacket) == 0xB0, "size of CommandBlockUpdatePacket should be 176"); +static_assert(sizeof(CommandOutputPacket) == 0xA0, "size of CommandOutputPacket should be 160"); +static_assert(sizeof(UpdateTradePacket) == 0x90, "size of UpdateTradePacket should be 144"); +static_assert(sizeof(UpdateEquipPacket) == 0x58, "size of UpdateEquipPacket should be 88"); +static_assert(sizeof(ResourcePackDataInfoPacket) == 0x88, "size of ResourcePackDataInfoPacket should be 136"); +static_assert(sizeof(ResourcePackChunkDataPacket) == 0x78, "size of ResourcePackChunkDataPacket should be 120"); +static_assert(sizeof(ResourcePackChunkRequestPacket) == 0x58, "size of ResourcePackChunkRequestPacket should be 88"); +static_assert(sizeof(TransferPacket) == 0x58, "size of TransferPacket should be 88"); +static_assert(sizeof(PlaySoundPacket) == 0x68, "size of PlaySoundPacket should be 104"); +static_assert(sizeof(StopSoundPacket) == 0x58, "size of StopSoundPacket should be 88"); +static_assert(sizeof(SetTitlePacket) == 0xA8, "size of SetTitlePacket should be 168"); +static_assert(sizeof(AddBehaviorTreePacket) == 0x50, "size of AddBehaviorTreePacket should be 80"); +static_assert(sizeof(StructureBlockUpdatePacket) == 0xF0, "size of StructureBlockUpdatePacket should be 240"); +static_assert(sizeof(ShowStoreOfferPacket) == 0x78, "size of ShowStoreOfferPacket should be 120"); +static_assert(sizeof(PurchaseReceiptPacket) == 0x48, "size of PurchaseReceiptPacket should be 72"); +static_assert(sizeof(PlayerSkinPacket) == 0x2E8, "size of PlayerSkinPacket should be 744"); +static_assert(sizeof(SubClientLoginPacket) == 0x38, "size of SubClientLoginPacket should be 56"); +static_assert(sizeof(AutomationClientConnectPacket) == 0x50, "size of AutomationClientConnectPacket should be 80"); +static_assert(sizeof(SetLastHurtByPacket) == 0x38, "size of SetLastHurtByPacket should be 56"); +static_assert(sizeof(BookEditPacket) == 0xA0, "size of BookEditPacket should be 160"); +static_assert(sizeof(NpcRequestPacket) == 0x88, "size of NpcRequestPacket should be 136"); +static_assert(sizeof(PhotoTransferPacket) == 0xC0, "size of PhotoTransferPacket should be 192"); +static_assert(sizeof(ModalFormRequestPacket) == 0x58, "size of ModalFormRequestPacket should be 88"); +static_assert(sizeof(ModalFormResponsePacket) == 0x58, "size of ModalFormResponsePacket should be 88"); +static_assert(sizeof(ServerSettingsRequestPacket) == 0x30, "size of ServerSettingsRequestPacket should be 48"); +static_assert(sizeof(ServerSettingsResponsePacket) == 0x58, "size of ServerSettingsResponsePacket should be 88"); +static_assert(sizeof(ShowProfilePacket) == 0x50, "size of ShowProfilePacket should be 80"); +static_assert(sizeof(SetDefaultGameTypePacket) == 0x38, "size of SetDefaultGameTypePacket should be 56"); +static_assert(sizeof(RemoveObjectivePacket) == 0x50, "size of RemoveObjectivePacket should be 80"); +static_assert(sizeof(SetDisplayObjectivePacket) == 0xB8, "size of SetDisplayObjectivePacket should be 184"); +static_assert(sizeof(SetScorePacket) == 0x50, "size of SetScorePacket should be 80"); +static_assert(sizeof(LabTablePacket) == 0x48, "size of LabTablePacket should be 72"); +static_assert(sizeof(UpdateBlockSyncedPacket) == 0x58, "size of UpdateBlockSyncedPacket should be 88"); +static_assert(sizeof(MoveActorDeltaPacket) == 0x70, "size of MoveActorDeltaPacket should be 112"); +static_assert(sizeof(SetScoreboardIdentityPacket) == 0x50, "size of SetScoreboardIdentityPacket should be 80"); +static_assert(sizeof(SetLocalPlayerAsInitializedPacket) == 0x38, "size of SetLocalPlayerAsInitializedPacket should be 56"); +static_assert(sizeof(UpdateSoftEnumPacket) == 0x70, "size of UpdateSoftEnumPacket should be 112"); +static_assert(sizeof(NetworkStackLatencyPacket) == 0x40, "size of NetworkStackLatencyPacket should be 64"); +static_assert(sizeof(ScriptCustomEventPacket) == 0x60, "size of ScriptCustomEventPacket should be 96"); +static_assert(sizeof(SpawnParticleEffectPacket) == 0x70, "size of SpawnParticleEffectPacket should be 112"); +static_assert(sizeof(AvailableActorIdentifiersPacket) == 0x48, "size of AvailableActorIdentifiersPacket should be 72"); +static_assert(sizeof(LevelSoundEventPacketV2) == 0x70, "size of LevelSoundEventPacketV2 should be 112"); +static_assert(sizeof(NetworkChunkPublisherUpdatePacket) == 0x40, "size of NetworkChunkPublisherUpdatePacket should be 64"); +static_assert(sizeof(BiomeDefinitionListPacket) == 0x48, "size of BiomeDefinitionListPacket should be 72"); +static_assert(sizeof(LevelSoundEventPacket) == 0x70, "size of LevelSoundEventPacket should be 112"); +static_assert(sizeof(LevelEventGenericPacket) == 0x40, "size of LevelEventGenericPacket should be 64"); +static_assert(sizeof(LecternUpdatePacket) == 0x48, "size of LecternUpdatePacket should be 72"); +static_assert(sizeof(AddEntityPacket) == 0x38, "size of AddEntityPacket should be 56"); +static_assert(sizeof(RemoveEntityPacket) == 0x38, "size of RemoveEntityPacket should be 56"); +static_assert(sizeof(ClientCacheStatusPacket) == 0x38, "size of ClientCacheStatusPacket should be 56"); +static_assert(sizeof(OnScreenTextureAnimationPacket) == 0x38, "size of OnScreenTextureAnimationPacket should be 56"); +static_assert(sizeof(MapCreateLockedCopyPacket) == 0x40, "size of MapCreateLockedCopyPacket should be 64"); +static_assert(sizeof(StructureTemplateDataRequestPacket) == 0xC8, "size of StructureTemplateDataRequestPacket should be 200"); +static_assert(sizeof(StructureTemplateDataResponsePacket) == 0x60, "size of StructureTemplateDataResponsePacket should be 96"); +static_assert(sizeof(ClientCacheBlobStatusPacket) == 0x60, "size of ClientCacheBlobStatusPacket should be 96"); +static_assert(sizeof(ClientCacheMissResponsePacket) == 0x88, "size of ClientCacheMissResponsePacket should be 136"); +static_assert(sizeof(EducationSettingsPacket) == 0x178, "size of EducationSettingsPacket should be 376"); +static_assert(sizeof(EmotePacket) == 0x60, "size of EmotePacket should be 96"); +static_assert(sizeof(MultiplayerSettingsPacket) == 0x38, "size of MultiplayerSettingsPacket should be 56"); +static_assert(sizeof(SettingsCommandPacket) == 0x58, "size of SettingsCommandPacket should be 88"); +static_assert(sizeof(AnvilDamagePacket) == 0x40, "size of AnvilDamagePacket should be 64"); +static_assert(sizeof(CompletedUsingItemPacket) == 0x38, "size of CompletedUsingItemPacket should be 56"); +static_assert(sizeof(NetworkSettingsPacket) == 0x38, "size of NetworkSettingsPacket should be 56"); +static_assert(sizeof(PlayerAuthInputPacket) == 0xA8, "size of PlayerAuthInputPacket should be 168"); +static_assert(sizeof(CreativeContentPacket) == 0x50, "size of CreativeContentPacket should be 80"); +static_assert(sizeof(PlayerEnchantOptionsPacket) == 0x48, "size of PlayerEnchantOptionsPacket should be 72"); +static_assert(sizeof(ItemStackRequestPacket) == 0x38, "size of ItemStackRequestPacket should be 56"); +static_assert(sizeof(ItemStackResponsePacket) == 0x48, "size of ItemStackResponsePacket should be 72"); +static_assert(sizeof(PlayerArmorDamagePacket) == 0x40, "size of PlayerArmorDamagePacket should be 64"); +static_assert(sizeof(CodeBuilderPacket) == 0x58, "size of CodeBuilderPacket should be 88"); +static_assert(sizeof(UpdatePlayerGameTypePacket) == 0x40, "size of UpdatePlayerGameTypePacket should be 64"); +static_assert(sizeof(EmoteListPacket) == 0x50, "size of EmoteListPacket should be 80"); +static_assert(sizeof(PositionTrackingDBServerBroadcastPacket) == 0x50, "size of PositionTrackingDBServerBroadcastPacket should be 80"); +static_assert(sizeof(PositionTrackingDBClientRequestPacket) == 0x38, "size of PositionTrackingDBClientRequestPacket should be 56"); +static_assert(sizeof(DebugInfoPacket) == 0x58, "size of DebugInfoPacket should be 88"); +static_assert(sizeof(PacketViolationWarningPacket) == 0x60, "size of PacketViolationWarningPacket should be 96"); +static_assert(sizeof(MotionPredictionHintsPacket) == 0x48, "size of MotionPredictionHintsPacket should be 72"); +static_assert(sizeof(AnimateEntityPacket) == 0xD8, "size of AnimateEntityPacket should be 216"); +static_assert(sizeof(CameraShakePacket) == 0x40, "size of CameraShakePacket should be 64"); +static_assert(sizeof(PlayerFogPacket) == 0x48, "size of PlayerFogPacket should be 72"); +static_assert(sizeof(CorrectPlayerMovePredictionPacket) == 0x58, "size of CorrectPlayerMovePredictionPacket should be 88"); +static_assert(sizeof(ItemComponentPacket) == 0x48, "size of ItemComponentPacket should be 72"); +static_assert(sizeof(FilterTextPacket) == 0x58, "size of FilterTextPacket should be 88"); +static_assert(sizeof(ClientboundDebugRendererPacket) == 0x88, "size of ClientboundDebugRendererPacket should be 136"); +static_assert(sizeof(SyncActorPropertyPacket) == 0x48, "size of SyncActorPropertyPacket should be 72"); +static_assert(sizeof(AddVolumeEntityPacket) == 0x100, "size of AddVolumeEntityPacket should be 256"); +static_assert(sizeof(RemoveVolumeEntityPacket) == 0x38, "size of RemoveVolumeEntityPacket should be 56"); +static_assert(sizeof(SimulationTypePacket) == 0x38, "size of SimulationTypePacket should be 56"); +static_assert(sizeof(NpcDialoguePacket) == 0xC0, "size of NpcDialoguePacket should be 192"); +static_assert(sizeof(EduUriResourcePacket) == 0x70, "size of EduUriResourcePacket should be 112"); +static_assert(sizeof(CreatePhotoPacket) == 0x78, "size of CreatePhotoPacket should be 120"); +static_assert(sizeof(UpdateSubChunkBlocksPacket) == 0x70, "size of UpdateSubChunkBlocksPacket should be 112"); +static_assert(sizeof(SubChunkPacket) == 0x60, "size of SubChunkPacket should be 96"); +static_assert(sizeof(SubChunkRequestPacket) == 0x80, "size of SubChunkRequestPacket should be 128"); +static_assert(sizeof(PlayerStartItemCooldownPacket) == 0x58, "size of PlayerStartItemCooldownPacket should be 88"); +static_assert(sizeof(ScriptMessagePacket) == 0x70, "size of ScriptMessagePacket should be 112"); +static_assert(sizeof(CodeBuilderSourcePacket) == 0x58, "size of CodeBuilderSourcePacket should be 88"); + +#endif // SIZE_STATIC_ASSERT + +#ifdef SIZE_STATIC_ASSERT_IF_DEFINE + +static_assert(sizeof(LoginPacket) == 0x40 || sizeof(LoginPacket) == 48, "size of LoginPacket should be 64 or 48(default)"); +static_assert(sizeof(PlayStatusPacket) == 0x38 || sizeof(PlayStatusPacket) == 48, "size of PlayStatusPacket should be 56 or 48(default)"); +static_assert(sizeof(ServerToClientHandshakePacket) == 0x50 || sizeof(ServerToClientHandshakePacket) == 48, "size of ServerToClientHandshakePacket should be 80 or 48(default)"); +static_assert(sizeof(ClientToServerHandshakePacket) == 0x30 || sizeof(ClientToServerHandshakePacket) == 48, "size of ClientToServerHandshakePacket should be 48 or 48(default)"); +static_assert(sizeof(DisconnectPacket) == 0x58 || sizeof(DisconnectPacket) == 48, "size of DisconnectPacket should be 88 or 48(default)"); +static_assert(sizeof(ResourcePacksInfoPacket) == 0x68 || sizeof(ResourcePacksInfoPacket) == 48, "size of ResourcePacksInfoPacket should be 104 or 48(default)"); +static_assert(sizeof(ResourcePackStackPacket) == 0x128 || sizeof(ResourcePackStackPacket) == 48, "size of ResourcePackStackPacket should be 296 or 48(default)"); +static_assert(sizeof(ResourcePackClientResponsePacket) == 0x48 || sizeof(ResourcePackClientResponsePacket) == 48, "size of ResourcePackClientResponsePacket should be 72 or 48(default)"); +static_assert(sizeof(TextPacket) == 0xD8 || sizeof(TextPacket) == 48, "size of TextPacket should be 216 or 48(default)"); +static_assert(sizeof(SetTimePacket) == 0x38 || sizeof(SetTimePacket) == 48, "size of SetTimePacket should be 56 or 48(default)"); +static_assert(sizeof(StartGamePacket) == 0x630 || sizeof(StartGamePacket) == 48, "size of StartGamePacket should be 1584 or 48(default)"); +static_assert(sizeof(AddPlayerPacket) == 0x2E8 || sizeof(AddPlayerPacket) == 48, "size of AddPlayerPacket should be 744 or 48(default)"); +static_assert(sizeof(AddActorPacket) == 0x180 || sizeof(AddActorPacket) == 48, "size of AddActorPacket should be 384 or 48(default)"); +static_assert(sizeof(RemoveActorPacket) == 0x38 || sizeof(RemoveActorPacket) == 48, "size of RemoveActorPacket should be 56 or 48(default)"); +static_assert(sizeof(AddItemActorPacket) == 0x100 || sizeof(AddItemActorPacket) == 48, "size of AddItemActorPacket should be 256 or 48(default)"); +static_assert(sizeof(TakeItemActorPacket) == 0x40 || sizeof(TakeItemActorPacket) == 48, "size of TakeItemActorPacket should be 64 or 48(default)"); +static_assert(sizeof(MoveActorAbsolutePacket) == 0x50 || sizeof(MoveActorAbsolutePacket) == 48, "size of MoveActorAbsolutePacket should be 80 or 48(default)"); +static_assert(sizeof(MovePlayerPacket) == 0x70 || sizeof(MovePlayerPacket) == 48, "size of MovePlayerPacket should be 112 or 48(default)"); +static_assert(sizeof(PassengerJumpPacket) == 0x38 || sizeof(PassengerJumpPacket) == 48, "size of PassengerJumpPacket should be 56 or 48(default)"); +static_assert(sizeof(UpdateBlockPacket) == 0x48 || sizeof(UpdateBlockPacket) == 48, "size of UpdateBlockPacket should be 72 or 48(default)"); +static_assert(sizeof(AddPaintingPacket) == 0x70 || sizeof(AddPaintingPacket) == 48, "size of AddPaintingPacket should be 112 or 48(default)"); +static_assert(sizeof(TickSyncPacket) == 0x40 || sizeof(TickSyncPacket) == 48, "size of TickSyncPacket should be 64 or 48(default)"); +static_assert(sizeof(LevelSoundEventPacketV1) == 0x50 || sizeof(LevelSoundEventPacketV1) == 48, "size of LevelSoundEventPacketV1 should be 80 or 48(default)"); +static_assert(sizeof(LevelEventPacket) == 0x48 || sizeof(LevelEventPacket) == 48, "size of LevelEventPacket should be 72 or 48(default)"); +static_assert(sizeof(BlockEventPacket) == 0x48 || sizeof(BlockEventPacket) == 48, "size of BlockEventPacket should be 72 or 48(default)"); +static_assert(sizeof(ActorEventPacket) == 0x40 || sizeof(ActorEventPacket) == 48, "size of ActorEventPacket should be 64 or 48(default)"); +static_assert(sizeof(MobEffectPacket) == 0x50 || sizeof(MobEffectPacket) == 48, "size of MobEffectPacket should be 80 or 48(default)"); +static_assert(sizeof(UpdateAttributesPacket) == 0x58 || sizeof(UpdateAttributesPacket) == 48, "size of UpdateAttributesPacket should be 88 or 48(default)"); +static_assert(sizeof(InventoryTransactionPacket) == 0x60 || sizeof(InventoryTransactionPacket) == 48, "size of InventoryTransactionPacket should be 96 or 48(default)"); +static_assert(sizeof(MobEquipmentPacket) == 0xC8 || sizeof(MobEquipmentPacket) == 48, "size of MobEquipmentPacket should be 200 or 48(default)"); +static_assert(sizeof(MobArmorEquipmentPacket) == 0x238 || sizeof(MobArmorEquipmentPacket) == 48, "size of MobArmorEquipmentPacket should be 568 or 48(default)"); +static_assert(sizeof(InteractPacket) == 0x50 || sizeof(InteractPacket) == 48, "size of InteractPacket should be 80 or 48(default)"); +static_assert(sizeof(BlockPickRequestPacket) == 0x40 || sizeof(BlockPickRequestPacket) == 48, "size of BlockPickRequestPacket should be 64 or 48(default)"); +static_assert(sizeof(ActorPickRequestPacket) == 0x40 || sizeof(ActorPickRequestPacket) == 48, "size of ActorPickRequestPacket should be 64 or 48(default)"); +static_assert(sizeof(PlayerActionPacket) == 0x50 || sizeof(PlayerActionPacket) == 48, "size of PlayerActionPacket should be 80 or 48(default)"); +static_assert(sizeof(HurtArmorPacket) == 0x40 || sizeof(HurtArmorPacket) == 48, "size of HurtArmorPacket should be 64 or 48(default)"); +static_assert(sizeof(SetActorDataPacket) == 0x58 || sizeof(SetActorDataPacket) == 48, "size of SetActorDataPacket should be 88 or 48(default)"); +static_assert(sizeof(SetActorMotionPacket) == 0x48 || sizeof(SetActorMotionPacket) == 48, "size of SetActorMotionPacket should be 72 or 48(default)"); +static_assert(sizeof(SetActorLinkPacket) == 0x50 || sizeof(SetActorLinkPacket) == 48, "size of SetActorLinkPacket should be 80 or 48(default)"); +static_assert(sizeof(SetHealthPacket) == 0x38 || sizeof(SetHealthPacket) == 48, "size of SetHealthPacket should be 56 or 48(default)"); +static_assert(sizeof(SetSpawnPositionPacket) == 0x50 || sizeof(SetSpawnPositionPacket) == 48, "size of SetSpawnPositionPacket should be 80 or 48(default)"); +static_assert(sizeof(AnimatePacket) == 0x40 || sizeof(AnimatePacket) == 48, "size of AnimatePacket should be 64 or 48(default)"); +static_assert(sizeof(RespawnPacket) == 0x48 || sizeof(RespawnPacket) == 48, "size of RespawnPacket should be 72 or 48(default)"); +static_assert(sizeof(ContainerOpenPacket) == 0x48 || sizeof(ContainerOpenPacket) == 48, "size of ContainerOpenPacket should be 72 or 48(default)"); +static_assert(sizeof(ContainerClosePacket) == 0x38 || sizeof(ContainerClosePacket) == 48, "size of ContainerClosePacket should be 56 or 48(default)"); +static_assert(sizeof(PlayerHotbarPacket) == 0x38 || sizeof(PlayerHotbarPacket) == 48, "size of PlayerHotbarPacket should be 56 or 48(default)"); +static_assert(sizeof(InventoryContentPacket) == 0x50 || sizeof(InventoryContentPacket) == 48, "size of InventoryContentPacket should be 80 or 48(default)"); +static_assert(sizeof(InventorySlotPacket) == 0xB8 || sizeof(InventorySlotPacket) == 48, "size of InventorySlotPacket should be 184 or 48(default)"); +static_assert(sizeof(ContainerSetDataPacket) == 0x40 || sizeof(ContainerSetDataPacket) == 48, "size of ContainerSetDataPacket should be 64 or 48(default)"); +static_assert(sizeof(CraftingDataPacket) == 0x98 || sizeof(CraftingDataPacket) == 48, "size of CraftingDataPacket should be 152 or 48(default)"); +static_assert(sizeof(CraftingEventPacket) == 0x78 || sizeof(CraftingEventPacket) == 48, "size of CraftingEventPacket should be 120 or 48(default)"); +static_assert(sizeof(GuiDataPickItemPacket) == 0x78 || sizeof(GuiDataPickItemPacket) == 48, "size of GuiDataPickItemPacket should be 120 or 48(default)"); +static_assert(sizeof(AdventureSettingsPacket) == 0x50 || sizeof(AdventureSettingsPacket) == 48, "size of AdventureSettingsPacket should be 80 or 48(default)"); +static_assert(sizeof(BlockActorDataPacket) == 0x58 || sizeof(BlockActorDataPacket) == 48, "size of BlockActorDataPacket should be 88 or 48(default)"); +static_assert(sizeof(PlayerInputPacket) == 0x40 || sizeof(PlayerInputPacket) == 48, "size of PlayerInputPacket should be 64 or 48(default)"); +static_assert(sizeof(LevelChunkPacket) == 0x88 || sizeof(LevelChunkPacket) == 48, "size of LevelChunkPacket should be 136 or 48(default)"); +static_assert(sizeof(SetCommandsEnabledPacket) == 0x38 || sizeof(SetCommandsEnabledPacket) == 48, "size of SetCommandsEnabledPacket should be 56 or 48(default)"); +static_assert(sizeof(SetDifficultyPacket) == 0x38 || sizeof(SetDifficultyPacket) == 48, "size of SetDifficultyPacket should be 56 or 48(default)"); +static_assert(sizeof(ChangeDimensionPacket) == 0x48 || sizeof(ChangeDimensionPacket) == 48, "size of ChangeDimensionPacket should be 72 or 48(default)"); +static_assert(sizeof(SetPlayerGameTypePacket) == 0x38 || sizeof(SetPlayerGameTypePacket) == 48, "size of SetPlayerGameTypePacket should be 56 or 48(default)"); +//static_assert(sizeof(PlayerListPacket) == 0x50 || sizeof(PlayerListPacket) == 48, "size of PlayerListPacket should be 80 or 48(default)"); +static_assert(sizeof(SimpleEventPacket) == 0x38 || sizeof(SimpleEventPacket) == 48, "size of SimpleEventPacket should be 56 or 48(default)"); +static_assert(sizeof(EventPacket) == 0x140 || sizeof(EventPacket) == 48, "size of EventPacket should be 320 or 48(default)"); +static_assert(sizeof(SpawnExperienceOrbPacket) == 0x40 || sizeof(SpawnExperienceOrbPacket) == 48, "size of SpawnExperienceOrbPacket should be 64 or 48(default)"); +static_assert(sizeof(ClientboundMapItemDataPacket) == 0xB8 || sizeof(ClientboundMapItemDataPacket) == 48, "size of ClientboundMapItemDataPacket should be 184 or 48(default)"); +static_assert(sizeof(MapInfoRequestPacket) == 0x38 || sizeof(MapInfoRequestPacket) == 48, "size of MapInfoRequestPacket should be 56 or 48(default)"); +static_assert(sizeof(RequestChunkRadiusPacket) == 0x38 || sizeof(RequestChunkRadiusPacket) == 48, "size of RequestChunkRadiusPacket should be 56 or 48(default)"); +static_assert(sizeof(ChunkRadiusUpdatedPacket) == 0x38 || sizeof(ChunkRadiusUpdatedPacket) == 48, "size of ChunkRadiusUpdatedPacket should be 56 or 48(default)"); +static_assert(sizeof(ItemFrameDropItemPacket) == 0x40 || sizeof(ItemFrameDropItemPacket) == 48, "size of ItemFrameDropItemPacket should be 64 or 48(default)"); +static_assert(sizeof(GameRulesChangedPacket) == 0x48 || sizeof(GameRulesChangedPacket) == 48, "size of GameRulesChangedPacket should be 72 or 48(default)"); +static_assert(sizeof(CameraPacket) == 0x40 || sizeof(CameraPacket) == 48, "size of CameraPacket should be 64 or 48(default)"); +static_assert(sizeof(BossEventPacket) == 0x80 || sizeof(BossEventPacket) == 48, "size of BossEventPacket should be 128 or 48(default)"); +static_assert(sizeof(ShowCreditsPacket) == 0x40 || sizeof(ShowCreditsPacket) == 48, "size of ShowCreditsPacket should be 64 or 48(default)"); +static_assert(sizeof(AvailableCommandsPacket) == 0xC0 || sizeof(AvailableCommandsPacket) == 48, "size of AvailableCommandsPacket should be 192 or 48(default)"); +static_assert(sizeof(CommandRequestPacket) == 0x98 || sizeof(CommandRequestPacket) == 48, "size of CommandRequestPacket should be 152 or 48(default)"); +static_assert(sizeof(CommandBlockUpdatePacket) == 0xB0 || sizeof(CommandBlockUpdatePacket) == 48, "size of CommandBlockUpdatePacket should be 176 or 48(default)"); +static_assert(sizeof(CommandOutputPacket) == 0xA0 || sizeof(CommandOutputPacket) == 48, "size of CommandOutputPacket should be 160 or 48(default)"); +static_assert(sizeof(UpdateTradePacket) == 0x90 || sizeof(UpdateTradePacket) == 48, "size of UpdateTradePacket should be 144 or 48(default)"); +static_assert(sizeof(UpdateEquipPacket) == 0x58 || sizeof(UpdateEquipPacket) == 48, "size of UpdateEquipPacket should be 88 or 48(default)"); +static_assert(sizeof(ResourcePackDataInfoPacket) == 0x88 || sizeof(ResourcePackDataInfoPacket) == 48, "size of ResourcePackDataInfoPacket should be 136 or 48(default)"); +static_assert(sizeof(ResourcePackChunkDataPacket) == 0x78 || sizeof(ResourcePackChunkDataPacket) == 48, "size of ResourcePackChunkDataPacket should be 120 or 48(default)"); +static_assert(sizeof(ResourcePackChunkRequestPacket) == 0x58 || sizeof(ResourcePackChunkRequestPacket) == 48, "size of ResourcePackChunkRequestPacket should be 88 or 48(default)"); +static_assert(sizeof(TransferPacket) == 0x58 || sizeof(TransferPacket) == 48, "size of TransferPacket should be 88 or 48(default)"); +static_assert(sizeof(PlaySoundPacket) == 0x68 || sizeof(PlaySoundPacket) == 48, "size of PlaySoundPacket should be 104 or 48(default)"); +static_assert(sizeof(StopSoundPacket) == 0x58 || sizeof(StopSoundPacket) == 48, "size of StopSoundPacket should be 88 or 48(default)"); +static_assert(sizeof(SetTitlePacket) == 0xA8 || sizeof(SetTitlePacket) == 48, "size of SetTitlePacket should be 168 or 48(default)"); +static_assert(sizeof(AddBehaviorTreePacket) == 0x50 || sizeof(AddBehaviorTreePacket) == 48, "size of AddBehaviorTreePacket should be 80 or 48(default)"); +static_assert(sizeof(StructureBlockUpdatePacket) == 0xF0 || sizeof(StructureBlockUpdatePacket) == 48, "size of StructureBlockUpdatePacket should be 240 or 48(default)"); +static_assert(sizeof(ShowStoreOfferPacket) == 0x78 || sizeof(ShowStoreOfferPacket) == 48, "size of ShowStoreOfferPacket should be 120 or 48(default)"); +static_assert(sizeof(PurchaseReceiptPacket) == 0x48 || sizeof(PurchaseReceiptPacket) == 48, "size of PurchaseReceiptPacket should be 72 or 48(default)"); +//static_assert(sizeof(PlayerSkinPacket) == 0x2E8 || sizeof(PlayerSkinPacket) == 48, "size of PlayerSkinPacket should be 744 or 48(default)"); +static_assert(sizeof(SubClientLoginPacket) == 0x38 || sizeof(SubClientLoginPacket) == 48, "size of SubClientLoginPacket should be 56 or 48(default)"); +static_assert(sizeof(AutomationClientConnectPacket) == 0x50 || sizeof(AutomationClientConnectPacket) == 48, "size of AutomationClientConnectPacket should be 80 or 48(default)"); +static_assert(sizeof(SetLastHurtByPacket) == 0x38 || sizeof(SetLastHurtByPacket) == 48, "size of SetLastHurtByPacket should be 56 or 48(default)"); +static_assert(sizeof(BookEditPacket) == 0xA0 || sizeof(BookEditPacket) == 48, "size of BookEditPacket should be 160 or 48(default)"); +static_assert(sizeof(NpcRequestPacket) == 0x88 || sizeof(NpcRequestPacket) == 48, "size of NpcRequestPacket should be 136 or 48(default)"); +static_assert(sizeof(PhotoTransferPacket) == 0xC0 || sizeof(PhotoTransferPacket) == 48, "size of PhotoTransferPacket should be 192 or 48(default)"); +static_assert(sizeof(ModalFormRequestPacket) == 0x58 || sizeof(ModalFormRequestPacket) == 48, "size of ModalFormRequestPacket should be 88 or 48(default)"); +static_assert(sizeof(ModalFormResponsePacket) == 0x58 || sizeof(ModalFormResponsePacket) == 48, "size of ModalFormResponsePacket should be 88 or 48(default)"); +static_assert(sizeof(ServerSettingsRequestPacket) == 0x30 || sizeof(ServerSettingsRequestPacket) == 48, "size of ServerSettingsRequestPacket should be 48 or 48(default)"); +static_assert(sizeof(ServerSettingsResponsePacket) == 0x58 || sizeof(ServerSettingsResponsePacket) == 48, "size of ServerSettingsResponsePacket should be 88 or 48(default)"); +static_assert(sizeof(ShowProfilePacket) == 0x50 || sizeof(ShowProfilePacket) == 48, "size of ShowProfilePacket should be 80 or 48(default)"); +static_assert(sizeof(SetDefaultGameTypePacket) == 0x38 || sizeof(SetDefaultGameTypePacket) == 48, "size of SetDefaultGameTypePacket should be 56 or 48(default)"); +static_assert(sizeof(RemoveObjectivePacket) == 0x50 || sizeof(RemoveObjectivePacket) == 48, "size of RemoveObjectivePacket should be 80 or 48(default)"); +static_assert(sizeof(SetDisplayObjectivePacket) == 0xB8 || sizeof(SetDisplayObjectivePacket) == 48, "size of SetDisplayObjectivePacket should be 184 or 48(default)"); +static_assert(sizeof(SetScorePacket) == 0x50 || sizeof(SetScorePacket) == 48, "size of SetScorePacket should be 80 or 48(default)"); +static_assert(sizeof(LabTablePacket) == 0x48 || sizeof(LabTablePacket) == 48, "size of LabTablePacket should be 72 or 48(default)"); +static_assert(sizeof(UpdateBlockSyncedPacket) == 0x58 || sizeof(UpdateBlockSyncedPacket) == 48, "size of UpdateBlockSyncedPacket should be 88 or 48(default)"); +static_assert(sizeof(MoveActorDeltaPacket) == 0x70 || sizeof(MoveActorDeltaPacket) == 48, "size of MoveActorDeltaPacket should be 112 or 48(default)"); +static_assert(sizeof(SetScoreboardIdentityPacket) == 0x50 || sizeof(SetScoreboardIdentityPacket) == 48, "size of SetScoreboardIdentityPacket should be 80 or 48(default)"); +static_assert(sizeof(SetLocalPlayerAsInitializedPacket) == 0x38 || sizeof(SetLocalPlayerAsInitializedPacket) == 48, "size of SetLocalPlayerAsInitializedPacket should be 56 or 48(default)"); +static_assert(sizeof(UpdateSoftEnumPacket) == 0x70 || sizeof(UpdateSoftEnumPacket) == 48, "size of UpdateSoftEnumPacket should be 112 or 48(default)"); +static_assert(sizeof(NetworkStackLatencyPacket) == 0x40 || sizeof(NetworkStackLatencyPacket) == 48, "size of NetworkStackLatencyPacket should be 64 or 48(default)"); +static_assert(sizeof(ScriptCustomEventPacket) == 0x60 || sizeof(ScriptCustomEventPacket) == 48, "size of ScriptCustomEventPacket should be 96 or 48(default)"); +static_assert(sizeof(SpawnParticleEffectPacket) == 0x70 || sizeof(SpawnParticleEffectPacket) == 48, "size of SpawnParticleEffectPacket should be 112 or 48(default)"); +//static_assert(sizeof(AvailableActorIdentifiersPacket) == 0x48 || sizeof(AvailableActorIdentifiersPacket) == 48, "size of AvailableActorIdentifiersPacket should be 72 or 48(default)"); +static_assert(sizeof(LevelSoundEventPacketV2) == 0x70 || sizeof(LevelSoundEventPacketV2) == 48, "size of LevelSoundEventPacketV2 should be 112 or 48(default)"); +static_assert(sizeof(NetworkChunkPublisherUpdatePacket) == 0x40 || sizeof(NetworkChunkPublisherUpdatePacket) == 48, "size of NetworkChunkPublisherUpdatePacket should be 64 or 48(default)"); +//static_assert(sizeof(BiomeDefinitionListPacket) == 0x48 || sizeof(BiomeDefinitionListPacket) == 48, "size of BiomeDefinitionListPacket should be 72 or 48(default)"); +static_assert(sizeof(LevelSoundEventPacket) == 0x70 || sizeof(LevelSoundEventPacket) == 48, "size of LevelSoundEventPacket should be 112 or 48(default)"); +static_assert(sizeof(LevelEventGenericPacket) == 0x40 || sizeof(LevelEventGenericPacket) == 48, "size of LevelEventGenericPacket should be 64 or 48(default)"); +static_assert(sizeof(LecternUpdatePacket) == 0x48 || sizeof(LecternUpdatePacket) == 48, "size of LecternUpdatePacket should be 72 or 48(default)"); +static_assert(sizeof(AddEntityPacket) == 0x38 || sizeof(AddEntityPacket) == 48, "size of AddEntityPacket should be 56 or 48(default)"); +static_assert(sizeof(RemoveEntityPacket) == 0x38 || sizeof(RemoveEntityPacket) == 48, "size of RemoveEntityPacket should be 56 or 48(default)"); +static_assert(sizeof(ClientCacheStatusPacket) == 0x38 || sizeof(ClientCacheStatusPacket) == 48, "size of ClientCacheStatusPacket should be 56 or 48(default)"); +static_assert(sizeof(OnScreenTextureAnimationPacket) == 0x38 || sizeof(OnScreenTextureAnimationPacket) == 48, "size of OnScreenTextureAnimationPacket should be 56 or 48(default)"); +static_assert(sizeof(MapCreateLockedCopyPacket) == 0x40 || sizeof(MapCreateLockedCopyPacket) == 48, "size of MapCreateLockedCopyPacket should be 64 or 48(default)"); +static_assert(sizeof(StructureTemplateDataRequestPacket) == 0xC8 || sizeof(StructureTemplateDataRequestPacket) == 48, "size of StructureTemplateDataRequestPacket should be 200 or 48(default)"); +static_assert(sizeof(StructureTemplateDataResponsePacket) == 0x60 || sizeof(StructureTemplateDataResponsePacket) == 48, "size of StructureTemplateDataResponsePacket should be 96 or 48(default)"); +static_assert(sizeof(ClientCacheBlobStatusPacket) == 0x60 || sizeof(ClientCacheBlobStatusPacket) == 48, "size of ClientCacheBlobStatusPacket should be 96 or 48(default)"); +static_assert(sizeof(ClientCacheMissResponsePacket) == 0x88 || sizeof(ClientCacheMissResponsePacket) == 48, "size of ClientCacheMissResponsePacket should be 136 or 48(default)"); +static_assert(sizeof(EducationSettingsPacket) == 0x178 || sizeof(EducationSettingsPacket) == 48, "size of EducationSettingsPacket should be 376 or 48(default)"); +static_assert(sizeof(EmotePacket) == 0x60 || sizeof(EmotePacket) == 48, "size of EmotePacket should be 96 or 48(default)"); +static_assert(sizeof(MultiplayerSettingsPacket) == 0x38 || sizeof(MultiplayerSettingsPacket) == 48, "size of MultiplayerSettingsPacket should be 56 or 48(default)"); +static_assert(sizeof(SettingsCommandPacket) == 0x58 || sizeof(SettingsCommandPacket) == 48, "size of SettingsCommandPacket should be 88 or 48(default)"); +static_assert(sizeof(AnvilDamagePacket) == 0x40 || sizeof(AnvilDamagePacket) == 48, "size of AnvilDamagePacket should be 64 or 48(default)"); +static_assert(sizeof(CompletedUsingItemPacket) == 0x38 || sizeof(CompletedUsingItemPacket) == 48, "size of CompletedUsingItemPacket should be 56 or 48(default)"); +static_assert(sizeof(NetworkSettingsPacket) == 0x38 || sizeof(NetworkSettingsPacket) == 48, "size of NetworkSettingsPacket should be 56 or 48(default)"); +static_assert(sizeof(PlayerAuthInputPacket) == 0xA8 || sizeof(PlayerAuthInputPacket) == 48, "size of PlayerAuthInputPacket should be 168 or 48(default)"); +static_assert(sizeof(CreativeContentPacket) == 0x50 || sizeof(CreativeContentPacket) == 48, "size of CreativeContentPacket should be 80 or 48(default)"); +static_assert(sizeof(PlayerEnchantOptionsPacket) == 0x48 || sizeof(PlayerEnchantOptionsPacket) == 48, "size of PlayerEnchantOptionsPacket should be 72 or 48(default)"); +static_assert(sizeof(ItemStackRequestPacket) == 0x38 || sizeof(ItemStackRequestPacket) == 48, "size of ItemStackRequestPacket should be 56 or 48(default)"); +static_assert(sizeof(ItemStackResponsePacket) == 0x48 || sizeof(ItemStackResponsePacket) == 48, "size of ItemStackResponsePacket should be 72 or 48(default)"); +static_assert(sizeof(PlayerArmorDamagePacket) == 0x40 || sizeof(PlayerArmorDamagePacket) == 48, "size of PlayerArmorDamagePacket should be 64 or 48(default)"); +static_assert(sizeof(CodeBuilderPacket) == 0x58 || sizeof(CodeBuilderPacket) == 48, "size of CodeBuilderPacket should be 88 or 48(default)"); +static_assert(sizeof(UpdatePlayerGameTypePacket) == 0x40 || sizeof(UpdatePlayerGameTypePacket) == 48, "size of UpdatePlayerGameTypePacket should be 64 or 48(default)"); +static_assert(sizeof(EmoteListPacket) == 0x50 || sizeof(EmoteListPacket) == 48, "size of EmoteListPacket should be 80 or 48(default)"); +static_assert(sizeof(PositionTrackingDBServerBroadcastPacket) == 0x50 || sizeof(PositionTrackingDBServerBroadcastPacket) == 48, "size of PositionTrackingDBServerBroadcastPacket should be 80 or 48(default)"); +static_assert(sizeof(PositionTrackingDBClientRequestPacket) == 0x38 || sizeof(PositionTrackingDBClientRequestPacket) == 48, "size of PositionTrackingDBClientRequestPacket should be 56 or 48(default)"); +static_assert(sizeof(DebugInfoPacket) == 0x58 || sizeof(DebugInfoPacket) == 48, "size of DebugInfoPacket should be 88 or 48(default)"); +static_assert(sizeof(PacketViolationWarningPacket) == 0x60 || sizeof(PacketViolationWarningPacket) == 48, "size of PacketViolationWarningPacket should be 96 or 48(default)"); +static_assert(sizeof(MotionPredictionHintsPacket) == 0x48 || sizeof(MotionPredictionHintsPacket) == 48, "size of MotionPredictionHintsPacket should be 72 or 48(default)"); +static_assert(sizeof(AnimateEntityPacket) == 0xD8 || sizeof(AnimateEntityPacket) == 48, "size of AnimateEntityPacket should be 216 or 48(default)"); +static_assert(sizeof(CameraShakePacket) == 0x40 || sizeof(CameraShakePacket) == 48, "size of CameraShakePacket should be 64 or 48(default)"); +static_assert(sizeof(PlayerFogPacket) == 0x48 || sizeof(PlayerFogPacket) == 48, "size of PlayerFogPacket should be 72 or 48(default)"); +static_assert(sizeof(CorrectPlayerMovePredictionPacket) == 0x58 || sizeof(CorrectPlayerMovePredictionPacket) == 48, "size of CorrectPlayerMovePredictionPacket should be 88 or 48(default)"); +static_assert(sizeof(ItemComponentPacket) == 0x48 || sizeof(ItemComponentPacket) == 48, "size of ItemComponentPacket should be 72 or 48(default)"); +static_assert(sizeof(FilterTextPacket) == 0x58 || sizeof(FilterTextPacket) == 48, "size of FilterTextPacket should be 88 or 48(default)"); +static_assert(sizeof(ClientboundDebugRendererPacket) == 0x88 || sizeof(ClientboundDebugRendererPacket) == 48, "size of ClientboundDebugRendererPacket should be 136 or 48(default)"); +//static_assert(sizeof(SyncActorPropertyPacket) == 0x48 || sizeof(SyncActorPropertyPacket) == 48, "size of SyncActorPropertyPacket should be 72 or 48(default)"); +static_assert(sizeof(AddVolumeEntityPacket) == 0x100 || sizeof(AddVolumeEntityPacket) == 48, "size of AddVolumeEntityPacket should be 256 or 48(default)"); +static_assert(sizeof(RemoveVolumeEntityPacket) == 0x38 || sizeof(RemoveVolumeEntityPacket) == 48, "size of RemoveVolumeEntityPacket should be 56 or 48(default)"); +static_assert(sizeof(SimulationTypePacket) == 0x38 || sizeof(SimulationTypePacket) == 48, "size of SimulationTypePacket should be 56 or 48(default)"); +static_assert(sizeof(NpcDialoguePacket) == 0xC0 || sizeof(NpcDialoguePacket) == 48, "size of NpcDialoguePacket should be 192 or 48(default)"); +static_assert(sizeof(EduUriResourcePacket) == 0x70 || sizeof(EduUriResourcePacket) == 48, "size of EduUriResourcePacket should be 112 or 48(default)"); +static_assert(sizeof(CreatePhotoPacket) == 0x78 || sizeof(CreatePhotoPacket) == 48, "size of CreatePhotoPacket should be 120 or 48(default)"); +static_assert(sizeof(UpdateSubChunkBlocksPacket) == 0x70 || sizeof(UpdateSubChunkBlocksPacket) == 48, "size of UpdateSubChunkBlocksPacket should be 112 or 48(default)"); +static_assert(sizeof(SubChunkPacket) == 0x60 || sizeof(SubChunkPacket) == 48, "size of SubChunkPacket should be 96 or 48(default)"); +static_assert(sizeof(SubChunkRequestPacket) == 0x80 || sizeof(SubChunkRequestPacket) == 48, "size of SubChunkRequestPacket should be 128 or 48(default)"); +static_assert(sizeof(PlayerStartItemCooldownPacket) == 0x58 || sizeof(PlayerStartItemCooldownPacket) == 48, "size of PlayerStartItemCooldownPacket should be 88 or 48(default)"); +static_assert(sizeof(ScriptMessagePacket) == 0x70 || sizeof(ScriptMessagePacket) == 48, "size of ScriptMessagePacket should be 112 or 48(default)"); +static_assert(sizeof(CodeBuilderSourcePacket) == 0x58 || sizeof(CodeBuilderSourcePacket) == 48, "size of CodeBuilderSourcePacket should be 88 or 48(default)"); + +#endif // SIZE_STATIC_ASSERT_IF_DEFINE diff --git a/LiteLoader/LiteLoader.vcxproj b/LiteLoader/LiteLoader.vcxproj index 10fac48ad6..91e3f1dc59 100644 --- a/LiteLoader/LiteLoader.vcxproj +++ b/LiteLoader/LiteLoader.vcxproj @@ -93,6 +93,7 @@ LibraryBuilder.exe + diff --git a/LiteLoader/LiteLoader.vcxproj.filters b/LiteLoader/LiteLoader.vcxproj.filters index f9f4485efd..974dc91bc9 100644 --- a/LiteLoader/LiteLoader.vcxproj.filters +++ b/LiteLoader/LiteLoader.vcxproj.filters @@ -312,6 +312,9 @@ Kernel + + Kernel\Network + From 5f5a0d74d3d0cb31695231270a9520d638cbeb33 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Wed, 2 Mar 2022 20:12:09 +0800 Subject: [PATCH 18/23] fix build --- LiteLoader/Header/DynamicCommandAPI.h | 2 +- LiteLoader/Header/MC/AvailableCommandsPacket.hpp | 5 +++-- LiteLoader/Header/MC/CommandFlag.hpp | 1 - LiteLoader/Header/MC/CommandRegistry.hpp | 16 +++++++--------- LiteLoader/Kernel/Command/CommandRegistryAPI.cpp | 11 +++++++++++ LiteLoader/Kernel/Command/DynamicCommandAPI.cpp | 10 +++++----- LiteLoader/Kernel/Network/PacketAPI.cpp | 2 +- 7 files changed, 28 insertions(+), 19 deletions(-) diff --git a/LiteLoader/Header/DynamicCommandAPI.h b/LiteLoader/Header/DynamicCommandAPI.h index 5e220c7306..9eb61dccad 100644 --- a/LiteLoader/Header/DynamicCommandAPI.h +++ b/LiteLoader/Header/DynamicCommandAPI.h @@ -6,10 +6,10 @@ class Actor; #include "MC/Command.hpp" #include "MC/CommandOrigin.hpp" #include "MC/CommandOutput.hpp" +#include "MC/CommandParameterData.hpp" #include "MC/CommandRegistry.hpp" #include "MC/CommandSelector.hpp" #include "MC/CommandPosition.hpp" -#include "MC/CommandParameterData.hpp" #include "Utils/WinHelper.h" #include diff --git a/LiteLoader/Header/MC/AvailableCommandsPacket.hpp b/LiteLoader/Header/MC/AvailableCommandsPacket.hpp index c44bda4ab7..45bd9f2d21 100644 --- a/LiteLoader/Header/MC/AvailableCommandsPacket.hpp +++ b/LiteLoader/Header/MC/AvailableCommandsPacket.hpp @@ -6,7 +6,8 @@ #define BEFORE_EXTRA // Include Headers or Declare Types Here -#include "CommandRegistry.hpp" +#include "CommandFlag.hpp" +enum CommandPermissionLevel : char; #undef BEFORE_EXTRA @@ -29,7 +30,7 @@ class AvailableCommandsPacket : public Packet { struct ParamData { std::string desc; - CommandRegistry::Symbol sym; + unsigned int sym; }; struct OverloadData { diff --git a/LiteLoader/Header/MC/CommandFlag.hpp b/LiteLoader/Header/MC/CommandFlag.hpp index 8722903627..e750cab02f 100644 --- a/LiteLoader/Header/MC/CommandFlag.hpp +++ b/LiteLoader/Header/MC/CommandFlag.hpp @@ -1,6 +1,5 @@ #pragma once - enum class CommandFlagValue : unsigned short { None = 0, diff --git a/LiteLoader/Header/MC/CommandRegistry.hpp b/LiteLoader/Header/MC/CommandRegistry.hpp index 75a5d16807..ac3e197ee7 100644 --- a/LiteLoader/Header/MC/CommandRegistry.hpp +++ b/LiteLoader/Header/MC/CommandRegistry.hpp @@ -167,17 +167,15 @@ class CommandRegistry { double a = 0; // 48 double b = 0; // 56 double c = 0; // 64 - inline Overload(CommandVersion version, - FactoryFn factory, - std::vector&& args) - : version(version), - factory(factory), - params(std::forward>(args)), - unk(255) {} + LIAPI Overload(CommandVersion version, + FactoryFn factory, + std::vector&& args); - inline std::string toDebugString() const + LIAPI ~Overload(); + + inline std::string toDebugString() { - return fmt::format("", params.size()); + return fmt::format(""); } }; diff --git a/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp b/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp index a7fdf6b557..7d72a973b6 100644 --- a/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp +++ b/LiteLoader/Kernel/Command/CommandRegistryAPI.cpp @@ -21,6 +21,17 @@ void CommandRegistry::registerOverload(std::string const& name, Overload::Factor }*/ extern Logger logger; + +CommandRegistry::Overload::Overload(CommandVersion version, + FactoryFn factory, + std::vector&& args) + : version(version) + , factory(factory) + , params(std::forward>(args)) + , unk(255){}; + +CommandRegistry::Overload::~Overload(){}; + std::vector CommandRegistry::getEnumNames() { if (!Global) diff --git a/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp b/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp index 902dd12e43..f3a2592021 100644 --- a/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp +++ b/LiteLoader/Kernel/Command/DynamicCommandAPI.cpp @@ -62,11 +62,11 @@ namespace //static std::string latestAllocateName = ""; std::unordered_map> dynamicCommandInstances; -typedef DynamicCommand::Result Result; -typedef DynamicCommand::ParameterType ParameterType; -typedef DynamicCommand::ParameterPtr ParameterPtr; -typedef DynamicCommand::ParameterData ParameterData; -typedef DynamicCommandInstance::ParameterIndex ParameterIndex; +using Result = DynamicCommand::Result; +using ParameterType = DynamicCommand::ParameterType; +using ParameterPtr = DynamicCommand::ParameterPtr; +using ParameterData = DynamicCommand::ParameterData; +using ParameterIndex = DynamicCommandInstance::ParameterIndex; namespace ParameterDataType { diff --git a/LiteLoader/Kernel/Network/PacketAPI.cpp b/LiteLoader/Kernel/Network/PacketAPI.cpp index eb247a18ca..25976de59a 100644 --- a/LiteLoader/Kernel/Network/PacketAPI.cpp +++ b/LiteLoader/Kernel/Network/PacketAPI.cpp @@ -1,4 +1,4 @@ -#include +#include #include #define INCLUDE_ALL_PACKET From c9f4029c3ff80e5176d77b88cc0a27f146540045 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Wed, 2 Mar 2022 20:20:33 +0800 Subject: [PATCH 19/23] fix Packet inheritance manually --- .../Header/MC/AvailableActorIdentifiersPacket.hpp | 2 +- .../Header/MC/BiomeDefinitionListPacket.hpp | 2 +- LiteLoader/Header/MC/PlayerListPacket.hpp | 2 +- LiteLoader/Header/MC/PlayerSkinPacket.hpp | 2 +- LiteLoader/Header/MC/SyncActorPropertyPacket.hpp | 2 +- .../{BinaryStream.cpp => BinaryStreamAPI.cpp} | 0 LiteLoader/Kernel/Network/PacketAPI.cpp | 15 ++++++++------- LiteLoader/LiteLoader.vcxproj.filters | 2 +- 8 files changed, 14 insertions(+), 13 deletions(-) rename LiteLoader/Kernel/Network/{BinaryStream.cpp => BinaryStreamAPI.cpp} (100%) diff --git a/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp b/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp index 2ca89a84b3..d3cffb8e18 100644 --- a/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp +++ b/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp @@ -8,7 +8,7 @@ #undef BEFORE_EXTRA -class AvailableActorIdentifiersPacket { +class AvailableActorIdentifiersPacket : public Packet { #define AFTER_EXTRA // Add Member There diff --git a/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp b/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp index 6b0d3f112d..3a3106b214 100644 --- a/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp +++ b/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp @@ -8,7 +8,7 @@ #undef BEFORE_EXTRA -class BiomeDefinitionListPacket { +class BiomeDefinitionListPacket : public Packet { #define AFTER_EXTRA // Add Member There diff --git a/LiteLoader/Header/MC/PlayerListPacket.hpp b/LiteLoader/Header/MC/PlayerListPacket.hpp index 29488b1728..d0246459ca 100644 --- a/LiteLoader/Header/MC/PlayerListPacket.hpp +++ b/LiteLoader/Header/MC/PlayerListPacket.hpp @@ -7,7 +7,7 @@ // Include Headers or Declare Types Here #include "PlayerListEntry.hpp" -enum PlayerListPacketType +enum class PlayerListPacketType { Add, Remove diff --git a/LiteLoader/Header/MC/PlayerSkinPacket.hpp b/LiteLoader/Header/MC/PlayerSkinPacket.hpp index ace895a2d1..72730417bb 100644 --- a/LiteLoader/Header/MC/PlayerSkinPacket.hpp +++ b/LiteLoader/Header/MC/PlayerSkinPacket.hpp @@ -8,7 +8,7 @@ #undef BEFORE_EXTRA -class PlayerSkinPacket { +class PlayerSkinPacket : public Packet{ #define AFTER_EXTRA // Add Member There diff --git a/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp b/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp index dfc93084a6..cd15e2430c 100644 --- a/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp +++ b/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp @@ -8,7 +8,7 @@ #undef BEFORE_EXTRA -class SyncActorPropertyPacket { +class SyncActorPropertyPacket : public Packet { #define AFTER_EXTRA // Add Member There diff --git a/LiteLoader/Kernel/Network/BinaryStream.cpp b/LiteLoader/Kernel/Network/BinaryStreamAPI.cpp similarity index 100% rename from LiteLoader/Kernel/Network/BinaryStream.cpp rename to LiteLoader/Kernel/Network/BinaryStreamAPI.cpp diff --git a/LiteLoader/Kernel/Network/PacketAPI.cpp b/LiteLoader/Kernel/Network/PacketAPI.cpp index 25976de59a..f6d76c6364 100644 --- a/LiteLoader/Kernel/Network/PacketAPI.cpp +++ b/LiteLoader/Kernel/Network/PacketAPI.cpp @@ -2,8 +2,9 @@ #include #define INCLUDE_ALL_PACKET -//#define SIZE_STATIC_ASSERT #define SIZE_STATIC_ASSERT_IF_DEFINE +//#define SIZE_STATIC_ASSERT +//#define GENERATE_PACKET #ifdef INCLUDE_ALL_PACKET @@ -67,7 +68,7 @@ #include #include #include -//#include +#include #include #include #include @@ -898,7 +899,7 @@ static_assert(sizeof(SetCommandsEnabledPacket) == 0x38 || sizeof(SetCommandsEnab static_assert(sizeof(SetDifficultyPacket) == 0x38 || sizeof(SetDifficultyPacket) == 48, "size of SetDifficultyPacket should be 56 or 48(default)"); static_assert(sizeof(ChangeDimensionPacket) == 0x48 || sizeof(ChangeDimensionPacket) == 48, "size of ChangeDimensionPacket should be 72 or 48(default)"); static_assert(sizeof(SetPlayerGameTypePacket) == 0x38 || sizeof(SetPlayerGameTypePacket) == 48, "size of SetPlayerGameTypePacket should be 56 or 48(default)"); -//static_assert(sizeof(PlayerListPacket) == 0x50 || sizeof(PlayerListPacket) == 48, "size of PlayerListPacket should be 80 or 48(default)"); +static_assert(sizeof(PlayerListPacket) == 0x50 || sizeof(PlayerListPacket) == 48, "size of PlayerListPacket should be 80 or 48(default)"); static_assert(sizeof(SimpleEventPacket) == 0x38 || sizeof(SimpleEventPacket) == 48, "size of SimpleEventPacket should be 56 or 48(default)"); static_assert(sizeof(EventPacket) == 0x140 || sizeof(EventPacket) == 48, "size of EventPacket should be 320 or 48(default)"); static_assert(sizeof(SpawnExperienceOrbPacket) == 0x40 || sizeof(SpawnExperienceOrbPacket) == 48, "size of SpawnExperienceOrbPacket should be 64 or 48(default)"); @@ -928,7 +929,7 @@ static_assert(sizeof(AddBehaviorTreePacket) == 0x50 || sizeof(AddBehaviorTreePac static_assert(sizeof(StructureBlockUpdatePacket) == 0xF0 || sizeof(StructureBlockUpdatePacket) == 48, "size of StructureBlockUpdatePacket should be 240 or 48(default)"); static_assert(sizeof(ShowStoreOfferPacket) == 0x78 || sizeof(ShowStoreOfferPacket) == 48, "size of ShowStoreOfferPacket should be 120 or 48(default)"); static_assert(sizeof(PurchaseReceiptPacket) == 0x48 || sizeof(PurchaseReceiptPacket) == 48, "size of PurchaseReceiptPacket should be 72 or 48(default)"); -//static_assert(sizeof(PlayerSkinPacket) == 0x2E8 || sizeof(PlayerSkinPacket) == 48, "size of PlayerSkinPacket should be 744 or 48(default)"); +static_assert(sizeof(PlayerSkinPacket) == 0x2E8 || sizeof(PlayerSkinPacket) == 48, "size of PlayerSkinPacket should be 744 or 48(default)"); static_assert(sizeof(SubClientLoginPacket) == 0x38 || sizeof(SubClientLoginPacket) == 48, "size of SubClientLoginPacket should be 56 or 48(default)"); static_assert(sizeof(AutomationClientConnectPacket) == 0x50 || sizeof(AutomationClientConnectPacket) == 48, "size of AutomationClientConnectPacket should be 80 or 48(default)"); static_assert(sizeof(SetLastHurtByPacket) == 0x38 || sizeof(SetLastHurtByPacket) == 48, "size of SetLastHurtByPacket should be 56 or 48(default)"); @@ -953,10 +954,10 @@ static_assert(sizeof(UpdateSoftEnumPacket) == 0x70 || sizeof(UpdateSoftEnumPacke static_assert(sizeof(NetworkStackLatencyPacket) == 0x40 || sizeof(NetworkStackLatencyPacket) == 48, "size of NetworkStackLatencyPacket should be 64 or 48(default)"); static_assert(sizeof(ScriptCustomEventPacket) == 0x60 || sizeof(ScriptCustomEventPacket) == 48, "size of ScriptCustomEventPacket should be 96 or 48(default)"); static_assert(sizeof(SpawnParticleEffectPacket) == 0x70 || sizeof(SpawnParticleEffectPacket) == 48, "size of SpawnParticleEffectPacket should be 112 or 48(default)"); -//static_assert(sizeof(AvailableActorIdentifiersPacket) == 0x48 || sizeof(AvailableActorIdentifiersPacket) == 48, "size of AvailableActorIdentifiersPacket should be 72 or 48(default)"); +static_assert(sizeof(AvailableActorIdentifiersPacket) == 0x48 || sizeof(AvailableActorIdentifiersPacket) == 48, "size of AvailableActorIdentifiersPacket should be 72 or 48(default)"); static_assert(sizeof(LevelSoundEventPacketV2) == 0x70 || sizeof(LevelSoundEventPacketV2) == 48, "size of LevelSoundEventPacketV2 should be 112 or 48(default)"); static_assert(sizeof(NetworkChunkPublisherUpdatePacket) == 0x40 || sizeof(NetworkChunkPublisherUpdatePacket) == 48, "size of NetworkChunkPublisherUpdatePacket should be 64 or 48(default)"); -//static_assert(sizeof(BiomeDefinitionListPacket) == 0x48 || sizeof(BiomeDefinitionListPacket) == 48, "size of BiomeDefinitionListPacket should be 72 or 48(default)"); +static_assert(sizeof(BiomeDefinitionListPacket) == 0x48 || sizeof(BiomeDefinitionListPacket) == 48, "size of BiomeDefinitionListPacket should be 72 or 48(default)"); static_assert(sizeof(LevelSoundEventPacket) == 0x70 || sizeof(LevelSoundEventPacket) == 48, "size of LevelSoundEventPacket should be 112 or 48(default)"); static_assert(sizeof(LevelEventGenericPacket) == 0x40 || sizeof(LevelEventGenericPacket) == 48, "size of LevelEventGenericPacket should be 64 or 48(default)"); static_assert(sizeof(LecternUpdatePacket) == 0x48 || sizeof(LecternUpdatePacket) == 48, "size of LecternUpdatePacket should be 72 or 48(default)"); @@ -997,7 +998,7 @@ static_assert(sizeof(CorrectPlayerMovePredictionPacket) == 0x58 || sizeof(Correc static_assert(sizeof(ItemComponentPacket) == 0x48 || sizeof(ItemComponentPacket) == 48, "size of ItemComponentPacket should be 72 or 48(default)"); static_assert(sizeof(FilterTextPacket) == 0x58 || sizeof(FilterTextPacket) == 48, "size of FilterTextPacket should be 88 or 48(default)"); static_assert(sizeof(ClientboundDebugRendererPacket) == 0x88 || sizeof(ClientboundDebugRendererPacket) == 48, "size of ClientboundDebugRendererPacket should be 136 or 48(default)"); -//static_assert(sizeof(SyncActorPropertyPacket) == 0x48 || sizeof(SyncActorPropertyPacket) == 48, "size of SyncActorPropertyPacket should be 72 or 48(default)"); +static_assert(sizeof(SyncActorPropertyPacket) == 0x48 || sizeof(SyncActorPropertyPacket) == 48, "size of SyncActorPropertyPacket should be 72 or 48(default)"); static_assert(sizeof(AddVolumeEntityPacket) == 0x100 || sizeof(AddVolumeEntityPacket) == 48, "size of AddVolumeEntityPacket should be 256 or 48(default)"); static_assert(sizeof(RemoveVolumeEntityPacket) == 0x38 || sizeof(RemoveVolumeEntityPacket) == 48, "size of RemoveVolumeEntityPacket should be 56 or 48(default)"); static_assert(sizeof(SimulationTypePacket) == 0x38 || sizeof(SimulationTypePacket) == 48, "size of SimulationTypePacket should be 56 or 48(default)"); diff --git a/LiteLoader/LiteLoader.vcxproj.filters b/LiteLoader/LiteLoader.vcxproj.filters index 974dc91bc9..80791c026a 100644 --- a/LiteLoader/LiteLoader.vcxproj.filters +++ b/LiteLoader/LiteLoader.vcxproj.filters @@ -177,7 +177,7 @@ Kernel\Network - + Kernel\Network From e099ce7387cdcc940060a6a191344733b9dcac90 Mon Sep 17 00:00:00 2001 From: xiaoqch Date: Wed, 2 Mar 2022 20:34:38 +0800 Subject: [PATCH 20/23] fix Packets and build --- LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp | 1 + LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp | 3 ++- LiteLoader/Header/MC/PlayerListPacket.hpp | 1 + LiteLoader/Header/MC/PlayerSkinPacket.hpp | 1 + LiteLoader/Header/MC/SyncActorPropertyPacket.hpp | 3 ++- LiteLoader/LiteLoader.vcxproj | 2 +- 6 files changed, 8 insertions(+), 3 deletions(-) diff --git a/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp b/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp index d3cffb8e18..f600940543 100644 --- a/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp +++ b/LiteLoader/Header/MC/AvailableActorIdentifiersPacket.hpp @@ -27,6 +27,7 @@ class AvailableActorIdentifiersPacket : public Packet { /*2*/ virtual std::string getName() const; /*3*/ virtual void write(class BinaryStream&) const; /*4*/ virtual struct ExtendedStreamReadResult readExtended(class ReadOnlyBinaryStream&); + /*6*/ virtual enum StreamReadResult _read(class ReadOnlyBinaryStream&); /* inline ~AvailableActorIdentifiersPacket(){ (AvailableActorIdentifiersPacket::*rv)(); diff --git a/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp b/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp index 3a3106b214..164eaec07a 100644 --- a/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp +++ b/LiteLoader/Header/MC/BiomeDefinitionListPacket.hpp @@ -25,8 +25,9 @@ class BiomeDefinitionListPacket : public Packet { /*0*/ virtual ~BiomeDefinitionListPacket(); /*1*/ virtual enum MinecraftPacketIds getId() const; /*2*/ virtual std::string getName() const; - /*3*/ virtual void __unk_vfn_3(); + /*3*/ virtual void write(class BinaryStream&) const; /*4*/ virtual struct ExtendedStreamReadResult readExtended(class ReadOnlyBinaryStream&); + /*6*/ virtual enum StreamReadResult _read(class ReadOnlyBinaryStream&); /* inline ~BiomeDefinitionListPacket(){ (BiomeDefinitionListPacket::*rv)(); diff --git a/LiteLoader/Header/MC/PlayerListPacket.hpp b/LiteLoader/Header/MC/PlayerListPacket.hpp index d0246459ca..3006da7f81 100644 --- a/LiteLoader/Header/MC/PlayerListPacket.hpp +++ b/LiteLoader/Header/MC/PlayerListPacket.hpp @@ -39,6 +39,7 @@ class PlayerListPacket : public Packet /*2*/ virtual std::string getName() const; /*3*/ virtual void write(class BinaryStream&) const; /*4*/ virtual struct ExtendedStreamReadResult readExtended(class ReadOnlyBinaryStream&); + /*6*/ virtual enum StreamReadResult _read(class ReadOnlyBinaryStream&); /* inline enum StreamReadResult _read(class ReadOnlyBinaryStream& a0){ enum StreamReadResult (PlayerListPacket::*rv)(class ReadOnlyBinaryStream&); diff --git a/LiteLoader/Header/MC/PlayerSkinPacket.hpp b/LiteLoader/Header/MC/PlayerSkinPacket.hpp index 72730417bb..a0c5a0a5b2 100644 --- a/LiteLoader/Header/MC/PlayerSkinPacket.hpp +++ b/LiteLoader/Header/MC/PlayerSkinPacket.hpp @@ -27,6 +27,7 @@ class PlayerSkinPacket : public Packet{ /*2*/ virtual std::string getName() const; /*3*/ virtual void write(class BinaryStream&) const; /*4*/ virtual struct ExtendedStreamReadResult readExtended(class ReadOnlyBinaryStream&); + /*6*/ virtual enum StreamReadResult _read(class ReadOnlyBinaryStream&); /* inline enum StreamReadResult _read(class ReadOnlyBinaryStream& a0){ enum StreamReadResult (PlayerSkinPacket::*rv)(class ReadOnlyBinaryStream&); diff --git a/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp b/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp index cd15e2430c..8f6ad2e19e 100644 --- a/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp +++ b/LiteLoader/Header/MC/SyncActorPropertyPacket.hpp @@ -25,8 +25,9 @@ class SyncActorPropertyPacket : public Packet { /*0*/ virtual ~SyncActorPropertyPacket(); /*1*/ virtual enum MinecraftPacketIds getId() const; /*2*/ virtual std::string getName() const; - /*3*/ virtual void __unk_vfn_3(); + /*3*/ virtual void write(class BinaryStream&) const; /*4*/ virtual struct ExtendedStreamReadResult readExtended(class ReadOnlyBinaryStream&); + /*6*/ virtual enum StreamReadResult _read(class ReadOnlyBinaryStream&); /* inline ~SyncActorPropertyPacket(){ (SyncActorPropertyPacket::*rv)(); diff --git a/LiteLoader/LiteLoader.vcxproj b/LiteLoader/LiteLoader.vcxproj index 91e3f1dc59..babc430ed9 100644 --- a/LiteLoader/LiteLoader.vcxproj +++ b/LiteLoader/LiteLoader.vcxproj @@ -185,7 +185,7 @@ LibraryBuilder.exe - + From fd9aa0a787f7964cb31270bb4739695888f83035 Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 20:41:18 +0800 Subject: [PATCH 21/23] add check --- ScriptEngine/Engine/MessageSystem.cpp | 2 ++ ScriptEngine/Engine/TimeTaskSystem.cpp | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/ScriptEngine/Engine/MessageSystem.cpp b/ScriptEngine/Engine/MessageSystem.cpp index 16ec5d136c..a593fb21a5 100644 --- a/ScriptEngine/Engine/MessageSystem.cpp +++ b/ScriptEngine/Engine/MessageSystem.cpp @@ -379,6 +379,8 @@ void InitMessageSystem() while (true) { MessageSystemLoopOnce(); + if (LL::getServerStatus() >= LL::ServerStatus::Stopping) + return; SleepEx(5, true); if (LL::getServerStatus() >= LL::ServerStatus::Stopping) return; diff --git a/ScriptEngine/Engine/TimeTaskSystem.cpp b/ScriptEngine/Engine/TimeTaskSystem.cpp index 16f9822440..187250bcbe 100644 --- a/ScriptEngine/Engine/TimeTaskSystem.cpp +++ b/ScriptEngine/Engine/TimeTaskSystem.cpp @@ -85,12 +85,15 @@ int NewTimeout(Local func, vector> paras, int timeout) { vector> args; for (auto& para : taskData.paras) - args.emplace_back(para.get()); + if (para.isEmpty()) + return; + else + args.emplace_back(para.get()); taskData.func.get().call({}, args); } timeTaskMap.erase(id); } - TIMETASK_CATCH("setTimeout"); + TIMETASK_CATCH("setTimeout-Function"); }, timeout / 50); return timeTaskId; } @@ -123,7 +126,7 @@ int NewTimeout(Local func, int timeout) engine->eval(taskData.code.get().toString()); timeTaskMap.erase(id); } - TIMETASK_CATCH("setTimeout"); + TIMETASK_CATCH("setTimeout-String"); }, timeout / 50); return timeTaskId; } @@ -165,11 +168,14 @@ int NewInterval(Local func, vector> paras, int timeout) { vector> args; for (auto& para : taskData.paras) - args.emplace_back(para.get()); + if (para.isEmpty()) + return; + else + args.emplace_back(para.get()); taskData.func.get().call({}, args); } } - TIMETASK_CATCH("setInterval"); + TIMETASK_CATCH("setInterval-Function"); }, timeout / 50); return timeTaskId; } @@ -205,7 +211,7 @@ int NewInterval(Local func, int timeout) EngineScope scope(engine); engine->eval(taskData.code.get().toString()); } - TIMETASK_CATCH("setInterval"); + TIMETASK_CATCH("setInterval-String"); }, timeout / 50); return timeTaskId; } From b9756ba15180c43adc08ef765cec90ea266f0404 Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 21:29:38 +0800 Subject: [PATCH 22/23] Update CHANGELOG.txt --- CHANGELOG.txt | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c2816f087d..7cb593d981 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,24 +1,28 @@ -## [LiteLoader Release Note] -LiteLoaderBDS-2.1.3 update has been released, automatic update has been pushed -This is a bug fix update, please update as soon as possible +This is a bug fix update, fix several problems that may cause crash. Please update as soon as possible ## [New features] -- Added dynamic command registration interface (DynamicCommandAPI) -- Added text encoding conversion interface (I18nAPI) -- Added CompoundTag::toPrettySNBT beautification output interface -- Provide support for NetworkNBT format -- Provided annotation support for all json interfaces of scripting engine -- Added the symbol cache switch for PrintCurrentStackTraceback -- Added addons management and query commands -- Upgraded the included LLMoney version -## [Bug Fix] -- The script engine fixes the problem that the database cannot be closed -- Fix the problem that StructureTemplate class exists -- Scripting engine fixes the problem of repeated loading of ll.require -- Script engine fixes the problem that some object data is not updated after setNbt -- Scripting engine fixes the problem of missing onLiquidFlow event dimension -- Scripting engine fixes item.clone -- Scripting engine provides binary interface for base64 conversion -- Scripting engine adds engine validity check for multiple callbacks, improving stability -- Fix some problems of SymDBHelper in SDK -- Provide UTF8 conversion for most of the abnormal output to avoid the crash caused by local encoding in the output process. -- Fix the problem of crash caused by inputting full-angle characters in the background. \ No newline at end of file +New dynamic command registration interface (DynamicCommandAPI) +New text encoding conversion interface (I18nAPI) +Added built-in OutputFilter regex output filtering function +Added addons automatic installation, management and query commands +Added CompoundTag::toPrettySNBT beautification output interface +Provided support for NetworkNBT format +Provide comment support for all json interfaces of scripting engine +Added a symbol cache switch for PrintCurrentStackTraceback +Upgraded the included LLMoney version +## [Bug fixes] +Repair the problem of incorrect content of some packet classes +Repair the problems of StructureTemplate class. +Repair the problem of error reporting in hot management command +Add lock to Logger to solve the problem of probable collapse of service when multi-threaded output +The script engine fixes the problem that the database cannot be closed. +Scripting engine fixes the problem of repeated loading of ll.require +Scripting engine fixes the problem that some object data is not updated after setNbt +Scripting engine fixes missing onLiquidFlow event dimension +Scripting engine fixes item.clone +Scripting engine provides binary interface for base64 conversion +Scripting engine fixes possible problems with TimeTask, adds security checks +Scripting engine adds engine validity checks for multiple callbacks, improving stability +Scripting engine fixes the problem that V8 output abnormal information triggers debugger and causes crash. +Fix some problems of SymDBHelper in SDK. +Provide UTF8 conversion for most of the output, to avoid the crash caused by local encoding +Repair the problem of crashing caused by inputting full-angle characters in the background \ No newline at end of file From 0a48b152fae6a519a91e8b458d5989931689b58e Mon Sep 17 00:00:00 2001 From: yqs112358 <1425321705@qq.com> Date: Wed, 2 Mar 2022 21:29:48 +0800 Subject: [PATCH 23/23] modify docs --- docs/index.html | 39 ++++++++++++++++++++++++++++++++++++++ docs/zh_CN/README.md | 18 +++++++++++++----- docs/zh_CN/Usage/README.md | 14 ++++++++------ 3 files changed, 60 insertions(+), 11 deletions(-) diff --git a/docs/index.html b/docs/index.html index 254ffc5975..8a50cc9cce 100644 --- a/docs/index.html +++ b/docs/index.html @@ -71,6 +71,42 @@ nextText: "Next", crossChapter: true, crossChapterText: true, + }, + progress: { + position: "top", + color: "var(--theme-color,#42b983)", + height: "1px", + }, + 'flexible-alerts': { + style: 'flat', + note: { + label: { + '/de_DE/': 'Hinweis', + '/en/': 'Note', + '/zh_CN/': '信息' + } + }, + tip: { + label: { + '/de_DE/': 'Tipp', + '/en/': 'Tip', + '/zh_CN/': '提示' + } + }, + warning: { + label: { + '/de_DE/': 'Warnung', + '/en/': 'Warning', + '/zh_CN/': '警告' + } + }, + attention: { + label: { + '/de_DE/': 'Achtung', + '/en/': 'Attention', + '/zh_CN/': '注意' + } + } } } @@ -87,6 +123,9 @@ + + + \ No newline at end of file diff --git a/docs/zh_CN/README.md b/docs/zh_CN/README.md index 8e628c3d32..94173a2286 100644 --- a/docs/zh_CN/README.md +++ b/docs/zh_CN/README.md @@ -1,6 +1,6 @@ # LiteLoader BDS - LL帮助中心 -[![GitHub license](https://img.shields.io/github/license/LiteLDev/LiteLoaderBDS)](https://github.com/LiteLDev/LiteLoaderBDS/blob/main/LICENSE) +[![GitHub license](https://img.shields.io/badge/license-GPLv3-orange)](https://github.com/LiteLDev/LiteLoaderBDS/blob/main/LICENSE) [![Build](https://img.shields.io/badge/build-passing-brightgreen)](#) ![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/LiteLDev/LiteLoader?include_prereleases) @@ -13,22 +13,30 @@ ## 🔨 加载器安装 与 使用指南 -这里介绍了如何为BDS服务端安装`LiteLoaderBDS`加载器,以及如何安装 LL 插件 +这里介绍了如何为BDS服务端安装`LiteLoaderBDS`加载器,如何修改配置,以及如何安装 LL 插件 -👉[点击此处](zh_CN/Usage/)👈 查看 LiteLoaderBDS 安装和使用文档 +👉[点击此处](zh_CN/Usage/)👈 查看 `LiteLoaderBDS` 安装和使用文档 + +
+ +## ❓常见问题 + +安装和使用 `LiteLoaderBDS` 过程中遇到问题?这里有一些常见问题的解决方法 + +👉[点击此处](zh_CN/QA/)👈 查看常见问题与解决方法
## ⛳ C++ 插件 - 开发指南 与 API文档 -使用 `C++`, `Golang` 等编译型语言语言开发 LL 插件,拥有海量API,自由实现你的任意想法 +使用 `C++`, `Golang` 等编译型语言语言开发 LL 插件,拥有海量API,自由实现你的任意想法 👉[点击此处](zh_CN/Development/)👈 查看 C++ 插件开发文档
## 🎯 脚本插件 - 开发指南 与 API文档 -使用 `JavaScript`, `Lua` 等脚本语言开发 LL 插件,容易上手,功能强大 +使用 `JavaScript`, `Lua` 等脚本语言开发 LL 插件,容易上手,功能强大 👉[点击此处](zh_CN/Development/)👈 查看 脚本插件开发文档 diff --git a/docs/zh_CN/Usage/README.md b/docs/zh_CN/Usage/README.md index 99792dfce8..43c522d070 100644 --- a/docs/zh_CN/Usage/README.md +++ b/docs/zh_CN/Usage/README.md @@ -10,7 +10,7 @@ ### 对于 Windows 用户 -1. 前往 [MineBBS](https://www.minebbs.com/liteloader/) 或 [GitHub Release](https://github.com/LiteLDev/LiteLoader/releases) 下载最新的 `LiteLoader-版本号.zip` 压缩包 +1. 前往 [MineBBS](https://www.minebbs.com/liteloader/) 或 [GitHub Release](https://github.com/LiteLDev/LiteLoader/releases) 下载最新的 `LiteLoader-版本号.zip` 压缩包 2. 将压缩文件内的所有内容解压到 `bedrock_server.exe` 所在的目录。如果解压的过程中提示文件有冲突,选择覆盖即可。 3. 保证 `bedrock_server.pdb`文件存在。运行 `SymDB2.exe` 来生成 - 符号文件 `bedrock_server.symdb2` @@ -67,24 +67,26 @@ docker create --name liteloader -p 19132:19132/udp -i -t shrbox/liteloaderbds - `ll load ./plugins/xxxx.js` **热加载** 位于指定路径的插件。路径是相对于BDS根目录的相对路径。 - `ll unload xxxx.lua` - **热卸载 **在插件列表中名为 xxxx.lua 的插件 + **热卸载** 在插件列表中名为 xxxx.lua 的插件 - `ll reload xxxx.dll` - **重新加载 **在插件列表中名为 xxxx.dll 的插件 + **重新加载** 在插件列表中名为 xxxx.dll 的插件 - `ll reload` **重新加载** 插件列表中的所有插件 - `ll version` 输出当前安装的LL版本 - `ll upgrade` - 手动检查LiteLoader自动更新 + 手动检查`LiteLoaderBDS`自动更新 -#### 热管理功能 使用警示 ⚠ +#### 热管理功能 常见问题 & 解答 - 热卸载插件后,此插件注册的命令不会被删除。玩家使用那些命令时,会提示命令不存在 - 如果你的插件有导出的函数被其他插件 Import,则当你卸载 / 重载此插件后,其他插件对应的 Import 会失效 - 请勿在服务器尚未启动完毕,或者服务器中有大量玩家时卸载或者重载插件!否则服务器有可能发生崩溃 - 热加载 / 热重载一个插件之后,插件注册的`onServerStarted`事件会被立刻调用一次,玩家进服事件`onPlayerJoin`会被逐个调用一次(因为此时服务器已经开启完毕了) -插件热管理机制仅供调试插件时使用。在 **生产环境中最好避免使用**,以免出现一些奇奇怪怪的问题。 +>[!WARNING] +> +>插件热管理机制仅供调试插件时使用。在 **生产环境中请避免使用**,以免出现问题 ## 📡 脚本引擎 - 实时调试模式