change namespace LL -> ll

This commit is contained in:
Qiuzhizhe 2023-03-02 23:45:20 -08:00
parent d7ee6e94a2
commit 55ab798f36
55 changed files with 306 additions and 306 deletions

View File

@ -13,7 +13,7 @@ struct Addon {
std::string name; std::string name;
std::string description; std::string description;
Type type; Type type;
LL::Version version; ll::Version version;
std::string uuid; std::string uuid;
std::string directory; std::string directory;
bool enable = false; bool enable = false;

View File

@ -15,7 +15,7 @@ constexpr const char* NoCrashLogger[] = {"AntiCheats"};
/////////////////////// LL Configs /////////////////////// /////////////////////// LL Configs ///////////////////////
#define LITELOADER_CONFIG_FILE "plugins/LiteLoader/LiteLoader.json" #define LITELOADER_CONFIG_FILE "plugins/LiteLoader/LiteLoader.json"
namespace LL { namespace ll {
struct CommandLineOption { struct CommandLineOption {
bool noColorOption = false; bool noColorOption = false;
}; };
@ -77,7 +77,7 @@ void inline from_json(const nlohmann::json& j, LLConfig& conf);
bool LoadLLConfig(); bool LoadLLConfig();
bool SaveLLConfig(); bool SaveLLConfig();
} // namespace LL } // namespace ll
/////////////////////// Addon Helper /////////////////////// /////////////////////// Addon Helper ///////////////////////

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
namespace LL { namespace ll {
bool StartCrashLoggerProcess(); bool StartCrashLoggerProcess();
void InitCrashLogger(bool enableCrashLogger); void InitCrashLogger(bool enableCrashLogger);
} // namespace LL } // namespace ll

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <string> #include <string>
namespace LL { namespace ll {
void LoadMain(); void LoadMain();
} // namespace LL } // namespace ll

View File

@ -3,7 +3,7 @@
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
namespace LL { namespace ll {
struct Plugin; struct Plugin;
struct Version; struct Version;
@ -13,12 +13,12 @@ class PluginManager {
public: public:
static LIAPI bool registerPlugin(HMODULE handle, std::string name, std::string desc, static LIAPI bool registerPlugin(HMODULE handle, std::string name, std::string desc,
LL::Version version, std::map<std::string, std::string> others); ll::Version version, std::map<std::string, std::string> others);
static LIAPI LL::Plugin* getPlugin(HMODULE handle); static LIAPI ll::Plugin* getPlugin(HMODULE handle);
static LIAPI LL::Plugin* getPlugin(std::string name, bool includeScriptPlugin = true); static LIAPI ll::Plugin* getPlugin(std::string name, bool includeScriptPlugin = true);
static LIAPI bool hasPlugin(std::string name, bool includeScriptPlugin = true); static LIAPI bool hasPlugin(std::string name, bool includeScriptPlugin = true);
static LIAPI std::unordered_map<std::string, LL::Plugin*> getAllPlugins(bool includeScriptPlugin = true); static LIAPI std::unordered_map<std::string, ll::Plugin*> getAllPlugins(bool includeScriptPlugin = true);
static bool loadPlugin(std::string pluginFilePath, bool outputStatus = false, bool isHotLoad = false); static bool loadPlugin(std::string pluginFilePath, bool outputStatus = false, bool isHotLoad = false);
static bool unloadPlugin(std::string pluginName, bool outputStatus = false); static bool unloadPlugin(std::string pluginName, bool outputStatus = false);
@ -27,7 +27,7 @@ public:
static LIAPI bool unRegisterPlugin(std::string name); static LIAPI bool unRegisterPlugin(std::string name);
}; };
} // namespace LL } // namespace ll
LIAPI bool RegisterPlugin(HMODULE handle, std::string name, std::string desc, LL::Version version, LIAPI bool RegisterPlugin(HMODULE handle, std::string name, std::string desc, ll::Version version,
std::map<std::string, std::string> others); std::map<std::string, std::string> others);

View File

@ -12,7 +12,7 @@
#define TARGET_BDS_PROTOCOL_VERSION 408 #define TARGET_BDS_PROTOCOL_VERSION 408
#define LITELOADER_VERSION LL::getLoaderVersion() #define LITELOADER_VERSION ll::getLoaderVersion()
#define __TO_VERSION_STRING(ver) #ver #define __TO_VERSION_STRING(ver) #ver

View File

@ -95,12 +95,12 @@ template <typename EVENT>
class EventTemplate { class EventTemplate {
public: public:
static EventListener<EVENT> subscribe(std::function<bool(EVENT)> callback) { static EventListener<EVENT> subscribe(std::function<bool(EVENT)> callback) {
auto plugin = LL::getPlugin(GetCurrentModule()); auto plugin = ll::getPlugin(GetCurrentModule());
return EventListener<EVENT>(EventManager<EVENT>::addEventListener(plugin ? plugin->name : "", callback)); return EventListener<EVENT>(EventManager<EVENT>::addEventListener(plugin ? plugin->name : "", callback));
} }
static EventListener<EVENT> subscribe_ref(std::function<bool(EVENT&)> callback) { static EventListener<EVENT> subscribe_ref(std::function<bool(EVENT&)> callback) {
auto plugin = LL::getPlugin(GetCurrentModule()); auto plugin = ll::getPlugin(GetCurrentModule());
return EventListener<EVENT>(EventManager<EVENT>::addEventListenerRef(plugin ? plugin->name : "", callback)); return EventListener<EVENT>(EventManager<EVENT>::addEventListenerRef(plugin ? plugin->name : "", callback));
} }

View File

@ -338,8 +338,8 @@ inline I18nBase* load(Args&&... args) {
* @return I18nBase* The pointer to the I18nBase object in PluginOwnData, null if failed * @return I18nBase* The pointer to the I18nBase object in PluginOwnData, null if failed
*/ */
inline I18nBase* loadFrom(const std::string& plugin) { inline I18nBase* loadFrom(const std::string& plugin) {
if (LL::hasPlugin(plugin)) { if (ll::hasPlugin(plugin)) {
auto p = LL::getPlugin(plugin); auto p = ll::getPlugin(plugin);
if (p) { if (p) {
return loadFromImpl(GetCurrentModule(), p->handle); return loadFromImpl(GetCurrentModule(), p->handle);
} }

View File

@ -18,7 +18,7 @@
#include "llapi/utils/PluginOwnData.h" #include "llapi/utils/PluginOwnData.h"
// LL types // LL types
namespace LL { namespace ll {
struct Version { struct Version {
enum Status { enum Status {
@ -67,23 +67,23 @@ struct Plugin {
} }
}; };
} // namespace LL } // namespace ll
inline bool operator<=(LL::Version a, LL::Version b) { inline bool operator<=(ll::Version a, ll::Version b) {
return a < b || a == b; return a < b || a == b;
} }
inline bool operator>(LL::Version a, LL::Version b) { inline bool operator>(ll::Version a, ll::Version b) {
return b < a; return b < a;
} }
inline bool operator>=(LL::Version a, LL::Version b) { inline bool operator>=(ll::Version a, ll::Version b) {
return b < a || b == a; return b < a || b == a;
} }
// helper // helper
LIAPI bool RegisterPlugin(HMODULE hPlugin, std::string name, std::string desc, LL::Version version, LIAPI bool RegisterPlugin(HMODULE hPlugin, std::string name, std::string desc, ll::Version version,
std::map<std::string, std::string> others); std::map<std::string, std::string> others);
// Loader APIs // Loader APIs
namespace LL { namespace ll {
/** /**
* @brief Get the loader version as a string * @brief Get the loader version as a string
@ -94,7 +94,7 @@ LIAPI std::string getLoaderVersionString();
/** /**
* @brief Get the loader version as a Version object * @brief Get the loader version as a Version object
* *
* @return LL::Version The loader version * @return ll::Version The loader version
*/ */
LIAPI Version getLoaderVersion(); LIAPI Version getLoaderVersion();
/** /**
@ -117,14 +117,14 @@ LIAPI std::string getDataPath(const std::string& pluginName);
* *
* @param name The name of the plugin * @param name The name of the plugin
* @param desc The description(introduction) of the plugin * @param desc The description(introduction) of the plugin
* @param version The version of the plugin(LL::Version) * @param version The version of the plugin(ll::Version)
* @param git The git information of the plugin * @param git The git information of the plugin
* @param license The license of the plugin * @param license The license of the plugin
* @param website The website * @param website The website
* @return bool True if the plugin is registered successfully * @return bool True if the plugin is registered successfully
* @note The implementation of this function must be in header file(because of `GetCurrentModule`) * @note The implementation of this function must be in header file(because of `GetCurrentModule`)
*/ */
inline bool registerPlugin(std::string name, std::string desc, LL::Version version, inline bool registerPlugin(std::string name, std::string desc, ll::Version version,
std::string git = "", std::string license = "", std::string website = "") { std::string git = "", std::string license = "", std::string website = "") {
std::map<std::string, std::string> others; std::map<std::string, std::string> others;
if (!git.empty()) if (!git.empty())
@ -141,17 +141,17 @@ inline bool registerPlugin(std::string name, std::string desc, LL::Version versi
* *
* @param name The name of the plugin * @param name The name of the plugin
* @param desc The descirption(introduction) of the plugin * @param desc The descirption(introduction) of the plugin
* @param version The version of the plugin(LL::Version) * @param version The version of the plugin(ll::Version)
* @param others The other information of the plugin(key-value) * @param others The other information of the plugin(key-value)
* @return bool True if the plugin is registered successfully * @return bool True if the plugin is registered successfully
* @note The implementation of this function must be in header file(because of `GetCurrentModule`) * @note The implementation of this function must be in header file(because of `GetCurrentModule`)
* *
* @par Example * @par Example
* @code * @code
* LL::registerPlugin("Test", "A test plugin", Version(0, 0, 1, Version::Dev), {{"Note","This is Note"}}); * ll::registerPlugin("Test", "A test plugin", Version(0, 0, 1, Version::Dev), {{"Note","This is Note"}});
* @endcode * @endcode
*/ */
inline bool registerPlugin(std::string name, std::string desc, LL::Version version, inline bool registerPlugin(std::string name, std::string desc, ll::Version version,
std::map<std::string, std::string> others) { std::map<std::string, std::string> others) {
return ::RegisterPlugin(GetCurrentModule(), name, desc, version, others); return ::RegisterPlugin(GetCurrentModule(), name, desc, version, others);
} }
@ -160,16 +160,16 @@ inline bool registerPlugin(std::string name, std::string desc, LL::Version versi
* @brief Get a loaded plugin by name * @brief Get a loaded plugin by name
* *
* @param name The name of the plugin * @param name The name of the plugin
* @return LL::Plugin* The plugin(nullptr if not found) * @return ll::Plugin* The plugin(nullptr if not found)
*/ */
LIAPI LL::Plugin* getPlugin(std::string name); LIAPI ll::Plugin* getPlugin(std::string name);
/** /**
* @brief Get a loaded plugin by HMODULE handle * @brief Get a loaded plugin by HMODULE handle
* *
* @param name The name of the plugin * @param name The name of the plugin
* @return LL::Plugin* The plugin(nullptr if not found) * @return ll::Plugin* The plugin(nullptr if not found)
*/ */
LIAPI LL::Plugin* getPlugin(HMODULE handle); LIAPI ll::Plugin* getPlugin(HMODULE handle);
/** /**
* @brief Get whether the plugin is loaded * @brief Get whether the plugin is loaded
@ -182,9 +182,9 @@ LIAPI bool hasPlugin(std::string name);
/** /**
* @brief Get the All the loaded plugins * @brief Get the All the loaded plugins
* *
* @return std::unordered_map<std::string, LL::Plugin*> The loaded plugins(name-plugin) * @return std::unordered_map<std::string, ll::Plugin*> The loaded plugins(name-plugin)
*/ */
LIAPI std::unordered_map<std::string, LL::Plugin*> getAllPlugins(); LIAPI std::unordered_map<std::string, ll::Plugin*> getAllPlugins();
/** /**
* @breif Get the handle of LiteLoader.dll. * @breif Get the handle of LiteLoader.dll.
@ -209,4 +209,4 @@ LIAPI bool isServerStopping();
* @return std::string Language(such as: en, zh_CN, ja, ru) * @return std::string Language(such as: en, zh_CN, ja, ru)
*/ */
std::string getLanguage(); std::string getLanguage();
}; // namespace LL }; // namespace ll

View File

@ -37,7 +37,7 @@ public:
void inline init(HMODULE hModule = nullptr) { void inline init(HMODULE hModule = nullptr) {
if (!hModule) { if (!hModule) {
auto pPtr = LL::getPlugin("ParticleAPI"); auto pPtr = ll::getPlugin("ParticleAPI");
if (!pPtr) { if (!pPtr) {
throw std::runtime_error("Cannot get ParticleAPI.dll"); throw std::runtime_error("Cannot get ParticleAPI.dll");
} }

View File

@ -60,7 +60,7 @@ public:
*/ */
void init(HMODULE hModule = nullptr) { void init(HMODULE hModule = nullptr) {
if (!hModule) { if (!hModule) {
auto pPtr = LL::getPlugin("PermissionAPI"); auto pPtr = ll::getPlugin("PermissionAPI");
if (!pPtr) { if (!pPtr) {
throw std::runtime_error("Cannot get the plugin object"); throw std::runtime_error("Cannot get the plugin object");
} }

View File

@ -2,8 +2,8 @@
#include <string> #include <string>
#include "Global.h" #include "Global.h"
namespace LL { namespace ll {
LIAPI std::string getBdsVersion(); LIAPI std::string getBdsVersion();
LIAPI int getServerProtocolVersion(); LIAPI int getServerProtocolVersion();
LIAPI bool setServerMotd(const std::string& motd); LIAPI bool setServerMotd(const std::string& motd);
} // namespace LL } // namespace ll

View File

@ -79,7 +79,7 @@ std::optional<Addon> parseAddonFromPath(std::filesystem::path addonPath) {
addon.directory = UTF82String(addonPath.u8string()); addon.directory = UTF82String(addonPath.u8string());
auto ver = header["version"]; auto ver = header["version"];
addon.version = LL::Version(ver[0], ver[1], ver[2]); addon.version = ll::Version(ver[0], ver[1], ver[2]);
string type = manifest["modules"][0]["type"]; string type = manifest["modules"][0]["type"];
if (type == "resources") if (type == "resources")
@ -239,7 +239,7 @@ void FindManifest(vector<string>& result, const string& path) {
} }
std::string Addon::getPrintName() const { std::string Addon::getPrintName() const {
if (LL::globalConfig.colorLog) if (ll::globalConfig.colorLog)
return ColorFormat::convertToConsole(std::string(name)); return ColorFormat::convertToConsole(std::string(name));
else else
return ColorFormat::removeColorCode(std::string(name)); return ColorFormat::removeColorCode(std::string(name));
@ -619,7 +619,7 @@ bool AutoInstallAddons(string path) {
std::error_code ec; std::error_code ec;
if (!filesystem::exists(str2wstr(path))) { if (!filesystem::exists(str2wstr(path))) {
filesystem::create_directories(str2wstr(path), ec); filesystem::create_directories(str2wstr(path), ec);
addonLogger.info(tr("ll.addonsHelper.autoInstall.tip.dirCreated", LL::globalConfig.addonsInstallPath)); addonLogger.info(tr("ll.addonsHelper.autoInstall.tip.dirCreated", ll::globalConfig.addonsInstallPath));
return false; return false;
} }
std::vector<string> toInstallList; std::vector<string> toInstallList;
@ -659,13 +659,13 @@ bool AutoInstallAddons(string path) {
} }
void InitAddonsHelper() { void InitAddonsHelper() {
if (LL::isDebugMode()) if (ll::isDebugMode())
addonLogger.consoleLevel = addonLogger.debug.level; addonLogger.consoleLevel = addonLogger.debug.level;
filesystem::remove_all(ADDON_INSTALL_TEMP_DIR); filesystem::remove_all(ADDON_INSTALL_TEMP_DIR);
filesystem::create_directories(ADDON_INSTALL_TEMP_DIR); filesystem::create_directories(ADDON_INSTALL_TEMP_DIR);
AutoInstallAddons(LL::globalConfig.addonsInstallPath); AutoInstallAddons(ll::globalConfig.addonsInstallPath);
BuildAddonsList(); BuildAddonsList();
filesystem::remove_all(ADDON_INSTALL_TEMP_DIR); filesystem::remove_all(ADDON_INSTALL_TEMP_DIR);

View File

@ -225,8 +225,8 @@ nlohmann::json addAdvancedPie(const string& key, const unordered_map<string, int
nlohmann::json getCustomCharts() { nlohmann::json getCustomCharts() {
nlohmann::json pluginsJson; nlohmann::json pluginsJson;
pluginsJson.emplace_back(addSimplePie("liteloaderbds_version", LL::getLoaderVersion().toString(false))); pluginsJson.emplace_back(addSimplePie("liteloaderbds_version", ll::getLoaderVersion().toString(false)));
pluginsJson.emplace_back(addSimplePie("bds_version", LL::getBdsVersion().substr(1))); pluginsJson.emplace_back(addSimplePie("bds_version", ll::getBdsVersion().substr(1)));
pluginsJson.emplace_back(addSimplePie("xbox_auth", isOnlineAuth ? "Required" : "Not required")); pluginsJson.emplace_back(addSimplePie("xbox_auth", isOnlineAuth ? "Required" : "Not required"));
pluginsJson.emplace_back(addAdvancedPie("player_platform", playerPlatList)); pluginsJson.emplace_back(addAdvancedPie("player_platform", playerPlatList));
@ -322,7 +322,7 @@ void scheduleThread() {
Schedule::nextTick(submitTask); Schedule::nextTick(submitTask);
std::this_thread::sleep_for(std::chrono::milliseconds(secondDelay)); std::this_thread::sleep_for(std::chrono::milliseconds(secondDelay));
while (!LL::isServerStopping()) { while (!ll::isServerStopping()) {
Schedule::nextTick(submitTask); Schedule::nextTick(submitTask);
std::this_thread::sleep_for(std::chrono::milliseconds(period)); std::this_thread::sleep_for(std::chrono::milliseconds(period));
} }

View File

@ -19,7 +19,7 @@
//#include <MC/ServerPlayer.hpp> //#include <MC/ServerPlayer.hpp>
//#include <ScheduleAPI.h> //#include <ScheduleAPI.h>
// //
//using namespace LL; //using namespace ll;
// //
//// Fix bug //// Fix bug
//TClasslessInstanceHook(bool, "?_read@ClientCacheBlobStatusPacket@@EEAA?AW4StreamReadResult@@AEAVReadOnlyBinaryStream@@@Z", //TClasslessInstanceHook(bool, "?_read@ClientCacheBlobStatusPacket@@EEAA?AW4StreamReadResult@@AEAVReadOnlyBinaryStream@@@Z",
@ -185,7 +185,7 @@
//TInstanceHook(void, "?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z", ServerPlayer , ActorDamageSource* ds) //TInstanceHook(void, "?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z", ServerPlayer , ActorDamageSource* ds)
//{ //{
// original(this, ds); // original(this, ds);
// if (LL::globalConfig.enableFixMcBug) // if (ll::globalConfig.enableFixMcBug)
// { // {
// auto name = getRealName(); // auto name = getRealName();
// Schedule::delay([name]() { // Schedule::delay([name]() {
@ -199,7 +199,7 @@
// //
//// Fix Fishing Hook changeDimension Crash //// Fix Fishing Hook changeDimension Crash
//TInstanceHook(__int64, "?changeDimension@Actor@@UEAAXV?$AutomaticID@VDimension@@H@@@Z", Actor, unsigned int a1) { //TInstanceHook(__int64, "?changeDimension@Actor@@UEAAXV?$AutomaticID@VDimension@@H@@@Z", Actor, unsigned int a1) {
// if (!LL::globalConfig.enableFixMcBug) // if (!ll::globalConfig.enableFixMcBug)
// return original(this, a1); // return original(this, a1);
// if ((int)this->getEntityTypeId() == 0x4D) // if ((int)this->getEntityTypeId() == 0x4D)
// return 0; // return 0;
@ -207,7 +207,7 @@
//} //}
// //
//TClasslessInstanceHook(__int64, "?teleportEntity@EndGatewayBlockActor@@QEAAXAEAVActor@@@Z", Actor* a1) { //TClasslessInstanceHook(__int64, "?teleportEntity@EndGatewayBlockActor@@QEAAXAEAVActor@@@Z", Actor* a1) {
// if (!LL::globalConfig.enableFixMcBug) // if (!ll::globalConfig.enableFixMcBug)
// return original(this, a1); // return original(this, a1);
// if ((int)a1->getEntityTypeId() == 0x4D) // if ((int)a1->getEntityTypeId() == 0x4D)
// return 0; // return 0;
@ -235,33 +235,33 @@
//// Fix command crash when server is stopping //// Fix command crash when server is stopping
//TClasslessInstanceHook(void, "?fireEventPlayerMessage@MinecraftEventing@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000@Z", //TClasslessInstanceHook(void, "?fireEventPlayerMessage@MinecraftEventing@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@000@Z",
// std::string const& a1, std::string const& a2, std::string const& a3, std::string const& a4) { // std::string const& a1, std::string const& a2, std::string const& a3, std::string const& a4) {
// if (LL::isServerStopping()) // if (ll::isServerStopping())
// return; // return;
// original(this, a1, a2, a3, a4); // original(this, a1, a2, a3, a4);
//} //}
//TClasslessInstanceHook(void, "?fireEventPlayerTransform@MinecraftEventing@@SAXAEAVPlayer@@@Z", //TClasslessInstanceHook(void, "?fireEventPlayerTransform@MinecraftEventing@@SAXAEAVPlayer@@@Z",
// class Player& a1) { // class Player& a1) {
// if (LL::isServerStopping()) // if (ll::isServerStopping())
// return; // return;
// original(this, a1); // original(this, a1);
//} //}
// //
//TClasslessInstanceHook(void, "?fireEventPlayerTravelled@MinecraftEventing@@UEAAXPEAVPlayer@@M@Z", //TClasslessInstanceHook(void, "?fireEventPlayerTravelled@MinecraftEventing@@UEAAXPEAVPlayer@@M@Z",
// class Player& a1, float a2) { // class Player& a1, float a2) {
// if (LL::isServerStopping()) // if (ll::isServerStopping())
// return; // return;
// original(this, a1, a2); // original(this, a1, a2);
//} //}
//TClasslessInstanceHook(void, "?fireEventPlayerTeleported@MinecraftEventing@@SAXPEAVPlayer@@MW4TeleportationCause@1@H@Z", //TClasslessInstanceHook(void, "?fireEventPlayerTeleported@MinecraftEventing@@SAXPEAVPlayer@@MW4TeleportationCause@1@H@Z",
// class Player* a1, float a2, int a3, int a4) { // class Player* a1, float a2, int a3, int a4) {
// if (LL::isServerStopping()) // if (ll::isServerStopping())
// return; // return;
// original(this, a1, a2, a3, a4); // original(this, a1, a2, a3, a4);
//} //}
// //
//// Set stdin mode to text mode if in wine environment //// Set stdin mode to text mode if in wine environment
//inline bool _tryFixConsoleInputMode() { //inline bool _tryFixConsoleInputMode() {
// if ((LL::globalConfig.enableFixMcBug && IsWineEnvironment()) || LL::globalConfig.enableForceUtf8Input) { // if ((ll::globalConfig.enableFixMcBug && IsWineEnvironment()) || ll::globalConfig.enableForceUtf8Input) {
// int result = _setmode(_fileno(stdin), _O_U8TEXT); // int result = _setmode(_fileno(stdin), _O_U8TEXT);
// if (result == -1) { // if (result == -1) {
// logger.error("Cannot set stdin to utf8 text mode"); // logger.error("Cannot set stdin to utf8 text mode");
@ -285,14 +285,14 @@
// //
//// Fix server broadcast bug. //// Fix server broadcast bug.
//TClasslessInstanceHook(bool, "?getLANBroadcast@LevelData@@QEBA_NXZ") { //TClasslessInstanceHook(bool, "?getLANBroadcast@LevelData@@QEBA_NXZ") {
// if (LL::globalConfig.enableFixBroadcastBug) { // if (ll::globalConfig.enableFixBroadcastBug) {
// return true; // return true;
// } // }
// return original(this); // return original(this);
//} //}
// //
//TClasslessInstanceHook(bool, "?getLANBroadcastIntent@LevelData@@QEBA_NXZ") { //TClasslessInstanceHook(bool, "?getLANBroadcastIntent@LevelData@@QEBA_NXZ") {
// if (LL::globalConfig.enableFixBroadcastBug) { // if (ll::globalConfig.enableFixBroadcastBug) {
// return true; // return true;
// } // }
// return original(this); // return original(this);
@ -302,7 +302,7 @@
//bool pauseBLogging = false; //bool pauseBLogging = false;
//THook(__int64, "std::_Func_impl_no_alloc<<lambda_bc4a73e92ba7b703b39f322d94bb55f6>,TaskResult>::_Do_call", //THook(__int64, "std::_Func_impl_no_alloc<<lambda_bc4a73e92ba7b703b39f322d94bb55f6>,TaskResult>::_Do_call",
// __int64 a1, __int64 a2) { // __int64 a1, __int64 a2) {
// if (LL::globalConfig.disableAutoCompactionLog) { // if (ll::globalConfig.disableAutoCompactionLog) {
// pauseBLogging = true; // pauseBLogging = true;
// auto v = original(a1, a2); // auto v = original(a1, a2);
// pauseBLogging = false; // pauseBLogging = false;
@ -313,7 +313,7 @@
// //
//TClasslessInstanceHook(char, "?log_va@BedrockLog@@YAXW4LogCategory@1@V?$bitset@$02@std@@W4LogRule@1@W4LogAreaID@@IPEBDH4PEAD@Z", //TClasslessInstanceHook(char, "?log_va@BedrockLog@@YAXW4LogCategory@1@V?$bitset@$02@std@@W4LogRule@1@W4LogAreaID@@IPEBDH4PEAD@Z",
// char a2, int a3, int a4, unsigned int a5, __int64 a6, int a7, __int64 a8, __int64 a9) { // char a2, int a3, int a4, unsigned int a5, __int64 a6, int a7, __int64 a8, __int64 a9) {
// if (LL::globalConfig.disableAutoCompactionLog && pauseBLogging) { // if (ll::globalConfig.disableAutoCompactionLog && pauseBLogging) {
// return 0; // return 0;
// } // }
// return original(this, a2, a3, a4, a5, a6, a7, a8, a9); // return original(this, a2, a3, a4, a5, a6, a7, a8, a9);
@ -325,7 +325,7 @@
// //
//THook(void*, "??0ScopedTimer@ImguiProfiler@@QEAA@PEBD0_N@Z", //THook(void*, "??0ScopedTimer@ImguiProfiler@@QEAA@PEBD0_N@Z",
// void* self, char* a2, char* a3, char a4) { // void* self, char* a2, char* a3, char a4) {
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// return nullptr; // return nullptr;
// } // }
// return original(self, a2, a3, a4); // return original(self, a2, a3, a4);
@ -333,7 +333,7 @@
// //
//THook(void, "??1ScopedTimer@ImguiProfiler@@UEAA@XZ", //THook(void, "??1ScopedTimer@ImguiProfiler@@UEAA@XZ",
// void* self) { // void* self) {
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// return; // return;
// } // }
// return original(self); // return original(self);
@ -342,7 +342,7 @@
//SHook2("_tickDimensionTransition", __int64, "40 53 55 41 56 41 57 48 ?? ?? ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ?? 48 33 " //SHook2("_tickDimensionTransition", __int64, "40 53 55 41 56 41 57 48 ?? ?? ?? ?? ?? ?? 48 ?? ?? ?? ?? ?? ?? 48 33 "
// "C4 48 89 ?? ?? ?? 48 8B C2 4C 8B F9 48 8B C8 33 D2 49 8B D9 49 8B E8 E8 ?? ?? ?? ?? 4C 8B F0 48 85 C0", // "C4 48 89 ?? ?? ?? 48 8B C2 4C 8B F9 48 8B C8 33 D2 49 8B D9 49 8B E8 E8 ?? ?? ?? ?? 4C 8B F0 48 85 C0",
// __int64 a1, ActorOwnerComponent* a2, __int64 a3, void* a4) { // __int64 a1, ActorOwnerComponent* a2, __int64 a3, void* a4) {
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// auto ac = Actor::tryGetFromComponent(*a2, 0); // auto ac = Actor::tryGetFromComponent(*a2, 0);
// if (ac) { // if (ac) {
// auto bs = &ac->getRegionConst(); // auto bs = &ac->getRegionConst();
@ -355,7 +355,7 @@
// //
//THook(void, "?_trackMovement@GameEventMovementTrackingSystem@@CAXAEAVActor@@AEAVGameEventMovementTrackingComponent@@@Z", //THook(void, "?_trackMovement@GameEventMovementTrackingSystem@@CAXAEAVActor@@AEAVGameEventMovementTrackingComponent@@@Z",
// Actor* a1, void* self) { // Actor* a1, void* self) {
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// auto bs = &a1->getRegionConst(); // auto bs = &a1->getRegionConst();
// if (bs == nullptr || !bs) { // if (bs == nullptr || !bs) {
// return; // return;
@ -369,7 +369,7 @@
// //
//THook(LevelChunk*, "?getChunk@BlockSource@@QEBAPEAVLevelChunk@@AEBVChunkPos@@@Z", //THook(LevelChunk*, "?getChunk@BlockSource@@QEBAPEAVLevelChunk@@AEBVChunkPos@@@Z",
// BlockSource* self, ChunkPos* a2) { // BlockSource* self, ChunkPos* a2) {
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// LevelChunk* ptr = nullptr; // LevelChunk* ptr = nullptr;
// try { // try {
// ptr = original(self, a2); // ptr = original(self, a2);
@ -384,7 +384,7 @@
// //
//THook(__int64, "?getAvailableChunk@ChunkSource@@QEAA?AV?$shared_ptr@VLevelChunk@@@std@@AEBVChunkPos@@@Z", //THook(__int64, "?getAvailableChunk@ChunkSource@@QEAA?AV?$shared_ptr@VLevelChunk@@@std@@AEBVChunkPos@@@Z",
// __int64 a1, __int64 a2) { // __int64 a1, __int64 a2) {
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// __int64 ptr = NULL; // __int64 ptr = NULL;
// try { // try {
// ptr = original(a1, a2); // ptr = original(a1, a2);
@ -400,7 +400,7 @@
// Actor) { // Actor) {
// //
// auto bs = original(this); // auto bs = original(this);
// if (LL::globalConfig.enableFixBDSCrash) { // if (ll::globalConfig.enableFixBDSCrash) {
// if (!bs) { // if (!bs) {
// return Level::getBlockSource(getDimensionId()); // return Level::getBlockSource(getDimensionId());
// } // }

View File

@ -15,7 +15,7 @@
#include "ScriptEngine/src/main/Configs.h" #include "ScriptEngine/src/main/Configs.h"
using namespace RegisterCommandHelper; using namespace RegisterCommandHelper;
using namespace LL; using namespace ll;
//static_assert(sizeof(CommandSelector<Player>) == 200); //static_assert(sizeof(CommandSelector<Player>) == 200);
@ -149,7 +149,7 @@ public:
}; };
void LLListPluginsCommand(CommandOutput& output) { void LLListPluginsCommand(CommandOutput& output) {
auto plugins = LL::getAllPlugins(); auto plugins = ll::getAllPlugins();
output.trSuccess("ll.cmd.listPlugin.overview", plugins.size()); output.trSuccess("ll.cmd.listPlugin.overview", plugins.size());
std::ostringstream oss; std::ostringstream oss;
@ -170,7 +170,7 @@ void LLListPluginsCommand(CommandOutput& output) {
} }
void LLPluginInfoCommand(CommandOutput& output, const string& pluginName) { void LLPluginInfoCommand(CommandOutput& output, const string& pluginName) {
auto plugin = LL::getPlugin(pluginName); auto plugin = ll::getPlugin(pluginName);
if (plugin) { if (plugin) {
std::map<std::string, std::string> outs; std::map<std::string, std::string> outs;
std::ostringstream oss; std::ostringstream oss;
@ -201,7 +201,7 @@ void LLPluginInfoCommand(CommandOutput& output, const string& pluginName) {
} }
void LLVersionCommand(CommandOutput& output) { void LLVersionCommand(CommandOutput& output) {
output.trSuccess("ll.cmd.version.msg", LL::getBdsVersion(), LL::getLoaderVersionString(), LL::getServerProtocolVersion()); output.trSuccess("ll.cmd.version.msg", ll::getBdsVersion(), ll::getLoaderVersionString(), ll::getServerProtocolVersion());
} }
void LLHelpCommand(CommandOutput& output) { void LLHelpCommand(CommandOutput& output) {
@ -209,7 +209,7 @@ void LLHelpCommand(CommandOutput& output) {
} }
void LLLoadPluginCommand(CommandOutput& output, const string& path) { void LLLoadPluginCommand(CommandOutput& output, const string& path) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return; // return;
if (PluginManager::loadPlugin(path, true)) { if (PluginManager::loadPlugin(path, true)) {
output.trSuccess("ll.cmd.loadPlugin.success", path); output.trSuccess("ll.cmd.loadPlugin.success", path);
@ -219,7 +219,7 @@ void LLLoadPluginCommand(CommandOutput& output, const string& path) {
} }
void LLUnloadPluginCommand(CommandOutput& output, const string& pluginName) { void LLUnloadPluginCommand(CommandOutput& output, const string& pluginName) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return; // return;
if (PluginManager::unloadPlugin(pluginName, true)) { if (PluginManager::unloadPlugin(pluginName, true)) {
output.trSuccess("ll.cmd.unloadPlugin.success", pluginName); output.trSuccess("ll.cmd.unloadPlugin.success", pluginName);
@ -229,7 +229,7 @@ void LLUnloadPluginCommand(CommandOutput& output, const string& pluginName) {
} }
void LLReloadPluginCommand(CommandOutput& output, const string& pluginName, bool reloadAll) { void LLReloadPluginCommand(CommandOutput& output, const string& pluginName, bool reloadAll) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return; // return;
if (!reloadAll) { if (!reloadAll) {
if (PluginManager::reloadPlugin(pluginName, true)) { if (PluginManager::reloadPlugin(pluginName, true)) {
@ -316,7 +316,7 @@ public:
// Register softenum // Register softenum
vector<string> pluginList; vector<string> pluginList;
for (auto& [name, p] : LL::getAllPlugins()) { for (auto& [name, p] : ll::getAllPlugins()) {
pluginList.push_back(name); pluginList.push_back(name);
} }
registry->addSoftEnum("PluginName", pluginList); registry->addSoftEnum("PluginName", pluginList);
@ -381,7 +381,7 @@ void RegisterCommands() {
Event::RegCmdEvent::subscribe([](Event::RegCmdEvent ev) { // Register commands Event::RegCmdEvent::subscribe([](Event::RegCmdEvent ev) { // Register commands
LLCommand::setup(ev.mCommandRegistry); LLCommand::setup(ev.mCommandRegistry);
VersionCommand::setup(ev.mCommandRegistry); VersionCommand::setup(ev.mCommandRegistry);
if (LL::globalConfig.enableTpdimCommand) { if (ll::globalConfig.enableTpdimCommand) {
TeleportDimensionCommand::setup(ev.mCommandRegistry); TeleportDimensionCommand::setup(ev.mCommandRegistry);
} }
return true; return true;

View File

@ -19,10 +19,10 @@ TInstanceHook(void, "?registerCommand@CommandRegistry@@QEAAXAEBV?$basic_string@D
throw std::runtime_error("There is already a command named " + name); throw std::runtime_error("There is already a command named " + name);
} }
} }
if (LL::globalConfig.enableUnlockCmd) { if (ll::globalConfig.enableUnlockCmd) {
flag1 |= 0x80; flag1 |= 0x80;
} }
if (LL::globalConfig.debugMode) { if (ll::globalConfig.debugMode) {
LogCommandRegistration(name, description, perm, flag1, flag2); LogCommandRegistration(name, description, perm, flag1, flag2);
} }
return original(this, name, description, perm, flag1, flag2); return original(this, name, description, perm, flag1, flag2);
@ -32,7 +32,7 @@ class CommandSelectorBase;
class CommandOrigin; class CommandOrigin;
//TClasslessInstanceHook(bool, "?isExpansionAllowed@CommandSelectorBase@@AEBA_NAEBVCommandOrigin@@@Z", //TClasslessInstanceHook(bool, "?isExpansionAllowed@CommandSelectorBase@@AEBA_NAEBVCommandOrigin@@@Z",
// CommandOrigin* a2) { // CommandOrigin* a2) {
// if (LL::globalConfig.enableUnlockCmd) { // if (ll::globalConfig.enableUnlockCmd) {
// original(this, a2); // original(this, a2);
// return true; // return true;
// } // }
@ -87,7 +87,7 @@ class CommandOrigin;
} }
TClasslessInstanceHook(void, "?addEnumValueConstraints@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@W4SemanticConstraint@@@Z", TClasslessInstanceHook(void, "?addEnumValueConstraints@CommandRegistry@@QEAAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@3@W4SemanticConstraint@@@Z",
std::string const& enumName, std::vector<std::string> const& enumValues, SemanticConstraint constraint) { std::string const& enumName, std::vector<std::string> const& enumValues, SemanticConstraint constraint) {
if (!LL::globalConfig.enableUnlockCmd) if (!ll::globalConfig.enableUnlockCmd)
return original(this, enumName, enumValues, constraint); return original(this, enumName, enumValues, constraint);
if (constraint & SemanticConstraint::RequiresCheatsEnabled) { if (constraint & SemanticConstraint::RequiresCheatsEnabled) {
constraint = (SemanticConstraint)(constraint & (~SemanticConstraint::RequiresCheatsEnabled)); constraint = (SemanticConstraint)(constraint & (~SemanticConstraint::RequiresCheatsEnabled));

View File

@ -8,10 +8,10 @@
using namespace std; using namespace std;
namespace LL { namespace ll {
LIAPI LLConfig globalConfig; LIAPI LLConfig globalConfig;
LIAPI LL::CommandLineOption commandLineOption; LIAPI ll::CommandLineOption commandLineOption;
void inline to_json(nlohmann::json& j, const LLConfig& conf) { void inline to_json(nlohmann::json& j, const LLConfig& conf) {
// clang-format off // clang-format off
@ -96,7 +96,7 @@ void inline to_json(nlohmann::json& j, const LLConfig& conf) {
void inline from_json(const nlohmann::json& j, LLConfig& conf) { void inline from_json(const nlohmann::json& j, LLConfig& conf) {
conf.debugMode = j.value("DebugMode", false); conf.debugMode = j.value("DebugMode", false);
if (LL::commandLineOption.noColorOption) if (ll::commandLineOption.noColorOption)
conf.colorLog = false; conf.colorLog = false;
else else
conf.colorLog = j.value("ColorLog", true); conf.colorLog = j.value("ColorLog", true);
@ -207,7 +207,7 @@ void inline from_json(const nlohmann::json& j, LLConfig& conf) {
} }
} }
} }
} // namespace LL } // namespace ll
inline bool SaveConfig(nlohmann::json& config) { inline bool SaveConfig(nlohmann::json& config) {
std::ofstream of(LITELOADER_CONFIG_FILE); std::ofstream of(LITELOADER_CONFIG_FILE);
@ -240,12 +240,12 @@ void ChooseLanguage() {
std::cin >> selected; std::cin >> selected;
std::cin.ignore(); std::cin.ignore();
if (!languages[selected].empty()) { if (!languages[selected].empty()) {
LL::globalConfig.language = languages[selected]; ll::globalConfig.language = languages[selected];
} }
} }
*/ */
bool LL::LoadLLConfig() { bool ll::LoadLLConfig() {
try { try {
auto content = ReadAllFile(LITELOADER_CONFIG_FILE); auto content = ReadAllFile(LITELOADER_CONFIG_FILE);
@ -255,17 +255,17 @@ bool LL::LoadLLConfig() {
// ChooseLanguage(); // ChooseLanguage();
// } // }
filesystem::create_directories(filesystem::path(LITELOADER_CONFIG_FILE).remove_filename().u8string()); filesystem::create_directories(filesystem::path(LITELOADER_CONFIG_FILE).remove_filename().u8string());
LL::SaveLLConfig(); ll::SaveLLConfig();
} else { } else {
try { try {
auto out = nlohmann::json::parse(*content, nullptr, false, true); auto out = nlohmann::json::parse(*content, nullptr, false, true);
LL::globalConfig = out; ll::globalConfig = out;
auto config = nlohmann::json(LL::globalConfig); auto config = nlohmann::json(ll::globalConfig);
if (out != config) { if (out != config) {
logger.warn(tr("ll.config.warning.configOutdated", LITELOADER_CONFIG_FILE)); logger.warn(tr("ll.config.warning.configOutdated", LITELOADER_CONFIG_FILE));
logger.warn(tr("ll.config.updating")); logger.warn(tr("ll.config.updating"));
LL::globalConfig.language = "system"; ll::globalConfig.language = "system";
config = nlohmann::json(LL::globalConfig); config = nlohmann::json(ll::globalConfig);
return SaveConfig(config); return SaveConfig(config);
} }
return true; return true;
@ -273,7 +273,7 @@ bool LL::LoadLLConfig() {
logger.error("Fail to parse config file <{}> !", LITELOADER_CONFIG_FILE); logger.error("Fail to parse config file <{}> !", LITELOADER_CONFIG_FILE);
logger.error("{}", e.what()); logger.error("{}", e.what());
logger.error("Using default config file..."); logger.error("Using default config file...");
return LL::SaveLLConfig(); return ll::SaveLLConfig();
} }
} }
} catch (const nlohmann::json::exception& e) { } catch (const nlohmann::json::exception& e) {
@ -287,7 +287,7 @@ bool LL::LoadLLConfig() {
return true; return true;
} }
bool LL::SaveLLConfig() { bool ll::SaveLLConfig() {
auto config = nlohmann::json(LL::globalConfig); auto config = nlohmann::json(ll::globalConfig);
return SaveConfig(config); return SaveConfig(config);
} }

View File

@ -7,11 +7,11 @@
#include <llapi/mc/Common.hpp> #include <llapi/mc/Common.hpp>
#include <llapi/mc/SharedConstants.hpp> #include <llapi/mc/SharedConstants.hpp>
using namespace std; using namespace std;
using namespace LL; using namespace ll;
Logger crashLogger("CrashLogger"); Logger crashLogger("CrashLogger");
bool LL::StartCrashLoggerProcess() { bool ll::StartCrashLoggerProcess() {
if (IsDebuggerPresent()) { if (IsDebuggerPresent()) {
crashLogger.info(tr("ll.crashLogger.existsingDebuggerDetected")); crashLogger.info(tr("ll.crashLogger.existsingDebuggerDetected"));
return true; return true;
@ -45,7 +45,7 @@ bool LL::StartCrashLoggerProcess() {
return true; return true;
} }
void LL::InitCrashLogger(bool enableCrashLogger) { void ll::InitCrashLogger(bool enableCrashLogger) {
// Enable PreLog Module // Enable PreLog Module
try { try {
LoadLibrary(CL_PRELOG_MODULE); LoadLibrary(CL_PRELOG_MODULE);

View File

@ -80,7 +80,7 @@ void DecompressResourcePacks() {
} }
void CheckRunningBDS() { void CheckRunningBDS() {
if (!LL::globalConfig.enableCheckRunningBDS) if (!ll::globalConfig.enableCheckRunningBDS)
return; return;
std::vector<DWORD> pids; std::vector<DWORD> pids;
PROCESSENTRY32 pe32{}; PROCESSENTRY32 pe32{};
@ -159,7 +159,7 @@ extern bool InitPlayerDatabase();
extern void RegisterSimpleServerLogger(); extern void RegisterSimpleServerLogger();
void Welcome() { void Welcome() {
if (!LL::globalConfig.enableWelcomeText) if (!ll::globalConfig.enableWelcomeText)
return; return;
@ -184,19 +184,19 @@ void Welcome() {
} }
void CheckDevMode() { void CheckDevMode() {
if (LL::globalConfig.debugMode) if (ll::globalConfig.debugMode)
logger.warn(tr("ll.main.warning.inDevMode")); logger.warn(tr("ll.main.warning.inDevMode"));
} }
void CheckBetaVersion() { void CheckBetaVersion() {
if (LITELOADER_VERSION_STATUS != LL::Version::Release) { if (LITELOADER_VERSION_STATUS != ll::Version::Release) {
logger.warn(tr("ll.main.warning.betaVersion")); logger.warn(tr("ll.main.warning.betaVersion"));
logger.warn(tr("ll.main.warning.productionEnv")); logger.warn(tr("ll.main.warning.productionEnv"));
} }
} }
void CheckProtocolVersion() { void CheckProtocolVersion() {
auto currentProtocol = LL::getServerProtocolVersion(); auto currentProtocol = ll::getServerProtocolVersion();
if (TARGET_BDS_PROTOCOL_VERSION != currentProtocol) { if (TARGET_BDS_PROTOCOL_VERSION != currentProtocol) {
logger.warn(tr("ll.main.warning.protocolVersionNotMatch.1"), TARGET_BDS_PROTOCOL_VERSION, currentProtocol); logger.warn(tr("ll.main.warning.protocolVersionNotMatch.1"), TARGET_BDS_PROTOCOL_VERSION, currentProtocol);
logger.warn(tr("ll.main.warning.protocolVersionNotMatch.2")); logger.warn(tr("ll.main.warning.protocolVersionNotMatch.2"));
@ -257,7 +257,7 @@ void LLMain() {
auto i18n = Translation::load("plugins/LiteLoader/LangPack/"); auto i18n = Translation::load("plugins/LiteLoader/LangPack/");
// Load Config // Load Config
LL::LoadLLConfig(); ll::LoadLLConfig();
//Unzip packed Node Modules //Unzip packed Node Modules
UnzipNodeModules(); UnzipNodeModules();
@ -266,12 +266,12 @@ void LLMain() {
DecompressResourcePacks(); DecompressResourcePacks();
// If SEH Protection is not enabled (Debug mode), restore old SE translator // If SEH Protection is not enabled (Debug mode), restore old SE translator
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(oldSeTranslator); _set_se_translator(oldSeTranslator);
// Update default language // Update default language
if (i18n && LL::globalConfig.language != "system") { if (i18n && ll::globalConfig.language != "system") {
i18n->defaultLocaleName = LL::globalConfig.language; i18n->defaultLocaleName = ll::globalConfig.language;
} }
// Check Protocol Version // Check Protocol Version
@ -291,14 +291,14 @@ void LLMain() {
CheckRunningBDS(); CheckRunningBDS();
// Builtin CrashLogger // Builtin CrashLogger
LL::InitCrashLogger(LL::globalConfig.enableCrashLogger); ll::InitCrashLogger(ll::globalConfig.enableCrashLogger);
// Initialize Player Database // Initialize Player Database
InitPlayerDatabase(); InitPlayerDatabase();
// Rename Window // Rename Window
HWND hwnd = GetConsoleWindow(); HWND hwnd = GetConsoleWindow();
std::wstring s = L"Bedrock Dedicated Server " + str2wstr(LL::getBdsVersion().substr(1)); std::wstring s = L"Bedrock Dedicated Server " + str2wstr(ll::getBdsVersion().substr(1));
SetWindowText(hwnd, s.c_str()); SetWindowText(hwnd, s.c_str());
// Register Exit Event Handler. // Register Exit Event Handler.
@ -313,12 +313,12 @@ void LLMain() {
CheckDevMode(); CheckDevMode();
// Addon Helper // Addon Helper
if (LL::globalConfig.enableAddonsHelper) { if (ll::globalConfig.enableAddonsHelper) {
InitAddonsHelper(); InitAddonsHelper();
} }
// Load plugins // Load plugins
LL::LoadMain(); ll::LoadMain();
// Register built-in commands // Register built-in commands
RegisterCommands(); RegisterCommands();
@ -351,7 +351,7 @@ THook(int, "main", int a, void* b) {
char** str = static_cast<char**>(b); char** str = static_cast<char**>(b);
for (int i = 0; i < a; ++i) { for (int i = 0; i < a; ++i) {
if (strcmp(str[i], "--noColor") == 0) { if (strcmp(str[i], "--noColor") == 0) {
LL::commandLineOption.noColorOption = true; ll::commandLineOption.noColorOption = true;
break; break;
} }
} }

View File

@ -192,7 +192,7 @@ void LoadParticleAPI() {
} }
void LL::LoadMain() { void ll::LoadMain() {
logger.info(tr("ll.loader.loadMain.start")); logger.info(tr("ll.loader.loadMain.start"));
CleanOldScriptEngine(); CleanOldScriptEngine();
@ -263,7 +263,7 @@ void LL::LoadMain() {
} }
if (PluginManager::getPlugin(lib) == nullptr) { if (PluginManager::getPlugin(lib) == nullptr) {
if (!RegisterPlugin(lib, pluginFileName, pluginFileName, LL::Version(1, 0, 0), {})) { if (!RegisterPlugin(lib, pluginFileName, pluginFileName, ll::Version(1, 0, 0), {})) {
logger.error(tr("ll.pluginManager.error.failToRegisterPlugin", UTF82String(path.u8string()))); logger.error(tr("ll.pluginManager.error.failToRegisterPlugin", UTF82String(path.u8string())));
if (getPlugin(pluginFileName)) { if (getPlugin(pluginFileName)) {
logger.error(tr("ll.pluginManager.error.hasBeenRegistered", pluginFileName)); logger.error(tr("ll.pluginManager.error.hasBeenRegistered", pluginFileName));
@ -283,22 +283,22 @@ void LL::LoadMain() {
} }
// Load PermissionAPI // Load PermissionAPI
if(LL::globalConfig.enablePermissionAPI) { if(ll::globalConfig.enablePermissionAPI) {
if (filesystem::exists("plugins/LiteLoader/PermissionAPI.dll")) { if (filesystem::exists("plugins/LiteLoader/PermissionAPI.dll")) {
LoadPermissionAPI(); LoadPermissionAPI();
} }
} }
if(LL::globalConfig.enableParticleAPI) { if(ll::globalConfig.enableParticleAPI) {
if (filesystem::exists("plugins/LiteLoader/ParticleAPI.dll")) { if (filesystem::exists("plugins/LiteLoader/ParticleAPI.dll")) {
LoadParticleAPI(); LoadParticleAPI();
} }
} }
// Load ScriptEngine // Load ScriptEngine
if (LL::globalConfig.enableScriptEngine) { if (ll::globalConfig.enableScriptEngine) {
InitNodeJsDirectories(); InitNodeJsDirectories();
if (LL::globalConfig.alwaysLaunchScriptEngine || IsExistNodeJsPlugin() || IsExistScriptPlugin()) { if (ll::globalConfig.alwaysLaunchScriptEngine || IsExistNodeJsPlugin() || IsExistScriptPlugin()) {
LoadScriptEngine(); LoadScriptEngine();
} }
} }

View File

@ -11,7 +11,7 @@ Logger serverLogger("Server");
extern void CheckBetaVersion(); extern void CheckBetaVersion();
THook(std::string, "?getServerVersionString@Common@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ") { THook(std::string, "?getServerVersionString@Common@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ") {
CheckBetaVersion(); CheckBetaVersion();
return original() + "(ProtocolVersion " + to_string(LL::getServerProtocolVersion()) + ") with " + fmt::format(LL::globalConfig.colorLog ? fg(fmt::color::light_sky_blue) | fmt::emphasis::bold | fmt::emphasis::italic : fmt::text_style(), "LiteLoaderBDS " + LL::getLoaderVersion().toString(true)); return original() + "(ProtocolVersion " + to_string(ll::getServerProtocolVersion()) + ") with " + fmt::format(ll::globalConfig.colorLog ? fg(fmt::color::light_sky_blue) | fmt::emphasis::bold | fmt::emphasis::italic : fmt::text_style(), "LiteLoaderBDS " + ll::getLoaderVersion().toString(true));
} }
@ -91,7 +91,7 @@ TClasslessInstanceHook(void*, "?send@CommandOutputSender@@UEAAXAEBVCommandOrigin
std::cout.rdbuf(&tmpBuf); std::cout.rdbuf(&tmpBuf);
auto rv = original(this, origin, output); auto rv = original(this, origin, output);
std::cout.rdbuf(oldBuf); std::cout.rdbuf(oldBuf);
if (LL::isDebugMode() && LL::globalConfig.tickThreadId != std::this_thread::get_id()) { if (ll::isDebugMode() && ll::globalConfig.tickThreadId != std::this_thread::get_id()) {
logger.warn("The thread executing the CommandOutputSender::send is not the \"MC_SERVER\" thread"); logger.warn("The thread executing the CommandOutputSender::send is not the \"MC_SERVER\" thread");
logger.warn("Output: {}", tmpBuf.str()); logger.warn("Output: {}", tmpBuf.str());
} }
@ -107,7 +107,7 @@ TClasslessInstanceHook(void*, "?send@CommandOutputSender@@UEAAXAEBVCommandOrigin
resultOfOrigin.erase(it); resultOfOrigin.erase(it);
return rv; return rv;
} catch (...) { } catch (...) {
if (LL::isDebugMode()) { if (ll::isDebugMode()) {
logger.warn("Output: {}", tmpBuf.str()); logger.warn("Output: {}", tmpBuf.str());
logger.warn("size of resultOfOrigin: {}", resultOfOrigin.size()); logger.warn("size of resultOfOrigin: {}", resultOfOrigin.size());
} }
@ -120,7 +120,7 @@ TClasslessInstanceHook(void*, "?send@CommandOutputSender@@UEAAXAEBVCommandOrigin
std::istringstream iss(tmpBuf.str()); std::istringstream iss(tmpBuf.str());
string line; string line;
while (getline(iss, line)) { while (getline(iss, line)) {
if (LL::globalConfig.colorLog) if (ll::globalConfig.colorLog)
log << ColorFormat::convertToConsole(line, false) << Logger::endl; log << ColorFormat::convertToConsole(line, false) << Logger::endl;
else else
log << ColorFormat::removeColorCode(line) << Logger::endl; log << ColorFormat::removeColorCode(line) << Logger::endl;

View File

@ -16,9 +16,9 @@
using namespace std; using namespace std;
extern Logger logger; extern Logger logger;
std::unordered_map<std::string, LL::Plugin> plugins; std::unordered_map<std::string, ll::Plugin> plugins;
bool LL::PluginManager::registerPlugin(HMODULE handle, std::string name, std::string desc, LL::Version version, bool ll::PluginManager::registerPlugin(HMODULE handle, std::string name, std::string desc, ll::Version version,
std::map<std::string, std::string> others) { std::map<std::string, std::string> others) {
if (handle != nullptr) // DLL Plugin if (handle != nullptr) // DLL Plugin
{ {
@ -31,7 +31,7 @@ bool LL::PluginManager::registerPlugin(HMODULE handle, std::string name, std::st
} }
} }
LL::Plugin plugin{name, desc, version, others}; ll::Plugin plugin{name, desc, version, others};
plugin.handle = handle; plugin.handle = handle;
try { try {
plugin.type = others.at("PluginType") == "Script Plugin" ? Plugin::PluginType::ScriptPlugin : Plugin::PluginType::DllPlugin; plugin.type = others.at("PluginType") == "Script Plugin" ? Plugin::PluginType::ScriptPlugin : Plugin::PluginType::DllPlugin;
@ -52,7 +52,7 @@ bool LL::PluginManager::registerPlugin(HMODULE handle, std::string name, std::st
return true; return true;
} }
bool LL::PluginManager::unRegisterPlugin(std::string name) { bool ll::PluginManager::unRegisterPlugin(std::string name) {
auto plugin = getPlugin(name); auto plugin = getPlugin(name);
if (plugin == nullptr) { if (plugin == nullptr) {
return false; return false;
@ -63,10 +63,10 @@ bool LL::PluginManager::unRegisterPlugin(std::string name) {
} }
// Helper // Helper
LL::Plugin* GetPlugin_Raw(std::string name, bool includeScriptPlugin) { ll::Plugin* GetPlugin_Raw(std::string name, bool includeScriptPlugin) {
for (auto& it : plugins) { for (auto& it : plugins) {
if (it.second.name == name || UTF82String(filesystem::path(str2wstr(it.second.filePath)).filename().u8string()) == name) { if (it.second.name == name || UTF82String(filesystem::path(str2wstr(it.second.filePath)).filename().u8string()) == name) {
if (!includeScriptPlugin && it.second.type == LL::Plugin::PluginType::ScriptPlugin) if (!includeScriptPlugin && it.second.type == ll::Plugin::PluginType::ScriptPlugin)
continue; continue;
return &it.second; return &it.second;
} }
@ -74,7 +74,7 @@ LL::Plugin* GetPlugin_Raw(std::string name, bool includeScriptPlugin) {
return nullptr; return nullptr;
} }
LL::Plugin* LL::PluginManager::getPlugin(std::string name, bool includeScriptPlugin) { ll::Plugin* ll::PluginManager::getPlugin(std::string name, bool includeScriptPlugin) {
auto res = GetPlugin_Raw(name, includeScriptPlugin); auto res = GetPlugin_Raw(name, includeScriptPlugin);
if (res) if (res)
return res; return res;
@ -90,7 +90,7 @@ LL::Plugin* LL::PluginManager::getPlugin(std::string name, bool includeScriptPlu
return nullptr; return nullptr;
} }
LL::Plugin* LL::PluginManager::getPlugin(HMODULE handle) { ll::Plugin* ll::PluginManager::getPlugin(HMODULE handle) {
if (!handle) if (!handle)
return nullptr; return nullptr;
@ -102,12 +102,12 @@ LL::Plugin* LL::PluginManager::getPlugin(HMODULE handle) {
return nullptr; return nullptr;
} }
bool LL::PluginManager::hasPlugin(std::string name, bool includeScriptPlugin) { bool ll::PluginManager::hasPlugin(std::string name, bool includeScriptPlugin) {
return getPlugin(name, includeScriptPlugin) != nullptr; return getPlugin(name, includeScriptPlugin) != nullptr;
} }
std::unordered_map<std::string, LL::Plugin*> LL::PluginManager::getAllPlugins(bool includeScriptPlugin) { std::unordered_map<std::string, ll::Plugin*> ll::PluginManager::getAllPlugins(bool includeScriptPlugin) {
std::unordered_map<std::string, LL::Plugin*> res; std::unordered_map<std::string, ll::Plugin*> res;
for (auto& [k, v] : plugins) { for (auto& [k, v] : plugins) {
if (!includeScriptPlugin && v.type == Plugin::PluginType::ScriptPlugin) if (!includeScriptPlugin && v.type == Plugin::PluginType::ScriptPlugin)
continue; continue;
@ -116,8 +116,8 @@ std::unordered_map<std::string, LL::Plugin*> LL::PluginManager::getAllPlugins(bo
return res; return res;
} }
bool LL::PluginManager::loadPlugin(string pluginFilePath, bool outputResult, bool isHotLoad) { bool ll::PluginManager::loadPlugin(string pluginFilePath, bool outputResult, bool isHotLoad) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
try { try {
filesystem::path path(filesystem::path(str2wstr(pluginFilePath)).lexically_normal()); filesystem::path path(filesystem::path(str2wstr(pluginFilePath)).lexically_normal());
@ -179,7 +179,7 @@ bool LL::PluginManager::loadPlugin(string pluginFilePath, bool outputResult, boo
auto lib = LoadLibrary(str2wstr(pluginFilePath).c_str()); auto lib = LoadLibrary(str2wstr(pluginFilePath).c_str());
if (lib) { if (lib) {
if (getPlugin(lib) == nullptr) { if (getPlugin(lib) == nullptr) {
if (!RegisterPlugin(lib, pluginFileName, pluginFileName, LL::Version(1, 0, 0), {})) { if (!RegisterPlugin(lib, pluginFileName, pluginFileName, ll::Version(1, 0, 0), {})) {
logger.error(tr("ll.pluginManager.error.failToRegisterPlugin", pluginFilePath)); logger.error(tr("ll.pluginManager.error.failToRegisterPlugin", pluginFilePath));
if (getPlugin(pluginFileName)) { if (getPlugin(pluginFileName)) {
logger.error(tr("ll.pluginManager.error.hasBeenRegistered", pluginFileName)); logger.error(tr("ll.pluginManager.error.hasBeenRegistered", pluginFileName));
@ -240,11 +240,11 @@ bool LL::PluginManager::loadPlugin(string pluginFilePath, bool outputResult, boo
} }
} }
bool LL::PluginManager::unloadPlugin(string pluginName, bool outputResult) { bool ll::PluginManager::unloadPlugin(string pluginName, bool outputResult) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
try { try {
LL::Plugin* plugin = getPlugin(pluginName); ll::Plugin* plugin = getPlugin(pluginName);
if (!plugin) { if (!plugin) {
if (outputResult) { if (outputResult) {
logger.error(tr("ll.pluginManager.error.pluginNotFound")); logger.error(tr("ll.pluginManager.error.pluginNotFound"));
@ -284,11 +284,11 @@ bool LL::PluginManager::unloadPlugin(string pluginName, bool outputResult) {
} }
} }
bool LL::PluginManager::reloadPlugin(string pluginName, bool outputResult) { bool ll::PluginManager::reloadPlugin(string pluginName, bool outputResult) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
try { try {
LL::Plugin* plugin = getPlugin(pluginName); ll::Plugin* plugin = getPlugin(pluginName);
if (!plugin) { if (!plugin) {
if (outputResult) { if (outputResult) {
logger.error(tr("ll.pluginManager.error.pluginNotFound")); logger.error(tr("ll.pluginManager.error.pluginNotFound"));
@ -327,8 +327,8 @@ bool LL::PluginManager::reloadPlugin(string pluginName, bool outputResult) {
} }
} }
int LL::PluginManager::reloadAllPlugins(bool outputResult) { int ll::PluginManager::reloadAllPlugins(bool outputResult) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
try { try {
auto plugins = getAllPlugins(true); auto plugins = getAllPlugins(true);
@ -367,8 +367,8 @@ int LL::PluginManager::reloadAllPlugins(bool outputResult) {
} }
} }
bool LL::PluginManager::callEventAtHotLoad(std::string pluginName) { bool ll::PluginManager::callEventAtHotLoad(std::string pluginName) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
Schedule::nextTick([pluginName]() { Schedule::nextTick([pluginName]() {
Event::ServerStartedEvent().callToPlugin(pluginName); // ServerStartedEvent Event::ServerStartedEvent().callToPlugin(pluginName); // ServerStartedEvent
@ -395,8 +395,8 @@ bool LL::PluginManager::callEventAtHotLoad(std::string pluginName) {
return true; return true;
} }
bool LL::PluginManager::callEventAtHotUnload(std::string pluginName) { bool ll::PluginManager::callEventAtHotUnload(std::string pluginName) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
auto players = Level::getAllPlayers(); auto players = Level::getAllPlayers();
for (auto& pl : players) // PlayerLeftEvent for (auto& pl : players) // PlayerLeftEvent
@ -412,9 +412,9 @@ bool LL::PluginManager::callEventAtHotUnload(std::string pluginName) {
} }
// Helper // Helper
LIAPI bool RegisterPlugin(HMODULE handle, std::string name, std::string desc, LL::Version version, LIAPI bool RegisterPlugin(HMODULE handle, std::string name, std::string desc, ll::Version version,
std::map<std::string, std::string> others) { std::map<std::string, std::string> others) {
others["PluginType"] = "DLL Plugin"; others["PluginType"] = "DLL Plugin";
others["PluginFilePath"] = handle ? GetModulePath(handle) : name; others["PluginFilePath"] = handle ? GetModulePath(handle) : name;
return LL::PluginManager::registerPlugin(handle, name, desc, version, others); return ll::PluginManager::registerPlugin(handle, name, desc, version, others);
} }

View File

@ -10,7 +10,7 @@ using namespace Event;
void RegisterSimpleServerLogger() { void RegisterSimpleServerLogger() {
if (LL::globalConfig.enableSimpleServerLogger) { if (ll::globalConfig.enableSimpleServerLogger) {
Event::PlayerChatEvent::subscribe([](const Event::PlayerChatEvent& ev) { Event::PlayerChatEvent::subscribe([](const Event::PlayerChatEvent& ev) {
static Logger logger("Chat"); static Logger logger("Chat");
logger.info("<{}> {}", ev.mPlayer->getRealName(), ev.mMessage); logger.info("<{}> {}", ev.mPlayer->getRealName(), ev.mMessage);
@ -28,7 +28,7 @@ void RegisterSimpleServerLogger() {
#include <llapi/HookAPI.h> #include <llapi/HookAPI.h>
TInstanceHook(void, "?setPermissions@ServerPlayer@@UEAAXW4CommandPermissionLevel@@@Z", TInstanceHook(void, "?setPermissions@ServerPlayer@@UEAAXW4CommandPermissionLevel@@@Z",
Player, CommandPermissionLevel perm) { Player, CommandPermissionLevel perm) {
if (LL::globalConfig.enableSimpleServerLogger) { if (ll::globalConfig.enableSimpleServerLogger) {
static Logger logger("Permissions"); static Logger logger("Permissions");
logger.info("<{}> {}({}) -> {}({})", logger.info("<{}> {}({}) -> {}({})",
getRealName(), magic_enum::enum_name(getCommandPermissionLevel()), (int)getCommandPermissionLevel(), magic_enum::enum_name(perm), (int)perm); getRealName(), magic_enum::enum_name(getCommandPermissionLevel()), (int)getCommandPermissionLevel(), magic_enum::enum_name(perm), (int)perm);

View File

@ -133,7 +133,7 @@ inline void OutputError(std::string errorMsg, int errorCode, std::string errorWh
logger.error("Error: Code [{}] {}", errorCode, errorWhat); logger.error("Error: Code [{}] {}", errorCode, errorWhat);
logger.error("In Event ({})", eventName); logger.error("In Event ({})", eventName);
if (!pluginName.empty()) { if (!pluginName.empty()) {
auto plugin = LL::getPlugin(pluginName); auto plugin = ll::getPlugin(pluginName);
if (plugin) { if (plugin) {
logger.error("In Plugin <{} {}>", plugin->name, plugin->version.toString()); logger.error("In Plugin <{} {}>", plugin->name, plugin->version.toString());
} else { } else {
@ -1071,7 +1071,7 @@ TInstanceHook(bool, "?canOpenContainerScreen@Player@@UEAA_NXZ", Player) {
return rtn; return rtn;
} }
if (LL::isDebugMode() && LL::globalConfig.tickThreadId != std::this_thread::get_id()) { if (ll::isDebugMode() && ll::globalConfig.tickThreadId != std::this_thread::get_id()) {
logger.warn("The thread executing the command \"{}\" is not the \"MC_SERVER\" thread", cmd); logger.warn("The thread executing the command \"{}\" is not the \"MC_SERVER\" thread", cmd);
} }
if (sp) { if (sp) {
@ -1996,14 +1996,14 @@ TClasslessInstanceHook(void, "?onScoreChanged@ServerScoreboard@@UEAAXAEBUScorebo
// 没有这个符号 // 没有这个符号
TClasslessInstanceHook(void, "?onServerThreadStarted@MinecraftServerScriptEngine@@UEAA?AW4EventResult@@AEAVServerInstance@@@Z", TClasslessInstanceHook(void, "?onServerThreadStarted@MinecraftServerScriptEngine@@UEAA?AW4EventResult@@AEAVServerInstance@@@Z",
class ServerInstance& ins) { class ServerInstance& ins) {
if(!LL::isDebugMode()) if(!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
LL::globalConfig.tickThreadId = std::this_thread::get_id(); ll::globalConfig.tickThreadId = std::this_thread::get_id();
Global<Level> = Global<Minecraft>->getLevel(); Global<Level> = Global<Minecraft>->getLevel();
Global<ServerLevel> = (ServerLevel*)Global<Minecraft>->getLevel(); Global<ServerLevel> = (ServerLevel*)Global<Minecraft>->getLevel();
// Global<ServerNetworkHandler> = Global<Minecraft>->getServerNetworkHandler(); // Global<ServerNetworkHandler> = Global<Minecraft>->getServerNetworkHandler();
LL::globalConfig.serverStatus = LL::LLServerStatus::Running; ll::globalConfig.serverStatus = ll::LLServerStatus::Running;
IF_LISTENED(ServerStartedEvent) { IF_LISTENED(ServerStartedEvent) {
ServerStartedEvent ev{}; ServerStartedEvent ev{};
@ -2016,7 +2016,7 @@ TClasslessInstanceHook(void, "?onScoreChanged@ServerScoreboard@@UEAAXAEBUScorebo
////////////// ServerStopped ////////////// ////////////// ServerStopped //////////////
TClasslessInstanceHook(void, "??1DedicatedServer@@UEAA@XZ") { TClasslessInstanceHook(void, "??1DedicatedServer@@UEAA@XZ") {
LL::globalConfig.serverStatus = LL::LLServerStatus::Stopping; ll::globalConfig.serverStatus = ll::LLServerStatus::Stopping;
IF_LISTENED(ServerStoppedEvent) { IF_LISTENED(ServerStoppedEvent) {
ServerStoppedEvent ev{}; ServerStoppedEvent ev{};
@ -2027,7 +2027,7 @@ TClasslessInstanceHook(void, "??1DedicatedServer@@UEAA@XZ") {
} }
TClasslessInstanceHook(void, "?execute@StopCommand@@UEBAXAEBVCommandOrigin@@AEAVCommandOutput@@@Z", TClasslessInstanceHook(void, "?execute@StopCommand@@UEBAXAEBVCommandOrigin@@AEAVCommandOutput@@@Z",
class CommandOrigin const& origin, class CommandOutput& output) { class CommandOrigin const& origin, class CommandOutput& output) {
LL::globalConfig.serverStatus = LL::LLServerStatus::Stopping; ll::globalConfig.serverStatus = ll::LLServerStatus::Stopping;
original(this, origin, output); original(this, origin, output);
} }

View File

@ -10,7 +10,7 @@
using namespace std; using namespace std;
std::string LL::getDataPath(const std::string& pluginName) { std::string ll::getDataPath(const std::string& pluginName) {
string dataPath = "plugins\\LiteLoader\\" + pluginName; string dataPath = "plugins\\LiteLoader\\" + pluginName;
if (!filesystem::exists(str2wstr(dataPath))) { if (!filesystem::exists(str2wstr(dataPath))) {
std::error_code ec; std::error_code ec;
@ -19,53 +19,53 @@ std::string LL::getDataPath(const std::string& pluginName) {
return dataPath; return dataPath;
} }
std::string LL::getLoaderVersionString() { std::string ll::getLoaderVersionString() {
return getLoaderVersion().toString(); return getLoaderVersion().toString();
} }
LL::Version LL::getLoaderVersion() { ll::Version ll::getLoaderVersion() {
return Version(LITELOADER_VERSION_MAJOR, LITELOADER_VERSION_MINOR, LITELOADER_VERSION_REVISION, (LL::Version::Status)LITELOADER_VERSION_STATUS); return Version(LITELOADER_VERSION_MAJOR, LITELOADER_VERSION_MINOR, LITELOADER_VERSION_REVISION, (ll::Version::Status)LITELOADER_VERSION_STATUS);
} }
bool LL::isDebugMode() { bool ll::isDebugMode() {
return LL::globalConfig.debugMode; return ll::globalConfig.debugMode;
} }
LL::Plugin* LL::getPlugin(std::string name) { ll::Plugin* ll::getPlugin(std::string name) {
return PluginManager::getPlugin(name); return PluginManager::getPlugin(name);
} }
LL::Plugin* LL::getPlugin(HMODULE handle) { ll::Plugin* ll::getPlugin(HMODULE handle) {
return PluginManager::getPlugin(handle); return PluginManager::getPlugin(handle);
} }
bool LL::hasPlugin(std::string name) { bool ll::hasPlugin(std::string name) {
return PluginManager::hasPlugin(name); return PluginManager::hasPlugin(name);
} }
std::unordered_map<std::string, LL::Plugin*> LL::getAllPlugins() { std::unordered_map<std::string, ll::Plugin*> ll::getAllPlugins() {
return PluginManager::getAllPlugins(); return PluginManager::getAllPlugins();
} }
HMODULE LL::getLoaderHandle() { HMODULE ll::getLoaderHandle() {
return GetCurrentModule(); return GetCurrentModule();
} }
// Version // Version
LL::Version::Version(int major, int minor, int revision, Status status) ll::Version::Version(int major, int minor, int revision, Status status)
: major(major), minor(minor), revision(revision), status(status) { : major(major), minor(minor), revision(revision), status(status) {
} }
bool LL::Version::operator<(LL::Version b) { bool ll::Version::operator<(ll::Version b) {
return major < b.major || (major == b.major && minor < b.minor) || return major < b.major || (major == b.major && minor < b.minor) ||
(major == b.major && minor == b.minor && revision < b.revision); (major == b.major && minor == b.minor && revision < b.revision);
} }
bool LL::Version::operator==(LL::Version b) { bool ll::Version::operator==(ll::Version b) {
return major == b.major && minor == b.minor && revision == b.revision; return major == b.major && minor == b.minor && revision == b.revision;
} }
std::string LL::Version::toString(bool needStatus) { std::string ll::Version::toString(bool needStatus) {
string res = to_string(major) + "." + to_string(minor) + "." + to_string(revision); string res = to_string(major) + "." + to_string(minor) + "." + to_string(revision);
if (needStatus) { if (needStatus) {
if (status == Status::Beta) if (status == Status::Beta)
@ -77,7 +77,7 @@ std::string LL::Version::toString(bool needStatus) {
} }
LL::Version LL::Version::parse(const std::string& str) { ll::Version ll::Version::parse(const std::string& str) {
Version ver; Version ver;
std::string a = str; std::string a = str;
std::string status; std::string status;
@ -106,18 +106,18 @@ LL::Version LL::Version::parse(const std::string& str) {
return ver; return ver;
} }
LL::ServerStatus LL::getServerStatus() { ll::ServerStatus ll::getServerStatus() {
return (LL::ServerStatus)(LL::globalConfig.serverStatus); return (ll::ServerStatus)(ll::globalConfig.serverStatus);
} }
bool LL::isServerStarting() { bool ll::isServerStarting() {
return getServerStatus() == LL::ServerStatus::Starting; return getServerStatus() == ll::ServerStatus::Starting;
} }
bool LL::isServerStopping() { bool ll::isServerStopping() {
return getServerStatus() == LL::ServerStatus::Stopping; return getServerStatus() == ll::ServerStatus::Stopping;
} }
std::string LL::getLanguage() { std::string ll::getLanguage() {
return LL::globalConfig.language; return ll::globalConfig.language;
} }

View File

@ -88,13 +88,13 @@ Logger::OutputStream::OutputStream(Logger* logger, int level, std::string&& cons
bool checkLogLevel(int level, int outLevel) { bool checkLogLevel(int level, int outLevel) {
if (level >= outLevel) if (level >= outLevel)
return true; return true;
if (level == -1 && LL::globalConfig.logLevel >= outLevel) if (level == -1 && ll::globalConfig.logLevel >= outLevel)
return true; return true;
return false; return false;
} }
#define H do_hash #define H do_hash
fmt::text_style getModeColor(string a1) { fmt::text_style getModeColor(string a1) {
if (!LL::globalConfig.colorLog) if (!ll::globalConfig.colorLog)
return fmt::text_style(); return fmt::text_style();
switch (H(a1.c_str())) { switch (H(a1.c_str())) {
case H("INFO"): case H("INFO"):
@ -148,8 +148,8 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) {
auto text = o.os.str(); auto text = o.os.str();
bool filterBanned = false; bool filterBanned = false;
// Output Filter // Output Filter
if (LL::globalConfig.enableOutputFilter) if (ll::globalConfig.enableOutputFilter)
for (auto& regexStr : LL::globalConfig.outputFilterRegex) { for (auto& regexStr : ll::globalConfig.outputFilterRegex) {
try { try {
std::regex re(regexStr); std::regex re(regexStr);
if (std::regex_search(text, re) || std::regex_search(title, re)) { if (std::regex_search(text, re) || std::regex_search(title, re)) {
@ -162,14 +162,14 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) {
if (checkLogLevel(o.logger->consoleLevel, o.level) && !filterBanned) { if (checkLogLevel(o.logger->consoleLevel, o.level) && !filterBanned) {
fmt::print( fmt::print(
o.consoleFormat, o.consoleFormat,
applyTextStyle(LL::globalConfig.colorLog ? fg(fmt::color::light_blue) : fmt::text_style(), applyTextStyle(ll::globalConfig.colorLog ? fg(fmt::color::light_blue) : fmt::text_style(),
fmt::format("{:%H:%M:%S}", fmt::localtime(_time64(nullptr)))), fmt::format("{:%H:%M:%S}", fmt::localtime(_time64(nullptr)))),
applyTextStyle(getModeColor(o.levelPrefix), o.levelPrefix), 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(), title),
applyTextStyle(LL::globalConfig.colorLog ? o.style : fmt::text_style(), text)); applyTextStyle(ll::globalConfig.colorLog ? o.style : fmt::text_style(), text));
} }
if (checkLogLevel(o.logger->fileLevel, o.level) && (LL::globalConfig.onlyFilterConsoleOutput || !filterBanned)) { if (checkLogLevel(o.logger->fileLevel, o.level) && (ll::globalConfig.onlyFilterConsoleOutput || !filterBanned)) {
if (o.logger->ofs.is_open() || PluginOwnData::hasImpl(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, text); auto fileContent = fmt::format(o.fileFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, text);
if (o.logger->ofs.is_open()) if (o.logger->ofs.is_open())
@ -180,7 +180,7 @@ void Logger::endlImpl(HMODULE hPlugin, OutputStream& o) {
} }
} }
if (checkLogLevel(o.logger->playerLevel, o.level) && o.logger->player && Player::isValid(o.logger->player) && (LL::globalConfig.onlyFilterConsoleOutput || !filterBanned)) { if (checkLogLevel(o.logger->playerLevel, o.level) && o.logger->player && Player::isValid(o.logger->player) && (ll::globalConfig.onlyFilterConsoleOutput || !filterBanned)) {
o.logger->player->sendTextPacket( o.logger->player->sendTextPacket(
fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, text)); fmt::format(o.playerFormat, fmt::localtime(_time64(nullptr)), o.levelPrefix, title, text));
} }

View File

@ -41,7 +41,7 @@ bool removeFunc(std::string const& nameSpace, std::string const& funcName) {
void _onCallError(std::string const& msg, HMODULE handle) { void _onCallError(std::string const& msg, HMODULE handle) {
logger.error(msg); logger.error(msg);
auto plugin = LL::getPlugin(handle); auto plugin = ll::getPlugin(handle);
if (plugin) if (plugin)
logger.error("In plugin <{}>", plugin->name); logger.error("In plugin <{}>", plugin->name);
} }

View File

@ -147,18 +147,18 @@ public:
logger.error("SEH exception occurred in ScheduleTask!"); logger.error("SEH exception occurred in ScheduleTask!");
logger.error("{}", TextEncoding::toUTF8(e.what())); logger.error("{}", TextEncoding::toUTF8(e.what()));
logger.error("TaskId: {}", t.taskId); logger.error("TaskId: {}", t.taskId);
if (auto plugin = LL::getPlugin(t.handle)) if (auto plugin = ll::getPlugin(t.handle))
logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString()); logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString());
} catch (const std::exception& e) { } catch (const std::exception& e) {
logger.error("Exception occurred in ScheduleTask!"); logger.error("Exception occurred in ScheduleTask!");
logger.error("{}", TextEncoding::toUTF8(e.what())); logger.error("{}", TextEncoding::toUTF8(e.what()));
logger.error("TaskId: {}", t.taskId); logger.error("TaskId: {}", t.taskId);
if (auto plugin = LL::getPlugin(t.handle)) if (auto plugin = ll::getPlugin(t.handle))
logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString()); logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString());
} catch (...) { } catch (...) {
logger.error("Exception occurred in ScheduleTask!"); logger.error("Exception occurred in ScheduleTask!");
logger.error("TaskId: {}", t.taskId); logger.error("TaskId: {}", t.taskId);
if (auto plugin = LL::getPlugin(t.handle)) if (auto plugin = ll::getPlugin(t.handle))
logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString()); logger.error("In Plugin: <{} {}>", plugin->name, plugin->version.toString());
} }
pop(); pop();
@ -181,7 +181,7 @@ ScheduleTaskQueueType taskQueue;
namespace Schedule { namespace Schedule {
ScheduleTask delay(std::function<void(void)> task, unsigned long long tickDelay, HMODULE handle) { ScheduleTask delay(std::function<void(void)> task, unsigned long long tickDelay, HMODULE handle) {
if (LL::globalConfig.serverStatus >= LL::LLServerStatus::Stopping) if (ll::globalConfig.serverStatus >= ll::LLServerStatus::Stopping)
return ScheduleTask((unsigned)-1); return ScheduleTask((unsigned)-1);
ScheduleTaskData sche(ScheduleTaskData::TaskType::Delay, task, tickDelay, -1, -1, handle); ScheduleTaskData sche(ScheduleTaskData::TaskType::Delay, task, tickDelay, -1, -1, handle);
locker.lock(); locker.lock();
@ -191,7 +191,7 @@ ScheduleTask delay(std::function<void(void)> task, unsigned long long tickDelay,
} }
ScheduleTask repeat(std::function<void(void)> task, unsigned long long tickRepeat, int maxCount, HMODULE handle) { ScheduleTask repeat(std::function<void(void)> task, unsigned long long tickRepeat, int maxCount, HMODULE handle) {
if (LL::globalConfig.serverStatus >= LL::LLServerStatus::Stopping) if (ll::globalConfig.serverStatus >= ll::LLServerStatus::Stopping)
return ScheduleTask((unsigned)-1); return ScheduleTask((unsigned)-1);
ScheduleTaskData::TaskType type = maxCount < 0 ? ScheduleTaskData::TaskType::InfiniteRepeat ScheduleTaskData::TaskType type = maxCount < 0 ? ScheduleTaskData::TaskType::InfiniteRepeat
: ScheduleTaskData::TaskType::Repeat; : ScheduleTaskData::TaskType::Repeat;
@ -204,7 +204,7 @@ ScheduleTask repeat(std::function<void(void)> task, unsigned long long tickRepea
ScheduleTask delayRepeat(std::function<void(void)> task, unsigned long long tickDelay, ScheduleTask delayRepeat(std::function<void(void)> task, unsigned long long tickDelay,
unsigned long long tickRepeat, int maxCount, HMODULE handle) { unsigned long long tickRepeat, int maxCount, HMODULE handle) {
if (LL::globalConfig.serverStatus >= LL::LLServerStatus::Stopping) if (ll::globalConfig.serverStatus >= ll::LLServerStatus::Stopping)
return ScheduleTask((unsigned)-1); return ScheduleTask((unsigned)-1);
ScheduleTaskData::TaskType type = maxCount < 0 ? ScheduleTaskData::TaskType::InfiniteRepeat ScheduleTaskData::TaskType type = maxCount < 0 ? ScheduleTaskData::TaskType::InfiniteRepeat
: ScheduleTaskData::TaskType::Repeat; : ScheduleTaskData::TaskType::Repeat;
@ -216,7 +216,7 @@ ScheduleTask delayRepeat(std::function<void(void)> task, unsigned long long tick
} }
ScheduleTask nextTick(std::function<void(void)> task, HMODULE handle) { ScheduleTask nextTick(std::function<void(void)> task, HMODULE handle) {
if (LL::globalConfig.serverStatus >= LL::LLServerStatus::Stopping) if (ll::globalConfig.serverStatus >= ll::LLServerStatus::Stopping)
return ScheduleTask((unsigned)-1); return ScheduleTask((unsigned)-1);
ScheduleTaskData sche(ScheduleTaskData::TaskType::Delay, task, 1, -1, -1, handle); ScheduleTaskData sche(ScheduleTaskData::TaskType::Delay, task, 1, -1, -1, handle);
locker.lock(); locker.lock();

View File

@ -6,7 +6,7 @@
#include <string> #include <string>
class UserEntityIdentifierComponent; class UserEntityIdentifierComponent;
namespace LL { namespace ll {
std::string getBdsVersion() { std::string getBdsVersion() {
return Common::getGameVersionString(); return Common::getGameVersionString();
} }
@ -22,4 +22,4 @@ bool setServerMotd(const std::string& motd) {
Global<ServerNetworkHandler>->allowIncomingConnections(motd, true); Global<ServerNetworkHandler>->allowIncomingConnections(motd, true);
return true; return true;
} }
} // namespace LL } // namespace ll

View File

@ -93,7 +93,7 @@
#include <liteloader/Config.h> #include <liteloader/Config.h>
bool CommandRegistry::unregisterCommand(std::string const& name) { bool CommandRegistry::unregisterCommand(std::string const& name) {
if (!LL::globalConfig.debugMode) { if (!ll::globalConfig.debugMode) {
logger.error("unregister command is only enabled in debug mode"); logger.error("unregister command is only enabled in debug mode");
return false; return false;
} }

View File

@ -127,7 +127,7 @@
logger.error(errorMsg); logger.error(errorMsg);
logger.error("Error: Code [{}] {}", errorCode, errorWhat); logger.error("Error: Code [{}] {}", errorCode, errorWhat);
logger.error("In Function ({})", func); logger.error("In Function ({})", func);
if (auto plugin = LL::getPlugin(handle)) if (auto plugin = ll::getPlugin(handle))
logger.error("In Plugin <{}>", plugin->name); logger.error("In Plugin <{}>", plugin->name);
} }
@ -537,7 +537,7 @@
std::string name = command->getCommandName(); std::string name = command->getCommandName();
auto handle = command->handle; auto handle = command->handle;
try { try {
if (!LL::getPlugin(handle) && handle != GetCurrentModule()) if (!ll::getPlugin(handle) && handle != GetCurrentModule())
throw std::runtime_error("Plugin that registered command \"" + name + "\" not found"); throw std::runtime_error("Plugin that registered command \"" + name + "\" not found");
auto res = DynamicCommand::_setup(std::move(command)); auto res = DynamicCommand::_setup(std::move(command));
if (!res) if (!res)
@ -698,7 +698,7 @@
} }
inline std::unique_ptr<DynamicCommandInstance> DynamicCommandInstance::create(std::string const& name, std::string const& description, CommandPermissionLevel permission, CommandFlag flag, HMODULE handle) { inline std::unique_ptr<DynamicCommandInstance> DynamicCommandInstance::create(std::string const& name, std::string const& description, CommandPermissionLevel permission, CommandFlag flag, HMODULE handle) {
if (LL::globalConfig.serverStatus != LL::LLServerStatus::Running) { if (ll::globalConfig.serverStatus != ll::LLServerStatus::Running) {
for (auto& cmd : delaySetupCommandInstances) { for (auto& cmd : delaySetupCommandInstances) {
if (cmd->name == name) { if (cmd->name == name) {
logger.error("Command \"{}\" already exists", name); logger.error("Command \"{}\" already exists", name);
@ -1279,7 +1279,7 @@
TClasslessInstanceHook(void, "?compile@BaseCommandBlock@@AEAAXAEBVCommandOrigin@@AEAVLevel@@@Z", TClasslessInstanceHook(void, "?compile@BaseCommandBlock@@AEAAXAEBVCommandOrigin@@AEAVLevel@@@Z",
class CommandOrigin const& origin, class Level& level) { class CommandOrigin const& origin, class Level& level) {
if (LL::globalConfig.tickThreadId != std::this_thread::get_id()) { if (ll::globalConfig.tickThreadId != std::this_thread::get_id()) {
SRWLockSharedHolder locker(delaySetupLock); SRWLockSharedHolder locker(delaySetupLock);
return original(this, origin, level); return original(this, origin, level);
} }

View File

@ -105,7 +105,7 @@ wstring MapModuleFromAddr(HANDLE hProcess, void* address) {
bool PrintCurrentStackTraceback(PEXCEPTION_POINTERS e, Logger* l) { bool PrintCurrentStackTraceback(PEXCEPTION_POINTERS e, Logger* l) {
Logger& debugLogger = l ? *l : logger; Logger& debugLogger = l ? *l : logger;
if (!LL::globalConfig.enableErrorStackTraceback) { if (!ll::globalConfig.enableErrorStackTraceback) {
logger.error("* Stack traceback is disabled by config file."); logger.error("* Stack traceback is disabled by config file.");
return true; return true;
} }
@ -113,7 +113,7 @@ bool PrintCurrentStackTraceback(PEXCEPTION_POINTERS e, Logger* l) {
HANDLE hProcess = GetCurrentProcess(); HANDLE hProcess = GetCurrentProcess();
HANDLE hThread = GetCurrentThread(); HANDLE hThread = GetCurrentThread();
DWORD threadId = GetCurrentThreadId(); DWORD threadId = GetCurrentThreadId();
bool cacheSymbol = LL::globalConfig.cacheErrorStackTracebackSymbol; bool cacheSymbol = ll::globalConfig.cacheErrorStackTracebackSymbol;
bool res = false; bool res = false;
std::thread printThread([e, hProcess, hThread, threadId, cacheSymbol, &res, &debugLogger]() { std::thread printThread([e, hProcess, hThread, threadId, cacheSymbol, &res, &debugLogger]() {

View File

@ -111,7 +111,7 @@ TInstanceHook(Scoreboard*, "??0ServerScoreboard@@QEAA@VCommandSoftEnumRegistry@@
#include <llapi/mc/PropertiesSettings.hpp> #include <llapi/mc/PropertiesSettings.hpp>
TInstanceHook(size_t, "??0PropertiesSettings@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z", PropertiesSettings, const std::string& file) { TInstanceHook(size_t, "??0PropertiesSettings@@QEAA@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z", PropertiesSettings, const std::string& file) {
auto out = original(this, file); auto out = original(this, file);
// if (LL::globalConfig.enableUnoccupyPort19132) { // if (ll::globalConfig.enableUnoccupyPort19132) {
// // logger.warn("If you turn on this feature, your server will not be displayed on the LAN"); // // logger.warn("If you turn on this feature, your server will not be displayed on the LAN");
// DWORD v4Flag, v6Flag; // DWORD v4Flag, v6Flag;
// VirtualProtect((void*)&SharedConstants::NetworkDefaultGamePort, 4, PAGE_READWRITE, &v4Flag); // VirtualProtect((void*)&SharedConstants::NetworkDefaultGamePort, 4, PAGE_READWRITE, &v4Flag);

View File

@ -40,7 +40,7 @@ bool HttpGet(const string& url, const httplib::Headers& headers, const function<
cli->set_connection_timeout(timeout, 0); cli->set_connection_timeout(timeout, 0);
std::thread([cli, headers, callback, path{std::move(path)}]() { std::thread([cli, headers, callback, path{std::move(path)}]() {
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
try { try {
auto response = cli->Get(path.c_str(), headers); auto response = cli->Get(path.c_str(), headers);
@ -86,7 +86,7 @@ bool HttpPost(const string& url, const httplib::Headers& headers, const string&
cli->set_connection_timeout(timeout, 0); cli->set_connection_timeout(timeout, 0);
std::thread([cli, headers, data, type, callback, path{std::move(path)}]() { std::thread([cli, headers, data, type, callback, path{std::move(path)}]() {
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
try { try {
auto response = cli->Post(path.c_str(), headers, data, type.c_str()); auto response = cli->Post(path.c_str(), headers, data, type.c_str());

View File

@ -73,7 +73,7 @@ bool NewProcess(const std::string& process, std::function<void(int, std::string)
std::thread([hRead{hRead}, hProcess{pi.hProcess}, std::thread([hRead{hRead}, hProcess{pi.hProcess},
callback{std::move(callback)}, timeLimit{timeLimit}, wCmd{wCmd}]() { callback{std::move(callback)}, timeLimit{timeLimit}, wCmd{wCmd}]() {
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
if (timeLimit == -1) if (timeLimit == -1)
WaitForSingleObject(hProcess, INFINITE); WaitForSingleObject(hProcess, INFINITE);

View File

@ -244,14 +244,14 @@ Local<Value> McClass::newFloatPos(const Arguments& args) {
Local<Value> McClass::getBDSVersion(const Arguments& args) { Local<Value> McClass::getBDSVersion(const Arguments& args) {
try { try {
return String::newString(LL::getBdsVersion()); return String::newString(ll::getBdsVersion());
} }
CATCH("Fail in GetBDSVersion!") CATCH("Fail in GetBDSVersion!")
} }
Local<Value> McClass::getServerProtocolVersion(const Arguments& args) { Local<Value> McClass::getServerProtocolVersion(const Arguments& args) {
try { try {
return Number::newNumber(LL::getServerProtocolVersion()); return Number::newNumber(ll::getServerProtocolVersion());
} }
CATCH("Fail in GetServerProtocolVersion!") CATCH("Fail in GetServerProtocolVersion!")
} }

View File

@ -1141,7 +1141,7 @@ void InitBasicEventListeners() {
// Plugin Hot Management // Plugin Hot Management
Event::ScriptPluginManagerEvent::subscribe_ref([](ScriptPluginManagerEvent& ev) { Event::ScriptPluginManagerEvent::subscribe_ref([](ScriptPluginManagerEvent& ev) {
// if (!LL::isDebugMode()) // if (!ll::isDebugMode())
// return false; // return false;
switch (ev.operation) { switch (ev.operation) {

View File

@ -233,7 +233,7 @@ Local<Value> FileClass::read(const Arguments& args) {
pool.enqueue([cnt, fp{&file}, isBinary{isBinary}, lock{&lock}, pool.enqueue([cnt, fp{&file}, isBinary{isBinary}, lock{&lock},
callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() { callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -267,7 +267,7 @@ Local<Value> FileClass::readLine(const Arguments& args) {
pool.enqueue([fp{&file}, lock{&lock}, pool.enqueue([fp{&file}, lock{&lock},
callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() { callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -297,7 +297,7 @@ Local<Value> FileClass::readAll(const Arguments& args) {
pool.enqueue([fp{&file}, isBinary{isBinary}, lock{&lock}, pool.enqueue([fp{&file}, isBinary{isBinary}, lock{&lock},
callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() { callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -342,7 +342,7 @@ Local<Value> FileClass::write(const Arguments& args) {
pool.enqueue([fp{&file}, lock{&lock}, data{std::move(data)}, isString, pool.enqueue([fp{&file}, lock{&lock}, data{std::move(data)}, isString,
callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() { callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -383,7 +383,7 @@ Local<Value> FileClass::writeLine(const Arguments& args) {
pool.enqueue([fp{&file}, lock{&lock}, data{std::move(data)}, pool.enqueue([fp{&file}, lock{&lock}, data{std::move(data)},
callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() { callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;

View File

@ -58,7 +58,7 @@ bool SimpleFormClass::sendForm(Form::SimpleForm* form, Player* player, script::L
return form->sendTo(player, return form->sendTo(player,
[engine{EngineScope::currentEngine()}, callback{std::move(callbackFunc)}](Player* pl, int chosen) { [engine{EngineScope::currentEngine()}, callback{std::move(callbackFunc)}](Player* pl, int chosen) {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -140,7 +140,7 @@ bool CustomFormClass::sendForm(Form::CustomForm* form, Player* player, script::L
return form->sendToForRawJson(player, return form->sendToForRawJson(player,
[engine{EngineScope::currentEngine()}, callback{std::move(callbackFunc)}](Player* pl, string data) { [engine{EngineScope::currentEngine()}, callback{std::move(callbackFunc)}](Player* pl, string data) {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;

View File

@ -54,7 +54,7 @@ Local<Value> LlClass::registerPlugin(const Arguments& args) {
string name = args[0].toStr(); string name = args[0].toStr();
string desc = args.size() >= 2 ? args[1].toStr() : ""; string desc = args.size() >= 2 ? args[1].toStr() : "";
LL::Version ver = LL::Version(1, 0, 0); ll::Version ver = ll::Version(1, 0, 0);
if (args.size() >= 3) { if (args.size() >= 3) {
if (args[2].isArray()) { if (args[2].isArray()) {
Local<Array> verInfo = args[2].asArray(); Local<Array> verInfo = args[2].asArray();
@ -118,7 +118,7 @@ Local<Value> LlClass::getPluginInfo(const Arguments& args) {
try { try {
std::string name = args[0].toStr(); std::string name = args[0].toStr();
auto plugin = LL::getPlugin(name); auto plugin = ll::getPlugin(name);
if (plugin) { if (plugin) {
auto result = Object::newObject(); auto result = Object::newObject();
@ -150,11 +150,11 @@ Local<Value> LlClass::getVersionStatus(const Arguments& args) {
try { try {
int versionStatusValue; int versionStatusValue;
if (LITELOADER_VERSION_STATUS == LL::Version::Status::Release) { if (LITELOADER_VERSION_STATUS == ll::Version::Status::Release) {
versionStatusValue = 0; versionStatusValue = 0;
} else if (LITELOADER_VERSION_STATUS == LL::Version::Status::Beta) { } else if (LITELOADER_VERSION_STATUS == ll::Version::Status::Beta) {
versionStatusValue = 1; versionStatusValue = 1;
} else if (LITELOADER_VERSION_STATUS == LL::Version::Status::Dev) { } else if (LITELOADER_VERSION_STATUS == ll::Version::Status::Dev) {
versionStatusValue = 2; versionStatusValue = 2;
} }
@ -169,9 +169,9 @@ Local<Value> LlClass::version(const Arguments& args) {
ver.set("major", LITELOADER_VERSION_MAJOR); ver.set("major", LITELOADER_VERSION_MAJOR);
ver.set("minor", LITELOADER_VERSION_MINOR); ver.set("minor", LITELOADER_VERSION_MINOR);
ver.set("revision", LITELOADER_VERSION_REVISION); ver.set("revision", LITELOADER_VERSION_REVISION);
ver.set("isBeta", LITELOADER_VERSION_STATUS == LL::Version::Status::Beta); ver.set("isBeta", LITELOADER_VERSION_STATUS == ll::Version::Status::Beta);
ver.set("isRelease", LITELOADER_VERSION_STATUS == LL::Version::Status::Release); ver.set("isRelease", LITELOADER_VERSION_STATUS == ll::Version::Status::Release);
ver.set("isDev", LITELOADER_VERSION_STATUS == LL::Version::Status::Dev); ver.set("isDev", LITELOADER_VERSION_STATUS == ll::Version::Status::Dev);
return ver; return ver;
} }
CATCH("Fail in LLSEGetVersion!") CATCH("Fail in LLSEGetVersion!")
@ -179,21 +179,21 @@ Local<Value> LlClass::version(const Arguments& args) {
Local<Value> LlClass::getLanguage() { Local<Value> LlClass::getLanguage() {
try { try {
return String::newString(PluginOwnData::getImpl<I18nBase>(LL::getLoaderHandle(), I18nBase::POD_KEY).defaultLocaleName); return String::newString(PluginOwnData::getImpl<I18nBase>(ll::getLoaderHandle(), I18nBase::POD_KEY).defaultLocaleName);
} }
CATCH("Fail in LLSEGetLanguage") CATCH("Fail in LLSEGetLanguage")
} }
Local<Value> LlClass::isDebugMode(const Arguments& args) { Local<Value> LlClass::isDebugMode(const Arguments& args) {
try { try {
return Boolean::newBoolean(LL::isDebugMode()); return Boolean::newBoolean(ll::isDebugMode());
} }
CATCH("Fail in LLSEGetIsDebugMode") CATCH("Fail in LLSEGetIsDebugMode")
} }
Local<Value> LlClass::versionString(const Arguments& args) { Local<Value> LlClass::versionString(const Arguments& args) {
try { try {
return String::newString(LL::getLoaderVersionString()); return String::newString(ll::getLoaderVersionString());
} }
CATCH("Fail in LLSEGetVersionString!") CATCH("Fail in LLSEGetVersionString!")
} }

View File

@ -153,10 +153,10 @@ void WSClientClass::initListeners() {
void WSClientClass::initListeners_s() { void WSClientClass::initListeners_s() {
ws->OnTextReceived([nowList{&listeners[int(WSClientEvents::onTextReceived)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, string msg) { ws->OnTextReceived([nowList{&listeners[int(WSClientEvents::onTextReceived)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, string msg) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
Schedule::nextTick([nowList, engine, msg = std::move(msg)]() { Schedule::nextTick([nowList, engine, msg = std::move(msg)]() {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
if (!nowList->empty()) if (!nowList->empty())
@ -167,10 +167,10 @@ void WSClientClass::initListeners_s() {
}); });
ws->OnBinaryReceived([nowList{&listeners[int(WSClientEvents::onBinaryReceived)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, vector<uint8_t> data) { ws->OnBinaryReceived([nowList{&listeners[int(WSClientEvents::onBinaryReceived)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, vector<uint8_t> data) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
Schedule::nextTick([nowList, engine, data = std::move(data)]() mutable { Schedule::nextTick([nowList, engine, data = std::move(data)]() mutable {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
if (!nowList->empty()) if (!nowList->empty())
@ -181,10 +181,10 @@ void WSClientClass::initListeners_s() {
}); });
ws->OnError([nowList{&listeners[int(WSClientEvents::onError)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, string msg) { ws->OnError([nowList{&listeners[int(WSClientEvents::onError)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, string msg) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
Schedule::nextTick([nowList, engine, msg = std::move(msg)]() { Schedule::nextTick([nowList, engine, msg = std::move(msg)]() {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
if (!nowList->empty()) if (!nowList->empty())
@ -195,10 +195,10 @@ void WSClientClass::initListeners_s() {
}); });
ws->OnLostConnection([nowList{&listeners[int(WSClientEvents::onLostConnection)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, int code) { ws->OnLostConnection([nowList{&listeners[int(WSClientEvents::onLostConnection)]}, engine = EngineScope::currentEngine()](WebSocketClient& client, int code) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
Schedule::nextTick([nowList, engine, code]() { Schedule::nextTick([nowList, engine, code]() {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
if (!nowList->empty()) if (!nowList->empty())
@ -277,7 +277,7 @@ Local<Value> WSClientClass::connectAsync(const Arguments& args) {
#ifdef DEBUG #ifdef DEBUG
SetThreadDescription(GetCurrentThread(), L"LLSE Connect WebSocket"); SetThreadDescription(GetCurrentThread(), L"LLSE Connect WebSocket");
#endif // DEBUG #endif // DEBUG
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
try { try {
bool result = false; bool result = false;
@ -287,7 +287,7 @@ Local<Value> WSClientClass::connectAsync(const Arguments& args) {
} catch (const std::runtime_error& e) { } catch (const std::runtime_error& e) {
result = false; result = false;
} }
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
// fix get on empty Global // fix get on empty Global
@ -381,10 +381,10 @@ using namespace httplib;
#define ADD_CALLBACK(method, path, func) \ #define ADD_CALLBACK(method, path, func) \
callbacks.emplace(make_pair(path, HttpServerCallback{EngineScope::currentEngine(), script::Global<Function>{func}, HttpRequestType::method, path})); \ callbacks.emplace(make_pair(path, HttpServerCallback{EngineScope::currentEngine(), script::Global<Function>{func}, HttpRequestType::method, path})); \
svr->##method##(path.c_str(), [this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { \ svr->##method##(path.c_str(), [this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { \
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) \ if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) \
return; \ return; \
auto task = Schedule::nextTick([this, engine, req, &resp] { \ auto task = Schedule::nextTick([this, engine, req, &resp] { \
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) \ if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) \
return; \ return; \
EngineScope enter(engine); \ EngineScope enter(engine); \
for (auto& [k, v] : this->callbacks) { \ for (auto& [k, v] : this->callbacks) { \
@ -436,10 +436,10 @@ Local<Value> HttpServerClass::onGet(const Arguments& args) {
/* for debug /* for debug
callbacks.emplace(make_pair(path, HttpServerCallback{EngineScope::currentEngine(), script::Global<Function>{func}, HttpRequestType::Get, path})); callbacks.emplace(make_pair(path, HttpServerCallback{EngineScope::currentEngine(), script::Global<Function>{func}, HttpRequestType::Get, path}));
svr->Get(path.c_str(), [this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { svr->Get(path.c_str(), [this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
auto task = Schedule::nextTick([this, engine, req, &resp] { auto task = Schedule::nextTick([this, engine, req, &resp] {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
for (auto& [k, v] : this->callbacks) for (auto& [k, v] : this->callbacks)
@ -547,11 +547,11 @@ Local<Value> HttpServerClass::onPreRouting(const Arguments& args) {
try { try {
preRoutingCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}}; preRoutingCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}};
svr->set_pre_routing_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { svr->set_pre_routing_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return Server::HandlerResponse::Unhandled; return Server::HandlerResponse::Unhandled;
bool handled = false; bool handled = false;
auto task = Schedule::nextTick([this, engine, req, &resp, &handled] { auto task = Schedule::nextTick([this, engine, req, &resp, &handled] {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
auto reqObj = new HttpRequestClass(req); auto reqObj = new HttpRequestClass(req);
@ -578,10 +578,10 @@ Local<Value> HttpServerClass::onPostRouting(const Arguments& args) {
try { try {
postRoutingCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}}; postRoutingCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}};
svr->set_post_routing_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { svr->set_post_routing_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
auto task = Schedule::nextTick([this, engine, req, &resp] { auto task = Schedule::nextTick([this, engine, req, &resp] {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
auto reqObj = new HttpRequestClass(req); auto reqObj = new HttpRequestClass(req);
@ -604,10 +604,10 @@ Local<Value> HttpServerClass::onError(const Arguments& args) {
try { try {
errorCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}}; errorCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}};
svr->set_error_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) { svr->set_error_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
auto task = Schedule::nextTick([this, engine, req, &resp] { auto task = Schedule::nextTick([this, engine, req, &resp] {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
auto reqObj = new HttpRequestClass(req); auto reqObj = new HttpRequestClass(req);
@ -630,10 +630,10 @@ Local<Value> HttpServerClass::onException(const Arguments& args) {
try { try {
exceptionCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}}; exceptionCallback = {EngineScope::currentEngine(), script::Global{args[0].asFunction()}};
svr->set_exception_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp, std::exception_ptr e) { svr->set_exception_handler([this, engine = EngineScope::currentEngine()](const Request& req, Response& resp, std::exception_ptr e) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
auto task = Schedule::nextTick([this, engine, req, &resp, e] { auto task = Schedule::nextTick([this, engine, req, &resp, e] {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope enter(engine); EngineScope enter(engine);
auto reqObj = new HttpRequestClass(req); auto reqObj = new HttpRequestClass(req);
@ -1009,7 +1009,7 @@ Local<Value> NetworkClass::httpGet(const Arguments& args) {
script::Global<Function> callbackFunc{args[args.size() - 1].asFunction()}; script::Global<Function> callbackFunc{args[args.size() - 1].asFunction()};
auto lambda = [callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int status, string body) { auto lambda = [callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int status, string body) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope scope(engine); EngineScope scope(engine);
@ -1055,7 +1055,7 @@ Local<Value> NetworkClass::httpPost(const Arguments& args) {
script::Global<Function> callbackFunc{args[args.size() - 1].asFunction()}; script::Global<Function> callbackFunc{args[args.size() - 1].asFunction()};
auto lambda = [callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int status, string body) { auto lambda = [callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int status, string body) {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return; return;
EngineScope scope(engine); EngineScope scope(engine);

View File

@ -1752,7 +1752,7 @@ Local<Value> PlayerClass::sendSimpleForm(const Arguments& args) {
player->sendSimpleFormPacket(args[0].toStr(), args[1].toStr(), texts, images, player->sendSimpleFormPacket(args[0].toStr(), args[1].toStr(), texts, images,
[id{player->getUniqueID()}, engine{EngineScope::currentEngine()}, [id{player->getUniqueID()}, engine{EngineScope::currentEngine()},
callback{script::Global(args[4].asFunction())}](int chosen) { callback{script::Global(args[4].asFunction())}](int chosen) {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -1790,7 +1790,7 @@ Local<Value> PlayerClass::sendModalForm(const Arguments& args) {
player->sendModalFormPacket(args[0].toStr(), args[1].toStr(), args[2].toStr(), args[3].toStr(), player->sendModalFormPacket(args[0].toStr(), args[1].toStr(), args[2].toStr(), args[3].toStr(),
[id{player->getUniqueID()}, engine{EngineScope::currentEngine()}, [id{player->getUniqueID()}, engine{EngineScope::currentEngine()},
callback{script::Global(args[4].asFunction())}](bool chosen) { callback{script::Global(args[4].asFunction())}](bool chosen) {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -1827,7 +1827,7 @@ Local<Value> PlayerClass::sendCustomForm(const Arguments& args) {
player->sendCustomFormPacket(data, player->sendCustomFormPacket(data,
[id{player->getUniqueID()}, engine{EngineScope::currentEngine()}, [id{player->getUniqueID()}, engine{EngineScope::currentEngine()},
callback{script::Global(args[1].asFunction())}](string result) { callback{script::Global(args[1].asFunction())}](string result) {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;

View File

@ -233,7 +233,7 @@ bool LLSEExportFunc(ScriptEngine* engine, const Local<Function>& func, const str
// script::Global<Function> callback = script::Global<Function>(func); // script::Global<Function> callback = script::Global<Function>(func);
std::string identifier = nameSpace + "::" + funcName; std::string identifier = nameSpace + "::" + funcName;
RemoteCall::CallbackFn cb = [engine, identifier /*, scriptCallback = std::move(callback)*/](std::vector<RemoteCall::ValueType> params) -> RemoteCall::ValueType { RemoteCall::CallbackFn cb = [engine, identifier /*, scriptCallback = std::move(callback)*/](std::vector<RemoteCall::ValueType> params) -> RemoteCall::ValueType {
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return ""; return "";
EngineScope enter(engine); EngineScope enter(engine);
try { try {

View File

@ -85,7 +85,7 @@ Local<Value> ColorLog(const Arguments& args) {
LOG_ERROR_WITH_SCRIPT_INFO("Invalid color!"); LOG_ERROR_WITH_SCRIPT_INFO("Invalid color!");
break; break;
} }
// if (!LL::globalConfig.colorLog) // if (!ll::globalConfig.colorLog)
// prefix = ""; // prefix = "";
auto& infoOut = ENGINE_OWN_DATA()->logger.info; auto& infoOut = ENGINE_OWN_DATA()->logger.info;
infoOut << prefix; infoOut << prefix;

View File

@ -11,14 +11,14 @@ Local<Value> McClass::setMotd(const Arguments& args) {
CHECK_ARG_TYPE(args[0], ValueKind::kString) CHECK_ARG_TYPE(args[0], ValueKind::kString)
try { try {
return Boolean::newBoolean(LL::setServerMotd(args[0].asString().toString())); return Boolean::newBoolean(ll::setServerMotd(args[0].asString().toString()));
} }
CATCH("Fail in SetServerMotd!") CATCH("Fail in SetServerMotd!")
} }
Local<Value> McClass::crashBDS(const Arguments& args) //===========??? Local<Value> McClass::crashBDS(const Arguments& args) //===========???
{ {
if (LL::isDebugMode()) { if (ll::isDebugMode()) {
RecordOperation(ENGINE_OWN_DATA()->pluginName, "Crash Server", "Execute mc.crash() to crash server."); RecordOperation(ENGINE_OWN_DATA()->pluginName, "Crash Server", "Execute mc.crash() to crash server.");
throw; throw;
return Boolean::newBoolean(true); return Boolean::newBoolean(true);

View File

@ -40,7 +40,7 @@ Local<Value> SystemClass::cmd(const Arguments& args) {
[callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int exitCode, string output) { [callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int exitCode, string output) {
Schedule::nextTick( Schedule::nextTick(
[engine, callback = std::move(callback), exitCode, output = std::move(output)]() { [engine, callback = std::move(callback), exitCode, output = std::move(output)]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -75,7 +75,7 @@ Local<Value> SystemClass::newProcess(const Arguments& args) {
[callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int exitCode, string output) { [callback{std::move(callbackFunc)}, engine{EngineScope::currentEngine()}](int exitCode, string output) {
Schedule::nextTick( Schedule::nextTick(
[engine, callback = std::move(callback), exitCode, output = std::move(output)]() { [engine, callback = std::move(callback), exitCode, output = std::move(output)]() {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;

View File

@ -315,16 +315,16 @@ void InitMessageSystem() {
SetThreadDescription(GetCurrentThread(), L"LLSE MessageSystem " _CRT_WIDE(LLSE_MODULE_TYPE)); SetThreadDescription(GetCurrentThread(), L"LLSE MessageSystem " _CRT_WIDE(LLSE_MODULE_TYPE));
#endif // DEBUG #endif // DEBUG
// Set global SEH-Exception handler // Set global SEH-Exception handler
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
globalShareData->messageThreads[LLSE_BACKEND_TYPE] = GetCurrentThread(); globalShareData->messageThreads[LLSE_BACKEND_TYPE] = GetCurrentThread();
while (true) { while (true) {
MessageSystemLoopOnce(); MessageSystemLoopOnce();
if (LL::getServerStatus() >= LL::ServerStatus::Stopping) if (ll::getServerStatus() >= ll::ServerStatus::Stopping)
return; return;
SleepEx(5, true); SleepEx(5, true);
if (LL::getServerStatus() >= LL::ServerStatus::Stopping) if (ll::getServerStatus() >= ll::ServerStatus::Stopping)
return; return;
} }
}).detach(); }).detach();

View File

@ -129,7 +129,7 @@ bool LLSEExportFunc(ScriptEngine *engine, const Local<Function> &func, const str
return ""; return "";
} }
auto engine = data->second.engine; auto engine = data->second.engine;
if (LL::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying()) if (ll::isServerStopping() || !EngineManager::isValid(engine) || engine->isDestroying())
return ""; return "";
EngineScope enter(data->second.engine); EngineScope enter(data->second.engine);
std::vector<script::Local<Value>> scriptParams; std::vector<script::Local<Value>> scriptParams;

View File

@ -65,7 +65,7 @@ std::unordered_map<int, TimeTaskData> timeTaskMap;
// } // }
// Schedule::delay( // Schedule::delay(
// [engine, func = std::move(func), paras = std::move(tmp)]() { // [engine, func = std::move(func), paras = std::move(tmp)]() {
// if (LL::isServerStopping()) // if (ll::isServerStopping())
// return; // return;
// if (!EngineManager::isValid(engine)) // if (!EngineManager::isValid(engine))
// return; // return;
@ -100,7 +100,7 @@ int NewTimeout(Local<Function> func, vector<Local<Value>> paras, int timeout) {
data.task = Schedule::delay( data.task = Schedule::delay(
[engine{EngineScope::currentEngine()}, id{tid}]() { [engine{EngineScope::currentEngine()}, id{tid}]() {
try { try {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -150,7 +150,7 @@ int NewTimeout(Local<String> func, int timeout) {
data.task = Schedule::delay( data.task = Schedule::delay(
[engine{EngineScope::currentEngine()}, id{tid}]() { [engine{EngineScope::currentEngine()}, id{tid}]() {
try { try {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) if (!EngineManager::isValid(engine))
return; return;
@ -192,7 +192,7 @@ int NewInterval(Local<Function> func, vector<Local<Value>> paras, int timeout) {
data.task = Schedule::repeat( data.task = Schedule::repeat(
[engine{EngineScope::currentEngine()}, id{tid}]() { [engine{EngineScope::currentEngine()}, id{tid}]() {
try { try {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) { if (!EngineManager::isValid(engine)) {
ClearTimeTask(id); ClearTimeTask(id);
@ -248,7 +248,7 @@ int NewInterval(Local<String> func, int timeout) {
data.task = Schedule::repeat( data.task = Schedule::repeat(
[engine{EngineScope::currentEngine()}, id{tid}]() { [engine{EngineScope::currentEngine()}, id{tid}]() {
try { try {
if (LL::isServerStopping()) if (ll::isServerStopping())
return; return;
if (!EngineManager::isValid(engine)) { if (!EngineManager::isValid(engine)) {
ClearTimeTask(id); ClearTimeTask(id);

View File

@ -39,7 +39,7 @@ struct dynamicSymbolsMap_type
bool EconomySystem::init() bool EconomySystem::init()
{ {
auto llmoney = LL::getPlugin("LLMoney"); auto llmoney = ll::getPlugin("LLMoney");
if (!llmoney) if (!llmoney)
{ {
if (localShareData->isFirstInstance) { if (localShareData->isFirstInstance) {

View File

@ -150,11 +150,11 @@ bool loadPluginCode(script::ScriptEngine* engine, std::string entryScriptPath, s
// Start libuv event loop // Start libuv event loop
uvLoopTask[env] = Schedule::repeat([engine, env, isRunningMap{&isRunning}, eventLoop{it->second->event_loop()}]() { uvLoopTask[env] = Schedule::repeat([engine, env, isRunningMap{&isRunning}, eventLoop{it->second->event_loop()}]() {
if (!LL::isServerStopping() && (*isRunningMap)[env]) { if (!ll::isServerStopping() && (*isRunningMap)[env]) {
EngineScope enter(engine); EngineScope enter(engine);
uv_run(eventLoop, UV_RUN_NOWAIT); uv_run(eventLoop, UV_RUN_NOWAIT);
} }
if (LL::isServerStopping()) { if (ll::isServerStopping()) {
uv_stop(eventLoop); uv_stop(eventLoop);
logger.debug("Destroy ServerStopping"); logger.debug("Destroy ServerStopping");
} }
@ -288,7 +288,7 @@ bool loadNodeJsPlugin(std::string dirPath, const std::string& packagePath, bool
if (!PluginManager::getPlugin(pluginName)) { if (!PluginManager::getPlugin(pluginName)) {
// Plugin did't register itself. Help to register it // Plugin did't register itself. Help to register it
string description = pluginName; string description = pluginName;
LL::Version ver(1, 0, 0); ll::Version ver(1, 0, 0);
std::map<string, string> others = {}; std::map<string, string> others = {};
// Read information from package.json // Read information from package.json
@ -305,7 +305,7 @@ bool loadNodeJsPlugin(std::string dirPath, const std::string& packagePath, bool
} }
// version // version
if (j.contains("version") && j["version"].is_string()) { if (j.contains("version") && j["version"].is_string()) {
ver = LL::Version::parse(j["version"].get<std::string>()); ver = ll::Version::parse(j["version"].get<std::string>());
} }
// license // license
if (j.contains("license") && j["license"].is_string()) { if (j.contains("license") && j["license"].is_string()) {

View File

@ -152,7 +152,7 @@ bool PluginManager::loadPlugin(const std::string& fileOrDirPath, bool isHotLoad,
// If plugin itself doesn't register, help it to do so // If plugin itself doesn't register, help it to do so
if (!PluginManager::getPlugin(pluginName)) if (!PluginManager::getPlugin(pluginName))
PluginManager::registerPlugin(realPath, pluginName, pluginName, LL::Version(1, 0, 0), {}); PluginManager::registerPlugin(realPath, pluginName, pluginName, ll::Version(1, 0, 0), {});
// Call necessary events when at hot load // Call necessary events when at hot load
if (isHotLoad) if (isHotLoad)
@ -274,19 +274,19 @@ bool PluginManager::reloadAllPlugins() {
return true; return true;
} }
LL::Plugin* PluginManager::getPlugin(std::string name) { ll::Plugin* PluginManager::getPlugin(std::string name) {
return LL::PluginManager::getPlugin(name, true); return ll::PluginManager::getPlugin(name, true);
} }
// Get all plugins of current language // Get all plugins of current language
std::unordered_map<std::string, LL::Plugin*> PluginManager::getLocalPlugins() { std::unordered_map<std::string, ll::Plugin*> PluginManager::getLocalPlugins() {
std::unordered_map<std::string, LL::Plugin*> res; std::unordered_map<std::string, ll::Plugin*> res;
auto engines = EngineManager::getLocalEngines(); auto engines = EngineManager::getLocalEngines();
for (auto& engine : engines) { for (auto& engine : engines) {
string name = ENGINE_GET_DATA(engine)->pluginName; string name = ENGINE_GET_DATA(engine)->pluginName;
if (name != LLSE_DEBUG_ENGINE_NAME) { if (name != LLSE_DEBUG_ENGINE_NAME) {
LL::Plugin* plugin = PluginManager::getPlugin(name); ll::Plugin* plugin = PluginManager::getPlugin(name);
if (plugin) if (plugin)
res[plugin->name] = plugin; res[plugin->name] = plugin;
} }
@ -294,28 +294,28 @@ std::unordered_map<std::string, LL::Plugin*> PluginManager::getLocalPlugins() {
return res; return res;
} }
std::unordered_map<std::string, LL::Plugin*> PluginManager::getAllScriptPlugins() { std::unordered_map<std::string, ll::Plugin*> PluginManager::getAllScriptPlugins() {
auto res = getAllPlugins(); auto res = getAllPlugins();
erase_if(res, [](auto& item) { erase_if(res, [](auto& item) {
return item.second->type != LL::Plugin::PluginType::ScriptPlugin; return item.second->type != ll::Plugin::PluginType::ScriptPlugin;
}); });
return res; return res;
} }
// Get all plugins // Get all plugins
std::unordered_map<std::string, LL::Plugin*> PluginManager::getAllPlugins() { std::unordered_map<std::string, ll::Plugin*> PluginManager::getAllPlugins() {
return LL::PluginManager::getAllPlugins(); return ll::PluginManager::getAllPlugins();
} }
bool PluginManager::registerPlugin(std::string filePath, std::string name, std::string desc, bool PluginManager::registerPlugin(std::string filePath, std::string name, std::string desc,
LL::Version version, std::map<std::string, std::string> others) { ll::Version version, std::map<std::string, std::string> others) {
others["PluginType"] = "Script Plugin"; others["PluginType"] = "Script Plugin";
others["PluginFilePath"] = filePath; others["PluginFilePath"] = filePath;
return LL::PluginManager::registerPlugin(NULL, name, desc, version, others); return ll::PluginManager::registerPlugin(NULL, name, desc, version, others);
} }
bool PluginManager::unRegisterPlugin(std::string name) { bool PluginManager::unRegisterPlugin(std::string name) {
return LL::PluginManager::unRegisterPlugin(name); return ll::PluginManager::unRegisterPlugin(name);
} }
// Get plugin backend type from its file path (single file plugin) // Get plugin backend type from its file path (single file plugin)

View File

@ -16,13 +16,13 @@ public:
static bool reloadPlugin(const std::string& name); static bool reloadPlugin(const std::string& name);
static bool reloadAllPlugins(); static bool reloadAllPlugins();
static LL::Plugin* getPlugin(std::string name); static ll::Plugin* getPlugin(std::string name);
static std::unordered_map<std::string, LL::Plugin*> getLocalPlugins(); static std::unordered_map<std::string, ll::Plugin*> getLocalPlugins();
static std::unordered_map<std::string, LL::Plugin*> getAllScriptPlugins(); static std::unordered_map<std::string, ll::Plugin*> getAllScriptPlugins();
static std::unordered_map<std::string, LL::Plugin*> getAllPlugins(); static std::unordered_map<std::string, ll::Plugin*> getAllPlugins();
static std::string getPluginBackendType(const std::string &path); static std::string getPluginBackendType(const std::string &path);
static bool registerPlugin(std::string filePath, std::string name, std::string desc, static bool registerPlugin(std::string filePath, std::string name, std::string desc,
LL::Version version, std::map<std::string, std::string> others); ll::Version version, std::map<std::string, std::string> others);
}; };

View File

@ -34,15 +34,15 @@ extern void LoadDebugEngine();
void entry() { void entry() {
// Enable thread SEH protection // Enable thread SEH protection
if (!LL::isDebugMode()) if (!ll::isDebugMode())
_set_se_translator(seh_exception::TranslateSEHtoCE); _set_se_translator(seh_exception::TranslateSEHtoCE);
// Register myself // Register myself
LL::registerPlugin(LLSE_LOADER_NAME, LLSE_LOADER_DESCRIPTION, LITELOADER_VERSION, ll::registerPlugin(LLSE_LOADER_NAME, LLSE_LOADER_DESCRIPTION, LITELOADER_VERSION,
{{"GitHub", "github.com/LiteLDev/LiteLoaderBDS"}}); {{"GitHub", "github.com/LiteLDev/LiteLoaderBDS"}});
// Load i18n files // Load i18n files
Translation::loadFromImpl(GetCurrentModule(), LL::getLoaderHandle()); Translation::loadFromImpl(GetCurrentModule(), ll::getLoaderHandle());
// Init global share data // Init global share data
InitLocalShareData(); InitLocalShareData();
@ -55,7 +55,7 @@ void entry() {
} }
// Init builtin economy system // Init builtin economy system
if (LL::globalConfig.enableEconomyCore) { if (ll::globalConfig.enableEconomyCore) {
EconomySystem::init(); EconomySystem::init();
} }