From df18489aca8034bc6614dd0210ce5254960c7147 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Mon, 12 Feb 2024 15:27:57 +0800 Subject: [PATCH 1/6] adapt: adapt GMLIB 0.7.3 --- SDK-GMLIB | 2 +- src/LegacyServerApi.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SDK-GMLIB b/SDK-GMLIB index 1c2918e..fe6194d 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit 1c2918e15dc5ed06199f5695a89f030191f5d703 +Subproject commit fe6194d24e0bf104c049688d10c0e71ad2a124e0 diff --git a/src/LegacyServerApi.cpp b/src/LegacyServerApi.cpp index 0a7a385..a33aafe 100644 --- a/src/LegacyServerApi.cpp +++ b/src/LegacyServerApi.cpp @@ -8,11 +8,11 @@ void Export_Legacy_GMLib_ServerAPI() { GMLIB_Level::forceEnableAbilityCommand(); }); RemoteCall::exportAs("GMLib_ServerAPI", "addFloatingTextPacket", [](std::string text, std::pair pos, int dimid) -> int { - auto ft = new FloatingText(text, pos.first, pos.second); - return ft->mRuntimeId; + auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second); + return ft->getRuntimeID(); }); RemoteCall::exportAs("GMLib_ServerAPI", "deleteFloatingTextPacket", [](int id) -> void { - FloatingText::deleteFloatingText(id); + GMLIB::Server::FloatingText::deleteFloatingText(id); }); RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void { GMLIB_Level::setForceAchievementsEnabled(); From 4090dc702559c42e87d5f3727477804c243852be Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:12:37 +0800 Subject: [PATCH 2/6] adapt: adapt GMLIB 0.8.0 --- SDK-GMLIB | 2 +- tooth.json | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tooth.json diff --git a/SDK-GMLIB b/SDK-GMLIB index fe6194d..72e596a 160000 --- a/SDK-GMLIB +++ b/SDK-GMLIB @@ -1 +1 @@ -Subproject commit fe6194d24e0bf104c049688d10c0e71ad2a124e0 +Subproject commit 72e596afb1fcca9c7bf0bdedc88535704bfb19a8 diff --git a/tooth.json b/tooth.json new file mode 100644 index 0000000..6788d0f --- /dev/null +++ b/tooth.json @@ -0,0 +1,28 @@ +{ + "format_version": 2, + "tooth": "github.com/GroupMountain/GMLIB-LegacyRemoteCallApi", + "version": "0.8.0", + "info": { + "name": "GMLIB-LegacyRemoteCallApi", + "description": "Legacy RemoteCall API for GMLIB", + "author": "GroupMountain Team", + "tags": [ + "LeviLamina", + "GMLIB", + "GMLIB-LegacyRemoteCallApi", + "Library" + ] + }, + "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" + }, + "files": { + "place": [ + { + "src": "GMLIB-LegacyRemoteCallApi/*", + "dest": "plugins/GMLIB-LegacyRemoteCallApi" + } + ] + } +} \ No newline at end of file From 928c470150a5f3dbf22c334df2553853192684d4 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:42:45 +0800 Subject: [PATCH 3/6] 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, 106 insertions(+), 32 deletions(-) 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": [ 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 4/6] 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": [ From 78f831cef6d956525c828afe728db19f8fecb518 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:00:02 +0800 Subject: [PATCH 5/6] feat: more api --- src/CompatibilityApi.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index a572e22..6298871 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -13,4 +13,14 @@ void Export_Compatibility_API() { 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 From 701d120abbcead788e6abff980ca8b31ab13b367 Mon Sep 17 00:00:00 2001 From: Tsubasa6848 <116721335+Tsubasa6848@users.noreply.github.com> Date: Thu, 15 Feb 2024 17:06:52 +0800 Subject: [PATCH 6/6] fix: fix crash before ServerStarted --- src/CompatibilityApi.cpp | 18 +++++++-- src/LegacyModApi.cpp | 40 ++++++++++++++++++++ src/LegacyServerApi.cpp | 82 ++++++++++++++++++++++++---------------- 3 files changed, 105 insertions(+), 35 deletions(-) diff --git a/src/CompatibilityApi.cpp b/src/CompatibilityApi.cpp index 6298871..c5dde29 100644 --- a/src/CompatibilityApi.cpp +++ b/src/CompatibilityApi.cpp @@ -2,13 +2,25 @@ void Export_Compatibility_API() { RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float { - return GMLIB_Level::getLevel()->getServerMspt(); + auto level = GMLIB_Level::getLevel(); + if (!level) { + return 0.0f; + } + return level->getServerMspt(); }); RemoteCall::exportAs("GMLIB_API", "getServerCurrentTps", []() -> float { - return GMLIB_Level::getLevel()->getServerCurrentTps(); + auto level = GMLIB_Level::getLevel(); + if (!level) { + return 0.0f; + } + return level->getServerCurrentTps(); }); RemoteCall::exportAs("GMLIB_API", "getServerAverageTps", []() -> float { - return GMLIB_Level::getLevel()->getServerAverageTps(); + auto level = GMLIB_Level::getLevel(); + if (!level) { + return 0.0f; + } + return level->getServerAverageTps(); }); RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector { return GMLIB_Player::getAllUuids(); diff --git a/src/LegacyModApi.cpp b/src/LegacyModApi.cpp index fd8bc1b..4d6d740 100644 --- a/src/LegacyModApi.cpp +++ b/src/LegacyModApi.cpp @@ -23,6 +23,10 @@ void Export_Legacy_GMLib_ModAPI() { std::string result, int count, std::string unlock) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } std::vector types; for (auto ing : ingredients) { auto key = RecipeIngredient(ing, 0, 1); @@ -42,6 +46,10 @@ void Export_Legacy_GMLib_ModAPI() { std::string result, int count, std::string unlock) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } std::vector types; for (auto ing : ingredients) { auto key = RecipeIngredient(ing, 0, 1); @@ -56,6 +64,10 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerFurnaceRecipe", [](std::string recipe_id, std::string input, std::string output, std::vector tags) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); @@ -65,6 +77,10 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerBrewingMixRecipe", [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } auto rea = RecipeIngredient(reagent, 0, 1); GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); } @@ -73,6 +89,10 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerBrewingContainerRecipe", [](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1); @@ -87,6 +107,10 @@ void Export_Legacy_GMLib_ModAPI() { std::string base, std::string addition, std::string result) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe( recipe_id, smithing_template, @@ -100,6 +124,10 @@ void Export_Legacy_GMLib_ModAPI() { "GMLib_ModAPI", "registerSmithingTrimRecipe", [](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition); } ); @@ -112,6 +140,10 @@ void Export_Legacy_GMLib_ModAPI() { std::string output, int output_data, int output_count) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } auto inp = RecipeIngredient(input, 0, 1); auto outp = RecipeIngredient(output, 0, 1); GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); @@ -130,11 +162,19 @@ void Export_Legacy_GMLib_ModAPI() { } }); RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + 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 { + auto level = GMLIB_Level::getLevel(); + if (!level) { + 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..2904824 100644 --- a/src/LegacyServerApi.cpp +++ b/src/LegacyServerApi.cpp @@ -1,49 +1,67 @@ #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 { + 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", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); }); + RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { GMLIB_Level::setCoResourcePack(); }); + RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return ""; + } + return level->getLevelName(); }); - RemoteCall::exportAs("GMLib_ServerAPI", "enableCoResourcePack", []() -> void { - GMLIB_Level::setCoResourcePack(); + RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } + return level->setLevelName(name); }); - RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string { - return GMLIB_Level::getLevel()->getLevelName(); + RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void { + auto level = GMLIB_Level::getLevel(); + if (!level) { + return; + } + return level->setFakeSeed(seed); }); - RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { - GMLIB_Level::getLevel()->setLevelName(name); - }); - 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