The scripting engine's `ExecutePluginCall` by default frees its `JSValue` arguments.
When `HookEngine::Call` iterates over multiple subscribers, the first call would free
the argument, leaving subsequent subscribers with an invalid pointer (use-after-free).
This commit fixes the issue by duplicating the `JSValue` for each subscriber and
ensuring the original value is correctly managed based on the `keepArgsAlive` flag.
A new C++ headless test `ScriptingTests.cpp` is added to verify the fix and prevent
future regressions.
Previously JS entities would create prototypes on each allocation in
`Sc*::New`. This change creates a single global protype for each entity
class which then gets copied upon entity allocation in JS realm.
Running test with "Live Ride Measurements" plugin on a park shared for
performance testing I get following results:
| | OpenRCT2::Scripting::HookEngine::Call | OpenRCT2::Scripting::ScMap::getAllEntities |
|-----------------|---------------------------------------|--------------------------------------------|
| duktape | 68ms | 10ms |
| quickjs current | 318ms | 126ms |
| quickjs + fix | 22ms | 942µs |
Previously each call to `getAllEntities` would result in 1382 calls to
`JS_SetPropertyFunctionList`, each costing 90.5µs.
Park used: https://files.catbox.moe/z6j2g4.park
* Pass ParkData ref to game actions
* Require ParkData& param for most Park functions
* Pass ParkData& param to Award check functions
* Replace a few more instances of indirect ParkData access
Query all tiles before execution to calculate total cost and detect errors upfront. Show a single combined error with the accumulated total cost instead of per tile errors with stacking sounds
Query all tiles before execution to calculate total cost and detect errors upfront. It now shows a single combined error with the accumulated total cost for insufficient funds instead of per tile errors
Disable error window sound during the placement loop and play the error sound once at the end if all tiles failed. This prevents the sound from stacking when multiple tiles fail simultaneously.