diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index a572e22..39d4df3 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -2,15 +2,34 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float { + if (!isServerStarted) { + return 0; + } return GMLIB_Level::getLevel()->getServerMspt(); }); RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float { + if (!isServerStarted) { + return 0; + } return GMLIB_Level::getLevel()->getServerCurrentTps(); }); RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> float { + if (!isServerStarted) { + return 0; + } return GMLIB_Level::getLevel()->getServerAverageTps(); }); RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector { return GMLIB_Player::getAllUuids(); }); + RemoteCall::exportAs("GMLIB_API", "getAllExperiments", []() -> std::vector { + return {6, 7, 8, 9, 10, 13, 16, 17, 18}; + }); + RemoteCall::exportAs("GMLIB_API", "getExperimentTranslatedName", [](int id) -> std::string { + auto map = GMLIB_Level::getAllExperimentsTranslateKeys(); + if (map.count(id)) { + return map[id]; + } + return ""; + }); } \ No newline at end of file diff --git a/src/Global.h b/src/Global.h index c445e32..0e38497 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,10 +1,11 @@ #pragma once -#include #include +#include #define PLUGIN_NAME "GMLIB-LRCA" extern ll::Logger logger; +extern bool isServerStarted; extern void Export_Legacy_GMLib_ModAPI(); extern void Export_Legacy_GMLib_ServerAPI(); diff --git a/src/LegacyModApi.cpp b/src/LegacyModApi.cpp index fd8bc1b..68fbcef 100644 --- a/src/LegacyModApi.cpp +++ b/src/LegacyModApi.cpp @@ -1,7 +1,7 @@ #include "Global.h" std::unordered_set HardCodedKeys = {"AlwaysUnlocked", "PlayerHasManyItems", "PlayerInWater", "None"}; -std::unordered_set ExperimentsList = {6, 7, 8, 9, 10, 12, 15, 16}; +std::unordered_set ExperimentsList = {6, 7, 8, 9, 10, 13, 16, 17, 18}; std::variant> makeRecipeUnlockingKey(std::string& key) { if (HardCodedKeys.count(key)) { @@ -23,6 +23,9 @@ void Export_Legacy_GMLib_ModAPI() { std::string result, int count, std::string unlock) -> void { + if (!isServerStarted) { + return; + } std::vector types; for (auto ing : ingredients) { auto key = RecipeIngredient(ing, 0, 1); @@ -42,6 +45,9 @@ void Export_Legacy_GMLib_ModAPI() { std::string result, int count, std::string unlock) -> void { + if (!isServerStarted) { + return; + } std::vector types; for (auto ing : ingredients) { auto key = RecipeIngredient(ing, 0, 1); @@ -56,6 +62,9 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerFurnaceRecipe", [](std::string recipe_id, std::string input, std::string output, std::vector tags) -> void { + if (!isServerStarted) { + return; + } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); @@ -65,6 +74,9 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerBrewingMixRecipe", [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { + if (!isServerStarted) { + return; + } auto rea = RecipeIngredient(reagent, 0, 1); GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); } @@ -73,6 +85,9 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerBrewingContainerRecipe", [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { + if (!isServerStarted) { + return; + } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1); @@ -87,6 +102,9 @@ void Export_Legacy_GMLib_ModAPI() { std::string base, std::string addition, std::string result) -> void { + if (!isServerStarted) { + return; + } GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe( recipe_id, smithing_template, @@ -100,6 +118,9 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerSmithingTrimRecipe", [](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void { + if (!isServerStarted) { + return; + } GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); } ); @@ -112,6 +133,9 @@ void Export_Legacy_GMLib_ModAPI() { std::string output, int output_data, int output_count) -> void { + if (!isServerStarted) { + return; + } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); @@ -130,11 +154,17 @@ void Export_Legacy_GMLib_ModAPI() { } }); RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void { + if (!isServerStarted) { + return; + } if (ExperimentsList.count(experiment_id)) { GMLIB_Level::getLevel()->setExperimentEnabled(((AllExperiments)experiment_id), value); } else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); }); RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool { + if (!isServerStarted) { + return false; + } if (ExperimentsList.count(experiment_id)) { return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id)); } else { diff --git a/src/LegacyServerApi.cpp b/src/LegacyServerApi.cpp index a33aafe..9ba41c4 100644 --- a/src/LegacyServerApi.cpp +++ b/src/LegacyServerApi.cpp @@ -1,49 +1,70 @@ #include "Global.h" void Export_Legacy_GMLib_ServerAPI() { - RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void { + RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void { GMLIB_Level::addEducationEditionRequired(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void { + RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void { GMLIB_Level::forceEnableAbilityCommand(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "addFloatingTextPacket", [](std::string text, std::pair pos, int dimid) -> int { - auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second); - return ft->getRuntimeID(); - }); - RemoteCall::exportAs("GMLib_ServerAPI", "deleteFloatingTextPacket", [](int id) -> void { + RemoteCall::exportAs( + "GMLib_ServerAPI", + "addFloatingTextPacket", + [](std::string text, std::pair pos, int dimid) -> int { + if (!isServerStarted) { + return -1; + } + auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second); + return ft->getRuntimeID(); + } + ); + RemoteCall::exportAs("GMLib_ServerAPI", "deleteFloatingTextPacket", [](int id) -> void { + if (!isServerStarted) { + return; + } GMLIB::Server::FloatingText::deleteFloatingText(id); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void { + RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void { GMLIB_Level::setForceAchievementsEnabled(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { - GMLIB_Level::setForceTrustSkin(); - }); - RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { - GMLIB_Level::setCoResourcePack(); - }); - RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string { + RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); }); + RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { GMLIB_Level::setCoResourcePack(); }); + RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string { + if (!isServerStarted) { + return ""; + } return GMLIB_Level::getLevel()->getLevelName(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { + RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { + if (!isServerStarted) { + return; + } GMLIB_Level::getLevel()->setLevelName(name); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { + RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { + if (!isServerStarted) { + return; + } GMLIB_Level::getLevel()->setFakeSeed(seed); }); - RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair pos, std::string name) -> Actor* { + RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair pos, std::string name) -> Actor* { return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name); }); - RemoteCall::exportAs("GMLib_ServerAPI", "shootProjectile", [](Actor* owner, std::string name, float speed, float offset) -> Actor* { - auto ac = (GMLIB_Actor*)owner; - return ac->shootProjectile(name, speed, offset); - }); - RemoteCall::exportAs("GMLib_ServerAPI", "throwEntity", [](Actor* owner, Actor* actor, float speed, float offset) -> bool { - auto ac = (GMLIB_Actor*)owner; - return ac->throwEntity(actor, speed, offset); - }); - RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { - return (Actor*)player; - }); + RemoteCall::exportAs( + "GMLib_ServerAPI", + "shootProjectile", + [](Actor* owner, std::string name, float speed, float offset) -> Actor* { + auto ac = (GMLIB_Actor*)owner; + return ac->shootProjectile(name, speed, offset); + } + ); + RemoteCall::exportAs( + "GMLib_ServerAPI", + "throwEntity", + [](Actor* owner, Actor* actor, float speed, float offset) -> bool { + auto ac = (GMLIB_Actor*)owner; + return ac->throwEntity(actor, speed, offset); + } + ); + RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { return (Actor*)player; }); } \ No newline at end of file diff --git a/src/Plugin.cpp b/src/Plugin.cpp index a9b0f8e..17544a7 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -2,6 +2,7 @@ #include "Global.h" ll::Logger logger(PLUGIN_NAME); +bool isServerStarted = false; namespace plugin { @@ -16,6 +17,7 @@ Plugin::Plugin(ll::plugin::NativePlugin& self) : mSelf(self) { } bool Plugin::enable() { + isServerStarted = true; // Code for enabling the plugin goes here. return true; } diff --git a/tooth.json b/tooth.json index 6788d0f..ead9461 100644 --- a/tooth.json +++ b/tooth.json @@ -15,7 +15,8 @@ }, "asset_url": "https://github.com/GroupMountain/GMLIB-LegacyRemoteCallApi/releases/download/v0.8.0/GMLIB-LegacyRemoteCallApi-windows-x64.zip", "dependencies": { - "github.com/GroupMountain/GMLIB": ">=0.8.0" + "github.com/GroupMountain/GMLIB": ">=0.8.1", + "github.com/LiteLDev/LegacyRemoteCall": "0.3.x" }, "files": { "place": [