Index: source/main.cpp =================================================================== --- source/main.cpp +++ source/main.cpp @@ -51,6 +51,7 @@ #include "ps/Globals.h" #include "ps/Hotkey.h" #include "ps/Loader.h" +#include "ps/Mod.h" #include "ps/ModInstaller.h" #include "ps/Profile.h" #include "ps/Profiler2.h" @@ -547,6 +548,7 @@ g_VFS = CreateVfs(); g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE); MountMods(paths, GetMods(args, INIT_MODS)); + Mod::CacheEnabledModVersions(g_ScriptRuntime); { CReplayPlayer replay; @@ -616,6 +618,7 @@ installer.Install(modPath, g_ScriptRuntime, true); installedMods = installer.GetInstalledMods(); + modsToInstall.clear(); } if (isNonVisual) @@ -632,9 +635,6 @@ Frame(); } - // Do not install mods again in case of restart (typically from the mod selector) - modsToInstall.clear(); - Shutdown(0); MainControllerShutdown(); flags &= ~INIT_MODS; Index: source/ps/GameSetup/GameSetup.h =================================================================== --- source/ps/GameSetup/GameSetup.h +++ source/ps/GameSetup/GameSetup.h @@ -33,6 +33,8 @@ **/ extern void EarlyInit(); +class ScriptRuntime; + enum InitFlags { // avoid setting a video mode / initializing OpenGL; assume that has Index: source/ps/GameSetup/GameSetup.cpp =================================================================== --- source/ps/GameSetup/GameSetup.cpp +++ source/ps/GameSetup/GameSetup.cpp @@ -80,6 +80,7 @@ #include "scriptinterface/ScriptInterface.h" #include "scriptinterface/ScriptStats.h" #include "scriptinterface/ScriptConversions.h" +#include "scriptinterface/ScriptRuntime.h" #include "simulation2/Simulation2.h" #include "lobby/IXmppClient.h" #include "soundmanager/scripting/JSInterface_Sound.h" @@ -922,6 +923,8 @@ const int heapGrowthBytesGCTrigger = 20 * 1024 * 1024; g_ScriptRuntime = ScriptInterface::CreateRuntime(shared_ptr(), runtimeSize, heapGrowthBytesGCTrigger); + Mod::CacheEnabledModVersions(g_ScriptRuntime); + // Special command-line mode to dump the entity schemas instead of running the game. // (This must be done after loading VFS etc, but should be done before wasting time // on anything else.) Index: source/ps/Mod.h =================================================================== --- source/ps/Mod.h +++ source/ps/Mod.h @@ -38,6 +38,8 @@ */ JS::Value GetLoadedModsWithVersions(const ScriptInterface& scriptInterface); + void CacheEnabledModVersions(shared_ptr scriptRuntime); + /** * Gets info (version and mods loaded) on the running engine * Index: source/ps/Mod.cpp =================================================================== --- source/ps/Mod.cpp +++ source/ps/Mod.cpp @@ -31,6 +31,8 @@ std::vector g_modsLoaded; +std::vector> g_LoadedModVersions; + CmdLineArgs g_args; JS::Value Mod::GetAvailableMods(const ScriptInterface& scriptInterface) @@ -101,33 +103,50 @@ return JS::ObjectValue(*obj); } -JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) +void Mod::CacheEnabledModVersions(shared_ptr scriptRuntime) { + debug_printf("CacheEnabledModVersions\n"); + debug_printf("1\n"); + ScriptInterface scriptInterface("Engine", "CacheEnabledModVersions", scriptRuntime); + debug_printf("2\n"); JSContext* cx = scriptInterface.GetContext(); + debug_printf("3\n"); JSAutoRequest rq(cx); + debug_printf("4\n"); JS::RootedValue availableMods(cx, GetAvailableMods(scriptInterface)); + debug_printf("5\n"); - JS::RootedValue ret(cx, JS::ObjectValue(*JS_NewArrayObject(cx, 0))); + g_LoadedModVersions.clear(); - // Index of the created array - size_t j = 0; for (size_t i = 0; i < g_modsLoaded.size(); ++i) { // Ignore user and mod mod as they are irrelevant for compatibility checks if (g_modsLoaded[i] == "mod" || g_modsLoaded[i] == "user") continue; + CStr version; JS::RootedValue modData(cx); if (scriptInterface.GetProperty(availableMods, g_modsLoaded[i].c_str(), &modData)) scriptInterface.GetProperty(modData, "version", version); - scriptInterface.SetPropertyInt(ret, j++, std::vector{g_modsLoaded[i], version}); + + g_LoadedModVersions.push_back({g_modsLoaded[i], version}); } - return ret; +} + +JS::Value Mod::GetLoadedModsWithVersions(const ScriptInterface& scriptInterface) +{ + debug_printf("GetLoadedModsWithVersions\n"); + JSContext* cx = scriptInterface.GetContext(); + JSAutoRequest rq(cx); + JS::RootedValue returnValue(cx); + scriptInterface.ToJSVal(cx, &returnValue, g_LoadedModVersions); + return returnValue; } JS::Value Mod::GetEngineInfo(const ScriptInterface& scriptInterface) { + debug_printf("GetEngineInfo\n"); JSContext* cx = scriptInterface.GetContext(); JSAutoRequest rq(cx);