fix: fix crash before ServerStarted

This commit is contained in:
Tsubasa6848
2024-02-15 17:06:52 +08:00
Unverified
parent 78f831cef6
commit 701d120abb
3 changed files with 105 additions and 35 deletions
+15 -3
View File
@@ -2,13 +2,25 @@
void Export_Compatibility_API() { void Export_Compatibility_API() {
RemoteCall::exportAs("GMLIB_API", "getServerMspt", []() -> float { 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 { 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 { 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<std::string> { RemoteCall::exportAs("GMLIB_API", "getAllPlayerUuids", []() -> std::vector<std::string> {
return GMLIB_Player::getAllUuids(); return GMLIB_Player::getAllUuids();
+40
View File
@@ -23,6 +23,10 @@ void Export_Legacy_GMLib_ModAPI() {
std::string result, std::string result,
int count, int count,
std::string unlock) -> void { std::string unlock) -> void {
auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
std::vector<RecipeIngredient> types; std::vector<RecipeIngredient> types;
for (auto ing : ingredients) { for (auto ing : ingredients) {
auto key = RecipeIngredient(ing, 0, 1); auto key = RecipeIngredient(ing, 0, 1);
@@ -42,6 +46,10 @@ void Export_Legacy_GMLib_ModAPI() {
std::string result, std::string result,
int count, int count,
std::string unlock) -> void { std::string unlock) -> void {
auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
std::vector<RecipeIngredient> types; std::vector<RecipeIngredient> types;
for (auto ing : ingredients) { for (auto ing : ingredients) {
auto key = RecipeIngredient(ing, 0, 1); auto key = RecipeIngredient(ing, 0, 1);
@@ -56,6 +64,10 @@ void Export_Legacy_GMLib_ModAPI() {
"GMLib_ModAPI", "GMLib_ModAPI",
"registerFurnaceRecipe", "registerFurnaceRecipe",
[](std::string recipe_id, std::string input, std::string output, std::vector<std::string> tags) -> void { [](std::string recipe_id, std::string input, std::string output, std::vector<std::string> tags) -> void {
auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags); GMLIB::Mod::CustomRecipe::registerFurnaceRecipe(recipe_id, inp, outp, tags);
@@ -65,6 +77,10 @@ void Export_Legacy_GMLib_ModAPI() {
"GMLib_ModAPI", "GMLib_ModAPI",
"registerBrewingMixRecipe", "registerBrewingMixRecipe",
[](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { [](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); auto rea = RecipeIngredient(reagent, 0, 1);
GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea); GMLIB::Mod::CustomRecipe::registerBrewingMixRecipe(recipe_id, input, output, rea);
} }
@@ -73,6 +89,10 @@ void Export_Legacy_GMLib_ModAPI() {
"GMLib_ModAPI", "GMLib_ModAPI",
"registerBrewingContainerRecipe", "registerBrewingContainerRecipe",
[](std::string recipe_id, std::string input, std::string output, std::string reagent) -> void { [](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 inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
auto rea = RecipeIngredient(reagent, 0, 1); auto rea = RecipeIngredient(reagent, 0, 1);
@@ -87,6 +107,10 @@ void Export_Legacy_GMLib_ModAPI() {
std::string base, std::string base,
std::string addition, std::string addition,
std::string result) -> void { std::string result) -> void {
auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe( GMLIB::Mod::CustomRecipe::registerSmithingTransformRecipe(
recipe_id, recipe_id,
smithing_template, smithing_template,
@@ -100,6 +124,10 @@ void Export_Legacy_GMLib_ModAPI() {
"GMLib_ModAPI", "GMLib_ModAPI",
"registerSmithingTrimRecipe", "registerSmithingTrimRecipe",
[](std::string recipe_id, std::string smithing_template, std::string base, std::string addition) -> void { [](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); GMLIB::Mod::CustomRecipe::registerSmithingTrimRecipe(recipe_id, smithing_template, base, addition);
} }
); );
@@ -112,6 +140,10 @@ void Export_Legacy_GMLib_ModAPI() {
std::string output, std::string output,
int output_data, int output_data,
int output_count) -> void { int output_count) -> void {
auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
auto inp = RecipeIngredient(input, 0, 1); auto inp = RecipeIngredient(input, 0, 1);
auto outp = RecipeIngredient(output, 0, 1); auto outp = RecipeIngredient(output, 0, 1);
GMLIB::Mod::CustomRecipe::registerStoneCutterRecipe(recipe_id, inp, outp); 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 { RemoteCall::exportAs("GMLib_ModAPI", "setExperimentEnabled", [](int experiment_id, bool value) -> void {
auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
if (ExperimentsList.count(experiment_id)) { if (ExperimentsList.count(experiment_id)) {
GMLIB_Level::getLevel()->setExperimentEnabled(((AllExperiments)experiment_id), value); GMLIB_Level::getLevel()->setExperimentEnabled(((AllExperiments)experiment_id), value);
} else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id); } else ll::Logger("Server").error("Experiment ID '{}' does not exist!", experiment_id);
}); });
RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool { RemoteCall::exportAs("GMLib_ModAPI", "getExperimentEnabled", [](int experiment_id) -> bool {
auto level = GMLIB_Level::getLevel();
if (!level) {
return false;
}
if (ExperimentsList.count(experiment_id)) { if (ExperimentsList.count(experiment_id)) {
return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id)); return GMLIB_Level::getLevel()->getExperimentEnabled(((AllExperiments)experiment_id));
} else { } else {
+50 -32
View File
@@ -1,49 +1,67 @@
#include "Global.h" #include "Global.h"
void Export_Legacy_GMLib_ServerAPI() { void Export_Legacy_GMLib_ServerAPI() {
RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void { RemoteCall::exportAs("GMLib_ServerAPI", "setEducationFeatureEnabled", []() -> void {
GMLIB_Level::addEducationEditionRequired(); GMLIB_Level::addEducationEditionRequired();
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void { RemoteCall::exportAs("GMLib_ServerAPI", "registerAbilityCommand", []() -> void {
GMLIB_Level::forceEnableAbilityCommand(); GMLIB_Level::forceEnableAbilityCommand();
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "addFloatingTextPacket", [](std::string text, std::pair<Vec3, int> pos, int dimid) -> int { RemoteCall::exportAs(
auto ft = new GMLIB::Server::FloatingText(text, pos.first, pos.second); "GMLib_ServerAPI",
return ft->getRuntimeID(); "addFloatingTextPacket",
}); [](std::string text, std::pair<Vec3, int> pos, int dimid) -> int {
RemoteCall::exportAs("GMLib_ServerAPI", "deleteFloatingTextPacket", [](int id) -> void { 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); GMLIB::Server::FloatingText::deleteFloatingText(id);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void { RemoteCall::exportAs("GMLib_ServerAPI", "setEnableAchievement", []() -> void {
GMLIB_Level::setForceAchievementsEnabled(); GMLIB_Level::setForceAchievementsEnabled();
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { RemoteCall::exportAs("GMLib_ServerAPI", "setForceTrustSkins", []() -> void { GMLIB_Level::setForceTrustSkin(); });
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 { RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void {
GMLIB_Level::setCoResourcePack(); auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
return level->setLevelName(name);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "getLevelName", []() -> std::string { RemoteCall::exportAs("GMLib_ServerAPI", "setFakeSeed", [](int64_t seed) -> void {
return GMLIB_Level::getLevel()->getLevelName(); auto level = GMLIB_Level::getLevel();
if (!level) {
return;
}
return level->setFakeSeed(seed);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "setLevelName", [](std::string name) -> void { RemoteCall::exportAs("GMLib_ServerAPI", "spawnEntity", [](std::pair<Vec3, int> pos, std::string name) -> Actor* {
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<Vec3, int> pos, std::string name) -> Actor* {
return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name); return GMLIB_Spawner::spawnEntity(pos.first, pos.second, name);
}); });
RemoteCall::exportAs("GMLib_ServerAPI", "shootProjectile", [](Actor* owner, std::string name, float speed, float offset) -> Actor* { RemoteCall::exportAs(
auto ac = (GMLIB_Actor*)owner; "GMLib_ServerAPI",
return ac->shootProjectile(name, speed, offset); "shootProjectile",
}); [](Actor* owner, std::string name, float speed, float offset) -> Actor* {
RemoteCall::exportAs("GMLib_ServerAPI", "throwEntity", [](Actor* owner, Actor* actor, float speed, float offset) -> bool { auto ac = (GMLIB_Actor*)owner;
auto ac = (GMLIB_Actor*)owner; return ac->shootProjectile(name, speed, offset);
return ac->throwEntity(actor, speed, offset); }
}); );
RemoteCall::exportAs("GMLib_ServerAPI", "PlayerToEntity", [](Player* player) -> Actor* { RemoteCall::exportAs(
return (Actor*)player; "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; });
} }