diff --git a/bin/ai/compat_14.nut b/bin/ai/compat_14.nut index 012a8d070c..721278c24e 100644 --- a/bin/ai/compat_14.nut +++ b/bin/ai/compat_14.nut @@ -36,3 +36,11 @@ AITown.FoundTown <- function(tile, size, city, layout, name) { return AITown.Fou AIVehicle.SetNameCompat14 <- AIVehicle.SetName; AIVehicle.SetName <- function(id, name) { return AIVehicle.SetNameCompat14(id, AICompat14.Text(name)); } + +AIObject.constructorCompat14 <- AIObject.constructor; +foreach(name, object in CompatScriptRootTable) { + if (type(object) != "class") continue; + if (!object.rawin("constructor")) continue; + if (object.constructor != AIObject.constructorCompat14) continue; + object.constructor <- function() : (name) { AILog.Error("'" + name + "' is not instantiable"); } +} diff --git a/bin/game/compat_14.nut b/bin/game/compat_14.nut index 757e2496f4..652f6724ca 100644 --- a/bin/game/compat_14.nut +++ b/bin/game/compat_14.nut @@ -81,3 +81,11 @@ GSTown.FoundTown <- function(tile, size, city, layout, name) { return GSTown.Fou GSVehicle.SetNameCompat14 <- GSVehicle.SetName; GSVehicle.SetName <- function(id, name) { return GSVehicle.SetNameCompat14(id, GSCompat14.Text(name)); } + +GSObject.constructorCompat14 <- GSObject.constructor; +foreach(name, object in CompatScriptRootTable) { + if (type(object) != "class") continue; + if (!object.rawin("constructor")) continue; + if (object.constructor != GSObject.constructorCompat14) continue; + object.constructor <- function() : (name) { GSLog.Error("'" + name + "' is not instantiable"); } +} diff --git a/src/script/script_instance.cpp b/src/script/script_instance.cpp index 58ba727b62..6cc092e626 100644 --- a/src/script/script_instance.cpp +++ b/src/script/script_instance.cpp @@ -128,6 +128,13 @@ bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::spanapi_version)); + HSQUIRRELVM vm = this->engine->GetVM(); + sq_pushroottable(vm); + sq_pushstring(vm, "CompatScriptRootTable"); + sq_pushroottable(vm); + sq_newslot(vm, -3, SQFalse); + sq_pop(vm, 1); + /* Downgrade the API till we are the same version as the script. The last * entry in the list is always the current version, so skip that one. */ for (auto it = std::rbegin(api_versions) + 1; it != std::rend(api_versions); ++it) { @@ -136,6 +143,11 @@ bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::spanapi_version) break; } + sq_pushroottable(vm); + sq_pushstring(vm, "CompatScriptRootTable"); + sq_deleteslot(vm, -2, SQFalse); + sq_pop(vm, 1); + return true; }