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
+40
View File
@@ -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<RecipeIngredient> 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<RecipeIngredient> 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<std::string> 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 {