From 543c042789073c93bd4bbc00a3b0d996211b074c Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:00:01 +0800 Subject: [PATCH] Revert "fix: fix crash" --- src/CompatibilityApi.cpp | 19 ---------- src/Global.h | 3 +- src/LegacyModApi.cpp | 32 +--------------- src/LegacyServerApi.cpp | 79 +++++++++++++++------------------------- src/Plugin.cpp | 2 - tooth.json | 3 +- 6 files changed, 32 insertions(+), 106 deletions(-) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 39d4df3..a572e22 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -2,34 +2,15 @@ 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 0e38497..c445e32 100644 --- a/src/Global.h +++ b/src/Global.h @@ -1,11 +1,10 @@ #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 68fbcef..fd8bc1b 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, 13, 16, 17, 18}; +std::unordered_set ExperimentsList = {6, 7, 8, 9, 10, 12, 15, 16}; std::variant> makeRecipeUnlockingKey(std::string& key) { if (HardCodedKeys.count(key)) { @@ -23,9 +23,6 @@ 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); @@ -45,9 +42,6 @@ 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); @@ -62,9 +56,6 @@ 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); @@ -74,9 +65,6 @@ 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); } @@ -85,9 +73,6 @@ 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); @@ -102,9 +87,6 @@ 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, @@ -118,9 +100,6 @@ 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); } ); @@ -133,9 +112,6 @@ 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); @@ -154,17 +130,11 @@ 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 9ba41c4..a33aafe 100644 --- a/src/LegacyServerApi.cpp +++ b/src/LegacyServerApi.cpp @@ -1,70 +1,49 @@ #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 { - 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; - } + 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 { 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 { - if (!isServerStarted) { - return ""; - } + 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 { return GMLIB_Level::getLevel()->getLevelName(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { - if (!isServerStarted) { - return; - } + RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { GMLIB_Level::getLevel()->setLevelName(name); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { - if (!isServerStarted) { - return; - } + RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { 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 17544a7..a9b0f8e 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -2,7 +2,6 @@ #include "Global.h" ll::Logger logger(PLUGIN_NAME); -bool isServerStarted = false; namespace plugin { @@ -17,7 +16,6 @@ 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 ead9461..6788d0f 100644 --- a/tooth.json +++ b/tooth.json @@ -15,8 +15,7 @@ }, "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.1", - "github.com/LiteLDev/LegacyRemoteCall": "0.3.x" + "github.com/GroupMountain/GMLIB": ">=0.8.0" }, "files": { "place": [