From 8f964ee637aa65b5c9320bd01da58a86ab097ac8 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Wed, 1 Jul 2020 18:21:19 +0100 Subject: [PATCH] Add day length compatibility fixup for BeeRewards GS --- bin/game/compat_brgs.nut | 9 +++++++++ src/script/script_instance.cpp | 9 ++++++++- src/script/script_instance.hpp | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 bin/game/compat_brgs.nut diff --git a/bin/game/compat_brgs.nut b/bin/game/compat_brgs.nut new file mode 100644 index 0000000000..4b46af98f1 --- /dev/null +++ b/bin/game/compat_brgs.nut @@ -0,0 +1,9 @@ +if ("GetTimeBetweenDates" in CompanyGoal) { + CompanyGoal._GetTimeBetweenDates <- CompanyGoal.GetTimeBetweenDates; + CompanyGoal.GetTimeBetweenDates <- function(start, end) + { + return CompanyGoal._GetTimeBetweenDates(start, start + ((end - start) / GSDate.GetDayLengthFactor())); + } + + GSLog.Info("Day length compatibility in effect."); +} diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 81283cb772..1ed808b590 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -59,7 +59,8 @@ ScriptInstance::ScriptInstance(const char *APIName) : suspend(0), is_paused(false), in_shutdown(false), - callback(nullptr) + callback(nullptr), + APIName(APIName) { this->storage = new ScriptStorage(); this->engine = new Squirrel(APIName); @@ -87,6 +88,12 @@ void ScriptInstance::Initialize(const char *main_script, const char *instance_na return; } + if (strcmp(this->APIName, "GS") == 0) { + if (strcmp(instance_name, "BeeRewardClass") == 0) { + this->LoadCompatibilityScripts("brgs", GAME_DIR); + } + } + /* Create the main-class */ this->instance = new SQObject(); if (!this->engine->CreateClassInstance(instance_name, this->controller, this->instance)) { diff --git a/src/script/script_instance.hpp b/src/script/script_instance.hpp index c097e0eb7b..b06f79a030 100644 --- a/src/script/script_instance.hpp +++ b/src/script/script_instance.hpp @@ -256,6 +256,7 @@ private: bool in_shutdown; ///< Is this instance currently being destructed? Script_SuspendCallbackProc *callback; ///< Callback that should be called in the next tick the script runs. size_t last_allocated_memory; ///< Last known allocated memory value (for display for crashed scripts) + const char *APIName; ///< Name of the API used for this squirrel. /** * Call the script Load function if it exists and data was loaded